UAS_出货标签管理.cs 85 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782
  1. using System;
  2. using System.Data;
  3. using System.Drawing;
  4. using System.Windows.Forms;
  5. using System.Text.RegularExpressions;
  6. using System.Text;
  7. using System.Collections.Generic;
  8. using System.Diagnostics;
  9. using UAS_LabelMachine.PublicMethod;
  10. using UAS_LabelMachine.Entity;
  11. using UAS_LabelMachine.PublicForm;
  12. using System.Threading;
  13. using FastReport;
  14. using System.Linq;
  15. namespace UAS_LabelMachine
  16. {
  17. public partial class UAS_出货标签打印 : Form
  18. {
  19. //自适应屏幕
  20. AutoSizeFormClass asc = new AutoSizeFormClass();
  21. DataHelper dh;
  22. DataTable dt;
  23. StringBuilder sql = new StringBuilder();
  24. /// <summary>
  25. /// 单盘打印文件
  26. /// </summary>
  27. Report SingleReport = new Report();
  28. /// <summary>
  29. /// 中盒打印文件
  30. /// </summary>
  31. Report MidReport = new Report();
  32. /// <summary>
  33. /// 外箱打印文件
  34. /// </summary>
  35. Report OutReport = new Report();
  36. /// <summary>
  37. /// 唛头文件打印
  38. /// </summary>
  39. Report FootReport = new Report();
  40. /// <summary>
  41. /// Loading窗口
  42. /// </summary>
  43. SetLoadingWindow stw;
  44. /// <summary>
  45. /// 弹窗线程
  46. /// </summary>
  47. Thread thread;
  48. /// <summary>
  49. /// 当前品牌
  50. /// </summary>
  51. string PI_ID;
  52. bool logout = false;
  53. //主表数据源
  54. DataTable LabelInfDataTable;
  55. /// <summary>
  56. /// 存放单盘的ID
  57. /// </summary>
  58. List<string> SingleID = new List<string>();
  59. /// <summary>
  60. /// 是否全选
  61. /// </summary>
  62. bool AllChecked = false;
  63. DataTable SumQty;
  64. /// <summary>
  65. /// 是否通过选择Combox来改变打开的文件
  66. /// </summary>
  67. bool ComBoxClickChangeLabelDoc = false;
  68. //当前采集的物料编号
  69. string CurrentPrCode = "";
  70. //当前采集的最小包装
  71. string CurrentZXBZ = "";
  72. //当前采集的单位
  73. string CurrentUnit = "";
  74. //当前采集的总数
  75. string CurrentPrCount = "";
  76. //当前明细序号
  77. string CurrentPDNO = "";
  78. //当前的物料品牌
  79. string CurrentBrand = "";
  80. string Prefix = "";
  81. string Suffix = "";
  82. int MaxNum = 0;
  83. int NumLength = 0;
  84. int Radix = 0;
  85. private bool EnablePrint = true;
  86. string[] PIBID;
  87. DataTable Attach;
  88. public UAS_出货标签打印(string Master)
  89. {
  90. InitializeComponent();
  91. (new EnvironmentSettings()).ReportSettings.ShowProgress = false;
  92. Text = Text + "-" + Master;
  93. }
  94. protected override void WndProc(ref Message m)
  95. {
  96. //拦截双击标题栏、移动窗体的系统消息
  97. if (m.Msg != 0xA3)
  98. {
  99. base.WndProc(ref m);
  100. }
  101. }
  102. private void 贴标机条码打印_Load(object sender, EventArgs e)
  103. {
  104. //用计时器重置数据库链接
  105. LogManager.DoLog("程序启动,登陆人员【" + User.UserName + "】");
  106. dh = SystemInf.dh;
  107. CheckForIllegalCrossThreadCalls = false;
  108. pi_inoutno.Focus();
  109. Point pt = new Point();
  110. //禁止所有列的排序
  111. foreach (DataGridViewColumn dgv in LabelInf.Columns)
  112. {
  113. dgv.SortMode = DataGridViewColumnSortMode.NotSortable;
  114. }
  115. int ScreenWidth = Screen.GetWorkingArea(pt).Width;
  116. //设置获取当前屏幕大小自动全屏但是保留任务栏
  117. Rectangle ScreenArea = Screen.GetWorkingArea(this);
  118. Top = 0;
  119. Left = 0;
  120. Width = ScreenArea.Width;
  121. Height = ScreenArea.Height;
  122. OutboxCapacity.Value = Properties.Settings.Default.OutboxCapacity;
  123. MidboxCapacity.Value = Properties.Settings.Default.MidBoxCapacity;
  124. if (MidboxCapacity.Value == 0)
  125. {
  126. MidboxCapacity.Value = 10;
  127. }
  128. DCCheck.Text = Properties.Settings.Default.DCCheck.ToString();
  129. OutBoxPrinter.Text = Properties.Settings.Default.OPrinter;
  130. MidLabelPrinter.Text = Properties.Settings.Default.MPrinter;
  131. SingleLabelPrinter.Text = Properties.Settings.Default.SPrinter;
  132. asc.controllInitializeSize(this);
  133. asc.controlAutoSize(this);
  134. RefreshDBConnect.Interval = 60000;
  135. RefreshDBConnect.Start();
  136. }
  137. //只执行一次窗体自适应
  138. bool AutoSized = false;
  139. private void 贴标机条码打印_SizeChanged(object sender, EventArgs e)
  140. {
  141. if (!AutoSized)
  142. {
  143. asc.controlAutoSize(this);
  144. AutoSized = true;
  145. }
  146. }
  147. private void LabelMaintain_Click(object sender, EventArgs e)
  148. {
  149. 客户标签维护 form = new 客户标签维护();
  150. BaseUtil.SetFormCenter(form);
  151. form.FormClosed += LabelFormClose;
  152. form.ShowDialog();
  153. }
  154. private void LabelFormClose(object sender, EventArgs e)
  155. {
  156. if (GetGridOnly.Checked)
  157. GetInOutInfAndLabelFile();
  158. else
  159. {
  160. GetGridOnly.Checked = true;
  161. GetInOutInfAndLabelFile();
  162. GetGridOnly.Checked = false;
  163. }
  164. }
  165. //输入框Enter事件
  166. private void Input_KeyDown(object sender, KeyEventArgs e)
  167. {
  168. if (e.KeyCode == Keys.Enter)
  169. {
  170. if (Input.Text == "")
  171. {
  172. MessageBox.Show("采集的数据不能为空");
  173. return;
  174. }
  175. CollectInputData();
  176. }
  177. }
  178. /// <summary>
  179. /// 采集数据
  180. /// </summary>
  181. private void CollectInputData()
  182. {
  183. if (Input.Text == "SC")
  184. {
  185. PrintStatus.PerformClick();
  186. Input.Text = "";
  187. return;
  188. }
  189. Input.Text = Input.Text.Replace("\n", "").Replace(" ", "").Replace("\t", "").Replace("\r", "");
  190. Dictionary<string, string> Data = new Dictionary<string, string>();
  191. string[] SplitData = Input.Text.Split('*');
  192. if (SplitData.Length < 5)
  193. {
  194. MessageBox.Show("数据格式错误,无法解析", "提示");
  195. Input.SelectAll();
  196. return;
  197. }
  198. for (int i = 0; i < SplitData.Length; i++)
  199. {
  200. switch (i.ToString())
  201. {
  202. case "0":
  203. Data.Add("PRCODE", SplitData[i]);
  204. break;
  205. case "1":
  206. Data.Add("QTY", SplitData[i]);
  207. break;
  208. case "2":
  209. Data.Add("DATECODE", SplitData[i]);
  210. break;
  211. case "3":
  212. Data.Add("BRAND", SplitData[i]);
  213. break;
  214. case "4":
  215. Data.Add("LOTNO", SplitData[i]);
  216. break;
  217. case "5":
  218. Data.Add("PO", SplitData[i]);
  219. break;
  220. case "6":
  221. Data.Add("SERIAL", SplitData[i]);
  222. break;
  223. default:
  224. break;
  225. }
  226. }
  227. //校验DateCode是否过期
  228. if (!CheckDateCode(Data["DATECODE"]))
  229. {
  230. MessageBox.Show("物料" + Data["PRCODE"] + "【DateCode】超出校验日期");
  231. }
  232. if (Data["PRCODE"] != CurrentPrCode)
  233. {
  234. MessageBox.Show("当前采集【物料编号】不对应,请重新采集", "提示");
  235. Input.SelectAll();
  236. return;
  237. }
  238. if (Data["BRAND"] != CurrentBrand)
  239. {
  240. string close = MessageBox.Show(this.ParentForm, "当前采集【品牌】不对应,是否继续采集", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question).ToString();
  241. if (close != "Yes")
  242. {
  243. Input.SelectAll();
  244. return;
  245. }
  246. }
  247. int CodeCount = 0;
  248. //如果单位是KPCS则需要除1000
  249. double CollectNum = 0;
  250. if (CurrentUnit == "KPCS")
  251. {
  252. try
  253. {
  254. double.Parse(CurrentZXBZ);
  255. }
  256. catch (Exception)
  257. {
  258. MessageBox.Show("请检查最小包装数");
  259. }
  260. //如果单位是KPCS则必须是1000的整数倍
  261. if (Convert.ToDouble((double.Parse(Data["QTY"]) / 1000).ToString("0.000")) / Convert.ToDouble(double.Parse(CurrentZXBZ).ToString("0.000")) % 1 != 0)
  262. {
  263. MessageBox.Show("物料" + Data["PRCODE"] + "采集数量无法按照最小包装数拆分", "提示");
  264. Input.SelectAll();
  265. return;
  266. }
  267. CodeCount = int.Parse((double.Parse(Data["QTY"]) / 1000 / double.Parse(CurrentZXBZ)).ToString());
  268. CollectNum = double.Parse(Data["QTY"]) / 1000;
  269. }
  270. else
  271. {
  272. if (double.Parse(Data["QTY"]) % double.Parse(CurrentZXBZ) != 0)
  273. {
  274. MessageBox.Show("采集【数量】无法按照最小包装数拆分", "提示");
  275. Input.SelectAll();
  276. return;
  277. }
  278. CodeCount = int.Parse((double.Parse(Data["QTY"]) / double.Parse(CurrentZXBZ)).ToString());
  279. CollectNum = double.Parse(Data["QTY"]);
  280. }
  281. string pib_barcode = Data.ContainsKey("SERIAL") ? Data["SERIAL"] : "";
  282. //获取ID
  283. PIBID = dh.GetSEQ("prodiobarcode_seq", CodeCount);
  284. string pib_outboxcode2 = "";
  285. if (OutBoxNum.Text == "新增")
  286. {
  287. string maxoutbox = dh.getFieldDataByCondition("prodiobarcode", "max(to_number(pib_outboxcode2))", "pib_inoutno='" + pi_inoutno.Text + "'").ToString();
  288. //如果没有则从开始插入
  289. if (maxoutbox == "")
  290. {
  291. pib_outboxcode2 = "1";
  292. }
  293. else
  294. {
  295. pib_outboxcode2 = (int.Parse(maxoutbox) + 1).ToString();
  296. }
  297. }
  298. else
  299. {
  300. pib_outboxcode2 = OutBoxNum.Text;
  301. }
  302. if (OutBoxNum.Text == "全部")
  303. {
  304. MessageBox.Show("请选择指定箱号或者新增");
  305. return;
  306. }
  307. //计算当前采集数量
  308. string collectqty = dh.getFieldDataByCondition("prodiobarcode", "sum(pib_qty)", "pib_inoutno='" + pi_inoutno.Text + "' and pib_prodcode='" + CurrentPrCode + "' and pib_pdno='" + CurrentPDNO + "'").ToString();
  309. double CollectQty = (collectqty == "" ? 0 : double.Parse(collectqty));
  310. if (Convert.ToDouble((CollectQty + CollectNum).ToString("0.000")) > Convert.ToDouble(double.Parse(CurrentPrCount).ToString("0.000")))
  311. {
  312. MessageBox.Show("物料" + Data["PRCODE"] + "采集后数量为" + (CollectQty + CollectNum) + ",【超出】本行出货数量" + CurrentPrCount, "提示");
  313. Input.SelectAll();
  314. return;
  315. }
  316. GetBarCodeRule(out Prefix, out Suffix, out MaxNum, out NumLength, out Radix);
  317. List<string> CustBarCode = new List<string>();
  318. if (!(Radix > 0))
  319. {
  320. string close = MessageBox.Show(this.ParentForm, "未维护条码规则,是否继续生成", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question).ToString();
  321. if (close.ToString() != "Yes")
  322. return;
  323. }
  324. for (int i = 0; i < CodeCount; i++)
  325. {
  326. if (Radix > 0)
  327. {
  328. string serialcode = BaseUtil.DToAny(MaxNum, Radix);
  329. for (int j = serialcode.ToString().Length; j < NumLength; j++)
  330. {
  331. serialcode = "0" + serialcode;
  332. }
  333. CustBarCode.Add(Prefix + serialcode + Suffix);
  334. MaxNum = MaxNum + 1;
  335. }
  336. else
  337. {
  338. CustBarCode.Add("");
  339. }
  340. }
  341. sql.Clear();
  342. sql.Append("insert into prodiobarcode(PIB_ID,PIB_PRODCODE,PIB_INDATE,PIB_INOUTNO,PIB_PIID,PIB_PDNO, PIB_PDID,PIB_PICLASS,");
  343. sql.Append("PIB_BARCODE,PIB_CUSTBARCODE,PIB_QTY,pib_brand,pib_datecode,pib_lotno,PIB_OUTBOXCODE2,pib_inman,PIB_IFPRINT,PIB_ORDERCODE,PIB_CUSTPO,pib_remark,pib_midcapatity,pib_custcode) ");
  344. sql.Append("select :PIB_ID,pd_prodcode,sysdate,pi_inoutno,pi_id,pd_pdno,pd_id,pi_class,");
  345. sql.Append("'" + pib_barcode + "',:PIB_CUSTBARCODE,'" + CurrentZXBZ + "','" + Data["BRAND"] + "','" + Data["DATECODE"] + "','" + Data["LOTNO"] + "','" + pib_outboxcode2 + "','" + User.UserCode + "','" + (EnablePrint && SingleLabelAutoPrint.Checked ? 1 : 0).ToString() + "',pd_ordercode,pd_pocode,pd_remark,'" + MidboxCapacity.Value + "','" + pi_cardcode.Text + "' ");
  346. sql.Append("from prodinout left join prodiodetail on pi_id=pd_piid left join PRODJOINVENDDETAIL on pjd_brand =pd_brand and pjd_prodcode=pd_prodcode where pi_id='" + PI_ID + "' and pd_prodcode='" + CurrentPrCode + "' and pd_pdno='" + CurrentPDNO + "'");
  347. dh.BatchInsert(sql.ToString(), new string[] { "PIB_ID", "PIB_CUSTBARCODE" }, PIBID, CustBarCode.ToArray());
  348. //更新流水号
  349. dh.UpdateByCondition("RULEMAXNUM", "rmn_maxnumber='" + (MaxNum) + "'", "rmn_nrcode='" + (pi_cardcode.Text == "" ? "Default" : pi_cardcode.Text) + "' and rmn_prefix='" + Prefix + "'");
  350. LoadGridData(new object(), new EventArgs());
  351. //加载完数据之后进行容量的判断
  352. int BoxNum = LabelInfDataTable.Select("pib_outboxcode2='" + OutBoxNum.Text + "'").Length;
  353. if (BoxNum > OutboxCapacity.Value)
  354. {
  355. MessageBox.Show("箱号【" + OutBoxNum.Text + "】超出容量,当前已采集" + BoxNum, "提示");
  356. }
  357. if (SingleLabelAutoPrint.Checked)
  358. {
  359. thread = new Thread(AutoPrintSingleLabel);
  360. stw = new SetLoadingWindow(thread, "正在打印单盘标签");
  361. BaseUtil.SetFormCenter(stw);
  362. stw.ShowDialog();
  363. }
  364. //采集后重新计数,自动跳到下一行
  365. collectqty = (SumQty.Compute("sum(pib_qty)", "pib_prodcode='" + CurrentPrCode + "' and pib_pdno='" + CurrentPDNO + "'").ToString());
  366. CollectQty = (collectqty == "" ? 0 : double.Parse(collectqty));
  367. //采集达到了数量进行换行
  368. if (CollectQty == double.Parse(CurrentPrCount))
  369. {
  370. DataGridViewSelectedRowCollection selectrow = GridPrcode.SelectedRows;
  371. if (selectrow.Count > 0)
  372. {
  373. if (selectrow[0].Index + 1 < GridPrcode.Rows.Count)
  374. {
  375. string outqty = GridPrcode.Rows[selectrow[0].Index + 1].Cells["pd_outqty"].Value.ToString();
  376. string collectnum = GridPrcode.Rows[selectrow[0].Index + 1].Cells["CollectedNum"].Value.ToString();
  377. if (double.Parse(outqty) > double.Parse(collectnum == "" ? "0" : collectnum))
  378. {
  379. GridPrcode.Rows[selectrow[0].Index + 1].Selected = true;
  380. }
  381. }
  382. }
  383. }
  384. Input.Clear();
  385. if (OutBoxNum.Text == "新增")
  386. {
  387. OutBoxNum.Items.Clear();
  388. DataTable dt = (DataTable)dh.ExecuteSql("select distinct pib_outboxcode2 from prodiobarcode where pib_inoutno='" + pi_inoutno.Text + "' order by to_number(pib_outboxcode2) desc", "select");
  389. ItemObject io = new ItemObject("新增", "新增");
  390. OutBoxNum.Items.Add(io);
  391. io = new ItemObject("全部", "全部");
  392. OutBoxNum.Items.Add(io);
  393. for (int i = 0; i < dt.Rows.Count; i++)
  394. {
  395. string piboutboxcode2 = dt.Rows[i]["pib_outboxcode2"].ToString();
  396. io = new ItemObject(piboutboxcode2, piboutboxcode2);
  397. OutBoxNum.Items.Add(io);
  398. }
  399. if (OutBoxNum.Items.Count > 2)
  400. OutBoxNum.SelectedIndex = 2;
  401. }
  402. }
  403. private void AutoPrintSingleLabel()
  404. {
  405. if (EnablePrint)
  406. {
  407. //用标签本身的变量作为最外层的循环条件去匹配;
  408. StringBuilder ParamLog = new StringBuilder();
  409. string pibid = "";
  410. for (int i = 0; i < PIBID.Length; i++)
  411. {
  412. if (i != PIBID.Length - 1)
  413. pibid += PIBID[i] + ",";
  414. else
  415. pibid += PIBID[i];
  416. }
  417. if (!SingleLabelCombox.SelectedValue.ToString().Contains("System.Data.DataRowView"))
  418. SingleReport.Load(SingleLabelCombox.SelectedValue.ToString());
  419. for (int j = 0; j < SingleReport.Parameters.Count; j++)
  420. {
  421. SingleReport.SetParameterValue(SingleReport.Parameters[j].Name, "");
  422. for (int k = 0; k < Attach.Rows.Count; k++)
  423. {
  424. if (Attach.Rows[k][0].ToString() == SingleReport.Parameters[j].Name)
  425. {
  426. SingleReport.SetParameterValue(SingleReport.Parameters[j].Name, Attach.Rows[k][1].ToString());
  427. }
  428. }
  429. }
  430. DataTable dt = (DataTable)dh.ExecuteSql("select * from prodiosingleinfo_view where 主键ID in (" + pibid + ")", "select");
  431. SingleReport.RegisterData(dt, "prodiosingleinfo_view");
  432. SingleReport.GetDataSource("prodiosingleinfo_view").Enabled = true;
  433. SingleReport.PrintSettings.ShowDialog = false;
  434. SingleReport.PrintSettings.Printer = SingleLabelPrinter.Text;
  435. try
  436. {
  437. SingleReport.Print();
  438. }
  439. catch (Exception e)
  440. {
  441. MessageBox.Show(e.Message);
  442. return;
  443. }
  444. Properties.Settings.Default.SPrinter = SingleLabelPrinter.Text;
  445. Properties.Settings.Default.Save();
  446. LogManager.DoCommandLog(pi_inoutno.Text, User.UserCode, "自动打印箱标", "打印成功");
  447. }
  448. }
  449. //关闭窗口前提示用户确认
  450. private void 贴标机条码打印_FormClosing(object sender, FormClosingEventArgs e)
  451. {
  452. //如果不是注销的话
  453. if (!logout)
  454. {
  455. string close = MessageBox.Show(this.ParentForm, "是否关闭", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question).ToString();
  456. if (close.ToString() != "Yes")
  457. e.Cancel = true;
  458. else
  459. {
  460. LogManager.DoLog("关闭程序");
  461. }
  462. }
  463. }
  464. /// <summary>
  465. /// 获取打印标签
  466. /// </summary>
  467. private void GetInOutInfAndLabelFile()
  468. {
  469. ComBoxClickChangeLabelDoc = false;
  470. sql.Clear();
  471. sql.Append("select to_char(nvl(cl_date,sysdate),'YYYY-MM-DD HH24:Mi:SS') cl_date,cl_labelurl,cl_labelname,cl_isdefault,la_id||'#'||cl_labelurl||'#'||to_char(cl_date,'YYYY-MM-DD HH24:Mi:SS') la_id,cl_custcode from customerlabel left join prodinout on pi_cardcode=cl_custcode ");
  472. sql.Append("left join customer on cu_code=cl_custcode left join label on la_code=CL_LABELCODE where ((pi_cardcode='" + pi_cardcode.Text + "' ");
  473. sql.Append("and pi_inoutno='" + pi_inoutno.Text + "') or( cl_custcode is null)) and cl_labeltype='单盘' order by cl_custcode,cl_date desc");
  474. dt = (DataTable)dh.ExecuteSql(sql.ToString(), "select");
  475. SingleLabelCombox.DisplayMember = "cl_labelname";
  476. SingleLabelCombox.ValueMember = "cl_labelurl";
  477. SingleLabelCombox.DataSource = dt;
  478. if (SingleLabelCombox.Text != "")
  479. {
  480. if (!SingleLabelCombox.SelectedValue.ToString().Contains("System.Data.DataRowView"))
  481. SingleReport.Load(SingleLabelCombox.SelectedValue.ToString());
  482. }
  483. sql.Clear();
  484. sql.Append("select to_char(nvl(cl_date,sysdate),'YYYY-MM-DD HH24:Mi:SS') cl_date,cl_labelurl,cl_labelname,cl_isdefault,la_id||'#'||cl_labelurl||'#'||to_char(cl_date,'YYYY-MM-DD HH24:Mi:SS') la_id,cl_custcode from customerlabel left join prodinout on pi_cardcode=cl_custcode ");
  485. sql.Append("left join customer on cu_code=cl_custcode left join label on la_code=CL_LABELCODE where ((pi_cardcode='" + pi_cardcode.Text + "' ");
  486. sql.Append("and pi_inoutno='" + pi_inoutno.Text + "') or( cl_custcode is null)) and cl_labeltype='中盒' order by cl_custcode,cl_date desc");
  487. dt = (DataTable)dh.ExecuteSql(sql.ToString(), "select");
  488. MidLabelCombox.DisplayMember = "cl_labelname";
  489. MidLabelCombox.ValueMember = "cl_labelurl";
  490. MidLabelCombox.DataSource = dt;
  491. if (MidLabelCombox.Text != "")
  492. {
  493. if (!MidLabelCombox.SelectedValue.ToString().Contains("System.Data.DataRowView"))
  494. MidReport.Load(MidLabelCombox.SelectedValue.ToString());
  495. }
  496. sql.Clear();
  497. sql.Append("select to_char(nvl(cl_date,sysdate),'YYYY-MM-DD HH24:Mi:SS') cl_date,cl_labelurl,cl_labelname,cl_isdefault,la_id||'#'||cl_labelurl||'#'||to_char(cl_date,'YYYY-MM-DD HH24:Mi:SS') la_id,cl_custcode from customerlabel left join prodinout on pi_cardcode=cl_custcode ");
  498. sql.Append("left join customer on cu_code=cl_custcode left join label on la_code=CL_LABELCODE where ((pi_cardcode='" + pi_cardcode.Text + "' ");
  499. sql.Append("and pi_inoutno='" + pi_inoutno.Text + "') or( cl_custcode is null)) and cl_labeltype='外箱' order by cl_custcode,cl_date desc");
  500. dt = (DataTable)dh.ExecuteSql(sql.ToString(), "select");
  501. OutBoxCombox.DisplayMember = "cl_labelname";
  502. OutBoxCombox.ValueMember = "cl_labelurl";
  503. OutBoxCombox.DataSource = dt;
  504. if (OutBoxCombox.Text != "")
  505. {
  506. if (!OutBoxCombox.SelectedValue.ToString().Contains("System.Data.DataRowView"))
  507. OutReport.Load(OutBoxCombox.SelectedValue.ToString());
  508. }
  509. FootReport.Load(@"\\10.2.10.238\PRINTE\FASTREPORT\唛头.frx");
  510. ComBoxClickChangeLabelDoc = true;
  511. }
  512. /// <summary>
  513. /// 出入库单录入框的回车事件
  514. /// </summary>
  515. /// <param name="sender"></param>
  516. /// <param name="e"></param>
  517. private void pi_inoutno_KeyDown(object sender, KeyEventArgs e)
  518. {
  519. if (e.KeyCode == Keys.Enter)
  520. {
  521. Combindetail.Checked = false;
  522. Input.Clear();
  523. sql.Clear();
  524. sql.Append("select pi_id,pi_cardcode,pi_title,to_char(pi_date,'yyyymmdd')pi_date from prodinout where pi_inoutno='" + pi_inoutno.Text + "' and pi_invostatuscode='AUDITED'");
  525. dt = (DataTable)dh.ExecuteSql(sql.ToString(), "select");
  526. if (dt.Rows.Count > 0)
  527. {
  528. pi_cardcode.Text = dt.Rows[0]["pi_cardcode"].ToString();
  529. pi_title.Text = dt.Rows[0]["pi_title"].ToString();
  530. if (pi_cardcode.Text != "ZGCC")
  531. {
  532. CustomerLabel.Enabled = false;
  533. }
  534. else
  535. {
  536. CustomerLabel.Enabled = true;
  537. }
  538. pi_date.Text = dt.Rows[0]["pi_date"].ToString();
  539. PI_ID = dt.Rows[0]["pi_id"].ToString();
  540. OutBoxNum_Click(new object(), new EventArgs());
  541. LoadGridData(sender, e);
  542. LoadPrcodeData();
  543. //获取条码规则
  544. GetBarCodeRule(out Prefix, out Suffix, out MaxNum, out NumLength, out Radix);
  545. SingleID.Clear();
  546. Input.Focus();
  547. ////从后往前找未采集的行
  548. for (int i = GridPrcode.Rows.Count - 1; i >= 0; i--)
  549. {
  550. string outqty = GridPrcode.Rows[i].Cells["pd_outqty"].Value.ToString();
  551. string collectnum = GridPrcode.Rows[i].Cells["CollectedNum"].Value.ToString();
  552. if (double.Parse(outqty) > double.Parse(collectnum == "" ? "0" : collectnum))
  553. {
  554. GridPrcode.Rows[i].Selected = true;
  555. if (i - 2 >= 0)
  556. GridPrcode.FirstDisplayedScrollingRowIndex = i - 2;
  557. else
  558. GridPrcode.FirstDisplayedScrollingRowIndex = i;
  559. }
  560. }
  561. bi_inman.Text = dh.getFieldDataByCondition("barcodeio left join employee on bi_inman=em_code", "wm_concat(distinct em_name)", "bi_piid=" + PI_ID).ToString();
  562. pib_inman.Text = dh.getFieldDataByCondition("prodiobarcode left join employee on pib_inman=em_code", "wm_concat(distinct em_name)", "pib_piid=" + PI_ID).ToString();
  563. Attach = (DataTable)dh.ExecuteSql("select lap_param lp_name,lap_value lp_sql from LABELATTACHPARAMETER where lap_custcode='" + pi_cardcode.Text + "' and lap_inman='" + User.UserCode + "'", "select");
  564. thread = new Thread(GetInOutInfAndLabelFile);
  565. stw = new SetLoadingWindow(thread, "正在获取打印标签");
  566. BaseUtil.SetFormCenter(stw);
  567. stw.ShowDialog();
  568. LogManager.DoLog("输入单号【" + pi_inoutno.Text + "】");
  569. }
  570. else MessageBox.Show("当前出入库单号不存在或者未审核!", "提示");
  571. }
  572. }
  573. private void SingleBoxPrint()
  574. {
  575. if (EnablePrint)
  576. {
  577. if (LabelInf.Rows.Count > 0)
  578. {
  579. //每次打印清除之前缓存的行号和ID,后面会判断需要打印的数据重新加载
  580. SingleID.Clear();
  581. //获取全部的中盒号
  582. Dictionary<string, bool> outboxcode1 = new Dictionary<string, bool>();
  583. //判断所有盒号为该盒的是否勾选已采集
  584. outboxcode1.Add(LabelInf.Rows[0].Cells["pib_outboxcode1"].Value.ToString(), true);
  585. for (int i = 0; i < LabelInf.Rows.Count; i++)
  586. {
  587. if (!SingleID.Contains(LabelInf.Rows[i].Cells["pib_id1"].Value.ToString()))
  588. SingleID.Add(LabelInf.Rows[i].Cells["pib_id1"].Value.ToString());
  589. }
  590. if (SingleID.ToArray().Length == 0)
  591. {
  592. MessageBox.Show("选择的行未勾选采集或者已打印", "提示");
  593. return;
  594. }
  595. for (int i = 0; i < LabelInf.RowCount; i++)
  596. {
  597. if (i + 1 < LabelInf.RowCount)
  598. {
  599. //如果本行的中盒号和下一行不相等的话
  600. if (LabelInf.Rows[i].Cells["pib_outboxcode1"].Value.ToString() != LabelInf.Rows[i + 1].Cells["pib_outboxcode1"].Value.ToString())
  601. {
  602. if (!outboxcode1.ContainsKey(LabelInf.Rows[i + 1].Cells["pib_outboxcode1"].Value.ToString()))
  603. outboxcode1.Add(LabelInf.Rows[i + 1].Cells["pib_outboxcode1"].Value.ToString(), true);
  604. }
  605. }
  606. }
  607. string pibid = "";
  608. for (int i = 0; i < LabelInf.RowCount; i++)
  609. {
  610. //勾选了并且未打印
  611. if (LabelInf.Rows[i].Cells["Choose"].FormattedValue != null && LabelInf.Rows[i].Cells["Choose"].FormattedValue.ToString().ToLower() == "true")
  612. {
  613. pibid += LabelInf.Rows[i].Cells["pib_id1"].Value.ToString() + ",";
  614. LabelInf.Rows[i].Cells["pib_ifprint"].Value = true;
  615. }
  616. }
  617. if (pibid != "")
  618. {
  619. if (!SingleLabelCombox.SelectedValue.ToString().Contains("System.Data.DataRowView"))
  620. SingleReport.Load(SingleLabelCombox.SelectedValue.ToString());
  621. for (int j = 0; j < SingleReport.Parameters.Count; j++)
  622. {
  623. SingleReport.SetParameterValue(SingleReport.Parameters[j].Name, "");
  624. for (int k = 0; k < Attach.Rows.Count; k++)
  625. {
  626. if (Attach.Rows[k][0].ToString() == SingleReport.Parameters[j].Name)
  627. {
  628. SingleReport.SetParameterValue(SingleReport.Parameters[j].Name, Attach.Rows[k][1].ToString());
  629. }
  630. }
  631. }
  632. DataTable dt = (DataTable)dh.ExecuteSql("select * from prodiosingleinfo_view where 主键ID in (" + pibid.Substring(0, pibid.Length - 1) + ")", "select");
  633. SingleReport.RegisterData(dt, "prodiosingleinfo_view");
  634. SingleReport.GetDataSource("prodiosingleinfo_view").Enabled = true;
  635. //保存参数打印
  636. SingleReport.PrintSettings.ShowDialog = false;
  637. SingleReport.PrintSettings.Printer = SingleLabelPrinter.Text;
  638. try
  639. {
  640. SingleReport.Print();
  641. }
  642. catch (Exception e)
  643. {
  644. MessageBox.Show(e.Message);
  645. return;
  646. }
  647. Properties.Settings.Default.SPrinter = SingleLabelPrinter.Text;
  648. Properties.Settings.Default.Save();
  649. }
  650. else
  651. {
  652. MessageBox.Show("未勾选打印明细", "提示", MessageBoxButtons.OK, MessageBoxIcon.None, MessageBoxDefaultButton.Button1, MessageBoxOptions.ServiceNotification);
  653. }
  654. LogManager.DoCommandLog(pi_inoutno.Text, User.UserCode, "手动打印箱标", "打印成功");
  655. dh.BatchInsert("update prodiobarcode set pib_printdate=sysdate where pib_id=:pib_id", new string[] { "pib_id" }, SingleID.ToArray());
  656. outboxcode1.Clear();
  657. }
  658. else
  659. {
  660. MessageBox.Show("此模板尚未维护参数或不存在打印明细", "提示");
  661. return;
  662. }
  663. }
  664. }
  665. private void SingleLabelPrint_Click(object sender, EventArgs e)
  666. {
  667. if (SingleLabelCombox.Text != "")
  668. {
  669. if (SingleBoxBegin.Text != "" || SingleBoxEnd.Text != "")
  670. {
  671. try
  672. {
  673. int begin = int.Parse(SingleBoxBegin.Text == "" ? "1" : SingleBoxBegin.Text);
  674. int end = int.Parse(SingleBoxEnd.Text == "" ? LabelInf.Rows.Count.ToString() : SingleBoxEnd.Text);
  675. if (begin > 0 && end <= LabelInf.Rows.Count && begin <= end)
  676. {
  677. for (int i = begin - 1; i < end; i++)
  678. {
  679. LabelInf.Rows[i].Cells["Choose"].Value = true;
  680. LabelInf.Rows[i].Cells["pib_ifprint"].Value = false;
  681. }
  682. }
  683. else
  684. {
  685. MessageBox.Show("单盘打印范围错误", "提示");
  686. return;
  687. }
  688. }
  689. catch (Exception)
  690. {
  691. MessageBox.Show("单盘打印范围错误", "提示");
  692. return;
  693. }
  694. }
  695. thread = new Thread(SingleBoxPrint);
  696. stw = new SetLoadingWindow(thread, "正在打印单盘");
  697. BaseUtil.SetFormCenter(stw);
  698. stw.ShowDialog();
  699. Input.Focus();
  700. }
  701. else
  702. {
  703. MessageBox.Show("未维护单盘标签", "提示");
  704. LogManager.DoCommandLog(pi_inoutno.Text, User.UserCode, "手动打印箱标", "打印失败,未维护标签");
  705. }
  706. }
  707. private void MidBoxLabelPrint()
  708. {
  709. //未输入内容打印全部中盒
  710. if (MidLabelNum.Text == "")
  711. {
  712. int begin = 0;
  713. int end = 0;
  714. if (MidBoxBegin.Text != "" || MidBoxEnd.Text != "")
  715. {
  716. try
  717. {
  718. begin = int.Parse(MidBoxBegin.Text == "" ? "1" : MidBoxBegin.Text);
  719. end = int.Parse(MidBoxEnd.Text == "" ? LabelInf.Rows[LabelInf.Rows.Count - 1].Cells["pib_outboxcode1"].Value.ToString() : MidBoxEnd.Text);
  720. int minmidbox = int.Parse(LabelInf.Rows[0].Cells["pib_outboxcode1"].Value.ToString());
  721. int maxmidbox = int.Parse(LabelInf.Rows[LabelInf.Rows.Count - 1].Cells["pib_outboxcode1"].Value.ToString());
  722. if (begin >= minmidbox && end <= maxmidbox && begin <= end)
  723. {
  724. //设置中盒打印范围的行号
  725. for (int i = 0; i < LabelInf.Rows.Count; i++)
  726. {
  727. if (int.Parse(LabelInf.Rows[i].Cells["pib_outboxcode1"].Value.ToString()) == begin)
  728. {
  729. begin = i;
  730. }
  731. if (int.Parse(LabelInf.Rows[i].Cells["pib_outboxcode1"].Value.ToString()) == end)
  732. {
  733. end = i;
  734. }
  735. }
  736. }
  737. else
  738. {
  739. MessageBox.Show("中盒打印范围错误", "提示");
  740. return;
  741. }
  742. }
  743. catch (Exception)
  744. {
  745. MessageBox.Show("中盒打印范围错误", "提示");
  746. return;
  747. }
  748. }
  749. List<int> MidOutBoxCode = new List<int>();
  750. List<int> MidOutBoxCodeIndex = new List<int>();
  751. for (int i = (begin == 0 ? 0 : begin); i <= (end == 0 ? LabelInf.Rows.Count - 1 : end); i++)
  752. {
  753. try
  754. {
  755. if (!MidOutBoxCode.Contains(int.Parse(LabelInf.Rows[i].Cells["pib_outboxcode1"].Value.ToString())))
  756. {
  757. MidOutBoxCode.Add(int.Parse(LabelInf.Rows[i].Cells["pib_outboxcode1"].Value.ToString()));
  758. MidOutBoxCodeIndex.Add(i);
  759. }
  760. }
  761. catch (Exception)
  762. {
  763. MessageBox.Show("请先封箱!");
  764. return;
  765. }
  766. }
  767. //如果有选中行
  768. if (SelectRowIndex >= 0)
  769. {
  770. MidOutBoxCode.Clear();
  771. MidOutBoxCodeIndex.Clear();
  772. SelectProdcode = LabelInf.Rows[SelectRowIndex].Cells["pib_prodcode"].Value.ToString();
  773. SelectMidBoxCode = LabelInf.Rows[SelectRowIndex].Cells["pib_outboxcode1"].Value.ToString();
  774. for (int i = SelectRowIndex; i >= 0; i--)
  775. {
  776. if (LabelInf.Rows[i].Cells["pib_prodcode"].Value.ToString() == SelectProdcode && SelectMidBoxCode == LabelInf.Rows[i].Cells["pib_outboxcode1"].Value.ToString())
  777. {
  778. if (!MidOutBoxCode.Contains(int.Parse(LabelInf.Rows[i].Cells["pib_outboxcode1"].Value.ToString())))
  779. {
  780. MidOutBoxCode.Add(int.Parse(LabelInf.Rows[i].Cells["pib_outboxcode1"].Value.ToString()));
  781. MidOutBoxCodeIndex.Add(i);
  782. }
  783. }
  784. else
  785. {
  786. break;
  787. }
  788. }
  789. for (int i = SelectRowIndex; i < LabelInf.Rows.Count - 1; i++)
  790. {
  791. if (LabelInf.Rows[i].Cells["pib_prodcode"].Value.ToString() == SelectProdcode && SelectMidBoxCode == LabelInf.Rows[i].Cells["pib_outboxcode1"].Value.ToString())
  792. {
  793. if (!MidOutBoxCode.Contains(int.Parse(LabelInf.Rows[i].Cells["pib_outboxcode1"].Value.ToString())))
  794. {
  795. MidOutBoxCode.Add(int.Parse(LabelInf.Rows[i].Cells["pib_outboxcode1"].Value.ToString()));
  796. MidOutBoxCodeIndex.Add(i);
  797. }
  798. }
  799. else
  800. {
  801. break;
  802. }
  803. }
  804. }
  805. try
  806. {
  807. MidBoxCodePrint(MidOutBoxCodeIndex.ToArray());
  808. }
  809. catch (Exception e)
  810. {
  811. MessageBox.Show(e.Message);
  812. return;
  813. }
  814. return;
  815. }
  816. bool FindMidLabel = false;
  817. if (MidLabelCombox.SelectedValue != null)
  818. {
  819. //中盒号所在的行
  820. int MidLabelRowIndex = 0;
  821. //缓存中盒数据
  822. for (int i = 0; i < LabelInf.RowCount; i++)
  823. {
  824. if (MidLabelNum.Text == LabelInf.Rows[i].Cells["pib_outboxcode1"].Value.ToString())
  825. {
  826. //找到了输入的中盒号停止循环
  827. FindMidLabel = true;
  828. MidLabelRowIndex = i;
  829. }
  830. }
  831. int[] rowindx = new int[] { MidLabelRowIndex };
  832. //找到了指定的盒号
  833. if (FindMidLabel)
  834. MidBoxCodePrint(rowindx);
  835. else
  836. MessageBox.Show("该出入库单未找到该中盒号!", "提示");
  837. }
  838. else
  839. MessageBox.Show("未维护中盒模板", "提示");
  840. }
  841. private void MidLabelPrint_Click(object sender, EventArgs e)
  842. {
  843. if (MidLabelCombox.Text != "")
  844. {
  845. PackMidBox_Click(sender, e);
  846. thread = new Thread(MidBoxLabelPrint);
  847. stw = new SetLoadingWindow(thread, "正在打印中盒");
  848. BaseUtil.SetFormCenter(stw);
  849. stw.ShowDialog();
  850. }
  851. else
  852. MessageBox.Show("未维护中盒标签", "提示");
  853. }
  854. private void OutBoxPrint()
  855. {
  856. List<string> Outboxcode = new List<string>();
  857. //如果未勾选箱号则对勾选的数据的箱号进行整合
  858. if (OutBoxNum.Text == "" || OutBoxNum.Text == "全部")
  859. {
  860. for (int i = 0; i < LabelInf.RowCount; i++)
  861. {
  862. string outboxcode2 = LabelInf.Rows[i].Cells["pib_outboxcode2"].Value.ToString();
  863. //富为使用包装单的逻辑
  864. //如果不包含该箱号则进行添加
  865. if (!Outboxcode.Contains(outboxcode2))
  866. Outboxcode.Add(outboxcode2);
  867. }
  868. //按获取到的箱号列表进行打印
  869. if (Outboxcode.ToArray().Length > 0)
  870. {
  871. for (int i = 0; i < Outboxcode.ToArray().Length; i++)
  872. {
  873. for (int h = 0; h < LabelInf.RowCount; h++)
  874. {
  875. if (LabelInf.Rows[h].Cells["pib_outboxcode2"].Value.ToString() == Outboxcode.ToArray()[i])
  876. {
  877. OutBoxCodePrint(h);
  878. break;
  879. }
  880. }
  881. }
  882. }
  883. else
  884. {
  885. MessageBox.Show("请勾选需要打印的外箱", "提示");
  886. }
  887. }
  888. else
  889. {
  890. bool FindMidLabel = false;
  891. try
  892. {
  893. int OutBoxLabelRowIndex = 0;
  894. //查找是否存在该中盒号
  895. for (int i = 0; i < LabelInf.RowCount; i++)
  896. {
  897. if (OutBoxNum.Text == LabelInf.Rows[i].Cells["pib_outboxcode2"].Value.ToString())
  898. {
  899. //找到了输入的中盒号停止循环
  900. FindMidLabel = true;
  901. OutBoxLabelRowIndex = i;
  902. break;
  903. }
  904. }
  905. //找到了指定的盒号
  906. if (FindMidLabel)
  907. OutBoxCodePrint(OutBoxLabelRowIndex);
  908. else
  909. MessageBox.Show("该出入库单未找到该外箱号!", "提示");
  910. }
  911. catch (Exception) { }
  912. }
  913. Outboxcode.Clear();
  914. }
  915. private void MidBoxCodePrint(int[] rowindex)
  916. {
  917. if (EnablePrint)
  918. {
  919. string pib_outboxcode1 = "";
  920. for (int i = 0; i < rowindex.Length; i++)
  921. {
  922. if (i != rowindex.Length - 1)
  923. pib_outboxcode1 += "'" + LabelInf.Rows[rowindex[i]].Cells["pib_outboxcode1"].Value.ToString() + "'" + ",";
  924. else
  925. pib_outboxcode1 += "'" + LabelInf.Rows[rowindex[i]].Cells["pib_outboxcode1"].Value.ToString() + "'";
  926. }
  927. //名称相等的时候,取SQL进行值的查询
  928. DataTable dt;
  929. if (MidLabelAutoPrint.Checked)
  930. {
  931. dt = (DataTable)dh.ExecuteSql("select * from prodiomidinfo_view where 出货单号='" + pi_inoutno.Text + "' and 中盒号 in(" + pib_outboxcode1 + ")", "select");
  932. }
  933. else
  934. {
  935. dt = (DataTable)dh.ExecuteSql("select * from prodiomidinfo_view where 出货单号='" + pi_inoutno.Text + "' and 中盒号 in(" + pib_outboxcode1 + ") and 中盒标识='外'", "select");
  936. }
  937. if (dt.Rows.Count > 0)
  938. {
  939. if (!MidLabelCombox.SelectedValue.ToString().Contains("System.Data.DataRowView"))
  940. MidReport.Load(MidLabelCombox.SelectedValue.ToString());
  941. for (int j = 0; j < MidReport.Parameters.Count; j++)
  942. {
  943. MidReport.SetParameterValue(MidReport.Parameters[j].Name, "");
  944. for (int i = 0; i < Attach.Rows.Count; i++)
  945. {
  946. if (Attach.Rows[i][0].ToString() == MidReport.Parameters[j].Name)
  947. {
  948. MidReport.SetParameterValue(MidReport.Parameters[j].Name, Attach.Rows[i][1].ToString());
  949. }
  950. }
  951. }
  952. MidReport.RegisterData(dt, "prodiomidinfo_view");
  953. MidReport.GetDataSource("prodiomidinfo_view").Enabled = true;
  954. MidReport.PrintSettings.ShowDialog = false;
  955. MidReport.PrintSettings.Printer = MidLabelPrinter.Text;
  956. MidReport.Print();
  957. }
  958. Properties.Settings.Default.MPrinter = MidLabelPrinter.Text;
  959. Properties.Settings.Default.Save();
  960. }
  961. }
  962. /// <summary>
  963. /// 执行打印外箱号
  964. /// </summary>
  965. private void OutBoxCodePrint(int rowindex)
  966. {
  967. if (EnablePrint)
  968. {
  969. if (!OutBoxCombox.SelectedValue.ToString().Contains("System.Data.DataRowView"))
  970. OutReport.Load(OutBoxCombox.SelectedValue.ToString());
  971. for (int j = 0; j < OutReport.Parameters.Count; j++)
  972. {
  973. OutReport.SetParameterValue(OutReport.Parameters[j].Name, "");
  974. for (int i = 0; i < Attach.Rows.Count; i++)
  975. {
  976. if (Attach.Rows[i][0].ToString() == OutReport.Parameters[j].Name)
  977. {
  978. OutReport.SetParameterValue(OutReport.Parameters[j].Name, Attach.Rows[i][1].ToString());
  979. }
  980. }
  981. }
  982. string pib_outboxcode2 = LabelInf.Rows[rowindex].Cells["pib_outboxcode2"].Value.ToString();
  983. DataTable dt = (DataTable)dh.ExecuteSql("select * from prodiooutinfo_view where 出货单号='" + pi_inoutno.Text + "' and 外箱号='" + pib_outboxcode2 + "'", "select");
  984. OutReport.RegisterData(dt, "prodiooutinfo_view");
  985. OutReport.GetDataSource("prodiooutinfo_view").Enabled = true;
  986. OutReport.PrintSettings.ShowDialog = false;
  987. OutReport.PrintSettings.Printer = OutBoxPrinter.Text;
  988. OutReport.Print();
  989. Properties.Settings.Default.OPrinter = OutBoxPrinter.Text;
  990. Properties.Settings.Default.Save();
  991. }
  992. }
  993. private void CleanDetail_Click(object sender, EventArgs e)
  994. {
  995. if (dh.getFieldDataByCondition("prodinout", "pi_statuscode", "pi_inoutno='" + pi_inoutno.Text + "'").ToString() == "POSTED")
  996. {
  997. MessageBox.Show("单据" + pi_inoutno.Text + "已过账,不允许删除条码");
  998. return;
  999. }
  1000. ArrayList<string> DeleteID = new ArrayList<string>();
  1001. for (int i = 0; i < LabelInf.RowCount; i++)
  1002. {
  1003. if (LabelInf.Rows[i].Cells["Choose"].FormattedValue.ToString().ToLower() == "true")
  1004. DeleteID.Add(LabelInf.Rows[i].Cells["pib_id1"].Value.ToString());
  1005. }
  1006. //勾选了删除的明细之后
  1007. if (DeleteID.ToArray().Length > 0)
  1008. {
  1009. string close = MessageBox.Show(this.ParentForm, "删除后不可恢复,是否确认删除", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question).ToString();
  1010. if (close.ToString() == "Yes")
  1011. {
  1012. dh.BatchInsert("delete from prodiobarcode where pib_id=:pib_id", new string[] { "pib_id" }, DeleteID.ToArray());
  1013. LogManager.DoCommandLog(pi_inoutno.Text, User.UserCode, "删除明细", "删除明细成功");
  1014. MessageBox.Show("删除成功", "提示");
  1015. Input.Clear();
  1016. LoadPrcodeData();
  1017. LoadGridData(sender, e);
  1018. dh.UpdateByCondition("prodinout", "pi_user_packingstatus='Packing'", "pi_inoutno='" + pi_inoutno.Text + "'");
  1019. }
  1020. }
  1021. else
  1022. MessageBox.Show("尚未勾选需要删除的明细", "提示");
  1023. }
  1024. private void OutBoxLabelPrint_Click(object sender, EventArgs e)
  1025. {
  1026. if (OutBoxCombox.Text != "")
  1027. {
  1028. Pack_Click(sender, e);
  1029. thread = new Thread(OutBoxPrint);
  1030. stw = new SetLoadingWindow(thread, "正在打印外箱");
  1031. BaseUtil.SetFormCenter(stw);
  1032. stw.ShowDialog();
  1033. Input.Focus();
  1034. }
  1035. else
  1036. MessageBox.Show("未维护外箱标签", "提示");
  1037. }
  1038. private void LoadGridData()
  1039. {
  1040. LoadGridData(new object(), new EventArgs());
  1041. }
  1042. /// <summary>
  1043. /// 自定义函数 加载明细行的数据,多处使用添加进函数
  1044. /// </summary>
  1045. /// <param name="sender"></param>
  1046. /// <param name="e"></param>
  1047. private void LoadGridData(object sender, EventArgs e)
  1048. {
  1049. AllChecked = false;
  1050. sql.Clear();
  1051. sql.Append("select pd_custprodcode,pd_custprodspec,pib_custmidboxcode,pd_pocode,pjd_orispeccode,pib_madein,pib_custbarcode,pib_custoutboxcode,pib_id,pib_datecode1,pib_pdid,pib_piid,");
  1052. sql.Append("pib_pdno,pib_prodcode,pib_brand,pr_vendprodcode,pib_lotno,pib_datecode,week_to_date(pib_datecode) datecode1,pib_qty,pr_spec,");
  1053. sql.Append("pr_zxbzs,pr_unit,pib_barcode,pib_outboxcode1,pib_outboxcode2,nvl(pib_ifprint,0)pib_ifprint from prodiobarcode left join ");
  1054. sql.Append("prodiodetail on pib_piid=pd_piid and pd_pdno=pib_pdno and pd_prodcode=pib_prodcode left join product on pr_code=pib_prodcode ");
  1055. sql.Append("left join sale on sa_code=pib_ordercode left join PRODJOINVENDDETAIL on pjd_brand =pd_brand and pjd_prodcode=pd_prodcode where pib_piid='" + PI_ID + "' ");
  1056. if (OutBoxNum.Text != "全部")
  1057. {
  1058. sql.Append(" and pib_outboxcode2='" + OutBoxNum.Text + "' ");
  1059. }
  1060. sql.Append(" order by to_number(pib_outboxcode2),pib_id,pd_prodcode");
  1061. LabelInfDataTable = (DataTable)dh.ExecuteSql(sql.ToString(), "select");
  1062. BaseUtil.FillDgvWithDataTable(LabelInf, LabelInfDataTable);
  1063. if (LabelInf.Rows.Count > 0)
  1064. {
  1065. LabelInf.FirstDisplayedScrollingRowIndex = LabelInf.Rows.Count - 1;
  1066. LabelInf.Rows[LabelInf.Rows.Count - 1].Selected = true;
  1067. }
  1068. double CollectNum = 0;
  1069. double OutNum = 0;
  1070. sql.Clear();
  1071. sql.Append("select pib_pdno,pib_prodcode,sum(pib_qty) pib_qty from prodiodetail left join prodiobarcode on pd_id=pib_pdid and pd_pdno=pib_pdno ");
  1072. sql.Append("where pib_inoutno='" + pi_inoutno.Text + "' group by pib_prodcode,pib_pdno order by pib_pdno ");
  1073. SumQty = (DataTable)dh.ExecuteSql(sql.ToString(), "select");
  1074. for (int i = 0; i < GridPrcode.Rows.Count; i++)
  1075. {
  1076. string CurrentPrCode = GridPrcode.Rows[i].Cells["pd_prodcode"].Value.ToString();
  1077. string CurrentPDNO = GridPrcode.Rows[i].Cells["pd_pdno"].Value.ToString();
  1078. string CurrentOutQTY = GridPrcode.Rows[i].Cells["pd_outqty"].Value.ToString();
  1079. string collectqty = (SumQty.Compute("sum(pib_qty)", "pib_prodcode='" + CurrentPrCode + "' and pib_pdno='" + CurrentPDNO + "'").ToString());
  1080. CollectNum += double.Parse(collectqty == "" ? "0" : collectqty);
  1081. OutNum += double.Parse(CurrentOutQTY);
  1082. GridPrcode.Rows[i].Cells["CollectedNum"].Value = collectqty == "" ? "0" : collectqty; ;
  1083. GridPrcode.Rows[i].Cells["UnCollectedNum"].Value = Convert.ToDouble(double.Parse(GridPrcode.Rows[i].Cells["pd_outqty"].Value.ToString()) - double.Parse(collectqty == "" ? "0" : collectqty)).ToString("0.000");
  1084. }
  1085. ProcessCount.Text = CollectNum + "/" + OutNum;
  1086. if (CollectNum == OutNum)
  1087. {
  1088. dh.UpdateByCondition("prodinout", "pi_user_packingstatus='Packed'", "pi_inoutno='" + pi_inoutno.Text + "'");
  1089. }
  1090. }
  1091. private void Refresh_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
  1092. {
  1093. KeyEventArgs e2 = new KeyEventArgs(Keys.Enter);
  1094. pi_inoutno_KeyDown(sender, e2);
  1095. }
  1096. private void LogingOut_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
  1097. {
  1098. string close = MessageBox.Show(this.ParentForm, "是否注销", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question).ToString();
  1099. if (close.ToString() == "Yes")
  1100. {
  1101. Login login = new Login();
  1102. //注销的时候需要将拼接的连接字符串置空
  1103. DataHelper.DBConnectionString = null;
  1104. logout = true;
  1105. this.Hide();
  1106. login.ShowDialog();
  1107. this.Close();
  1108. }
  1109. }
  1110. private void LabelInf_DataError(object sender, DataGridViewDataErrorEventArgs e) { }
  1111. /// <summary>
  1112. /// 切换打开的单盘文件
  1113. /// </summary>
  1114. /// <param name="sender"></param>
  1115. /// <param name="e"></param>
  1116. private void SingleLabelCombox_SelectedIndexChanged(object sender, EventArgs e)
  1117. {
  1118. try
  1119. {
  1120. if (ComBoxClickChangeLabelDoc)
  1121. {
  1122. if (!SingleLabelCombox.SelectedValue.ToString().Contains("System.Data.DataRowView"))
  1123. SingleReport.Load(SingleLabelCombox.SelectedValue.ToString());
  1124. }
  1125. }
  1126. catch (Exception) { }
  1127. }
  1128. /// <summary>
  1129. /// 切换打开的中盒文件
  1130. /// </summary>
  1131. /// <param name="sender"></param>
  1132. /// <param name="e"></param>
  1133. private void MidLabelCombox_SelectedIndexChanged(object sender, EventArgs e)
  1134. {
  1135. try
  1136. {
  1137. if (ComBoxClickChangeLabelDoc)
  1138. {
  1139. if (!MidLabelCombox.SelectedValue.ToString().Contains("System.Data.DataRowView"))
  1140. MidReport.Load(MidLabelCombox.SelectedValue.ToString());
  1141. }
  1142. }
  1143. catch (Exception) { }
  1144. }
  1145. /// <summary>
  1146. /// 切换打开的外箱文件
  1147. /// </summary>
  1148. /// <param name="sender"></param>
  1149. /// <param name="e"></param>
  1150. private void OutBoxCombox_SelectedIndexChanged(object sender, EventArgs e)
  1151. {
  1152. try
  1153. {
  1154. if (ComBoxClickChangeLabelDoc)
  1155. {
  1156. if (!OutBoxCombox.SelectedValue.ToString().Contains("System.Data.DataRowView"))
  1157. OutReport.Load(OutBoxCombox.SelectedValue.ToString());
  1158. }
  1159. }
  1160. catch (Exception) { }
  1161. }
  1162. private void ChooseAll_Click(object sender, EventArgs e)
  1163. {
  1164. if (AllChecked)
  1165. {
  1166. foreach (DataGridViewRow dr in LabelInf.Rows)
  1167. dr.Cells[0].Value = false;
  1168. AllChecked = false;
  1169. }
  1170. else
  1171. {
  1172. foreach (DataGridViewRow dr in LabelInf.Rows)
  1173. dr.Cells[0].Value = true;
  1174. AllChecked = true;
  1175. }
  1176. }
  1177. private void ExportData_Click(object sender, EventArgs e)
  1178. {
  1179. ExportFileDialog.Description = "选择导出的路径";
  1180. DialogResult result = ExportFileDialog.ShowDialog();
  1181. if (result == DialogResult.OK)
  1182. {
  1183. ExcelHandler eh = new ExcelHandler();
  1184. DataTable dt = LabelInfDataTable.Copy();
  1185. for (int i = dt.Columns.Count - 1; i >= 0; i--)
  1186. {
  1187. for (int j = 0; j < LabelInf.Columns.Count; j++)
  1188. {
  1189. //去除ID列
  1190. if (dt.Columns[i].ColumnName.ToLower().Contains("id") || dt.Columns[i].ColumnName.ToLower() == "pib_barcode" || dt.Columns[i].ColumnName.ToLower() == "pib_pdno" || dt.Columns[i].ColumnName.ToLower() == "pib_ifprint" || dt.Columns[i].ColumnName.ToLower() == "pib_datecode1" || dt.Columns[i].ColumnName.ToLower() == "pr_vendprodcode")
  1191. {
  1192. dt.Columns.RemoveAt(i);
  1193. break;
  1194. }
  1195. switch (dt.Columns[i].ColumnName.ToLower())
  1196. {
  1197. case "pib_lotno":
  1198. dt.Columns[i].ColumnName = "批次号";
  1199. break;
  1200. case "pib_datecode":
  1201. dt.Columns[i].ColumnName = "生产年周";
  1202. break;
  1203. case "pib_custbarcode":
  1204. dt.Columns[i].ColumnName = "最小产品包装条码";
  1205. break;
  1206. case "datecode1":
  1207. dt.Columns[i].ColumnName = "生产日期";
  1208. break;
  1209. default:
  1210. break;
  1211. }
  1212. if (dt.Columns[i].ColumnName.ToLower() == LabelInf.Columns[j].DataPropertyName.ToLower())
  1213. {
  1214. dt.Columns[i].ColumnName = LabelInf.Columns[j].HeaderText;
  1215. break;
  1216. }
  1217. }
  1218. }
  1219. eh.ExportExcel(dt, ExportFileDialog.SelectedPath, pi_date.Text + "-" + pi_inoutno.Text);
  1220. string close = MessageBox.Show(this.ParentForm, "导出成功,是否打开文件", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question).ToString();
  1221. if (close.ToString() == "Yes")
  1222. Process.Start(ExportFileDialog.SelectedPath + "\\" + pi_date.Text + "-" + pi_inoutno.Text + ".xls");
  1223. }
  1224. }
  1225. private void AttachInfo_Click(object sender, EventArgs e)
  1226. {
  1227. if (pi_cardcode.Text != "")
  1228. {
  1229. 附件内容打印 att = new 附件内容打印(pi_cardcode.Text);
  1230. att.ShowDialog();
  1231. }
  1232. else MessageBox.Show("请先获取出库单信息", "提示");
  1233. }
  1234. private void MidBoxCapacity_Leave(object sender, EventArgs e)
  1235. {
  1236. NumericUpDown nup = (NumericUpDown)sender;
  1237. switch (nup.Name)
  1238. {
  1239. case "MidBoxCapacity":
  1240. Properties.Settings.Default.MidBoxCapacity = nup.Value;
  1241. Properties.Settings.Default.Save();
  1242. break;
  1243. case "OutboxCapacity":
  1244. Properties.Settings.Default.OutboxCapacity = nup.Value;
  1245. Properties.Settings.Default.Save();
  1246. break;
  1247. default:
  1248. break;
  1249. }
  1250. }
  1251. private void RefreshDBConnect_Tick(object sender, EventArgs e)
  1252. {
  1253. dh.ExecuteSql("select sysdate from dual", "select");
  1254. }
  1255. private void LoadPrcodeData()
  1256. {
  1257. GridPrcode.DataSource = (DataTable)dh.ExecuteSql("select pd_pdno,pd_custprodcode,pd_whcode,pd_prodcode,'0' CollectedNum,'0' UnCollectedNum,pd_outqty,pr_unit,pr_spec,pd_brand,pjd_zxbzs_user,pjd_id from prodiodetail left join prodinout on pi_id=pd_piid left join PRODJOINVENDDETAIL on pjd_brand =pd_brand and pjd_prodcode=pd_prodcode left join product on pd_prodcode=pr_code where pi_id='" + PI_ID + "' order by pd_pdno", "select");
  1258. List<int> RemoveIndex = new List<int>();
  1259. double CollectNum = 0;
  1260. double OutNum = 0;
  1261. if (Combindetail.Checked)
  1262. {
  1263. int CurrentIndex = 0;
  1264. for (int i = 0; i < GridPrcode.Rows.Count; i++)
  1265. {
  1266. string CurrentPrCode = GridPrcode.Rows[i].Cells["pd_prodcode"].Value.ToString();
  1267. string CurrentPDNO = GridPrcode.Rows[i].Cells["pd_pdno"].Value.ToString();
  1268. string CurrentOutQTY = GridPrcode.Rows[i].Cells["pd_outqty"].Value.ToString();
  1269. string collectqty = (SumQty.Compute("sum(pib_qty)", "pib_prodcode='" + CurrentPrCode + "' and pib_pdno='" + CurrentPDNO + "'").ToString());
  1270. CollectNum += double.Parse(collectqty == "" ? "0" : collectqty);
  1271. OutNum += double.Parse(CurrentOutQTY);
  1272. GridPrcode.Rows[i].Cells["CollectedNum"].Value = collectqty == "" ? "0" : collectqty;
  1273. GridPrcode.Rows[i].Cells["UnCollectedNum"].Value = Convert.ToDouble(double.Parse(GridPrcode.Rows[i].Cells["pd_outqty"].Value.ToString()) - double.Parse(collectqty == "" ? "0" : collectqty)).ToString("0.000");
  1274. }
  1275. for (int i = 0; i < GridPrcode.Rows.Count; i++)
  1276. {
  1277. if (i + 1 < GridPrcode.Rows.Count)
  1278. {
  1279. string BProdCode = GridPrcode.Rows[i].Cells["pd_prodcode"].Value.ToString();
  1280. string BCustProdCode = GridPrcode.Rows[i].Cells["pd_custprodcode1"].Value.ToString();
  1281. string BWhCode = GridPrcode.Rows[i].Cells["pd_whcode"].Value.ToString();
  1282. string BPrUnit = GridPrcode.Rows[i].Cells["pr_unit"].Value.ToString();
  1283. string BPrBrand = GridPrcode.Rows[i].Cells["pd_brand"].Value.ToString();
  1284. string FProdCode = GridPrcode.Rows[i + 1].Cells["pd_prodcode"].Value.ToString();
  1285. string FCustProdCode = GridPrcode.Rows[i + 1].Cells["pd_custprodcode1"].Value.ToString();
  1286. string FPrUnit = GridPrcode.Rows[i + 1].Cells["pr_unit"].Value.ToString();
  1287. string FrBrand = GridPrcode.Rows[i + 1].Cells["pd_brand"].Value.ToString();
  1288. string FWhCode = GridPrcode.Rows[i + 1].Cells["pd_whcode"].Value.ToString();
  1289. if (BProdCode == FProdCode && BPrBrand == FrBrand && BCustProdCode == FCustProdCode)
  1290. {
  1291. GridPrcode.Rows[CurrentIndex].Cells["pd_outqty"].Value = double.Parse(GridPrcode.Rows[CurrentIndex].Cells["pd_outqty"].Value.ToString()) + double.Parse(GridPrcode.Rows[i + 1].Cells["pd_outqty"].Value.ToString());
  1292. GridPrcode.Rows[CurrentIndex].Cells["CollectedNum"].Value = double.Parse(GridPrcode.Rows[CurrentIndex].Cells["CollectedNum"].Value.ToString()) + double.Parse(GridPrcode.Rows[i + 1].Cells["CollectedNum"].Value.ToString());
  1293. GridPrcode.Rows[CurrentIndex].Cells["UnCollectedNum"].Value = (double.Parse(GridPrcode.Rows[CurrentIndex].Cells["UnCollectedNum"].Value.ToString()) + double.Parse(GridPrcode.Rows[i + 1].Cells["UnCollectedNum"].Value.ToString())).ToString("0.000");
  1294. RemoveIndex.Add(i + 1);
  1295. }
  1296. else
  1297. {
  1298. CurrentIndex = i + 1;
  1299. }
  1300. }
  1301. }
  1302. foreach (int item in RemoveIndex.OrderByDescending(x => x))
  1303. {
  1304. GridPrcode.Rows.RemoveAt(item);
  1305. }
  1306. }
  1307. else
  1308. {
  1309. for (int i = 0; i < GridPrcode.Rows.Count; i++)
  1310. {
  1311. string CurrentPrCode = GridPrcode.Rows[i].Cells["pd_prodcode"].Value.ToString();
  1312. string CurrentPDNO = GridPrcode.Rows[i].Cells["pd_pdno"].Value.ToString();
  1313. string CurrentOutQTY = GridPrcode.Rows[i].Cells["pd_outqty"].Value.ToString();
  1314. string collectqty = (SumQty.Compute("sum(pib_qty)", "pib_prodcode='" + CurrentPrCode + "' and pib_pdno='" + CurrentPDNO + "'").ToString());
  1315. CollectNum += double.Parse(collectqty == "" ? "0" : collectqty);
  1316. OutNum += double.Parse(CurrentOutQTY);
  1317. GridPrcode.Rows[i].Cells["CollectedNum"].Value = collectqty == "" ? "0" : collectqty;
  1318. GridPrcode.Rows[i].Cells["UnCollectedNum"].Value = Convert.ToDouble(double.Parse(GridPrcode.Rows[i].Cells["pd_outqty"].Value.ToString()) - double.Parse(collectqty == "" ? "0" : collectqty)).ToString("0.000");
  1319. }
  1320. }
  1321. ProcessCount.Text = CollectNum + "/" + OutNum;
  1322. if (GridPrcode.Rows.Count > 0)
  1323. {
  1324. CurrentPrCode = GridPrcode.Rows[0].Cells["pd_prodcode"].Value.ToString();
  1325. CurrentZXBZ = GridPrcode.Rows[0].Cells["pjd_zxbzs_user"].Value.ToString();
  1326. CurrentUnit = GridPrcode.Rows[0].Cells["pr_unit"].Value.ToString();
  1327. CurrentPDNO = GridPrcode.Rows[0].Cells["pd_pdno"].Value.ToString();
  1328. CurrentPrCount = GridPrcode.Rows[0].Cells["pd_outqty"].Value.ToString();
  1329. CurrentBrand = GridPrcode.Rows[0].Cells["pd_brand"].Value.ToString();
  1330. GridPrcode.Rows[0].Selected = true;
  1331. }
  1332. }
  1333. private void OutBoxNum_Click(object sender, EventArgs e)
  1334. {
  1335. string OutBox = OutBoxNum.Text;
  1336. OutBoxNum.Items.Clear();
  1337. DataTable dt = (DataTable)dh.ExecuteSql("select distinct pib_outboxcode2 from prodiobarcode where pib_inoutno='" + pi_inoutno.Text + "' order by to_number(pib_outboxcode2) desc", "select");
  1338. ItemObject io = new ItemObject("新增", "新增");
  1339. OutBoxNum.Items.Add(io);
  1340. io = new ItemObject("全部", "全部");
  1341. OutBoxNum.Items.Add(io);
  1342. for (int i = 0; i < dt.Rows.Count; i++)
  1343. {
  1344. string pib_outboxcode2 = dt.Rows[i]["pib_outboxcode2"].ToString();
  1345. io = new ItemObject(pib_outboxcode2, pib_outboxcode2);
  1346. OutBoxNum.Items.Add(io);
  1347. }
  1348. if (OutBoxNum.Text == "新增" || OutBoxNum.Text == "")
  1349. {
  1350. if (dt.Rows.Count > 0)
  1351. OutBoxNum.SelectedIndex = 2;
  1352. else
  1353. OutBoxNum.SelectedIndex = 0;
  1354. }
  1355. if (OutBox != "新增" && OutBox != "")
  1356. OutBoxNum.Text = OutBox;
  1357. }
  1358. /// <summary>
  1359. /// 获取条码规则
  1360. /// </summary>
  1361. /// <param name="Type"></param>
  1362. /// <param name="Prefix"></param>
  1363. /// <param name="Suffix"></param>
  1364. /// <param name="MaxNum"></param>
  1365. /// <param name="SerialNumLength"></param>
  1366. /// <param name="Radix"></param>
  1367. private void GetBarCodeRule(out string Prefix, out string Suffix, out int MaxNum, out int SerialNumLength, out int Radix)
  1368. {
  1369. //获取编码规则
  1370. Prefix = "";
  1371. Suffix = "";
  1372. MaxNum = 0;
  1373. SerialNumLength = 0;
  1374. Radix = 0;
  1375. DataTable Nr = (DataTable)dh.ExecuteSql("select nrd_detno,nrd_name,nrd_type,nrd_radix,nrd_sql,nrd_length from NoRuleDetail left join norule on nrd_nrid=nr_id where nr_custcode='" + pi_cardcode.Text + "' order by nrd_detno", "select");
  1376. //如果没有则取公共规则
  1377. if (Nr.Rows.Count == 0)
  1378. Nr = (DataTable)dh.ExecuteSql("select nrd_detno,nrd_name,nrd_radix,nrd_type,nrd_sql,nrd_length from NoRuleDetail left join norule on nrd_nrid=nr_id where nr_custcode is null and nr_isdefault <> 0 order by nrd_detno", "select");
  1379. //用于过滤参数的正则表达式
  1380. Regex match = new Regex("{\\w+}");
  1381. //用于存放每一项的明细的数据
  1382. string[] NrData = new string[Nr.Rows.Count];
  1383. //流水长度
  1384. Dictionary<int, string> NrDic = new Dictionary<int, string>();
  1385. Prefix = "";
  1386. for (int m = 0; m < Nr.Rows.Count; m++)
  1387. {
  1388. switch (Nr.Rows[m]["nrd_type"].ToString())
  1389. {
  1390. //常量直接进行拼接
  1391. case "常量":
  1392. Prefix += Nr.Rows[m]["nrd_sql"].ToString();
  1393. Suffix += Nr.Rows[m]["nrd_sql"].ToString();
  1394. break;
  1395. case "SQL":
  1396. string SQL = Nr.Rows[m]["nrd_sql"].ToString();
  1397. DataTable Temp;
  1398. //如果不包含参数替换
  1399. if (SQL.IndexOf("{") == 0)
  1400. {
  1401. Temp = (DataTable)dh.ExecuteSql(SQL, "select");
  1402. }
  1403. else
  1404. {
  1405. //替换参数后重新执行SQL
  1406. foreach (Match mch in match.Matches(SQL))
  1407. {
  1408. SQL = SQL.Replace(mch.Value.Trim(), "'" + pi_inoutno.Text + "'");
  1409. }
  1410. Temp = (DataTable)dh.ExecuteSql(SQL, "select");
  1411. }
  1412. if (Temp.Rows.Count > 0)
  1413. {
  1414. Prefix += Temp.Rows[0][0].ToString();
  1415. Suffix += Temp.Rows[0][0].ToString();
  1416. }
  1417. break;
  1418. //流水需要通过MaxNumber去取
  1419. case "流水":
  1420. string maxnum = dh.getFieldDataByCondition("RuleMaxNum", "rmn_maxnumber", "rmn_nrcode='" + (pi_cardcode.Text == "" ? "Default" : pi_cardcode.Text) + "' and rmn_prefix='" + Prefix + "'").ToString();
  1421. //设置当前流水
  1422. if (maxnum == "")
  1423. {
  1424. dh.ExecuteSql("insert into RuleMaxNum(rmn_id,rmn_nrcode,rmn_prefix,rmn_maxnumber) values(RuleMaxNum_seq.nextval,'" + (pi_cardcode.Text == "" ? "Default" : pi_cardcode.Text) + "','" + Prefix + "','1')", "insert");
  1425. MaxNum = 1;
  1426. }
  1427. else
  1428. {
  1429. MaxNum = int.Parse(maxnum);
  1430. }
  1431. SerialNumLength = int.Parse(Nr.Rows[m]["nrd_length"].ToString());
  1432. Radix = int.Parse(Nr.Rows[m]["nrd_radix"].ToString());
  1433. Suffix = "";
  1434. break;
  1435. default:
  1436. break;
  1437. }
  1438. }
  1439. }
  1440. private void GridPrcode_CellEndEdit(object sender, DataGridViewCellEventArgs e)
  1441. {
  1442. string Value = GridPrcode.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString();
  1443. string ID = GridPrcode.Rows[e.RowIndex].Cells["pjd_id"].Value.ToString();
  1444. dh.UpdateByCondition("PRODJOINVENDDETAIL", "pjd_zxbzs_user='" + Value + "'", "pjd_id='" + ID + "'");
  1445. //删除对应物料的明细
  1446. CurrentPrCode = GridPrcode.Rows[e.RowIndex].Cells["pd_prodcode"].Value.ToString();
  1447. CurrentZXBZ = GridPrcode.Rows[e.RowIndex].Cells["pjd_zxbzs_user"].Value.ToString();
  1448. CurrentUnit = GridPrcode.Rows[e.RowIndex].Cells["pr_unit"].Value.ToString();
  1449. CurrentPDNO = GridPrcode.Rows[e.RowIndex].Cells["pd_pdno"].Value.ToString();
  1450. CurrentPrCount = GridPrcode.Rows[e.RowIndex].Cells["pd_outqty"].Value.ToString();
  1451. CurrentBrand = GridPrcode.Rows[e.RowIndex].Cells["pd_brand"].Value.ToString();
  1452. GridPrcode.Rows[e.RowIndex].Selected = true;
  1453. if (e.RowIndex - 2 >= 0)
  1454. GridPrcode.FirstDisplayedScrollingRowIndex = e.RowIndex - 2;
  1455. else
  1456. GridPrcode.FirstDisplayedScrollingRowIndex = e.RowIndex;
  1457. LoadGridData(sender, new EventArgs());
  1458. }
  1459. private void GridPrcode_SelectionChanged(object sender, EventArgs e)
  1460. {
  1461. if (GridPrcode.SelectedRows.Count > 0)
  1462. {
  1463. DataGridViewSelectedRowCollection dsc = GridPrcode.SelectedRows;
  1464. CurrentPrCode = GridPrcode.Rows[dsc[0].Index].Cells["pd_prodcode"].Value.ToString();
  1465. CurrentZXBZ = GridPrcode.Rows[dsc[0].Index].Cells["pjd_zxbzs_user"].Value.ToString();
  1466. CurrentUnit = GridPrcode.Rows[dsc[0].Index].Cells["pr_unit"].Value.ToString();
  1467. CurrentPDNO = GridPrcode.Rows[dsc[0].Index].Cells["pd_pdno"].Value.ToString();
  1468. CurrentPrCount = GridPrcode.Rows[dsc[0].Index].Cells["pd_outqty"].Value.ToString();
  1469. CurrentBrand = GridPrcode.Rows[dsc[0].Index].Cells["pd_brand"].Value.ToString();
  1470. GridPrcode.Rows[dsc[0].Index].Selected = true;
  1471. if (dsc[0].Index - 2 >= 0)
  1472. GridPrcode.FirstDisplayedScrollingRowIndex = dsc[0].Index - 2;
  1473. else
  1474. GridPrcode.FirstDisplayedScrollingRowIndex = dsc[0].Index;
  1475. }
  1476. }
  1477. private void GridPrcode_DataError(object sender, DataGridViewDataErrorEventArgs e) { }
  1478. private void GridPrcode_CellClick(object sender, DataGridViewCellEventArgs e)
  1479. {
  1480. if (e.RowIndex >= 0)
  1481. {
  1482. GridPrcode.Rows[e.RowIndex].Selected = true;
  1483. if (e.RowIndex - 2 > 0)
  1484. GridPrcode.FirstDisplayedScrollingRowIndex = e.RowIndex - 2;
  1485. else
  1486. GridPrcode.FirstDisplayedScrollingRowIndex = e.RowIndex;
  1487. }
  1488. }
  1489. private void DCCheck_Leave(object sender, EventArgs e)
  1490. {
  1491. try
  1492. {
  1493. Properties.Settings.Default.DCCheck = int.Parse(DCCheck.Text);
  1494. Properties.Settings.Default.Save();
  1495. }
  1496. catch (Exception)
  1497. {
  1498. MessageBox.Show("DC校验时间必须是整数");
  1499. }
  1500. }
  1501. /// <summary>
  1502. /// 校验DateCode
  1503. /// </summary>
  1504. /// <param name="DateCode"></param>
  1505. private bool CheckDateCode(string DateCode)
  1506. {
  1507. try
  1508. {
  1509. //根据DateCode计算的日期
  1510. string Year = DateCode.Substring(0, 2);
  1511. System.DateTime dt = new System.DateTime(int.Parse("20" + Year), 01, 01);
  1512. string Week = DateCode.Substring(2, 2);
  1513. System.DateTime dt1 = dt.AddDays(int.Parse(Week) * 7);
  1514. //减去DC校验后的日期
  1515. System.DateTime now = System.DateTime.Now;
  1516. System.DateTime now1 = now.AddDays(-int.Parse(DCCheck.Text));
  1517. //物料的DateCode大于限制日期即可
  1518. if (dt1 > now1)
  1519. {
  1520. return true;
  1521. }
  1522. return false;
  1523. }
  1524. catch (Exception)
  1525. {
  1526. return false;
  1527. }
  1528. }
  1529. private void PrintFooter_Click(object sender, EventArgs e)
  1530. {
  1531. DataTable dt = (DataTable)dh.ExecuteSql("select pib_outboxcode2,max(pib_id) pib_id from prodiobarcode where pib_inoutno='" + pi_inoutno.Text + "' group by pib_outboxcode2 order by to_number(pib_outboxcode2)", "select");
  1532. string SQL = "select pib_outboxcode2||'/'||(select max(to_number(pib_outboxcode2)) from prodiobarcode where pib_inoutno='" + pi_inoutno.Text + "') from prodiobarcode where pib_id=";
  1533. for (int i = 0; i < dt.Rows.Count; i++)
  1534. {
  1535. DataTable dt1 = (DataTable)dh.ExecuteSql(SQL + dt.Rows[i]["pib_id"].ToString(), "select");
  1536. FootReport.SetParameterValue("唛头", dt1.Rows[0][0].ToString());
  1537. FootReport.PrintSettings.ShowDialog = false;
  1538. FootReport.PrintSettings.Printer = SingleLabelPrinter.Text;
  1539. FootReport.Print();
  1540. }
  1541. LogManager.DoCommandLog(pi_inoutno.Text, User.UserCode, "打印唛头", "成功");
  1542. }
  1543. private void Input_KeyUp(object sender, KeyEventArgs e)
  1544. {
  1545. if (e.KeyCode == Keys.Enter)
  1546. {
  1547. Input.SelectAll();
  1548. }
  1549. }
  1550. private void GridPrcode_CellPainting(object sender, DataGridViewCellPaintingEventArgs e)
  1551. {
  1552. bool mouseOver = e.CellBounds.Contains(this.PointToClient(Cursor.Position));
  1553. if (e.ColumnIndex > 0 && e.RowIndex >= 0)
  1554. {
  1555. if (GridPrcode.Columns[e.ColumnIndex].Name == "CollectedNum")
  1556. {
  1557. SolidBrush solidBrush = new SolidBrush(Color.FromArgb(51, 153, 255));
  1558. if (GridPrcode.Rows[e.RowIndex].Cells["CollectedNum"].Value.ToString() != GridPrcode.Rows[e.RowIndex].Cells["pd_outqty"].Value.ToString())
  1559. e.Graphics.FillRectangle(mouseOver ? solidBrush : Brushes.Yellow, e.CellBounds);
  1560. else
  1561. e.Graphics.FillRectangle(mouseOver ? solidBrush : Brushes.White, e.CellBounds);
  1562. Rectangle border = e.CellBounds;
  1563. border.Width -= 1;
  1564. e.Graphics.DrawRectangle(Pens.White, border);
  1565. e.PaintContent(e.CellBounds);
  1566. e.Handled = true;
  1567. }
  1568. }
  1569. }
  1570. private void GridPrcode_CellMouseUp(object sender, DataGridViewCellMouseEventArgs e)
  1571. {
  1572. if (e.Button == MouseButtons.Right)
  1573. {
  1574. if (e.RowIndex >= 0 && e.ColumnIndex > 0)
  1575. {
  1576. string Conetent = GridPrcode.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString();
  1577. Clipboard.SetText(Conetent);
  1578. MessageBox.Show("已复制内容" + Conetent);
  1579. }
  1580. }
  1581. }
  1582. private void Pack_Click(object sender, EventArgs e)
  1583. {
  1584. if (LabelInf.Rows.Count > 0)
  1585. {
  1586. GetBarCodeRule(out Prefix, out Suffix, out MaxNum, out NumLength, out Radix);
  1587. List<string> OutBoxCode = new List<string>();
  1588. List<string> PIBID = new List<string>();
  1589. for (int i = 0; i < LabelInf.Rows.Count; i++)
  1590. {
  1591. if (LabelInf.Rows[i].Cells["pib_custoutboxcode"].Value.ToString() == "")
  1592. {
  1593. PIBID.Add(LabelInf.Rows[i].Cells["pib_id1"].Value.ToString());
  1594. string serialcode = BaseUtil.DToAny(MaxNum, Radix);
  1595. for (int k = serialcode.ToString().Length; k < NumLength; k++)
  1596. {
  1597. serialcode = "0" + serialcode;
  1598. }
  1599. if (i + 1 < LabelInf.Rows.Count)
  1600. {
  1601. string FPrcode = LabelInf.Rows[i].Cells["pib_prodcode"].Value.ToString();
  1602. string FPocode = LabelInf.Rows[i].Cells["pd_pocode"].Value.ToString();
  1603. string BPrcode = LabelInf.Rows[i + 1].Cells["pib_prodcode"].Value.ToString();
  1604. string BPocode = LabelInf.Rows[i + 1].Cells["pd_pocode"].Value.ToString();
  1605. if (FPrcode != BPrcode || FPocode != BPocode)
  1606. {
  1607. MaxNum = MaxNum + 1;
  1608. }
  1609. }
  1610. OutBoxCode.Add(Prefix + serialcode + Suffix);
  1611. }
  1612. }
  1613. dh.BatchInsert("update prodiobarcode set pib_custoutboxcode=:pib_custoutboxcode where pib_id=:pib_id and pib_custoutboxcode is null", new string[] { "pib_custoutboxcode", "pib_outboxcode2" }, OutBoxCode.ToArray(), PIBID.ToArray());
  1614. MaxNum = MaxNum + 1;
  1615. dh.UpdateByCondition("RULEMAXNUM", "rmn_maxnumber='" + MaxNum + "'", "rmn_nrcode='" + (pi_cardcode.Text == "" ? "Default" : pi_cardcode.Text) + "' and rmn_prefix='" + Prefix + "'");
  1616. LoadGridData(sender, e);
  1617. }
  1618. }
  1619. private void PackMidBox_Click(object sender, EventArgs e)
  1620. {
  1621. DataTable dt = (DataTable)dh.ExecuteSql("select distinct pib_outboxcode2 from prodiobarcode where pib_inoutno='" + pi_inoutno.Text + "' order by pib_outboxcode2", "select");
  1622. GetBarCodeRule(out Prefix, out Suffix, out MaxNum, out NumLength, out Radix);
  1623. if (Radix > 0)
  1624. {
  1625. //生成中盒条码
  1626. int pib_outboxcode1 = int.Parse(dh.getFieldDataByCondition("prodiobarcode", "max(to_number(nvl(pib_outboxcode1,0)))", "pib_inoutno='" + pi_inoutno.Text + "'").ToString());
  1627. MaxNum = MaxNum - 1;
  1628. for (int i = 0; i < dt.Rows.Count; i++)
  1629. {
  1630. List<string> MidBoxCode = new List<string>();
  1631. List<string> PIBID = new List<string>();
  1632. List<string> PIBOUTBOXCODE1 = new List<string>();
  1633. DataTable dt1 = (DataTable)dh.ExecuteSql("select pib_id,pib_prodcode from prodiobarcode where pib_inoutno='" + pi_inoutno.Text + "' and pib_outboxcode2='" + dt.Rows[i]["pib_outboxcode2"].ToString() + "' and pib_outboxcode1 is null order by to_number(pib_id)", "select");
  1634. //如果不是10的整数倍则为尾盒
  1635. int tencount = 0;
  1636. for (int j = 0; j < dt1.Rows.Count; j++)
  1637. {
  1638. if (tencount % MidboxCapacity.Value == 0 || (dt1.Rows[j]["pib_prodcode"].ToString() != dt1.Rows[j - 1]["pib_prodcode"].ToString()))
  1639. {
  1640. pib_outboxcode1 = pib_outboxcode1 + 1;
  1641. MaxNum = MaxNum + 1;
  1642. tencount = 0;
  1643. }
  1644. tencount = tencount + 1;
  1645. string serialcode = BaseUtil.DToAny(MaxNum, Radix);
  1646. for (int k = serialcode.ToString().Length; k < NumLength; k++)
  1647. {
  1648. serialcode = "0" + serialcode;
  1649. }
  1650. MidBoxCode.Add(Prefix + serialcode + Suffix);
  1651. PIBID.Add(dt1.Rows[j]["pib_id"].ToString());
  1652. PIBOUTBOXCODE1.Add(pib_outboxcode1.ToString());
  1653. }
  1654. dh.BatchInsert("update prodiobarcode set pib_custmidboxcode=:pib_custmidboxcode,pib_outboxcode1=:pib_outboxcode1 where pib_id=:pib_id and pib_custmidboxcode is null", new string[] { "pib_custmidboxcode", "pib_outboxcode1", "pib_id" }, MidBoxCode.ToArray(), PIBOUTBOXCODE1.ToArray(), PIBID.ToArray());
  1655. }
  1656. MaxNum = MaxNum + 1;
  1657. dh.UpdateByCondition("RULEMAXNUM", "rmn_maxnumber='" + MaxNum + "'", "rmn_nrcode='" + (pi_cardcode.Text == "" ? "Default" : pi_cardcode.Text) + "' and rmn_prefix='" + Prefix + "'");
  1658. }
  1659. LoadGridData(sender, e);
  1660. }
  1661. private void PrintStatus_Click(object sender, EventArgs e)
  1662. {
  1663. EnablePrint = !EnablePrint;
  1664. if (EnablePrint)
  1665. {
  1666. SetPrintStatus_label.ForeColor = Color.Green;
  1667. SetPrintStatus_label.Text = "可打印";
  1668. }
  1669. else
  1670. {
  1671. SetPrintStatus_label.ForeColor = Color.Red;
  1672. SetPrintStatus_label.Text = "暂停打印";
  1673. }
  1674. Input.Focus();
  1675. }
  1676. private void CustomerLabel_Click(object sender, EventArgs e)
  1677. {
  1678. sql.Clear();
  1679. sql.Append("update prodiobarcode set pib_custbarcode=case when instr(pib_custbarcode,'SL')=0 ");
  1680. sql.Append("then ('SL'||pib_custbarcode)else pib_custbarcode end, pib_custoutboxcode=case when instr");
  1681. sql.Append("(pib_custoutboxcode,'SC')=0 then ('SC'||pib_custoutboxcode)else pib_custoutboxcode end where pib_inoutno='" + pi_inoutno.Text + "'");
  1682. dh.ExecuteSql(sql.ToString(), "select");
  1683. LoadGridData(sender, e);
  1684. CustomerLabel.Enabled = false;
  1685. }
  1686. private void Combindetail_CheckedChanged(object sender, EventArgs e)
  1687. {
  1688. LoadPrcodeData();
  1689. }
  1690. string SelectProdcode = "";
  1691. string SelectMidBoxCode = "";
  1692. int SelectRowIndex = -1;
  1693. private void LabelInf_CellClick(object sender, DataGridViewCellEventArgs e)
  1694. {
  1695. if (e.RowIndex >= 0)
  1696. {
  1697. LabelInf.Rows[e.RowIndex].Selected = true;
  1698. SelectRowIndex = e.RowIndex;
  1699. }
  1700. }
  1701. private void OutBoxNum_SelectedIndexChanged(object sender, EventArgs e)
  1702. {
  1703. LoadGridData(sender, e);
  1704. }
  1705. private void LabelInf_SelectionChanged(object sender, EventArgs e)
  1706. {
  1707. DataGridViewSelectedRowCollection dsc = LabelInf.SelectedRows;
  1708. if (dsc.Count > 0)
  1709. {
  1710. SelectRowIndex = dsc[0].Index;
  1711. }
  1712. }
  1713. }
  1714. }