UAS_出货标签管理.cs 150 KB

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