📄 frmproductsdemand.vb
字号:
dtData = DataSet11.Tables("主需求计划")
'定义一个DataGrid表样式
Dim ts As New DataGridTableStyle
Dim aColumnTextColumn As DataGridTextBoxColumn
Dim numCols As Integer = dtData.Columns.Count
Dim i As Integer
For i = 1 To 6
If i <> 4 And i <> 5 Then
aColumnTextColumn = New DataGridTextBoxColumn
aColumnTextColumn.MappingName = _
dtData.Columns(i).ColumnName
aColumnTextColumn.HeaderText = _
dtData.Columns(i).ColumnName
aColumnTextColumn.NullText = ""
aColumnTextColumn.Width = 60
ts.GridColumnStyles.Add(aColumnTextColumn)
End If
Next
ts.AlternatingBackColor = Color.LightGray
ts.AllowSorting = False
ts.MappingName = dtData.TableName
dgdList.TableStyles.Add(ts)
Dim dv As DataView = dtData.DefaultView
dv.AllowNew = False
dv.AllowDelete = False
dv.AllowEdit = False
dgdList.DataSource = dtData.DefaultView
bmData = Me.BindingContext(DataSet11, "主需求计划")
If dtData.Rows.Count > 0 Then
Dim db As DataBase = New DataBase
Dim dvTemp As DataView
Dim strSQL As String = "select 物料名称 from 物料主文件 where 物料编号='"
strSQL += dtData.Rows(0)("物料编号") + "'"
dvTemp = db.RunSelectSQL(strSQL)
If dvTemp Is Nothing = False Then
Me.txbName.Text = dvTemp(0)(0).ToString()
End If
db.Dispose()
End If
End Sub
Public Overrides Sub SetOpenButton(ByVal bEnable As Boolean)
btnDate.Enabled = bEnable
btnProduct.Enabled = bEnable
End Sub
Private Sub btnProduct_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnProduct.Click
Try
Dim dlgSelect As frmSelect = New frmSelect
dlgSelect.ShowDialog()
Dim sResult() As String = dlgSelect.GetInfo().Trim.Split("|")
txbID.Text = sResult(0)
txbName.Text = sResult(1)
Catch ex As Exception
MessageBox.Show(ex.ToString)
End Try
End Sub
Public Overrides Sub Clear()
Me.txbBegDate.Text = ""
Me.txbCount.Text = ""
Me.txbDate.Text = ""
Me.txbEndDate.Text = ""
Me.txbID.Text = ""
Me.txbName.Text = ""
Me.txbRemark.Text = ""
Me.txbPlanDate.Text = ""
End Sub
Public Overrides Sub SaveForUpdate()
Try
Dim dv As DataView = DataSet11.Tables("主需求计划").DefaultView
dv.AllowNew = True
Dim row As Integer
row = dgdList.CurrentCell.RowNumber
dgdList.CurrentCell = New DataGridCell(row + 1, 0)
If Me.DataSet11.HasChanges = True Then
SqlDataAdapter1.Update(DataSet11)
End If
dgdList.CurrentCell = New DataGridCell(row - 1, 0)
dv.AllowNew = False
Catch ex As Exception
MessageBox.Show("数据修改失败!")
End Try
End Sub
Public Overrides Sub DeleteData()
Try
DataSet11.Tables("主需求计划").Rows(bmData.Position).Delete()
If Me.DataSet11.HasChanges = True Then
SqlDataAdapter1.Update(DataSet11)
End If
Catch ex As Exception
MessageBox.Show("数据删除失败!")
End Try
End Sub
Public Overrides Sub SaveForAdd()
Dim drData As DataRow = DataSet11.Tables("主需求计划").NewRow()
Try
drData("物料编号") = txbID.Text
drData("年份") = txbDate.Text
drData("计划期") = txbPlanDate.Text
drData("开始日期") = txbBegDate.Text
drData("结束日期") = txbEndDate.Text
drData("需求数量") = txbCount.Text
drData("状态") = Me.cbbState.Text
drData("备注") = txbRemark.Text
Catch ex As Exception
MessageBox.Show("数据格式不正确!")
Exit Sub
End Try
Try
DataSet11.Tables("主需求计划").Rows.Add(drData)
If Me.DataSet11.HasChanges = True Then
SqlDataAdapter1.Update(DataSet11)
End If
Catch ex As Exception
MessageBox.Show("数据添加失败!")
End Try
End Sub
Private Sub btnDate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDate.Click
Try
Dim dlgSelect As frmCalendarMan = New frmCalendarMan
dlgSelect.GroupBox1.Visible = False
dlgSelect.ToolBar1.Visible = False
dlgSelect.dgdList.Dock = DockStyle.Fill
dlgSelect.bClose = True
dlgSelect.ShowDialog()
Dim sResult() As String = dlgSelect.GetInfo().Trim.Split("|")
Me.txbDate.Text = sResult(0)
Me.txbPlanDate.Text = sResult(1)
Me.txbBegDate.Text = sResult(2)
Me.txbEndDate.Text = sResult(3)
Catch ex As Exception
MessageBox.Show(ex.ToString)
End Try
End Sub
Private Sub LoadData()
Dim strFilter As String
If txbOne.Text.Trim.Length = 0 Then
If txbTwo.Text.Trim.Length = 0 Then
If txbThree.Text.Trim.Length = 0 Then
strFilter = ""
Else
strFilter = "where 计划期 like '" + txbThree.Text.Trim + "%'"
End If
Else
strFilter = "where 年份 like '" + txbTwo.Text.Trim + "%'"
If txbThree.Text.Trim.Length <> 0 Then
strFilter += " and 计划期 like '" + txbThree.Text.Trim + "%'"
End If
End If
Else
strFilter = "where 物料编号 like '" + txbOne.Text.Trim + "%'"
If txbTwo.Text.Trim.Length <> 0 Then
strFilter += " and 年份 like '" + txbTwo.Text.Trim + "%'"
If txbThree.Text.Trim.Length <> 0 Then
strFilter += " and 计划期 like '" + txbThree.Text.Trim + "%'"
End If
Else
If txbThree.Text.Trim.Length <> 0 Then
strFilter += " and 计划期 like '" + txbThree.Text.Trim + "%'"
End If
End If
End If
DataSet11.Clear()
SqlConnection1.ConnectionString = DataBase.sConn
SqlDataAdapter1.SelectCommand.CommandText = "select * from 主需求计划 " + strFilter
SqlDataAdapter1.Fill(DataSet11)
dtData = DataSet11.Tables("主需求计划")
bmData = Me.BindingContext(DataSet11, "主需求计划")
End Sub
Public Overrides Sub SearchResult()
LoadData()
dgdList.DataSource = dtData.DefaultView
End Sub
Public Overrides Sub SetProductName()
Dim iRow As Integer = bmData.Position
Dim db As DataBase = New DataBase
Dim dv As DataView
Dim strSQL As String = "select 物料名称 from 物料主文件 where 物料编号='"
strSQL += dtData.Rows(iRow)("物料编号") + "'"
dv = db.RunSelectSQL(strSQL)
Me.txbName.Text = dv(0)(0).ToString()
db.Dispose()
End Sub
Public Overrides Sub SetTextBoxState(ByVal bState As Boolean)
txbBegDate.ReadOnly = bState
txbCount.ReadOnly = bState
txbDate.ReadOnly = bState
txbEndDate.ReadOnly = bState
txbID.ReadOnly = bState
txbName.ReadOnly = bState
txbPlanDate.ReadOnly = bState
txbRemark.ReadOnly = bState
End Sub
End Class
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -