UAS_出货标签管理.cs 161 KB

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