📄 frmgoods.vb
字号:
Me.txtStockNum.MaxLength = 9
Me.txtStockNum.Name = "txtStockNum"
Me.txtStockNum.Size = New System.Drawing.Size(112, 21)
Me.txtStockNum.TabIndex = 11
Me.txtStockNum.Text = ""
'
'Label6
'
Me.Label6.AutoSize = True
Me.Label6.Location = New System.Drawing.Point(48, 272)
Me.Label6.Name = "Label6"
Me.Label6.Size = New System.Drawing.Size(42, 17)
Me.Label6.TabIndex = 10
Me.Label6.Text = "数量:*"
'
'txtUnit
'
Me.txtUnit.Location = New System.Drawing.Point(112, 232)
Me.txtUnit.MaxLength = 5
Me.txtUnit.Name = "txtUnit"
Me.txtUnit.Size = New System.Drawing.Size(112, 21)
Me.txtUnit.TabIndex = 9
Me.txtUnit.Text = ""
'
'Label5
'
Me.Label5.AutoSize = True
Me.Label5.Location = New System.Drawing.Point(48, 232)
Me.Label5.Name = "Label5"
Me.Label5.Size = New System.Drawing.Size(60, 17)
Me.Label5.TabIndex = 8
Me.Label5.Text = "单位(本):"
'
'txtPrice
'
Me.txtPrice.Location = New System.Drawing.Point(112, 192)
Me.txtPrice.Name = "txtPrice"
Me.txtPrice.Size = New System.Drawing.Size(112, 21)
Me.txtPrice.TabIndex = 7
Me.txtPrice.Text = ""
'
'Label4
'
Me.Label4.AutoSize = True
Me.Label4.Location = New System.Drawing.Point(48, 192)
Me.Label4.Name = "Label4"
Me.Label4.Size = New System.Drawing.Size(66, 17)
Me.Label4.TabIndex = 6
Me.Label4.Text = "单价(元)*:"
'
'txtGoodsName
'
Me.txtGoodsName.Location = New System.Drawing.Point(112, 152)
Me.txtGoodsName.MaxLength = 30
Me.txtGoodsName.Name = "txtGoodsName"
Me.txtGoodsName.Size = New System.Drawing.Size(200, 21)
Me.txtGoodsName.TabIndex = 5
Me.txtGoodsName.Text = ""
'
'Label3
'
Me.Label3.AutoSize = True
Me.Label3.Location = New System.Drawing.Point(48, 152)
Me.Label3.Name = "Label3"
Me.Label3.Size = New System.Drawing.Size(66, 17)
Me.Label3.TabIndex = 4
Me.Label3.Text = "图书名称:*"
'
'cboTypeName
'
Me.cboTypeName.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList
Me.cboTypeName.Location = New System.Drawing.Point(112, 72)
Me.cboTypeName.Name = "cboTypeName"
Me.cboTypeName.Size = New System.Drawing.Size(104, 20)
Me.cboTypeName.TabIndex = 3
'
'Label2
'
Me.Label2.AutoSize = True
Me.Label2.Location = New System.Drawing.Point(48, 72)
Me.Label2.Name = "Label2"
Me.Label2.Size = New System.Drawing.Size(66, 17)
Me.Label2.TabIndex = 2
Me.Label2.Text = "图书类型:*"
'
'txtGoodsID
'
Me.txtGoodsID.Location = New System.Drawing.Point(112, 32)
Me.txtGoodsID.Name = "txtGoodsID"
Me.txtGoodsID.ReadOnly = True
Me.txtGoodsID.Size = New System.Drawing.Size(112, 21)
Me.txtGoodsID.TabIndex = 1
Me.txtGoodsID.Text = ""
'
'Label1
'
Me.Label1.AutoSize = True
Me.Label1.Location = New System.Drawing.Point(48, 32)
Me.Label1.Name = "Label1"
Me.Label1.Size = New System.Drawing.Size(66, 17)
Me.Label1.TabIndex = 0
Me.Label1.Text = "图书编号:*"
'
'btnAdd
'
Me.btnAdd.Location = New System.Drawing.Point(528, 544)
Me.btnAdd.Name = "btnAdd"
Me.btnAdd.Size = New System.Drawing.Size(64, 24)
Me.btnAdd.TabIndex = 2
Me.btnAdd.Text = "添加"
'
'btnUpdate
'
Me.btnUpdate.Location = New System.Drawing.Point(608, 544)
Me.btnUpdate.Name = "btnUpdate"
Me.btnUpdate.Size = New System.Drawing.Size(64, 24)
Me.btnUpdate.TabIndex = 3
Me.btnUpdate.Text = "更新"
'
'btnDel
'
Me.btnDel.Location = New System.Drawing.Point(688, 544)
Me.btnDel.Name = "btnDel"
Me.btnDel.Size = New System.Drawing.Size(64, 24)
Me.btnDel.TabIndex = 4
Me.btnDel.Text = "删除"
'
'btnOK
'
Me.btnOK.Location = New System.Drawing.Point(768, 544)
Me.btnOK.Name = "btnOK"
Me.btnOK.Size = New System.Drawing.Size(64, 24)
Me.btnOK.TabIndex = 5
Me.btnOK.Text = "确定"
'
'btnCancel
'
Me.btnCancel.Location = New System.Drawing.Point(848, 544)
Me.btnCancel.Name = "btnCancel"
Me.btnCancel.Size = New System.Drawing.Size(64, 24)
Me.btnCancel.TabIndex = 6
Me.btnCancel.Text = "取消"
'
'frmGoods
'
Me.AutoScaleBaseSize = New System.Drawing.Size(6, 14)
Me.ClientSize = New System.Drawing.Size(928, 581)
Me.Controls.Add(Me.btnCancel)
Me.Controls.Add(Me.btnOK)
Me.Controls.Add(Me.btnDel)
Me.Controls.Add(Me.btnUpdate)
Me.Controls.Add(Me.btnAdd)
Me.Controls.Add(Me.GroupBox1)
Me.Controls.Add(Me.GroupBox2)
Me.MaximizeBox = False
Me.Name = "frmGoods"
Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
Me.Text = "图书信息管理"
Me.WindowState = System.Windows.Forms.FormWindowState.Maximized
Me.GroupBox1.ResumeLayout(False)
CType(Me.dgGoods, System.ComponentModel.ISupportInitialize).EndInit()
Me.GroupBox2.ResumeLayout(False)
Me.ResumeLayout(False)
End Sub
#End Region
Private Sub frmGoods_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
strCommand = ""
Dim Params() As SqlParameter = {}
myDataObj.ExecuteSP("sp_GetAllCategory", Params, drSqlServer)
cboOrderbyType.Items.Add("所有")
Do While drSqlServer.Read()
cboTypeID.Items.Add(drSqlServer(0))
cboTypeName.Items.Add(drSqlServer(1))
cboOrderbyType.Items.Add(drSqlServer(1))
Loop
drSqlServer.Close()
myDataObj.ExecuteSP("sp_GetAllWarehouse", Params, drSqlServer)
cboOrderByWarehouse.Items.Add("所有")
Do While drSqlServer.Read()
cboWarehouseID.Items.Add(drSqlServer(0))
cboWarehouseName.Items.Add(drSqlServer(1))
cboOrderByWarehouse.Items.Add(drSqlServer(1))
Loop
drSqlServer.Close()
'cboOrderbyType.SelectedIndex = 0
'cboOrderByWarehouse.SelectedIndex = 0
With cboOrderbyNum.Items()
.Add("所有")
.Add("正常")
.Add("过低")
.Add("过高")
End With
If strUserType = "3" Then
btnAdd.Visible = False
btnUpdate.Visible = False
btnDel.Visible = False
' strSQL = "SELECT t.TransactionID, t.TransactionType, t.GoodsID, g.GoodsName, t.GoodsPrice, t.GoodsNum, t.GoodsAmount, t.CustomerID, c.CustomerName, t.ModifyDate, t.UserID, t.Status " & _
' "FROM TransInfo t " & _
' "INNER JOIN Goods g ON t.GoodsID=g.GoodsID " & _
' "INNER JOIN Customer c ON t.CustomerID=c.CustomerID "
'图书库存管理员
ElseIf strUserType = "2" Then
btnAdd.Visible = True
btnUpdate.Visible = True
btnDel.Visible = True
' strSQL = "SELECT t.TransactionID, t.TransactionType, t.GoodsID, g.GoodsName, t.GoodsPrice, t.GoodsNum, t.GoodsAmount, t.CustomerID, c.CustomerName, t.ModifyDate, t.UserID, t.Status " & _
' "FROM TransInfo t " & _
' "INNER JOIN Goods g ON t.GoodsID=g.GoodsID " & _
' "INNER JOIN Customer c ON t.CustomerID=c.CustomerID " & _
' "WHERE Status='已提交'"
End If
strSQL = "SELECT g.GoodsID, g.GoodsName, c.TypeName,g.TypeID, g.Price, g.StockNum, g.Unit, g.NumLow, g.NumHigh, w.WarehouseName, g.WarehouseID " & _
"FROM Goods g " & _
"INNER JOIN Category c ON g.TypeID=c.TypeID " & _
"INNER JOIN Warehouse w ON g.WarehouseID=w.WarehouseID"
freshData()
End Sub
Private Sub freshData()
Dim dsGoods As New DataSet()
dsGoods.Clear()
'myDataAdapter = New SqlDataAdapter(strSQL, cnSqlServer)
'myDataAdapter.Fill(dsGoods)
myDataObj.ExecuteSQL(strSQL, dsGoods)
With dgGoods
.TableStyles.Clear()
.DataSource = dsGoods
.DataMember = "table"
End With
Dim ts As New DataGridTableStyle()
Dim ac As New DataGridTextBoxColumn()
Dim HeaderValues(10) As String
Dim WidthValues(10) As Integer
Dim i As Integer
HeaderValues(0) = "商品ID"
HeaderValues(1) = "商品名称"
HeaderValues(2) = "商品类型"
HeaderValues(3) = "类型ID"
HeaderValues(4) = "单价"
HeaderValues(5) = "数量"
HeaderValues(6) = "单位"
HeaderValues(7) = "数量下限"
HeaderValues(8) = "数量上限"
HeaderValues(9) = "所在仓库"
HeaderValues(10) = "仓库ID"
WidthValues(0) = 50
WidthValues(1) = 100
WidthValues(2) = 70
WidthValues(3) = 100
WidthValues(4) = 100
WidthValues(5) = 70
WidthValues(6) = 100
WidthValues(7) = 70
WidthValues(8) = 70
WidthValues(9) = 70
WidthValues(10) = 100
ts.MappingName = dsGoods.Tables(0).TableName
For i = 0 To 10
ac = New DataGridTextBoxColumn()
ac.HeaderText = HeaderValues(i) '列名
ac.MappingName = dsGoods.Tables("table").Columns(i).ColumnName
ac.TextBox.AutoSize = True 'datagrid内的文本框宽度自适应调整
ac.NullText = String.Empty
ts.AlternatingBackColor = Color.LightGray '设定交替行的背景色
ts.PreferredColumnWidth = WidthValues(i) '列宽
ts.GridColumnStyles.Add(ac)
Next i
dgGoods.TableStyles.Add(ts)
'需要判断DataGrid控件内容是否为空
'showData()
End Sub
Private Sub showData()
With dgGoods
txtGoodsID.Text = .Item(.CurrentRowIndex, 0)
txtGoodsName.Text = .Item(.CurrentRowIndex, 1)
cboTypeName.Text = .Item(.CurrentRowIndex, 2)
cboTypeID.Text = .Item(.CurrentRowIndex, 3)
txtPrice.Text = .Item(.CurrentRowIndex, 4)
txtStockNum.Text = .Item(.CurrentRowIndex, 5)
txtUnit.Text = .Item(.CurrentRowIndex, 6)
txtNumLow.Text = .Item(.CurrentRowIndex, 7)
txtNumHigh.Text = .Item(.CurrentRowIndex, 8)
cboWarehouseName.Text = .Item(.CurrentRowIndex, 9)
cboWarehouseID.Text = .Item(.CurrentRowIndex, 10)
End With
End Sub
Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click
GroupBox2.Enabled = True
txtGoodsID.Text = ""
txtGoodsName.Text = ""
cboTypeName.Text = ""
txtPrice.Text = ""
txtStockNum.Text = ""
txtUnit.Text = "本"
txtNumLow.Text = ""
txtNumHigh.Text = ""
cboWarehouseName.Text = ""
strCommand = "add"
btnUpdate.Enabled = False
btnDel.Enabled = False
End Sub
Private Sub btnUpdate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnUpdate.Click
GroupBox2.Enabled = True
strCommand = "update"
btnAdd.Enabled = False
btnDel.Enabled = False
End Sub
Private Sub btnOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOK.Click
If strCommand = "add" Then
If cboTypeName.Text = "" Or txtGoodsName.Text.Trim = "" Or txtPrice.Text.Trim = "" Or _
txtStockNum.Text.Trim = "" Or txtNumLow.Text = "" Or txtNumHigh.Text = "" Or cboWarehouseName.Text = "" Then
MsgBox("请填写完整的信息", MsgBoxStyle.Exclamation)
Exit Sub
End If
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -