UAS_出货标签管理.cs 161 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391
  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 + 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. if (AutoAfterPrint.Checked)
  1576. OutBoxNum.Text = "新增";
  1577. }
  1578. else
  1579. MessageBox.Show("未维护外箱标签", "提示");
  1580. Input.Focus();
  1581. }
  1582. /// <summary>
  1583. /// 自定义函数 加载明细行的数据,多处使用添加进函数
  1584. /// </summary>
  1585. /// <param name="sender"></param>
  1586. /// <param name="e"></param>
  1587. private void LoadGridData(object sender, EventArgs e)
  1588. {
  1589. AllChecked = false;
  1590. string SQL = "";
  1591. if (OutBoxNum.Text != "全部")
  1592. {
  1593. //LogicHandler.GetDataSQL(PI_ID, "and pib_outboxcode2='" + OutBoxNum.Text + "'", out SQL);
  1594. 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," +
  1595. "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," +
  1596. "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 " +
  1597. "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 " +
  1598. "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";
  1599. }
  1600. else
  1601. {
  1602. 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," +
  1603. "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," +
  1604. "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 " +
  1605. "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 " +
  1606. "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";
  1607. }
  1608. LabelInfDataTable = (DataTable)dh.ExecuteSql(SQL, "select");
  1609. BoxCount.Text = LabelInfDataTable.Compute("sum(pib_qty)", "1=1").ToString() + "KPCS";
  1610. bindingsource(LabelInf, LabelInfDataTable);
  1611. if (LabelInf.Rows.Count > 0)
  1612. {
  1613. LabelInf.FirstDisplayedScrollingRowIndex = LabelInf.Rows.Count - 1;
  1614. }
  1615. sql.Clear();
  1616. 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 ");
  1617. sql.Append("where pd_inoutno='" + pi_inoutno.Text + "' group by pib_prodcode,pib_pdno order by pib_pdno ");
  1618. SumQty = (DataTable)dh.ExecuteSql(sql.ToString(), "select");
  1619. }
  1620. private void Refresh_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
  1621. {
  1622. KeyEventArgs e2 = new KeyEventArgs(Keys.Enter);
  1623. pi_inoutno_KeyDown(sender, e2);
  1624. }
  1625. private void LogingOut_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
  1626. {
  1627. string close = MessageBox.Show(this.ParentForm, "是否注销", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question).ToString();
  1628. if (close.ToString() == "Yes")
  1629. {
  1630. Login login = new Login();
  1631. //注销的时候需要将拼接的连接字符串置空
  1632. DataHelper.DBConnectionString = null;
  1633. logout = true;
  1634. this.Hide();
  1635. login.ShowDialog();
  1636. this.Close();
  1637. }
  1638. }
  1639. private void LabelInf_DataError(object sender, DataGridViewDataErrorEventArgs e) { }
  1640. /// <summary>
  1641. /// 切换打开的单盘文件
  1642. /// </summary>
  1643. /// <param name="sender"></param>
  1644. /// <param name="e"></param>
  1645. private void SingleLabelCombox_SelectedIndexChanged(object sender, EventArgs e)
  1646. {
  1647. try
  1648. {
  1649. if (ComBoxClickChangeLabelDoc)
  1650. {
  1651. if (!SingleLabelCombox.SelectedValue.ToString().Contains("System.Data.DataRowView"))
  1652. SingleReport.Load(SingleLabelCombox.SelectedValue.ToString());
  1653. }
  1654. }
  1655. catch (Exception) { }
  1656. }
  1657. /// <summary>
  1658. /// 切换打开的中盒文件
  1659. /// </summary>
  1660. /// <param name="sender"></param>
  1661. /// <param name="e"></param>
  1662. private void MidLabelCombox_SelectedIndexChanged(object sender, EventArgs e)
  1663. {
  1664. try
  1665. {
  1666. if (ComBoxClickChangeLabelDoc)
  1667. {
  1668. if (!MidLabelCombox.SelectedValue.ToString().Contains("System.Data.DataRowView"))
  1669. MidReport.Load(MidLabelCombox.SelectedValue.ToString());
  1670. }
  1671. }
  1672. catch (Exception) { }
  1673. }
  1674. /// <summary>
  1675. /// 切换打开的外箱文件
  1676. /// </summary>
  1677. /// <param name="sender"></param>
  1678. /// <param name="e"></param>
  1679. private void OutBoxCombox_SelectedIndexChanged(object sender, EventArgs e)
  1680. {
  1681. try
  1682. {
  1683. if (ComBoxClickChangeLabelDoc)
  1684. {
  1685. if (!OutBoxCombox.SelectedValue.ToString().Contains("System.Data.DataRowView"))
  1686. OutReport.Load(OutBoxCombox.SelectedValue.ToString());
  1687. }
  1688. }
  1689. catch (Exception) { }
  1690. }
  1691. private void ChooseAll_Click(object sender, EventArgs e)
  1692. {
  1693. if (AllChecked)
  1694. {
  1695. foreach (DataGridViewRow dr in LabelInf.Rows)
  1696. dr.Cells[0].Value = false;
  1697. AllChecked = false;
  1698. }
  1699. else
  1700. {
  1701. foreach (DataGridViewRow dr in LabelInf.Rows)
  1702. dr.Cells[0].Value = true;
  1703. AllChecked = true;
  1704. }
  1705. }
  1706. private void ExportData_Click(object sender, EventArgs e)
  1707. {
  1708. ShowMenu.Items.Clear();
  1709. DataTable dt = (DataTable)dh.ExecuteSql("select * from CS_EXPORTSETTING where es_custcode='" + pi_cardcode.Text + "'", "select");
  1710. if (dt.Rows.Count == 0)
  1711. dt = (DataTable)dh.ExecuteSql("select * from CS_EXPORTSETTING where es_custcode is null", "select");
  1712. for (int i = 0; i < dt.Rows.Count; i++)
  1713. {
  1714. ShowMenu.Items.Add(new ToolStripMenuItem(dt.Rows[i]["el_remark"].ToString() + "#" + dt.Rows[i]["el_type"].ToString()));
  1715. }
  1716. ShowMenu.Show(new Point(ExportData.Location.X, ExportData.Location.Y + 20));
  1717. }
  1718. private void ShowMenu_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
  1719. {
  1720. //获取类型,单盘或者外箱
  1721. string type = e.ClickedItem.Text.Split('#')[1];
  1722. ExportFileDialog.Description = "选择导出的路径";
  1723. DialogResult result = ExportFileDialog.ShowDialog();
  1724. if (result == DialogResult.OK)
  1725. {
  1726. ExcelHandler eh = new ExcelHandler();
  1727. 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");
  1728. if (Field.Rows.Count == 0)
  1729. {
  1730. 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");
  1731. }
  1732. string Fileds = "";
  1733. for (int i = 0; i < Field.Rows.Count; i++)
  1734. {
  1735. Fileds += Field.Rows[i]["esd_filed"].ToString() + ",";
  1736. }
  1737. sql.Clear();
  1738. sql.Append("select " + Fileds.Substring(0, Fileds.Length - 1) + " from ExportView where pib_inoutno='" + pi_inoutno.Text + "'");
  1739. string finnalSQL = "";
  1740. LogicHandler.GetExportDataSQL(pi_inoutno.Text, pi_cardcode.Text, type, sql.ToString(), out finnalSQL);
  1741. dt = (DataTable)dh.ExecuteSql(finnalSQL, "select");
  1742. eh.ExportExcel(dt, Field, ExportFileDialog.SelectedPath, pi_date.Text + "-" + pi_inoutno.Text + type);
  1743. string close = MessageBox.Show(this.ParentForm, "导出成功,是否打开文件", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question).ToString();
  1744. if (close.ToString() == "Yes")
  1745. Process.Start(ExportFileDialog.SelectedPath + "\\" + pi_date.Text + "-" + pi_inoutno.Text + type + ".xls");
  1746. }
  1747. }
  1748. private void AttachInfo_Click(object sender, EventArgs e)
  1749. {
  1750. if (pi_cardcode.Text != "")
  1751. {
  1752. 附件内容打印 att = new 附件内容打印(pi_cardcode.Text);
  1753. att.ShowDialog();
  1754. }
  1755. else MessageBox.Show("请先获取出库单信息", "提示");
  1756. }
  1757. private void MidBoxCapacity_Leave(object sender, EventArgs e)
  1758. {
  1759. NumericUpDown nup = (NumericUpDown)sender;
  1760. switch (nup.Name)
  1761. {
  1762. case "MidBoxCapacity":
  1763. Properties.Settings.Default.MidBoxCapacity = nup.Value;
  1764. Properties.Settings.Default.Save();
  1765. break;
  1766. case "OutboxCapacity":
  1767. Properties.Settings.Default.OutboxCapacity = nup.Value;
  1768. Properties.Settings.Default.Save();
  1769. break;
  1770. default:
  1771. break;
  1772. }
  1773. }
  1774. private void RefreshDBConnect_Tick(object sender, EventArgs e)
  1775. {
  1776. dh.ExecuteSql("select sysdate from dual", "select");
  1777. }
  1778. DataTable CSPrcode;
  1779. private void LoadPrcodeData()
  1780. {
  1781. 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");
  1782. GridPrcode.DataSource = Prcode;
  1783. List<int> RemoveIndex = new List<int>();
  1784. double CollectNum = 0;
  1785. double OutNum = 0;
  1786. int combined = 0;
  1787. if (Combindetail.Checked)
  1788. combined = 1;
  1789. if (CombindetailTwo.Checked)
  1790. combined = 2;
  1791. if (CombindetailThree.Checked)
  1792. combined = 3;
  1793. if (Combindetail.Checked || CombindetailTwo.Checked || CombindetailThree.Checked)
  1794. {
  1795. 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");
  1796. if (CSPrcode.Rows.Count == 0)
  1797. {
  1798. int CurrentIndex = 0;
  1799. for (int i = 0; i < GridPrcode.Rows.Count; i++)
  1800. {
  1801. string CurrentPrCode = GridPrcode.Rows[i].Cells["pd_prodcode"].Value.ToString();
  1802. string CurrentPDNO = GridPrcode.Rows[i].Cells["pd_pdno"].Value.ToString();
  1803. string CurrentOutQTY = GridPrcode.Rows[i].Cells["pd_outqty"].Value.ToString();
  1804. if (SumQty == null)
  1805. {
  1806. sql.Clear();
  1807. 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 ");
  1808. sql.Append("where pd_inoutno='" + pi_inoutno.Text + "' group by pib_prodcode,pib_pdno order by pib_pdno ");
  1809. SumQty = (DataTable)dh.ExecuteSql(sql.ToString(), "select");
  1810. }
  1811. string collectqty = (SumQty.Compute("sum(pib_qty)", "pib_prodcode='" + CurrentPrCode + "' and pib_pdno='" + CurrentPDNO + "'").ToString());
  1812. CollectNum += double.Parse(collectqty == "" ? "0" : collectqty);
  1813. OutNum += double.Parse(CurrentOutQTY);
  1814. GridPrcode.Rows[i].Cells["CollectedNum"].Value = collectqty == "" ? "0" : collectqty;
  1815. }
  1816. for (int i = 0; i < GridPrcode.Rows.Count; i++)
  1817. {
  1818. if (i + 1 < GridPrcode.Rows.Count)
  1819. {
  1820. string BProdCode = GridPrcode.Rows[i].Cells["pd_prodcode"].Value.ToString();
  1821. string BCustProdCode = GridPrcode.Rows[i].Cells["pd_custprodcode1"].Value.ToString();
  1822. string BWhCode = GridPrcode.Rows[i].Cells["pd_whcode"].Value.ToString();
  1823. string BPrUnit = GridPrcode.Rows[i].Cells["pr_unit"].Value.ToString();
  1824. string BPrBrand = GridPrcode.Rows[i].Cells["pd_brand"].Value.ToString();
  1825. string BPoCode = GridPrcode.Rows[i].Cells["pd_pocode1"].Value.ToString();
  1826. string BRemark = GridPrcode.Rows[i].Cells["pd_remark1"].Value.ToString();
  1827. string FProdCode = GridPrcode.Rows[i + 1].Cells["pd_prodcode"].Value.ToString();
  1828. string FCustProdCode = GridPrcode.Rows[i + 1].Cells["pd_custprodcode1"].Value.ToString();
  1829. string FPrUnit = GridPrcode.Rows[i + 1].Cells["pr_unit"].Value.ToString();
  1830. string FrBrand = GridPrcode.Rows[i + 1].Cells["pd_brand"].Value.ToString();
  1831. string FWhCode = GridPrcode.Rows[i + 1].Cells["pd_whcode"].Value.ToString();
  1832. string FPoCode = GridPrcode.Rows[i + 1].Cells["pd_pocode1"].Value.ToString();
  1833. string FRemark = GridPrcode.Rows[i + 1].Cells["pd_remark1"].Value.ToString();
  1834. if (BProdCode == FProdCode && BPrBrand == FrBrand && BCustProdCode == FCustProdCode && (CombindetailTwo.Checked && FPoCode == BPoCode || Combindetail.Checked || CombindetailThree.Checked && FRemark == BRemark && FPoCode == BPoCode))
  1835. {
  1836. 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());
  1837. 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());
  1838. RemoveIndex.Add(i + 1);
  1839. }
  1840. else
  1841. {
  1842. CurrentIndex = i + 1;
  1843. }
  1844. }
  1845. }
  1846. foreach (int item in RemoveIndex.OrderByDescending(x => x))
  1847. {
  1848. (GridPrcode.DataSource as DataTable).Rows.RemoveAt(item);
  1849. }
  1850. }
  1851. else GridPrcode.DataSource = CSPrcode;
  1852. }
  1853. else
  1854. {
  1855. 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");
  1856. if (CSPrcode.Rows.Count == 0)
  1857. {
  1858. for (int i = 0; i < GridPrcode.Rows.Count; i++)
  1859. {
  1860. string CurrentPrCode = GridPrcode.Rows[i].Cells["pd_prodcode"].Value.ToString();
  1861. string CurrentPDNO = GridPrcode.Rows[i].Cells["pd_pdno"].Value.ToString();
  1862. string CurrentOutQTY = GridPrcode.Rows[i].Cells["pd_outqty"].Value.ToString();
  1863. if (SumQty == null)
  1864. {
  1865. sql.Clear();
  1866. 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 ");
  1867. sql.Append("where pd_inoutno='" + pi_inoutno.Text + "' group by pib_prodcode,pib_pdno order by pib_pdno ");
  1868. SumQty = (DataTable)dh.ExecuteSql(sql.ToString(), "select");
  1869. }
  1870. string collectqty = (SumQty.Compute("sum(pib_qty)", "pib_prodcode='" + CurrentPrCode + "' and pib_pdno='" + CurrentPDNO + "'").ToString());
  1871. CollectNum += double.Parse(collectqty == "" ? "0" : collectqty);
  1872. OutNum += double.Parse(CurrentOutQTY);
  1873. GridPrcode.Rows[i].Cells["CollectedNum"].Value = collectqty == "" ? "0" : collectqty;
  1874. }
  1875. }
  1876. else GridPrcode.DataSource = CSPrcode;
  1877. }
  1878. dh.UpdateByCondition("prodinout", "pi_combine_user=" + combined, "pi_inoutno='" + pi_inoutno.Text + "'");
  1879. if (CSPrcode.Rows.Count == 0)
  1880. {
  1881. sql.Clear();
  1882. sql.Append("insert into CS$InoutPrcode (pd_piid,pd_pdno,pd_custprodcode,pd_whcode,pd_prodcode,");
  1883. sql.Append("CollectedNum,UnCollectedNum,pd_outqty,pr_unit,pr_spec,pd_brand,pjd_zxbzs_user,pjd_id,pd_inoutno,combined,pd_pocode,pd_remark)");
  1884. 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)");
  1885. dh.SaveDataTable((GridPrcode.DataSource as DataTable), "CS$InoutPrcode", "pd_piid", sql.ToString());
  1886. }
  1887. else
  1888. {
  1889. CollectNum = float.Parse(CSPrcode.Compute("sum(CollectedNum)", "1=1").ToString());
  1890. OutNum = float.Parse(CSPrcode.Compute("sum(pd_outqty)", "1=1").ToString());
  1891. }
  1892. ProcessCount.Text = CollectNum + "/" + OutNum;
  1893. if (GridPrcode.Rows.Count > 0)
  1894. {
  1895. CurrentPrCode = GridPrcode.Rows[0].Cells["pd_prodcode"].Value.ToString();
  1896. CurrentZXBZ = GridPrcode.Rows[0].Cells["pjd_zxbzs_user"].Value.ToString();
  1897. CurrentUnit = GridPrcode.Rows[0].Cells["pr_unit"].Value.ToString();
  1898. CurrentPDNO = GridPrcode.Rows[0].Cells["pd_pdno"].Value.ToString();
  1899. CurrentPrCount = GridPrcode.Rows[0].Cells["pd_outqty"].Value.ToString();
  1900. CurrentBrand = GridPrcode.Rows[0].Cells["pd_brand"].Value.ToString();
  1901. GridPrcode.Rows[0].Selected = true;
  1902. }
  1903. }
  1904. private void OutBoxNum_Click(object sender, EventArgs e)
  1905. {
  1906. string OutBox = OutBoxNum.Text;
  1907. OutBoxNum.Items.Clear();
  1908. 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");
  1909. ItemObject io = new ItemObject("新增", "新增");
  1910. OutBoxNum.Items.Add(io);
  1911. io = new ItemObject("全部", "全部");
  1912. OutBoxNum.Items.Add(io);
  1913. for (int i = 0; i < dt.Rows.Count; i++)
  1914. {
  1915. string pib_outboxcode2 = dt.Rows[i]["pib_outboxcode2"].ToString();
  1916. io = new ItemObject(pib_outboxcode2, pib_outboxcode2);
  1917. OutBoxNum.Items.Add(io);
  1918. }
  1919. if (OutBoxNum.Text == "新增" || OutBoxNum.Text == "")
  1920. {
  1921. if (dt.Rows.Count > 0)
  1922. OutBoxNum.SelectedIndex = 2;
  1923. else
  1924. OutBoxNum.SelectedIndex = 0;
  1925. }
  1926. if (OutBox != "新增" && OutBox != "")
  1927. OutBoxNum.Text = OutBox;
  1928. }
  1929. string ShareRule;
  1930. string ReSetType = "";
  1931. /// <summary>
  1932. /// 获取条码规则
  1933. /// </summary>
  1934. /// <param name="Type"></param>
  1935. /// <param name="Prefix"></param>
  1936. /// <param name="Suffix"></param>
  1937. /// <param name="MaxNum"></param>
  1938. /// <param name="SerialNumLength"></param>
  1939. /// <param name="Radix"></param>
  1940. private void GetBarCodeRule(out string Prefix, out string Suffix, out int MaxNum, out int SerialNumLength, out int Radix, int Count)
  1941. {
  1942. //获取编码规则
  1943. Prefix = "";
  1944. Suffix = "";
  1945. NrCode = "";
  1946. MaxNum = 0;
  1947. SerialNumLength = 0;
  1948. Radix = 0;
  1949. 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");
  1950. //如果没有则取公共规则
  1951. if (Nr.Rows.Count == 0)
  1952. 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");
  1953. //用于过滤参数的正则表达式
  1954. ReSetType = "";
  1955. if (Nr.Rows.Count > 0)
  1956. {
  1957. ShareRule = Nr.Rows[0]["nr_sharerule"].ToString();
  1958. 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");
  1959. if (dt1.Rows.Count > 0)
  1960. {
  1961. Nr = dt1;
  1962. }
  1963. else
  1964. {
  1965. if (ShareRule != "")
  1966. {
  1967. MessageBox.Show("共享规则" + ShareRule + "不存在");
  1968. return;
  1969. }
  1970. }
  1971. }
  1972. if (Nr.Rows.Count > 0)
  1973. {
  1974. switch (Nr.Rows[0]["nr_resettype"].ToString())
  1975. {
  1976. case "Year":
  1977. sql.Clear();
  1978. sql.Append("to_char(sysdate,'yyyy')");
  1979. break;
  1980. case "Month":
  1981. sql.Clear();
  1982. sql.Append("to_char(sysdate,'yyyyMM')");
  1983. break;
  1984. case "Week":
  1985. sql.Clear();
  1986. sql.Append("to_char(sysdate,'yyyyiw')");
  1987. break;
  1988. case "Day":
  1989. sql.Clear();
  1990. sql.Append("to_char(sysdate,'yyyyMMdd')");
  1991. break;
  1992. case " ":
  1993. sql.Clear();
  1994. sql.Append("' '");
  1995. break;
  1996. default:
  1997. break;
  1998. }
  1999. ReSetType = dh.getFieldDataByCondition("dual", sql.ToString(), "1=1").ToString();
  2000. }
  2001. Regex match = new Regex("{\\w+}");
  2002. //用于存放每一项的明细的数据
  2003. string[] NrData = new string[Nr.Rows.Count];
  2004. //流水长度
  2005. Dictionary<int, string> NrDic = new Dictionary<int, string>();
  2006. for (int m = 0; m < Nr.Rows.Count; m++)
  2007. {
  2008. NrCode = Nr.Rows[m]["nr_code"].ToString();
  2009. switch (Nr.Rows[m]["nrd_type"].ToString())
  2010. {
  2011. //常量直接进行拼接
  2012. case "常量":
  2013. Prefix += Nr.Rows[m]["nrd_sql"].ToString();
  2014. Suffix += Nr.Rows[m]["nrd_sql"].ToString();
  2015. break;
  2016. case "SQL":
  2017. string SQL = Nr.Rows[m]["nrd_sql"].ToString();
  2018. DataTable Temp;
  2019. //如果不包含参数替换
  2020. if (SQL.IndexOf("{") == 0)
  2021. {
  2022. Temp = (DataTable)dh.ExecuteSql(SQL, "select");
  2023. }
  2024. else
  2025. {
  2026. SQL = SQL.Replace("{pd_pdno}", CurrentPDNO);
  2027. //替换参数后重新执行SQL
  2028. foreach (Match mch in match.Matches(SQL))
  2029. {
  2030. SQL = SQL.Replace(mch.Value.Trim(), "'" + pi_inoutno.Text + "'");
  2031. }
  2032. Temp = (DataTable)dh.ExecuteSql(SQL, "select");
  2033. }
  2034. if (Temp.Rows.Count > 0)
  2035. {
  2036. Prefix += Temp.Rows[0][0].ToString();
  2037. Suffix += Temp.Rows[0][0].ToString();
  2038. }
  2039. break;
  2040. //流水需要通过MaxNumber去取
  2041. case "流水":
  2042. string maxnum = "";
  2043. if (ReSetType != " ")
  2044. {
  2045. maxnum = dh.getFieldDataByConditionForUpdate("RuleMaxNum", "rmn_maxnumber", "rmn_nrcode='" + (NrCode == "" ? "Default" : NrCode) + "' and nvl(rmn_type,' ')='" + ReSetType + "'", "update of rmn_maxnumber nowait").ToString();
  2046. }
  2047. else
  2048. {
  2049. maxnum = dh.getFieldDataByConditionForUpdate("RuleMaxNum", "rmn_maxnumber", "rmn_nrcode='" + (NrCode == "" ? "Default" : NrCode) + "' and rmn_prefix='" + Prefix + "' ", "update of rmn_maxnumber nowait").ToString();
  2050. }
  2051. //设置当前流水
  2052. if (maxnum == "")
  2053. {
  2054. if (ReSetType != " ")
  2055. {
  2056. maxnum = dh.getFieldDataByConditionForUpdate("RuleMaxNum", "rmn_maxnumber", "rmn_nrcode='" + (NrCode == "" ? "Default" : NrCode) + "' and nvl(rmn_type,' ')='" + ReSetType + "'", "update of rmn_maxnumber nowait").ToString();
  2057. }
  2058. else
  2059. {
  2060. maxnum = dh.getFieldDataByConditionForUpdate("RuleMaxNum", "rmn_maxnumber", "rmn_nrcode='" + (NrCode == "" ? "Default" : NrCode) + "' and rmn_prefix='" + Prefix + "' ", "update of rmn_maxnumber nowait").ToString();
  2061. }
  2062. if (maxnum == "")
  2063. {
  2064. maxnum = "1";
  2065. }
  2066. Count = int.Parse(maxnum) + Count;
  2067. 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");
  2068. MaxNum = int.Parse(maxnum);
  2069. }
  2070. else
  2071. {
  2072. MaxNum = int.Parse(maxnum);
  2073. if (ReSetType != " ")
  2074. {
  2075. dh.UpdateByCondition("RULEMAXNUM", "rmn_maxnumber='" + (MaxNum + Count) + "'", "rmn_nrcode='" + (NrCode == "" ? "Default" : NrCode) + "' and nvl(rmn_type,' ')='" + ReSetType + "'");
  2076. }
  2077. else
  2078. {
  2079. dh.UpdateByCondition("RULEMAXNUM", "rmn_maxnumber='" + (MaxNum + Count) + "'", "rmn_nrcode='" + (NrCode == "" ? "Default" : NrCode) + "' and rmn_prefix='" + Prefix + "'");
  2080. }
  2081. }
  2082. SerialNumLength = int.Parse(Nr.Rows[m]["nrd_length"].ToString());
  2083. Radix = int.Parse(Nr.Rows[m]["nrd_radix"].ToString());
  2084. Suffix = "";
  2085. break;
  2086. default:
  2087. break;
  2088. }
  2089. }
  2090. }
  2091. private void GridPrcode_CellEndEdit(object sender, DataGridViewCellEventArgs e)
  2092. {
  2093. string Value = GridPrcode.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString();
  2094. string ID = GridPrcode.Rows[e.RowIndex].Cells["pjd_id"].Value.ToString();
  2095. string checknum = GridPrcode.Rows[e.RowIndex].Cells["checknum"].Value.ToString();
  2096. string pdno = GridPrcode.Rows[e.RowIndex].Cells["pd_pdno"].Value.ToString();
  2097. if (GridPrcode.Columns[e.ColumnIndex].Name == "pjd_zxbzs_user")
  2098. {
  2099. dh.UpdateByCondition("PRODJOINVENDDETAIL", "pjd_zxbzs_user='" + Value + "'", "pjd_id='" + ID + "'");
  2100. dh.UpdateByCondition("CS$INOUTPRCODE", "pjd_zxbzs_user='" + Value + "'", "pjd_id='" + ID + "' and pd_inoutno='" + pi_inoutno.Text + "'");
  2101. }
  2102. if (GridPrcode.Columns[e.ColumnIndex].Name == "checknum")
  2103. {
  2104. //更新复核数据
  2105. dh.UpdateByCondition("CS$InoutPrcode", "checknum='" + checknum + "'", "pd_inoutno='" + pi_inoutno.Text + "' and pd_pdno='" + pdno + "' and combined=" + combined);
  2106. }
  2107. //删除对应物料的明细
  2108. CurrentPrCode = GridPrcode.Rows[e.RowIndex].Cells["pd_prodcode"].Value.ToString();
  2109. CurrentZXBZ = GridPrcode.Rows[e.RowIndex].Cells["pjd_zxbzs_user"].Value.ToString();
  2110. CurrentUnit = GridPrcode.Rows[e.RowIndex].Cells["pr_unit"].Value.ToString();
  2111. CurrentPDNO = GridPrcode.Rows[e.RowIndex].Cells["pd_pdno"].Value.ToString();
  2112. CurrentPrCount = GridPrcode.Rows[e.RowIndex].Cells["pd_outqty"].Value.ToString();
  2113. CurrentBrand = GridPrcode.Rows[e.RowIndex].Cells["pd_brand"].Value.ToString();
  2114. GridPrcode.Rows[e.RowIndex].Selected = true;
  2115. if (e.RowIndex - 2 >= 0)
  2116. GridPrcode.FirstDisplayedScrollingRowIndex = e.RowIndex - 2;
  2117. else
  2118. GridPrcode.FirstDisplayedScrollingRowIndex = e.RowIndex;
  2119. LoadGridData(sender, new EventArgs());
  2120. }
  2121. private void GridPrcode_SelectionChanged(object sender, EventArgs e)
  2122. {
  2123. if (GridPrcode.SelectedRows.Count > 0)
  2124. {
  2125. DataGridViewSelectedRowCollection dsc = GridPrcode.SelectedRows;
  2126. MachineCollectRowIndex = GridPrcode.SelectedRows[0].Index;
  2127. CurrentPrCode = GridPrcode.Rows[dsc[0].Index].Cells["pd_prodcode"].Value.ToString();
  2128. CurrentZXBZ = GridPrcode.Rows[dsc[0].Index].Cells["pjd_zxbzs_user"].Value.ToString();
  2129. CurrentUnit = GridPrcode.Rows[dsc[0].Index].Cells["pr_unit"].Value.ToString();
  2130. CurrentPDNO = GridPrcode.Rows[dsc[0].Index].Cells["pd_pdno"].Value.ToString();
  2131. CurrentPrCount = GridPrcode.Rows[dsc[0].Index].Cells["pd_outqty"].Value.ToString();
  2132. CurrentBrand = GridPrcode.Rows[dsc[0].Index].Cells["pd_brand"].Value.ToString();
  2133. GridPrcode.Rows[dsc[0].Index].Selected = true;
  2134. if (dsc[0].Index - 2 >= 0)
  2135. GridPrcode.FirstDisplayedScrollingRowIndex = dsc[0].Index - 2;
  2136. else
  2137. GridPrcode.FirstDisplayedScrollingRowIndex = dsc[0].Index;
  2138. }
  2139. }
  2140. private void GridPrcode_DataError(object sender, DataGridViewDataErrorEventArgs e) { }
  2141. private void GridPrcode_CellClick(object sender, DataGridViewCellEventArgs e)
  2142. {
  2143. if (e.RowIndex >= 0)
  2144. {
  2145. GridPrcode.Rows[e.RowIndex].Selected = true;
  2146. if (e.RowIndex - 2 > 0)
  2147. GridPrcode.FirstDisplayedScrollingRowIndex = e.RowIndex - 2;
  2148. else
  2149. GridPrcode.FirstDisplayedScrollingRowIndex = e.RowIndex;
  2150. }
  2151. }
  2152. private void DCCheck_Leave(object sender, EventArgs e)
  2153. {
  2154. try
  2155. {
  2156. Properties.Settings.Default.DCCheck = int.Parse(DCCheck.Text);
  2157. Properties.Settings.Default.Save();
  2158. }
  2159. catch (Exception)
  2160. {
  2161. MessageBox.Show("DC校验时间必须是整数");
  2162. }
  2163. }
  2164. /// <summary>
  2165. /// 校验DateCode
  2166. /// </summary>
  2167. /// <param name="DateCode"></param>
  2168. private bool CheckDateCode(string DateCode)
  2169. {
  2170. try
  2171. {
  2172. //根据DateCode计算的日期
  2173. string Year = DateCode.Substring(0, 2);
  2174. System.DateTime dt = new DateTime(int.Parse("20" + Year), 01, 01);
  2175. string Week = DateCode.Substring(2, 2);
  2176. System.DateTime dt1 = dt.AddDays((int.Parse(Week) -1)* 7);
  2177. //减去DC校验后的日期
  2178. System.DateTime now = System.DateTime.Now;
  2179. System.DateTime now1 = now.AddDays(-int.Parse(DCCheck.Text));
  2180. //物料的DateCode大于限制日期即可
  2181. if (dt1 > now1 && dt1 < now)
  2182. {
  2183. return true;
  2184. }
  2185. return false;
  2186. }
  2187. catch (Exception)
  2188. {
  2189. return false;
  2190. }
  2191. }
  2192. private void PrintFooter_Click(object sender, EventArgs e)
  2193. {
  2194. FootReport.Load(@"\\10.2.10.238\PRINTE\FASTREPORT\唛头.frx");
  2195. 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");
  2196. string SQL = "select pib_outboxcode2||'/'||(select max(to_number(pib_outboxcode2)) from prodiobarcode where pib_inoutno='" + pi_inoutno.Text + "') from prodiobarcode where pib_id=";
  2197. for (int i = 0; i < dt.Rows.Count; i++)
  2198. {
  2199. DataTable dt1 = (DataTable)dh.ExecuteSql(SQL + "'" + dt.Rows[i]["pib_id"].ToString() + "'", "select");
  2200. FootReport.SetParameterValue("唛头", dt1.Rows[0][0].ToString());
  2201. FootReport.PrintSettings.ShowDialog = false;
  2202. FootReport.PrintSettings.Printer = SingleLabelPrinter.Text;
  2203. FootReport.Print();
  2204. }
  2205. LogManager.DoCommandLog(pi_inoutno.Text, User.UserCode, "打印唛头", "成功");
  2206. }
  2207. private void Input_KeyUp(object sender, KeyEventArgs e)
  2208. {
  2209. if (e.KeyCode == Keys.Enter)
  2210. {
  2211. if (!forinput.Checked)
  2212. Input.SelectAll();
  2213. }
  2214. }
  2215. private void GridPrcode_CellPainting(object sender, DataGridViewCellPaintingEventArgs e)
  2216. {
  2217. bool mouseOver = e.CellBounds.Contains(this.PointToClient(Cursor.Position));
  2218. if (e.ColumnIndex > 0 && e.RowIndex >= 0)
  2219. {
  2220. if (GridPrcode.Columns[e.ColumnIndex].Name == "CollectedNum")
  2221. {
  2222. SolidBrush solidBrush = new SolidBrush(Color.FromArgb(51, 153, 255));
  2223. if (GridPrcode.Rows[e.RowIndex].Cells["CollectedNum"].Value.ToString() != GridPrcode.Rows[e.RowIndex].Cells["pd_outqty"].Value.ToString())
  2224. e.Graphics.FillRectangle(mouseOver ? solidBrush : Brushes.Yellow, e.CellBounds);
  2225. else
  2226. e.Graphics.FillRectangle(mouseOver ? solidBrush : Brushes.White, e.CellBounds);
  2227. Rectangle border = e.CellBounds;
  2228. border.Width -= 1;
  2229. e.Graphics.DrawRectangle(Pens.White, border);
  2230. e.PaintContent(e.CellBounds);
  2231. e.Handled = true;
  2232. }
  2233. }
  2234. }
  2235. private void GridPrcode_CellMouseUp(object sender, DataGridViewCellMouseEventArgs e)
  2236. {
  2237. if (e.Button == MouseButtons.Right)
  2238. {
  2239. if (e.RowIndex >= 0 && e.ColumnIndex > 0)
  2240. {
  2241. string Conetent = GridPrcode.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString();
  2242. Clipboard.SetText(Conetent);
  2243. MessageBox.Show("已复制内容" + Conetent);
  2244. }
  2245. }
  2246. }
  2247. private void Pack_Click(object sender, EventArgs e)
  2248. {
  2249. if (LabelInf.Rows.Count > 0)
  2250. {
  2251. int GetNumCount = 1;
  2252. for (int i = 0; i < LabelInf.Rows.Count; i++)
  2253. {
  2254. if (LabelInf.Rows[i].Cells["pib_custoutboxcode"].Value.ToString() == "")
  2255. {
  2256. if (i + 1 < LabelInf.Rows.Count)
  2257. {
  2258. string FPrcode = LabelInf.Rows[i].Cells["pib_prodcode"].Value.ToString();
  2259. string FPocode = LabelInf.Rows[i].Cells["pd_pocode"].Value.ToString();
  2260. string FWhcode = LabelInf.Rows[i].Cells["pib_brand"].Value.ToString();
  2261. string FDC = LabelInf.Rows[i].Cells["pib_datecode"].Value.ToString();
  2262. string FLOTNO = LabelInf.Rows[i].Cells["pib_lotno"].Value.ToString();
  2263. string FPDCustProdCode = LabelInf.Rows[i].Cells["pd_custprodcode"].Value.ToString();
  2264. string BPrcode = LabelInf.Rows[i + 1].Cells["pib_prodcode"].Value.ToString();
  2265. string BPocode = LabelInf.Rows[i + 1].Cells["pd_pocode"].Value.ToString();
  2266. string BWhcode = LabelInf.Rows[i + 1].Cells["pib_brand"].Value.ToString();
  2267. string BDC = LabelInf.Rows[i + 1].Cells["pib_datecode"].Value.ToString();
  2268. string BLOTNO = LabelInf.Rows[i + 1].Cells["pib_lotno"].Value.ToString();
  2269. string BPDCustProdCode = LabelInf.Rows[i + 1].Cells["pd_custprodcode"].Value.ToString();
  2270. if (FPDCustProdCode != BPDCustProdCode || FPrcode != BPrcode || FPocode != BPocode || FWhcode != BWhcode || (DiffDC.Checked && FDC != BDC) || (DiffLotNo.Checked && FLOTNO != BLOTNO))
  2271. {
  2272. GetNumCount = GetNumCount + 1;
  2273. }
  2274. }
  2275. }
  2276. }
  2277. GetBarCodeRule(out Prefix, out Suffix, out MaxNum, out NumLength, out Radix, GetNumCount);
  2278. List<string> OutBoxCode = new List<string>();
  2279. List<string> PIBID = new List<string>();
  2280. string Str_OutBoxCode = "";
  2281. for (int i = 0; i < LabelInf.Rows.Count; i++)
  2282. {
  2283. if (LabelInf.Rows[i].Cells["pib_custoutboxcode"].Value.ToString() == "")
  2284. {
  2285. PIBID.Add(LabelInf.Rows[i].Cells["pib_id1"].Value.ToString());
  2286. string serialcode = BaseUtil.DToAny(MaxNum, Radix);
  2287. for (int k = serialcode.ToString().Length; k < NumLength; k++)
  2288. {
  2289. serialcode = "0" + serialcode;
  2290. }
  2291. if (i + 1 < LabelInf.Rows.Count)
  2292. {
  2293. string FPrcode = LabelInf.Rows[i].Cells["pib_prodcode"].Value.ToString();
  2294. string FPocode = LabelInf.Rows[i].Cells["pd_pocode"].Value.ToString();
  2295. string FWhcode = LabelInf.Rows[i].Cells["pib_brand"].Value.ToString();
  2296. string FDC = LabelInf.Rows[i].Cells["pib_datecode"].Value.ToString();
  2297. string FLOTNO = LabelInf.Rows[i].Cells["pib_lotno"].Value.ToString();
  2298. string FPDCustProdCode = LabelInf.Rows[i].Cells["pd_custprodcode"].Value.ToString();
  2299. string FPDNO = LabelInf.Rows[i].Cells["pib_pdno"].Value.ToString();
  2300. string BPrcode = LabelInf.Rows[i + 1].Cells["pib_prodcode"].Value.ToString();
  2301. string BPocode = LabelInf.Rows[i + 1].Cells["pd_pocode"].Value.ToString();
  2302. string BWhcode = LabelInf.Rows[i + 1].Cells["pib_brand"].Value.ToString();
  2303. string BDC = LabelInf.Rows[i + 1].Cells["pib_datecode"].Value.ToString();
  2304. string BLOTNO = LabelInf.Rows[i + 1].Cells["pib_lotno"].Value.ToString();
  2305. string BPDCustProdCode = LabelInf.Rows[i + 1].Cells["pd_custprodcode"].Value.ToString();
  2306. string BPDNO = LabelInf.Rows[i + 1].Cells["pib_pdno"].Value.ToString();
  2307. if ((DiffDetno.Checked && BPDNO != FPDNO) || (DiffCPN.Checked && FPDCustProdCode != BPDCustProdCode) || FPrcode != BPrcode || FPocode != BPocode || FWhcode != BWhcode || (DiffDC.Checked && FDC != BDC) || (DiffLotNo.Checked && FLOTNO != BLOTNO))
  2308. {
  2309. MaxNum = MaxNum + 1;
  2310. }
  2311. }
  2312. OutBoxCode.Add(Prefix + serialcode + Suffix);
  2313. Str_OutBoxCode += "'" + Prefix + serialcode + Suffix + "',";
  2314. }
  2315. }
  2316. if (OutBoxCode.ToArray().Length > 0)
  2317. {
  2318. if (!dh.CheckExist("prodiobarcode", "pib_custcode='" + pi_cardcode.Text + "' and pib_custoutboxcode in (" + Str_OutBoxCode.Substring(0, Str_OutBoxCode.Length - 1) + ")"))
  2319. {
  2320. 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());
  2321. }
  2322. else
  2323. {
  2324. if (ReSetType != " ")
  2325. {
  2326. dh.UpdateByCondition("RULEMAXNUM", "rmn_maxnumber='" + (MaxNum + 1) + "'", "rmn_nrcode='" + (NrCode == "" ? "Default" : NrCode) + "' and nvl(rmn_type,' ')='" + ReSetType + "'");
  2327. }
  2328. else
  2329. {
  2330. dh.UpdateByCondition("RULEMAXNUM", "rmn_maxnumber='" + (MaxNum + 1) + "'", "rmn_nrcode='" + (NrCode == "" ? "Default" : NrCode) + "' and rmn_prefix='" + Prefix + "'");
  2331. }
  2332. Pack_Click(sender, e);
  2333. return;
  2334. }
  2335. LoadGridData(sender, e);
  2336. }
  2337. }
  2338. }
  2339. private void PackMidBox_Click(object sender, EventArgs e)
  2340. {
  2341. 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");
  2342. DataTable dt1 = null;
  2343. int GetNumCount = 0;
  2344. for (int i = 0; i < dt.Rows.Count; i++)
  2345. {
  2346. 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");
  2347. //如果不是10的整数倍则为尾盒
  2348. int tencount = 0;
  2349. for (int j = 0; j < dt1.Rows.Count; j++)
  2350. {
  2351. 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()))
  2352. {
  2353. GetNumCount = GetNumCount + 1;
  2354. }
  2355. tencount = tencount + 1;
  2356. }
  2357. }
  2358. GetBarCodeRule(out Prefix, out Suffix, out MaxNum, out NumLength, out Radix, GetNumCount);
  2359. if (Radix > 0)
  2360. {
  2361. //生成中盒条码
  2362. int pib_outboxcode1 = int.Parse(dh.getFieldDataByCondition("prodiobarcode", "max(to_number(nvl(pib_outboxcode1,0)))", "pib_inoutno='" + pi_inoutno.Text + "'").ToString());
  2363. MaxNum = MaxNum - 1;
  2364. for (int i = 0; i < dt.Rows.Count; i++)
  2365. {
  2366. List<string> MidBoxCode = new List<string>();
  2367. List<string> PIBID = new List<string>();
  2368. List<string> PIBOUTBOXCODE1 = new List<string>();
  2369. 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");
  2370. //如果不是10的整数倍则为尾盒
  2371. int tencount = 0;
  2372. for (int j = 0; j < dt1.Rows.Count; j++)
  2373. {
  2374. 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()))
  2375. {
  2376. pib_outboxcode1 = pib_outboxcode1 + 1;
  2377. MaxNum = MaxNum + 1;
  2378. tencount = 0;
  2379. }
  2380. tencount = tencount + 1;
  2381. string serialcode = BaseUtil.DToAny(MaxNum, Radix);
  2382. for (int k = serialcode.ToString().Length; k < NumLength; k++)
  2383. {
  2384. serialcode = "0" + serialcode;
  2385. }
  2386. MidBoxCode.Add(Prefix + serialcode + Suffix);
  2387. PIBID.Add(dt1.Rows[j]["pib_id"].ToString());
  2388. PIBOUTBOXCODE1.Add(pib_outboxcode1.ToString());
  2389. }
  2390. 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());
  2391. }
  2392. }
  2393. LoadGridData(sender, e);
  2394. }
  2395. private void PrintStatus_Click(object sender, EventArgs e)
  2396. {
  2397. EnablePrint = !EnablePrint;
  2398. if (EnablePrint)
  2399. {
  2400. SetPrintStatus_label.ForeColor = Color.Green;
  2401. SetPrintStatus_label.Text = "可打印";
  2402. }
  2403. else
  2404. {
  2405. SetPrintStatus_label.ForeColor = Color.Red;
  2406. SetPrintStatus_label.Text = "暂停打印";
  2407. }
  2408. Input.Focus();
  2409. }
  2410. private void CustomerLabel_Click(object sender, EventArgs e)
  2411. {
  2412. sql.Clear();
  2413. sql.Append("update prodiobarcode set pib_custbarcode=case when instr(pib_custbarcode,'SL')=0 ");
  2414. sql.Append("then ('SL'||pib_custbarcode)else pib_custbarcode end, pib_custoutboxcode=case when instr");
  2415. sql.Append("(pib_custoutboxcode,'SC')=0 then ('SC'||pib_custoutboxcode)else pib_custoutboxcode end where pib_inoutno='" + pi_inoutno.Text + "'");
  2416. dh.ExecuteSql(sql.ToString(), "select");
  2417. LoadGridData(sender, e);
  2418. CustomerLabel.Enabled = false;
  2419. }
  2420. private void Combindetail_CheckedChanged(object sender, EventArgs e)
  2421. {
  2422. if (Combindetail.Checked)
  2423. {
  2424. CombindetailTwo.Checked = false;
  2425. CombindetailThree.Checked = false;
  2426. }
  2427. if (LoadCheck)
  2428. {
  2429. LoadPrcodeData();
  2430. string response = "";
  2431. string[] param = new string[] { PI_ID, "1", response };
  2432. dh.CallProcedure("USER_PRODOUT_GROUPQTY", param);
  2433. }
  2434. }
  2435. private void CombindetailTwo_CheckedChanged(object sender, EventArgs e)
  2436. {
  2437. if (CombindetailTwo.Checked)
  2438. {
  2439. Combindetail.Checked = false;
  2440. CombindetailThree.Checked = false;
  2441. }
  2442. if (LoadCheck)
  2443. {
  2444. LoadPrcodeData();
  2445. string response = "";
  2446. string[] param = new string[] { PI_ID, "2", response };
  2447. dh.CallProcedure("USER_PRODOUT_GROUPQTY", param);
  2448. }
  2449. }
  2450. private void CombindetailThree_CheckedChanged(object sender, EventArgs e)
  2451. {
  2452. if (CombindetailThree.Checked)
  2453. {
  2454. Combindetail.Checked = false;
  2455. CombindetailTwo.Checked = false;
  2456. }
  2457. if (LoadCheck)
  2458. {
  2459. LoadPrcodeData();
  2460. string response = "";
  2461. string[] param = new string[] { PI_ID, "3", response };
  2462. dh.CallProcedure("USER_PRODOUT_GROUPQTY_TEST", param);
  2463. }
  2464. }
  2465. string SelectProdcode = "";
  2466. int SelectRowIndex = -1;
  2467. private void LabelInf_CellClick(object sender, DataGridViewCellEventArgs e)
  2468. {
  2469. if (e.RowIndex >= 0)
  2470. {
  2471. LabelInf.Rows[e.RowIndex].Selected = true;
  2472. SelectRowIndex = e.RowIndex;
  2473. }
  2474. }
  2475. private void OutBoxNum_SelectedIndexChanged(object sender, EventArgs e)
  2476. {
  2477. OutBoxNum1 = OutBoxNum.Text;
  2478. LoadGridData(sender, e);
  2479. }
  2480. private void LabelInf_SelectionChanged(object sender, EventArgs e)
  2481. {
  2482. DataGridViewSelectedRowCollection dsc = LabelInf.SelectedRows;
  2483. if (dsc.Count > 0)
  2484. {
  2485. SelectRowIndex = dsc[0].Index;
  2486. }
  2487. }
  2488. string OutBoxNum1 = "";
  2489. private void OutBoxNum_SelectionChangeCommitted(object sender, EventArgs e)
  2490. {
  2491. if (OutBoxNum1 != "全部" && OutBoxNum1 != "新增")
  2492. if (dh.getFieldDataByCondition("prodiobarcode", "pib_outifprint", "pib_inoutno='" + pi_inoutno.Text + "' and pib_outboxcode2='" + OutBoxNum1 + "'").ToString() != "-1")
  2493. {
  2494. MessageBox.Show("外箱号" + OutBoxNum1 + "尚未打印标签");
  2495. }
  2496. OutBoxNum1 = OutBoxNum.Text;
  2497. if (OutBoxNum1 == "新增")
  2498. {
  2499. PassSixTenCount = 1;
  2500. PassTenCount = 1;
  2501. CurrentBoxNum.Value = 0;
  2502. CurrentOutBoxNum.Value = 0;
  2503. }
  2504. }
  2505. private void Reset_Click(object sender, EventArgs e)
  2506. {
  2507. string close = MessageBox.Show(this.ParentForm, "清除当前已采集数据,刷新待采集数据", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question).ToString();
  2508. if (close.ToString() == "Yes")
  2509. {
  2510. dh.ExecuteSql("delete from prodiobarcode where pib_inoutno='" + pi_inoutno.Text + "'", "delete");
  2511. dh.ExecuteSql("delete from CS$InoutPrcode where pd_inoutno='" + pi_inoutno.Text + "'", "delete");
  2512. dh.UpdateByCondition("prodinout", "pi_user_packingstatus=''", "pi_inoutno='" + pi_inoutno.Text + "'");
  2513. pi_inoutno_KeyDown(sender, new KeyEventArgs(Keys.Enter));
  2514. }
  2515. }
  2516. private void AddNewOutBox_Click(object sender, EventArgs e)
  2517. {
  2518. if (OutBoxNum1 != "全部" && OutBoxNum1 != "新增")
  2519. if (dh.getFieldDataByCondition("prodiobarcode", "pib_outifprint", "pib_inoutno='" + pi_inoutno.Text + "' and pib_outboxcode2='" + OutBoxNum1 + "'").ToString() != "-1")
  2520. {
  2521. MessageBox.Show("外箱号" + OutBoxNum1 + "尚未打印标签");
  2522. }
  2523. OutBoxNum1 = OutBoxNum.Text;
  2524. if (OutBoxNum1 == "新增")
  2525. {
  2526. PassSixTenCount = 1;
  2527. PassTenCount = 1;
  2528. CurrentBoxNum.Value = 0;
  2529. CurrentOutBoxNum.Value = 0;
  2530. }
  2531. OutBoxNum.Text = "新增";
  2532. }
  2533. private void GetPDdata_Click(object sender, EventArgs e)
  2534. {
  2535. dh.ExecuteSql("delete from CS$InoutPrcode where pd_inoutno='" + pi_inoutno.Text + "'", "delete");
  2536. LoadPrcodeData();
  2537. 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 + "'");
  2538. MessageBox.Show("同步出货单明细数据成功", "提示");
  2539. }
  2540. private void ResetHBXH_Click(object sender, EventArgs e)
  2541. {
  2542. dh.ExecuteSql("update prodiodetail set PD_HBXH_USER=pd_pdno where pd_inoutno='" + pi_inoutno.Text + "'", "update");
  2543. MessageBox.Show("重置序号成功", "提示");
  2544. }
  2545. private void ButtonWeigh_Click(object sender, EventArgs e)
  2546. {
  2547. if (Weight.Text != "" && Weight.Text != "0.000")
  2548. {
  2549. sql.Clear();
  2550. sql.Append("update prodiobarcode set pib_boxweight='" + Weight.Text + "' where pib_inoutno='" + pi_inoutno.Text + "' ");
  2551. sql.Append(" and pib_outboxcode2='" + OutBoxNum.Text + "'");
  2552. dh.ExecuteSql(sql.ToString(), "update");
  2553. LoadGridData(sender, e);
  2554. }
  2555. else
  2556. {
  2557. MessageBox.Show("请先连接电子秤!");
  2558. }
  2559. }
  2560. Regex reg = new Regex(@"\d+.\d+");
  2561. ComInfoSet cis;
  2562. private void ConnectCom_Click(object sender, EventArgs e)
  2563. {
  2564. cis = new ComInfoSet();
  2565. (cis.Controls["PortName"] as SerialPortCombox).SelectedValue = Properties.Settings.Default.PortName;
  2566. cis.Controls["BaudRate"].Text = Properties.Settings.Default.BaudRate;
  2567. cis.Controls["Confirm"].Click += UAS_出货标签打印_Click;
  2568. cis.ShowDialog();
  2569. }
  2570. private void UAS_出货标签打印_Click(object sender, EventArgs e)
  2571. {
  2572. if (Com.IsOpen && Com.PortName == cis.Controls["PortName"].Text)
  2573. {
  2574. MessageBox.Show("串口" + Com.PortName + "已打开");
  2575. return;
  2576. }
  2577. else
  2578. {
  2579. if (Com.IsOpen)
  2580. {
  2581. Com.Close();
  2582. }
  2583. }
  2584. int BaudRate = 0;
  2585. Com.PortName = cis.Controls["PortName"].Text;
  2586. if (int.TryParse(cis.Controls["BaudRate"].Text, out BaudRate))
  2587. {
  2588. Com.BaudRate = BaudRate;
  2589. }
  2590. Properties.Settings.Default.BaudRate = BaudRate.ToString();
  2591. Properties.Settings.Default.PortName = cis.Controls["PortName"].Text;
  2592. Properties.Settings.Default.Save();
  2593. Com.DataReceived += Com_DataReceived;
  2594. Com.Open();
  2595. cis.Close();
  2596. }
  2597. private void Com_DataReceived(object sender, System.IO.Ports.SerialDataReceivedEventArgs e)
  2598. {
  2599. try
  2600. {
  2601. int len = Com.BytesToRead;
  2602. byte[] readBuffer = new byte[len];
  2603. Com.Read(readBuffer, 0, len); //将数据读入缓存
  2604. string value = reg.Match(Encoding.ASCII.GetString(readBuffer, 0, len)).Value;
  2605. if (value != "")
  2606. {
  2607. Weight.Text = value;
  2608. }
  2609. //读不到数据的时间删掉
  2610. }
  2611. catch (Exception)
  2612. {
  2613. return;
  2614. }
  2615. }
  2616. private void CloseSerialPort_Click(object sender, EventArgs e)
  2617. {
  2618. if (Com.IsOpen)
  2619. {
  2620. Com.Close();
  2621. Com.DataReceived -= Com_DataReceived;
  2622. }
  2623. }
  2624. private void ShowMenu_Total_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
  2625. {
  2626. ShowMenu_Total.Close();
  2627. switch (e.ClickedItem.Text)
  2628. {
  2629. case "清除明细":
  2630. CleanDetail_Click(sender, e);
  2631. break;
  2632. case "标签维护":
  2633. LabelMaintain_Click(sender, e);
  2634. break;
  2635. case "打印唛头":
  2636. PrintFooter_Click(sender, e);
  2637. break;
  2638. case "附加信息":
  2639. AttachInfo_Click(sender, e);
  2640. break;
  2641. case "打印状态":
  2642. PrintStatus_Click(sender, e);
  2643. break;
  2644. case "标签自定义":
  2645. CustomerLabel_Click(sender, e);
  2646. break;
  2647. case "同步出货数据":
  2648. GetPDdata_Click(sender, e);
  2649. break;
  2650. case "重置单据":
  2651. Reset_Click(sender, e);
  2652. break;
  2653. case "贴标机参数设置":
  2654. MachineSetting ms = new MachineSetting();
  2655. BaseUtil.SetFormCenter(ms);
  2656. ms.ShowDialog();
  2657. break;
  2658. case "断开贴标机":
  2659. receiveClient.Close();
  2660. sendClient.Close();
  2661. resetClient.Close();
  2662. break;
  2663. case "内部标签打印":
  2664. 内部标签打印 ms2 = new 内部标签打印(SingleLabelPrinter.Text);
  2665. BaseUtil.SetFormCenter(ms2);
  2666. ms2.ShowDialog();
  2667. break;
  2668. case "贴标角度设置":
  2669. if (pi_cardcode.Text != "")
  2670. {
  2671. 贴标角度设置 ms1 = new 贴标角度设置(pi_cardcode.Text);
  2672. ms1.FormClosed += Ms1_FormClosed;
  2673. BaseUtil.SetFormCenter(ms1);
  2674. ms1.ShowDialog();
  2675. }
  2676. else
  2677. {
  2678. MessageBox.Show("请先获取客户信息");
  2679. }
  2680. break;
  2681. }
  2682. }
  2683. private void Ms1_FormClosed(object sender, FormClosedEventArgs e)
  2684. {
  2685. DataTable XY = (DataTable)dh.ExecuteSql("select * from PRINTXY where px_custcode='" + pi_cardcode.Text + "' and px_machine='" + SystemInf.Machine + "'", "select");
  2686. if (XY.Rows.Count == 0)
  2687. {
  2688. XY = (DataTable)dh.ExecuteSql("select * from PRINTXY where px_custcode='" + pi_cardcode.Text + "'", "select");
  2689. }
  2690. if (XY.Rows.Count > 0)
  2691. {
  2692. Angle = XY.Rows[0]["px_angle"].ToString();
  2693. X = XY.Rows[0]["px_x"].ToString();
  2694. Y = XY.Rows[0]["px_y"].ToString();
  2695. }
  2696. }
  2697. private void MenuManage_Click(object sender, EventArgs e)
  2698. {
  2699. ShowMenu_Total.Show(new Point(MenuManage.Location.X, MenuManage.Location.Y + 20));
  2700. }
  2701. SqliteDBHelper sdh = SystemInf.sdh;
  2702. //接受数据客户端
  2703. TcpClient receiveClient;
  2704. //发送指令客户端
  2705. TcpClient sendClient;
  2706. //复核数据客户端
  2707. TcpClient resetClient;
  2708. NetworkStream ns;
  2709. NetworkStream ns1;
  2710. Thread receiveThread;
  2711. Thread sendThread;
  2712. int dataindex = 0;
  2713. string ps_split = "";
  2714. private void Connect_Click(object sender, EventArgs e)
  2715. {
  2716. SingleLabelAutoPrint.Checked = true;
  2717. MidLabelAutoPrint.Checked = true;
  2718. CurrentRowOnly.Checked = true;
  2719. AutoPrintMidBox.Checked = true;
  2720. receiveClient = new TcpClient();
  2721. sendClient = new TcpClient();
  2722. resetClient = new TcpClient();
  2723. DataTable dt = (DataTable)sdh.ExecuteSql("select * from ParamSetting", "select");
  2724. if (dt.Rows.Count > 0)
  2725. {
  2726. try
  2727. {
  2728. //发起TCP连接
  2729. receiveClient.Connect(dt.Rows[0]["ps_ip"].ToString(), int.Parse(dt.Rows[0]["ps_receiveport"].ToString()));
  2730. sendClient.Connect(dt.Rows[0]["ps_ip"].ToString(), int.Parse(dt.Rows[0]["ps_sendport"].ToString()));
  2731. resetClient.Connect(dt.Rows[0]["ps_ip"].ToString(), int.Parse(dt.Rows[0]["ps_resetport"].ToString()));
  2732. dataindex = int.Parse(dt.Rows[0]["ps_dataindex"].ToString());
  2733. ps_split = dt.Rows[0]["ps_split"].ToString();
  2734. if (receiveClient != null)
  2735. {
  2736. MessageBox.Show("连接服务器成功");
  2737. ConnectToMachine = true;
  2738. //获得绑定的网络数据流
  2739. ns = receiveClient.GetStream();
  2740. ns1 = sendClient.GetStream();
  2741. Control.CheckForIllegalCrossThreadCalls = false;
  2742. //实例化并启动接受消息线程
  2743. receiveThread = new Thread(receive_message);
  2744. receiveThread.Start();
  2745. sendThread = new Thread(send_message);
  2746. sendThread.Start();
  2747. }
  2748. else
  2749. {
  2750. MessageBox.Show("连接服务器失败");
  2751. }
  2752. }
  2753. catch (Exception ex)
  2754. {
  2755. MessageBox.Show(ex.Message);
  2756. }
  2757. }
  2758. }
  2759. bool IsSum = false;
  2760. private void receive_message()
  2761. {
  2762. while (IsOnline(receiveClient))
  2763. {
  2764. try
  2765. {
  2766. //创建接收数据的字节流
  2767. byte[] getData = new byte[1024];
  2768. //从网络流中读取数据
  2769. ns.Read(getData, 0, getData.Length);
  2770. //将字节数组转换成文本形式
  2771. string getMsg = Encoding.Default.GetString(getData);
  2772. if (getMsg.Contains("ReadId"))
  2773. {
  2774. string msgStr = getMsg.Trim('\0').Replace("ReadId1|,|", "");
  2775. if (!msgStr.Contains("三星"))
  2776. {
  2777. 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;
  2778. //设置索引和内容
  2779. // msgStr = msgStr.Split(ps_split.ToCharArray()[0])[dataindex];
  2780. Input.Text = msgStr;
  2781. IsSum = false;
  2782. }
  2783. else
  2784. {
  2785. IsSum = true;
  2786. }
  2787. Input_KeyDown(Input, new KeyEventArgs(Keys.Enter));
  2788. }
  2789. }
  2790. catch (Exception)
  2791. {
  2792. //接受消息发生异常
  2793. break;
  2794. //并释放相关资源
  2795. //if (ns != null)
  2796. // ns.Dispose();
  2797. //break;
  2798. }
  2799. }
  2800. MessageBox.Show("网络中断");
  2801. }
  2802. private void send_message()
  2803. {
  2804. while (IsOnline(sendClient))
  2805. {
  2806. try
  2807. {
  2808. //创建接收数据的字节流
  2809. byte[] getData = new byte[1024];
  2810. //从网络流中读取数据 z
  2811. ns1.Read(getData, 0, getData.Length);
  2812. //将字节数组转换成文本形式
  2813. string getMsg = Encoding.Default.GetString(getData);
  2814. if (getMsg.Contains("ReadId3"))
  2815. {
  2816. string msgStr = getMsg.Trim('\0').Replace("ReadId3|,|", "");
  2817. 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;
  2818. string pr_code = "";
  2819. //如果不存在原厂标签的话
  2820. if (temp != "")
  2821. {
  2822. pr_code = temp.Split('*')[0];
  2823. }
  2824. //如果允许混料的话
  2825. bool OutBoxSplit = false;
  2826. if (PassSixTenCount > OutboxCapacity.Value)
  2827. {
  2828. string close = MessageBox.Show(this.ParentForm, "此箱号采集后超数量,是否继续?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1, MessageBoxOptions.DefaultDesktopOnly).ToString();
  2829. if (close == "Yes")
  2830. {
  2831. OutBoxSplit = true;
  2832. PassSixTenCount = 1;
  2833. //sendClient.Client.Send(Encoding.ASCII.GetBytes("ReadId3|,|OK|,|0"));
  2834. }
  2835. else
  2836. {
  2837. }
  2838. }
  2839. if (MixPrCode.Checked)
  2840. {
  2841. bool SendLast = false;
  2842. for (int i = 0; i < GridPrcode.Rows.Count; i++)
  2843. {
  2844. //获取复核的数据
  2845. int checknum = int.Parse(GridPrcode.Rows[i].Cells["checknum"].Value.ToString());
  2846. double outqty = double.Parse(GridPrcode.Rows[i].Cells["pd_outqty"].Value.ToString());
  2847. double zxbzs = double.Parse(GridPrcode.Rows[i].Cells["PJD_ZXBZS_USER"].Value.ToString());
  2848. string Prcode = GridPrcode.Rows[i].Cells["pd_prodcode"].Value.ToString();
  2849. string pdno = GridPrcode.Rows[i].Cells["pd_pdno"].Value.ToString();
  2850. if (checknum < outqty / zxbzs)
  2851. {
  2852. checknum = checknum + 1;
  2853. GridPrcode.Rows[i].Cells["checknum"].Value = checknum;
  2854. 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");
  2855. if (i == GridPrcode.Rows.Count - 1 && checknum == outqty / zxbzs)
  2856. SendLast = true;
  2857. break;
  2858. }
  2859. }
  2860. if (PassTenCount == MidboxCapacity.Value)
  2861. {
  2862. sendClient.Client.Send(Encoding.ASCII.GetBytes("ReadId3|,|OK|,|1"));
  2863. PassTenCount = 0;
  2864. }
  2865. else
  2866. {
  2867. if (SendLast)
  2868. {
  2869. sendClient.Client.Send(Encoding.ASCII.GetBytes("ReadId3|,|OK|,|1"));
  2870. string close = MessageBox.Show("采集完此行数据,是否继续?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1, MessageBoxOptions.DefaultDesktopOnly).ToString();
  2871. if (close == "Yes")
  2872. {
  2873. }
  2874. else
  2875. {
  2876. }
  2877. }
  2878. else
  2879. {
  2880. if (!OutBoxSplit)
  2881. sendClient.Client.Send(Encoding.ASCII.GetBytes("ReadId3|,|OK|,|0"));
  2882. }
  2883. }
  2884. }
  2885. else
  2886. {
  2887. bool SendLast = false;
  2888. for (int i = 0; i < GridPrcode.Rows.Count; i++)
  2889. {
  2890. //获取复核的数据
  2891. int checknum = int.Parse(GridPrcode.Rows[i].Cells["checknum"].Value.ToString());
  2892. double outqty = double.Parse(GridPrcode.Rows[i].Cells["pd_outqty"].Value.ToString());
  2893. double zxbzs = double.Parse(GridPrcode.Rows[i].Cells["PJD_ZXBZS_USER"].Value.ToString());
  2894. string Prcode = GridPrcode.Rows[i].Cells["pd_prodcode"].Value.ToString();
  2895. string pdno = GridPrcode.Rows[i].Cells["pd_pdno"].Value.ToString();
  2896. string SelectPrCode = GridPrcode.Rows[MachineCollectRowIndex].Cells["pd_prodcode"].Value.ToString();
  2897. if ((MachineCollectRowIndex == i && SelectPrCode == pr_code) || ((pr_code == Prcode || pr_code == "") && SelectPrCode != pr_code) && checknum < outqty / zxbzs)
  2898. {
  2899. checknum = checknum + 1;
  2900. GridPrcode.Rows[i].Cells["checknum"].Value = checknum;
  2901. if (checknum < outqty / zxbzs)
  2902. {
  2903. 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");
  2904. }
  2905. else if (checknum == outqty / zxbzs)
  2906. {
  2907. 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");
  2908. sendClient.Client.Send(Encoding.ASCII.GetBytes("ReadId3|,|OK|,|1"));
  2909. checknum = 0;
  2910. SendLast = true;
  2911. PassTenCount = 0;
  2912. string close = MessageBox.Show("采集完此行数据,是否继续?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1, MessageBoxOptions.DefaultDesktopOnly).ToString();
  2913. if (close == "Yes")
  2914. {
  2915. }
  2916. else
  2917. {
  2918. }
  2919. }
  2920. break;
  2921. }
  2922. }
  2923. //达到了中盒容量之后
  2924. if (PassTenCount == MidboxCapacity.Value)
  2925. {
  2926. sendClient.Client.Send(Encoding.ASCII.GetBytes("ReadId3|,|OK|,|1"));
  2927. PassTenCount = 0;
  2928. }
  2929. else
  2930. {
  2931. //如果发送了最后一盒,则不发送继续堆叠的指令 或者需要分盒的时候
  2932. if ((!SendLast && !OutBoxSplit) || OutBoxSplit)
  2933. {
  2934. sendClient.Client.Send(Encoding.ASCII.GetBytes("ReadId3|,|OK|,|0"));
  2935. }
  2936. }
  2937. }
  2938. //中盒当前进度
  2939. CurrentBoxNum.Value = PassTenCount;
  2940. PassTenCount = PassTenCount + 1;
  2941. //外箱当前进度
  2942. CurrentOutBoxNum.Value = PassSixTenCount;
  2943. PassSixTenCount = PassSixTenCount + 1;
  2944. }
  2945. //设置索引和内容
  2946. //msgStr = msgStr.Split(ps_split.ToCharArray()[0])[dataindex];
  2947. //Input.Text = msgStr;
  2948. //Input_KeyDown(Input, new KeyEventArgs(Keys.Enter));
  2949. //}
  2950. //catch (ThreadAbortException)
  2951. //{
  2952. // //捕捉到线程被终止异常则表示是人为的断开TCP连接
  2953. // //不弹出错误提示
  2954. // break;
  2955. }
  2956. catch (Exception)
  2957. {
  2958. //接受消息发生异常
  2959. break;
  2960. //并释放相关资源
  2961. //if (ns != null)
  2962. // ns.Dispose();
  2963. //break;
  2964. }
  2965. }
  2966. MessageBox.Show("网络中断");
  2967. }
  2968. private string GetSendCode(string Code)
  2969. {
  2970. if (Angle != "")
  2971. {
  2972. Code = Code + "|,|" + Angle;
  2973. }
  2974. if (X != "")
  2975. {
  2976. Code = Code + "|,|" + X;
  2977. }
  2978. if (Y != "")
  2979. {
  2980. Code = Code + "|,|" + Y;
  2981. }
  2982. return Code;
  2983. }
  2984. /// <summary>
  2985. /// 检测TCP连接是否存在还是已经中断
  2986. /// </summary>
  2987. /// <param name="c"></param>
  2988. /// <returns></returns>
  2989. public bool IsOnline(TcpClient c)
  2990. {
  2991. try
  2992. {
  2993. bool result = !((c.Client.Poll(1000, SelectMode.SelectRead) && (c.Client.Available == 0)) || !c.Client.Connected);
  2994. return result;
  2995. }
  2996. catch
  2997. {
  2998. return false;
  2999. }
  3000. }
  3001. private void CurrentBoxNum_ValueChanged(object sender, EventArgs e)
  3002. {
  3003. }
  3004. private void CurrentBoxNum_KeyDown(object sender, KeyEventArgs e)
  3005. {
  3006. if (e.KeyCode == Keys.Enter)
  3007. {
  3008. PassTenCount = int.Parse(CurrentBoxNum.Value.ToString()) + 1;
  3009. }
  3010. }
  3011. private void CurrentOutBoxNum_KeyDown(object sender, KeyEventArgs e)
  3012. {
  3013. if (e.KeyCode == Keys.Enter)
  3014. {
  3015. PassSixTenCount = int.Parse(CurrentOutBoxNum.Value.ToString()) + 1;
  3016. }
  3017. }
  3018. private void richTextAutoBottom1_TextChanged(object sender, EventArgs e)
  3019. {
  3020. }
  3021. private void Weight_Click(object sender, EventArgs e)
  3022. {
  3023. }
  3024. private void groupBoxWithBorder2_Enter(object sender, EventArgs e)
  3025. {
  3026. }
  3027. private void DCCheck_TextChanged(object sender, EventArgs e)
  3028. {
  3029. }
  3030. private void GridPrcode_CellContentClick(object sender, DataGridViewCellEventArgs e)
  3031. {
  3032. }
  3033. private void label18_Click(object sender, EventArgs e)
  3034. {
  3035. }
  3036. private void MidBoxEnd_TextChanged(object sender, EventArgs e)
  3037. {
  3038. }
  3039. private void MidBoxBegin_TextChanged(object sender, EventArgs e)
  3040. {
  3041. }
  3042. private void label16_Click(object sender, EventArgs e)
  3043. {
  3044. }
  3045. private void SingleBoxEnd_TextChanged(object sender, EventArgs e)
  3046. {
  3047. }
  3048. private void SingleBoxBegin_TextChanged(object sender, EventArgs e)
  3049. {
  3050. }
  3051. private void label12_Click(object sender, EventArgs e)
  3052. {
  3053. }
  3054. private void label7_Click(object sender, EventArgs e)
  3055. {
  3056. }
  3057. private void groupBoxWithBorder1_Enter(object sender, EventArgs e)
  3058. {
  3059. }
  3060. private void Input_TextChanged(object sender, EventArgs e)
  3061. {
  3062. }
  3063. private void LabelInf_CellContentClick(object sender, DataGridViewCellEventArgs e)
  3064. {
  3065. }
  3066. private void pi_inoutno_TextChanged(object sender, EventArgs e)
  3067. {
  3068. }
  3069. private void label14_Click(object sender, EventArgs e)
  3070. {
  3071. }
  3072. private void CurrentOutBoxNum_ValueChanged(object sender, EventArgs e)
  3073. {
  3074. }
  3075. private void label13_Click(object sender, EventArgs e)
  3076. {
  3077. }
  3078. private void SingleLabelPrinter_Load(object sender, EventArgs e)
  3079. {
  3080. }
  3081. private void SingleLabelAutoPrint_CheckedChanged(object sender, EventArgs e)
  3082. {
  3083. }
  3084. private void SingleLabel_Enter(object sender, EventArgs e)
  3085. {
  3086. }
  3087. private void CurrentRowOnly_CheckedChanged(object sender, EventArgs e)
  3088. {
  3089. }
  3090. private void MidboxCapacity_ValueChanged(object sender, EventArgs e)
  3091. {
  3092. }
  3093. private void label2_Click(object sender, EventArgs e)
  3094. {
  3095. }
  3096. private void MidLabelNum_TextChanged(object sender, EventArgs e)
  3097. {
  3098. }
  3099. private void label5_Click(object sender, EventArgs e)
  3100. {
  3101. }
  3102. private void MidLabelPrinter_Load(object sender, EventArgs e)
  3103. {
  3104. }
  3105. private void MidLabelAutoPrint_CheckedChanged(object sender, EventArgs e)
  3106. {
  3107. }
  3108. private void MidLabel_Enter(object sender, EventArgs e)
  3109. {
  3110. }
  3111. private void DiffDetno_CheckedChanged(object sender, EventArgs e)
  3112. {
  3113. }
  3114. private void DiffCPN_CheckedChanged(object sender, EventArgs e)
  3115. {
  3116. }
  3117. private void BoxCount_Click(object sender, EventArgs e)
  3118. {
  3119. }
  3120. private void DiffLotNo_CheckedChanged(object sender, EventArgs e)
  3121. {
  3122. }
  3123. private void DiffDC_CheckedChanged(object sender, EventArgs e)
  3124. {
  3125. }
  3126. private void OnlyOneRow_CheckedChanged(object sender, EventArgs e)
  3127. {
  3128. }
  3129. private void AllLabel_CheckedChanged(object sender, EventArgs e)
  3130. {
  3131. }
  3132. private void label10_Click(object sender, EventArgs e)
  3133. {
  3134. }
  3135. private void label6_Click(object sender, EventArgs e)
  3136. {
  3137. }
  3138. private void OutBoxPrinter_Load(object sender, EventArgs e)
  3139. {
  3140. }
  3141. private void OutboxCapacity_ValueChanged(object sender, EventArgs e)
  3142. {
  3143. }
  3144. private void OutBoxLabel_Enter(object sender, EventArgs e)
  3145. { }
  3146. private void ButtonMidWeigh_Click(object sender, EventArgs e)
  3147. {
  3148. if (Weight.Text != "" && Weight.Text != "0.000")
  3149. {
  3150. string pib_outboxcode1 = LabelInf.Rows[SelectRowIndex].Cells["pib_outboxcode1"].Value.ToString();
  3151. sql.Clear();
  3152. sql.Append("update prodiobarcode set pib_midboxweight='" + Weight.Text + "' where pib_inoutno='" + pi_inoutno.Text + "' ");
  3153. sql.Append(" and pib_outboxcode2='" + OutBoxNum.Text + "' and pib_outboxcode1='" + pib_outboxcode1 + "'");
  3154. dh.ExecuteSql(sql.ToString(), "update");
  3155. LoadGridData(sender, e);
  3156. }
  3157. else
  3158. {
  3159. MessageBox.Show("请先连接电子秤!");
  3160. }
  3161. }
  3162. private void RemainTxt()
  3163. {
  3164. string[] str = Input.Text.Split('*');
  3165. Input.Text = "";
  3166. if (str.Length >= 4)
  3167. {
  3168. for (int i = 0; i < 4; i++)
  3169. {
  3170. Input.Text += str[i] + "*";
  3171. }
  3172. Input.Text.Replace("\n", "").Replace("\r", "");
  3173. Input.SelectionStart = Input.Text.Length;
  3174. }
  3175. }
  3176. }
  3177. }