Make_Sndown.cs 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  1. using System;
  2. using System.Data;
  3. using System.Threading;
  4. using System.Windows.Forms;
  5. using UAS_MES_NEW.DataOperate;
  6. using UAS_MES_NEW.Entity;
  7. using UAS_MES_NEW.PublicForm;
  8. using UAS_MES_NEW.PublicMethod;
  9. namespace UAS_MES_NEW.Make
  10. {
  11. public partial class Make_Sndown : Form
  12. {
  13. DataHelper dh;
  14. LogStringBuilder sql = new LogStringBuilder();
  15. AutoSizeFormClass asc = new AutoSizeFormClass();
  16. DataTable ComBoxData = new DataTable();
  17. DataTable Dbfind;
  18. public Make_Sndown()
  19. {
  20. InitializeComponent();
  21. }
  22. private void Query_OnlineTraceBack_Load(object sender, EventArgs e)
  23. {
  24. asc.controllInitializeSize(this);
  25. dh = SystemInf.dh;
  26. //工单号放大镜配置
  27. ma_code.TableName = "make left join product on ma_prodcode=pr_code";
  28. ma_code.SelectField = "ma_code # 工单号,ma_prodcode # 产品编号,ma_qty # 工单数量,pr_detail # 产品名称,ma_softversion # 软件版本";
  29. ma_code.FormName = Name;
  30. ma_code.SetValueField = new string[] { "ma_code" };
  31. ma_code.Condition = "ma_statuscode='STARTED'";
  32. ma_code.DbChange += Ma_code_DbChange;
  33. DataTable dt = (DataTable)dh.ExecuteSql(" select li_code,li_name from line ", "select");
  34. linecode.DisplayMember = "li_name";
  35. linecode.ValueMember = "li_code";
  36. linecode.DataSource = dt;
  37. linecode.Text = "";
  38. }
  39. private void Ma_code_DbChange(object sender, EventArgs e)
  40. {
  41. Dbfind = ma_code.ReturnData;
  42. BaseUtil.SetFormValue(this.Controls, Dbfind);
  43. // Query.PerformClick();
  44. }
  45. private void Query_OnlineTraceBack_SizeChanged(object sender, EventArgs e)
  46. {
  47. asc.controlAutoSize(this);
  48. }
  49. private void Query_Click(object sender, EventArgs e)
  50. {
  51. if (dh.CheckExist("make", "ma_code='" + ma_code.Text + "'"))
  52. {
  53. string condition = BaseUtil.GetScreenSqlCondition(ma_code, linecode, ms_stepcode, sncode);
  54. sql.Clear();
  55. sql.Append("select sp_id,sp_sncode,sp_makecode,sp_prodcode,li_name,st_name,sp_date from steppassed left join line on sp_linecode = li_code left join step on sp_stepcode = st_code ");
  56. sql.Append(condition);
  57. 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)");
  58. sql.Append(" order by sp_date asc ");
  59. DataTable dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  60. BaseUtil.FillDgvWithDataTable(SnInf, dt);
  61. checkBox1.Checked = false;
  62. Count.Text = "";
  63. }
  64. else
  65. {
  66. MessageBox.Show("工单号" + ma_code.Text + "不存在");
  67. //BaseUtil.CleanDataGridView(SnInf);
  68. //ma_code.Text = "";
  69. }
  70. }
  71. private void normalButton1_Click(object sender, EventArgs e)
  72. {
  73. Thread InitPrint;
  74. InitPrint = new Thread(InPrint);
  75. SetLoadingWindow stw = new SetLoadingWindow(InitPrint, "SN锁定中");
  76. BaseUtil.SetFormCenter(stw);
  77. stw.ShowDialog();
  78. }
  79. private void InPrint()
  80. {
  81. try
  82. {
  83. int count = SnInf.Rows.Count;
  84. int check = 0;
  85. for (int i = 0; i < count; i++)
  86. {
  87. DataGridViewCheckBoxCell checkCell = (DataGridViewCheckBoxCell)SnInf.Rows[i].Cells["choose1"];
  88. Boolean flag = Convert.ToBoolean(checkCell.Value);
  89. if (flag == true)
  90. {
  91. 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 "))
  92. {
  93. sql.Clear();
  94. sql.Append("INSERT INTO MAKEDOWN (MD_ID,MD_MSID,MD_LINECODE,MD_STEPCODE,");
  95. sql.Append("MD_SNCODE,MD_PRODCODE,MD_MACODE, MD_CODE,");
  96. sql.Append("MD_DOWNDATE,MD_DOWNMAN,MD_STATUS) select MAKEDOWN_seq.nextval,ms_id,'" + SnInf.Rows[i].Cells["li_name"].Value.ToString() + "',");
  97. 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() + "'");
  98. //执行
  99. dh.ExecuteSql(sql.GetString(), "insert");
  100. check++;
  101. }
  102. }
  103. }
  104. MessageBox.Show(check + "条数据下地锁定成功");
  105. Thread.Sleep(500);
  106. Query_Click(null, null);
  107. }
  108. catch (Exception EX)
  109. {
  110. MessageBox.Show(EX.Message);
  111. }
  112. }
  113. private void Query_OnlineTraceBack_FormClosing(object sender, FormClosingEventArgs e)
  114. {
  115. dh.Dispose();
  116. }
  117. private void checkBox1_CheckedChanged(object sender, EventArgs e)
  118. {
  119. int count = SnInf.Rows.Count;
  120. for (int i = 0; i < count; i++)
  121. {
  122. DataGridViewCheckBoxCell checkCell = (DataGridViewCheckBoxCell)SnInf.Rows[i].Cells["choose1"];
  123. Boolean flag = Convert.ToBoolean(checkCell.Value);
  124. if (flag != checkBox1.Checked)
  125. {
  126. checkCell.Value = checkBox1.Checked;
  127. }
  128. else
  129. {
  130. continue;
  131. }
  132. }
  133. countcheck();
  134. }
  135. private void normalButton2_Click(object sender, EventArgs e)
  136. {
  137. }
  138. private void countcheck()
  139. {
  140. int checkedRowCount = 0;
  141. foreach (DataGridViewRow row in SnInf.Rows)
  142. {
  143. DataGridViewCheckBoxCell checkBoxCell = row.Cells["choose1"] as DataGridViewCheckBoxCell;
  144. if (checkBoxCell != null && Convert.ToBoolean(checkBoxCell.Value) == true)
  145. {
  146. checkedRowCount++;
  147. }
  148. }
  149. Count.Text = checkedRowCount.ToString();
  150. }
  151. private void ma_code_UserControlTextChanged(object sender, EventArgs e)
  152. {
  153. DataTable dt = (DataTable)dh.ExecuteSql(" select mcd_stepcode,mcd_stepname from MAKECRAFTDETAIL where mcd_macode = '" + ma_code.Text + "' order by mcd_detno asc ", "select");
  154. ms_stepcode.DisplayMember = "mcd_stepname";
  155. ms_stepcode.ValueMember = "mcd_stepcode";
  156. ms_stepcode.DataSource = dt;
  157. ms_stepcode.Text = "";
  158. }
  159. private void SnInf_CurrentCellDirtyStateChanged(object sender, EventArgs e)
  160. {
  161. if (SnInf.CurrentCell is DataGridViewCheckBoxCell)
  162. {
  163. SnInf.CommitEdit(DataGridViewDataErrorContexts.Commit);
  164. countcheck();
  165. // 执行你的操作,使用 checkedRows
  166. }
  167. }
  168. private void normalButton2_Click_1(object sender, EventArgs e)
  169. {
  170. //Data表示导出数据
  171. //Templet表示导出模板
  172. folderBrowserDialog1.Description = "选择导出的路径";
  173. DialogResult result = folderBrowserDialog1.ShowDialog();
  174. if (result == DialogResult.OK)
  175. {
  176. string FolderPath = folderBrowserDialog1.SelectedPath;
  177. ExcelHandler eh = new ExcelHandler();
  178. //DataTable dt = (DataTable)SnInf.DataSource;
  179. //导出Excel的时候返回一个文件名,用户选择是否打开
  180. string filePath = eh.ExportExcel(SnInf, FolderPath);
  181. //用户选择导出之后是否立即打开
  182. MessageBoxButtons messButton = MessageBoxButtons.YesNo;
  183. string openFile = MessageBox.Show(this.ParentForm, "是否打开文件" + filePath, "提示", messButton).ToString();
  184. if (openFile == "Yes")
  185. {
  186. System.Diagnostics.Process.Start(filePath);
  187. }
  188. }
  189. }
  190. }
  191. }