UAS_出货标签管理.cs 154 KB

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