Query_OnlineTraceBack.cs 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  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.Query
  15. {
  16. public partial class Query_OnlineTraceBack : Form
  17. {
  18. DataHelper dh;
  19. LogStringBuilder sql = new LogStringBuilder();
  20. AutoSizeFormClass asc = new AutoSizeFormClass();
  21. DataTable ComBoxData = new DataTable();
  22. BarTender.Application engine;
  23. Thread InitPrint;
  24. DataTable Dbfind;
  25. public Query_OnlineTraceBack()
  26. {
  27. InitializeComponent();
  28. }
  29. private void Query_OnlineTraceBack_Load(object sender, EventArgs e)
  30. {
  31. asc.controllInitializeSize(this);
  32. dh = SystemInf.dh;
  33. DataColumn status = new DataColumn("status");
  34. DataColumn statuscode = new DataColumn("statuscode");
  35. ComBoxData.Columns.Add(status);
  36. ComBoxData.Columns.Add(statuscode);
  37. DataRow dr = ComBoxData.NewRow();
  38. dr[0] = "全部"; dr[1] = "ALL"; ComBoxData.Rows.Add(dr);
  39. dr = ComBoxData.NewRow();
  40. dr[0] = "未生产"; dr[1] = "null"; ComBoxData.Rows.Add(dr);
  41. dr = ComBoxData.NewRow();
  42. dr[0] = "已归属"; dr[1] = "0"; ComBoxData.Rows.Add(dr);
  43. dr = ComBoxData.NewRow();
  44. dr[0] = "在线"; dr[1] = "1"; ComBoxData.Rows.Add(dr);
  45. dr = ComBoxData.NewRow();
  46. dr[0] = "已完工"; dr[1] = "2"; ComBoxData.Rows.Add(dr);
  47. dr = ComBoxData.NewRow();
  48. dr[0] = "不良待维修"; dr[1] = "3"; ComBoxData.Rows.Add(dr);
  49. dr = ComBoxData.NewRow();
  50. dr[0] = "已报废"; dr[1] = "4"; ComBoxData.Rows.Add(dr);
  51. ms_status.DataSource = ComBoxData;
  52. ms_status.DisplayMember = "status";
  53. ms_status.ValueMember = "statuscode";
  54. //工单号放大镜配置
  55. ma_code.TableName = "make left join product on ma_prodcode=pr_code";
  56. ma_code.SelectField = "ma_code # 工单号,ma_prodcode # 产品编号,ma_qty # 工单数量,pr_detail # 产品名称,ma_softversion # 软件版本";
  57. ma_code.FormName = Name;
  58. ma_code.SetValueField = new string[] { "ma_code" };
  59. ma_code.Condition = "ma_statuscode='STARTED'";
  60. ma_code.DbChange += Ma_code_DbChange;
  61. InitPrint = new Thread(InPrint);
  62. SetLoadingWindow stw = new SetLoadingWindow(InitPrint, "初始化打印程序");
  63. InitPrint.Start();
  64. }
  65. private void InPrint()
  66. {
  67. try
  68. {
  69. engine = new BarTender.Application();
  70. //lbl = new ApplicationClass();
  71. //BaseUtil.WriteLbl();
  72. }
  73. catch (Exception ex)
  74. {
  75. // OperateResult.AppendText("未正确安装打印软件\n", Color.Red);
  76. }
  77. }
  78. private void Ma_code_DbChange(object sender, EventArgs e)
  79. {
  80. Dbfind = ma_code.ReturnData;
  81. BaseUtil.SetFormValue(this.Controls, Dbfind);
  82. Query.PerformClick();
  83. }
  84. private void Query_OnlineTraceBack_SizeChanged(object sender, EventArgs e)
  85. {
  86. asc.controlAutoSize(this);
  87. }
  88. private void Query_Click(object sender, EventArgs e)
  89. {
  90. if (dh.CheckExist("make", "ma_code='" + ma_code.Text + "'"))
  91. {
  92. string condition = BaseUtil.GetScreenSqlCondition(ma_code, ms_stepcode, ms_nextstepcode);
  93. string statuscode = ms_status.SelectedValue.ToString();
  94. sql.Clear();
  95. sql.Append("select distinct sncode SN,ms_linecode 线别,ms_stepcode 当前工序,ms_nextstepcode 下一工序,ms_craftcode 当前途程,makecode ms_makecode, ");
  96. sql.Append("case when ms_status is null then '未生产' when ms_status=0 then '已归属' when ms_status=1 then '在线' when ms_status=2 ");
  97. sql.Append(" then '已完工' when ms_status=3 then '不良待维修' when ms_status=4 then '已报废' ");
  98. sql.Append("else 'null' end 状态 from((select msd_sncode sncode,msd_makecode makecode,msd_type type ");
  99. sql.Append("from makesnruledetail where msd_makecode='" + ma_code.Text + "') union (select msl_sncode sncode,msl_makecode ");
  100. sql.Append("makecode,msl_type type from makesnlist where msl_makecode='" + ma_code.Text + "') union (");
  101. sql.Append("select ms_sncode,ms_makecode,'' type from makeserial where ms_makecode='" + ma_code.Text + "'))");
  102. sql.Append("A left join makeserial on ms_sncode=sncode and ms_makecode=makecode ");
  103. sql.Append(condition);
  104. if (statuscode == "null")
  105. {
  106. sql.Append("and ms_status is null");
  107. }
  108. else if (statuscode == "ALL")
  109. {
  110. }
  111. else
  112. {
  113. sql.Append("and ms_status ='" + statuscode + "'");
  114. }
  115. sql.Append(" order by SN ");
  116. DataTable dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  117. BaseUtil.FillDgvWithDataTable(SnInf, dt);
  118. Count.Text = SnInf.Rows.Count.ToString();
  119. ma_qty.Text = dh.getFieldDataByCondition("make", "ma_qty", "ma_code='" + ma_code.Text + "'").ToString();
  120. }
  121. else
  122. {
  123. MessageBox.Show("工单号" + ma_code.Text + "不存在");
  124. BaseUtil.CleanDataGridView(SnInf);
  125. ma_code.Text = "";
  126. }
  127. }
  128. private void ms_status_SelectedIndexChanged(object sender, EventArgs e)
  129. {
  130. if (ma_code.Text != "")
  131. Query.PerformClick();
  132. }
  133. private void normalButton1_Click(object sender, EventArgs e)
  134. {
  135. //Data表示导出数据
  136. //Templet表示导出模板
  137. folderBrowserDialog1.Description = "选择导出的路径";
  138. DialogResult result = folderBrowserDialog1.ShowDialog();
  139. if (result == DialogResult.OK)
  140. {
  141. string FolderPath = folderBrowserDialog1.SelectedPath;
  142. ExcelHandler eh = new ExcelHandler();
  143. DataTable dt = (DataTable)SnInf.DataSource;
  144. //导出Excel的时候返回一个文件名,用户选择是否打开
  145. string filePath = eh.ExportExcel(dt, FolderPath);
  146. //用户选择导出之后是否立即打开
  147. MessageBoxButtons messButton = MessageBoxButtons.YesNo;
  148. string openFile = MessageBox.Show(this.ParentForm, "是否打开文件"+ filePath, "提示", messButton).ToString();
  149. if (openFile == "Yes")
  150. {
  151. System.Diagnostics.Process.Start(filePath);
  152. }
  153. }
  154. }
  155. private void Query_OnlineTraceBack_FormClosing(object sender, FormClosingEventArgs e)
  156. {
  157. if (engine != null)
  158. engine.Quit(BarTender.BtSaveOptions.btDoNotSaveChanges);
  159. dh.Dispose();
  160. }
  161. private void checkBox1_CheckedChanged(object sender, EventArgs e)
  162. {
  163. int count = SnInf.Rows.Count;
  164. for (int i = 0; i < count; i++)
  165. {
  166. DataGridViewCheckBoxCell checkCell = (DataGridViewCheckBoxCell)SnInf.Rows[i].Cells["choose1"];
  167. Boolean flag = Convert.ToBoolean(checkCell.Value);
  168. if (flag != checkBox1.Checked)
  169. {
  170. checkCell.Value = checkBox1.Checked;
  171. }
  172. else
  173. {
  174. continue;
  175. }
  176. }
  177. }
  178. private void normalButton2_Click(object sender, EventArgs e)
  179. {
  180. BarTender.Format doc2 = engine.Formats.Open(System.AppDomain.CurrentDomain.BaseDirectory + "20X10打印标签.btw");
  181. if (doc2 == null)
  182. {
  183. MessageBox.Show("标签文件打开失败");
  184. return;
  185. }
  186. int count = SnInf.Rows.Count;
  187. for (int i = 0; i < count; i++)
  188. {
  189. DataGridViewCheckBoxCell checkCell = (DataGridViewCheckBoxCell)SnInf.Rows[i].Cells["choose1"];
  190. Boolean flag = Convert.ToBoolean(checkCell.Value);
  191. if (flag == true)
  192. {
  193. doc2.SetNamedSubStringValue("SN", SnInf.Rows[i].Cells["SN"].Value.ToString());
  194. // 同样标签的份数
  195. doc2.PrintSetup.IdenticalCopiesOfLabel = 1;
  196. // 序列标签数
  197. doc2.PrintSetup.NumberSerializedLabels = 1;
  198. doc2.PrintSetup.Printer = Printer.Text;
  199. doc2.PrintOut(false, false);
  200. }
  201. }
  202. doc2.Close(BarTender.BtSaveOptions.btDoNotSaveChanges);
  203. //打印完毕
  204. engine.Quit(BarTender.BtSaveOptions.btDoNotSaveChanges);
  205. }
  206. private void Setting_Click(object sender, EventArgs e)
  207. {
  208. PrintDialog printd = new PrintDialog();
  209. printd.PrinterSettings.PrinterName = Printer.Text;
  210. printd.ShowDialog();
  211. }
  212. private void ma_code_UserControlTextChanged(object sender, EventArgs e)
  213. {
  214. DataTable dt = (DataTable)dh.ExecuteSql(" select mcd_stepcode,mcd_stepname from MAKECRAFTDETAIL where mcd_macode = '" + ma_code.Text+"' order by mcd_detno asc ", "select");
  215. DataTable dt2 = (DataTable)dh.ExecuteSql(" select mcd_stepcode,mcd_stepname from MAKECRAFTDETAIL where mcd_macode = '" + ma_code.Text + "' order by mcd_detno asc ", "select");
  216. ms_stepcode.DisplayMember = "mcd_stepname";
  217. ms_stepcode.ValueMember = "mcd_stepcode";
  218. ms_stepcode.DataSource = dt;
  219. ms_stepcode.Text = "";
  220. ms_nextstepcode.DisplayMember = "mcd_stepname";
  221. ms_nextstepcode.ValueMember = "mcd_stepcode";
  222. ms_nextstepcode.DataSource = dt2;
  223. ms_nextstepcode.Text = "";
  224. }
  225. }
  226. }