MRPCal.cs
上传用户:hjieqiu
上传日期:2013-05-11
资源大小:16494k
文件大小:15k
源码类别:

企业管理

开发平台:

C#

  1. using System;
  2. using System.Drawing;
  3. using System.Collections;
  4. using System.ComponentModel;
  5. using System.Windows.Forms;
  6. using System.Data.SqlClient;
  7. namespace 生产管理系统
  8. {
  9. /// <summary>
  10. /// MRPCal 的摘要说明。
  11. /// </summary>
  12. public class MRPCal : System.Windows.Forms.Form
  13. {
  14. private System.Windows.Forms.GroupBox groupBox1;
  15. private System.Windows.Forms.GroupBox groupBox2;
  16. private System.Windows.Forms.GroupBox groupBox3;
  17. private System.Windows.Forms.CheckBox checkBox1;
  18. private System.Windows.Forms.CheckBox checkBox2;
  19. private System.Windows.Forms.CheckBox checkBox3;
  20. private System.Windows.Forms.Button btnCal;
  21. private System.Windows.Forms.Button btnRelease;
  22. private System.Windows.Forms.DataGrid dataGrid1;
  23. private System.Windows.Forms.DataGrid dataGrid2;
  24. private System.Data.SqlClient.SqlDataAdapter da1;
  25. private System.Data.SqlClient.SqlCommand sqlSelectCommand1;
  26. private System.Data.SqlClient.SqlConnection sqlConnection1;
  27. private System.Data.SqlClient.SqlDataAdapter da2;
  28. private System.Data.SqlClient.SqlCommand sqlSelectCommand2;
  29. private 生产管理系统.DataSet3 dataSet31;
  30. /// <summary>
  31. /// 必需的设计器变量。
  32. /// </summary>
  33. private System.ComponentModel.Container components = null;
  34. public MRPCal()
  35. {
  36. //
  37. // Windows 窗体设计器支持所必需的
  38. //
  39. InitializeComponent();
  40. //
  41. // TODO: 在 InitializeComponent 调用后添加任何构造函数代码
  42. //
  43. }
  44. /// <summary>
  45. /// 清理所有正在使用的资源。
  46. /// </summary>
  47. protected override void Dispose( bool disposing )
  48. {
  49. if( disposing )
  50. {
  51. if(components != null)
  52. {
  53. components.Dispose();
  54. }
  55. }
  56. base.Dispose( disposing );
  57. }
  58. #region Windows 窗体设计器生成的代码
  59. /// <summary>
  60. /// 设计器支持所需的方法 - 不要使用代码编辑器修改
  61. /// 此方法的内容。
  62. /// </summary>
  63. private void InitializeComponent()
  64. {
  65. System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(MRPCal));
  66. this.groupBox1 = new System.Windows.Forms.GroupBox();
  67. this.btnRelease = new System.Windows.Forms.Button();
  68. this.btnCal = new System.Windows.Forms.Button();
  69. this.checkBox3 = new System.Windows.Forms.CheckBox();
  70. this.checkBox2 = new System.Windows.Forms.CheckBox();
  71. this.checkBox1 = new System.Windows.Forms.CheckBox();
  72. this.groupBox2 = new System.Windows.Forms.GroupBox();
  73. this.dataGrid1 = new System.Windows.Forms.DataGrid();
  74. this.dataSet31 = new 生产管理系统.DataSet3();
  75. this.groupBox3 = new System.Windows.Forms.GroupBox();
  76. this.dataGrid2 = new System.Windows.Forms.DataGrid();
  77. this.da1 = new System.Data.SqlClient.SqlDataAdapter();
  78. this.sqlSelectCommand1 = new System.Data.SqlClient.SqlCommand();
  79. this.sqlConnection1 = new System.Data.SqlClient.SqlConnection();
  80. this.da2 = new System.Data.SqlClient.SqlDataAdapter();
  81. this.sqlSelectCommand2 = new System.Data.SqlClient.SqlCommand();
  82. this.groupBox1.SuspendLayout();
  83. this.groupBox2.SuspendLayout();
  84. ((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).BeginInit();
  85. ((System.ComponentModel.ISupportInitialize)(this.dataSet31)).BeginInit();
  86. this.groupBox3.SuspendLayout();
  87. ((System.ComponentModel.ISupportInitialize)(this.dataGrid2)).BeginInit();
  88. this.SuspendLayout();
  89. // 
  90. // groupBox1
  91. // 
  92. this.groupBox1.Controls.Add(this.btnRelease);
  93. this.groupBox1.Controls.Add(this.btnCal);
  94. this.groupBox1.Controls.Add(this.checkBox3);
  95. this.groupBox1.Controls.Add(this.checkBox2);
  96. this.groupBox1.Controls.Add(this.checkBox1);
  97. this.groupBox1.Location = new System.Drawing.Point(0, 8);
  98. this.groupBox1.Name = "groupBox1";
  99. this.groupBox1.Size = new System.Drawing.Size(632, 80);
  100. this.groupBox1.TabIndex = 0;
  101. this.groupBox1.TabStop = false;
  102. this.groupBox1.Text = "计算参数";
  103. // 
  104. // btnRelease
  105. // 
  106. this.btnRelease.Enabled = false;
  107. this.btnRelease.Image = ((System.Drawing.Image)(resources.GetObject("btnRelease.Image")));
  108. this.btnRelease.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
  109. this.btnRelease.Location = new System.Drawing.Point(520, 40);
  110. this.btnRelease.Name = "btnRelease";
  111. this.btnRelease.Size = new System.Drawing.Size(96, 23);
  112. this.btnRelease.TabIndex = 4;
  113. this.btnRelease.Text = "结果发布";
  114. this.btnRelease.Click += new System.EventHandler(this.btnRelease_Click);
  115. // 
  116. // btnCal
  117. // 
  118. this.btnCal.Image = ((System.Drawing.Image)(resources.GetObject("btnCal.Image")));
  119. this.btnCal.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
  120. this.btnCal.Location = new System.Drawing.Point(416, 40);
  121. this.btnCal.Name = "btnCal";
  122. this.btnCal.TabIndex = 3;
  123. this.btnCal.Text = "计算";
  124. this.btnCal.Click += new System.EventHandler(this.btnCal_Click);
  125. // 
  126. // checkBox3
  127. // 
  128. this.checkBox3.Location = new System.Drawing.Point(304, 32);
  129. this.checkBox3.Name = "checkBox3";
  130. this.checkBox3.Size = new System.Drawing.Size(80, 24);
  131. this.checkBox3.TabIndex = 2;
  132. this.checkBox3.Text = "考虑损耗";
  133. // 
  134. // checkBox2
  135. // 
  136. this.checkBox2.Location = new System.Drawing.Point(176, 32);
  137. this.checkBox2.Name = "checkBox2";
  138. this.checkBox2.TabIndex = 1;
  139. this.checkBox2.Text = "考虑提前期";
  140. // 
  141. // checkBox1
  142. // 
  143. this.checkBox1.Checked = true;
  144. this.checkBox1.CheckState = System.Windows.Forms.CheckState.Checked;
  145. this.checkBox1.Location = new System.Drawing.Point(24, 28);
  146. this.checkBox1.Name = "checkBox1";
  147. this.checkBox1.Size = new System.Drawing.Size(120, 32);
  148. this.checkBox1.TabIndex = 0;
  149. this.checkBox1.Text = "考虑库存,生产和采购订单";
  150. // 
  151. // groupBox2
  152. // 
  153. this.groupBox2.Controls.Add(this.dataGrid1);
  154. this.groupBox2.Location = new System.Drawing.Point(0, 96);
  155. this.groupBox2.Name = "groupBox2";
  156. this.groupBox2.Size = new System.Drawing.Size(640, 168);
  157. this.groupBox2.TabIndex = 1;
  158. this.groupBox2.TabStop = false;
  159. this.groupBox2.Text = "主生产计划";
  160. // 
  161. // dataGrid1
  162. // 
  163. this.dataGrid1.CaptionVisible = false;
  164. this.dataGrid1.DataMember = "主生产计划";
  165. this.dataGrid1.DataSource = this.dataSet31;
  166. this.dataGrid1.HeaderForeColor = System.Drawing.SystemColors.ControlText;
  167. this.dataGrid1.Location = new System.Drawing.Point(8, 24);
  168. this.dataGrid1.Name = "dataGrid1";
  169. this.dataGrid1.ReadOnly = true;
  170. this.dataGrid1.Size = new System.Drawing.Size(624, 136);
  171. this.dataGrid1.TabIndex = 0;
  172. // 
  173. // dataSet31
  174. // 
  175. this.dataSet31.DataSetName = "DataSet3";
  176. this.dataSet31.Locale = new System.Globalization.CultureInfo("zh-CN");
  177. // 
  178. // groupBox3
  179. // 
  180. this.groupBox3.Controls.Add(this.dataGrid2);
  181. this.groupBox3.Location = new System.Drawing.Point(0, 264);
  182. this.groupBox3.Name = "groupBox3";
  183. this.groupBox3.Size = new System.Drawing.Size(640, 224);
  184. this.groupBox3.TabIndex = 2;
  185. this.groupBox3.TabStop = false;
  186. this.groupBox3.Text = "MRP计算结果(物料需求)";
  187. // 
  188. // dataGrid2
  189. // 
  190. this.dataGrid2.CaptionVisible = false;
  191. this.dataGrid2.DataMember = "mrp物料需求计算";
  192. this.dataGrid2.DataSource = this.dataSet31;
  193. this.dataGrid2.HeaderForeColor = System.Drawing.SystemColors.ControlText;
  194. this.dataGrid2.Location = new System.Drawing.Point(8, 16);
  195. this.dataGrid2.Name = "dataGrid2";
  196. this.dataGrid2.ReadOnly = true;
  197. this.dataGrid2.Size = new System.Drawing.Size(624, 200);
  198. this.dataGrid2.TabIndex = 1;
  199. // 
  200. // da1
  201. // 
  202. this.da1.SelectCommand = this.sqlSelectCommand1;
  203. this.da1.TableMappings.AddRange(new System.Data.Common.DataTableMapping[] {
  204.   new System.Data.Common.DataTableMapping("Table", "主生产计划", new System.Data.Common.DataColumnMapping[] {
  205.    new System.Data.Common.DataColumnMapping("物料名称", "物料名称"),
  206.    new System.Data.Common.DataColumnMapping("物料编号", "物料编号"),
  207.    new System.Data.Common.DataColumnMapping("编号", "编号"),
  208.    new System.Data.Common.DataColumnMapping("年份", "年份"),
  209.    new System.Data.Common.DataColumnMapping("计划期", "计划期"),
  210.    new System.Data.Common.DataColumnMapping("开始日期", "开始日期"),
  211.    new System.Data.Common.DataColumnMapping("结束日期", "结束日期"),
  212.    new System.Data.Common.DataColumnMapping("期初库存", "期初库存"),
  213.    new System.Data.Common.DataColumnMapping("需求数量", "需求数量"),
  214.    new System.Data.Common.DataColumnMapping("MPS数量", "MPS数量"),
  215.    new System.Data.Common.DataColumnMapping("生产单数量", "生产单数量"),
  216.    new System.Data.Common.DataColumnMapping("预计库存", "预计库存"),
  217.    new System.Data.Common.DataColumnMapping("记帐人", "记帐人"),
  218.    new System.Data.Common.DataColumnMapping("修改日期", "修改日期"),
  219.    new System.Data.Common.DataColumnMapping("审核人", "审核人"),
  220.    new System.Data.Common.DataColumnMapping("审核日期", "审核日期"),
  221.    new System.Data.Common.DataColumnMapping("状态", "状态"),
  222.    new System.Data.Common.DataColumnMapping("备注", "备注")})});
  223. // 
  224. // sqlSelectCommand1
  225. // 
  226. this.sqlSelectCommand1.CommandText = "SELECT b.物料名称, a.物料编号, a.编号, a.年份, a.计划期, a.开始日期, a.结束日期, a.期初库存, a.需求数量, a.MPS数量" +
  227. ", a.生产单数量, a.预计库存, a.记帐人, a.修改日期, a.审核人, a.审核日期, a.状态, a.备注 FROM 主生产计划 a INNER J" +
  228. "OIN 物料主文件 b ON a.物料编号 = b.物料编号";
  229. this.sqlSelectCommand1.Connection = this.sqlConnection1;
  230. // 
  231. // sqlConnection1
  232. // 
  233. this.sqlConnection1.ConnectionString = "workstation id=localhost;Integrated Security=SSPI;Database=mrpbook;";
  234. // 
  235. // da2
  236. // 
  237. this.da2.SelectCommand = this.sqlSelectCommand2;
  238. this.da2.TableMappings.AddRange(new System.Data.Common.DataTableMapping[] {
  239.   new System.Data.Common.DataTableMapping("Table", "mrp物料需求计算", new System.Data.Common.DataColumnMapping[] {
  240.    new System.Data.Common.DataColumnMapping("物料名称", "物料名称"),
  241.    new System.Data.Common.DataColumnMapping("物料编号", "物料编号"),
  242.    new System.Data.Common.DataColumnMapping("年份", "年份"),
  243.    new System.Data.Common.DataColumnMapping("计划期", "计划期"),
  244.    new System.Data.Common.DataColumnMapping("期初库存", "期初库存"),
  245.    new System.Data.Common.DataColumnMapping("毛需求", "毛需求"),
  246.    new System.Data.Common.DataColumnMapping("预计入库", "预计入库"),
  247.    new System.Data.Common.DataColumnMapping("预计出库", "预计出库"),
  248.    new System.Data.Common.DataColumnMapping("预计库存", "预计库存"),
  249.    new System.Data.Common.DataColumnMapping("净需求", "净需求"),
  250.    new System.Data.Common.DataColumnMapping("计划产出", "计划产出"),
  251.    new System.Data.Common.DataColumnMapping("计划投入", "计划投入")})});
  252. // 
  253. // sqlSelectCommand2
  254. // 
  255. this.sqlSelectCommand2.CommandText = "SELECT b.物料名称, a.物料编号, a.年份, a.计划期, a.期初库存, a.毛需求, a.预计入库, a.预计出库, a.预计库存, a.净需求," +
  256. " a.计划产出, a.计划投入 FROM mrp物料需求计算 a INNER JOIN 物料主文件 b ON a.物料编号 = b.物料编号";
  257. this.sqlSelectCommand2.Connection = this.sqlConnection1;
  258. // 
  259. // MRPCal
  260. // 
  261. this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
  262. this.ClientSize = new System.Drawing.Size(648, 493);
  263. this.Controls.Add(this.groupBox3);
  264. this.Controls.Add(this.groupBox2);
  265. this.Controls.Add(this.groupBox1);
  266. this.Name = "MRPCal";
  267. this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
  268. this.Text = "【MRP计算】";
  269. this.Load += new System.EventHandler(this.MRPCal_Load);
  270. this.groupBox1.ResumeLayout(false);
  271. this.groupBox2.ResumeLayout(false);
  272. ((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).EndInit();
  273. ((System.ComponentModel.ISupportInitialize)(this.dataSet31)).EndInit();
  274. this.groupBox3.ResumeLayout(false);
  275. ((System.ComponentModel.ISupportInitialize)(this.dataGrid2)).EndInit();
  276. this.ResumeLayout(false);
  277. }
  278. #endregion
  279. //----------窗体创建时读入数据-----------
  280. private void MRPCal_Load(object sender, System.EventArgs e)
  281. {
  282. da1.Fill(dataSet31);
  283. }
  284. //------------计算MPR--------------
  285. private void btnCal_Click(object sender, System.EventArgs e)
  286. {
  287. if(dataSet31.主生产计划.Count==0)//如主生产计划为空,则不做任何操作
  288. return;
  289. string inStr1="0";//根据选择设置调用储存过程的参数
  290. string inStr2="0";
  291. string inStr3="0";
  292. if(checkBox1.Checked)
  293. inStr1="1";
  294. if(checkBox2.Checked)
  295. inStr2="1";
  296. if(checkBox3.Checked)
  297. inStr3="1";
  298. string strConn = "server=localhost;Integrated Security=SSPI;database=mrpbook";
  299. SqlConnection cn=new SqlConnection(strConn);
  300. cn.Open();
  301. SqlCommand cmd=cn.CreateCommand();
  302. cmd.CommandText="exec sf_mrp计算 '"+inStr1+"','"+inStr2+"','"+inStr3+"'";
  303. int exResult=cmd.ExecuteNonQuery();
  304. if(exResult!=-1)//允许发布MRP计算结果
  305. {
  306. MessageBox.Show("MRP计算成功,请发布计算结果");
  307. dataSet31.Clear();
  308. da1.Fill(dataSet31);
  309. da2.Fill(dataSet31);
  310. btnRelease.Enabled=true;
  311. }
  312.             
  313. }
  314. //------------发布MRP计算结果--------------
  315. private void btnRelease_Click(object sender, System.EventArgs e)
  316. {
  317. string strConn = "server=localhost;Integrated Security=SSPI;database=mrpbook";
  318. SqlConnection cn=new SqlConnection(strConn);
  319. cn.Open();
  320. SqlCommand cmd=cn.CreateCommand();
  321. cmd.CommandText="exec sf_mrp结果发布";
  322. int exResult=cmd.ExecuteNonQuery();
  323. if(exResult!=-1)
  324. {
  325. dataSet31.Clear();//刷新数据集
  326. da1.Fill(dataSet31);
  327. da2.Fill(dataSet31);
  328. btnRelease.Enabled=false;
  329. }
  330. }
  331. }
  332. }