📄 warehouseoutform.vb
字号:
'文件名:WarehouseOutForm.vb
Imports System.Data.SqlClient
Public Class WarehouseOutForm
Public MyCompany As String
Private MyQueryTable As DataTable
Private MyID As Integer
Private MyTable As System.Data.DataTable
Private Sub WarehouseOutForm_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"))
MyTable.Columns.Add("生产日期", System.Type.GetType("System.DateTime"))
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 = "CG0000000" + MyID.ToString()
Case 2
MyNewID = "CG000000" + MyID.ToString()
Case 3
MyNewID = "CG00000" + MyID.ToString()
Case 4
MyNewID = "CG0000" + MyID.ToString()
Case 5
MyNewID = "CG000" + MyID.ToString()
Case 6
MyNewID = "CG00" + MyID.ToString()
Case 7
MyNewID = "CG0" + 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.生产日期DateTimePicker.Value = Me.采购明细DataGridView.CurrentRow.Cells(7).Value
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 + -