BomForm.cs
资源名称:VCSDB.rar [点击查看]
上传用户:hjieqiu
上传日期:2013-05-11
资源大小:16494k
文件大小:39k
源码类别:
企业管理
开发平台:
C#
- using System;
- using System.Drawing;
- using System.Collections;
- using System.ComponentModel;
- using System.Windows.Forms;
- using System.Data;
- using System.Data.SqlClient;
- namespace 生产管理系统
- {
- /// <summary>
- /// BomForm 的摘要说明。
- /// </summary>
- public class BomForm : System.Windows.Forms.Form
- {
- private DataTable tblBom=new DataTable();
- private int curStatus=0;//在提交判断当前状态是新增还是修改,以使用不同的SQL语句,0代表普通状态
- public static string mID,mName;//保存物料编号和名称
- private System.Windows.Forms.TreeView treeView1;
- private System.Data.SqlClient.SqlDataAdapter sqlDataAdapter1;
- private System.Data.SqlClient.SqlCommand sqlSelectCommand1;
- private System.Data.SqlClient.SqlCommand sqlInsertCommand1;
- private System.Data.SqlClient.SqlCommand sqlUpdateCommand1;
- private System.Data.SqlClient.SqlCommand sqlDeleteCommand1;
- private System.Data.SqlClient.SqlConnection sqlConnection1;
- private System.Windows.Forms.ToolBar toolBar1;
- private System.Windows.Forms.ToolBarButton tBtnNew;
- private System.Windows.Forms.ToolBarButton tBtnEdit;
- private System.Windows.Forms.ToolBarButton tBtnDelete;
- private System.Windows.Forms.ToolBarButton tBtnSubmit;
- private System.Windows.Forms.ToolBarButton tBtnCancel;
- private System.Windows.Forms.ToolBarButton tBtnQuit;
- private System.Windows.Forms.ImageList imageList1;
- private System.Windows.Forms.GroupBox groupBox1;
- private System.Windows.Forms.Label label1;
- private System.Windows.Forms.TextBox txt1;
- private System.Windows.Forms.TextBox txt2;
- private System.Windows.Forms.TextBox txt4;
- private System.Windows.Forms.TextBox txt3;
- private System.Windows.Forms.TextBox txt6;
- private System.Windows.Forms.TextBox txt5;
- private System.Windows.Forms.TextBox txt8;
- private System.Windows.Forms.TextBox txt7;
- private System.Windows.Forms.TextBox txt9;
- private System.Windows.Forms.TextBox txt10;
- private System.Windows.Forms.Label label2;
- private System.Windows.Forms.Label label3;
- private System.Windows.Forms.Label label4;
- private System.Windows.Forms.Label label5;
- private System.Windows.Forms.Label label6;
- private System.Windows.Forms.Label label7;
- private System.Windows.Forms.Label label8;
- private System.Windows.Forms.Label label9;
- private System.Windows.Forms.Label label10;
- private System.Windows.Forms.Button selBtn1;
- private System.ComponentModel.IContainer components;
- public BomForm()
- {
- //
- // Windows 窗体设计器支持所必需的
- //
- InitializeComponent();
- //
- // TODO: 在 InitializeComponent 调用后添加任何构造函数代码
- //
- }
- /// <summary>
- /// 清理所有正在使用的资源。
- /// </summary>
- protected override void Dispose( bool disposing )
- {
- if( disposing )
- {
- if(components != null)
- {
- components.Dispose();
- }
- }
- base.Dispose( disposing );
- }
- #region Windows 窗体设计器生成的代码
- /// <summary>
- /// 设计器支持所需的方法 - 不要使用代码编辑器修改
- /// 此方法的内容。
- /// </summary>
- private void InitializeComponent()
- {
- this.components = new System.ComponentModel.Container();
- System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(BomForm));
- this.treeView1 = new System.Windows.Forms.TreeView();
- this.sqlDataAdapter1 = new System.Data.SqlClient.SqlDataAdapter();
- this.sqlDeleteCommand1 = new System.Data.SqlClient.SqlCommand();
- this.sqlConnection1 = new System.Data.SqlClient.SqlConnection();
- this.sqlInsertCommand1 = new System.Data.SqlClient.SqlCommand();
- this.sqlSelectCommand1 = new System.Data.SqlClient.SqlCommand();
- this.sqlUpdateCommand1 = new System.Data.SqlClient.SqlCommand();
- this.toolBar1 = new System.Windows.Forms.ToolBar();
- this.tBtnNew = new System.Windows.Forms.ToolBarButton();
- this.tBtnEdit = new System.Windows.Forms.ToolBarButton();
- this.tBtnDelete = new System.Windows.Forms.ToolBarButton();
- this.tBtnSubmit = new System.Windows.Forms.ToolBarButton();
- this.tBtnCancel = new System.Windows.Forms.ToolBarButton();
- this.tBtnQuit = new System.Windows.Forms.ToolBarButton();
- this.imageList1 = new System.Windows.Forms.ImageList(this.components);
- this.groupBox1 = new System.Windows.Forms.GroupBox();
- this.selBtn1 = new System.Windows.Forms.Button();
- this.label1 = new System.Windows.Forms.Label();
- this.txt1 = new System.Windows.Forms.TextBox();
- this.txt2 = new System.Windows.Forms.TextBox();
- this.txt4 = new System.Windows.Forms.TextBox();
- this.txt3 = new System.Windows.Forms.TextBox();
- this.txt6 = new System.Windows.Forms.TextBox();
- this.txt5 = new System.Windows.Forms.TextBox();
- this.txt8 = new System.Windows.Forms.TextBox();
- this.txt7 = new System.Windows.Forms.TextBox();
- this.txt9 = new System.Windows.Forms.TextBox();
- this.txt10 = new System.Windows.Forms.TextBox();
- this.label2 = new System.Windows.Forms.Label();
- this.label3 = new System.Windows.Forms.Label();
- this.label4 = new System.Windows.Forms.Label();
- this.label5 = new System.Windows.Forms.Label();
- this.label6 = new System.Windows.Forms.Label();
- this.label7 = new System.Windows.Forms.Label();
- this.label8 = new System.Windows.Forms.Label();
- this.label9 = new System.Windows.Forms.Label();
- this.label10 = new System.Windows.Forms.Label();
- this.groupBox1.SuspendLayout();
- this.SuspendLayout();
- //
- // treeView1
- //
- this.treeView1.ImageIndex = -1;
- this.treeView1.Location = new System.Drawing.Point(0, 48);
- this.treeView1.Name = "treeView1";
- this.treeView1.SelectedImageIndex = -1;
- this.treeView1.Size = new System.Drawing.Size(192, 392);
- this.treeView1.TabIndex = 0;
- this.treeView1.AfterSelect += new System.Windows.Forms.TreeViewEventHandler(this.treeView1_AfterSelect);
- //
- // sqlDataAdapter1
- //
- this.sqlDataAdapter1.DeleteCommand = this.sqlDeleteCommand1;
- this.sqlDataAdapter1.InsertCommand = this.sqlInsertCommand1;
- this.sqlDataAdapter1.SelectCommand = this.sqlSelectCommand1;
- this.sqlDataAdapter1.TableMappings.AddRange(new System.Data.Common.DataTableMapping[] {
- new System.Data.Common.DataTableMapping("Table", "物料清单", new System.Data.Common.DataColumnMapping[] {
- new System.Data.Common.DataColumnMapping("父项编号", "父项编号"),
- new System.Data.Common.DataColumnMapping("物料编号", "物料编号"),
- new System.Data.Common.DataColumnMapping("需要数量", "需要数量"),
- new System.Data.Common.DataColumnMapping("领料车间", "领料车间"),
- new System.Data.Common.DataColumnMapping("领料库房", "领料库房"),
- new System.Data.Common.DataColumnMapping("损耗率", "损耗率"),
- new System.Data.Common.DataColumnMapping("bom状态", "bom状态"),
- new System.Data.Common.DataColumnMapping("bom信息状态", "bom信息状态"),
- new System.Data.Common.DataColumnMapping("审核者", "审核者"),
- new System.Data.Common.DataColumnMapping("审核日期", "审核日期"),
- new System.Data.Common.DataColumnMapping("其它事项", "其它事项"),
- new System.Data.Common.DataColumnMapping("低层码", "低层码"),
- new System.Data.Common.DataColumnMapping("展开标记", "展开标记")})});
- this.sqlDataAdapter1.UpdateCommand = this.sqlUpdateCommand1;
- //
- // sqlDeleteCommand1
- //
- this.sqlDeleteCommand1.CommandText = @"DELETE FROM 物料清单 WHERE (父项编号 = @Original_父项编号) AND (物料编号 = @Original_物料编号) AND (bom信息状态 = @Original_bom信息状态 OR @Original_bom信息状态 IS NULL AND bom信息状态 IS NULL) AND (bom状态 = @Original_bom状态 OR @Original_bom状态 IS NULL AND bom状态 IS NULL) AND (低层码 = @Original_低层码 OR @Original_低层码 IS NULL AND 低层码 IS NULL) AND (审核日期 = @Original_审核日期 OR @Original_审核日期 IS NULL AND 审核日期 IS NULL) AND (审核者 = @Original_审核者 OR @Original_审核者 IS NULL AND 审核者 IS NULL) AND (展开标记 = @Original_展开标记 OR @Original_展开标记 IS NULL AND 展开标记 IS NULL) AND (损耗率 = @Original_损耗率 OR @Original_损耗率 IS NULL AND 损耗率 IS NULL) AND (需要数量 = @Original_需要数量) AND (领料库房 = @Original_领料库房 OR @Original_领料库房 IS NULL AND 领料库房 IS NULL) AND (领料车间 = @Original_领料车间 OR @Original_领料车间 IS NULL AND 领料车间 IS NULL)";
- this.sqlDeleteCommand1.Connection = this.sqlConnection1;
- this.sqlDeleteCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_父项编号", System.Data.SqlDbType.VarChar, 14, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "父项编号", System.Data.DataRowVersion.Original, null));
- this.sqlDeleteCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_物料编号", System.Data.SqlDbType.VarChar, 14, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "物料编号", System.Data.DataRowVersion.Original, null));
- this.sqlDeleteCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_bom信息状态", System.Data.SqlDbType.VarChar, 1, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "bom信息状态", System.Data.DataRowVersion.Original, null));
- this.sqlDeleteCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_bom状态", System.Data.SqlDbType.VarChar, 1, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "bom状态", System.Data.DataRowVersion.Original, null));
- this.sqlDeleteCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_低层码", System.Data.SqlDbType.Int, 4, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "低层码", System.Data.DataRowVersion.Original, null));
- this.sqlDeleteCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_审核日期", System.Data.SqlDbType.Int, 4, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "审核日期", System.Data.DataRowVersion.Original, null));
- this.sqlDeleteCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_审核者", System.Data.SqlDbType.VarChar, 8, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "审核者", System.Data.DataRowVersion.Original, null));
- this.sqlDeleteCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_展开标记", System.Data.SqlDbType.Bit, 1, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "展开标记", System.Data.DataRowVersion.Original, null));
- this.sqlDeleteCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_损耗率", System.Data.SqlDbType.Decimal, 5, System.Data.ParameterDirection.Input, false, ((System.Byte)(5)), ((System.Byte)(4)), "损耗率", System.Data.DataRowVersion.Original, null));
- this.sqlDeleteCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_需要数量", System.Data.SqlDbType.Decimal, 9, System.Data.ParameterDirection.Input, false, ((System.Byte)(18)), ((System.Byte)(4)), "需要数量", System.Data.DataRowVersion.Original, null));
- this.sqlDeleteCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_领料库房", System.Data.SqlDbType.VarChar, 10, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "领料库房", System.Data.DataRowVersion.Original, null));
- this.sqlDeleteCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_领料车间", System.Data.SqlDbType.VarChar, 10, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "领料车间", System.Data.DataRowVersion.Original, null));
- //
- // sqlConnection1
- //
- this.sqlConnection1.ConnectionString = "workstation id=localhost;Integrated Security=SSPI;Database=mrpbook;";
- //
- // sqlInsertCommand1
- //
- this.sqlInsertCommand1.CommandText = @"INSERT INTO 物料清单(父项编号, 物料编号, 需要数量, 领料车间, 领料库房, 损耗率, bom状态, bom信息状态, 审核者, 审核日期, 其它事项, 低层码, 展开标记) VALUES (@父项编号, @物料编号, @需要数量, @领料车间, @领料库房, @损耗率, @bom状态, @bom信息状态, @审核者, @审核日期, @其它事项, @低层码, @展开标记); SELECT 父项编号, 物料编号, 需要数量, 领料车间, 领料库房, 损耗率, bom状态, bom信息状态, 审核者, 审核日期, 其它事项, 低层码, 展开标记 FROM 物料清单 WHERE (父项编号 = @父项编号) AND (物料编号 = @物料编号)";
- this.sqlInsertCommand1.Connection = this.sqlConnection1;
- this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@父项编号", System.Data.SqlDbType.VarChar, 14, "父项编号"));
- this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@物料编号", System.Data.SqlDbType.VarChar, 14, "物料编号"));
- this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@需要数量", System.Data.SqlDbType.Decimal, 9, System.Data.ParameterDirection.Input, false, ((System.Byte)(18)), ((System.Byte)(4)), "需要数量", System.Data.DataRowVersion.Current, null));
- this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@领料车间", System.Data.SqlDbType.VarChar, 10, "领料车间"));
- this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@领料库房", System.Data.SqlDbType.VarChar, 10, "领料库房"));
- this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@损耗率", System.Data.SqlDbType.Decimal, 5, System.Data.ParameterDirection.Input, false, ((System.Byte)(5)), ((System.Byte)(4)), "损耗率", System.Data.DataRowVersion.Current, null));
- this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@bom状态", System.Data.SqlDbType.VarChar, 1, "bom状态"));
- this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@bom信息状态", System.Data.SqlDbType.VarChar, 1, "bom信息状态"));
- this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@审核者", System.Data.SqlDbType.VarChar, 8, "审核者"));
- this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@审核日期", System.Data.SqlDbType.Int, 4, "审核日期"));
- this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@其它事项", System.Data.SqlDbType.VarChar, 2147483647, "其它事项"));
- this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@低层码", System.Data.SqlDbType.Int, 4, "低层码"));
- this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@展开标记", System.Data.SqlDbType.Bit, 1, "展开标记"));
- //
- // sqlSelectCommand1
- //
- this.sqlSelectCommand1.CommandText = "SELECT 父项编号, 物料编号, 需要数量, 领料车间, 领料库房, 损耗率, bom状态, bom信息状态, 审核者, 审核日期, 其它事项, 低层码, 展" +
- "开标记 FROM 物料清单";
- this.sqlSelectCommand1.Connection = this.sqlConnection1;
- //
- // sqlUpdateCommand1
- //
- this.sqlUpdateCommand1.CommandText = @"UPDATE 物料清单 SET 父项编号 = @父项编号, 物料编号 = @物料编号, 需要数量 = @需要数量, 领料车间 = @领料车间, 领料库房 = @领料库房, 损耗率 = @损耗率, bom状态 = @bom状态, bom信息状态 = @bom信息状态, 审核者 = @审核者, 审核日期 = @审核日期, 其它事项 = @其它事项, 低层码 = @低层码, 展开标记 = @展开标记 WHERE (父项编号 = @Original_父项编号) AND (物料编号 = @Original_物料编号) AND (bom信息状态 = @Original_bom信息状态 OR @Original_bom信息状态 IS NULL AND bom信息状态 IS NULL) AND (bom状态 = @Original_bom状态 OR @Original_bom状态 IS NULL AND bom状态 IS NULL) AND (低层码 = @Original_低层码 OR @Original_低层码 IS NULL AND 低层码 IS NULL) AND (审核日期 = @Original_审核日期 OR @Original_审核日期 IS NULL AND 审核日期 IS NULL) AND (审核者 = @Original_审核者 OR @Original_审核者 IS NULL AND 审核者 IS NULL) AND (展开标记 = @Original_展开标记 OR @Original_展开标记 IS NULL AND 展开标记 IS NULL) AND (损耗率 = @Original_损耗率 OR @Original_损耗率 IS NULL AND 损耗率 IS NULL) AND (需要数量 = @Original_需要数量) AND (领料库房 = @Original_领料库房 OR @Original_领料库房 IS NULL AND 领料库房 IS NULL) AND (领料车间 = @Original_领料车间 OR @Original_领料车间 IS NULL AND 领料车间 IS NULL); SELECT 父项编号, 物料编号, 需要数量, 领料车间, 领料库房, 损耗率, bom状态, bom信息状态, 审核者, 审核日期, 其它事项, 低层码, 展开标记 FROM 物料清单 WHERE (父项编号 = @父项编号) AND (物料编号 = @物料编号)";
- this.sqlUpdateCommand1.Connection = this.sqlConnection1;
- this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@父项编号", System.Data.SqlDbType.VarChar, 14, "父项编号"));
- this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@物料编号", System.Data.SqlDbType.VarChar, 14, "物料编号"));
- this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@需要数量", System.Data.SqlDbType.Decimal, 9, System.Data.ParameterDirection.Input, false, ((System.Byte)(18)), ((System.Byte)(4)), "需要数量", System.Data.DataRowVersion.Current, null));
- this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@领料车间", System.Data.SqlDbType.VarChar, 10, "领料车间"));
- this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@领料库房", System.Data.SqlDbType.VarChar, 10, "领料库房"));
- this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@损耗率", System.Data.SqlDbType.Decimal, 5, System.Data.ParameterDirection.Input, false, ((System.Byte)(5)), ((System.Byte)(4)), "损耗率", System.Data.DataRowVersion.Current, null));
- this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@bom状态", System.Data.SqlDbType.VarChar, 1, "bom状态"));
- this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@bom信息状态", System.Data.SqlDbType.VarChar, 1, "bom信息状态"));
- this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@审核者", System.Data.SqlDbType.VarChar, 8, "审核者"));
- this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@审核日期", System.Data.SqlDbType.Int, 4, "审核日期"));
- this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@其它事项", System.Data.SqlDbType.VarChar, 2147483647, "其它事项"));
- this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@低层码", System.Data.SqlDbType.Int, 4, "低层码"));
- this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@展开标记", System.Data.SqlDbType.Bit, 1, "展开标记"));
- this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_父项编号", System.Data.SqlDbType.VarChar, 14, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "父项编号", System.Data.DataRowVersion.Original, null));
- this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_物料编号", System.Data.SqlDbType.VarChar, 14, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "物料编号", System.Data.DataRowVersion.Original, null));
- this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_bom信息状态", System.Data.SqlDbType.VarChar, 1, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "bom信息状态", System.Data.DataRowVersion.Original, null));
- this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_bom状态", System.Data.SqlDbType.VarChar, 1, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "bom状态", System.Data.DataRowVersion.Original, null));
- this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_低层码", System.Data.SqlDbType.Int, 4, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "低层码", System.Data.DataRowVersion.Original, null));
- this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_审核日期", System.Data.SqlDbType.Int, 4, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "审核日期", System.Data.DataRowVersion.Original, null));
- this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_审核者", System.Data.SqlDbType.VarChar, 8, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "审核者", System.Data.DataRowVersion.Original, null));
- this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_展开标记", System.Data.SqlDbType.Bit, 1, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "展开标记", System.Data.DataRowVersion.Original, null));
- this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_损耗率", System.Data.SqlDbType.Decimal, 5, System.Data.ParameterDirection.Input, false, ((System.Byte)(5)), ((System.Byte)(4)), "损耗率", System.Data.DataRowVersion.Original, null));
- this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_需要数量", System.Data.SqlDbType.Decimal, 9, System.Data.ParameterDirection.Input, false, ((System.Byte)(18)), ((System.Byte)(4)), "需要数量", System.Data.DataRowVersion.Original, null));
- this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_领料库房", System.Data.SqlDbType.VarChar, 10, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "领料库房", System.Data.DataRowVersion.Original, null));
- this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_领料车间", System.Data.SqlDbType.VarChar, 10, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "领料车间", System.Data.DataRowVersion.Original, null));
- //
- // toolBar1
- //
- this.toolBar1.Buttons.AddRange(new System.Windows.Forms.ToolBarButton[] {
- this.tBtnNew,
- this.tBtnEdit,
- this.tBtnDelete,
- this.tBtnSubmit,
- this.tBtnCancel,
- this.tBtnQuit});
- this.toolBar1.DropDownArrows = true;
- this.toolBar1.ImageList = this.imageList1;
- this.toolBar1.Location = new System.Drawing.Point(0, 0);
- this.toolBar1.Name = "toolBar1";
- this.toolBar1.ShowToolTips = true;
- this.toolBar1.Size = new System.Drawing.Size(600, 41);
- this.toolBar1.TabIndex = 26;
- this.toolBar1.ButtonClick += new System.Windows.Forms.ToolBarButtonClickEventHandler(this.toolBar1_ButtonClick);
- //
- // tBtnNew
- //
- this.tBtnNew.ImageIndex = 4;
- this.tBtnNew.Text = "新增";
- this.tBtnNew.ToolTipText = "新增";
- //
- // tBtnEdit
- //
- this.tBtnEdit.ImageIndex = 5;
- this.tBtnEdit.Text = "修改";
- this.tBtnEdit.ToolTipText = "修改";
- //
- // tBtnDelete
- //
- this.tBtnDelete.ImageIndex = 6;
- this.tBtnDelete.Text = "删除";
- this.tBtnDelete.ToolTipText = "删除";
- //
- // tBtnSubmit
- //
- this.tBtnSubmit.ImageIndex = 7;
- this.tBtnSubmit.Text = "提交";
- this.tBtnSubmit.ToolTipText = "提交";
- //
- // tBtnCancel
- //
- this.tBtnCancel.ImageIndex = 8;
- this.tBtnCancel.Text = "取消";
- this.tBtnCancel.ToolTipText = "取消";
- //
- // tBtnQuit
- //
- this.tBtnQuit.ImageIndex = 9;
- this.tBtnQuit.Text = "退出";
- this.tBtnQuit.ToolTipText = "退出";
- //
- // imageList1
- //
- this.imageList1.ImageSize = new System.Drawing.Size(16, 16);
- this.imageList1.ImageStream = ((System.Windows.Forms.ImageListStreamer)(resources.GetObject("imageList1.ImageStream")));
- this.imageList1.TransparentColor = System.Drawing.SystemColors.ControlLightLight;
- //
- // groupBox1
- //
- this.groupBox1.Controls.Add(this.selBtn1);
- this.groupBox1.Controls.Add(this.label1);
- this.groupBox1.Controls.Add(this.txt1);
- this.groupBox1.Controls.Add(this.txt2);
- this.groupBox1.Controls.Add(this.txt4);
- this.groupBox1.Controls.Add(this.txt3);
- this.groupBox1.Controls.Add(this.txt6);
- this.groupBox1.Controls.Add(this.txt5);
- this.groupBox1.Controls.Add(this.txt8);
- this.groupBox1.Controls.Add(this.txt7);
- this.groupBox1.Controls.Add(this.txt9);
- this.groupBox1.Controls.Add(this.txt10);
- this.groupBox1.Controls.Add(this.label2);
- this.groupBox1.Controls.Add(this.label3);
- this.groupBox1.Controls.Add(this.label4);
- this.groupBox1.Controls.Add(this.label5);
- this.groupBox1.Controls.Add(this.label6);
- this.groupBox1.Controls.Add(this.label7);
- this.groupBox1.Controls.Add(this.label8);
- this.groupBox1.Controls.Add(this.label9);
- this.groupBox1.Controls.Add(this.label10);
- this.groupBox1.Location = new System.Drawing.Point(200, 48);
- this.groupBox1.Name = "groupBox1";
- this.groupBox1.Size = new System.Drawing.Size(384, 392);
- this.groupBox1.TabIndex = 27;
- this.groupBox1.TabStop = false;
- this.groupBox1.Text = "物料详细信息";
- //
- // selBtn1
- //
- this.selBtn1.Enabled = false;
- this.selBtn1.Image = ((System.Drawing.Image)(resources.GetObject("selBtn1.Image")));
- this.selBtn1.Location = new System.Drawing.Point(176, 72);
- this.selBtn1.Name = "selBtn1";
- this.selBtn1.Size = new System.Drawing.Size(24, 23);
- this.selBtn1.TabIndex = 51;
- this.selBtn1.Click += new System.EventHandler(this.selBtn1_Click);
- this.selBtn1.MouseUp += new System.Windows.Forms.MouseEventHandler(this.selBtn1_MouseUp);
- //
- // label1
- //
- this.label1.Location = new System.Drawing.Point(70, 48);
- this.label1.Name = "label1";
- this.label1.Size = new System.Drawing.Size(100, 16);
- this.label1.TabIndex = 44;
- this.label1.Text = "物料编号";
- //
- // txt1
- //
- this.txt1.Location = new System.Drawing.Point(70, 72);
- this.txt1.Name = "txt1";
- this.txt1.ReadOnly = true;
- this.txt1.TabIndex = 35;
- this.txt1.Text = "";
- //
- // txt2
- //
- this.txt2.Location = new System.Drawing.Point(208, 72);
- this.txt2.Name = "txt2";
- this.txt2.ReadOnly = true;
- this.txt2.TabIndex = 34;
- this.txt2.Text = "";
- //
- // txt4
- //
- this.txt4.Location = new System.Drawing.Point(208, 128);
- this.txt4.Name = "txt4";
- this.txt4.ReadOnly = true;
- this.txt4.TabIndex = 37;
- this.txt4.Text = "";
- //
- // txt3
- //
- this.txt3.Location = new System.Drawing.Point(70, 128);
- this.txt3.Name = "txt3";
- this.txt3.ReadOnly = true;
- this.txt3.TabIndex = 36;
- this.txt3.Text = "";
- //
- // txt6
- //
- this.txt6.Location = new System.Drawing.Point(144, 176);
- this.txt6.Name = "txt6";
- this.txt6.ReadOnly = true;
- this.txt6.Size = new System.Drawing.Size(64, 21);
- this.txt6.TabIndex = 33;
- this.txt6.Text = "";
- //
- // txt5
- //
- this.txt5.Location = new System.Drawing.Point(72, 176);
- this.txt5.Name = "txt5";
- this.txt5.ReadOnly = true;
- this.txt5.Size = new System.Drawing.Size(64, 21);
- this.txt5.TabIndex = 29;
- this.txt5.Text = "";
- //
- // txt8
- //
- this.txt8.Location = new System.Drawing.Point(208, 224);
- this.txt8.Name = "txt8";
- this.txt8.ReadOnly = true;
- this.txt8.Size = new System.Drawing.Size(104, 21);
- this.txt8.TabIndex = 28;
- this.txt8.Text = "";
- //
- // txt7
- //
- this.txt7.Location = new System.Drawing.Point(72, 224);
- this.txt7.Name = "txt7";
- this.txt7.ReadOnly = true;
- this.txt7.Size = new System.Drawing.Size(112, 21);
- this.txt7.TabIndex = 30;
- this.txt7.Text = "";
- //
- // txt9
- //
- this.txt9.Location = new System.Drawing.Point(212, 176);
- this.txt9.Name = "txt9";
- this.txt9.ReadOnly = true;
- this.txt9.Size = new System.Drawing.Size(96, 21);
- this.txt9.TabIndex = 32;
- this.txt9.Text = "";
- //
- // txt10
- //
- this.txt10.Location = new System.Drawing.Point(72, 280);
- this.txt10.Name = "txt10";
- this.txt10.ReadOnly = true;
- this.txt10.Size = new System.Drawing.Size(240, 21);
- this.txt10.TabIndex = 31;
- this.txt10.Text = "";
- //
- // label2
- //
- this.label2.Location = new System.Drawing.Point(208, 48);
- this.label2.Name = "label2";
- this.label2.Size = new System.Drawing.Size(100, 16);
- this.label2.TabIndex = 43;
- this.label2.Text = "物料名称";
- //
- // label3
- //
- this.label3.Location = new System.Drawing.Point(70, 112);
- this.label3.Name = "label3";
- this.label3.Size = new System.Drawing.Size(100, 16);
- this.label3.TabIndex = 45;
- this.label3.Text = "父项编号";
- //
- // label4
- //
- this.label4.Location = new System.Drawing.Point(208, 112);
- this.label4.Name = "label4";
- this.label4.Size = new System.Drawing.Size(100, 16);
- this.label4.TabIndex = 47;
- this.label4.Text = "父项名称";
- //
- // label5
- //
- this.label5.Location = new System.Drawing.Point(72, 160);
- this.label5.Name = "label5";
- this.label5.Size = new System.Drawing.Size(64, 16);
- this.label5.TabIndex = 46;
- this.label5.Text = "需要数量";
- //
- // label6
- //
- this.label6.Location = new System.Drawing.Point(144, 160);
- this.label6.Name = "label6";
- this.label6.Size = new System.Drawing.Size(48, 16);
- this.label6.TabIndex = 39;
- this.label6.Text = "低层码";
- //
- // label7
- //
- this.label7.Location = new System.Drawing.Point(72, 208);
- this.label7.Name = "label7";
- this.label7.Size = new System.Drawing.Size(72, 16);
- this.label7.TabIndex = 38;
- this.label7.Text = "领料车间";
- //
- // label8
- //
- this.label8.Location = new System.Drawing.Point(208, 208);
- this.label8.Name = "label8";
- this.label8.Size = new System.Drawing.Size(100, 16);
- this.label8.TabIndex = 40;
- this.label8.Text = "领料库房";
- //
- // label9
- //
- this.label9.Location = new System.Drawing.Point(216, 160);
- this.label9.Name = "label9";
- this.label9.Size = new System.Drawing.Size(72, 16);
- this.label9.TabIndex = 42;
- this.label9.Text = "审核日期";
- //
- // label10
- //
- this.label10.Location = new System.Drawing.Point(72, 256);
- this.label10.Name = "label10";
- this.label10.Size = new System.Drawing.Size(100, 16);
- this.label10.TabIndex = 41;
- this.label10.Text = "其他事项";
- //
- // BomForm
- //
- this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
- this.ClientSize = new System.Drawing.Size(600, 445);
- this.Controls.Add(this.groupBox1);
- this.Controls.Add(this.treeView1);
- this.Controls.Add(this.toolBar1);
- this.Name = "BomForm";
- this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
- this.Text = "【物料清单BOM】";
- this.Load += new System.EventHandler(this.BomForm_Load);
- this.groupBox1.ResumeLayout(false);
- this.ResumeLayout(false);
- }
- #endregion
- //-------------创建窗体时,显示树形图的BOM表------------
- private void BomForm_Load(object sender, System.EventArgs e)
- {
- this.ShowTree();//将BOM表用树形图的方式显示出来
- }
- //-------------读入数据并准备显示树形图-----------------
- private void ShowTree()
- {
- tblBom.Clear();
- this.sqlDataAdapter1.Fill(tblBom);//读入数据
- //DataTable tempDataTable = tblBom.Copy();//将组织机构表另存一份为tempDataTable
- DataView viewBom = new DataView(tblBom);//新建一个数据视图
- viewBom.RowFilter="低层码=0";
- //将数据集中的所有记录逐个根据他们之间的关系添加到树形表中去
- if (viewBom.Count > 0)
- {
- int i=0;//由于低层码为0的产品可能不止一个,因此设置序号,以便准确定位父项
- foreach (DataRowView myRow in viewBom)
- {
- string strName = myRow["物料编号"].ToString().Trim()+SetNodeName(myRow["物料编号"].ToString().Trim());
- //此处是添加前面头两个节点
- this.treeView1.Nodes.Add(new TreeNode(strName));
- //此处初始化参数是第一个节点,然后该函数会递归添加所有子节点
- PopulateTreeView(strName,treeView1.Nodes[i],myRow);
- i++;
- treeView1.SelectedNode = treeView1.Nodes[0]; //选中第一个节点
- }
- }
- }
- //---------根据输入的节点信息,递归调用最终添加所有的节点-----------------------
- private void PopulateTreeView(string parentPart,TreeNode parentNode,DataRowView parentRow)
- {
- string strName = "";
- DataTable tempDataTable = tblBom.Copy();
- DataView viewBom = new DataView(tempDataTable);
- //筛选获得当前传递过来的节点的子项,并将其添加到树形图中
- //判断方法是:凡父项编号等于传递过来的节点的物料编号的,就是该节点的子项
- viewBom.RowFilter = "父项编号 = '" + parentRow["物料编号"].ToString().Trim() + "'";
- //递归的添加每一个节点的所有子节点
- foreach (DataRowView myRow in viewBom)
- {
- strName = myRow["物料编号"].ToString().Trim()+SetNodeName(myRow["物料编号"].ToString().Trim());
- TreeNode myNode = new TreeNode(strName);
- parentNode.Nodes.Add(myNode);
- //函数递归调用,将所有节点按顺序添加完毕
- PopulateTreeView(strName,myNode,myRow);
- }
- }
- //---------根据物料编号,查找其名称----------
- private string SetNodeName(string materialID)
- {
- string strConn = "server=localhost;Integrated Security=SSPI;database=mrpbook";
- SqlConnection cn=new SqlConnection(strConn);
- cn.Open();
- SqlCommand cmd=cn.CreateCommand();
- cmd.CommandText="select 物料名称 from 物料主文件 where 物料编号='"+materialID+"'";
- return(cmd.ExecuteScalar().ToString().Trim());
- }
- //-----------将所选节点中的物料名称和编号分别提取出来-------------
- private string[] GetNodeInfo(string inputStr)
- {
- int i;
- string str1,str2;
- str1="";
- str2="";
- int length=inputStr.Length;
- char[] chars=inputStr.ToCharArray(0,length);
- for(i=0;i<length;i++)
- {
- char ch=chars[i];
- if(ch>='0'&&ch<='9')
- str1+=ch.ToString();
- else
- str2+=ch.ToString();
- }
- string[] resultStr = {str1,str2};
- return(resultStr);
- }
- //-----------------在树形图中选择一个节点,显示其详细信息----------------
- private void treeView1_AfterSelect(object sender, System.Windows.Forms.TreeViewEventArgs e)
- {
- string[] thisNodeInfo=GetNodeInfo(e.Node.Text);//显示当前节点信息
- txt1.Text=thisNodeInfo[0];
- txt2.Text=thisNodeInfo[1];
- if(e.Node.Parent!=null)//显示主节点信息
- {
- string[] parentNodeInfo=GetNodeInfo(e.Node.Parent.Text);
- txt3.Text=parentNodeInfo[0];
- txt4.Text=parentNodeInfo[1];
- }
- else
- {
- txt3.Text="0";//顶层两个节点父项编号是0
- txt4.Text="顶级节点无父节点";
- }
- string strConn = "server=localhost;Integrated Security=SSPI;database=mrpbook";
- SqlConnection cn=new SqlConnection(strConn);
- cn.Open();
- SqlCommand cmd=cn.CreateCommand();
- cmd.CommandText="select 需要数量,低层码,领料车间,领料库房,损耗率,审核日期,其它事项 from 物料清单 where (物料编号='"+txt1.Text+"')and(父项编号='"+txt3.Text+"')";
- SqlDataReader dr=cmd.ExecuteReader();
- dr.Read();
- txt5.Text=dr.GetValue(0).ToString().Trim();//保存需要数量
- txt6.Text=dr.GetValue(1).ToString().Trim();//保存低层码
- txt7.Text=dr.GetValue(2).ToString().Trim();//保存领料车间
- txt8.Text=dr.GetValue(3).ToString().Trim();//保存损耗率
- txt9.Text=dr.GetValue(4).ToString().Trim();//保存审核日期
- txt10.Text=dr.GetValue(5).ToString().Trim();//保存其它事项
- }
- //---------------设置工具栏操作--------------
- private void toolBar1_ButtonClick(object sender, System.Windows.Forms.ToolBarButtonClickEventArgs e)
- {
- if(treeView1.SelectedNode==null)//若未选中任何节点,则不做任何动作
- {
- return;
- }
- string strConn = "server=localhost;Integrated Security=SSPI;database=mrpbook";
- SqlConnection cn=new SqlConnection(strConn);
- cn.Open();
- SqlCommand cmd=cn.CreateCommand();
- if(e.Button.ToolTipText=="新增")//增加选中节点的子项
- {
- SetModifyMode(true);//允许选择文本框进行编辑
- selBtn1.Enabled=true;
- txt3.Text=txt1.Text;//当前节点成为新节点的父节点
- txt4.Text=txt2.Text;
- txt1.Clear();//清除原有数据并设置默认值
- txt2.Clear();
- txt5.Text="0";//默认需要数量为0
- int newOrder=Convert.ToInt32(txt6.Text.Trim())+1;
- txt6.Text=newOrder.ToString();
- txt7.Clear();
- txt8.Clear();
- txt9.Clear();
- txt10.Clear();
- curStatus=1;//标识现在是新增状态
- }
- if(e.Button.ToolTipText=="修改")
- {
- SetModifyMode(true);
- txt1.ReadOnly=true;//修改时不允许修改物料编号
- selBtn1.Enabled=false;
- curStatus=2;//表示现在是编辑状态
- }
- if(e.Button.ToolTipText=="删除")
- {
- if(treeView1.SelectedNode.LastNode!=null)
- MessageBox.Show("请先删除该节点的所有子节点","提示",MessageBoxButtons.OK,MessageBoxIcon.Warning);
- else
- {
- DialogResult result=MessageBox.Show("确认删除?","删除数据",MessageBoxButtons.OKCancel);
- if(result==DialogResult.OK)
- {
- cmd.CommandText="delete from 物料清单 where (物料编号='"+txt1.Text+"')and(父项编号='"+txt3.Text+"')";
- cmd.ExecuteNonQuery();
- treeView1.Nodes.Clear();
- ShowTree();//重新绘制树形图
- }
- }
- }
- if(e.Button.ToolTipText=="提交")
- {
- if(curStatus==0)//非新增,编辑状态,不作操作
- return;
- if(curStatus==1)//新增状态
- {
- cmd.CommandText="insert into 物料清单([父项编号], [物料编号], [需要数量], [领料车间],"+
- "[领料库房], [审核日期], [其它事项],[低层码]) "+
- "values('"+txt3.Text+"','"+txt1.Text+"','"+txt5.Text+"','"+txt7.Text+"','"+
- txt8.Text+"','"+txt9.Text+"','"+txt10.Text+"','"+txt6.Text+"')";
- cmd.ExecuteNonQuery();
- curStatus=0;//恢复普通状态
- SetModifyMode(false);
- treeView1.Nodes.Clear();
- ShowTree();//重新绘制树形图
- }
- if(curStatus==2)//编辑状态
- {
- cmd.CommandText="update 物料清单 set 需要数量='"+txt5.Text+"',领料车间='"+txt7.Text
- +"',领料库房='"+txt8.Text+"',审核日期='"+txt9.Text+"',其它事项='"+txt10.Text+"'"
- +" where (物料编号='"+txt1.Text+"')and(父项编号='"+txt3.Text+"')";
- cmd.ExecuteNonQuery();
- curStatus=0;//恢复普通状态
- SetModifyMode(false);
- treeView1.Nodes.Clear();
- ShowTree();//重新绘制树形图
- }
- }
- if (e.Button.ToolTipText == "取消")
- {
- treeView1.SelectedNode=treeView1.Nodes[0];//默认选中首项
- SetModifyMode(false);
- }
- if(e.Button.ToolTipText=="退出")
- {
- this.Close();
- }
- }
- //--------------对控件的ReadOnly属性做设置---------------
- private void SetModifyMode(bool blnModify)
- {
- //设置文本框
- txt1.ReadOnly=!blnModify;
- txt5.ReadOnly=!blnModify;
- txt7.ReadOnly=!blnModify;
- txt8.ReadOnly=!blnModify;
- txt9.ReadOnly=!blnModify;
- txt10.ReadOnly=!blnModify;
- //允许使用选择按钮
- selBtn1.Enabled=blnModify;
- }
- //------------调出窗体,选择物料--------------
- private void selBtn1_Click(object sender, System.EventArgs e)
- {
- SelectMaterial.callForm=3;
- SelectMaterial selFrm=new SelectMaterial();
- selFrm.ShowDialog();
- SendKeys.Send("{Tab}");//向活动应用程序发送Tab键,跳到下一控件
- }
- //---------将选择得到的物料编号和名称填入文本框----------
- private void selBtn1_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e)
- {
- txt1.Text=mID;
- txt2.Text=mName;
- SendKeys.Send("{Tab}");
- }
- }
- }