MRPCal.cs
上传用户:hjieqiu
上传日期:2013-05-11
资源大小:16494k
文件大小:15k
- using System;
- using System.Drawing;
- using System.Collections;
- using System.ComponentModel;
- using System.Windows.Forms;
- using System.Data.SqlClient;
- namespace 生产管理系统
- {
- /// <summary>
- /// MRPCal 的摘要说明。
- /// </summary>
- public class MRPCal : System.Windows.Forms.Form
- {
- private System.Windows.Forms.GroupBox groupBox1;
- private System.Windows.Forms.GroupBox groupBox2;
- private System.Windows.Forms.GroupBox groupBox3;
- private System.Windows.Forms.CheckBox checkBox1;
- private System.Windows.Forms.CheckBox checkBox2;
- private System.Windows.Forms.CheckBox checkBox3;
- private System.Windows.Forms.Button btnCal;
- private System.Windows.Forms.Button btnRelease;
- private System.Windows.Forms.DataGrid dataGrid1;
- private System.Windows.Forms.DataGrid dataGrid2;
- private System.Data.SqlClient.SqlDataAdapter da1;
- private System.Data.SqlClient.SqlCommand sqlSelectCommand1;
- private System.Data.SqlClient.SqlConnection sqlConnection1;
- private System.Data.SqlClient.SqlDataAdapter da2;
- private System.Data.SqlClient.SqlCommand sqlSelectCommand2;
- private 生产管理系统.DataSet3 dataSet31;
- /// <summary>
- /// 必需的设计器变量。
- /// </summary>
- private System.ComponentModel.Container components = null;
- public MRPCal()
- {
- //
- // 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()
- {
- System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(MRPCal));
- this.groupBox1 = new System.Windows.Forms.GroupBox();
- this.btnRelease = new System.Windows.Forms.Button();
- this.btnCal = new System.Windows.Forms.Button();
- this.checkBox3 = new System.Windows.Forms.CheckBox();
- this.checkBox2 = new System.Windows.Forms.CheckBox();
- this.checkBox1 = new System.Windows.Forms.CheckBox();
- this.groupBox2 = new System.Windows.Forms.GroupBox();
- this.dataGrid1 = new System.Windows.Forms.DataGrid();
- this.dataSet31 = new 生产管理系统.DataSet3();
- this.groupBox3 = new System.Windows.Forms.GroupBox();
- this.dataGrid2 = new System.Windows.Forms.DataGrid();
- this.da1 = new System.Data.SqlClient.SqlDataAdapter();
- this.sqlSelectCommand1 = new System.Data.SqlClient.SqlCommand();
- this.sqlConnection1 = new System.Data.SqlClient.SqlConnection();
- this.da2 = new System.Data.SqlClient.SqlDataAdapter();
- this.sqlSelectCommand2 = new System.Data.SqlClient.SqlCommand();
- this.groupBox1.SuspendLayout();
- this.groupBox2.SuspendLayout();
- ((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).BeginInit();
- ((System.ComponentModel.ISupportInitialize)(this.dataSet31)).BeginInit();
- this.groupBox3.SuspendLayout();
- ((System.ComponentModel.ISupportInitialize)(this.dataGrid2)).BeginInit();
- this.SuspendLayout();
- //
- // groupBox1
- //
- this.groupBox1.Controls.Add(this.btnRelease);
- this.groupBox1.Controls.Add(this.btnCal);
- this.groupBox1.Controls.Add(this.checkBox3);
- this.groupBox1.Controls.Add(this.checkBox2);
- this.groupBox1.Controls.Add(this.checkBox1);
- this.groupBox1.Location = new System.Drawing.Point(0, 8);
- this.groupBox1.Name = "groupBox1";
- this.groupBox1.Size = new System.Drawing.Size(632, 80);
- this.groupBox1.TabIndex = 0;
- this.groupBox1.TabStop = false;
- this.groupBox1.Text = "计算参数";
- //
- // btnRelease
- //
- this.btnRelease.Enabled = false;
- this.btnRelease.Image = ((System.Drawing.Image)(resources.GetObject("btnRelease.Image")));
- this.btnRelease.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
- this.btnRelease.Location = new System.Drawing.Point(520, 40);
- this.btnRelease.Name = "btnRelease";
- this.btnRelease.Size = new System.Drawing.Size(96, 23);
- this.btnRelease.TabIndex = 4;
- this.btnRelease.Text = "结果发布";
- this.btnRelease.Click += new System.EventHandler(this.btnRelease_Click);
- //
- // btnCal
- //
- this.btnCal.Image = ((System.Drawing.Image)(resources.GetObject("btnCal.Image")));
- this.btnCal.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
- this.btnCal.Location = new System.Drawing.Point(416, 40);
- this.btnCal.Name = "btnCal";
- this.btnCal.TabIndex = 3;
- this.btnCal.Text = "计算";
- this.btnCal.Click += new System.EventHandler(this.btnCal_Click);
- //
- // checkBox3
- //
- this.checkBox3.Location = new System.Drawing.Point(304, 32);
- this.checkBox3.Name = "checkBox3";
- this.checkBox3.Size = new System.Drawing.Size(80, 24);
- this.checkBox3.TabIndex = 2;
- this.checkBox3.Text = "考虑损耗";
- //
- // checkBox2
- //
- this.checkBox2.Location = new System.Drawing.Point(176, 32);
- this.checkBox2.Name = "checkBox2";
- this.checkBox2.TabIndex = 1;
- this.checkBox2.Text = "考虑提前期";
- //
- // checkBox1
- //
- this.checkBox1.Checked = true;
- this.checkBox1.CheckState = System.Windows.Forms.CheckState.Checked;
- this.checkBox1.Location = new System.Drawing.Point(24, 28);
- this.checkBox1.Name = "checkBox1";
- this.checkBox1.Size = new System.Drawing.Size(120, 32);
- this.checkBox1.TabIndex = 0;
- this.checkBox1.Text = "考虑库存,生产和采购订单";
- //
- // groupBox2
- //
- this.groupBox2.Controls.Add(this.dataGrid1);
- this.groupBox2.Location = new System.Drawing.Point(0, 96);
- this.groupBox2.Name = "groupBox2";
- this.groupBox2.Size = new System.Drawing.Size(640, 168);
- this.groupBox2.TabIndex = 1;
- this.groupBox2.TabStop = false;
- this.groupBox2.Text = "主生产计划";
- //
- // dataGrid1
- //
- this.dataGrid1.CaptionVisible = false;
- this.dataGrid1.DataMember = "主生产计划";
- this.dataGrid1.DataSource = this.dataSet31;
- this.dataGrid1.HeaderForeColor = System.Drawing.SystemColors.ControlText;
- this.dataGrid1.Location = new System.Drawing.Point(8, 24);
- this.dataGrid1.Name = "dataGrid1";
- this.dataGrid1.ReadOnly = true;
- this.dataGrid1.Size = new System.Drawing.Size(624, 136);
- this.dataGrid1.TabIndex = 0;
- //
- // dataSet31
- //
- this.dataSet31.DataSetName = "DataSet3";
- this.dataSet31.Locale = new System.Globalization.CultureInfo("zh-CN");
- //
- // groupBox3
- //
- this.groupBox3.Controls.Add(this.dataGrid2);
- this.groupBox3.Location = new System.Drawing.Point(0, 264);
- this.groupBox3.Name = "groupBox3";
- this.groupBox3.Size = new System.Drawing.Size(640, 224);
- this.groupBox3.TabIndex = 2;
- this.groupBox3.TabStop = false;
- this.groupBox3.Text = "MRP计算结果(物料需求)";
- //
- // dataGrid2
- //
- this.dataGrid2.CaptionVisible = false;
- this.dataGrid2.DataMember = "mrp物料需求计算";
- this.dataGrid2.DataSource = this.dataSet31;
- this.dataGrid2.HeaderForeColor = System.Drawing.SystemColors.ControlText;
- this.dataGrid2.Location = new System.Drawing.Point(8, 16);
- this.dataGrid2.Name = "dataGrid2";
- this.dataGrid2.ReadOnly = true;
- this.dataGrid2.Size = new System.Drawing.Size(624, 200);
- this.dataGrid2.TabIndex = 1;
- //
- // da1
- //
- this.da1.SelectCommand = this.sqlSelectCommand1;
- this.da1.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("结束日期", "结束日期"),
- new System.Data.Common.DataColumnMapping("期初库存", "期初库存"),
- new System.Data.Common.DataColumnMapping("需求数量", "需求数量"),
- new System.Data.Common.DataColumnMapping("MPS数量", "MPS数量"),
- 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("备注", "备注")})});
- //
- // sqlSelectCommand1
- //
- this.sqlSelectCommand1.CommandText = "SELECT b.物料名称, a.物料编号, a.编号, a.年份, a.计划期, a.开始日期, a.结束日期, a.期初库存, a.需求数量, a.MPS数量" +
- ", a.生产单数量, a.预计库存, a.记帐人, a.修改日期, a.审核人, a.审核日期, a.状态, a.备注 FROM 主生产计划 a INNER J" +
- "OIN 物料主文件 b ON a.物料编号 = b.物料编号";
- this.sqlSelectCommand1.Connection = this.sqlConnection1;
- //
- // sqlConnection1
- //
- this.sqlConnection1.ConnectionString = "workstation id=localhost;Integrated Security=SSPI;Database=mrpbook;";
- //
- // da2
- //
- this.da2.SelectCommand = this.sqlSelectCommand2;
- this.da2.TableMappings.AddRange(new System.Data.Common.DataTableMapping[] {
- new System.Data.Common.DataTableMapping("Table", "mrp物料需求计算", 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("预计入库", "预计入库"),
- 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("计划投入", "计划投入")})});
- //
- // sqlSelectCommand2
- //
- this.sqlSelectCommand2.CommandText = "SELECT b.物料名称, a.物料编号, a.年份, a.计划期, a.期初库存, a.毛需求, a.预计入库, a.预计出库, a.预计库存, a.净需求," +
- " a.计划产出, a.计划投入 FROM mrp物料需求计算 a INNER JOIN 物料主文件 b ON a.物料编号 = b.物料编号";
- this.sqlSelectCommand2.Connection = this.sqlConnection1;
- //
- // MRPCal
- //
- this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
- this.ClientSize = new System.Drawing.Size(648, 493);
- this.Controls.Add(this.groupBox3);
- this.Controls.Add(this.groupBox2);
- this.Controls.Add(this.groupBox1);
- this.Name = "MRPCal";
- this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
- this.Text = "【MRP计算】";
- this.Load += new System.EventHandler(this.MRPCal_Load);
- this.groupBox1.ResumeLayout(false);
- this.groupBox2.ResumeLayout(false);
- ((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).EndInit();
- ((System.ComponentModel.ISupportInitialize)(this.dataSet31)).EndInit();
- this.groupBox3.ResumeLayout(false);
- ((System.ComponentModel.ISupportInitialize)(this.dataGrid2)).EndInit();
- this.ResumeLayout(false);
- }
- #endregion
- //----------窗体创建时读入数据-----------
- private void MRPCal_Load(object sender, System.EventArgs e)
- {
- da1.Fill(dataSet31);
-
- }
- //------------计算MPR--------------
- private void btnCal_Click(object sender, System.EventArgs e)
- {
- if(dataSet31.主生产计划.Count==0)//如主生产计划为空,则不做任何操作
- return;
-
- string inStr1="0";//根据选择设置调用储存过程的参数
- string inStr2="0";
- string inStr3="0";
- if(checkBox1.Checked)
- inStr1="1";
- if(checkBox2.Checked)
- inStr2="1";
- if(checkBox3.Checked)
- inStr3="1";
- string strConn = "server=localhost;Integrated Security=SSPI;database=mrpbook";
- SqlConnection cn=new SqlConnection(strConn);
- cn.Open();
- SqlCommand cmd=cn.CreateCommand();
- cmd.CommandText="exec sf_mrp计算 '"+inStr1+"','"+inStr2+"','"+inStr3+"'";
- int exResult=cmd.ExecuteNonQuery();
- if(exResult!=-1)//允许发布MRP计算结果
- {
- MessageBox.Show("MRP计算成功,请发布计算结果");
- dataSet31.Clear();
- da1.Fill(dataSet31);
- da2.Fill(dataSet31);
- btnRelease.Enabled=true;
- }
-
-
- }
- //------------发布MRP计算结果--------------
- private void btnRelease_Click(object sender, System.EventArgs e)
- {
- string strConn = "server=localhost;Integrated Security=SSPI;database=mrpbook";
- SqlConnection cn=new SqlConnection(strConn);
- cn.Open();
- SqlCommand cmd=cn.CreateCommand();
- cmd.CommandText="exec sf_mrp结果发布";
- int exResult=cmd.ExecuteNonQuery();
- if(exResult!=-1)
- {
- dataSet31.Clear();//刷新数据集
- da1.Fill(dataSet31);
- da2.Fill(dataSet31);
- btnRelease.Enabled=false;
- }
- }
- }
- }