📄 salereduceform.vb
字号:
'文件名:SaleReduceForm.vb
Imports System.Data.SqlClient
Public Class SaleReduceForm
Public MyCompany As String
Private MyQueryTable As DataTable
Private MyID As Integer
Private MyTable As System.Data.DataTable
Private Sub SaleReduceForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.客户名称ToolStripComboBox.Items.Clear()
'设置采购商客户名称
Dim MyConnection As New SqlConnection()
MyConnection.ConnectionString = My.Settings.MySaleConnectionString
MyConnection.Open()
Dim MyCommand As New SqlCommand("Select DISTINCT 客户名称 From 采购商信息 ", MyConnection)
Dim MyReader As SqlDataReader = MyCommand.ExecuteReader()
While (MyReader.Read())
Me.客户名称ToolStripComboBox.Items.Add(MyReader.GetString(0))
End While
If (MyConnection.State = ConnectionState.Open) Then
MyConnection.Close()
End If
'创建无连接的数据表
Dim MyKey(1) As DataColumn
MyTable = New DataTable("退货明细表")
Dim MyColumn As New DataColumn()
MyColumn.DataType = System.Type.GetType("System.Int32")
MyColumn.ColumnName = "序号"
MyTable.Columns.Add(MyColumn)
MyKey(0) = MyColumn
MyTable.PrimaryKey = MyKey
MyTable.Columns.Add("商品编号", System.Type.GetType("System.String"))
MyTable.Columns.Add("商品名称", System.Type.GetType("System.String"))
MyTable.Columns.Add("规格型号", System.Type.GetType("System.String"))
MyTable.Columns.Add("单位", System.Type.GetType("System.String"))
MyTable.Columns.Add("实际销售价", System.Type.GetType("System.Double"))
MyTable.Columns.Add("实际退货价", System.Type.GetType("System.Double"))
MyTable.Columns.Add("数量", System.Type.GetType("System.Double"))
MyTable.Columns.Add("金额", System.Type.GetType("System.Double"))
Me.退货明细DataGridView.DataSource = MyTable
End Sub
Private Sub 客户名称ToolStripComboBox_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles 客户名称ToolStripComboBox.SelectedIndexChanged
Me.MyQueryTable = New DataTable()
Me.销售明细DataGridView.DataSource = MyQueryTable
Me.销售单号ToolStripComboBox.Items.Clear()
Dim MyConnection As New SqlConnection()
MyConnection.ConnectionString = My.Settings.MySaleConnectionString
MyConnection.Open()
Dim MyCommand As New SqlCommand("Select DISTINCT 销售单号 From 销售信息 WHERE 客户名称 LIKE '" + Me.客户名称ToolStripComboBox.Text + "' AND 销售单号 NOT LIKE 'Z这是在处理货款'", MyConnection)
Dim MyReader As SqlDataReader = MyCommand.ExecuteReader()
While (MyReader.Read())
Me.销售单号ToolStripComboBox.Items.Add(MyReader.GetString(0))
End While
If (MyConnection.State = ConnectionState.Open) Then
MyConnection.Close()
End If
新增退货单Button_Click(Nothing, Nothing)
Me.商品编号TextBox.Text = ""
Me.商品名称TextBox.Text = ""
Me.规格型号TextBox.Text = ""
Me.单位TextBox.Text = ""
Me.数量TextBox.Text = ""
Me.实际销售价TextBox.Text = ""
Me.实际退货价TextBox.Text = ""
Me.金额TextBox.Text = ""
End Sub
Private Sub 查询原销售单ToolStripButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles 查询原销售单ToolStripButton.Click
Me.MyQueryTable.Rows.Clear()
'查询指定客户的销售单明细
Me.销售单号ToolStripComboBox.Items.Clear()
Dim MyConnection As New SqlConnection()
MyConnection.ConnectionString = My.Settings.MySaleConnectionString
MyConnection.Open()
Dim MySQL As String = "Select * From 销售退货查询视图 Where 客户名称='" + Me.客户名称ToolStripComboBox.Text + "' AND 销售单号 LIKE '%" + Me.销售单号ToolStripComboBox.Text + "%'"
Dim MyAdapter As New SqlDataAdapter(MySQL, MyConnection)
MyAdapter.Fill(MyQueryTable)
Me.销售明细DataGridView.DataSource = MyQueryTable
If (MyConnection.State = ConnectionState.Open) Then
MyConnection.Close()
End If
End Sub
Private Sub 新增退货单Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles 新增退货单Button.Click
'自动计算退货单自编号
Dim MySQLConnectionString As String = My.Settings.MySaleConnectionString
Dim MyConnection As New SqlConnection(MySQLConnectionString)
MyConnection.Open()
Dim MyCommand As SqlCommand = MyConnection.CreateCommand()
MyCommand.CommandText = "Select max(自编号) 最大编号 From 销售信息"
Dim MyResult As Object = MyCommand.ExecuteScalar()
Dim MyID As System.Int64 = 1
If (Not (MyResult Is System.DBNull.Value)) Then
Dim MyMaxID As String = MyResult.ToString().Trim()
MyMaxID = MyMaxID.Substring(2, MyMaxID.Length - 2)
MyID = Convert.ToInt64(MyMaxID) + 1
End If
Dim MyLength As Integer = MyID.ToString().Length
Dim MyNewID As String = ""
Select Case (MyLength)
Case 1
MyNewID = "XS0000000" + MyID.ToString()
Case 2
MyNewID = "XS000000" + MyID.ToString()
Case 3
MyNewID = "XS00000" + MyID.ToString()
Case 4
MyNewID = "XS0000" + MyID.ToString()
Case 5
MyNewID = "XS000" + MyID.ToString()
Case 6
MyNewID = "XS00" + MyID.ToString()
Case 7
MyNewID = "XS0" + MyID.ToString()
End Select
If (MyConnection.State = ConnectionState.Open) Then
MyConnection.Close()
End If
Me.自编号TextBox.Text = MyNewID
Me.退货单号TextBox.Text = ""
Me.客户名称TextBox.Text = Me.客户名称ToolStripComboBox.Text
Me.退货金额TextBox.Text = "0"
Me.经办人TextBox.Text = ""
Me.说明TextBox.Text = ""
Me.MyID = 0
End Sub
Private Sub 销售明细DataGridView_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles 销售明细DataGridView.Click
If (Me.自编号TextBox.Text.Length < 1) Then
Return
End If
Me.商品编号TextBox.Text = Me.销售明细DataGridView.CurrentRow.Cells(1).Value.ToString()
Me.商品名称TextBox.Text = Me.销售明细DataGridView.CurrentRow.Cells(2).Value.ToString()
Me.规格型号TextBox.Text = Me.销售明细DataGridView.CurrentRow.Cells(3).Value.ToString()
Me.单位TextBox.Text = Me.销售明细DataGridView.CurrentRow.Cells(4).Value.ToString()
Me.数量TextBox.Text = "-" + Me.销售明细DataGridView.CurrentRow.Cells(5).Value.ToString()
Me.实际销售价TextBox.Text = Me.销售明细DataGridView.CurrentRow.Cells(6).Value.ToString()
Me.实际退货价TextBox.Text = Me.销售明细DataGridView.CurrentRow.Cells(6).Value.ToString()
Me.金额TextBox.Text = ""
End Sub
Private Sub 实际退货价TextBox_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles 实际退货价TextBox.TextChanged
If (Me.数量TextBox.Text.Length < 1) Then
Return
End If
If (Me.实际退货价TextBox.Text.Length < 1) Then
Return
End If
Dim My实际退货价 As Double = Convert.ToDouble(Me.实际退货价TextBox.Text)
Dim My数量 As Double = Convert.ToDouble(Me.数量TextBox.Text)
Dim My金额 As Double = My实际退货价 * My数量
Me.金额TextBox.Text = My金额.ToString()
End Sub
Private Sub 数量TextBox_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles 数量TextBox.TextChanged
If (Me.数量TextBox.Text.Length < 1) Then
Return
End If
If (Me.实际退货价TextBox.Text.Length < 1) Then
Return
End If
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -