UAS_出货标签管理.cs 83 KB

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