UAS_出货标签管理.cs 146 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101
  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. using System.Reflection;
  16. using UAS_LabelMachine.CustomControl;
  17. using System.Net.Sockets;
  18. namespace UAS_LabelMachine
  19. {
  20. public partial class UAS_出货标签打印 : Form
  21. {
  22. bool ConnectToMachine = false;
  23. //自适应屏幕
  24. AutoSizeFormClass asc = new AutoSizeFormClass();
  25. DataHelper dh;
  26. DataTable dt;
  27. StringBuilder sql = new StringBuilder();
  28. /// <summary>
  29. /// 单盘打印文件
  30. /// </summary>
  31. Report SingleReport = new Report();
  32. /// <summary>
  33. /// 中盒打印文件
  34. /// </summary>
  35. Report MidReport = new Report();
  36. /// <summary>
  37. /// 外箱打印文件
  38. /// </summary>
  39. Report OutReport = new Report();
  40. /// <summary>
  41. /// 唛头文件打印
  42. /// </summary>
  43. Report FootReport = new Report();
  44. /// <summary>
  45. /// Loading窗口
  46. /// </summary>
  47. SetLoadingWindow stw;
  48. /// <summary>
  49. /// 弹窗线程
  50. /// </summary>
  51. Thread thread;
  52. /// <summary>
  53. /// 当前品牌
  54. /// </summary>
  55. string PI_ID;
  56. bool logout = false;
  57. //主表数据源
  58. DataTable LabelInfDataTable;
  59. /// <summary>
  60. /// 存放单盘的ID
  61. /// </summary>
  62. List<string> SingleID = new List<string>();
  63. /// <summary>
  64. /// 是否全选
  65. /// </summary>
  66. bool AllChecked = false;
  67. DataTable SumQty;
  68. /// <summary>
  69. /// 是否通过选择Combox来改变打开的文件
  70. /// </summary>
  71. bool ComBoxClickChangeLabelDoc = false;
  72. //当前采集的物料编号
  73. string CurrentPrCode = "";
  74. //当前采集的最小包装
  75. string CurrentZXBZ = "";
  76. //当前采集的单位
  77. string CurrentUnit = "";
  78. //当前采集的总数
  79. string CurrentPrCount = "";
  80. //当前明细序号
  81. string CurrentPDNO = "";
  82. //当前的物料品牌
  83. string CurrentBrand = "";
  84. string NrCode = "";
  85. string Prefix = "";
  86. string Suffix = "";
  87. int MaxNum = 0;
  88. int NumLength = 0;
  89. int Radix = 0;
  90. private bool EnablePrint = true;
  91. string[] PIBID;
  92. DataTable Attach;
  93. //传送贴标角度
  94. string Angle = "";
  95. string X = "";
  96. string Y = "";
  97. //贴标机采集的行数
  98. int MachineCollectRowIndex = 0;
  99. public UAS_出货标签打印(string Master)
  100. {
  101. this.SetStyle(ControlStyles.OptimizedDoubleBuffer | ControlStyles.ResizeRedraw | ControlStyles.AllPaintingInWmPaint, true);
  102. this.UpdateStyles();
  103. InitializeComponent();
  104. //利用反射设置DataGridView的双缓冲
  105. Type dgvType = this.LabelInf.GetType();
  106. PropertyInfo pi = dgvType.GetProperty("DoubleBuffered", BindingFlags.Instance | BindingFlags.NonPublic);
  107. pi.SetValue(this.LabelInf, true, null);
  108. pi.SetValue(this.GridPrcode, true, null);
  109. (new EnvironmentSettings()).ReportSettings.ShowProgress = false;
  110. Text = Text + "-" + Master;
  111. }
  112. //protected override void WndProc(ref Message m)
  113. //{
  114. // //拦截双击标题栏、移动窗体的系统消息
  115. // if (m.Msg != 0xA3)
  116. // {
  117. // base.WndProc(ref m);
  118. // }
  119. //}
  120. delegate void BindDataSource(DataGridView dgv, DataTable dt);//定义委托
  121. void bindingsource(DataGridView dgv, DataTable dt)
  122. {
  123. if (dgv.InvokeRequired)
  124. {
  125. dgv.Invoke(new BindDataSource(bindingsource), new object[] { dgv, dt });
  126. }
  127. else
  128. {
  129. dgv.AutoGenerateColumns = false;
  130. dgv.DataSource = dt;
  131. }
  132. }
  133. private void 贴标机条码打印_Load(object sender, EventArgs e)
  134. {
  135. //用计时器重置数据库链接
  136. LogManager.DoLog("程序启动,登陆人员【" + User.UserName + "】");
  137. dh = SystemInf.dh;
  138. CheckForIllegalCrossThreadCalls = false;
  139. pi_inoutno.Focus();
  140. Point pt = new Point();
  141. //禁止所有列的排序
  142. foreach (DataGridViewColumn dgv in LabelInf.Columns)
  143. {
  144. dgv.SortMode = DataGridViewColumnSortMode.NotSortable;
  145. }
  146. foreach (DataGridViewColumn dgv in GridPrcode.Columns)
  147. {
  148. dgv.SortMode = DataGridViewColumnSortMode.NotSortable;
  149. }
  150. int ScreenWidth = Screen.GetWorkingArea(pt).Width;
  151. //设置获取当前屏幕大小自动全屏但是保留任务栏
  152. Rectangle ScreenArea = Screen.GetWorkingArea(this);
  153. Top = 0;
  154. Left = 0;
  155. Width = ScreenArea.Width;
  156. Height = ScreenArea.Height;
  157. //OutboxCapacity.Value = Properties.Settings.Default.OutboxCapacity;
  158. MidboxCapacity.Value = Properties.Settings.Default.MidBoxCapacity;
  159. if (MidboxCapacity.Value == 0)
  160. {
  161. MidboxCapacity.Value = 10;
  162. }
  163. DCCheck.Text = Properties.Settings.Default.DCCheck.ToString();
  164. OutBoxPrinter.Text = Properties.Settings.Default.OPrinter;
  165. MidLabelPrinter.Text = Properties.Settings.Default.MPrinter;
  166. SingleLabelPrinter.Text = Properties.Settings.Default.SPrinter;
  167. asc.controllInitializeSize(this);
  168. asc.controlAutoSize(this);
  169. RefreshDBConnect.Interval = 60000;
  170. RefreshDBConnect.Start();
  171. }
  172. //只执行一次窗体自适应
  173. bool AutoSized = false;
  174. private void 贴标机条码打印_SizeChanged(object sender, EventArgs e)
  175. {
  176. if (!AutoSized)
  177. {
  178. asc.controlAutoSize(this);
  179. AutoSized = true;
  180. }
  181. }
  182. private void LabelMaintain_Click(object sender, EventArgs e)
  183. {
  184. 客户标签维护 form = new 客户标签维护();
  185. BaseUtil.SetFormCenter(form);
  186. form.FormClosed += LabelFormClose;
  187. form.ShowDialog();
  188. }
  189. int combined = 0;
  190. private void LabelFormClose(object sender, EventArgs e)
  191. {
  192. GetInOutInfAndLabelFile();
  193. }
  194. int PassTenCount = 1;
  195. int PassSixTenCount = 1;
  196. //输入框Enter事件
  197. private void Input_KeyDown(object sender, KeyEventArgs e)
  198. {
  199. if (e.KeyCode == Keys.Enter)
  200. {
  201. if (Input.Text == "")
  202. {
  203. richTextAutoBottom1.AppendText("采集的数据不能为空\n");
  204. receiveClient.Client.Send(Encoding.ASCII.GetBytes("ReadId1|,|NG|,|Y"));
  205. return;
  206. }
  207. CollectInputData();
  208. }
  209. }
  210. /// <summary>
  211. /// 采集数据
  212. /// </summary>
  213. private void CollectInputData()
  214. {
  215. if (Input.Text == "SC")
  216. {
  217. PrintStatus.PerformClick();
  218. Input.Text = "";
  219. return;
  220. }
  221. Input.Text = Input.Text.Replace("\n", "").Replace(" ", "").Replace("\t", "").Replace("\r", "");
  222. Dictionary<string, string> Data = new Dictionary<string, string>();
  223. string[] SplitData = Input.Text.Split('*');
  224. if (SplitData.Length < 5)
  225. {
  226. richTextAutoBottom1.AppendText("数据格式错误,无法解析\n");
  227. if (ConnectToMachine)
  228. {
  229. receiveClient.Client.Send(Encoding.ASCII.GetBytes("ReadId1|,|NG|,|Y"));
  230. }
  231. //Input.SelectAll();
  232. return;
  233. }
  234. for (int i = 0; i < SplitData.Length; i++)
  235. {
  236. switch (i.ToString())
  237. {
  238. case "0":
  239. Data.Add("PRCODE", SplitData[i]);
  240. break;
  241. case "1":
  242. Data.Add("QTY", SplitData[i]);
  243. break;
  244. case "2":
  245. Data.Add("DATECODE", SplitData[i]);
  246. break;
  247. case "3":
  248. Data.Add("BRAND", SplitData[i]);
  249. break;
  250. case "4":
  251. Data.Add("LOTNO", SplitData[i]);
  252. break;
  253. case "5":
  254. Data.Add("PO", SplitData[i]);
  255. break;
  256. case "6":
  257. Data.Add("SERIAL", SplitData[i]);
  258. break;
  259. default:
  260. break;
  261. }
  262. }
  263. if (Data["PRCODE"] != CurrentPrCode)
  264. {
  265. if (!MixPrCode.Checked)
  266. {
  267. richTextAutoBottom1.AppendText("当前采集【物料编号" + Data["PRCODE"] + "】不对应,请重新采集\n");
  268. //Input.SelectAll();
  269. if (ConnectToMachine)
  270. receiveClient.Client.Send(Encoding.ASCII.GetBytes(GetSendCode("ReadId1|,|NG|,|Y")));
  271. return;
  272. }
  273. else
  274. {
  275. bool FindProd = false;
  276. for (int i = 0; i < GridPrcode.Rows.Count; i++)
  277. {
  278. string prodcode = GridPrcode.Rows[i].Cells["pd_prodcode"].Value.ToString();
  279. string outqty = GridPrcode.Rows[i].Cells["pd_outqty"].Value.ToString();
  280. string collectnum = GridPrcode.Rows[i].Cells["collectednum"].Value.ToString();
  281. //判断其他行是否有料可以匹配
  282. if (prodcode == Data["PRCODE"] && decimal.Parse(outqty) > decimal.Parse(collectnum))
  283. {
  284. GridPrcode.Rows[i].Selected = true;
  285. FindProd = true;
  286. }
  287. }
  288. if (!FindProd)
  289. {
  290. richTextAutoBottom1.AppendText("当前采集【物料编号" + Data["PRCODE"] + "】没有需要采集的内容\n");
  291. //Input.SelectAll();
  292. if (ConnectToMachine)
  293. receiveClient.Client.Send(Encoding.ASCII.GetBytes(GetSendCode("ReadId1|,|NG|,|Y")));
  294. return;
  295. }
  296. }
  297. }
  298. //校验DateCode是否过期
  299. if (!CheckDateCode(Data["DATECODE"]))
  300. {
  301. if (ConnectToMachine)
  302. {
  303. richTextAutoBottom1.AppendText("物料" + Data["PRCODE"] + "【DateCode】超出校验日期\n");
  304. receiveClient.Client.Send(Encoding.ASCII.GetBytes(GetSendCode("ReadId1|,|NG|,|Y")));
  305. return;
  306. }
  307. else
  308. {
  309. string close = MessageBox.Show(this.ParentForm, "物料" + Data["PRCODE"] + "【DateCode】超出校验日期\n", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question).ToString();
  310. if (close.ToString() != "Yes")
  311. return;
  312. }
  313. }
  314. if (Data["BRAND"] != CurrentBrand)
  315. {
  316. if (ConnectToMachine)
  317. {
  318. richTextAutoBottom1.AppendText("当前采集【品牌" + Data["BRAND"] + "】不对应\n");
  319. receiveClient.Client.Send(Encoding.ASCII.GetBytes(GetSendCode("ReadId1|,|NG|,|Y")));
  320. return;
  321. }
  322. else
  323. {
  324. string close = MessageBox.Show(this.ParentForm, "当前采集【品牌" + Data["BRAND"] + "】不对应", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question).ToString();
  325. if (close.ToString() != "Yes")
  326. return;
  327. }
  328. }
  329. int CodeCount = 0;
  330. //如果单位是KPCS则需要除1000
  331. double CollectNum = 0;
  332. if (CurrentUnit == "KPCS")
  333. {
  334. try
  335. {
  336. double.Parse(CurrentZXBZ);
  337. }
  338. catch (Exception)
  339. {
  340. MessageBox.Show("请检查最小包装数");
  341. }
  342. //如果单位是KPCS则必须是1000的整数倍
  343. if (decimal.Parse((Convert.ToDouble((double.Parse(Data["QTY"]) / 1000).ToString("0.000")) / Convert.ToDouble(double.Parse(CurrentZXBZ).ToString("0.000"))).ToString()) % 1 != 0)
  344. {
  345. richTextAutoBottom1.AppendText("物料" + Data["PRCODE"] + "采集数量无法按照最小包装数拆分\n");
  346. //Input.SelectAll();
  347. if (ConnectToMachine)
  348. receiveClient.Client.Send(Encoding.ASCII.GetBytes(GetSendCode("ReadId1|,|NG|,|Y")));
  349. return;
  350. }
  351. CodeCount = int.Parse((double.Parse(Data["QTY"]) / 1000 / double.Parse(CurrentZXBZ)).ToString());
  352. CollectNum = double.Parse(Data["QTY"]) / 1000;
  353. }
  354. else
  355. {
  356. if (double.Parse(Data["QTY"]) % double.Parse(CurrentZXBZ) != 0)
  357. {
  358. richTextAutoBottom1.AppendText("采集【数量】无法按照最小包装数拆分\n");
  359. if (ConnectToMachine)
  360. receiveClient.Client.Send(Encoding.ASCII.GetBytes(GetSendCode("ReadId1|,|NG|,|Y")));
  361. //Input.SelectAll();
  362. return;
  363. }
  364. CodeCount = int.Parse((double.Parse(Data["QTY"]) / double.Parse(CurrentZXBZ)).ToString());
  365. CollectNum = double.Parse(Data["QTY"]);
  366. }
  367. string pib_barcode = Data.ContainsKey("SERIAL") ? Data["SERIAL"] : "";
  368. //获取ID
  369. PIBID = dh.GetSEQ("prodiobarcode_seq", CodeCount);
  370. //加载完数据之后进行容量的判断
  371. string pib_outboxcode2 = "";
  372. int BoxNum = LabelInfDataTable.Select("pib_outboxcode2='" + OutBoxNum.Text + "'").Length;
  373. if (BoxNum + CodeCount > OutboxCapacity.Value && AutoSetOutBox.Checked)
  374. {
  375. string maxoutbox = dh.getFieldDataByCondition("prodiobarcode", "max(to_number(pib_outboxcode2))", "pib_inoutno='" + pi_inoutno.Text + "'").ToString();
  376. //如果没有则从开始插入
  377. if (maxoutbox == "")
  378. {
  379. pib_outboxcode2 = "1";
  380. }
  381. else
  382. {
  383. pib_outboxcode2 = (int.Parse(maxoutbox) + 1).ToString();
  384. }
  385. OutBoxNum.Items.Clear();
  386. 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");
  387. ItemObject io = new ItemObject("新增", "新增");
  388. OutBoxNum.Items.Add(io);
  389. io = new ItemObject("全部", "全部");
  390. OutBoxNum.Items.Add(io);
  391. io = new ItemObject(pib_outboxcode2, pib_outboxcode2);
  392. PassSixTenCount = 1;
  393. OutBoxNum.Items.Add(io);
  394. for (int i = 0; i < dt.Rows.Count; i++)
  395. {
  396. string piboutboxcode2 = dt.Rows[i]["pib_outboxcode2"].ToString();
  397. io = new ItemObject(piboutboxcode2, piboutboxcode2);
  398. OutBoxNum.Items.Add(io);
  399. }
  400. if (OutBoxNum.Items.Count > 2)
  401. OutBoxNum.SelectedIndex = 2;
  402. }
  403. else
  404. {
  405. if (OutBoxNum.Text == "新增")
  406. {
  407. string maxoutbox = dh.getFieldDataByCondition("prodiobarcode", "max(to_number(pib_outboxcode2))", "pib_inoutno='" + pi_inoutno.Text + "'").ToString();
  408. //如果没有则从开始插入
  409. if (maxoutbox == "")
  410. {
  411. pib_outboxcode2 = "1";
  412. }
  413. else
  414. {
  415. pib_outboxcode2 = (int.Parse(maxoutbox) + 1).ToString();
  416. }
  417. OutBoxNum.Items.Clear();
  418. PassSixTenCount = 1;
  419. 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");
  420. ItemObject io = new ItemObject("新增", "新增");
  421. OutBoxNum.Items.Add(io);
  422. io = new ItemObject("全部", "全部");
  423. OutBoxNum.Items.Add(io);
  424. io = new ItemObject(pib_outboxcode2, pib_outboxcode2);
  425. OutBoxNum.Items.Add(io);
  426. for (int i = 0; i < dt.Rows.Count; i++)
  427. {
  428. string piboutboxcode2 = dt.Rows[i]["pib_outboxcode2"].ToString();
  429. io = new ItemObject(piboutboxcode2, piboutboxcode2);
  430. OutBoxNum.Items.Add(io);
  431. }
  432. if (OutBoxNum.Items.Count > 2)
  433. OutBoxNum.SelectedIndex = 2;
  434. }
  435. else
  436. {
  437. pib_outboxcode2 = OutBoxNum.Text;
  438. }
  439. }
  440. if (OutBoxNum.Text == "全部")
  441. {
  442. MessageBox.Show("请选择指定箱号或者新增");
  443. return;
  444. }
  445. //计算当前采集数量
  446. string collectqty = dh.getFieldDataByCondition("prodiobarcode", "sum(pib_qty)", "pib_inoutno='" + pi_inoutno.Text + "' and pib_prodcode='" + CurrentPrCode + "' and pib_pdno='" + CurrentPDNO + "'").ToString();
  447. double CollectQty = (collectqty == "" ? 0 : double.Parse(collectqty));
  448. if (Convert.ToDouble((CollectQty + CollectNum).ToString("0.000")) > Convert.ToDouble(double.Parse(CurrentPrCount).ToString("0.000")))
  449. {
  450. richTextAutoBottom1.AppendText("物料" + Data["PRCODE"] + "采集后数量为" + (CollectQty + CollectNum) + ",【超出】本行出货数量" + CurrentPrCount + "\n");
  451. if (ConnectToMachine)
  452. receiveClient.Client.Send(Encoding.ASCII.GetBytes(GetSendCode("ReadId1|,|NG|,|Y")));
  453. //Input.SelectAll();
  454. return;
  455. }
  456. GetBarCodeRule(out Prefix, out Suffix, out MaxNum, out NumLength, out Radix, CodeCount);
  457. List<string> CustBarCode = new List<string>();
  458. if (!(Radix > 0))
  459. {
  460. string close = MessageBox.Show(this.ParentForm, "未维护条码规则,是否继续生成", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question).ToString();
  461. if (close.ToString() != "Yes")
  462. return;
  463. }
  464. for (int i = 0; i < CodeCount; i++)
  465. {
  466. if (Radix > 0)
  467. {
  468. string serialcode = BaseUtil.DToAny(MaxNum, Radix);
  469. for (int j = serialcode.ToString().Length; j < NumLength; j++)
  470. {
  471. serialcode = "0" + serialcode;
  472. }
  473. CustBarCode.Add(Prefix + serialcode + Suffix);
  474. MaxNum = MaxNum + 1;
  475. }
  476. else
  477. {
  478. CustBarCode.Add("");
  479. }
  480. }
  481. sql.Clear();
  482. sql.Append("insert into prodiobarcode(PIB_ID,PIB_PRODCODE,PIB_INDATE,PIB_INOUTNO,PIB_PIID,PIB_PDNO, PIB_PDID,PIB_PICLASS,");
  483. 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) ");
  484. sql.Append("select :PIB_ID,pd_prodcode,sysdate,pi_inoutno,pi_id,pd_pdno,pd_id,pi_class,");
  485. 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 + "' ");
  486. 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 + "'");
  487. int rowsnum = 0;
  488. try
  489. {
  490. rowsnum = dh.BatchInsert(sql.ToString(), new string[] { "PIB_ID", "PIB_CUSTBARCODE" }, PIBID, CustBarCode.ToArray());
  491. }
  492. catch (Exception)
  493. {
  494. if (ReSetType != " ")
  495. {
  496. dh.UpdateByCondition("RULEMAXNUM", "rmn_maxnumber='" + (MaxNum + 1) + "'", "rmn_nrcode='" + (NrCode == "" ? "Default" : NrCode) + "' and nvl(rmn_type,' ')='" + ReSetType + "'");
  497. }
  498. else
  499. {
  500. dh.UpdateByCondition("RULEMAXNUM", "rmn_maxnumber='" + (MaxNum + 1) + "'", "rmn_nrcode='" + (NrCode == "" ? "Default" : NrCode) + "' and rmn_prefix='" + Prefix + "'");
  501. }
  502. CollectInputData();
  503. return;
  504. }
  505. if (rowsnum == 0)
  506. {
  507. MessageBox.Show("未成功插入数据,请核对出货单当前明细", "提示");
  508. }
  509. //更新流水号
  510. LoadGridData(new object(), new EventArgs());
  511. if (LabelInf.Rows.Count > 0)
  512. {
  513. LabelInf.Rows[LabelInf.Rows.Count - 1].Selected = true;
  514. }
  515. if (SingleLabelAutoPrint.Checked)
  516. {
  517. thread = new Thread(AutoPrintSingleLabel);
  518. stw = new SetLoadingWindow(thread, "正在打印单盘标签");
  519. BaseUtil.SetFormCenter(stw);
  520. stw.ShowDialog();
  521. if (ConnectToMachine)
  522. receiveClient.Client.Send(Encoding.ASCII.GetBytes(GetSendCode("ReadId1|,|OK|,|Y")));
  523. }
  524. else
  525. {
  526. if (ConnectToMachine)
  527. receiveClient.Client.Send(Encoding.ASCII.GetBytes(GetSendCode("ReadId1|,|OK|,|N")));
  528. }
  529. if (SumQty.Columns.Count == 0)
  530. {
  531. sql.Clear();
  532. sql.Append("select pib_pdno,pib_prodcode,sum(pib_qty) pib_qty from prodiodetail left join prodiobarcode on pd_id=pib_pdid and pd_pdno=pib_pdno ");
  533. sql.Append("where pib_inoutno='" + pi_inoutno.Text + "' group by pib_prodcode,pib_pdno order by pib_pdno ");
  534. SumQty = (DataTable)dh.ExecuteSql(sql.ToString(), "select");
  535. }
  536. //采集后重新计数,自动跳到下一行
  537. collectqty = (SumQty.Compute("sum(pib_qty)", "pib_prodcode='" + CurrentPrCode + "' and pib_pdno='" + CurrentPDNO + "'").ToString());
  538. CollectQty = (collectqty == "" ? 0 : double.Parse(collectqty));
  539. if (Combindetail.Checked)
  540. combined = 1;
  541. if (CombindetailTwo.Checked)
  542. combined = 2;
  543. dh.UpdateByCondition("CS$InoutPrcode", "Collectednum='" + CollectQty + "'", "pd_inoutno='" + pi_inoutno.Text + "' and pd_pdno='" + CurrentPDNO + "' and combined=" + combined);
  544. CollectNum = 0;
  545. double OutNum = 0;
  546. if (GridPrcode.SelectedRows.Count > 0)
  547. {
  548. GridPrcode.Rows[GridPrcode.SelectedRows[0].Index].Cells["CollectedNum"].Value = CollectQty;
  549. for (int i = 0; i < GridPrcode.Rows.Count; i++)
  550. {
  551. CollectNum += float.Parse(GridPrcode.Rows[i].Cells["CollectedNum"].Value.ToString());
  552. OutNum += float.Parse(GridPrcode.Rows[i].Cells["pd_outqty"].Value.ToString());
  553. }
  554. }
  555. ProcessCount.Text = CollectNum + "/" + OutNum;
  556. if (CollectNum == OutNum)
  557. {
  558. dh.UpdateByCondition("prodinout", "pi_user_packingstatus='Packed'", "pi_inoutno='" + pi_inoutno.Text + "'");
  559. }
  560. if (CollectQty / double.Parse(CurrentZXBZ) % double.Parse(MidboxCapacity.Value.ToString()) == 0)
  561. {
  562. LabelInf.Rows[LabelInf.Rows.Count - 1].Selected = true;
  563. if (AutoPrintMidBox.Checked)
  564. MidLabelPrint.PerformClick();
  565. }
  566. //采集达到了数量进行换行
  567. if (CollectQty == double.Parse(CurrentPrCount))
  568. {
  569. if (AutoPrintMidBox.Checked && (CollectQty / double.Parse(CurrentZXBZ) % double.Parse(MidboxCapacity.Value.ToString()) != 0))
  570. MidLabelPrint.PerformClick();
  571. //需要换行,当前最后一盒
  572. DataGridViewSelectedRowCollection selectrow = GridPrcode.SelectedRows;
  573. if (selectrow.Count > 0)
  574. {
  575. if (selectrow[0].Index + 1 < GridPrcode.Rows.Count)
  576. {
  577. string outqty = GridPrcode.Rows[selectrow[0].Index + 1].Cells["pd_outqty"].Value.ToString();
  578. string collectnum = GridPrcode.Rows[selectrow[0].Index + 1].Cells["CollectedNum"].Value.ToString();
  579. if (double.Parse(outqty) > double.Parse(collectnum == "" ? "0" : collectnum))
  580. {
  581. GridPrcode.Rows[selectrow[0].Index + 1].Selected = true;
  582. }
  583. }
  584. }
  585. }
  586. GridPrcode.Refresh();
  587. Input.Clear();
  588. //if (OutBoxNum.Text == "新增")
  589. //{
  590. // OutBoxNum.Items.Clear();
  591. // 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");
  592. // ItemObject io = new ItemObject("新增", "新增");
  593. // OutBoxNum.Items.Add(io);
  594. // io = new ItemObject("全部", "全部");
  595. // OutBoxNum.Items.Add(io);
  596. // for (int i = 0; i < dt.Rows.Count; i++)
  597. // {
  598. // string piboutboxcode2 = dt.Rows[i]["pib_outboxcode2"].ToString();
  599. // io = new ItemObject(piboutboxcode2, piboutboxcode2);
  600. // OutBoxNum.Items.Add(io);
  601. // }
  602. // if (OutBoxNum.Items.Count > 2)
  603. // OutBoxNum.SelectedIndex = 2;
  604. //}
  605. }
  606. private void AutoPrintSingleLabel()
  607. {
  608. if (EnablePrint)
  609. {
  610. //用标签本身的变量作为最外层的循环条件去匹配;
  611. StringBuilder ParamLog = new StringBuilder();
  612. string pibid = "";
  613. for (int i = 0; i < PIBID.Length; i++)
  614. {
  615. if (i != PIBID.Length - 1)
  616. pibid += PIBID[i] + ",";
  617. else
  618. pibid += PIBID[i];
  619. }
  620. if (!SingleLabelCombox.SelectedValue.ToString().Contains("System.Data.DataRowView"))
  621. SingleReport.Load(SingleLabelCombox.SelectedValue.ToString());
  622. for (int j = 0; j < SingleReport.Parameters.Count; j++)
  623. {
  624. SingleReport.SetParameterValue(SingleReport.Parameters[j].Name, "");
  625. for (int k = 0; k < Attach.Rows.Count; k++)
  626. {
  627. if (Attach.Rows[k][0].ToString() == SingleReport.Parameters[j].Name)
  628. {
  629. SingleReport.SetParameterValue(SingleReport.Parameters[j].Name, Attach.Rows[k][1].ToString());
  630. }
  631. }
  632. }
  633. StringBuilder sql = new StringBuilder();
  634. sql.Clear();
  635. sql.Append("select * from (select to_char(pi_date,'yyiw')出库年周,to_char(sysdate,'yyiw')当前DateCode,pi_remark 单据备注,pi_date-1 出库前一天,pib_outboxcode2 外箱号,pd_orderdetno 订单序号,pib_totalweight 总重,pr_ywmc_user 英文名称,pib_boxweight 箱重,nvl(pib_totalweight,0)-nvl(pib_boxweight,0) 净重,pib_id 主键ID,pd_pdno 出货序号,pib_prodcode 物料编号,pr_detail 物料名称,to_char(pi_date,'yyyy-mm-dd') 送达日期,pd_custprodspec 客户型号,pd_custproddetail 客户物料名称,pi_title 客户全称,cu_shortname 客户简称,pr_spec 物料规格,pib_custbarcode 客户条码,pib_custmidboxcode 中盒条码,pib_custoutboxcode 外箱条码,pib_inoutno 出货单号,");
  636. sql.Append("PD_HBSL_USER 出库数量,PD_HBSL_USER*1000 出库数量k,pjd_orispeccode 原厂型号,pib_datecode DateCode,(week_to_date(pib_datecode))DateCode1,pd_remark 备注,pd_remark2 备注2,pd_remark3 备注3,pib_lotno LotNo,");
  637. sql.Append("nvl(nvl(pd_brand,pib_brand),pr_brand)品牌,pr_unit 单位, to_char(pi_date,'yyyy-mm-dd')出库日期,PIB_QTY 最小封装数量,PIB_QTY*1000 最小封装数量k,pd_pocode 客户PO,pd_custprodcode CPN客户料号,");
  638. sql.Append("to_char(ADD_MONTHS(to_date(week_to_date(pib_datecode),'yyyy-mm-dd'),12),'yyyy-mm-dd') 有效期一年,");
  639. sql.Append("to_char(ADD_MONTHS(to_date(week_to_date(pib_datecode),'yyyy-mm-dd'),24),'yyyy-mm-dd') 有效期两年,");
  640. sql.Append("to_char(ADD_MONTHS(to_date(week_to_date(pib_datecode),'yyyy-mm-dd'),36),'yyyy-mm-dd') 有效期三年,");
  641. sql.Append("to_char(ADD_MONTHS(to_date(week_to_date(pib_datecode),'yyyy-mm-dd'),12),'yyyy-iw')有效期一年_年周,");
  642. sql.Append("to_char(ADD_MONTHS(to_date(week_to_date(pib_datecode),'yyyy-mm-dd'),24),'yyyy-iw')有效期两年_年周,");
  643. sql.Append("to_char(ADD_MONTHS(to_date(week_to_date(pib_datecode),'yyyy-mm-dd'),36),'yyyy-iw')有效期三年_年周,");
  644. sql.Append("wh_ppmc_user 中文品牌,em_code 装箱员编号,em_name 装箱员名称 from prodiobarcode left join prodinout on pib_piid=pi_id left join product on pib_prodcode=pr_code left join ProdIODetail on pd_id=PIB_PDID ");
  645. sql.Append("left join PRODJOINVENDDETAIL on pjd_brand=pib_brand and pjd_prodcode=pib_prodcode left join customer on pi_cardcode=cu_code left join productcustomer on pc_custid=cu_id and pc_prodcode=pd_prodcode ");
  646. if (pibid.IndexOf(",") > 0)
  647. {
  648. sql.Append("and pc_custprodcode=pd_custprodcode left join WareHouse on wh_code=pd_whcode left join employee on em_code=pib_inman where pib_id in (" + pibid + ") order by pib_custbarcode)prodiosingleinfo_view");
  649. }
  650. else
  651. {
  652. sql.Append("and pc_custprodcode=pd_custprodcode left join WareHouse on wh_code=pd_whcode left join employee on em_code=pib_inman where pib_id='" + pibid + "' order by pib_custbarcode)prodiosingleinfo_view");
  653. }
  654. DataTable dt = (DataTable)dh.ExecuteSql(sql.ToString(), "select");
  655. SingleReport.RegisterData(dt, "prodiosingleinfo_view");
  656. SingleReport.GetDataSource("prodiosingleinfo_view").Enabled = true;
  657. SingleReport.PrintSettings.ShowDialog = false;
  658. SingleReport.PrintSettings.Printer = SingleLabelPrinter.Text;
  659. try
  660. {
  661. SingleReport.Print();
  662. }
  663. catch (Exception e)
  664. {
  665. MessageBox.Show(e.Message);
  666. return;
  667. }
  668. Properties.Settings.Default.SPrinter = SingleLabelPrinter.Text;
  669. Properties.Settings.Default.Save();
  670. LogManager.DoCommandLog(pi_inoutno.Text, User.UserCode, "自动打印箱标", "打印成功");
  671. }
  672. }
  673. //关闭窗口前提示用户确认
  674. private void 贴标机条码打印_FormClosing(object sender, FormClosingEventArgs e)
  675. {
  676. //如果不是注销的话
  677. if (!logout)
  678. {
  679. string close = MessageBox.Show(this.ParentForm, "是否关闭", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question).ToString();
  680. if (close.ToString() != "Yes")
  681. e.Cancel = true;
  682. else
  683. {
  684. LogManager.DoLog("关闭程序");
  685. }
  686. }
  687. }
  688. /// <summary>
  689. /// 获取打印标签
  690. /// </summary>
  691. private void GetInOutInfAndLabelFile()
  692. {
  693. ComBoxClickChangeLabelDoc = false;
  694. sql.Clear();
  695. 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 ");
  696. sql.Append("left join customer on cu_code=cl_custcode left join label on la_code=CL_LABELCODE where ((pi_cardcode='" + pi_cardcode.Text + "' ");
  697. sql.Append("and pi_inoutno='" + pi_inoutno.Text + "') or( cl_custcode is null)) and cl_labeltype='单盘' order by cl_custcode,cl_date desc");
  698. dt = (DataTable)dh.ExecuteSql(sql.ToString(), "select");
  699. SingleLabelCombox.DisplayMember = "cl_labelname";
  700. SingleLabelCombox.ValueMember = "cl_labelurl";
  701. SingleLabelCombox.DataSource = dt;
  702. sql.Clear();
  703. 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 ");
  704. sql.Append("left join customer on cu_code=cl_custcode left join label on la_code=CL_LABELCODE where ((pi_cardcode='" + pi_cardcode.Text + "' ");
  705. sql.Append("and pi_inoutno='" + pi_inoutno.Text + "') or( cl_custcode is null)) and cl_labeltype='中盒' order by cl_custcode,cl_date desc");
  706. dt = (DataTable)dh.ExecuteSql(sql.ToString(), "select");
  707. MidLabelCombox.DisplayMember = "cl_labelname";
  708. MidLabelCombox.ValueMember = "cl_labelurl";
  709. MidLabelCombox.DataSource = dt;
  710. sql.Clear();
  711. 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 ");
  712. sql.Append("left join customer on cu_code=cl_custcode left join label on la_code=CL_LABELCODE where ((pi_cardcode='" + pi_cardcode.Text + "' ");
  713. sql.Append("and pi_inoutno='" + pi_inoutno.Text + "') or( cl_custcode is null)) and cl_labeltype='外箱' order by cl_custcode,cl_date desc");
  714. dt = (DataTable)dh.ExecuteSql(sql.ToString(), "select");
  715. OutBoxCombox.DisplayMember = "cl_labelname";
  716. OutBoxCombox.ValueMember = "cl_labelurl";
  717. OutBoxCombox.DataSource = dt;
  718. ComBoxClickChangeLabelDoc = true;
  719. }
  720. bool LoadCheck = true;
  721. /// <summary>
  722. /// 出入库单录入框的回车事件
  723. /// </summary>
  724. /// <param name="sender"></param>
  725. /// <param name="e"></param>
  726. private void pi_inoutno_KeyDown(object sender, KeyEventArgs e)
  727. {
  728. if (e.KeyCode == Keys.Enter)
  729. {
  730. LoadCheck = false;
  731. Combindetail.Checked = false;
  732. CombindetailTwo.Checked = false;
  733. LoadCheck = true;
  734. Input.Clear();
  735. sql.Clear();
  736. sql.Append("select pi_id,pi_cardcode,pi_combine_user,pi_title,to_char(pi_date,'yyyymmdd')pi_date,nvl(pi_combine_user,0)pi_combine_user from prodinout where pi_inoutno='" + pi_inoutno.Text + "' and pi_invostatuscode='AUDITED'");
  737. dt = (DataTable)dh.ExecuteSql(sql.ToString(), "select");
  738. if (dt.Rows.Count > 0)
  739. {
  740. pi_cardcode.Text = dt.Rows[0]["pi_cardcode"].ToString();
  741. pi_title.Text = dt.Rows[0]["pi_title"].ToString();
  742. pi_date.Text = dt.Rows[0]["pi_date"].ToString();
  743. PI_ID = dt.Rows[0]["pi_id"].ToString();
  744. switch (dt.Rows[0]["pi_combine_user"].ToString())
  745. {
  746. case "1":
  747. Combindetail.Checked = true;
  748. break;
  749. case "2":
  750. CombindetailTwo.Checked = true;
  751. break;
  752. default:
  753. break;
  754. }
  755. PassTenCount = 1;
  756. PassSixTenCount = 1;
  757. if (pi_cardcode.Text != "ZGCC")
  758. {
  759. CustomerLabel.Enabled = false;
  760. }
  761. else
  762. {
  763. CustomerLabel.Enabled = true;
  764. }
  765. DataTable XY = (DataTable)dh.ExecuteSql("select * from PRINTXY where px_custcode='" + pi_cardcode.Text + "' and px_machine='" + SystemInf.Machine + "'", "select");
  766. if (XY.Rows.Count == 0)
  767. {
  768. XY = (DataTable)dh.ExecuteSql("select * from PRINTXY where px_custcode='" + pi_cardcode.Text + "'", "select");
  769. }
  770. if (XY.Rows.Count > 0)
  771. {
  772. Angle = XY.Rows[0]["px_angle"].ToString();
  773. X = XY.Rows[0]["px_x"].ToString();
  774. Y = XY.Rows[0]["px_y"].ToString();
  775. }
  776. OutBoxNum_Click(new object(), new EventArgs());
  777. LoadPrcodeData();
  778. //获取条码规则
  779. GetBarCodeRule(out Prefix, out Suffix, out MaxNum, out NumLength, out Radix, 1);
  780. SingleID.Clear();
  781. Input.Focus();
  782. ////从后往前找未采集的行
  783. for (int i = GridPrcode.Rows.Count - 1; i >= 0; i--)
  784. {
  785. string outqty = GridPrcode.Rows[i].Cells["pd_outqty"].Value.ToString();
  786. string collectnum = GridPrcode.Rows[i].Cells["CollectedNum"].Value.ToString();
  787. if (double.Parse(outqty) > double.Parse(collectnum == "" ? "0" : collectnum))
  788. {
  789. GridPrcode.Rows[i].Selected = true;
  790. MachineCollectRowIndex = GridPrcode.SelectedRows[0].Index;
  791. if (i - 2 >= 0)
  792. GridPrcode.FirstDisplayedScrollingRowIndex = i - 2;
  793. else
  794. GridPrcode.FirstDisplayedScrollingRowIndex = i;
  795. }
  796. }
  797. pib_indate.Text = dh.getFieldDataByCondition("prodiobarcode", "min(to_char(pib_indate,'yyyy-mm-dd'))", "pib_inoutno='" + pi_inoutno.Text + "'").ToString();
  798. bi_inman.Text = dh.getFieldDataByCondition("barcodeio left join employee on bi_inman=em_code", "wm_concat(distinct em_name)", "bi_piid=" + PI_ID).ToString();
  799. pib_inman.Text = dh.getFieldDataByCondition("prodiobarcode left join employee on pib_inman=em_code", "wm_concat(distinct em_name)", "pib_piid=" + PI_ID).ToString();
  800. 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");
  801. thread = new Thread(GetInOutInfAndLabelFile);
  802. stw = new SetLoadingWindow(thread, "正在获取打印标签");
  803. BaseUtil.SetFormCenter(stw);
  804. stw.ShowDialog();
  805. LogManager.DoLog("输入单号【" + pi_inoutno.Text + "】");
  806. }
  807. else MessageBox.Show("当前出入库单号不存在或者未审核!", "提示");
  808. }
  809. }
  810. private void SingleBoxPrint()
  811. {
  812. if (EnablePrint)
  813. {
  814. if (LabelInf.Rows.Count > 0)
  815. {
  816. //每次打印清除之前缓存的行号和ID,后面会判断需要打印的数据重新加载
  817. SingleID.Clear();
  818. //获取全部的中盒号
  819. Dictionary<string, bool> outboxcode1 = new Dictionary<string, bool>();
  820. //判断所有盒号为该盒的是否勾选已采集
  821. outboxcode1.Add(LabelInf.Rows[0].Cells["pib_outboxcode1"].Value.ToString(), true);
  822. for (int i = 0; i < LabelInf.Rows.Count; i++)
  823. {
  824. if (!SingleID.Contains(LabelInf.Rows[i].Cells["pib_id1"].Value.ToString()))
  825. SingleID.Add(LabelInf.Rows[i].Cells["pib_id1"].Value.ToString());
  826. }
  827. if (SingleID.ToArray().Length == 0)
  828. {
  829. MessageBox.Show("选择的行未勾选采集或者已打印", "提示");
  830. return;
  831. }
  832. for (int i = 0; i < LabelInf.RowCount; i++)
  833. {
  834. if (i + 1 < LabelInf.RowCount)
  835. {
  836. //如果本行的中盒号和下一行不相等的话
  837. if (LabelInf.Rows[i].Cells["pib_outboxcode1"].Value.ToString() != LabelInf.Rows[i + 1].Cells["pib_outboxcode1"].Value.ToString())
  838. {
  839. if (!outboxcode1.ContainsKey(LabelInf.Rows[i + 1].Cells["pib_outboxcode1"].Value.ToString()))
  840. outboxcode1.Add(LabelInf.Rows[i + 1].Cells["pib_outboxcode1"].Value.ToString(), true);
  841. }
  842. }
  843. }
  844. string pibid = "";
  845. for (int i = 0; i < LabelInf.RowCount; i++)
  846. {
  847. //勾选了并且未打印
  848. if (LabelInf.Rows[i].Cells["Choose"].FormattedValue != null && LabelInf.Rows[i].Cells["Choose"].FormattedValue.ToString().ToLower() == "true")
  849. {
  850. pibid += LabelInf.Rows[i].Cells["pib_id1"].Value.ToString() + ",";
  851. LabelInf.Rows[i].Cells["pib_ifprint"].Value = true;
  852. }
  853. }
  854. if (pibid != "")
  855. {
  856. if (!SingleLabelCombox.SelectedValue.ToString().Contains("System.Data.DataRowView"))
  857. SingleReport.Load(SingleLabelCombox.SelectedValue.ToString());
  858. for (int j = 0; j < SingleReport.Parameters.Count; j++)
  859. {
  860. SingleReport.SetParameterValue(SingleReport.Parameters[j].Name, "");
  861. for (int k = 0; k < Attach.Rows.Count; k++)
  862. {
  863. if (Attach.Rows[k][0].ToString() == SingleReport.Parameters[j].Name)
  864. {
  865. SingleReport.SetParameterValue(SingleReport.Parameters[j].Name, Attach.Rows[k][1].ToString());
  866. }
  867. }
  868. }
  869. DataTable dt = (DataTable)dh.ExecuteSql("select * from prodiosingleinfo_view where 主键ID in (" + pibid.Substring(0, pibid.Length - 1) + ")", "select");
  870. SingleReport.RegisterData(dt, "prodiosingleinfo_view");
  871. SingleReport.GetDataSource("prodiosingleinfo_view").Enabled = true;
  872. //保存参数打印
  873. SingleReport.PrintSettings.ShowDialog = false;
  874. SingleReport.PrintSettings.Printer = SingleLabelPrinter.Text;
  875. try
  876. {
  877. SingleReport.Print();
  878. }
  879. catch (Exception e)
  880. {
  881. MessageBox.Show(e.Message);
  882. return;
  883. }
  884. Properties.Settings.Default.SPrinter = SingleLabelPrinter.Text;
  885. Properties.Settings.Default.Save();
  886. }
  887. else
  888. {
  889. MessageBox.Show("未勾选打印明细", "提示", MessageBoxButtons.OK, MessageBoxIcon.None, MessageBoxDefaultButton.Button1, MessageBoxOptions.ServiceNotification);
  890. }
  891. LogManager.DoCommandLog(pi_inoutno.Text, User.UserCode, "手动打印盘标", "打印成功");
  892. dh.BatchInsert("update prodiobarcode set pib_printdate=sysdate where pib_id=:pib_id", new string[] { "pib_id" }, SingleID.ToArray());
  893. outboxcode1.Clear();
  894. }
  895. else
  896. {
  897. MessageBox.Show("此模板尚未维护参数或不存在打印明细", "提示");
  898. return;
  899. }
  900. }
  901. }
  902. private void SingleLabelPrint_Click(object sender, EventArgs e)
  903. {
  904. if (SingleLabelCombox.Text != "")
  905. {
  906. if (SingleBoxBegin.Text != "" || SingleBoxEnd.Text != "")
  907. {
  908. try
  909. {
  910. int begin = int.Parse(SingleBoxBegin.Text == "" ? "1" : SingleBoxBegin.Text);
  911. int end = int.Parse(SingleBoxEnd.Text == "" ? LabelInf.Rows.Count.ToString() : SingleBoxEnd.Text);
  912. if (begin > 0 && end <= LabelInf.Rows.Count && begin <= end)
  913. {
  914. for (int i = begin - 1; i < end; i++)
  915. {
  916. LabelInf.Rows[i].Cells["Choose"].Value = true;
  917. LabelInf.Rows[i].Cells["pib_ifprint"].Value = false;
  918. }
  919. }
  920. else
  921. {
  922. MessageBox.Show("单盘打印范围错误", "提示");
  923. return;
  924. }
  925. }
  926. catch (Exception)
  927. {
  928. MessageBox.Show("单盘打印范围错误", "提示");
  929. return;
  930. }
  931. }
  932. thread = new Thread(SingleBoxPrint);
  933. stw = new SetLoadingWindow(thread, "正在打印单盘");
  934. BaseUtil.SetFormCenter(stw);
  935. stw.ShowDialog();
  936. Input.Focus();
  937. }
  938. else
  939. {
  940. MessageBox.Show("未维护单盘标签", "提示");
  941. LogManager.DoCommandLog(pi_inoutno.Text, User.UserCode, "手动打印盘标", "打印失败,未维护标签");
  942. }
  943. }
  944. private void MidBoxLabelPrint()
  945. {
  946. //未输入内容打印全部中盒
  947. if (MidLabelNum.Text == "")
  948. {
  949. int begin = 0;
  950. int end = 0;
  951. if (MidBoxBegin.Text != "" || MidBoxEnd.Text != "")
  952. {
  953. try
  954. {
  955. begin = int.Parse(MidBoxBegin.Text == "" ? "1" : MidBoxBegin.Text);
  956. end = int.Parse(MidBoxEnd.Text == "" ? LabelInf.Rows[LabelInf.Rows.Count - 1].Cells["pib_outboxcode1"].Value.ToString() : MidBoxEnd.Text);
  957. int minmidbox = int.Parse(LabelInf.Rows[0].Cells["pib_outboxcode1"].Value.ToString());
  958. int maxmidbox = int.Parse(LabelInf.Rows[LabelInf.Rows.Count - 1].Cells["pib_outboxcode1"].Value.ToString());
  959. if (begin >= minmidbox && end <= maxmidbox && begin <= end)
  960. {
  961. //设置中盒打印范围的行号
  962. for (int i = 0; i < LabelInf.Rows.Count; i++)
  963. {
  964. if (int.Parse(LabelInf.Rows[i].Cells["pib_outboxcode1"].Value.ToString()) == begin)
  965. {
  966. begin = i;
  967. }
  968. if (int.Parse(LabelInf.Rows[i].Cells["pib_outboxcode1"].Value.ToString()) == end)
  969. {
  970. end = i;
  971. }
  972. }
  973. }
  974. else
  975. {
  976. MessageBox.Show("中盒打印范围错误", "提示");
  977. return;
  978. }
  979. }
  980. catch (Exception)
  981. {
  982. MessageBox.Show("中盒打印范围错误", "提示");
  983. return;
  984. }
  985. }
  986. List<int> MidOutBoxCode = new List<int>();
  987. List<int> MidOutBoxCodeIndex = new List<int>();
  988. for (int i = (begin == 0 ? 0 : begin); i <= (end == 0 ? LabelInf.Rows.Count - 1 : end); i++)
  989. {
  990. try
  991. {
  992. if (!MidOutBoxCode.Contains(int.Parse(LabelInf.Rows[i].Cells["pib_outboxcode1"].Value.ToString())))
  993. {
  994. MidOutBoxCode.Add(int.Parse(LabelInf.Rows[i].Cells["pib_outboxcode1"].Value.ToString()));
  995. MidOutBoxCodeIndex.Add(i);
  996. }
  997. }
  998. catch (Exception)
  999. {
  1000. MessageBox.Show("请先封箱!");
  1001. return;
  1002. }
  1003. }
  1004. //如果有选中行
  1005. if (SelectRowIndex >= 0 && LabelInf.Rows.Count > SelectRowIndex)
  1006. {
  1007. MidOutBoxCode.Clear();
  1008. MidOutBoxCodeIndex.Clear();
  1009. SelectProdcode = LabelInf.Rows[SelectRowIndex].Cells["pib_prodcode"].Value.ToString();
  1010. for (int i = SelectRowIndex; i >= 0; i--)
  1011. {
  1012. if ((LabelInf.Rows[i].Cells["pib_prodcode"].Value.ToString() == SelectProdcode && LabelInf.Rows[i].Cells["pib_midifprint"].FormattedValue.ToString().ToLower() != "true") || i == SelectRowIndex)
  1013. {
  1014. LabelInf.Rows[i].Cells["pib_midifprint"].Value = true;
  1015. if (!MidOutBoxCode.Contains(int.Parse(LabelInf.Rows[i].Cells["pib_outboxcode1"].Value.ToString())))
  1016. {
  1017. MidOutBoxCode.Add(int.Parse(LabelInf.Rows[i].Cells["pib_outboxcode1"].Value.ToString()));
  1018. MidOutBoxCodeIndex.Add(i);
  1019. }
  1020. }
  1021. else
  1022. {
  1023. break;
  1024. }
  1025. }
  1026. for (int i = SelectRowIndex; i < LabelInf.Rows.Count - 1; i++)
  1027. {
  1028. if ((LabelInf.Rows[i].Cells["pib_prodcode"].Value.ToString() == SelectProdcode && LabelInf.Rows[i].Cells["pib_midifprint"].FormattedValue.ToString().ToLower() != "true") || i == SelectRowIndex)
  1029. {
  1030. LabelInf.Rows[i].Cells["pib_midifprint"].Value = true;
  1031. if (!MidOutBoxCode.Contains(int.Parse(LabelInf.Rows[i].Cells["pib_outboxcode1"].Value.ToString())))
  1032. {
  1033. MidOutBoxCode.Add(int.Parse(LabelInf.Rows[i].Cells["pib_outboxcode1"].Value.ToString()));
  1034. MidOutBoxCodeIndex.Add(i);
  1035. }
  1036. }
  1037. else
  1038. {
  1039. break;
  1040. }
  1041. }
  1042. }
  1043. try
  1044. {
  1045. MidBoxCodePrint(MidOutBoxCodeIndex.ToArray());
  1046. }
  1047. catch (Exception e)
  1048. {
  1049. MessageBox.Show(e.Message);
  1050. return;
  1051. }
  1052. return;
  1053. }
  1054. bool FindMidLabel = false;
  1055. if (MidLabelCombox.SelectedValue != null)
  1056. {
  1057. //中盒号所在的行
  1058. int MidLabelRowIndex = 0;
  1059. //缓存中盒数据
  1060. for (int i = 0; i < LabelInf.RowCount; i++)
  1061. {
  1062. if (MidLabelNum.Text == LabelInf.Rows[i].Cells["pib_outboxcode1"].Value.ToString())
  1063. {
  1064. //找到了输入的中盒号停止循环
  1065. FindMidLabel = true;
  1066. MidLabelRowIndex = i;
  1067. }
  1068. }
  1069. int[] rowindx = new int[] { MidLabelRowIndex };
  1070. //找到了指定的盒号
  1071. if (FindMidLabel)
  1072. MidBoxCodePrint(rowindx);
  1073. else
  1074. MessageBox.Show("该出入库单未找到该中盒号!", "提示");
  1075. }
  1076. else
  1077. MessageBox.Show("未维护中盒模板", "提示");
  1078. }
  1079. private void MidLabelPrint_Click(object sender, EventArgs e)
  1080. {
  1081. if (MidLabelCombox.Text != "")
  1082. {
  1083. PackMidBox_Click(sender, e);
  1084. thread = new Thread(MidBoxLabelPrint);
  1085. stw = new SetLoadingWindow(thread, "正在打印中盒");
  1086. BaseUtil.SetFormCenter(stw);
  1087. stw.ShowDialog();
  1088. }
  1089. else
  1090. MessageBox.Show("未维护中盒标签", "提示");
  1091. Input.Focus();
  1092. }
  1093. private void OutBoxPrint()
  1094. {
  1095. List<string> Outboxcode = new List<string>();
  1096. //如果未勾选箱号则对勾选的数据的箱号进行整合
  1097. if (OutBoxNum.Text == "" || OutBoxNum.Text == "全部")
  1098. {
  1099. for (int i = 0; i < LabelInf.RowCount; i++)
  1100. {
  1101. string outboxcode2 = LabelInf.Rows[i].Cells["pib_outboxcode2"].Value.ToString();
  1102. //富为使用包装单的逻辑
  1103. //如果不包含该箱号则进行添加
  1104. if (!Outboxcode.Contains(outboxcode2))
  1105. Outboxcode.Add(outboxcode2);
  1106. }
  1107. //按获取到的箱号列表进行打印
  1108. if (Outboxcode.ToArray().Length > 0)
  1109. {
  1110. for (int i = 0; i < Outboxcode.ToArray().Length; i++)
  1111. {
  1112. for (int h = 0; h < LabelInf.RowCount; h++)
  1113. {
  1114. if (LabelInf.Rows[h].Cells["pib_outboxcode2"].Value.ToString() == Outboxcode.ToArray()[i])
  1115. {
  1116. if (!AllLabel.Checked)
  1117. OutBoxCodePrint(h);
  1118. else
  1119. OutBoxCodePrint(h, true);
  1120. break;
  1121. }
  1122. }
  1123. }
  1124. }
  1125. else
  1126. {
  1127. MessageBox.Show("请勾选需要打印的外箱", "提示");
  1128. }
  1129. }
  1130. else
  1131. {
  1132. bool FindMidLabel = false;
  1133. try
  1134. {
  1135. int OutBoxLabelRowIndex = 0;
  1136. //查找是否存在该中盒号
  1137. for (int i = 0; i < LabelInf.RowCount; i++)
  1138. {
  1139. if (OutBoxNum.Text == LabelInf.Rows[i].Cells["pib_outboxcode2"].Value.ToString())
  1140. {
  1141. //找到了输入的中盒号停止循环
  1142. FindMidLabel = true;
  1143. OutBoxLabelRowIndex = i;
  1144. break;
  1145. }
  1146. }
  1147. //找到了指定的盒号
  1148. if (FindMidLabel)
  1149. {
  1150. if (!AllLabel.Checked)
  1151. OutBoxCodePrint(OutBoxLabelRowIndex);
  1152. else
  1153. OutBoxCodePrint(OutBoxLabelRowIndex, true);
  1154. }
  1155. else
  1156. MessageBox.Show("该出入库单未找到该外箱号!", "提示");
  1157. }
  1158. catch (Exception) { }
  1159. }
  1160. LogManager.DoCommandLog(pi_inoutno.Text, User.UserCode, "手动打印箱标" + OutBoxNum.Text, "打印成功");
  1161. Outboxcode.Clear();
  1162. }
  1163. private void MidBoxCodePrint(int[] rowindex)
  1164. {
  1165. if (EnablePrint)
  1166. {
  1167. string pib_outboxcode1 = "";
  1168. for (int i = 0; i < rowindex.Length; i++)
  1169. {
  1170. if (i != rowindex.Length - 1)
  1171. pib_outboxcode1 += "'" + LabelInf.Rows[rowindex[i]].Cells["pib_outboxcode1"].Value.ToString() + "'" + ",";
  1172. else
  1173. pib_outboxcode1 += "'" + LabelInf.Rows[rowindex[i]].Cells["pib_outboxcode1"].Value.ToString() + "'";
  1174. }
  1175. //名称相等的时候,取SQL进行值的查询
  1176. DataTable dt;
  1177. sql.Clear();
  1178. sql.Append("update prodiobarcode set pib_midboxweight='" + Weight.Text + "' where pib_inoutno='" + pi_inoutno.Text + "' ");
  1179. sql.Append(" and pib_outboxcode1 in(" + pib_outboxcode1 + ")");
  1180. dh.ExecuteSql(sql.ToString(), "update");
  1181. if (MidLabelAutoPrint.Checked)
  1182. {
  1183. if (CurrentRowOnly.Checked)
  1184. {
  1185. string PDNO = "";
  1186. if (SelectRowIndex >= 0)
  1187. {
  1188. PDNO = LabelInf.Rows[SelectRowIndex].Cells["pib_pdno"].Value.ToString();
  1189. }
  1190. dt = (DataTable)dh.ExecuteSql("select * from prodiomidinfo_view where 出货单号='" + pi_inoutno.Text + "' and 中盒号 in(" + pib_outboxcode1 + ") and 出货序号='" + (PDNO == "" ? CurrentPDNO : PDNO) + "'", "select");
  1191. }
  1192. else
  1193. {
  1194. dt = (DataTable)dh.ExecuteSql("select * from prodiomidinfo_view where 出货单号='" + pi_inoutno.Text + "' and 中盒号 in(" + pib_outboxcode1 + ")", "select");
  1195. }
  1196. }
  1197. else
  1198. {
  1199. if (CurrentRowOnly.Checked)
  1200. {
  1201. string PDNO = "";
  1202. if (SelectRowIndex >= 0)
  1203. {
  1204. PDNO = LabelInf.Rows[SelectRowIndex].Cells["pib_pdno"].Value.ToString();
  1205. }
  1206. dt = (DataTable)dh.ExecuteSql("select * from prodiomidinfo_view where 出货单号='" + pi_inoutno.Text + "' and 中盒号 in(" + pib_outboxcode1 + ") and 中盒标识='外' and 出货序号='" + (PDNO == "" ? CurrentPDNO : PDNO) + "'", "select");
  1207. }
  1208. else
  1209. {
  1210. dt = (DataTable)dh.ExecuteSql("select * from prodiomidinfo_view where 出货单号='" + pi_inoutno.Text + "' and 中盒号 in(" + pib_outboxcode1 + ") and 中盒标识='外'", "select");
  1211. }
  1212. }
  1213. if (dt.Rows.Count > 0)
  1214. {
  1215. if (!MidLabelCombox.SelectedValue.ToString().Contains("System.Data.DataRowView"))
  1216. MidReport.Load(MidLabelCombox.SelectedValue.ToString());
  1217. for (int j = 0; j < MidReport.Parameters.Count; j++)
  1218. {
  1219. MidReport.SetParameterValue(MidReport.Parameters[j].Name, "");
  1220. for (int i = 0; i < Attach.Rows.Count; i++)
  1221. {
  1222. if (Attach.Rows[i][0].ToString() == MidReport.Parameters[j].Name)
  1223. {
  1224. MidReport.SetParameterValue(MidReport.Parameters[j].Name, Attach.Rows[i][1].ToString());
  1225. }
  1226. }
  1227. }
  1228. MidReport.RegisterData(dt, "prodiomidinfo_view");
  1229. MidReport.GetDataSource("prodiomidinfo_view").Enabled = true;
  1230. MidReport.PrintSettings.ShowDialog = false;
  1231. MidReport.PrintSettings.Printer = MidLabelPrinter.Text;
  1232. MidReport.Print();
  1233. dh.UpdateByCondition("prodiobarcode", "pib_midifprint=-1", "pib_inoutno='" + pi_inoutno.Text + "' and pib_outboxcode1 in (" + pib_outboxcode1 + ")");
  1234. SelectRowIndex = -1;
  1235. LoadGridData(new object(), new EventArgs());
  1236. LogManager.DoCommandLog(pi_inoutno.Text, User.UserCode, "打印中盒" + pib_outboxcode1.Replace("'", ""), "打印成功");
  1237. }
  1238. Properties.Settings.Default.MPrinter = MidLabelPrinter.Text;
  1239. Properties.Settings.Default.Save();
  1240. }
  1241. }
  1242. /// <summary>
  1243. /// 执行打印外箱号
  1244. /// </summary>
  1245. private void OutBoxCodePrint(int rowindex)
  1246. {
  1247. if (EnablePrint)
  1248. {
  1249. if (!OutBoxCombox.SelectedValue.ToString().Contains("System.Data.DataRowView"))
  1250. OutReport.Load(OutBoxCombox.SelectedValue.ToString());
  1251. for (int j = 0; j < OutReport.Parameters.Count; j++)
  1252. {
  1253. OutReport.SetParameterValue(OutReport.Parameters[j].Name, "");
  1254. for (int i = 0; i < Attach.Rows.Count; i++)
  1255. {
  1256. if (Attach.Rows[i][0].ToString() == OutReport.Parameters[j].Name)
  1257. {
  1258. OutReport.SetParameterValue(OutReport.Parameters[j].Name, Attach.Rows[i][1].ToString());
  1259. }
  1260. }
  1261. }
  1262. string pib_outboxcode2 = LabelInf.Rows[rowindex].Cells["pib_outboxcode2"].Value.ToString();
  1263. string SQL = "";
  1264. if (OnlyOneRow.Checked)
  1265. {
  1266. SQL = "select * from prodiooutinfo_view where 出货单号 = '" + pi_inoutno.Text + "' and 外箱号 = '" + pib_outboxcode2 + "' and rownum=1";
  1267. }
  1268. else
  1269. {
  1270. SQL = "select * from prodiooutinfo_view where 出货单号 = '" + pi_inoutno.Text + "' and 外箱号 = '" + pib_outboxcode2 + "'";
  1271. }
  1272. DataTable dt = (DataTable)dh.ExecuteSql(SQL, "select");
  1273. OutReport.RegisterData(dt, "prodiooutinfo_view");
  1274. OutReport.GetDataSource("prodiooutinfo_view").Enabled = true;
  1275. OutReport.PrintSettings.ShowDialog = false;
  1276. OutReport.PrintSettings.Printer = OutBoxPrinter.Text;
  1277. OutReport.Print();
  1278. Properties.Settings.Default.OPrinter = OutBoxPrinter.Text;
  1279. Properties.Settings.Default.Save();
  1280. dh.UpdateByCondition("prodiobarcode", "pib_outifprint=-1", "pib_inoutno='" + pi_inoutno.Text + "' and pib_outboxcode2='" + pib_outboxcode2 + "'");
  1281. }
  1282. }
  1283. /// <summary>
  1284. /// 执行打印外箱号
  1285. /// </summary>
  1286. private void OutBoxCodePrint(int rowindex, bool AllLabel)
  1287. {
  1288. if (EnablePrint)
  1289. {
  1290. int selectedindex = OutBoxCombox.SelectedIndex;
  1291. for (int i = 0; i < OutBoxCombox.Items.Count; i++)
  1292. {
  1293. OutBoxCombox.SelectedIndex = i;
  1294. if (!OutBoxCombox.SelectedValue.ToString().Contains("System.Data.DataRowView"))
  1295. OutReport.Load(OutBoxCombox.SelectedValue.ToString());
  1296. for (int j = 0; j < OutReport.Parameters.Count; j++)
  1297. {
  1298. OutReport.SetParameterValue(OutReport.Parameters[j].Name, "");
  1299. for (int k = 0; k < Attach.Rows.Count; k++)
  1300. {
  1301. if (Attach.Rows[k][0].ToString() == OutReport.Parameters[j].Name)
  1302. {
  1303. OutReport.SetParameterValue(OutReport.Parameters[j].Name, Attach.Rows[k][1].ToString());
  1304. }
  1305. }
  1306. }
  1307. string pib_outboxcode2 = LabelInf.Rows[rowindex].Cells["pib_outboxcode2"].Value.ToString();
  1308. DataTable dt = (DataTable)dh.ExecuteSql("select * from prodiooutinfo_view where 出货单号='" + pi_inoutno.Text + "' and 外箱号='" + pib_outboxcode2 + "'", "select");
  1309. OutReport.RegisterData(dt, "prodiooutinfo_view");
  1310. OutReport.GetDataSource("prodiooutinfo_view").Enabled = true;
  1311. OutReport.PrintSettings.ShowDialog = false;
  1312. OutReport.PrintSettings.Printer = OutBoxPrinter.Text;
  1313. OutReport.Print();
  1314. }
  1315. OutBoxCombox.SelectedIndex = selectedindex;
  1316. Properties.Settings.Default.OPrinter = OutBoxPrinter.Text;
  1317. Properties.Settings.Default.Save();
  1318. dh.UpdateByCondition("prodiobarcode", "pib_outifprint=-1", "pib_inoutno='" + pi_inoutno.Text + "' and pib_outboxcode2='" + pib_outboxcode2 + "'");
  1319. }
  1320. }
  1321. private void CleanDetail_Click(object sender, EventArgs e)
  1322. {
  1323. if (dh.getFieldDataByCondition("prodinout", "pi_statuscode", "pi_inoutno='" + pi_inoutno.Text + "'").ToString() == "POSTED")
  1324. {
  1325. //MessageBox.Show("单据" + pi_inoutno.Text + "已过账,不允许删除条码");
  1326. //return;
  1327. }
  1328. ArrayList<string> DeleteID = new ArrayList<string>();
  1329. for (int i = 0; i < LabelInf.RowCount; i++)
  1330. {
  1331. if (LabelInf.Rows[i].Cells["Choose"].FormattedValue.ToString().ToLower() == "true")
  1332. DeleteID.Add(LabelInf.Rows[i].Cells["pib_id1"].Value.ToString());
  1333. }
  1334. //勾选了删除的明细之后
  1335. if (DeleteID.ToArray().Length > 0)
  1336. {
  1337. string close = MessageBox.Show(this.ParentForm, "删除后不可恢复,是否确认删除", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question).ToString();
  1338. if (close.ToString() == "Yes")
  1339. {
  1340. dh.BatchInsert("delete from prodiobarcode where pib_id=:pib_id", new string[] { "pib_id" }, DeleteID.ToArray());
  1341. dh.UpdateByCondition("CS$InoutPrcode", "collectednum=(select nvl(sum(pib_qty),0) from prodiobarcode where pib_inoutno=pd_inoutno and pib_pdno=pd_pdno)", "pd_inoutno='" + pi_inoutno.Text + "'");
  1342. //dh.UpdateByCondition("CS$InoutPrcode", "checknum=CollectedNum/pjd_zxbzs_user", "pd_inoutno='" + pi_inoutno.Text + "'");
  1343. LogManager.DoCommandLog(pi_inoutno.Text, User.UserCode, "删除明细", "删除明细成功");
  1344. MessageBox.Show("删除成功", "提示");
  1345. Input.Clear();
  1346. LoadPrcodeData();
  1347. LoadGridData(sender, e);
  1348. if (int.Parse(dh.getFieldDataByCondition("prodiobarcode", "count(1)", "pib_inoutno='" + pi_inoutno.Text + "'").ToString()) == 0)
  1349. {
  1350. dh.UpdateByCondition("prodinout", "pi_user_packingstatus=''", "pi_inoutno='" + pi_inoutno.Text + "'");
  1351. }
  1352. else
  1353. {
  1354. dh.UpdateByCondition("prodinout", "pi_user_packingstatus='Packing'", "pi_inoutno='" + pi_inoutno.Text + "'");
  1355. }
  1356. }
  1357. }
  1358. else
  1359. MessageBox.Show("尚未勾选需要删除的明细", "提示");
  1360. }
  1361. private void OutBoxLabelPrint_Click(object sender, EventArgs e)
  1362. {
  1363. if (OutBoxCombox.Text != "")
  1364. {
  1365. Pack_Click(sender, e);
  1366. if (Weight.Text != "" && Weight.Text != "0.000")
  1367. {
  1368. //记录整箱的重量
  1369. sql.Clear();
  1370. sql.Append("update prodiobarcode set pib_totalweight='" + Weight.Text + "' where pib_inoutno='" + pi_inoutno.Text + "' ");
  1371. sql.Append(" and pib_outboxcode2='" + OutBoxNum.Text + "'");
  1372. dh.ExecuteSql(sql.ToString(), "update");
  1373. }
  1374. LoadGridData(sender, e);
  1375. thread = new Thread(OutBoxPrint);
  1376. stw = new SetLoadingWindow(thread, "正在打印外箱");
  1377. BaseUtil.SetFormCenter(stw);
  1378. stw.ShowDialog();
  1379. Input.Focus();
  1380. }
  1381. else
  1382. MessageBox.Show("未维护外箱标签", "提示");
  1383. Input.Focus();
  1384. }
  1385. /// <summary>
  1386. /// 自定义函数 加载明细行的数据,多处使用添加进函数
  1387. /// </summary>
  1388. /// <param name="sender"></param>
  1389. /// <param name="e"></param>
  1390. private void LoadGridData(object sender, EventArgs e)
  1391. {
  1392. AllChecked = false;
  1393. string SQL = "";
  1394. if (OutBoxNum.Text != "全部")
  1395. {
  1396. //LogicHandler.GetDataSQL(PI_ID, "and pib_outboxcode2='" + OutBoxNum.Text + "'", out SQL);
  1397. SQL = "select pib_boxweight,pib_midboxweight,pib_totalweight,pd_custprodcode,pd_custprodspec,nvl(pib_midifprint,0)pib_midifprint,pib_custmidboxcode,pd_pocode,pjd_orispeccode," +
  1398. "pib_madein,pib_custbarcode,pib_custoutboxcode,pib_id,pib_datecode1,pib_pdid,pib_piid,pib_pdno,pib_prodcode,pib_brand,pr_vendprodcode,pib_lotno,pib_datecode," +
  1399. "week_to_date(pib_datecode) datecode1,pib_qty,pr_spec,pr_zxbzs,pr_unit,pib_barcode,pib_outboxcode1,pib_outboxcode2,nvl(pib_ifprint, 0)pib_ifprint,pd_remark,pd_remark2 from prodiobarcode left join " +
  1400. "prodiodetail on pib_piid = pd_piid and pd_pdno = pib_pdno and pd_prodcode = pib_prodcode left join product on pr_code = pib_prodcode left join sale on sa_code = pib_ordercode left join " +
  1401. "PRODJOINVENDDETAIL on pjd_brand = pd_brand and pjd_prodcode = pd_prodcode where pib_piid = '" + PI_ID + "' and pib_outboxcode2='" + OutBoxNum.Text + "' order by to_number(pib_outboxcode2),pib_id,pd_prodcode";
  1402. }
  1403. else
  1404. {
  1405. SQL = "select pib_boxweight,pib_midboxweight,pib_totalweight,pd_custprodcode,pd_custprodspec,nvl(pib_midifprint,0)pib_midifprint,pib_custmidboxcode,pd_pocode,pjd_orispeccode," +
  1406. "pib_madein,pib_custbarcode,pib_custoutboxcode,pib_id,pib_datecode1,pib_pdid,pib_piid,pib_pdno,pib_prodcode,pib_brand,pr_vendprodcode,pib_lotno,pib_datecode," +
  1407. "week_to_date(pib_datecode) datecode1,pib_qty,pr_spec,pr_zxbzs,pr_unit,pib_barcode,pib_outboxcode1,pib_outboxcode2,nvl(pib_ifprint, 0)pib_ifprint,pd_remark,pd_remark2 from prodiobarcode left join " +
  1408. "prodiodetail on pib_piid = pd_piid and pd_pdno = pib_pdno and pd_prodcode = pib_prodcode left join product on pr_code = pib_prodcode left join sale on sa_code = pib_ordercode left join " +
  1409. "PRODJOINVENDDETAIL on pjd_brand = pd_brand and pjd_prodcode = pd_prodcode where pib_piid = '" + PI_ID + "' order by to_number(pib_outboxcode2),pib_id,pd_prodcode";
  1410. }
  1411. LabelInfDataTable = (DataTable)dh.ExecuteSql(SQL, "select");
  1412. BoxCount.Text = LabelInfDataTable.Compute("sum(pib_qty)", "1=1").ToString() + "KPCS";
  1413. bindingsource(LabelInf, LabelInfDataTable);
  1414. if (LabelInf.Rows.Count > 0)
  1415. {
  1416. LabelInf.FirstDisplayedScrollingRowIndex = LabelInf.Rows.Count - 1;
  1417. }
  1418. sql.Clear();
  1419. sql.Append("select pib_pdno,pib_prodcode,sum(pib_qty) pib_qty from prodiodetail left join prodiobarcode on pd_id=pib_pdid and pd_pdno=pib_pdno ");
  1420. sql.Append("where pib_inoutno='" + pi_inoutno.Text + "' group by pib_prodcode,pib_pdno order by pib_pdno ");
  1421. SumQty = (DataTable)dh.ExecuteSql(sql.ToString(), "select");
  1422. }
  1423. private void Refresh_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
  1424. {
  1425. KeyEventArgs e2 = new KeyEventArgs(Keys.Enter);
  1426. pi_inoutno_KeyDown(sender, e2);
  1427. }
  1428. private void LogingOut_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
  1429. {
  1430. string close = MessageBox.Show(this.ParentForm, "是否注销", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question).ToString();
  1431. if (close.ToString() == "Yes")
  1432. {
  1433. Login login = new Login();
  1434. //注销的时候需要将拼接的连接字符串置空
  1435. DataHelper.DBConnectionString = null;
  1436. logout = true;
  1437. this.Hide();
  1438. login.ShowDialog();
  1439. this.Close();
  1440. }
  1441. }
  1442. private void LabelInf_DataError(object sender, DataGridViewDataErrorEventArgs e) { }
  1443. /// <summary>
  1444. /// 切换打开的单盘文件
  1445. /// </summary>
  1446. /// <param name="sender"></param>
  1447. /// <param name="e"></param>
  1448. private void SingleLabelCombox_SelectedIndexChanged(object sender, EventArgs e)
  1449. {
  1450. try
  1451. {
  1452. if (ComBoxClickChangeLabelDoc)
  1453. {
  1454. if (!SingleLabelCombox.SelectedValue.ToString().Contains("System.Data.DataRowView"))
  1455. SingleReport.Load(SingleLabelCombox.SelectedValue.ToString());
  1456. }
  1457. }
  1458. catch (Exception) { }
  1459. }
  1460. /// <summary>
  1461. /// 切换打开的中盒文件
  1462. /// </summary>
  1463. /// <param name="sender"></param>
  1464. /// <param name="e"></param>
  1465. private void MidLabelCombox_SelectedIndexChanged(object sender, EventArgs e)
  1466. {
  1467. try
  1468. {
  1469. if (ComBoxClickChangeLabelDoc)
  1470. {
  1471. if (!MidLabelCombox.SelectedValue.ToString().Contains("System.Data.DataRowView"))
  1472. MidReport.Load(MidLabelCombox.SelectedValue.ToString());
  1473. }
  1474. }
  1475. catch (Exception) { }
  1476. }
  1477. /// <summary>
  1478. /// 切换打开的外箱文件
  1479. /// </summary>
  1480. /// <param name="sender"></param>
  1481. /// <param name="e"></param>
  1482. private void OutBoxCombox_SelectedIndexChanged(object sender, EventArgs e)
  1483. {
  1484. try
  1485. {
  1486. if (ComBoxClickChangeLabelDoc)
  1487. {
  1488. if (!OutBoxCombox.SelectedValue.ToString().Contains("System.Data.DataRowView"))
  1489. OutReport.Load(OutBoxCombox.SelectedValue.ToString());
  1490. }
  1491. }
  1492. catch (Exception) { }
  1493. }
  1494. private void ChooseAll_Click(object sender, EventArgs e)
  1495. {
  1496. if (AllChecked)
  1497. {
  1498. foreach (DataGridViewRow dr in LabelInf.Rows)
  1499. dr.Cells[0].Value = false;
  1500. AllChecked = false;
  1501. }
  1502. else
  1503. {
  1504. foreach (DataGridViewRow dr in LabelInf.Rows)
  1505. dr.Cells[0].Value = true;
  1506. AllChecked = true;
  1507. }
  1508. }
  1509. private void ExportData_Click(object sender, EventArgs e)
  1510. {
  1511. ShowMenu.Items.Clear();
  1512. DataTable dt = (DataTable)dh.ExecuteSql("select * from CS_EXPORTSETTING where es_custcode='" + pi_cardcode.Text + "'", "select");
  1513. if (dt.Rows.Count == 0)
  1514. dt = (DataTable)dh.ExecuteSql("select * from CS_EXPORTSETTING where es_custcode is null", "select");
  1515. for (int i = 0; i < dt.Rows.Count; i++)
  1516. {
  1517. ShowMenu.Items.Add(new ToolStripMenuItem(dt.Rows[i]["el_remark"].ToString() + "#" + dt.Rows[i]["el_type"].ToString()));
  1518. }
  1519. ShowMenu.Show(new Point(ExportData.Location.X, ExportData.Location.Y + 20));
  1520. }
  1521. private void ShowMenu_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
  1522. {
  1523. //获取类型,单盘或者外箱
  1524. string type = e.ClickedItem.Text.Split('#')[1];
  1525. ExportFileDialog.Description = "选择导出的路径";
  1526. DialogResult result = ExportFileDialog.ShowDialog();
  1527. if (result == DialogResult.OK)
  1528. {
  1529. ExcelHandler eh = new ExcelHandler();
  1530. DataTable Field = (DataTable)dh.ExecuteSql("select * from CS_EXPORTSETTINGdetail left join CS_EXPORTSETTING on es_id=esd_esid where es_custcode='" + pi_cardcode.Text + "' and esd_enable=-1 and esd_filed is not null and el_type='" + type + "' order by esd_detno", "select");
  1531. if (Field.Rows.Count == 0)
  1532. {
  1533. Field = (DataTable)dh.ExecuteSql("select * from CS_EXPORTSETTINGdetail left join CS_EXPORTSETTING on es_id=esd_esid where es_custcode is null and es_isdefault=-1 and esd_enable=-1 and esd_filed is not null and el_type='" + type + "' order by esd_detno", "select");
  1534. }
  1535. string Fileds = "";
  1536. for (int i = 0; i < Field.Rows.Count; i++)
  1537. {
  1538. Fileds += Field.Rows[i]["esd_filed"].ToString() + ",";
  1539. }
  1540. sql.Clear();
  1541. sql.Append("select " + Fileds.Substring(0, Fileds.Length - 1) + " from ExportView where pib_inoutno='" + pi_inoutno.Text + "'");
  1542. string finnalSQL = "";
  1543. LogicHandler.GetExportDataSQL(pi_inoutno.Text, pi_cardcode.Text, type, sql.ToString(), out finnalSQL);
  1544. dt = (DataTable)dh.ExecuteSql(finnalSQL, "select");
  1545. eh.ExportExcel(dt, Field, ExportFileDialog.SelectedPath, pi_date.Text + "-" + pi_inoutno.Text + type);
  1546. string close = MessageBox.Show(this.ParentForm, "导出成功,是否打开文件", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question).ToString();
  1547. if (close.ToString() == "Yes")
  1548. Process.Start(ExportFileDialog.SelectedPath + "\\" + pi_date.Text + "-" + pi_inoutno.Text + type + ".xls");
  1549. }
  1550. }
  1551. private void AttachInfo_Click(object sender, EventArgs e)
  1552. {
  1553. if (pi_cardcode.Text != "")
  1554. {
  1555. 附件内容打印 att = new 附件内容打印(pi_cardcode.Text);
  1556. att.ShowDialog();
  1557. }
  1558. else MessageBox.Show("请先获取出库单信息", "提示");
  1559. }
  1560. private void MidBoxCapacity_Leave(object sender, EventArgs e)
  1561. {
  1562. NumericUpDown nup = (NumericUpDown)sender;
  1563. switch (nup.Name)
  1564. {
  1565. case "MidBoxCapacity":
  1566. Properties.Settings.Default.MidBoxCapacity = nup.Value;
  1567. Properties.Settings.Default.Save();
  1568. break;
  1569. case "OutboxCapacity":
  1570. Properties.Settings.Default.OutboxCapacity = nup.Value;
  1571. Properties.Settings.Default.Save();
  1572. break;
  1573. default:
  1574. break;
  1575. }
  1576. }
  1577. private void RefreshDBConnect_Tick(object sender, EventArgs e)
  1578. {
  1579. dh.ExecuteSql("select sysdate from dual", "select");
  1580. }
  1581. DataTable CSPrcode;
  1582. private void LoadPrcodeData()
  1583. {
  1584. DataTable Prcode = (DataTable)dh.ExecuteSql("select '' pd_piid,pd_inoutno,pd_custprodcode,pd_pocode,pd_whcode,pd_prodcode,'0' CollectedNum,'0' UnCollectedNum,pd_outqty,pr_unit,pd_brand,pjd_zxbzs_user,pjd_id,pd_pdno,pr_spec,0 checknum 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");
  1585. GridPrcode.DataSource = Prcode;
  1586. List<int> RemoveIndex = new List<int>();
  1587. double CollectNum = 0;
  1588. double OutNum = 0;
  1589. int combined = 0;
  1590. if (Combindetail.Checked)
  1591. combined = 1;
  1592. if (CombindetailTwo.Checked)
  1593. combined = 2;
  1594. if (Combindetail.Checked || CombindetailTwo.Checked)
  1595. {
  1596. CSPrcode = (DataTable)dh.ExecuteSql("select pd_piid,pd_pdno,pd_custprodcode,pd_whcode,pd_prodcode,CollectedNum,UnCollectedNum,pd_outqty,pr_unit,pr_spec,pd_brand,pjd_zxbzs_user,pjd_id,pd_inoutno,pd_pocode,nvl(checknum,0)checknum from CS$InoutPrcode where pd_inoutno='" + pi_inoutno.Text + "' and combined=" + combined + " order by pd_pdno", "select");
  1597. if (CSPrcode.Rows.Count == 0)
  1598. {
  1599. int CurrentIndex = 0;
  1600. for (int i = 0; i < GridPrcode.Rows.Count; i++)
  1601. {
  1602. string CurrentPrCode = GridPrcode.Rows[i].Cells["pd_prodcode"].Value.ToString();
  1603. string CurrentPDNO = GridPrcode.Rows[i].Cells["pd_pdno"].Value.ToString();
  1604. string CurrentOutQTY = GridPrcode.Rows[i].Cells["pd_outqty"].Value.ToString();
  1605. string collectqty = (SumQty.Compute("sum(pib_qty)", "pib_prodcode='" + CurrentPrCode + "' and pib_pdno='" + CurrentPDNO + "'").ToString());
  1606. CollectNum += double.Parse(collectqty == "" ? "0" : collectqty);
  1607. OutNum += double.Parse(CurrentOutQTY);
  1608. GridPrcode.Rows[i].Cells["CollectedNum"].Value = collectqty == "" ? "0" : collectqty;
  1609. }
  1610. for (int i = 0; i < GridPrcode.Rows.Count; i++)
  1611. {
  1612. if (i + 1 < GridPrcode.Rows.Count)
  1613. {
  1614. string BProdCode = GridPrcode.Rows[i].Cells["pd_prodcode"].Value.ToString();
  1615. string BCustProdCode = GridPrcode.Rows[i].Cells["pd_custprodcode1"].Value.ToString();
  1616. string BWhCode = GridPrcode.Rows[i].Cells["pd_whcode"].Value.ToString();
  1617. string BPrUnit = GridPrcode.Rows[i].Cells["pr_unit"].Value.ToString();
  1618. string BPrBrand = GridPrcode.Rows[i].Cells["pd_brand"].Value.ToString();
  1619. string BPoCode = GridPrcode.Rows[i].Cells["pd_pocode1"].Value.ToString();
  1620. string FProdCode = GridPrcode.Rows[i + 1].Cells["pd_prodcode"].Value.ToString();
  1621. string FCustProdCode = GridPrcode.Rows[i + 1].Cells["pd_custprodcode1"].Value.ToString();
  1622. string FPrUnit = GridPrcode.Rows[i + 1].Cells["pr_unit"].Value.ToString();
  1623. string FrBrand = GridPrcode.Rows[i + 1].Cells["pd_brand"].Value.ToString();
  1624. string FWhCode = GridPrcode.Rows[i + 1].Cells["pd_whcode"].Value.ToString();
  1625. string FPoCode = GridPrcode.Rows[i + 1].Cells["pd_pocode1"].Value.ToString();
  1626. if (BProdCode == FProdCode && BPrBrand == FrBrand && BCustProdCode == FCustProdCode && (CombindetailTwo.Checked && FPoCode == BPoCode || Combindetail.Checked))
  1627. {
  1628. 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());
  1629. 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());
  1630. RemoveIndex.Add(i + 1);
  1631. }
  1632. else
  1633. {
  1634. CurrentIndex = i + 1;
  1635. }
  1636. }
  1637. }
  1638. foreach (int item in RemoveIndex.OrderByDescending(x => x))
  1639. {
  1640. (GridPrcode.DataSource as DataTable).Rows.RemoveAt(item);
  1641. }
  1642. }
  1643. else GridPrcode.DataSource = CSPrcode;
  1644. }
  1645. else
  1646. {
  1647. CSPrcode = (DataTable)dh.ExecuteSql("select pd_piid,pd_pdno,pd_custprodcode,pd_whcode,pd_prodcode,CollectedNum,UnCollectedNum,pd_outqty,pr_unit,pr_spec,pd_brand,pjd_zxbzs_user,pjd_id,pd_inoutno,pd_pocode,nvl(checknum,0)checknum from CS$InoutPrcode where pd_inoutno='" + pi_inoutno.Text + "' and combined=" + combined + " order by pd_pdno", "select");
  1648. if (CSPrcode.Rows.Count == 0)
  1649. {
  1650. for (int i = 0; i < GridPrcode.Rows.Count; i++)
  1651. {
  1652. string CurrentPrCode = GridPrcode.Rows[i].Cells["pd_prodcode"].Value.ToString();
  1653. string CurrentPDNO = GridPrcode.Rows[i].Cells["pd_pdno"].Value.ToString();
  1654. string CurrentOutQTY = GridPrcode.Rows[i].Cells["pd_outqty"].Value.ToString();
  1655. string collectqty = (SumQty.Compute("sum(pib_qty)", "pib_prodcode='" + CurrentPrCode + "' and pib_pdno='" + CurrentPDNO + "'").ToString());
  1656. CollectNum += double.Parse(collectqty == "" ? "0" : collectqty);
  1657. OutNum += double.Parse(CurrentOutQTY);
  1658. GridPrcode.Rows[i].Cells["CollectedNum"].Value = collectqty == "" ? "0" : collectqty;
  1659. }
  1660. }
  1661. else GridPrcode.DataSource = CSPrcode;
  1662. }
  1663. dh.UpdateByCondition("prodinout", "pi_combine_user=" + combined, "pi_inoutno='" + pi_inoutno.Text + "'");
  1664. if (CSPrcode.Rows.Count == 0)
  1665. {
  1666. sql.Clear();
  1667. sql.Append("insert into CS$InoutPrcode (pd_piid,pd_pdno,pd_custprodcode,pd_whcode,pd_prodcode,");
  1668. sql.Append("CollectedNum,UnCollectedNum,pd_outqty,pr_unit,pr_spec,pd_brand,pjd_zxbzs_user,pjd_id,pd_inoutno,combined,pd_pocode)");
  1669. sql.Append("values ('',:pd_pdno,:pd_custprodcode,:pd_whcode,:pd_prodcode,:CollectedNum,:UnCollectedNum,:pd_outqty,:pr_unit,:pr_spec,:pd_brand,:pjd_zxbzs_user,:pjd_id,:pd_inoutno,'" + combined + "',:pd_pocode)");
  1670. dh.SaveDataTable((GridPrcode.DataSource as DataTable), "CS$InoutPrcode", "pd_piid", sql.ToString());
  1671. }
  1672. else
  1673. {
  1674. CollectNum = float.Parse(CSPrcode.Compute("sum(CollectedNum)", "1=1").ToString());
  1675. OutNum = float.Parse(CSPrcode.Compute("sum(pd_outqty)", "1=1").ToString());
  1676. }
  1677. ProcessCount.Text = CollectNum + "/" + OutNum;
  1678. if (GridPrcode.Rows.Count > 0)
  1679. {
  1680. CurrentPrCode = GridPrcode.Rows[0].Cells["pd_prodcode"].Value.ToString();
  1681. CurrentZXBZ = GridPrcode.Rows[0].Cells["pjd_zxbzs_user"].Value.ToString();
  1682. CurrentUnit = GridPrcode.Rows[0].Cells["pr_unit"].Value.ToString();
  1683. CurrentPDNO = GridPrcode.Rows[0].Cells["pd_pdno"].Value.ToString();
  1684. CurrentPrCount = GridPrcode.Rows[0].Cells["pd_outqty"].Value.ToString();
  1685. CurrentBrand = GridPrcode.Rows[0].Cells["pd_brand"].Value.ToString();
  1686. GridPrcode.Rows[0].Selected = true;
  1687. }
  1688. }
  1689. private void OutBoxNum_Click(object sender, EventArgs e)
  1690. {
  1691. string OutBox = OutBoxNum.Text;
  1692. OutBoxNum.Items.Clear();
  1693. 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");
  1694. ItemObject io = new ItemObject("新增", "新增");
  1695. OutBoxNum.Items.Add(io);
  1696. io = new ItemObject("全部", "全部");
  1697. OutBoxNum.Items.Add(io);
  1698. for (int i = 0; i < dt.Rows.Count; i++)
  1699. {
  1700. string pib_outboxcode2 = dt.Rows[i]["pib_outboxcode2"].ToString();
  1701. io = new ItemObject(pib_outboxcode2, pib_outboxcode2);
  1702. OutBoxNum.Items.Add(io);
  1703. }
  1704. if (OutBoxNum.Text == "新增" || OutBoxNum.Text == "")
  1705. {
  1706. if (dt.Rows.Count > 0)
  1707. OutBoxNum.SelectedIndex = 2;
  1708. else
  1709. OutBoxNum.SelectedIndex = 0;
  1710. }
  1711. if (OutBox != "新增" && OutBox != "")
  1712. OutBoxNum.Text = OutBox;
  1713. }
  1714. string ReSetType = "";
  1715. /// <summary>
  1716. /// 获取条码规则
  1717. /// </summary>
  1718. /// <param name="Type"></param>
  1719. /// <param name="Prefix"></param>
  1720. /// <param name="Suffix"></param>
  1721. /// <param name="MaxNum"></param>
  1722. /// <param name="SerialNumLength"></param>
  1723. /// <param name="Radix"></param>
  1724. private void GetBarCodeRule(out string Prefix, out string Suffix, out int MaxNum, out int SerialNumLength, out int Radix, int Count)
  1725. {
  1726. //获取编码规则
  1727. Prefix = "";
  1728. Suffix = "";
  1729. NrCode = "";
  1730. MaxNum = 0;
  1731. SerialNumLength = 0;
  1732. Radix = 0;
  1733. DataTable Nr = (DataTable)dh.ExecuteSql("select nvl(nr_resettype,' ')nr_resettype,nr_sharerule,nr_code,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");
  1734. //如果没有则取公共规则
  1735. if (Nr.Rows.Count == 0)
  1736. Nr = (DataTable)dh.ExecuteSql("select nvl(nr_resettype,' ')nr_resettype,nr_sharerule,nr_code,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");
  1737. //用于过滤参数的正则表达式
  1738. ReSetType = "";
  1739. if (Nr.Rows.Count > 0)
  1740. {
  1741. string ShareRule = Nr.Rows[0]["nr_sharerule"].ToString();
  1742. DataTable dt1 = (DataTable)dh.ExecuteSql("select nvl(nr_resettype,' ')nr_resettype,nr_sharerule,nr_code,nrd_detno,nrd_name,nrd_radix,nrd_type,nrd_sql,nrd_length from NoRuleDetail left join norule on nrd_nrid=nr_id where nr_code='" + ShareRule + "' order by nrd_detno", "select");
  1743. if (dt1.Rows.Count > 0)
  1744. {
  1745. Nr = dt1;
  1746. }
  1747. else
  1748. {
  1749. if (ShareRule != "")
  1750. {
  1751. MessageBox.Show("共享规则" + ShareRule + "不存在");
  1752. return;
  1753. }
  1754. }
  1755. }
  1756. if (Nr.Rows.Count > 0)
  1757. {
  1758. switch (Nr.Rows[0]["nr_resettype"].ToString())
  1759. {
  1760. case "Year":
  1761. sql.Clear();
  1762. sql.Append("to_char(sysdate,'yyyy')");
  1763. break;
  1764. case "Month":
  1765. sql.Clear();
  1766. sql.Append("to_char(sysdate,'yyyyMM')");
  1767. break;
  1768. case "Week":
  1769. sql.Clear();
  1770. sql.Append("to_char(sysdate,'yyyyiw')");
  1771. break;
  1772. case "Day":
  1773. sql.Clear();
  1774. sql.Append("to_char(sysdate,'yyyyMMdd')");
  1775. break;
  1776. case " ":
  1777. sql.Clear();
  1778. sql.Append("' '");
  1779. break;
  1780. default:
  1781. break;
  1782. }
  1783. ReSetType = dh.getFieldDataByCondition("dual", sql.ToString(), "1=1").ToString();
  1784. }
  1785. Regex match = new Regex("{\\w+}");
  1786. //用于存放每一项的明细的数据
  1787. string[] NrData = new string[Nr.Rows.Count];
  1788. //流水长度
  1789. Dictionary<int, string> NrDic = new Dictionary<int, string>();
  1790. for (int m = 0; m < Nr.Rows.Count; m++)
  1791. {
  1792. NrCode = Nr.Rows[m]["nr_code"].ToString();
  1793. switch (Nr.Rows[m]["nrd_type"].ToString())
  1794. {
  1795. //常量直接进行拼接
  1796. case "常量":
  1797. Prefix += Nr.Rows[m]["nrd_sql"].ToString();
  1798. Suffix += Nr.Rows[m]["nrd_sql"].ToString();
  1799. break;
  1800. case "SQL":
  1801. string SQL = Nr.Rows[m]["nrd_sql"].ToString();
  1802. DataTable Temp;
  1803. //如果不包含参数替换
  1804. if (SQL.IndexOf("{") == 0)
  1805. {
  1806. Temp = (DataTable)dh.ExecuteSql(SQL, "select");
  1807. }
  1808. else
  1809. {
  1810. SQL = SQL.Replace("{pd_pdno}", CurrentPDNO);
  1811. //替换参数后重新执行SQL
  1812. foreach (Match mch in match.Matches(SQL))
  1813. {
  1814. SQL = SQL.Replace(mch.Value.Trim(), "'" + pi_inoutno.Text + "'");
  1815. }
  1816. Temp = (DataTable)dh.ExecuteSql(SQL, "select");
  1817. }
  1818. if (Temp.Rows.Count > 0)
  1819. {
  1820. Prefix += Temp.Rows[0][0].ToString();
  1821. Suffix += Temp.Rows[0][0].ToString();
  1822. }
  1823. break;
  1824. //流水需要通过MaxNumber去取
  1825. case "流水":
  1826. string maxnum = "";
  1827. if (ReSetType != " ")
  1828. {
  1829. maxnum = dh.getFieldDataByCondition("RuleMaxNum", "rmn_maxnumber", "rmn_nrcode='" + (NrCode == "" ? "Default" : NrCode) + "' and nvl(rmn_type,' ')='" + ReSetType + "'").ToString();
  1830. }
  1831. else
  1832. {
  1833. maxnum = dh.getFieldDataByCondition("RuleMaxNum", "rmn_maxnumber", "rmn_nrcode='" + (NrCode == "" ? "Default" : NrCode) + "' and rmn_prefix='" + Prefix + "' ").ToString();
  1834. }
  1835. //设置当前流水
  1836. if (maxnum == "")
  1837. {
  1838. if (ReSetType != " ")
  1839. {
  1840. maxnum = dh.getFieldDataByCondition("RuleMaxNum", "rmn_maxnumber", "rmn_nrcode='" + (NrCode == "" ? "Default" : NrCode) + "' and nvl(rmn_type,' ')='" + ReSetType + "'").ToString();
  1841. }
  1842. else
  1843. {
  1844. maxnum = dh.getFieldDataByCondition("RuleMaxNum", "rmn_maxnumber", "rmn_nrcode='" + (NrCode == "" ? "Default" : NrCode) + "' and rmn_prefix='" + Prefix + "' ").ToString();
  1845. }
  1846. if (maxnum == "")
  1847. {
  1848. maxnum = "1";
  1849. }
  1850. Count = int.Parse(maxnum) + Count;
  1851. dh.ExecuteSql("insert into RuleMaxNum(rmn_id,rmn_nrcode,rmn_prefix,rmn_maxnumber,rmn_type) values(RuleMaxNum_seq.nextval,'" + (NrCode == "" ? "Default" : NrCode) + "','" + Prefix + "','" + Count + "','" + ReSetType + "')", "insert");
  1852. MaxNum = int.Parse(maxnum);
  1853. }
  1854. else
  1855. {
  1856. MaxNum = int.Parse(maxnum);
  1857. if (ReSetType != " ")
  1858. {
  1859. dh.UpdateByCondition("RULEMAXNUM", "rmn_maxnumber='" + (MaxNum + Count) + "'", "rmn_nrcode='" + (NrCode == "" ? "Default" : NrCode) + "' and nvl(rmn_type,' ')='" + ReSetType + "'");
  1860. }
  1861. else
  1862. {
  1863. dh.UpdateByCondition("RULEMAXNUM", "rmn_maxnumber='" + (MaxNum + Count) + "'", "rmn_nrcode='" + (NrCode == "" ? "Default" : NrCode) + "' and rmn_prefix='" + Prefix + "'");
  1864. }
  1865. }
  1866. SerialNumLength = int.Parse(Nr.Rows[m]["nrd_length"].ToString());
  1867. Radix = int.Parse(Nr.Rows[m]["nrd_radix"].ToString());
  1868. Suffix = "";
  1869. break;
  1870. default:
  1871. break;
  1872. }
  1873. }
  1874. }
  1875. private void GridPrcode_CellEndEdit(object sender, DataGridViewCellEventArgs e)
  1876. {
  1877. string Value = GridPrcode.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString();
  1878. string ID = GridPrcode.Rows[e.RowIndex].Cells["pjd_id"].Value.ToString();
  1879. string checknum = GridPrcode.Rows[e.RowIndex].Cells["checknum"].Value.ToString();
  1880. string pdno = GridPrcode.Rows[e.RowIndex].Cells["pd_pdno"].Value.ToString();
  1881. if (GridPrcode.Columns[e.ColumnIndex].Name == "pjd_zxbzs_user")
  1882. {
  1883. dh.UpdateByCondition("PRODJOINVENDDETAIL", "pjd_zxbzs_user='" + Value + "'", "pjd_id='" + ID + "'");
  1884. dh.UpdateByCondition("CS$INOUTPRCODE", "pjd_zxbzs_user='" + Value + "'", "pjd_id='" + ID + "' and pd_inoutno='" + pi_inoutno.Text + "'");
  1885. }
  1886. if (GridPrcode.Columns[e.ColumnIndex].Name == "checknum")
  1887. {
  1888. //更新复核数据
  1889. dh.UpdateByCondition("CS$InoutPrcode", "checknum='" + checknum + "'", "pd_inoutno='" + pi_inoutno.Text + "' and pd_pdno='" + pdno + "' and combined=" + combined);
  1890. }
  1891. //删除对应物料的明细
  1892. CurrentPrCode = GridPrcode.Rows[e.RowIndex].Cells["pd_prodcode"].Value.ToString();
  1893. CurrentZXBZ = GridPrcode.Rows[e.RowIndex].Cells["pjd_zxbzs_user"].Value.ToString();
  1894. CurrentUnit = GridPrcode.Rows[e.RowIndex].Cells["pr_unit"].Value.ToString();
  1895. CurrentPDNO = GridPrcode.Rows[e.RowIndex].Cells["pd_pdno"].Value.ToString();
  1896. CurrentPrCount = GridPrcode.Rows[e.RowIndex].Cells["pd_outqty"].Value.ToString();
  1897. CurrentBrand = GridPrcode.Rows[e.RowIndex].Cells["pd_brand"].Value.ToString();
  1898. GridPrcode.Rows[e.RowIndex].Selected = true;
  1899. if (e.RowIndex - 2 >= 0)
  1900. GridPrcode.FirstDisplayedScrollingRowIndex = e.RowIndex - 2;
  1901. else
  1902. GridPrcode.FirstDisplayedScrollingRowIndex = e.RowIndex;
  1903. LoadGridData(sender, new EventArgs());
  1904. }
  1905. private void GridPrcode_SelectionChanged(object sender, EventArgs e)
  1906. {
  1907. if (GridPrcode.SelectedRows.Count > 0)
  1908. {
  1909. DataGridViewSelectedRowCollection dsc = GridPrcode.SelectedRows;
  1910. MachineCollectRowIndex = GridPrcode.SelectedRows[0].Index;
  1911. CurrentPrCode = GridPrcode.Rows[dsc[0].Index].Cells["pd_prodcode"].Value.ToString();
  1912. CurrentZXBZ = GridPrcode.Rows[dsc[0].Index].Cells["pjd_zxbzs_user"].Value.ToString();
  1913. CurrentUnit = GridPrcode.Rows[dsc[0].Index].Cells["pr_unit"].Value.ToString();
  1914. CurrentPDNO = GridPrcode.Rows[dsc[0].Index].Cells["pd_pdno"].Value.ToString();
  1915. CurrentPrCount = GridPrcode.Rows[dsc[0].Index].Cells["pd_outqty"].Value.ToString();
  1916. CurrentBrand = GridPrcode.Rows[dsc[0].Index].Cells["pd_brand"].Value.ToString();
  1917. GridPrcode.Rows[dsc[0].Index].Selected = true;
  1918. if (dsc[0].Index - 2 >= 0)
  1919. GridPrcode.FirstDisplayedScrollingRowIndex = dsc[0].Index - 2;
  1920. else
  1921. GridPrcode.FirstDisplayedScrollingRowIndex = dsc[0].Index;
  1922. }
  1923. }
  1924. private void GridPrcode_DataError(object sender, DataGridViewDataErrorEventArgs e) { }
  1925. private void GridPrcode_CellClick(object sender, DataGridViewCellEventArgs e)
  1926. {
  1927. if (e.RowIndex >= 0)
  1928. {
  1929. GridPrcode.Rows[e.RowIndex].Selected = true;
  1930. if (e.RowIndex - 2 > 0)
  1931. GridPrcode.FirstDisplayedScrollingRowIndex = e.RowIndex - 2;
  1932. else
  1933. GridPrcode.FirstDisplayedScrollingRowIndex = e.RowIndex;
  1934. }
  1935. }
  1936. private void DCCheck_Leave(object sender, EventArgs e)
  1937. {
  1938. try
  1939. {
  1940. Properties.Settings.Default.DCCheck = int.Parse(DCCheck.Text);
  1941. Properties.Settings.Default.Save();
  1942. }
  1943. catch (Exception)
  1944. {
  1945. MessageBox.Show("DC校验时间必须是整数");
  1946. }
  1947. }
  1948. /// <summary>
  1949. /// 校验DateCode
  1950. /// </summary>
  1951. /// <param name="DateCode"></param>
  1952. private bool CheckDateCode(string DateCode)
  1953. {
  1954. try
  1955. {
  1956. //根据DateCode计算的日期
  1957. string Year = DateCode.Substring(0, 2);
  1958. System.DateTime dt = new System.DateTime(int.Parse("20" + Year), 01, 01);
  1959. string Week = DateCode.Substring(2, 2);
  1960. System.DateTime dt1 = dt.AddDays(int.Parse(Week) * 7);
  1961. //减去DC校验后的日期
  1962. System.DateTime now = System.DateTime.Now;
  1963. System.DateTime now1 = now.AddDays(-int.Parse(DCCheck.Text));
  1964. //物料的DateCode大于限制日期即可
  1965. if (dt1 > now1)
  1966. {
  1967. return true;
  1968. }
  1969. return false;
  1970. }
  1971. catch (Exception)
  1972. {
  1973. return false;
  1974. }
  1975. }
  1976. private void PrintFooter_Click(object sender, EventArgs e)
  1977. {
  1978. FootReport.Load(@"\\10.2.10.238\PRINTE\FASTREPORT\唛头.frx");
  1979. 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");
  1980. string SQL = "select pib_outboxcode2||'/'||(select max(to_number(pib_outboxcode2)) from prodiobarcode where pib_inoutno='" + pi_inoutno.Text + "') from prodiobarcode where pib_id=";
  1981. for (int i = 0; i < dt.Rows.Count; i++)
  1982. {
  1983. DataTable dt1 = (DataTable)dh.ExecuteSql(SQL + dt.Rows[i]["pib_id"].ToString(), "select");
  1984. FootReport.SetParameterValue("唛头", dt1.Rows[0][0].ToString());
  1985. FootReport.PrintSettings.ShowDialog = false;
  1986. FootReport.PrintSettings.Printer = SingleLabelPrinter.Text;
  1987. FootReport.Print();
  1988. }
  1989. LogManager.DoCommandLog(pi_inoutno.Text, User.UserCode, "打印唛头", "成功");
  1990. }
  1991. private void Input_KeyUp(object sender, KeyEventArgs e)
  1992. {
  1993. if (e.KeyCode == Keys.Enter)
  1994. {
  1995. Input.SelectAll();
  1996. }
  1997. }
  1998. private void GridPrcode_CellPainting(object sender, DataGridViewCellPaintingEventArgs e)
  1999. {
  2000. bool mouseOver = e.CellBounds.Contains(this.PointToClient(Cursor.Position));
  2001. if (e.ColumnIndex > 0 && e.RowIndex >= 0)
  2002. {
  2003. if (GridPrcode.Columns[e.ColumnIndex].Name == "CollectedNum")
  2004. {
  2005. SolidBrush solidBrush = new SolidBrush(Color.FromArgb(51, 153, 255));
  2006. if (GridPrcode.Rows[e.RowIndex].Cells["CollectedNum"].Value.ToString() != GridPrcode.Rows[e.RowIndex].Cells["pd_outqty"].Value.ToString())
  2007. e.Graphics.FillRectangle(mouseOver ? solidBrush : Brushes.Yellow, e.CellBounds);
  2008. else
  2009. e.Graphics.FillRectangle(mouseOver ? solidBrush : Brushes.White, e.CellBounds);
  2010. Rectangle border = e.CellBounds;
  2011. border.Width -= 1;
  2012. e.Graphics.DrawRectangle(Pens.White, border);
  2013. e.PaintContent(e.CellBounds);
  2014. e.Handled = true;
  2015. }
  2016. }
  2017. }
  2018. private void GridPrcode_CellMouseUp(object sender, DataGridViewCellMouseEventArgs e)
  2019. {
  2020. if (e.Button == MouseButtons.Right)
  2021. {
  2022. if (e.RowIndex >= 0 && e.ColumnIndex > 0)
  2023. {
  2024. string Conetent = GridPrcode.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString();
  2025. Clipboard.SetText(Conetent);
  2026. MessageBox.Show("已复制内容" + Conetent);
  2027. }
  2028. }
  2029. }
  2030. private void Pack_Click(object sender, EventArgs e)
  2031. {
  2032. if (LabelInf.Rows.Count > 0)
  2033. {
  2034. int GetNumCount = 1;
  2035. for (int i = 0; i < LabelInf.Rows.Count; i++)
  2036. {
  2037. if (LabelInf.Rows[i].Cells["pib_custoutboxcode"].Value.ToString() == "")
  2038. {
  2039. if (i + 1 < LabelInf.Rows.Count)
  2040. {
  2041. string FPrcode = LabelInf.Rows[i].Cells["pib_prodcode"].Value.ToString();
  2042. string FPocode = LabelInf.Rows[i].Cells["pd_pocode"].Value.ToString();
  2043. string FWhcode = LabelInf.Rows[i].Cells["pib_brand"].Value.ToString();
  2044. string FDC = LabelInf.Rows[i].Cells["pib_datecode"].Value.ToString();
  2045. string FLOTNO = LabelInf.Rows[i].Cells["pib_lotno"].Value.ToString();
  2046. string FPDCustProdCode = LabelInf.Rows[i].Cells["pd_custprodcode"].Value.ToString();
  2047. string BPrcode = LabelInf.Rows[i + 1].Cells["pib_prodcode"].Value.ToString();
  2048. string BPocode = LabelInf.Rows[i + 1].Cells["pd_pocode"].Value.ToString();
  2049. string BWhcode = LabelInf.Rows[i + 1].Cells["pib_brand"].Value.ToString();
  2050. string BDC = LabelInf.Rows[i + 1].Cells["pib_datecode"].Value.ToString();
  2051. string BLOTNO = LabelInf.Rows[i + 1].Cells["pib_lotno"].Value.ToString();
  2052. string BPDCustProdCode = LabelInf.Rows[i + 1].Cells["pd_custprodcode"].Value.ToString();
  2053. if (FPDCustProdCode != BPDCustProdCode || FPrcode != BPrcode || FPocode != BPocode || FWhcode != BWhcode || (DiffDC.Checked && FDC != BDC) || (DiffLotNo.Checked && FLOTNO != BLOTNO))
  2054. {
  2055. GetNumCount = GetNumCount + 1;
  2056. }
  2057. }
  2058. }
  2059. }
  2060. GetBarCodeRule(out Prefix, out Suffix, out MaxNum, out NumLength, out Radix, GetNumCount);
  2061. List<string> OutBoxCode = new List<string>();
  2062. List<string> PIBID = new List<string>();
  2063. string Str_OutBoxCode = "";
  2064. for (int i = 0; i < LabelInf.Rows.Count; i++)
  2065. {
  2066. if (LabelInf.Rows[i].Cells["pib_custoutboxcode"].Value.ToString() == "")
  2067. {
  2068. PIBID.Add(LabelInf.Rows[i].Cells["pib_id1"].Value.ToString());
  2069. string serialcode = BaseUtil.DToAny(MaxNum, Radix);
  2070. for (int k = serialcode.ToString().Length; k < NumLength; k++)
  2071. {
  2072. serialcode = "0" + serialcode;
  2073. }
  2074. if (i + 1 < LabelInf.Rows.Count)
  2075. {
  2076. string FPrcode = LabelInf.Rows[i].Cells["pib_prodcode"].Value.ToString();
  2077. string FPocode = LabelInf.Rows[i].Cells["pd_pocode"].Value.ToString();
  2078. string FWhcode = LabelInf.Rows[i].Cells["pib_brand"].Value.ToString();
  2079. string FDC = LabelInf.Rows[i].Cells["pib_datecode"].Value.ToString();
  2080. string FLOTNO = LabelInf.Rows[i].Cells["pib_lotno"].Value.ToString();
  2081. string FPDCustProdCode = LabelInf.Rows[i].Cells["pd_custprodcode"].Value.ToString();
  2082. string FPDNO = LabelInf.Rows[i].Cells["pib_pdno"].Value.ToString();
  2083. string BPrcode = LabelInf.Rows[i + 1].Cells["pib_prodcode"].Value.ToString();
  2084. string BPocode = LabelInf.Rows[i + 1].Cells["pd_pocode"].Value.ToString();
  2085. string BWhcode = LabelInf.Rows[i + 1].Cells["pib_brand"].Value.ToString();
  2086. string BDC = LabelInf.Rows[i + 1].Cells["pib_datecode"].Value.ToString();
  2087. string BLOTNO = LabelInf.Rows[i + 1].Cells["pib_lotno"].Value.ToString();
  2088. string BPDCustProdCode = LabelInf.Rows[i + 1].Cells["pd_custprodcode"].Value.ToString();
  2089. string BPDNO = LabelInf.Rows[i + 1].Cells["pib_pdno"].Value.ToString();
  2090. if ((DiffDetno.Checked && BPDNO != FPDNO) || (DiffCPN.Checked && FPDCustProdCode != BPDCustProdCode) || FPrcode != BPrcode || FPocode != BPocode || FWhcode != BWhcode || (DiffDC.Checked && FDC != BDC) || (DiffLotNo.Checked && FLOTNO != BLOTNO))
  2091. {
  2092. MaxNum = MaxNum + 1;
  2093. }
  2094. }
  2095. OutBoxCode.Add(Prefix + serialcode + Suffix);
  2096. Str_OutBoxCode += "'" + Prefix + serialcode + Suffix + "',";
  2097. }
  2098. }
  2099. if (OutBoxCode.ToArray().Length > 0)
  2100. {
  2101. if (!dh.CheckExist("prodiobarcode", "pib_custcode='" + pi_cardcode.Text + "' and pib_custoutboxcode in (" + Str_OutBoxCode.Substring(0, Str_OutBoxCode.Length - 1) + ")"))
  2102. {
  2103. 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());
  2104. }
  2105. else
  2106. {
  2107. if (ReSetType != " ")
  2108. {
  2109. dh.UpdateByCondition("RULEMAXNUM", "rmn_maxnumber='" + (MaxNum + 1) + "'", "rmn_nrcode='" + (NrCode == "" ? "Default" : NrCode) + "' and nvl(rmn_type,' ')='" + ReSetType + "'");
  2110. }
  2111. else
  2112. {
  2113. dh.UpdateByCondition("RULEMAXNUM", "rmn_maxnumber='" + (MaxNum + 1) + "'", "rmn_nrcode='" + (NrCode == "" ? "Default" : NrCode) + "' and rmn_prefix='" + Prefix + "'");
  2114. }
  2115. Pack_Click(sender, e);
  2116. return;
  2117. }
  2118. LoadGridData(sender, e);
  2119. }
  2120. }
  2121. }
  2122. private void PackMidBox_Click(object sender, EventArgs e)
  2123. {
  2124. DataTable dt = (DataTable)dh.ExecuteSql("select distinct pib_outboxcode2 from prodiobarcode where pib_inoutno='" + pi_inoutno.Text + "' and pib_outboxcode2='" + OutBoxNum.Text + "' order by pib_outboxcode2", "select");
  2125. DataTable dt1 = null;
  2126. int GetNumCount = 0;
  2127. for (int i = 0; i < dt.Rows.Count; i++)
  2128. {
  2129. dt1 = (DataTable)dh.ExecuteSql("select pib_id,pib_prodcode,pd_custprodcode from prodiobarcode left join prodiodetail on pib_pdid=pd_id 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");
  2130. //如果不是10的整数倍则为尾盒
  2131. int tencount = 0;
  2132. for (int j = 0; j < dt1.Rows.Count; j++)
  2133. {
  2134. if (tencount % MidboxCapacity.Value == 0 || (dt1.Rows[j]["pib_prodcode"].ToString() != dt1.Rows[j - 1]["pib_prodcode"].ToString()) || (dt1.Rows[j]["pd_custprodcode"].ToString() != dt1.Rows[j - 1]["pd_custprodcode"].ToString()))
  2135. {
  2136. GetNumCount = GetNumCount + 1;
  2137. }
  2138. tencount = tencount + 1;
  2139. }
  2140. }
  2141. GetBarCodeRule(out Prefix, out Suffix, out MaxNum, out NumLength, out Radix, GetNumCount);
  2142. if (Radix > 0)
  2143. {
  2144. //生成中盒条码
  2145. int pib_outboxcode1 = int.Parse(dh.getFieldDataByCondition("prodiobarcode", "max(to_number(nvl(pib_outboxcode1,0)))", "pib_inoutno='" + pi_inoutno.Text + "'").ToString());
  2146. MaxNum = MaxNum - 1;
  2147. for (int i = 0; i < dt.Rows.Count; i++)
  2148. {
  2149. List<string> MidBoxCode = new List<string>();
  2150. List<string> PIBID = new List<string>();
  2151. List<string> PIBOUTBOXCODE1 = new List<string>();
  2152. dt1 = (DataTable)dh.ExecuteSql("select pib_id,pib_prodcode,pd_custprodcode from prodiobarcode left join prodiodetail on pib_pdid=pd_id 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");
  2153. //如果不是10的整数倍则为尾盒
  2154. int tencount = 0;
  2155. for (int j = 0; j < dt1.Rows.Count; j++)
  2156. {
  2157. if (tencount % MidboxCapacity.Value == 0 || (dt1.Rows[j]["pib_prodcode"].ToString() != dt1.Rows[j - 1]["pib_prodcode"].ToString()) || (dt1.Rows[j]["pd_custprodcode"].ToString() != dt1.Rows[j - 1]["pd_custprodcode"].ToString()))
  2158. {
  2159. pib_outboxcode1 = pib_outboxcode1 + 1;
  2160. MaxNum = MaxNum + 1;
  2161. tencount = 0;
  2162. }
  2163. tencount = tencount + 1;
  2164. string serialcode = BaseUtil.DToAny(MaxNum, Radix);
  2165. for (int k = serialcode.ToString().Length; k < NumLength; k++)
  2166. {
  2167. serialcode = "0" + serialcode;
  2168. }
  2169. MidBoxCode.Add(Prefix + serialcode + Suffix);
  2170. PIBID.Add(dt1.Rows[j]["pib_id"].ToString());
  2171. PIBOUTBOXCODE1.Add(pib_outboxcode1.ToString());
  2172. }
  2173. 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());
  2174. }
  2175. }
  2176. LoadGridData(sender, e);
  2177. }
  2178. private void PrintStatus_Click(object sender, EventArgs e)
  2179. {
  2180. EnablePrint = !EnablePrint;
  2181. if (EnablePrint)
  2182. {
  2183. SetPrintStatus_label.ForeColor = Color.Green;
  2184. SetPrintStatus_label.Text = "可打印";
  2185. }
  2186. else
  2187. {
  2188. SetPrintStatus_label.ForeColor = Color.Red;
  2189. SetPrintStatus_label.Text = "暂停打印";
  2190. }
  2191. Input.Focus();
  2192. }
  2193. private void CustomerLabel_Click(object sender, EventArgs e)
  2194. {
  2195. sql.Clear();
  2196. sql.Append("update prodiobarcode set pib_custbarcode=case when instr(pib_custbarcode,'SL')=0 ");
  2197. sql.Append("then ('SL'||pib_custbarcode)else pib_custbarcode end, pib_custoutboxcode=case when instr");
  2198. sql.Append("(pib_custoutboxcode,'SC')=0 then ('SC'||pib_custoutboxcode)else pib_custoutboxcode end where pib_inoutno='" + pi_inoutno.Text + "'");
  2199. dh.ExecuteSql(sql.ToString(), "select");
  2200. LoadGridData(sender, e);
  2201. CustomerLabel.Enabled = false;
  2202. }
  2203. private void Combindetail_CheckedChanged(object sender, EventArgs e)
  2204. {
  2205. if (Combindetail.Checked)
  2206. {
  2207. CombindetailTwo.Checked = false;
  2208. }
  2209. if (LoadCheck)
  2210. {
  2211. LoadPrcodeData();
  2212. string response = "";
  2213. string[] param = new string[] { PI_ID, "1", response };
  2214. dh.CallProcedure("USER_PRODOUT_GROUPQTY", param);
  2215. }
  2216. }
  2217. private void CombindetailTwo_CheckedChanged(object sender, EventArgs e)
  2218. {
  2219. if (CombindetailTwo.Checked)
  2220. {
  2221. Combindetail.Checked = false;
  2222. }
  2223. if (LoadCheck)
  2224. {
  2225. LoadPrcodeData();
  2226. string response = "";
  2227. string[] param = new string[] { PI_ID, "2", response };
  2228. dh.CallProcedure("USER_PRODOUT_GROUPQTY", param);
  2229. }
  2230. }
  2231. string SelectProdcode = "";
  2232. int SelectRowIndex = -1;
  2233. private void LabelInf_CellClick(object sender, DataGridViewCellEventArgs e)
  2234. {
  2235. if (e.RowIndex >= 0)
  2236. {
  2237. LabelInf.Rows[e.RowIndex].Selected = true;
  2238. SelectRowIndex = e.RowIndex;
  2239. }
  2240. }
  2241. private void OutBoxNum_SelectedIndexChanged(object sender, EventArgs e)
  2242. {
  2243. OutBoxNum1 = OutBoxNum.Text;
  2244. LoadGridData(sender, e);
  2245. }
  2246. private void LabelInf_SelectionChanged(object sender, EventArgs e)
  2247. {
  2248. DataGridViewSelectedRowCollection dsc = LabelInf.SelectedRows;
  2249. if (dsc.Count > 0)
  2250. {
  2251. SelectRowIndex = dsc[0].Index;
  2252. }
  2253. }
  2254. string OutBoxNum1 = "";
  2255. private void OutBoxNum_SelectionChangeCommitted(object sender, EventArgs e)
  2256. {
  2257. if (OutBoxNum1 != "全部" && OutBoxNum1 != "新增")
  2258. if (dh.getFieldDataByCondition("prodiobarcode", "pib_outifprint", "pib_inoutno='" + pi_inoutno.Text + "' and pib_outboxcode2='" + OutBoxNum1 + "'").ToString() != "-1")
  2259. {
  2260. MessageBox.Show("外箱号" + OutBoxNum1 + "尚未打印标签");
  2261. }
  2262. OutBoxNum1 = OutBoxNum.Text;
  2263. if (OutBoxNum1 == "新增")
  2264. {
  2265. PassSixTenCount = 1;
  2266. PassTenCount = 1;
  2267. CurrentBoxNum.Value = 0;
  2268. CurrentOutBoxNum.Value = 0;
  2269. }
  2270. }
  2271. private void Reset_Click(object sender, EventArgs e)
  2272. {
  2273. string close = MessageBox.Show(this.ParentForm, "清除当前已采集数据,刷新待采集数据", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question).ToString();
  2274. if (close.ToString() == "Yes")
  2275. {
  2276. dh.ExecuteSql("delete from prodiobarcode where pib_inoutno='" + pi_inoutno.Text + "'", "delete");
  2277. dh.ExecuteSql("delete from CS$InoutPrcode where pd_inoutno='" + pi_inoutno.Text + "'", "delete");
  2278. dh.UpdateByCondition("prodinout", "pi_user_packingstatus=''", "pi_inoutno='" + pi_inoutno.Text + "'");
  2279. pi_inoutno_KeyDown(sender, new KeyEventArgs(Keys.Enter));
  2280. }
  2281. }
  2282. private void AddNewOutBox_Click(object sender, EventArgs e)
  2283. {
  2284. OutBoxNum.Text = "新增";
  2285. }
  2286. private void GetPDdata_Click(object sender, EventArgs e)
  2287. {
  2288. dh.ExecuteSql("delete from CS$InoutPrcode where pd_inoutno='" + pi_inoutno.Text + "'", "delete");
  2289. LoadPrcodeData();
  2290. dh.UpdateByCondition("CS$InoutPrcode", "collectednum=(select nvl(sum(pib_qty),0) from prodiobarcode where pib_inoutno=pd_inoutno and pib_pdno=pd_pdno)", "pd_inoutno='" + pi_inoutno.Text + "'");
  2291. MessageBox.Show("同步出货单明细数据成功", "提示");
  2292. }
  2293. private void ResetHBXH_Click(object sender, EventArgs e)
  2294. {
  2295. dh.ExecuteSql("update prodiodetail set PD_HBXH_USER=pd_pdno where pd_inoutno='" + pi_inoutno.Text + "'", "update");
  2296. MessageBox.Show("重置序号成功", "提示");
  2297. }
  2298. private void ButtonWeigh_Click(object sender, EventArgs e)
  2299. {
  2300. if (Weight.Text != "" && Weight.Text != "0.000")
  2301. {
  2302. sql.Clear();
  2303. sql.Append("update prodiobarcode set pib_boxweight='" + Weight.Text + "' where pib_inoutno='" + pi_inoutno.Text + "' ");
  2304. sql.Append(" and pib_outboxcode2='" + OutBoxNum.Text + "'");
  2305. dh.ExecuteSql(sql.ToString(), "update");
  2306. LoadGridData(sender, e);
  2307. }
  2308. else
  2309. {
  2310. MessageBox.Show("请先连接电子秤!");
  2311. }
  2312. }
  2313. Regex reg = new Regex(@"\d+.\d+");
  2314. ComInfoSet cis;
  2315. private void ConnectCom_Click(object sender, EventArgs e)
  2316. {
  2317. cis = new ComInfoSet();
  2318. (cis.Controls["PortName"] as SerialPortCombox).SelectedValue = Properties.Settings.Default.PortName;
  2319. cis.Controls["BaudRate"].Text = Properties.Settings.Default.BaudRate;
  2320. cis.Controls["Confirm"].Click += UAS_出货标签打印_Click;
  2321. cis.ShowDialog();
  2322. }
  2323. private void UAS_出货标签打印_Click(object sender, EventArgs e)
  2324. {
  2325. if (Com.IsOpen && Com.PortName == cis.Controls["PortName"].Text)
  2326. {
  2327. MessageBox.Show("串口" + Com.PortName + "已打开");
  2328. return;
  2329. }
  2330. else
  2331. {
  2332. if (Com.IsOpen)
  2333. {
  2334. Com.Close();
  2335. }
  2336. }
  2337. int BaudRate = 0;
  2338. Com.PortName = cis.Controls["PortName"].Text;
  2339. if (int.TryParse(cis.Controls["BaudRate"].Text, out BaudRate))
  2340. {
  2341. Com.BaudRate = BaudRate;
  2342. }
  2343. Properties.Settings.Default.BaudRate = BaudRate.ToString();
  2344. Properties.Settings.Default.PortName = cis.Controls["PortName"].Text;
  2345. Properties.Settings.Default.Save();
  2346. Com.DataReceived += Com_DataReceived;
  2347. Com.Open();
  2348. cis.Close();
  2349. }
  2350. private void Com_DataReceived(object sender, System.IO.Ports.SerialDataReceivedEventArgs e)
  2351. {
  2352. try
  2353. {
  2354. int len = Com.BytesToRead;
  2355. byte[] readBuffer = new byte[len];
  2356. Com.Read(readBuffer, 0, len); //将数据读入缓存
  2357. string value = reg.Match(Encoding.ASCII.GetString(readBuffer, 0, len)).Value;
  2358. if (value != "")
  2359. {
  2360. Weight.Text = value;
  2361. }
  2362. //读不到数据的时间删掉
  2363. }
  2364. catch (Exception)
  2365. {
  2366. return;
  2367. }
  2368. }
  2369. private void CloseSerialPort_Click(object sender, EventArgs e)
  2370. {
  2371. if (Com.IsOpen)
  2372. {
  2373. Com.Close();
  2374. Com.DataReceived -= Com_DataReceived;
  2375. }
  2376. }
  2377. private void ShowMenu_Total_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
  2378. {
  2379. ShowMenu_Total.Close();
  2380. switch (e.ClickedItem.Text)
  2381. {
  2382. case "清除明细":
  2383. CleanDetail_Click(sender, e);
  2384. break;
  2385. case "标签维护":
  2386. LabelMaintain_Click(sender, e);
  2387. break;
  2388. case "打印唛头":
  2389. PrintFooter_Click(sender, e);
  2390. break;
  2391. case "附加信息":
  2392. AttachInfo_Click(sender, e);
  2393. break;
  2394. case "打印状态":
  2395. PrintStatus_Click(sender, e);
  2396. break;
  2397. case "标签自定义":
  2398. CustomerLabel_Click(sender, e);
  2399. break;
  2400. case "同步出货数据":
  2401. GetPDdata_Click(sender, e);
  2402. break;
  2403. case "重置单据":
  2404. Reset_Click(sender, e);
  2405. break;
  2406. case "贴标机参数设置":
  2407. MachineSetting ms = new MachineSetting();
  2408. BaseUtil.SetFormCenter(ms);
  2409. ms.ShowDialog();
  2410. break;
  2411. case "贴标角度设置":
  2412. if (pi_cardcode.Text != "")
  2413. {
  2414. 贴标角度设置 ms1 = new 贴标角度设置(pi_cardcode.Text);
  2415. ms1.FormClosed += Ms1_FormClosed;
  2416. BaseUtil.SetFormCenter(ms1);
  2417. ms1.ShowDialog();
  2418. }
  2419. else
  2420. {
  2421. MessageBox.Show("请先获取客户信息");
  2422. }
  2423. break;
  2424. }
  2425. }
  2426. private void Ms1_FormClosed(object sender, FormClosedEventArgs e)
  2427. {
  2428. DataTable XY = (DataTable)dh.ExecuteSql("select * from PRINTXY where px_custcode='" + pi_cardcode.Text + "' and px_machine='" + SystemInf.Machine + "'", "select");
  2429. if (XY.Rows.Count == 0)
  2430. {
  2431. XY = (DataTable)dh.ExecuteSql("select * from PRINTXY where px_custcode='" + pi_cardcode.Text + "'", "select");
  2432. }
  2433. if (XY.Rows.Count > 0)
  2434. {
  2435. Angle = XY.Rows[0]["px_angle"].ToString();
  2436. X = XY.Rows[0]["px_x"].ToString();
  2437. Y = XY.Rows[0]["px_y"].ToString();
  2438. }
  2439. }
  2440. private void MenuManage_Click(object sender, EventArgs e)
  2441. {
  2442. ShowMenu_Total.Show(new Point(MenuManage.Location.X, MenuManage.Location.Y + 20));
  2443. }
  2444. SqliteDBHelper sdh = SystemInf.sdh;
  2445. //接受数据客户端
  2446. TcpClient receiveClient;
  2447. //发送指令客户端
  2448. TcpClient sendClient;
  2449. //复核数据客户端
  2450. TcpClient resetClient;
  2451. NetworkStream ns;
  2452. NetworkStream ns1;
  2453. Thread receiveThread;
  2454. Thread sendThread;
  2455. int dataindex = 0;
  2456. string ps_split = "";
  2457. private void Connect_Click(object sender, EventArgs e)
  2458. {
  2459. receiveClient = new TcpClient();
  2460. sendClient = new TcpClient();
  2461. resetClient = new TcpClient();
  2462. DataTable dt = (DataTable)sdh.ExecuteSql("select * from ParamSetting", "select");
  2463. if (dt.Rows.Count > 0)
  2464. {
  2465. try
  2466. {
  2467. //发起TCP连接
  2468. receiveClient.Connect(dt.Rows[0]["ps_ip"].ToString(), int.Parse(dt.Rows[0]["ps_receiveport"].ToString()));
  2469. sendClient.Connect(dt.Rows[0]["ps_ip"].ToString(), int.Parse(dt.Rows[0]["ps_sendport"].ToString()));
  2470. resetClient.Connect(dt.Rows[0]["ps_ip"].ToString(), int.Parse(dt.Rows[0]["ps_resetport"].ToString()));
  2471. dataindex = int.Parse(dt.Rows[0]["ps_dataindex"].ToString());
  2472. ps_split = dt.Rows[0]["ps_split"].ToString();
  2473. if (receiveClient != null)
  2474. {
  2475. MessageBox.Show("连接服务器成功");
  2476. ConnectToMachine = true;
  2477. //获得绑定的网络数据流
  2478. ns = receiveClient.GetStream();
  2479. ns1 = sendClient.GetStream();
  2480. Control.CheckForIllegalCrossThreadCalls = false;
  2481. //实例化并启动接受消息线程
  2482. receiveThread = new Thread(receive_message);
  2483. receiveThread.Start();
  2484. sendThread = new Thread(send_message);
  2485. sendThread.Start();
  2486. }
  2487. else
  2488. {
  2489. MessageBox.Show("连接服务器失败");
  2490. }
  2491. }
  2492. catch (Exception ex)
  2493. {
  2494. MessageBox.Show(ex.Message);
  2495. }
  2496. }
  2497. }
  2498. private void receive_message()
  2499. {
  2500. while (IsOnline(receiveClient))
  2501. {
  2502. //try
  2503. //{
  2504. //创建接收数据的字节流
  2505. byte[] getData = new byte[1024];
  2506. //从网络流中读取数据
  2507. ns.Read(getData, 0, getData.Length);
  2508. //将字节数组转换成文本形式
  2509. string getMsg = Encoding.Default.GetString(getData);
  2510. if (getMsg.Contains("ReadId"))
  2511. {
  2512. string msgStr = getMsg.Trim('\0').Replace("ReadId1|,|", "");
  2513. msgStr = Regex.Match(msgStr, @"[-{0,5}/{0,5}.{0,5}0-9A-Za-z]+\*[-{0,5}/{0,5}.{0,5}0-9A-Za-z]+\*[-{0,5}/{0,5}.{0,5}0-9A-Za-z]+\*[-{0,5}/{0,5}.{0,5}0-9A-Za-z]+\*[-{0,5}/{0,5}.{0,5}0-9A-Za-z]+").Value;
  2514. //设置索引和内容
  2515. // msgStr = msgStr.Split(ps_split.ToCharArray()[0])[dataindex];
  2516. Input.Text = msgStr;
  2517. Input_KeyDown(Input, new KeyEventArgs(Keys.Enter));
  2518. }
  2519. //}
  2520. //catch (ThreadAbortException)
  2521. //{
  2522. // //捕捉到线程被终止异常则表示是人为的断开TCP连接
  2523. // //不弹出错误提示
  2524. // break;
  2525. //}
  2526. //catch (Exception e)
  2527. //{
  2528. // //接受消息发生异常
  2529. // MessageBox.Show(e.Message);
  2530. // receiveClient.Client.Send(Encoding.ASCII.GetBytes("ReadId1|,|NG|,|Y"));
  2531. // //并释放相关资源
  2532. // //if (ns != null)
  2533. // // ns.Dispose();
  2534. // //break;
  2535. //}
  2536. }
  2537. MessageBox.Show("网络中断");
  2538. }
  2539. private void send_message()
  2540. {
  2541. while (IsOnline(sendClient))
  2542. {
  2543. //try
  2544. //{
  2545. //创建接收数据的字节流
  2546. byte[] getData = new byte[1024];
  2547. //从网络流中读取数据 z
  2548. ns1.Read(getData, 0, getData.Length);
  2549. //将字节数组转换成文本形式
  2550. string getMsg = Encoding.Default.GetString(getData);
  2551. if (getMsg.Contains("ReadId3"))
  2552. {
  2553. string msgStr = getMsg.Trim('\0').Replace("ReadId3|,|", "");
  2554. string temp = Regex.Match(msgStr, @"[-{0,5}/{0,5}.{0,5}0-9A-Za-z]+\*[-{0,5}/{0,5}.{0,5}0-9A-Za-z]+\*[-{0,5}/{0,5}.{0,5}0-9A-Za-z]+\*[-{0,5}/{0,5}.{0,5}0-9A-Za-z]+\*[-{0,5}/{0,5}.{0,5}0-9A-Za-z]+").Value;
  2555. string pr_code = "";
  2556. //如果不存在原厂标签的话
  2557. if (temp != "")
  2558. {
  2559. pr_code = temp.Split('*')[0];
  2560. }
  2561. //如果允许混料的话
  2562. bool OutBoxSplit = false;
  2563. if (PassSixTenCount > OutboxCapacity.Value)
  2564. {
  2565. string close = MessageBox.Show(this.ParentForm, "此箱号采集后超数量,是否继续?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1, MessageBoxOptions.DefaultDesktopOnly).ToString();
  2566. if (close == "Yes")
  2567. {
  2568. OutBoxSplit = true;
  2569. PassSixTenCount = 1;
  2570. //sendClient.Client.Send(Encoding.ASCII.GetBytes("ReadId3|,|OK|,|0"));
  2571. }
  2572. else
  2573. {
  2574. }
  2575. }
  2576. if (MixPrCode.Checked)
  2577. {
  2578. bool SendLast = false;
  2579. for (int i = 0; i < GridPrcode.Rows.Count; i++)
  2580. {
  2581. //获取复核的数据
  2582. int checknum = int.Parse(GridPrcode.Rows[i].Cells["checknum"].Value.ToString());
  2583. double outqty = double.Parse(GridPrcode.Rows[i].Cells["pd_outqty"].Value.ToString());
  2584. double zxbzs = double.Parse(GridPrcode.Rows[i].Cells["PJD_ZXBZS_USER"].Value.ToString());
  2585. string Prcode = GridPrcode.Rows[i].Cells["pd_prodcode"].Value.ToString();
  2586. string pdno = GridPrcode.Rows[i].Cells["pd_pdno"].Value.ToString();
  2587. if (checknum < outqty / zxbzs)
  2588. {
  2589. checknum = checknum + 1;
  2590. GridPrcode.Rows[i].Cells["checknum"].Value = checknum;
  2591. dh.ExecuteSql("update CS$InoutPrcode set checknum=nvl(checknum,0)+1 where pd_inoutno='" + pi_inoutno.Text + "' and pd_pdno='" + pdno + "' and combined=" + combined, "update");
  2592. if (i == GridPrcode.Rows.Count - 1 && checknum == outqty / zxbzs)
  2593. SendLast = true;
  2594. break;
  2595. }
  2596. }
  2597. if (PassTenCount == MidboxCapacity.Value)
  2598. {
  2599. sendClient.Client.Send(Encoding.ASCII.GetBytes("ReadId3|,|OK|,|1"));
  2600. PassTenCount = 0;
  2601. }
  2602. else
  2603. {
  2604. if (SendLast)
  2605. {
  2606. sendClient.Client.Send(Encoding.ASCII.GetBytes("ReadId3|,|OK|,|1"));
  2607. string close = MessageBox.Show("采集完此行数据,是否继续?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1, MessageBoxOptions.DefaultDesktopOnly).ToString();
  2608. if (close == "Yes")
  2609. {
  2610. }
  2611. else
  2612. {
  2613. }
  2614. }
  2615. else
  2616. {
  2617. if (!OutBoxSplit)
  2618. sendClient.Client.Send(Encoding.ASCII.GetBytes("ReadId3|,|OK|,|0"));
  2619. }
  2620. }
  2621. }
  2622. else
  2623. {
  2624. bool SendLast = false;
  2625. for (int i = 0; i < GridPrcode.Rows.Count; i++)
  2626. {
  2627. //获取复核的数据
  2628. int checknum = int.Parse(GridPrcode.Rows[i].Cells["checknum"].Value.ToString());
  2629. double outqty = double.Parse(GridPrcode.Rows[i].Cells["pd_outqty"].Value.ToString());
  2630. double zxbzs = double.Parse(GridPrcode.Rows[i].Cells["PJD_ZXBZS_USER"].Value.ToString());
  2631. string Prcode = GridPrcode.Rows[i].Cells["pd_prodcode"].Value.ToString();
  2632. string pdno = GridPrcode.Rows[i].Cells["pd_pdno"].Value.ToString();
  2633. string SelectPrCode = GridPrcode.Rows[MachineCollectRowIndex].Cells["pd_prodcode"].Value.ToString();
  2634. if ((MachineCollectRowIndex == i && SelectPrCode == pr_code) || ((pr_code == Prcode || pr_code == "") && SelectPrCode != pr_code) && checknum < outqty / zxbzs)
  2635. {
  2636. checknum = checknum + 1;
  2637. GridPrcode.Rows[i].Cells["checknum"].Value = checknum;
  2638. if (checknum < outqty / zxbzs)
  2639. {
  2640. dh.ExecuteSql("update CS$InoutPrcode set checknum=nvl(checknum,0)+1 where pd_inoutno='" + pi_inoutno.Text + "' and pd_pdno='" + pdno + "' and combined=" + combined, "update");
  2641. }
  2642. else if (checknum == outqty / zxbzs)
  2643. {
  2644. dh.ExecuteSql("update CS$InoutPrcode set checknum=nvl(checknum,0)+1 where pd_inoutno='" + pi_inoutno.Text + "' and pd_pdno='" + pdno + "' and combined=" + combined, "update");
  2645. sendClient.Client.Send(Encoding.ASCII.GetBytes("ReadId3|,|OK|,|1"));
  2646. checknum = 0;
  2647. SendLast = true;
  2648. PassTenCount = 0;
  2649. string close = MessageBox.Show("采集完此行数据,是否继续?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1, MessageBoxOptions.DefaultDesktopOnly).ToString();
  2650. if (close == "Yes")
  2651. {
  2652. }
  2653. else
  2654. {
  2655. }
  2656. }
  2657. break;
  2658. }
  2659. }
  2660. //达到了中盒容量之后
  2661. if (PassTenCount == MidboxCapacity.Value)
  2662. {
  2663. sendClient.Client.Send(Encoding.ASCII.GetBytes("ReadId3|,|OK|,|1"));
  2664. PassTenCount = 0;
  2665. }
  2666. else
  2667. {
  2668. //如果发送了最后一盒,则不发送继续堆叠的指令 或者需要分盒的时候
  2669. if ((!SendLast && !OutBoxSplit) || OutBoxSplit)
  2670. {
  2671. sendClient.Client.Send(Encoding.ASCII.GetBytes("ReadId3|,|OK|,|0"));
  2672. }
  2673. }
  2674. }
  2675. //中盒当前进度
  2676. CurrentBoxNum.Value = PassTenCount;
  2677. PassTenCount = PassTenCount + 1;
  2678. //外箱当前进度
  2679. CurrentOutBoxNum.Value = PassSixTenCount;
  2680. PassSixTenCount = PassSixTenCount + 1;
  2681. }
  2682. //设置索引和内容
  2683. //msgStr = msgStr.Split(ps_split.ToCharArray()[0])[dataindex];
  2684. //Input.Text = msgStr;
  2685. //Input_KeyDown(Input, new KeyEventArgs(Keys.Enter));
  2686. //}
  2687. //catch (ThreadAbortException)
  2688. //{
  2689. // //捕捉到线程被终止异常则表示是人为的断开TCP连接
  2690. // //不弹出错误提示
  2691. // break;
  2692. //}
  2693. //catch (Exception e)
  2694. //{
  2695. // //接受消息发生异常
  2696. // MessageBox.Show(e.Message+e.StackTrace);
  2697. // sendClient.Client.Send(Encoding.ASCII.GetBytes("ReadId1|,|NG|,|Y"));
  2698. // //并释放相关资源
  2699. // //if (ns != null)
  2700. // // ns.Dispose();
  2701. // //break;
  2702. //}
  2703. }
  2704. MessageBox.Show("网络中断");
  2705. }
  2706. private string GetSendCode(string Code)
  2707. {
  2708. if (Angle != "")
  2709. {
  2710. Code = Code + "|,|" + Angle;
  2711. }
  2712. if (X != "")
  2713. {
  2714. Code = Code + "|,|" + X;
  2715. }
  2716. if (Y != "")
  2717. {
  2718. Code = Code + "|,|" + Y;
  2719. }
  2720. return Code;
  2721. }
  2722. /// <summary>
  2723. /// 检测TCP连接是否存在还是已经中断
  2724. /// </summary>
  2725. /// <param name="c"></param>
  2726. /// <returns></returns>
  2727. public bool IsOnline(TcpClient c)
  2728. {
  2729. return !((c.Client.Poll(1000, SelectMode.SelectRead) && (c.Client.Available == 0)) || !c.Client.Connected);
  2730. }
  2731. private void CurrentBoxNum_ValueChanged(object sender, EventArgs e)
  2732. {
  2733. }
  2734. private void CurrentBoxNum_KeyDown(object sender, KeyEventArgs e)
  2735. {
  2736. if (e.KeyCode == Keys.Enter)
  2737. {
  2738. PassTenCount = int.Parse(CurrentBoxNum.Value.ToString()) + 1;
  2739. }
  2740. }
  2741. private void CurrentOutBoxNum_KeyDown(object sender, KeyEventArgs e)
  2742. {
  2743. if (e.KeyCode == Keys.Enter)
  2744. {
  2745. PassSixTenCount = int.Parse(CurrentOutBoxNum.Value.ToString()) + 1;
  2746. }
  2747. }
  2748. private void richTextAutoBottom1_TextChanged(object sender, EventArgs e)
  2749. {
  2750. }
  2751. private void Weight_Click(object sender, EventArgs e)
  2752. {
  2753. }
  2754. private void groupBoxWithBorder2_Enter(object sender, EventArgs e)
  2755. {
  2756. }
  2757. private void DCCheck_TextChanged(object sender, EventArgs e)
  2758. {
  2759. }
  2760. private void GridPrcode_CellContentClick(object sender, DataGridViewCellEventArgs e)
  2761. {
  2762. }
  2763. private void label18_Click(object sender, EventArgs e)
  2764. {
  2765. }
  2766. private void MidBoxEnd_TextChanged(object sender, EventArgs e)
  2767. {
  2768. }
  2769. private void MidBoxBegin_TextChanged(object sender, EventArgs e)
  2770. {
  2771. }
  2772. private void label16_Click(object sender, EventArgs e)
  2773. {
  2774. }
  2775. private void SingleBoxEnd_TextChanged(object sender, EventArgs e)
  2776. {
  2777. }
  2778. private void SingleBoxBegin_TextChanged(object sender, EventArgs e)
  2779. {
  2780. }
  2781. private void label12_Click(object sender, EventArgs e)
  2782. {
  2783. }
  2784. private void label7_Click(object sender, EventArgs e)
  2785. {
  2786. }
  2787. private void groupBoxWithBorder1_Enter(object sender, EventArgs e)
  2788. {
  2789. }
  2790. private void Input_TextChanged(object sender, EventArgs e)
  2791. {
  2792. }
  2793. private void LabelInf_CellContentClick(object sender, DataGridViewCellEventArgs e)
  2794. {
  2795. }
  2796. private void pi_inoutno_TextChanged(object sender, EventArgs e)
  2797. {
  2798. }
  2799. private void label14_Click(object sender, EventArgs e)
  2800. {
  2801. }
  2802. private void CurrentOutBoxNum_ValueChanged(object sender, EventArgs e)
  2803. {
  2804. }
  2805. private void label13_Click(object sender, EventArgs e)
  2806. {
  2807. }
  2808. private void SingleLabelPrinter_Load(object sender, EventArgs e)
  2809. {
  2810. }
  2811. private void SingleLabelAutoPrint_CheckedChanged(object sender, EventArgs e)
  2812. {
  2813. }
  2814. private void SingleLabel_Enter(object sender, EventArgs e)
  2815. {
  2816. }
  2817. private void CurrentRowOnly_CheckedChanged(object sender, EventArgs e)
  2818. {
  2819. }
  2820. private void MidboxCapacity_ValueChanged(object sender, EventArgs e)
  2821. {
  2822. }
  2823. private void label2_Click(object sender, EventArgs e)
  2824. {
  2825. }
  2826. private void MidLabelNum_TextChanged(object sender, EventArgs e)
  2827. {
  2828. }
  2829. private void label5_Click(object sender, EventArgs e)
  2830. {
  2831. }
  2832. private void MidLabelPrinter_Load(object sender, EventArgs e)
  2833. {
  2834. }
  2835. private void MidLabelAutoPrint_CheckedChanged(object sender, EventArgs e)
  2836. {
  2837. }
  2838. private void MidLabel_Enter(object sender, EventArgs e)
  2839. {
  2840. }
  2841. private void DiffDetno_CheckedChanged(object sender, EventArgs e)
  2842. {
  2843. }
  2844. private void DiffCPN_CheckedChanged(object sender, EventArgs e)
  2845. {
  2846. }
  2847. private void BoxCount_Click(object sender, EventArgs e)
  2848. {
  2849. }
  2850. private void DiffLotNo_CheckedChanged(object sender, EventArgs e)
  2851. {
  2852. }
  2853. private void DiffDC_CheckedChanged(object sender, EventArgs e)
  2854. {
  2855. }
  2856. private void OnlyOneRow_CheckedChanged(object sender, EventArgs e)
  2857. {
  2858. }
  2859. private void AllLabel_CheckedChanged(object sender, EventArgs e)
  2860. {
  2861. }
  2862. private void label10_Click(object sender, EventArgs e)
  2863. {
  2864. }
  2865. private void label6_Click(object sender, EventArgs e)
  2866. {
  2867. }
  2868. private void OutBoxPrinter_Load(object sender, EventArgs e)
  2869. {
  2870. }
  2871. private void OutboxCapacity_ValueChanged(object sender, EventArgs e)
  2872. {
  2873. }
  2874. private void OutBoxLabel_Enter(object sender, EventArgs e)
  2875. {
  2876. }
  2877. private void ButtonMidWeigh_Click(object sender, EventArgs e)
  2878. {
  2879. if (Weight.Text != "" && Weight.Text != "0.000")
  2880. {
  2881. string pib_outboxcode1 = LabelInf.Rows[SelectRowIndex].Cells["pib_outboxcode1"].Value.ToString();
  2882. sql.Clear();
  2883. sql.Append("update prodiobarcode set pib_midboxweight='" + Weight.Text + "' where pib_inoutno='" + pi_inoutno.Text + "' ");
  2884. sql.Append(" and pib_outboxcode2='" + OutBoxNum.Text + "' and pib_outboxcode1='" + pib_outboxcode1 + "'");
  2885. dh.ExecuteSql(sql.ToString(), "update");
  2886. LoadGridData(sender, e);
  2887. }
  2888. else
  2889. {
  2890. MessageBox.Show("请先连接电子秤!");
  2891. }
  2892. }
  2893. }
  2894. }