UAS_出货标签管理.cs 84 KB

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