UAS_出货标签管理.cs 164 KB

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