⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 frmmps.vb

📁 生产管理系统。vb.net sql2
💻 VB
📖 第 1 页 / 共 4 页
字号:
        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 btnSubmit_Click(ByVal sender As System.Object, _
    ByVal e As System.EventArgs) Handles btnSubmit.Click
        '判断主需求列表是否为空
        If dvDetailResult.Count = 0 Then
            Exit Sub
        End If
        '查询最大的MPS编号
        Dim db As DataBase = New DataBase
        Dim strSQL As String = "select max(编号) from 主生产计划"
        Dim dv As DataView = db.RunSelectSQL(strSQL)
        Dim iMax As Integer
        Dim sMax As String
        If dv Is Nothing Then
            '如果主生产计划表中没有最大的MPS编号
            '查看主生产计划历史表中的最大的MPS编号
            strSQL = "select max(编号) from 主生产计划历史"
            Dim dvH As DataView = db.RunSelectSQL(strSQL)
            If dvH Is Nothing Then
                sMax = "MPS0000000001"
            Else
                '获得主生产计划历史表最大的MPS编号的数字部分
                sMax = dvH(0)(0).ToString().Substring(3)
                iMax = CInt(sMax)
                iMax += 1
                sMax = iMax.ToString
                Dim i, len As Integer
                len = 10 - iMax.ToString.Length
                For i = 0 To len - 1
                    sMax = "0" + sMax
                Next
                sMax = "MPS" + sMax
            End If
        Else
            '获得主生产计划表最大的MPS编号的数字部分
            sMax = dv(0)(0).ToString().Substring(3)
            iMax = CInt(sMax)
            iMax += 1
            sMax = iMax.ToString
            Dim i, len As Integer
            len = 10 - iMax.ToString.Length
            For i = 0 To len - 1
                sMax = "0" + sMax
            Next
            sMax = "MPS" + sMax
        End If
        '将主需求计划数据导入主生产计划数据
        Dim iRow As Integer = dgdDetailList.CurrentCell.RowNumber
        Dim sDemCount, sId, sDate, sPlanDate, _
        sBegDate, sEndDate, sState As String
        sDemCount = dvDetailResult.Item(iRow)("需求数量")
        sId = dvDetailResult.Item(iRow)("物料编号")
        sDate = dvDetailResult.Item(iRow)("年份")
        sPlanDate = dvDetailResult.Item(iRow)("计划期")
        sBegDate = dvDetailResult.Item(iRow)("开始日期")
        sEndDate = dvDetailResult.Item(iRow)("结束日期")
        sState = dvDetailResult.Item(iRow)("状态")
        strSQL = "insert into 主生产计划 (物料编号,编号,年份,"
        strSQL += "计划期,开始日期,结束日期,需求数量,MPS数量,状态)"
        strSQL += "values ('" + sId.Trim + "','" + sMax + "','"
        strSQL += sDate + "','" + sPlanDate + "','"
        strSQL += sBegDate + "','" + sEndDate + "','"
        strSQL += sDemCount + "','" + sDemCount + "','"
        strSQL += sState + "')"
        db.RunDelOrInsSQL(strSQL)
        strSQL = "delete from 主需求计划 where 物料编号='"
        strSQL += sId + "' and 年份='"
        strSQL += sDate + "' and 计划期='" + sPlanDate + "'"
        db.RunDelOrInsSQL(strSQL)
        db.Dispose()
        SearchResult()
        SetForDetailList()
    End Sub

    Public Overrides Sub SetOpenButton(ByVal bEnable As Boolean)
        btnDate.Enabled = bEnable
        btnProduct.Enabled = bEnable
    End Sub

    Public Overrides Sub SaveForUpdate()
        Try
            Dim row As Integer
            row = dgdList.CurrentCell.RowNumber
            dgdList.CurrentCell = New DataGridCell((row + 1) Mod bmData.Count, 0)
            If Me.DataSet11.HasChanges = True Then
                SqlDataAdapter1.Update(DataSet11)
            End If
        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("物料名称") = txbName.Text
            drData("年份") = txbDate.Text
            drData("计划期") = txbPlanDate.Text
            drData("开始日期") = txbBegDate.Text
            drData("结束日期") = txbEndDate.Text
            drData("期初库存") = SetText(txbProCount.Text)
            drData("需求数量") = SetText(txbDemCount.Text)
            drData("MPS数量") = SetText(txbMPSCount.Text)
            drData("生产单数量") = SetText(txbProCount.Text)
            drData("预计库存") = SetText(txbExpStock.Text)
            drData("备注") = txbRemark.Text
            drData("状态") = "正常"
        Catch ex As Exception
            MessageBox.Show(ex.ToString) '("数据格式不正确!")
            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(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
    Private Function SetText(ByVal strText As String) As String
        If strText.Trim = "" Then
            Return "0"
        Else
            Return strText.Trim
        End If
    End Function
End Class

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -