Query_BarcodeIn.cs 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. using DevExpress.Printing.Core.PdfExport.Metafile;
  2. using HslCommunication;
  3. using LabelManager2;
  4. using Seagull.BarTender.Print;
  5. using System;
  6. using System.Data;
  7. using System.Drawing;
  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. using static System.Runtime.CompilerServices.RuntimeHelpers;
  15. namespace UAS_MES_NEW.Query
  16. {
  17. public partial class Query_BarcodeIn : Form
  18. {
  19. DataHelper dh = SystemInf.dh;
  20. DataTable Dbfind;
  21. Thread InitPrint;
  22. Engine engine;
  23. public Query_BarcodeIn()
  24. {
  25. InitializeComponent();
  26. }
  27. private void InPrint()
  28. {
  29. try
  30. {
  31. engine = new Engine(true);
  32. }
  33. catch (Exception)
  34. {
  35. MessageBox.Show("未正确安装BarTender软件");
  36. }
  37. }
  38. private void Query_LoadMake_Load(object sender, EventArgs e)
  39. {
  40. pi_inoutno.TableName = "prodinout";
  41. pi_inoutno.SelectField = "pi_inoutno#单号";
  42. pi_inoutno.FormName = Name;
  43. pi_inoutno.SetValueField = new string[] { "pi_inoutno" };
  44. pi_inoutno.Condition = "1=1";
  45. pi_inoutno.DbChange += Ma_code_DbChange;
  46. InitPrint = new Thread(InPrint);
  47. SetLoadingWindow stw = new SetLoadingWindow(InitPrint, "初始化打印程序");
  48. BaseUtil.SetFormCenter(stw);
  49. stw.ShowDialog();
  50. LoadGridData();
  51. DataTable _dt = (DataTable)dh.ExecuteSql("select la_id,la_url,la_isdefault,replace(LA_SOFTTYPE,';',',')LA_SOFTTYPE from label where la_prodcode='生产退料标签' and la_templatetype='自定义' and la_statuscode='AUDITED' order by la_isdefault", "select");
  52. if (_dt.Rows.Count == 0)
  53. {
  54. _dt = (DataTable)dh.ExecuteSql("select la_id,la_url,la_isdefault,replace(LA_SOFTTYPE,';',',')LA_SOFTTYPE from label where la_prodcode is null and la_templatetype='自定义' and la_statuscode='AUDITED' order by la_isdefault", "select");
  55. }
  56. if (_dt.Rows.Count > 0)
  57. {
  58. string la_id = _dt.Rows[0]["la_id"].ToString();
  59. _dt = (DataTable)dh.ExecuteSql("select fp_name la_url,'" + la_id + "' la_id from FILEPATH where fp_id in (select * from table(select parsestring(LA_SOFTTYPE,';') from label where la_templatetype='自定义' and la_id='" + la_id + "') where COLUMN_VALUE is not null)", "select");
  60. PrintLabel.DataSource = _dt;
  61. PrintLabel.DisplayMember = "la_url";
  62. PrintLabel.ValueMember = "la_id";
  63. }
  64. }
  65. private void Ma_code_DbChange(object sender, EventArgs e)
  66. {
  67. Dbfind = pi_inoutno.ReturnData;
  68. BaseUtil.SetFormValue(this.Controls, Dbfind);
  69. }
  70. private void UpLoadMake_Click(object sender, EventArgs e)
  71. {
  72. LoadGridData();
  73. }
  74. private void LoadGridData()
  75. {
  76. DataTable dt = (DataTable)dh.ExecuteSql("select * from barcodeio left join product on pr_code=bi_prodcode where bi_inoutno='" + pi_inoutno.Text + "'", "select");
  77. BaseUtil.FillDgvWithDataTable(DGV, dt);
  78. }
  79. private bool ifcheckrow()
  80. {
  81. for (int i = 0; i < DGV.Rows.Count; i++)
  82. {
  83. if (DGV.Rows[i].Cells["Choose"].Value != null && DGV.Rows[i].Cells["Choose"].FormattedValue.ToString() == "True")
  84. {
  85. return true;
  86. }
  87. }
  88. return false;
  89. }
  90. private void Print_Click(object sender, EventArgs e)
  91. {
  92. string ErrMsg = "";
  93. LogicHandler.GenProdiodetail(pi_inoutno.Text, out ErrMsg);
  94. MessageBox.Show("生成明细成功");
  95. }
  96. string new_barcode = "";
  97. private void pi_inoutno_UserControlTextChanged(object sender, EventArgs e)
  98. {
  99. LoadGridData();
  100. }
  101. private void MakeCode_KeyDown(object sender, KeyEventArgs e)
  102. {
  103. if (e.KeyCode == Keys.Enter)
  104. {
  105. if (pi_inoutno.Text == "")
  106. {
  107. MessageBox.Show("出入库单号不能为空");
  108. return;
  109. }
  110. DataTable dt = (DataTable)dh.ExecuteSql("select bi_inqty,bi_barcode from barcodeio left join product on pr_code=bi_prodcode" +
  111. " where bi_inoutno='" + pi_inoutno.Text + "' and bi_barcode='" + barcode.Text + "'", "select");
  112. if (dt.Rows.Count > 0)
  113. {
  114. MessageBox.Show("出入库单已采集条码" + barcode.Text);
  115. return;
  116. }
  117. dt = (DataTable)dh.ExecuteSql("select bar_vendbarcode,to_char(nvl(bar_madedate,sysdate),'yyyy-mm-dd')bar_madedate,bar_code,bar_remain,bar_prodcode from barcode left " +
  118. "join product on pr_code=bar_prodcode where bar_code='" + barcode.Text + "'", "select");
  119. if (dt.Rows.Count == 0)
  120. {
  121. MessageBox.Show("条码" + barcode.Text + "不存在");
  122. return;
  123. }
  124. BarCodePrint bar = new BarCodePrint(barcode.Text);
  125. bar.StartPosition = FormStartPosition.CenterScreen;
  126. bar.ShowDialog();
  127. string newbarcode = bar.Controls["newbarcode"].Text;
  128. string bar_remain = bar.Controls["bar_remain"].Text;
  129. bar.Controls["PrintBarCode"].Click += Query_BarcodeIn_Click;
  130. string pi_id = dh.getFieldDataByCondition("prodinout", "pi_id", "pi_inoutno='" + pi_inoutno.Text + "'").ToString();
  131. string bar_code = dt.Rows[0]["bar_code"].ToString();
  132. string bar_prodcode = dt.Rows[0]["bar_prodcode"].ToString();
  133. string bar_madedate = dt.Rows[0]["bar_madedate"].ToString();
  134. string bar_vendbarcode = dt.Rows[0]["bar_vendbarcode"].ToString();
  135. dh.ExecuteSql("insert into barcodeio(bi_id,bi_piid,bi_barcode,bi_inoutno,bi_prodcode,bi_indate,bi_inqty,bi_vendbarcode,bi_madedate,bi_sourcecode)" +
  136. "values(barcodeio_seq.nextval,'" + pi_id + "','" + newbarcode + "','" + pi_inoutno.Text + "','" + bar_prodcode + "',sysdate,'" + bar_remain + "','" + bar_vendbarcode + "',to_date('" + bar_madedate + "','yyyy-mm-dd'),'" + bar_code + "')", "insert");
  137. LoadGridData();
  138. string ErrorMessage = "";
  139. if (Print.BarTender(Tag.ToString(), ref engine, PrintLabel.Text, PrintLabel.SelectedValue.ToString(), PrinterList.Text, new_barcode, int.Parse("1"), pi_inoutno.Text, bar_prodcode, "自定义", "0", out ErrorMessage))
  140. {
  141. }
  142. }
  143. }
  144. private void Query_BarcodeIn_Click(object sender, EventArgs e)
  145. {
  146. }
  147. private void DeleteBarcode_Click(object sender, EventArgs e)
  148. {
  149. if (!ifcheckrow())
  150. {
  151. MessageBox.Show("请勾选需要操作的行");
  152. return;
  153. }
  154. for (int i = 0; i < DGV.Rows.Count; i++)
  155. {
  156. if (DGV.Rows[i].Cells["Choose"].Value != null && DGV.Rows[i].Cells["Choose"].FormattedValue.ToString() == "True")
  157. {
  158. string barcode = DGV.Rows[i].Cells["bi_barcode"].Value.ToString();
  159. string prodcode = DGV.Rows[i].Cells["bi_prodcode"].Value.ToString();
  160. dh.ExecuteSql("delete from barcodeio where bi_id=" + DGV.Rows[i].Cells["bi_id"].Value.ToString(), "delete");
  161. }
  162. }
  163. LoadGridData();
  164. }
  165. private void ChooseAll_Click(object sender, EventArgs e)
  166. {
  167. for (int i = 0; i < DGV.Rows.Count; i++)
  168. {
  169. DGV.Rows[i].Cells["choose"].Value = true;
  170. }
  171. }
  172. private void Print_Click_1(object sender, EventArgs e)
  173. {
  174. if (!ifcheckrow())
  175. {
  176. MessageBox.Show("请勾选需要操作的行");
  177. return;
  178. }
  179. for (int i = 0; i < DGV.Rows.Count; i++)
  180. {
  181. if (DGV.Rows[i].Cells["Choose"].Value != null && DGV.Rows[i].Cells["Choose"].FormattedValue.ToString() == "True")
  182. {
  183. string barcode = DGV.Rows[i].Cells["bi_barcode"].Value.ToString();
  184. string prodcode = DGV.Rows[i].Cells["bi_prodcode"].Value.ToString();
  185. string ErrorMessage = "";
  186. if (Print.BarTender(Tag.ToString(), ref engine, PrintLabel.Text, PrintLabel.SelectedValue.ToString(), PrinterList.Text, barcode, int.Parse("1"), pi_inoutno.Text, prodcode, "自定义", "0", out ErrorMessage))
  187. {
  188. }
  189. }
  190. }
  191. }
  192. }
  193. }