Make_CancleSndown.cs 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  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_CancleSndown : 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_CancleSndown()
  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_name";
  41. linecode.DataSource = dt;
  42. linecode.Text = "";
  43. }
  44. private void Ma_code_DbChange(object sender, EventArgs e)
  45. {
  46. Dbfind = ma_code.ReturnData;
  47. // BaseUtil.SetFormValue(this.Controls, Dbfind);
  48. // Query.PerformClick();
  49. }
  50. private void Query_OnlineTraceBack_SizeChanged(object sender, EventArgs e)
  51. {
  52. asc.controlAutoSize(this);
  53. }
  54. private void Query_Click(object sender, EventArgs e)
  55. {
  56. //if (dh.CheckExist("make", "ma_code='" + ma_code.Text + "'"))
  57. //{
  58. string condition = BaseUtil.GetScreenSqlCondition(ma_code, linecode, ms_stepcode);
  59. sql.Clear();
  60. sql.Append("select md_id,md_sncode,md_macode,md_prodcode,md_linecode,md_stepcode,md_downdate,st_name,ms_outboxcode,v_outboxcode from makedown left join makeserial on md_msid = ms_id left join step on ms_nextstepcode = st_code left join mes_package_view on ms_makecode = v_makecode and ms_sncode = v_barcode and v_type = 3 ");
  61. sql.Append(condition);
  62. sql.Append("and md_downdate 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 md_status = 0");
  63. sql.Append(" order by md_id asc ");
  64. DataTable dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  65. BaseUtil.FillDgvWithDataTable(SnInf, dt);
  66. checkBox1.Checked = false;
  67. Count.Text = "";
  68. //}
  69. //else
  70. //{
  71. // MessageBox.Show("工单号" + ma_code.Text + "不存在");
  72. // //BaseUtil.CleanDataGridView(SnInf);
  73. // //ma_code.Text = "";
  74. //}
  75. }
  76. private void normalButton1_Click(object sender, EventArgs e)
  77. {
  78. Thread InitPrint;
  79. InitPrint = new Thread(InPrint);
  80. SetLoadingWindow stw = new SetLoadingWindow(InitPrint, "SN解锁中");
  81. BaseUtil.SetFormCenter(stw);
  82. stw.ShowDialog();
  83. }
  84. private void InPrint()
  85. {
  86. try
  87. {
  88. int count = SnInf.Rows.Count;
  89. int check = 0;
  90. for (int i = 0; i < count; i++)
  91. {
  92. DataGridViewCheckBoxCell checkCell = (DataGridViewCheckBoxCell)SnInf.Rows[i].Cells["choose1"];
  93. Boolean flag = Convert.ToBoolean(checkCell.Value);
  94. if (flag == true)
  95. {
  96. sql.Clear();
  97. sql.Append("update makedown set md_status = -1,md_update = sysdate,md_upman = '"+User.UserCode+"' where md_id = "+ SnInf.Rows[i].Cells["md_id"].Value.ToString() + " ");
  98. //执行
  99. dh.ExecuteSql(sql.GetString(), "insert");
  100. check++;
  101. }
  102. }
  103. MessageBox.Show(check + "条数据解除锁定成功");
  104. Thread.Sleep(500);
  105. Query_Click(null,null);
  106. }
  107. catch (Exception EX)
  108. {
  109. MessageBox.Show(EX.Message);
  110. }
  111. }
  112. private void Query_OnlineTraceBack_FormClosing(object sender, FormClosingEventArgs e)
  113. {
  114. dh.Dispose();
  115. }
  116. private void checkBox1_CheckedChanged(object sender, EventArgs e)
  117. {
  118. int count = SnInf.Rows.Count;
  119. for (int i = 0; i < count; i++)
  120. {
  121. DataGridViewCheckBoxCell checkCell = (DataGridViewCheckBoxCell)SnInf.Rows[i].Cells["choose1"];
  122. Boolean flag = Convert.ToBoolean(checkCell.Value);
  123. if (flag != checkBox1.Checked)
  124. {
  125. checkCell.Value = checkBox1.Checked;
  126. }
  127. else
  128. {
  129. continue;
  130. }
  131. }
  132. countcheck();
  133. }
  134. private void normalButton2_Click(object sender, EventArgs e)
  135. {
  136. }
  137. private void countcheck()
  138. {
  139. int checkedRowCount = 0;
  140. foreach (DataGridViewRow row in SnInf.Rows)
  141. {
  142. DataGridViewCheckBoxCell checkBoxCell = row.Cells["choose1"] as DataGridViewCheckBoxCell;
  143. if (checkBoxCell != null && Convert.ToBoolean(checkBoxCell.Value) == true)
  144. {
  145. checkedRowCount++;
  146. }
  147. }
  148. Count.Text = checkedRowCount.ToString();
  149. }
  150. private void ma_code_UserControlTextChanged(object sender, EventArgs e)
  151. {
  152. DataTable dt = (DataTable)dh.ExecuteSql(" select mcd_stepcode,mcd_stepname from MAKECRAFTDETAIL where mcd_macode = '" + ma_code.Text+"' order by mcd_detno asc ", "select");
  153. ms_stepcode.DisplayMember = "mcd_stepname";
  154. ms_stepcode.ValueMember = "mcd_stepname";
  155. ms_stepcode.DataSource = dt;
  156. ms_stepcode.Text = "";
  157. }
  158. private void SnInf_CurrentCellDirtyStateChanged(object sender, EventArgs e)
  159. {
  160. if (SnInf.CurrentCell is DataGridViewCheckBoxCell)
  161. {
  162. SnInf.CommitEdit(DataGridViewDataErrorContexts.Commit);
  163. countcheck();
  164. // 执行你的操作,使用 checkedRows
  165. }
  166. }
  167. private void normalButton2_Click_1(object sender, EventArgs e)
  168. {
  169. //Data表示导出数据
  170. //Templet表示导出模板
  171. folderBrowserDialog1.Description = "选择导出的路径";
  172. DialogResult result = folderBrowserDialog1.ShowDialog();
  173. if (result == DialogResult.OK)
  174. {
  175. string FolderPath = folderBrowserDialog1.SelectedPath;
  176. ExcelHandler eh = new ExcelHandler();
  177. //DataTable dt = (DataTable)SnInf.DataSource;
  178. //导出Excel的时候返回一个文件名,用户选择是否打开
  179. string filePath = eh.ExportExcel(SnInf, FolderPath);
  180. //用户选择导出之后是否立即打开
  181. MessageBoxButtons messButton = MessageBoxButtons.YesNo;
  182. string openFile = MessageBox.Show(this.ParentForm, "是否打开文件" + filePath, "提示", messButton).ToString();
  183. if (openFile == "Yes")
  184. {
  185. System.Diagnostics.Process.Start(filePath);
  186. }
  187. }
  188. }
  189. }
  190. }