UAS_出货标签管理.cs 164 KB

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