Make_Sndown.cs 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading;
  9. using System.Windows.Forms;
  10. using UAS_MES_NEW.DataOperate;
  11. using UAS_MES_NEW.Entity;
  12. using UAS_MES_NEW.PublicForm;
  13. using UAS_MES_NEW.PublicMethod;
  14. namespace UAS_MES_NEW.Make
  15. {
  16. public partial class Make_Sndown : Form
  17. {
  18. DataHelper dh;
  19. LogStringBuilder sql = new LogStringBuilder();
  20. AutoSizeFormClass asc = new AutoSizeFormClass();
  21. DataTable ComBoxData = new DataTable();
  22. DataTable Dbfind;
  23. public Make_Sndown()
  24. {
  25. InitializeComponent();
  26. }
  27. private void Query_OnlineTraceBack_Load(object sender, EventArgs e)
  28. {
  29. asc.controllInitializeSize(this);
  30. dh = SystemInf.dh;
  31. //工单号放大镜配置
  32. ma_code.TableName = "make left join product on ma_prodcode=pr_code";
  33. ma_code.SelectField = "ma_code # 工单号,ma_prodcode # 产品编号,ma_qty # 工单数量,pr_detail # 产品名称,ma_softversion # 软件版本";
  34. ma_code.FormName = Name;
  35. ma_code.SetValueField = new string[] { "ma_code" };
  36. ma_code.Condition = "ma_statuscode='STARTED'";
  37. ma_code.DbChange += Ma_code_DbChange;
  38. DataTable dt = (DataTable)dh.ExecuteSql(" select li_code,li_name from line ", "select");
  39. linecode.DisplayMember = "li_name";
  40. linecode.ValueMember = "li_code";
  41. linecode.DataSource = dt;
  42. linecode.Text = "";
  43. em_name.TableName = "employee";
  44. em_name.SelectField = "em_code # 人员编号,em_name # 人员名称";
  45. em_name.FormName = Name;
  46. em_name.SetValueField = new string[] { "em_name" };
  47. }
  48. private void Ma_code_DbChange(object sender, EventArgs e)
  49. {
  50. Dbfind = ma_code.ReturnData;
  51. BaseUtil.SetFormValue(this.Controls, Dbfind);
  52. // Query.PerformClick();
  53. }
  54. private void Query_OnlineTraceBack_SizeChanged(object sender, EventArgs e)
  55. {
  56. asc.controlAutoSize(this);
  57. }
  58. private void Query_Click(object sender, EventArgs e)
  59. {
  60. if (dh.CheckExist("make", "ma_code='" + ma_code.Text + "'"))
  61. {
  62. string condition = BaseUtil.GetScreenSqlCondition(ma_code, linecode, ms_stepcode,em_name);
  63. sql.Clear();
  64. sql.Append("select sp_id,sp_sncode,sp_makecode,sp_prodcode,li_name,st_name,sp_date,em_name from steppassed left join line on sp_linecode = li_code left join step on sp_stepcode = st_code left join employee on sp_inman = em_code ");
  65. sql.Append(condition);
  66. sql.Append("and sp_date between to_date('" + BeginDate.Value.ToString("yyyy-MM-dd HH:mm:ss") + "', 'yyyy-mm-dd hh24:mi:ss') and to_date('" + EndDate.Value.ToString("yyyy-MM-dd HH:mm:ss") + "', 'yyyy-mm-dd hh24:mi:ss') and not EXISTS (select 1 from makedown where (md_sncode = sp_sncode or md_code = sp_sncode) and md_status = 0 and md_macode = sp_makecode)");
  67. sql.Append(" order by sp_date asc ");
  68. DataTable dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  69. BaseUtil.FillDgvWithDataTable(SnInf, dt);
  70. checkBox1.Checked = false;
  71. Count.Text = "";
  72. }
  73. else
  74. {
  75. MessageBox.Show("工单号" + ma_code.Text + "不存在");
  76. //BaseUtil.CleanDataGridView(SnInf);
  77. //ma_code.Text = "";
  78. }
  79. }
  80. private void normalButton1_Click(object sender, EventArgs e)
  81. {
  82. Thread InitPrint;
  83. InitPrint = new Thread(InPrint);
  84. SetLoadingWindow stw = new SetLoadingWindow(InitPrint, "SN锁定中");
  85. BaseUtil.SetFormCenter(stw);
  86. stw.ShowDialog();
  87. }
  88. private void InPrint()
  89. {
  90. try
  91. {
  92. int count = SnInf.Rows.Count;
  93. int check = 0;
  94. for (int i = 0; i < count; i++)
  95. {
  96. DataGridViewCheckBoxCell checkCell = (DataGridViewCheckBoxCell)SnInf.Rows[i].Cells["choose1"];
  97. Boolean flag = Convert.ToBoolean(checkCell.Value);
  98. if (flag == true)
  99. {
  100. if (!dh.CheckExist("MAKEDOWN", "(MD_SNCODE = '" + SnInf.Rows[i].Cells["sp_sncode"].Value.ToString() + "' or MD_CODE = '" + SnInf.Rows[i].Cells["sp_sncode"].Value.ToString() + "') and MD_MACODE = '" + SnInf.Rows[i].Cells["sp_makecode"].Value.ToString() + "' and MD_STATUS = 0 "))
  101. {
  102. sql.Clear();
  103. sql.Append("INSERT INTO MAKEDOWN (MD_ID,MD_MSID,MD_LINECODE,MD_STEPCODE,");
  104. sql.Append("MD_SNCODE,MD_PRODCODE,MD_MACODE, MD_CODE,");
  105. sql.Append("MD_DOWNDATE,MD_DOWNMAN,MD_STATUS) select MAKEDOWN_seq.nextval,ms_id,'" + SnInf.Rows[i].Cells["li_name"].Value.ToString() + "',");
  106. sql.Append("'" + SnInf.Rows[i].Cells["st_name"].Value.ToString() + "',ms_sncode,'" + SnInf.Rows[i].Cells["sp_prodcode"].Value.ToString() + "','" + SnInf.Rows[i].Cells["sp_makecode"].Value.ToString() + "',ms_code,sysdate,'" + User.UserCode + "','0' from makeserial where (ms_sncode = '" + SnInf.Rows[i].Cells["sp_sncode"].Value.ToString() + "' or ms_code = '" + SnInf.Rows[i].Cells["sp_sncode"].Value.ToString() + "') and ms_makecode = '" + SnInf.Rows[i].Cells["sp_makecode"].Value.ToString() + "'");
  107. //执行
  108. dh.ExecuteSql(sql.GetString(), "insert");
  109. check++;
  110. }
  111. }
  112. }
  113. MessageBox.Show(check + "条数据下地锁定成功");
  114. Thread.Sleep(500);
  115. Query_Click(null, null);
  116. }
  117. catch (Exception EX)
  118. {
  119. MessageBox.Show(EX.Message);
  120. }
  121. }
  122. private void Query_OnlineTraceBack_FormClosing(object sender, FormClosingEventArgs e)
  123. {
  124. dh.Dispose();
  125. }
  126. private void checkBox1_CheckedChanged(object sender, EventArgs e)
  127. {
  128. int count = SnInf.Rows.Count;
  129. for (int i = 0; i < count; i++)
  130. {
  131. DataGridViewCheckBoxCell checkCell = (DataGridViewCheckBoxCell)SnInf.Rows[i].Cells["choose1"];
  132. Boolean flag = Convert.ToBoolean(checkCell.Value);
  133. if (flag != checkBox1.Checked)
  134. {
  135. checkCell.Value = checkBox1.Checked;
  136. }
  137. else
  138. {
  139. continue;
  140. }
  141. }
  142. countcheck();
  143. }
  144. private void normalButton2_Click(object sender, EventArgs e)
  145. {
  146. }
  147. private void countcheck()
  148. {
  149. int checkedRowCount = 0;
  150. foreach (DataGridViewRow row in SnInf.Rows)
  151. {
  152. DataGridViewCheckBoxCell checkBoxCell = row.Cells["choose1"] as DataGridViewCheckBoxCell;
  153. if (checkBoxCell != null && Convert.ToBoolean(checkBoxCell.Value) == true)
  154. {
  155. checkedRowCount++;
  156. }
  157. }
  158. Count.Text = checkedRowCount.ToString();
  159. }
  160. private void ma_code_UserControlTextChanged(object sender, EventArgs e)
  161. {
  162. DataTable dt = (DataTable)dh.ExecuteSql(" select mcd_stepcode,mcd_stepname from MAKECRAFTDETAIL where mcd_macode = '" + ma_code.Text+"' order by mcd_detno asc ", "select");
  163. ms_stepcode.DisplayMember = "mcd_stepname";
  164. ms_stepcode.ValueMember = "mcd_stepcode";
  165. ms_stepcode.DataSource = dt;
  166. ms_stepcode.Text = "";
  167. }
  168. private void SnInf_CurrentCellDirtyStateChanged(object sender, EventArgs e)
  169. {
  170. if (SnInf.CurrentCell is DataGridViewCheckBoxCell)
  171. {
  172. SnInf.CommitEdit(DataGridViewDataErrorContexts.Commit);
  173. countcheck();
  174. // 执行你的操作,使用 checkedRows
  175. }
  176. }
  177. }
  178. }