UAS_出货标签管理.cs 147 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175
  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.Linq;
  9. using System.Diagnostics;
  10. using LabelManager2;
  11. using UAS_LabelMachine.PublicMethod;
  12. using UAS_LabelMachine.Entity;
  13. using UAS_LabelMachine.PublicForm;
  14. using System.Threading;
  15. using System.IO;
  16. using System.Globalization;
  17. using System.Reflection;
  18. using Seagull.BarTender.Print;
  19. using UAS_LabelMachine.CustomControl;
  20. namespace UAS_LabelMachine
  21. {
  22. public partial class UAS_出货标签打印 : Form
  23. {
  24. //自适应屏幕
  25. AutoSizeFormClass asc = new AutoSizeFormClass();
  26. DataHelper dh;
  27. SqliteDBHelper sdh;
  28. DataTable dt;
  29. StringBuilder sql = new StringBuilder();
  30. /// <summary>
  31. /// CodeSoft新建打印机引擎
  32. /// </summary>
  33. ApplicationClass lbl;
  34. /// <summary>
  35. /// CodeSoft单盘打印文件
  36. /// </summary>
  37. Document SingleDoc;
  38. /// <summary>
  39. /// CodeSoft中盒打印文件
  40. /// </summary>
  41. Document MidDoc;
  42. /// <summary>
  43. /// CodeSoft外箱打印文件
  44. /// </summary>
  45. Document OutBoxDoc;
  46. /// <summary>
  47. /// Loading窗口
  48. /// </summary>
  49. SetLoadingWindow stw;
  50. /// <summary>
  51. /// 弹窗线程
  52. /// </summary>
  53. Thread thread;
  54. /// <summary>
  55. /// 当前品牌
  56. /// </summary>
  57. string Brand;
  58. string PI_ID;
  59. /// <summary>
  60. /// 当前扫描的项目
  61. /// </summary>
  62. int CurrentItemIndex = 0;
  63. /// <summary>
  64. /// 当前扫描的所在行
  65. /// </summary>
  66. int CurrentRowIndex = 0;
  67. /// <summary>
  68. /// 最大的出入口单号
  69. /// </summary>
  70. int MaxOutBoxCode = 1;
  71. /// <summary>
  72. /// 正则表达式用于项目匹配
  73. /// </summary>
  74. /*标识供应商物料编号采集是否通过*/
  75. bool CollectVeProdCodePass = true;
  76. bool CollectQTYPass = true;
  77. bool logout = false;
  78. //每个不同序号存在的
  79. object[] ItemData;
  80. DataTable SingleLabelParam;
  81. DataTable MidLabelParam;
  82. DataTable OutLabelParam;
  83. /// <summary>
  84. /// BarTender引擎
  85. /// </summary>
  86. Engine engine;
  87. LabelFormatDocument EmptySingleFormat;
  88. LabelFormatDocument EmptyOutFormat;
  89. /// <summary>
  90. /// BarTender单盘
  91. /// </summary>
  92. LabelFormatDocument SingleFormat;
  93. /// <summary>
  94. /// BarTender中盒
  95. /// </summary>
  96. LabelFormatDocument MidFormat;
  97. /// <summary>
  98. /// BarTender外箱
  99. /// </summary>
  100. LabelFormatDocument OutFormat;
  101. Dictionary<string, string> CollectData;
  102. //缓存单盘数据数据的DataTable
  103. /// <summary>
  104. /// 存放单盘的ID
  105. /// </summary>
  106. List<string> SingleID = new List<string>();
  107. /// <summary>
  108. /// 单盘的打印参数
  109. /// </summary>
  110. List<string> SingleBoxArgument = new List<string>();
  111. /// <summary>
  112. /// 中盒缓存数据
  113. /// </summary>
  114. /// <summary>
  115. /// 存放中盒的ID和盒号
  116. /// </summary>
  117. Dictionary<string, string> MidIDAndOutboxcode = new Dictionary<string, string>();
  118. /// <summary>
  119. /// 中盒的打印参数
  120. /// </summary>
  121. List<string> MidBoxArgument = new List<string>();
  122. /// <summary>
  123. /// 全部采集
  124. /// </summary>
  125. bool AllCollect = false;
  126. /// <summary>
  127. /// 是否获取过箱号
  128. /// </summary>
  129. bool GetPackingCode = false;
  130. /*用于存放采集项目的Grid信息*/
  131. Dictionary<string, Dictionary<string, string>> SiItem;
  132. int CloumnCount = 0;
  133. //使用二维数组进行排序
  134. ArrayList<ArrayList<string>> ScanData;
  135. ArrayList<string> GetData;
  136. /// <summary>
  137. /// 是否通过选择Combox来改变打开的文件
  138. /// </summary>
  139. bool ComBoxClickChangeLabelDoc = false;
  140. List<string> MidParam = new List<string>();
  141. List<string> OutParam = new List<string>();
  142. public static DataTable Attach;
  143. public string PrintMethod = "";
  144. /// <summary>
  145. /// 用于记录外箱号和当前的箱号进行比对,判断当前行和上一行是否是同一个箱号,从而判断是否要打印空白页
  146. /// </summary>
  147. public string Last_OutboxCode = "";
  148. public UAS_出货标签打印(string Master)
  149. {
  150. //设置窗体的双缓冲
  151. this.SetStyle(ControlStyles.OptimizedDoubleBuffer | ControlStyles.ResizeRedraw | ControlStyles.AllPaintingInWmPaint, true);
  152. this.UpdateStyles();
  153. InitializeComponent();
  154. //利用反射设置DataGridView的双缓冲
  155. Type dgvType = this.LabelInf.GetType();
  156. PropertyInfo pi = dgvType.GetProperty("DoubleBuffered", BindingFlags.Instance | BindingFlags.NonPublic);
  157. pi.SetValue(this.LabelInf, true, null);
  158. Text = Text + "-" + Master;
  159. }
  160. protected override void WndProc(ref System.Windows.Forms.Message m)
  161. {
  162. //拦截双击标题栏、移动窗体的系统消息
  163. if (m.Msg != 0xA3)
  164. {
  165. base.WndProc(ref m);
  166. }
  167. }
  168. private void 贴标机条码打印_Load(object sender, EventArgs e)
  169. {
  170. ShowMenu.TopLevel = false;
  171. ShowMenu.Parent = this;
  172. //杀死之前全部未关闭的进程
  173. Process[] processes = System.Diagnostics.Process.GetProcessesByName("lppa");
  174. Process[] processes1 = System.Diagnostics.Process.GetProcessesByName("bartend");
  175. for (int i = 0; i < processes1.Length; i++)
  176. {
  177. processes1[i].Kill();
  178. }
  179. for (int i = 0; i < processes.Length; i++)
  180. {
  181. processes[i].Kill();
  182. }
  183. //用计时器重置数据库链接
  184. LogManager.DoLog("程序启动,登陆人员【" + User.UserName + "】");
  185. dh = SystemInf.dh;
  186. sdh = SystemInf.sdh;
  187. sdh.ExecuteZip();
  188. CheckForIllegalCrossThreadCalls = false;
  189. CloumnCount = LabelInf.Columns.Count;
  190. pi_inoutno.TableName = "prodinout";
  191. pi_inoutno.Field = "pi_inoutno";
  192. pi_inoutno.ValueField = "pi_inoutno";
  193. pi_inoutno.Condition = "pi_class in('出货单','拨出单','其它出库单')";
  194. pi_inoutno.Focus();
  195. //将本地读取的打印机设置进Combox,并选中默认打印机
  196. sg_code.FormName = Name;
  197. sg_code.SetValueField = new string[] { "sg_code" };
  198. sg_code.SelectField = "sg_code # 策略编号 ,sg_name # 策略名称,sg_brand # 品牌,sg_separator # 分隔符";
  199. sg_code.TableName = "scangroup";
  200. sg_code.DbChange += Sg_code_DbChange;
  201. pr_code.FormName = Name;
  202. pr_code.SetValueField = new string[] { "pr_code" };
  203. pr_code.TableName = "prodiodetail left join product on pd_prodcode=pr_code";
  204. pr_code.SelectField = "pd_pdno # 行号,pr_code # 物料编号";
  205. cu_code.FormName = Name;
  206. cu_code.SetValueField = new string[] { "cu_code" };
  207. cu_code.TableName = "customer";
  208. cu_code.SelectField = "cu_code # 客户编号,cu_name # 客户名称";
  209. CollectionUnit.Text = "盘";
  210. Point pt = new Point();
  211. //禁止所有列的排序
  212. foreach (DataGridViewColumn dgv in LabelInf.Columns)
  213. {
  214. dgv.SortMode = DataGridViewColumnSortMode.NotSortable;
  215. }
  216. int ScreenWidth = Screen.GetWorkingArea(pt).Width;
  217. //设置获取当前屏幕大小自动全屏但是保留任务栏
  218. Rectangle ScreenArea = Screen.GetWorkingArea(this);
  219. Top = 0;
  220. Left = 0;
  221. Width = ScreenArea.Width;
  222. Height = ScreenArea.Height;
  223. MidBoxCapacity.Value = Properties.Settings.Default.MidBoxCapacity;
  224. OutboxCapacity.Value = Properties.Settings.Default.OutboxCapacity;
  225. SingleLabelPrinter.Text = Properties.Settings.Default.SinglePrinter;
  226. MidLabelPrinter.Text = Properties.Settings.Default.MidPrinter;
  227. OutBoxPrinter.Text = Properties.Settings.Default.OutPrinter;
  228. asc.controllInitializeSize(this);
  229. asc.controlAutoSize(this);
  230. string Code = dh.GetConfig("PrintMethod", "CodeOrBar").ToString();
  231. SystemInf.CheckDcAndLotNo = dh.GetConfig("PrintCheck", "CheckDcAndLotNo").ToString() == "" ? false : true;
  232. if (dh.GetConfig("isSpeac", "LabelSpace").ToString() == "" ? false : true)
  233. {
  234. LabelSpace.Visible = true;
  235. LabelSpace.Checked = true;
  236. }
  237. if (Code != "")
  238. {
  239. try
  240. {
  241. lbl = new ApplicationClass();
  242. }
  243. catch (Exception)
  244. {
  245. MessageBox.Show("未安装CodeSoft软件或者版本不正确");
  246. }
  247. }
  248. else
  249. {
  250. try
  251. {
  252. engine = new Engine(true);
  253. PrintMethod = "BarTender";
  254. }
  255. catch (Exception ex)
  256. {
  257. MessageLog.AppendText(ex.Message + ex.StackTrace);
  258. //MessageBox.Show(ex.Message + ex.StackTrace);
  259. }
  260. }
  261. pi_inoutno.BringToFront();
  262. LogicHandler.CustInit("0");
  263. }
  264. private void Sg_code_DbChange(object sender, EventArgs e)
  265. {
  266. DataTable dt = sg_code.ReturnData;
  267. BaseUtil.SetFormValue(this.Controls, dt);
  268. }
  269. //只执行一次窗体自适应
  270. bool AutoSized = false;
  271. private void 贴标机条码打印_SizeChanged(object sender, EventArgs e)
  272. {
  273. if (!AutoSized)
  274. {
  275. asc.controlAutoSize(this);
  276. AutoSized = true;
  277. }
  278. }
  279. private void GenerateBarCode_Click(object sender, EventArgs e)
  280. {
  281. 生成条码 form = new 生成条码(pi_inoutno.Text, Order_Prod.Checked ? "Prod" : "Detno");
  282. form.FormClosed += LoadGridData;
  283. BaseUtil.SetFormCenter(form);
  284. form.ShowDialog();
  285. }
  286. private void LabelFormClose(object sender, EventArgs e)
  287. {
  288. Activate();
  289. if (GetGridOnly.Checked)
  290. GetInOutInfAndLabelFile();
  291. else
  292. {
  293. GetInOutInfAndLabelFile();
  294. }
  295. }
  296. /// <summary>
  297. /// 保存明细
  298. /// </summary>
  299. /// <param name="sender"></param>
  300. /// <param name="e"></param>
  301. private void SaveGrid_Click(object sender, EventArgs e)
  302. {
  303. DataTable dt = (DataTable)sdh.ExecuteSql("select pib_id,pib_outboxcode1,pib_outboxcode2,pib_custmidboxcode,pib_custoutboxcode,pib_lotno,pib_datecode,pib_ifupload,pib_ifpick,pib_ifprint from prodiobarcode where pib_inoutno='" + pi_inoutno.Text + "' and pib_ifpick=-1 ", "select");
  304. if (dt.Rows.Count > 0)
  305. {
  306. dh.CallProcedure("sp_uploadbarcode", dt);
  307. MessageBox.Show("保存成功!");
  308. }
  309. }
  310. //放大镜选择后出发的事件
  311. private void sg_code_UserControlTextChanged(object sender, EventArgs e)
  312. {
  313. //取已启用的的按照采集次序排序
  314. dt = (DataTable)dh.ExecuteSql("select si_item,si_detno,sg_separator,si_kind,si_expression,si_expressionitem,si_index,si_indexstring,si_length from scanitem left join scangroup on si_sgid=sg_id where sg_code='" + sg_code.Text + "' and si_enable<>0 order by si_detno,si_innerdetno", "select");
  315. BaseUtil.FillDgvWithDataTable(Si_ItemDGV, dt);
  316. if (dt.Rows.Count > 0)
  317. {
  318. sg_separator.Text = dt.Rows[0]["sg_separator"].ToString();
  319. }
  320. //按DetNo排列之后的采集项
  321. ScanData = new ArrayList<ArrayList<string>>();
  322. //每个采集项目的子项
  323. GetData = new ArrayList<string>();
  324. //将数据添加进一个List的二维数组中
  325. for (int i = 0; i < Si_ItemDGV.RowCount; i++)
  326. {
  327. //如果不包含这个则添加进数组
  328. if (!GetData.Contains(Si_ItemDGV.Rows[i].Cells["si_item"].Value.ToString()))
  329. {
  330. GetData.Add(Si_ItemDGV.Rows[i].Cells["si_item"].Value.ToString());
  331. }
  332. //如果和后一个的采集次序相同
  333. if (((i + 1) < Si_ItemDGV.RowCount) && Si_ItemDGV.Rows[i].Cells["si_detno"].Value.ToString() == Si_ItemDGV.Rows[i + 1].Cells["si_detno"].Value.ToString())
  334. {
  335. GetData.Add(Si_ItemDGV.Rows[i + 1].Cells["si_item"].Value.ToString());
  336. }
  337. else
  338. {
  339. ScanData.Add(GetData);
  340. //添加完一次数据需要一个新的List
  341. GetData = new ArrayList<string>();
  342. }
  343. }
  344. RemindUser();
  345. if (ScanData.ToArray().Length > 0)
  346. {
  347. object[] arr = (ScanData.ToArray()[0] as ArrayList<string>).ToArray();
  348. if (arr.Contains("MPN"))
  349. {
  350. AutoMatch.CheckState = CheckState.Checked;
  351. AutoMatch.Enabled = true;
  352. }
  353. else
  354. {
  355. AutoMatch.CheckState = CheckState.Unchecked;
  356. AutoMatch.Enabled = false;
  357. }
  358. }
  359. }
  360. //输入框Enter事件
  361. private void Input_KeyDown(object sender, KeyEventArgs e)
  362. {
  363. if (e.KeyCode == Keys.Enter)
  364. {
  365. if (Input.Text == "")
  366. {
  367. MessageBox.Show("采集的数据不能为空");
  368. return;
  369. }
  370. if (Si_ItemDGV.Rows.Count == 0)
  371. {
  372. MessageBox.Show("未维护采集策略");
  373. return;
  374. }
  375. CollectInputData();
  376. }
  377. }
  378. /// <summary>
  379. /// 设置自动匹配的数据的行号
  380. /// </summary>
  381. /// <returns></returns>
  382. private void SetAutoMatchRow()
  383. {
  384. //采集策略的第一组数据
  385. string[] arr = new string[ItemData.Length];
  386. if (sg_separator.Text == "")
  387. {
  388. for (int i = 0; i < arr.Length; i++)
  389. {
  390. arr[i] = Input.Text;
  391. }
  392. }
  393. else
  394. {
  395. arr = Input.Text.Split(sg_separator.Text.ToCharArray()).ToArray();
  396. }
  397. bool FindAutoMatch = false;
  398. for (int i = 0; i < LabelInf.RowCount; i++)
  399. {
  400. for (int j = 0; j < arr.Length; j++)
  401. {
  402. if (LabelInf.Rows[i].Cells["pr_vendprodcode"].Value.ToString() == MatchStr(arr[j].ToString(), "MPN") && LabelInf.Rows[i].Cells["pib_ifpick"].FormattedValue.ToString() != "True")
  403. {
  404. CurrentRowIndex = i;
  405. FindAutoMatch = true;
  406. break;
  407. }
  408. }
  409. if (FindAutoMatch)
  410. break;
  411. }
  412. }
  413. /// <summary>
  414. /// 采集数据
  415. /// </summary>
  416. private void CollectInputData()
  417. {
  418. LogManager.DoLog("采集数据【" + Input.Text + "】,使用采集策略编号【" + sg_code.Text + "】");
  419. //按DetNo排列之后的采集项
  420. ScanData = new ArrayList<ArrayList<string>>();
  421. //每个采集项目的子项
  422. GetData = new ArrayList<string>();
  423. //用于保存采集策略的具体信息
  424. SiItem = new Dictionary<string, Dictionary<string, string>>();
  425. for (int i = 0; i < Si_ItemDGV.RowCount; i++)
  426. {
  427. //如果不包含这个则添加进数组
  428. if (!GetData.Contains(Si_ItemDGV.Rows[i].Cells["si_item"].Value.ToString()))
  429. GetData.Add(Si_ItemDGV.Rows[i].Cells["si_item"].Value.ToString());
  430. //如果和后一个的采集次序相同
  431. if (((i + 1) < Si_ItemDGV.RowCount) && Si_ItemDGV.Rows[i].Cells["si_detno"].Value.ToString() == Si_ItemDGV.Rows[i + 1].Cells["si_detno"].Value.ToString())
  432. GetData.Add(Si_ItemDGV.Rows[i + 1].Cells["si_item"].Value.ToString());
  433. else
  434. {
  435. ScanData.Add(GetData);
  436. //添加完一次数据需要一个新的List
  437. GetData = new ArrayList<string>();
  438. }
  439. Dictionary<string, string> item = new Dictionary<string, string>();
  440. for (int j = 0; j < Si_ItemDGV.ColumnCount; j++)
  441. {
  442. item.Add(Si_ItemDGV.Columns[j].DataPropertyName, Si_ItemDGV.Rows[i].Cells[j].Value.ToString());
  443. }
  444. SiItem.Add(Si_ItemDGV.Rows[i].Cells["si_item"].Value.ToString().ToUpper(), item);
  445. }
  446. //采集项目的数组
  447. ItemData = (ScanData.ToArray()[CurrentItemIndex] as ArrayList<string>).ToArray();
  448. //分隔符不为空的时候 //采集的项和Grid的数目不等
  449. //用户采集的数据的分割数组
  450. CollectData = new Dictionary<string, string>();
  451. if (sg_separator.Text == "")
  452. {
  453. for (int i = 0; i < ItemData.Length; i++)
  454. CollectData.Add(ItemData[i].ToString().ToUpper(), Input.Text);
  455. }
  456. else
  457. {
  458. int DataCount = Input.Text.Split(sg_separator.Text.ToCharArray()).Length;
  459. if (DataCount > ItemData.Length)
  460. {
  461. MessageBox.Show("采集数据大于采集项次");
  462. return;
  463. }
  464. else if (DataCount < ItemData.Length)
  465. {
  466. MessageBox.Show("采集数据小于采集项次");
  467. return;
  468. }
  469. for (int i = 0; i < DataCount; i++)
  470. CollectData.Add(ItemData[i].ToString().ToUpper(), Input.Text.Split(sg_separator.Text.ToCharArray())[i]);
  471. }
  472. //首先判断当前采集的个数,如果采集的个数为1则不对数据进行分隔符验证
  473. if (ItemData.Length > 0)
  474. {
  475. //CollectData.Clear();
  476. //for (int i = 0; i < ItemData.Length; i++)
  477. //{
  478. // CollectData.Add(ItemData[i].ToString().ToUpper(), Input.Text);
  479. //}
  480. //勾选了自动匹配调用该函数
  481. if (AutoMatch.Checked)
  482. SetAutoMatchRow();
  483. //将筛选之后的值赋给Cell
  484. SetDataToCell(ref CollectData);
  485. }
  486. else
  487. {
  488. MessageBox.Show("所采集的数据个数和采集项目不符");
  489. return;
  490. }
  491. //采集项目的索引+1
  492. CurrentItemIndex = CurrentItemIndex + 1;
  493. //如果已经采集完了最后一个
  494. if (CurrentItemIndex == ScanData.ToArray().Length)
  495. {
  496. //数据校验均已通过则勾选上已采集
  497. if (CollectVeProdCodePass && CollectQTYPass)
  498. {
  499. //如果按盒号采集,所有的此盒的均更新为
  500. DataTable dt = (DataTable)LabelInf.DataSource;
  501. StringBuilder pibid1 = new StringBuilder();
  502. string year = "0";
  503. string month = "0";
  504. string day = "0";
  505. string lotno = LabelInf.Rows[CurrentRowIndex].Cells["pib_lotno"].Value.ToString();
  506. string datecode = LabelInf.Rows[CurrentRowIndex].Cells["pib_datecode"].Value.ToString();
  507. string pr_brand = LabelInf.Rows[CurrentRowIndex].Cells["pib_brand"].Value.ToString();
  508. //LogicHandler.GetTimeFromDatecode(datecode, pr_brand, out year, out month, out day, out date);
  509. if (CollectionUnit.Text == "盒")
  510. {
  511. for (int i = 0; i < LabelInf.RowCount; i++)
  512. {
  513. if (LabelInf.Rows[i].Cells["pib_outboxcode1"].Value.ToString() == LabelInf.Rows[CurrentRowIndex].Cells["pib_outboxcode1"].Value.ToString())
  514. {
  515. string pibid = LabelInf.Rows[i].Cells["pib_id1"].Value.ToString();
  516. string outboxcode = LabelInf.Rows[i].Cells["pib_outboxcode2"].Value.ToString();
  517. dt.Rows[i]["pib_lotno"] = lotno;
  518. dt.Rows[i]["pib_datecode"] = datecode;
  519. dt.Rows[i]["pib_year"] = year;
  520. dt.Rows[i]["pib_month"] = month;
  521. dt.Rows[i]["pib_day"] = day;
  522. LabelInf.Rows[i].Cells["pib_ifpick"].Value = true;
  523. LabelInf.Rows[i].Cells["Choose"].Value = true;
  524. pibid1.Append(pibid + ",");
  525. LabelInf.Invalidate();
  526. //当前行的索引随循环增长
  527. CurrentRowIndex = i;
  528. if (SingleLabelAutoPrint.Checked)
  529. {
  530. AutoPrintSingleLabel(pibid, outboxcode);
  531. }
  532. if (MidLabelAutoPrint.Checked)
  533. AutoPrintMidLabel();
  534. SetOutBoxCode2(true);
  535. }
  536. }
  537. pibid1.Append("1");
  538. sdh.ExecuteSql("update prodiobarcode set pib_ifpick=-1,pib_lotno='" + lotno + "',pib_datecode='" + datecode + "',pib_year='" + year + "',pib_month='" + month + "',pib_day='" + day + "' where pib_id in (" + pibid1 + ")", "update");
  539. Last_OutboxCode = "";
  540. }
  541. else if (CollectionUnit.Text == "全部")
  542. {
  543. for (int i = 0; i < LabelInf.RowCount; i++)
  544. {
  545. string pibid = LabelInf.Rows[i].Cells["pib_id1"].Value.ToString();
  546. dt.Rows[i]["pib_lotno"] = lotno;
  547. dt.Rows[i]["pib_datecode"] = datecode;
  548. dt.Rows[i]["pib_year"] = year;
  549. dt.Rows[i]["pib_month"] = month;
  550. dt.Rows[i]["pib_day"] = day;
  551. CurrentRowIndex = i;
  552. LabelInf.Refresh();
  553. LabelInf.Rows[i].Cells["pib_ifpick"].Value = true;
  554. LabelInf.Rows[i].Cells["Choose"].Value = true;
  555. pibid1.Append(pibid + ",");
  556. LabelInf.Invalidate();
  557. SetOutBoxCode2(true);
  558. }
  559. pibid1.Append("1");
  560. sdh.ExecuteSql("update prodiobarcode set pib_ifpick=-1,pib_lotno='" + lotno + "',pib_datecode='" + datecode + "',pib_year='" + year + "',pib_month='" + month + "',pib_day='" + day + "' where pib_id in (" + pibid1 + ")", "update");
  561. }
  562. else
  563. {
  564. LabelInf.Rows[CurrentRowIndex].Cells["pib_ifpick"].Value = true;
  565. LabelInf.Rows[CurrentRowIndex].Cells["Choose"].Value = true;
  566. LabelInf.Rows[CurrentRowIndex].Cells["pib_year"].Value = year;
  567. LabelInf.Rows[CurrentRowIndex].Cells["pib_month"].Value = month;
  568. LabelInf.Rows[CurrentRowIndex].Cells["pib_day"].Value = day;
  569. sdh.ExecuteSql("update prodiobarcode set pib_ifpick=-1,pib_lotno='" + lotno + "',pib_datecode='" + datecode + "',pib_year='" + year + "',pib_month='" + month + "',pib_day='" + day + "' where pib_id in (" + pibid1 + ")", "update");
  570. LabelInf.Invalidate();
  571. //勾选了单盘自动打印
  572. if (SingleLabelAutoPrint.Checked)
  573. {
  574. if (SingleLabelCombox.SelectedValue != null)
  575. {
  576. AutoPrintSingleLabel(LabelInf.Rows[CurrentRowIndex].Cells["pib_id1"].Value.ToString(), LabelInf.Rows[CurrentRowIndex].Cells["pib_outboxcode2"].Value.ToString());
  577. Last_OutboxCode = "";
  578. }
  579. else
  580. {
  581. MessageBox.Show("未维护单盘标签");
  582. return;
  583. }
  584. }
  585. //勾选了中盒自动打印
  586. if (MidLabelAutoPrint.Checked)
  587. AutoPrintMidLabel();
  588. }
  589. }
  590. //采集未通过的时候
  591. else
  592. {
  593. //如果自动采集采集未成功需要移动到下一行
  594. if (!AutoMatch.Checked)
  595. SetRowIndexToCollectRow();
  596. }
  597. //当前项目已采集完成,重置采集项目
  598. CurrentItemIndex = 0;
  599. //未勾选自动匹配,设置到下一个未采集的行
  600. if (!AutoMatch.Checked)
  601. SetRowIndexToCollectRow();
  602. }
  603. //提醒用户需要采集的数据
  604. RemindUser();
  605. RefreshProcessData();
  606. MessageLog.AppendText(">>扫描到数据" + Input.Text + "\n", Color.Blue);
  607. //如果所采集的行的物料不一样的话,重新计算箱内容量
  608. if (CurrentRowIndex - 1 > 0)
  609. {
  610. string LastRowProd = LabelInf.Rows[CurrentRowIndex - 1].Cells["pib_prodcode"].Value.ToString();
  611. string CurrentRowProd = LabelInf.Rows[CurrentRowIndex].Cells["pib_prodcode"].Value.ToString();
  612. //如果两行的物料资料不相等的话
  613. if (LastRowProd != CurrentRowProd)
  614. SetOutBoxCapacity(CurrentRowProd);
  615. }
  616. if (CleanInputAfterCollect.Checked)
  617. Input.Text = "";
  618. }
  619. /// <summary>
  620. /// 根据物料资料的参数设置外箱容量
  621. /// </summary>
  622. /// <param name="pr_code"></param>
  623. private void SetOutBoxCapacity(string pr_code)
  624. {
  625. DataTable temp = (DataTable)dh.ExecuteSql("select pr_qtyperplace,pr_zxbzs from product where pr_code='" + pr_code + "'", "select");
  626. if (temp.Rows.Count > 0)
  627. {
  628. //try { OutboxCapacity.Value = (decimal)temp.Rows[0]["pr_qtyperplace"] / (decimal)temp.Rows[0]["pr_zxbzs"]; }
  629. //catch (Exception) { }
  630. }
  631. }
  632. //设置行的索引到当前需要采集的行
  633. private void SetRowIndexToCollectRow()
  634. {
  635. //获取当前需要采集的行
  636. for (int i = CurrentRowIndex; i < LabelInf.RowCount; i++)
  637. {
  638. if (LabelInf.Rows[i].Cells["pib_ifpick"].FormattedValue.ToString() != "True")
  639. {
  640. griddetno.Text = LabelInf.Rows[i].Cells["pib_pdno"].FormattedValue.ToString();
  641. pr_code.Text = LabelInf.Rows[i].Cells["pib_prodcode"].FormattedValue.ToString();
  642. CurrentRowIndex = LabelInf.Rows[i].Cells["pib_prodcode"].RowIndex;
  643. break;
  644. }
  645. }
  646. }
  647. private void AutoPrintSingleLabel(string pib_id, string outboxcode)
  648. {
  649. bool PrintBlankLabel = false;
  650. if (PrintMethod == "CodeSoft")
  651. Print.CodeSoft.SinglePrint(SingleDoc, SingleLabelParam, pib_id);
  652. else
  653. {
  654. //第一箱不打印空标签
  655. if (outboxcode != "" && Last_OutboxCode == "")
  656. {
  657. PrintBlankLabel = false;
  658. }
  659. //如果外箱不相等
  660. else if (outboxcode != "" && Last_OutboxCode != "" && outboxcode != Last_OutboxCode)
  661. {
  662. PrintBlankLabel = true;
  663. }
  664. Last_OutboxCode = outboxcode;
  665. //打印一张空白标签
  666. if (LabelSpace.Checked && PrintBlankLabel)
  667. {
  668. Print.BarTender.SinglePrint(EmptySingleFormat, SingleLabelParam, "-1");
  669. }
  670. Print.BarTender.SinglePrint(SingleFormat, SingleLabelParam, pib_id);
  671. }
  672. LabelInf.Rows[CurrentRowIndex].Cells["pib_ifprint"].Value = true;
  673. sdh.ExecuteSql("update prodiobarcode set pib_ifprint=-1 where pib_id='" + pib_id + "'", "update");
  674. }
  675. /// <summary>
  676. /// 提醒用户当前采集的项目
  677. /// </summary>
  678. private void RemindUser()
  679. {
  680. SetRowIndexToCollectRow();
  681. if (ScanData.ToArray().Length > 0)
  682. {
  683. object[] arr = (ScanData.ToArray()[CurrentItemIndex] as ArrayList<string>).ToArray();
  684. string Inf = "";
  685. for (int i = 0; i < arr.Length; i++)
  686. {
  687. Inf += arr[i] + " ";
  688. }
  689. MessageLog.AppendText(">>当前采集行" + (CurrentRowIndex + 1) + ",请采集" + Inf + "\n", Color.Green);
  690. }
  691. }
  692. /// <summary>
  693. /// 自定义函数 将匹配之后的值设置到Cell中,传递引用,每次赋值之后从List中移除已使用过的
  694. /// </summary>
  695. /// <param name="data"></param>
  696. /// <param name="kind"></param>
  697. private void SetDataToCell(ref Dictionary<string, string> setdata)
  698. {
  699. int length = setdata.Count;
  700. string pib_id = LabelInf.Rows[CurrentRowIndex].Cells["pib_id1"].Value.ToString();
  701. string LotNo = "";
  702. string DateCode = "";
  703. foreach (var item in setdata)
  704. {
  705. string[] data = new string[setdata.Count];
  706. for (int i = 0; i < length; i++)
  707. {
  708. data[i] = setdata[item.Key];
  709. }
  710. DataGridViewCell cell = null;
  711. string Matchstr = "";
  712. switch (item.Key)
  713. {
  714. case "DATECODE":
  715. cell = LabelInf.Rows[CurrentRowIndex].Cells["pib_datecode"];
  716. Matchstr = MatchStr(item.Value, "DATECODE");
  717. DateCode = Matchstr;
  718. length--;
  719. break;
  720. case "LOTNO":
  721. cell = LabelInf.Rows[CurrentRowIndex].Cells["pib_lotno"];
  722. Matchstr = MatchStr(item.Value, "LOTNO");
  723. LotNo = Matchstr;
  724. length--;
  725. break;
  726. case "MPN":
  727. cell = LabelInf.Rows[CurrentRowIndex].Cells["pr_vendprodcode"];
  728. Matchstr = MatchStr(item.Value, "MPN");
  729. //采集的供应商号不匹配的话
  730. if (cell.Value.ToString() != Matchstr)
  731. {
  732. CollectVeProdCodePass = false;
  733. //添加需要重绘的Cell
  734. LabelInf.Refresh();
  735. MessageLog.AppendText(">>供应商物料编号不匹配\n", Color.Red);
  736. }
  737. else
  738. {
  739. LabelInf.Refresh();
  740. CollectVeProdCodePass = true;
  741. }
  742. length--;
  743. break;
  744. case "QTY":
  745. cell = LabelInf.Rows[CurrentRowIndex].Cells["pib_qty"];
  746. Matchstr = MatchStr(item.Value, "QTY");
  747. //如果采集的数量不相等的话
  748. if (cell.Value.ToString() != Matchstr)
  749. {
  750. CollectQTYPass = false;
  751. LabelInf.Refresh();
  752. MessageLog.AppendText(">>数量不匹配\n", Color.Red);
  753. }
  754. else
  755. {
  756. LabelInf.Refresh();
  757. CollectQTYPass = true;
  758. }
  759. length--;
  760. break;
  761. case "品牌":
  762. cell = LabelInf.Rows[CurrentRowIndex].Cells["pib_brand"];
  763. Matchstr = MatchStr(item.Value, "品牌");
  764. //如果采集的数量不相等的话
  765. if (cell.Value.ToString() != Matchstr)
  766. {
  767. CollectQTYPass = false;
  768. LabelInf.Refresh();
  769. MessageLog.AppendText(">>品牌不匹配\n", Color.Red);
  770. }
  771. else
  772. {
  773. LabelInf.Refresh();
  774. CollectQTYPass = true;
  775. }
  776. length--;
  777. break;
  778. default:
  779. break;
  780. }
  781. //如果数据为空或者数据不为空的时候但是和需要采集的数据不相等的情况下进行采集
  782. //MPN和QTY只做比较不需要赋值
  783. if (cell.Value.ToString() == "" || cell.Value.ToString() != Matchstr)
  784. {
  785. string MatchResult = "";
  786. if (item.Key != "MPN" && item.Key != "QTY" && item.Key != "品牌")
  787. {
  788. DataTable dt = (DataTable)LabelInf.DataSource;
  789. cell.Value = Matchstr;
  790. MatchResult = "成功";
  791. }
  792. else
  793. MatchResult = "失败";
  794. switch (SiItem[item.Key]["si_kind"])
  795. {
  796. case "索引字符":
  797. LogManager.DoLog("采集项" + item.Key + ",匹配结果:【" + MatchResult + "】,匹配方式:" + SiItem[item.Key]["si_kind"] + ",使用字符" + SiItem[item.Key]["si_indexstring"] + ",匹配后字符串" + Matchstr);
  798. break;
  799. case "起始位置":
  800. LogManager.DoLog("采集项" + item.Key + ",匹配结果:【" + MatchResult + "】,匹配方式:" + SiItem[item.Key]["si_kind"] + ",从第" + SiItem[item.Key]["si_index"] + "位开始匹配,匹配后字符串" + Matchstr);
  801. break;
  802. case "二次解析":
  803. LogManager.DoLog("采集项" + item.Key + ",匹配结果:【" + MatchResult + "】,匹配方式:" + SiItem[item.Key]["si_kind"] + ",匹配后字符串" + Matchstr);
  804. break;
  805. case "全部":
  806. LogManager.DoLog("采集项" + item.Key + ",匹配结果:【" + MatchResult + "】,匹配方式:" + SiItem[item.Key]["si_kind"] + ",匹配后字符串" + Matchstr);
  807. break;
  808. default:
  809. break;
  810. }
  811. }
  812. else
  813. LogManager.DoLog("采集项" + item.Key + ",匹配结果:【成功】,匹配方式:" + SiItem[item.Key]["si_kind"] + ",,匹配后字符串" + Matchstr);
  814. }
  815. sql.Clear();
  816. sql.Append("update prodiobarcode set pib_ifpick=-1");
  817. if (LotNo != "")
  818. {
  819. sql.Append(",pib_lotno='" + LotNo + "'");
  820. }
  821. if (DateCode != "")
  822. {
  823. string year = "";
  824. string month = "";
  825. string day = "";
  826. string pr_brand = LabelInf.Rows[CurrentRowIndex].Cells["pib_brand"].Value.ToString();
  827. //LogicHandler.GetTimeFromDatecode(DateCode, pr_brand, out year, out month, out day, out date);
  828. sql.Append(",pib_datecode='" + DateCode + "',pib_year='" + year + "',pib_month='" + month + "',pib_day='" + day + "' ");
  829. }
  830. sql.Append(" where pib_id='" + pib_id + "'");
  831. sdh.ExecuteSql(sql.ToString(), "update");
  832. //添加外箱号,如果外箱号的箱内容量不为0并且已经采集完成
  833. SetOutBoxCode2(false);
  834. }
  835. //
  836. /// <summary>
  837. /// 设置外箱号
  838. /// </summary>
  839. /// <param name="BatchCollect">是否批量采集</param>
  840. private void SetOutBoxCode2(bool BatchCollect)
  841. {
  842. if (OutboxCapacity.Value != 0)
  843. {
  844. //获取当前出入口单最大的外箱号
  845. for (int i = 0; i < LabelInf.RowCount; i++)
  846. {
  847. string outboxcode = LabelInf.Rows[i].Cells["pib_outboxcode2"].Value.ToString();
  848. if (outboxcode.Contains("-"))
  849. {
  850. if (int.Parse(outboxcode.Split('-')[0] == "" ? "1" : outboxcode.Split('-')[0]) > MaxOutBoxCode)
  851. MaxOutBoxCode = int.Parse(outboxcode.Split('-')[0]);
  852. }
  853. else
  854. {
  855. if (int.Parse(outboxcode == "" ? "0" : outboxcode) > MaxOutBoxCode)
  856. MaxOutBoxCode = int.Parse(outboxcode);
  857. }
  858. }
  859. //统计最大的箱号存在多少
  860. int MaxOutBoxCodeCount = 0;
  861. for (int i = 0; i < LabelInf.RowCount; i++)
  862. {
  863. if (LabelInf.Rows[i].Cells["pib_outboxcode2"].Value.ToString() == MaxOutBoxCode.ToString())
  864. MaxOutBoxCodeCount = MaxOutBoxCodeCount + 1;
  865. }
  866. //如果是获取过包装单的话则不再继续追加箱号
  867. if (!GetPackingCode)
  868. {
  869. //如果箱内的盒数量小于容量,继续使用此箱号赋值,否则箱号+1
  870. if (BatchCollect)
  871. {
  872. if (MaxOutBoxCodeCount < OutboxCapacity.Value)
  873. LabelInf.Rows[CurrentRowIndex].Cells["pib_outboxcode2"].Value = MaxOutBoxCode;
  874. else
  875. {
  876. MaxOutBoxCode = MaxOutBoxCode + 1;
  877. LabelInf.Rows[CurrentRowIndex].Cells["pib_outboxcode2"].Value = MaxOutBoxCode;
  878. }
  879. }
  880. else
  881. {
  882. if (MaxOutBoxCodeCount <= OutboxCapacity.Value)
  883. LabelInf.Rows[CurrentRowIndex].Cells["pib_outboxcode2"].Value = MaxOutBoxCode;
  884. else
  885. {
  886. MaxOutBoxCode = MaxOutBoxCode + 1;
  887. LabelInf.Rows[CurrentRowIndex].Cells["pib_outboxcode2"].Value = MaxOutBoxCode;
  888. }
  889. }
  890. }
  891. }
  892. }
  893. /// <summary>
  894. /// 自定义函数 根据匹配规则
  895. /// si_item的二维数组,str是需要赋值的字符串,item表示DateCode,LotNo等
  896. /// </summary>
  897. /// <param name="SiItem"></param>
  898. /// <param name="str"></param>
  899. /// <param name="item"></param>
  900. /// <returns></returns>
  901. private string MatchStr(string str, string item)
  902. {
  903. string kind = SiItem[item]["si_kind"];
  904. //起始字符不为空的时候
  905. switch (kind)
  906. {
  907. case "起始位置":
  908. if (SiItem[item]["si_index"] != "")
  909. {
  910. try
  911. {
  912. //长度不为空的时候按照指定的长度去取数据
  913. if (SiItem[item]["si_length"] != "")
  914. str = str.Substring(int.Parse(SiItem[item]["si_index"]), int.Parse(SiItem[item]["si_length"]));
  915. //长度为空的时候取index之后的全部数据
  916. else
  917. str = str.Substring(int.Parse(SiItem[item]["si_index"]));
  918. }
  919. catch (Exception e) { LogManager.DoLog(e.StackTrace); }
  920. }
  921. break;
  922. case "索引字符":
  923. try
  924. {
  925. if (SiItem[item]["si_indexstring"] != "")
  926. {
  927. //长度不为空的时候按照指定的长度去取数据
  928. if (SiItem[item]["si_length"] != "")
  929. str = str.Substring(str.IndexOf(SiItem[item]["si_indexstring"]) + 1, int.Parse(SiItem[item]["si_length"]));
  930. //长度为空的时候取index之后的全部数据
  931. else
  932. str = str.Substring(str.IndexOf(SiItem[item]["si_indexstring"]) + 1);
  933. }
  934. }
  935. catch (Exception e) { LogManager.DoLog(e.StackTrace); }
  936. break;
  937. case "全部":
  938. break;
  939. default:
  940. break;
  941. }
  942. if (SiItem[item]["si_expression"] != "")
  943. {
  944. string log = "使用正则表达式" + SiItem[item]["si_expression"] + "匹配数据" + str;
  945. reg = new Regex(SiItem[item]["si_expression"]);
  946. try
  947. {
  948. str = reg.Matches(str)[int.Parse(SiItem[item]["si_expressionitem"].ToString()) - 1].Value;
  949. }
  950. catch (Exception)
  951. {
  952. }
  953. log += ",匹配后数据" + str;
  954. LogManager.DoLog(log);
  955. }
  956. return str;
  957. }
  958. //关闭窗口前提示用户确认
  959. private void 贴标机条码打印_FormClosing(object sender, FormClosingEventArgs e)
  960. {
  961. //如果不是注销的话
  962. if (!logout)
  963. {
  964. string close = MessageBox.Show(this.ParentForm, "是否关闭", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question).ToString();
  965. if (close.ToString() != "Yes")
  966. e.Cancel = true;
  967. else
  968. {
  969. if (lbl != null)
  970. lbl.Quit();
  971. if (engine != null)
  972. engine.Dispose();
  973. LogManager.DoLog("关闭程序");
  974. }
  975. }
  976. }
  977. /// <summary>
  978. /// 获取打印标签
  979. /// </summary>
  980. private void GetInOutInfAndLabelFile()
  981. {
  982. ComBoxClickChangeLabelDoc = false;
  983. Attach = (DataTable)dh.ExecuteSql("select lap_param lp_name,lap_value lp_sql from LabelAttachPARAMETER where lap_custcode='" + cu_code.Text + "'", "select");
  984. sql.Clear();
  985. sql.Append("select to_char(nvl(cl_date,sysdate),'YYYY-MM-DD HH24:Mi:SS') cl_date,cl_labelname,cl_isdefault,la_id||'#'||cl_labelurl||'#'||to_char(cl_date,'YYYY-MM-DD HH24:Mi:SS') ");
  986. sql.Append(" la_id,cl_custcode from customerlabel left join customer on cu_code=cl_custcode left join label on la_code=CL_LABELCODE where (cl_custcode='" + cu_code.Text + "' ");
  987. sql.Append(" or cl_custcode is null) and cl_labeltype='单盘' order by cl_custcode");
  988. dt = (DataTable)dh.ExecuteSql(sql.ToString(), "select");
  989. SingleLabelCombox.DisplayMember = "cl_labelname";
  990. SingleLabelCombox.ValueMember = "la_id";
  991. SingleLabelCombox.DataSource = dt;
  992. if (SingleDoc != null)
  993. SingleDoc.Close();
  994. if (!GetGridOnly.Checked)
  995. for (int i = 0; i < dt.Rows.Count; i++)
  996. {
  997. string LabelUrl = dt.Rows[i]["la_id"].ToString().Split('#')[1];
  998. string LabelName = dt.Rows[i]["cl_labelname"].ToString();
  999. System.DateTime time = Convert.ToDateTime(dt.Rows[i]["cl_date"].ToString());
  1000. FileInfo file = new FileInfo(ftpOperater.DownLoadTo + LabelName);
  1001. if (time.ToString() != file.LastWriteTime.ToString())
  1002. BaseUtil.GetLabelUrl(LabelUrl, LabelName, time);
  1003. }
  1004. if (SingleLabelCombox.Text != "")
  1005. {
  1006. if (PrintMethod == "CodeSoft")
  1007. {
  1008. SingleDoc = lbl.Documents.Open(ftpOperater.DownLoadTo + SingleLabelCombox.Text);
  1009. SingleDoc.Printer.SwitchTo(SingleLabelPrinter.Text);
  1010. }
  1011. else
  1012. {
  1013. if (SingleFormat != null)
  1014. {
  1015. SingleFormat.Close(SaveOptions.DoNotSaveChanges);
  1016. }
  1017. SingleFormat = engine.Documents.Open(ftpOperater.DownLoadTo + SingleLabelCombox.Text);
  1018. SingleFormat.PrintSetup.PrinterName = SingleLabelPrinter.Text;
  1019. }
  1020. SingleLabelParam = (DataTable)dh.ExecuteSql("select lp_name,lp_sql,lp_valuetype from label left join LABELPARAMETER on la_id= lp_laid where la_id=" + SingleLabelCombox.SelectedValue.ToString().Split('#')[0], "select");
  1021. }
  1022. sql.Clear();
  1023. sql.Append("select to_char(nvl(cl_date,sysdate),'YYYY-MM-DD HH24:Mi:SS') cl_date,cl_labelname,cl_isdefault,la_id||'#'||cl_labelurl||'#'||to_char(cl_date,'YYYY-MM-DD HH24:Mi:SS') ");
  1024. sql.Append(" la_id,cl_custcode from customerlabel left join customer on cu_code=cl_custcode left join label on la_code=CL_LABELCODE where (cl_custcode='" + cu_code.Text + "' ");
  1025. sql.Append(" or cl_custcode is null) and cl_labeltype='中盒' order by cl_labelname");
  1026. dt = (DataTable)dh.ExecuteSql(sql.ToString(), "select");
  1027. MidLabelCombox.DisplayMember = "cl_labelname";
  1028. MidLabelCombox.ValueMember = "la_id";
  1029. MidLabelCombox.DataSource = dt;
  1030. if (MidDoc != null)
  1031. MidDoc.Close();
  1032. if (!GetGridOnly.Checked)
  1033. for (int i = 0; i < dt.Rows.Count; i++)
  1034. {
  1035. string LabelUrl = dt.Rows[i]["la_id"].ToString().Split('#')[1];
  1036. string LabelName = dt.Rows[i]["cl_labelname"].ToString();
  1037. System.DateTime time = Convert.ToDateTime(dt.Rows[i]["cl_date"].ToString());
  1038. FileInfo file = new FileInfo(ftpOperater.DownLoadTo + LabelName);
  1039. if (time.ToString() != file.LastWriteTime.ToString())
  1040. BaseUtil.GetLabelUrl(LabelUrl, LabelName, time);
  1041. }
  1042. if (MidLabelCombox.Text != "")
  1043. {
  1044. if (PrintMethod == "CodeSoft")
  1045. {
  1046. MidDoc = lbl.Documents.Open(ftpOperater.DownLoadTo + MidLabelCombox.Text);
  1047. MidDoc.Printer.SwitchTo(MidLabelPrinter.Text);
  1048. }
  1049. else
  1050. {
  1051. if (MidFormat != null)
  1052. {
  1053. MidFormat.Close(SaveOptions.DoNotSaveChanges);
  1054. }
  1055. MidFormat = engine.Documents.Open(ftpOperater.DownLoadTo + MidLabelCombox.Text);
  1056. MidFormat.PrintSetup.PrinterName = MidLabelPrinter.Text;
  1057. }
  1058. MidLabelParam = (DataTable)dh.ExecuteSql("select lp_name,lp_sql,lp_valuetype from label left join LABELPARAMETER on la_id= lp_laid where la_id=" + MidLabelCombox.SelectedValue.ToString().Split('#')[0], "select");
  1059. }
  1060. //缓存中盒参数
  1061. sql.Clear();
  1062. sql.Append("select to_char(nvl(cl_date,sysdate),'YYYY-MM-DD HH24:Mi:SS') cl_date,cl_labelname,cl_isdefault,la_id||'#'||cl_labelurl||'#'||to_char(cl_date,'YYYY-MM-DD HH24:Mi:SS') ");
  1063. sql.Append(" la_id,cl_custcode from customerlabel left join customer on cu_code=cl_custcode left join label on la_code=CL_LABELCODE where (cl_custcode='" + cu_code.Text + "' ");
  1064. sql.Append(" or cl_custcode is null) and cl_labeltype='外箱' order by cl_custcode");
  1065. dt = (DataTable)dh.ExecuteSql(sql.ToString(), "select");
  1066. OutBoxCombox.DisplayMember = "cl_labelname";
  1067. OutBoxCombox.ValueMember = "la_id";
  1068. OutBoxCombox.DataSource = dt;
  1069. if (OutBoxDoc != null)
  1070. OutBoxDoc.Close();
  1071. if (!GetGridOnly.Checked)
  1072. for (int i = 0; i < dt.Rows.Count; i++)
  1073. {
  1074. string LabelUrl = dt.Rows[i]["la_id"].ToString().Split('#')[1];
  1075. string LabelName = dt.Rows[i]["cl_labelname"].ToString();
  1076. System.DateTime time = Convert.ToDateTime(dt.Rows[i]["cl_date"].ToString());
  1077. FileInfo file = new FileInfo(ftpOperater.DownLoadTo + LabelName);
  1078. if (time.ToString() != file.LastWriteTime.ToString())
  1079. BaseUtil.GetLabelUrl(LabelUrl, LabelName, time);
  1080. }
  1081. if (OutBoxCombox.Text != "")
  1082. {
  1083. if (PrintMethod == "CodeSoft")
  1084. {
  1085. OutBoxDoc = lbl.Documents.Open(ftpOperater.DownLoadTo + OutBoxCombox.Text);
  1086. OutBoxDoc.Printer.SwitchTo(OutBoxPrinter.Text);
  1087. }
  1088. else
  1089. {
  1090. if (OutFormat != null)
  1091. {
  1092. OutFormat.Close(SaveOptions.DoNotSaveChanges);
  1093. }
  1094. OutFormat = engine.Documents.Open(ftpOperater.DownLoadTo + OutBoxCombox.Text);
  1095. OutFormat.PrintSetup.PrinterName = OutBoxPrinter.Text;
  1096. }
  1097. OutLabelParam = (DataTable)dh.ExecuteSql("select lp_name,lp_sql,lp_valuetype from label left join LABELPARAMETER on la_id= lp_laid where la_id=" + OutBoxCombox.SelectedValue.ToString().Split('#')[0], "select");
  1098. }
  1099. try
  1100. {
  1101. //打开空标签文件
  1102. if (EmptySingleFormat == null)
  1103. {
  1104. EmptySingleFormat = engine.Documents.Open(System.Windows.Forms.Application.StartupPath + @"\Empty.btw");
  1105. EmptySingleFormat.PrintSetup.PrinterName = SingleLabelPrinter.Text;
  1106. }
  1107. if (EmptyOutFormat == null)
  1108. {
  1109. EmptyOutFormat = engine.Documents.Open(System.Windows.Forms.Application.StartupPath + @"\Empty1.btw");
  1110. EmptyOutFormat.PrintSetup.PrinterName = OutBoxPrinter.Text;
  1111. }
  1112. }
  1113. catch (Exception)
  1114. {
  1115. }
  1116. //缓存外箱参数
  1117. ComBoxClickChangeLabelDoc = true;
  1118. }
  1119. bool InitGetLabel = true;
  1120. /// <summary>
  1121. /// 出入库单录入框的回车事件
  1122. /// </summary>
  1123. /// <param name="sender"></param>
  1124. /// <param name="e"></param>
  1125. private void pi_inoutno_KeyDown(object sender, KeyEventArgs e)
  1126. {
  1127. if (e.KeyCode == Keys.Enter)
  1128. {
  1129. sql.Clear();
  1130. sql.Append("select pi_id,pi_cardcode,pi_class,to_char(pi_date,'yyyymmdd')pi_date from prodinout where pi_inoutno='" + pi_inoutno.Text + "'");
  1131. dt = (DataTable)dh.ExecuteSql(sql.ToString(), "select");
  1132. if (dt.Rows.Count > 0)
  1133. {
  1134. InitGetLabel = true;
  1135. cu_code.Text = dt.Rows[0]["pi_cardcode"].ToString();
  1136. InitGetLabel = false;
  1137. pi_date.Text = dt.Rows[0]["pi_date"].ToString();
  1138. pi_class.Text = dt.Rows[0]["pi_class"].ToString();
  1139. PI_ID = dt.Rows[0]["pi_id"].ToString();
  1140. if (dh.GetConfig("AutoBarcode", "ProdInOut!Sale").ToString() != "")
  1141. {
  1142. string[] param = new string[] { PI_ID, "" };
  1143. dh.CallProcedure("GetCustBarcode", ref param);
  1144. }
  1145. if (dh.GetConfig("PassOrNeg", "FTPModel").ToString() != "Y")
  1146. {
  1147. FTPModel.Checked = false;
  1148. SystemInf.FTPModel = false;
  1149. }
  1150. else
  1151. {
  1152. FTPModel.Checked = true;
  1153. SystemInf.FTPModel = true;
  1154. }
  1155. CurrentItemIndex = 0;
  1156. CurrentRowIndex = 0;
  1157. LoadGridData(sender, e);
  1158. //重新输入单号后清除缓存
  1159. MidBoxArgument.Clear();
  1160. SingleBoxArgument.Clear();
  1161. MidIDAndOutboxcode.Clear();
  1162. SingleID.Clear();
  1163. //刷新采集进度
  1164. RefreshProcessData();
  1165. //设置当前的最大箱号
  1166. for (int i = 0; i < LabelInf.RowCount; i++)
  1167. {
  1168. string outboxcode = LabelInf.Rows[i].Cells["pib_outboxcode2"].Value.ToString();
  1169. //如果包含有-,则需要解析
  1170. if (outboxcode.Contains("-"))
  1171. if (int.Parse(outboxcode.Split('-')[0] == "" ? "1" : outboxcode.Split('-')[0]) > MaxOutBoxCode)
  1172. MaxOutBoxCode = int.Parse(outboxcode.Split('-')[0]);
  1173. //else
  1174. //if (int.Parse(outboxcode == "" ? "1" : outboxcode) > MaxOutBoxCode)
  1175. // MaxOutBoxCode = int.Parse(outboxcode);
  1176. }
  1177. thread = new Thread(GetInOutInfAndLabelFile);
  1178. stw = new SetLoadingWindow(thread, "正在获取打印标签");
  1179. BaseUtil.SetFormCenter(stw);
  1180. stw.ShowDialog();
  1181. LogicHandler.CustInit(PI_ID);
  1182. //重置采集项次
  1183. LogManager.DoLog("输入单号【" + pi_inoutno.Text + "】");
  1184. }
  1185. else
  1186. MessageBox.Show("当前出入库单号不存在!");
  1187. }
  1188. }
  1189. private void SingleBoxPrint()
  1190. {
  1191. if (SingleLabelParam.Rows.Count > 0 && LabelInf.Rows.Count > 0)
  1192. {
  1193. //每次打印清除之前缓存的行号和ID,后面会判断需要打印的数据重新加载
  1194. MidIDAndOutboxcode.Clear();
  1195. SingleID.Clear();
  1196. //获取全部的中盒号
  1197. Dictionary<string, bool> outboxcode1 = new Dictionary<string, bool>();
  1198. //判断所有盒号为该盒的是否勾选已采集
  1199. outboxcode1.Add(LabelInf.Rows[0].Cells["pib_outboxcode1"].Value.ToString(), true);
  1200. for (int i = 0; i < LabelInf.Rows.Count; i++)
  1201. {
  1202. if (!SingleID.Contains(LabelInf.Rows[i].Cells["pib_id1"].Value.ToString()))
  1203. SingleID.Add(LabelInf.Rows[i].Cells["pib_id1"].Value.ToString());
  1204. if (LabelInf.Rows[i].Cells["Choose"].FormattedValue.ToString() == "True" && LabelInf.Rows[i].Cells["pib_ifpick"].FormattedValue.ToString() == "True" && LabelInf.Rows[i].Cells["pib_ifprint"].FormattedValue.ToString() != "True")
  1205. {
  1206. //如果不存在中盒号则进行添加
  1207. if (!MidIDAndOutboxcode.ContainsValue(LabelInf.Rows[i].Cells["pib_outboxcode1"].Value.ToString()))
  1208. {
  1209. MidIDAndOutboxcode.Add(LabelInf.Rows[i].Cells["pib_id1"].Value.ToString(), LabelInf.Rows[i].Cells["pib_outboxcode1"].Value.ToString());
  1210. }
  1211. }
  1212. }
  1213. if (SingleID.ToArray().Length == 0)
  1214. {
  1215. MessageBox.Show("选择的行未勾选采集或者已打印");
  1216. return;
  1217. }
  1218. for (int i = 0; i < LabelInf.RowCount; i++)
  1219. {
  1220. if (i + 1 < LabelInf.RowCount)
  1221. {
  1222. //如果本行的中盒号和下一行不相等的话
  1223. if (LabelInf.Rows[i].Cells["pib_outboxcode1"].Value.ToString() != LabelInf.Rows[i + 1].Cells["pib_outboxcode1"].Value.ToString())
  1224. {
  1225. if (!outboxcode1.ContainsKey(LabelInf.Rows[i + 1].Cells["pib_outboxcode1"].Value.ToString()))
  1226. outboxcode1.Add(LabelInf.Rows[i + 1].Cells["pib_outboxcode1"].Value.ToString(), true);
  1227. }
  1228. }
  1229. //只要有一行没有采集满就不打印
  1230. if (LabelInf.Rows[i].Cells["pib_outboxcode1"].Value.ToString() == LabelInf.Rows[CurrentRowIndex].Cells["pib_outboxcode1"].Value.ToString())
  1231. {
  1232. if (LabelInf.Rows[i].Cells["pib_ifpick"].FormattedValue.ToString() != "True")
  1233. outboxcode1[LabelInf.Rows[i].Cells["pib_outboxcode1"].Value.ToString()] = false;
  1234. }
  1235. }
  1236. //用于判断用户是否勾选了行
  1237. int CheckedRowCount = 0;
  1238. string[] arg = SingleBoxArgument.ToArray();
  1239. for (int i = 0; i < LabelInf.RowCount; i++)
  1240. {
  1241. //勾选了并且未打印
  1242. if (LabelInf.Rows[i].Cells["Choose"].FormattedValue.ToString() == "True" && LabelInf.Rows[i].Cells["pib_ifpick"].FormattedValue.ToString() == "True" && LabelInf.Rows[i].Cells["pib_ifprint"].FormattedValue.ToString() != "True")
  1243. {
  1244. CheckedRowCount = CheckedRowCount + 1;
  1245. CurrentRowIndex = i;
  1246. //以标签模板的参数为基准,循环取数
  1247. try
  1248. {
  1249. string pib_id = LabelInf.Rows[i].Cells["pib_id1"].Value.ToString();
  1250. string outboxcode = LabelInf.Rows[i].Cells["pib_outboxcode2"].Value.ToString();
  1251. AutoPrintSingleLabel(pib_id, outboxcode);
  1252. if (MidLabelAutoPrint.Checked)
  1253. {
  1254. //判断当前行的盒号和下一行不相等或者已经是最后一行了
  1255. if (i + 1 == LabelInf.RowCount || LabelInf.Rows[i].Cells["pib_outboxcode1"].Value.ToString() != LabelInf.Rows[i + 1 == LabelInf.RowCount ? i : i + 1].Cells["pib_outboxcode1"].Value.ToString())
  1256. {
  1257. if (outboxcode1[LabelInf.Rows[i].Cells["pib_outboxcode1"].Value.ToString()])
  1258. {
  1259. if (MidLabelCombox.SelectedValue != null)
  1260. {
  1261. MidBoxCodePrint(CurrentRowIndex);
  1262. }
  1263. }
  1264. }
  1265. }
  1266. //勾选为已打印
  1267. LabelInf.Rows[i].Cells["pib_ifprint"].Value = true;
  1268. sdh.ExecuteSql("update prodiobarcode set pib_ifprint=-1 where pib_id='" + pib_id + "'", "update");
  1269. }
  1270. catch (Exception ex) { LogManager.DoLog(ex.Message); }
  1271. }
  1272. }
  1273. Last_OutboxCode = "";
  1274. dh.BatchInsert("update prodiobarcode set pib_printdate=sysdate where pib_id=:pib_id", new string[] { "pib_id" }, SingleID.ToArray());
  1275. if (CheckedRowCount == 0)
  1276. MessageBox.Show("未勾选打印明细!");
  1277. else if (CurrentRowIndex + 1 < LabelInf.Rows.Count)
  1278. CurrentRowIndex = CurrentRowIndex + 1;
  1279. outboxcode1.Clear();
  1280. }
  1281. else
  1282. {
  1283. MessageBox.Show("此模板尚未维护参数或不存在打印明细");
  1284. return;
  1285. }
  1286. }
  1287. private void SingleLabelPrint_Click(object sender, EventArgs e)
  1288. {
  1289. if (SingleLabelCombox.Text != "")
  1290. {
  1291. if (SingleBoxBegin.Text != "" || SingleBoxEnd.Text != "")
  1292. {
  1293. try
  1294. {
  1295. int begin = int.Parse(SingleBoxBegin.Text == "" ? "1" : SingleBoxBegin.Text);
  1296. int end = int.Parse(SingleBoxEnd.Text == "" ? LabelInf.Rows.Count.ToString() : SingleBoxEnd.Text);
  1297. if (begin > 0 && end <= LabelInf.Rows.Count && begin <= end)
  1298. {
  1299. for (int i = begin - 1; i < end; i++)
  1300. {
  1301. LabelInf.Rows[i].Cells["Choose"].Value = true;
  1302. LabelInf.Rows[i].Cells["pib_ifpick"].Value = true;
  1303. LabelInf.Rows[i].Cells["pib_ifprint"].Value = false;
  1304. }
  1305. }
  1306. else
  1307. {
  1308. MessageBox.Show("单盘打印范围错误");
  1309. return;
  1310. }
  1311. LabelInf.Invalidate();
  1312. }
  1313. catch (Exception)
  1314. {
  1315. MessageBox.Show("单盘打印范围错误");
  1316. return;
  1317. }
  1318. }
  1319. thread = new Thread(SingleBoxPrint);
  1320. stw = new SetLoadingWindow(thread, "正在打印单盘");
  1321. BaseUtil.SetFormCenter(stw);
  1322. stw.ShowDialog();
  1323. }
  1324. else
  1325. MessageBox.Show("未维护单盘标签");
  1326. }
  1327. private void MidBoxLabelPrint()
  1328. {
  1329. if (MidLabelNum.Text == "")
  1330. {
  1331. int begin = 0;
  1332. int end = 0;
  1333. if (MidBoxBegin.Text != "" || MidBoxEnd.Text != "")
  1334. {
  1335. try
  1336. {
  1337. begin = int.Parse(MidBoxBegin.Text == "" ? "1" : MidBoxBegin.Text);
  1338. end = int.Parse(MidBoxEnd.Text == "" ? LabelInf.Rows[LabelInf.Rows.Count - 1].Cells["pib_outboxcode1"].Value.ToString() : MidBoxEnd.Text);
  1339. int minmidbox = int.Parse(LabelInf.Rows[0].Cells["pib_outboxcode1"].Value.ToString());
  1340. int maxmidbox = int.Parse(LabelInf.Rows[LabelInf.Rows.Count - 1].Cells["pib_outboxcode1"].Value.ToString());
  1341. if (begin >= minmidbox && end <= maxmidbox && begin <= end)
  1342. {
  1343. //设置中盒打印范围的行号
  1344. for (int i = 0; i < LabelInf.Rows.Count; i++)
  1345. {
  1346. string outboxcode1 = LabelInf.Rows[i].Cells["pib_outboxcode1"].Value.ToString();
  1347. if (outboxcode1 != "")
  1348. {
  1349. if (int.Parse(outboxcode1) == begin)
  1350. {
  1351. begin = i;
  1352. }
  1353. if (int.Parse(outboxcode1) == end)
  1354. {
  1355. end = i;
  1356. }
  1357. }
  1358. }
  1359. }
  1360. else
  1361. {
  1362. MessageBox.Show("中盒打印范围错误");
  1363. return;
  1364. }
  1365. }
  1366. catch (Exception)
  1367. {
  1368. MessageBox.Show("中盒打印范围错误");
  1369. return;
  1370. }
  1371. }
  1372. else
  1373. {
  1374. end = LabelInf.Rows.Count - 1;
  1375. }
  1376. MidBoxArgument.Clear();
  1377. List<int> MidOutBoxCode = new List<int>();
  1378. List<int> MidOutBoxCodeIndex = new List<int>();
  1379. for (int i = (begin == 0 ? 0 : begin); i <= (end); i++)
  1380. {
  1381. string outboxcode1 = LabelInf.Rows[i].Cells["pib_outboxcode1"].Value.ToString();
  1382. if (outboxcode1 != "")
  1383. {
  1384. if (!MidIDAndOutboxcode.ContainsValue(outboxcode1))
  1385. MidIDAndOutboxcode.Add(LabelInf.Rows[i].Cells["pib_id1"].Value.ToString(), outboxcode1);
  1386. if (!MidOutBoxCode.Contains(int.Parse(outboxcode1)))
  1387. {
  1388. MidOutBoxCode.Add(int.Parse(outboxcode1));
  1389. MidOutBoxCodeIndex.Add(i);
  1390. }
  1391. }
  1392. }
  1393. for (int i = 0; i < MidOutBoxCodeIndex.Count; i++)
  1394. {
  1395. MidBoxCodePrint(MidOutBoxCodeIndex[i]);
  1396. }
  1397. MidBoxArgument.Clear();
  1398. return;
  1399. }
  1400. bool FindMidLabel = false;
  1401. if (MidLabelCombox.SelectedValue != null)
  1402. {
  1403. //中盒号所在的行
  1404. int MidLabelRowIndex = 0;
  1405. //查找是否存在该中盒号
  1406. List<int> MidRowIndex = new List<int>();
  1407. //缓存中盒数据
  1408. for (int i = 0; i < LabelInf.RowCount; i++)
  1409. {
  1410. if (MidLabelNum.Text == LabelInf.Rows[i].Cells["pib_outboxcode1"].Value.ToString())
  1411. {
  1412. //找到了输入的中盒号停止循环
  1413. FindMidLabel = true;
  1414. MidLabelRowIndex = i;
  1415. MidRowIndex.Add(i);
  1416. }
  1417. }
  1418. //找到了指定的盒号
  1419. if (FindMidLabel)
  1420. MidBoxCodePrint(MidLabelRowIndex);
  1421. else
  1422. MessageBox.Show("该出入库单未找到该中盒号!");
  1423. }
  1424. else
  1425. MessageBox.Show("未维护中盒模板");
  1426. }
  1427. int MaxNum = 0;
  1428. int NumLength = 0;
  1429. private void PackMidBox_Click(object sender, EventArgs e)
  1430. {
  1431. 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");
  1432. GetBarCodeRule(out Prefix, out Suffix, out MaxNum, out NumLength, out Radix, 1);
  1433. if (Radix > 0)
  1434. {
  1435. //生成中盒条码
  1436. int pib_outboxcode1 = int.Parse(dh.getFieldDataByCondition("prodiobarcode", "max(to_number(nvl(pib_outboxcode1,0)))", "pib_inoutno='" + pi_inoutno.Text + "'").ToString())+1;
  1437. List<string> MidBoxCode = new List<string>();
  1438. List<string> PIBID = new List<string>();
  1439. List<string> PIBOUTBOXCODE1 = new List<string>();
  1440. MaxNum = MaxNum - 1;
  1441. for (int i = 0; i < LabelInf.Rows.Count; i++)
  1442. {
  1443. if (LabelInf.Rows[i].Cells["pib_ifpick"].FormattedValue.ToString() == "True" && LabelInf.Rows[i].Cells["pib_custmidboxcode"].Value.ToString() == "")
  1444. {
  1445. string serialcode = BaseUtil.DToAny(MaxNum, Radix);
  1446. for (int k = serialcode.ToString().Length; k < NumLength; k++)
  1447. {
  1448. serialcode = "0" + serialcode;
  1449. }
  1450. MidBoxCode.Add(Prefix + serialcode + Suffix);
  1451. PIBID.Add(LabelInf.Rows[i].Cells["pib_id1"].Value.ToString());
  1452. PIBOUTBOXCODE1.Add(pib_outboxcode1.ToString());
  1453. }
  1454. }
  1455. dh.BatchInsert("update prodiobarcode set pib_custmidboxcode=:pib_custmidboxcode,pib_outboxcode1=:pib_outboxcode1,pib_ifpick=-1 where pib_id=:pib_id and pib_custmidboxcode is null", new string[] { "pib_custmidboxcode", "pib_outboxcode1", "pib_id" }, MidBoxCode.ToArray(), PIBOUTBOXCODE1.ToArray(), PIBID.ToArray());
  1456. MidLabelNum.Text = "";
  1457. }
  1458. LoadGridData(sender, e);
  1459. }
  1460. private void MidLabelPrint_Click(object sender, EventArgs e)
  1461. {
  1462. if (MidLabelCombox.Text != "")
  1463. {
  1464. PackMidBox_Click(sender, e);
  1465. thread = new Thread(MidBoxLabelPrint);
  1466. stw = new SetLoadingWindow(thread, "正在打印中盒");
  1467. BaseUtil.SetFormCenter(stw);
  1468. stw.ShowDialog();
  1469. }
  1470. else
  1471. MessageBox.Show("未维护中盒标签");
  1472. }
  1473. private void OutBoxPrint()
  1474. {
  1475. List<string> Outboxcode = new List<string>();
  1476. //如果未勾选箱号则对勾选的数据的箱号进行整合
  1477. if (OutBoxNum.Text == "")
  1478. {
  1479. for (int i = 0; i < LabelInf.RowCount; i++)
  1480. {
  1481. if (LabelInf.Rows[i].Cells["Choose"].FormattedValue.ToString() == "True")
  1482. {
  1483. string outboxcode2 = LabelInf.Rows[i].Cells["pib_outboxcode2"].Value.ToString();
  1484. //富为使用包装单的逻辑
  1485. //如果不包含该箱号则进行添加
  1486. if (!Outboxcode.Contains(outboxcode2))
  1487. Outboxcode.Add(outboxcode2);
  1488. }
  1489. }
  1490. //按获取到的箱号列表进行打印
  1491. if (Outboxcode.ToArray().Length > 0)
  1492. {
  1493. try
  1494. {
  1495. // 循环打印外箱号
  1496. for (int i = 0; i < Outboxcode.ToArray().Length; i++)
  1497. {
  1498. for (int h = 0; h < LabelInf.RowCount; h++)
  1499. {
  1500. if (LabelInf.Rows[h].Cells["pib_outboxcode2"].Value.ToString() == Outboxcode.ToArray()[i])
  1501. {
  1502. OutBoxCodePrint(h);
  1503. break;
  1504. }
  1505. }
  1506. }
  1507. }
  1508. catch { }
  1509. }
  1510. else
  1511. {
  1512. MessageBox.Show("请勾选需要打印的外箱");
  1513. }
  1514. }
  1515. else
  1516. {
  1517. bool FindMidLabel = false;
  1518. try
  1519. {
  1520. int OutBoxLabelRowIndex = 0;
  1521. //查找是否存在该中盒号
  1522. for (int i = 0; i < LabelInf.RowCount; i++)
  1523. {
  1524. if (OutBoxNum.Text == LabelInf.Rows[i].Cells["pib_outboxcode2"].Value.ToString())
  1525. {
  1526. //找到了输入的中盒号停止循环
  1527. FindMidLabel = true;
  1528. OutBoxLabelRowIndex = i;
  1529. break;
  1530. }
  1531. }
  1532. //找到了指定的盒号
  1533. if (FindMidLabel)
  1534. OutBoxCodePrint(OutBoxLabelRowIndex);
  1535. else
  1536. MessageBox.Show("该出入库单未找到该外箱号!");
  1537. }
  1538. catch (Exception) { }
  1539. }
  1540. Outboxcode.Clear();
  1541. }
  1542. private void MidBoxCodePrint(int rowindex)
  1543. {
  1544. //获取对应行的pib_id
  1545. string pib_id = LabelInf.Rows[rowindex].Cells["pib_id1"].Value.ToString();
  1546. string pib_outboxcode1 = LabelInf.Rows[rowindex].Cells["pib_outboxcode1"].Value.ToString();
  1547. if (PrintMethod == "CodeSoft")
  1548. {
  1549. Print.CodeSoft.MidPrint(MidDoc, MidLabelParam, pi_inoutno.Text, pib_id, pib_outboxcode1);
  1550. }
  1551. else
  1552. {
  1553. Print.BarTender.MidPrint(MidFormat, MidLabelParam, pi_inoutno.Text, pib_id, pib_outboxcode1);
  1554. MidFormat.PrintSetup.PrinterName = MidLabelPrinter.Text;
  1555. }
  1556. }
  1557. private void OutBoxCodePrint(int rowindex)
  1558. {
  1559. //获取对应行的pib_id
  1560. string pib_id = LabelInf.Rows[rowindex].Cells["pib_id1"].Value.ToString();
  1561. string pib_outboxcode2 = LabelInf.Rows[rowindex].Cells["pib_outboxcode2"].Value.ToString();
  1562. if (PrintMethod == "CodeSoft")
  1563. Print.CodeSoft.OutPrint(OutBoxDoc, OutLabelParam, pi_inoutno.Text, pib_id, pib_outboxcode2, cu_print_outprod.Checked, cu_print_outpo.Checked, cu_print_outdc.Checked, cu_print_outlotno.Checked, cu_print_ordercode.Checked);
  1564. else
  1565. {
  1566. if (DiffCustOutBoxCode.Checked)
  1567. {
  1568. //执行本地SQL,获取需要更新的DataCode
  1569. DataTable dt = (DataTable)sdh.ExecuteSql(BaseUtil.GetOutBoxSQL(OutFormat, OutLabelParam, pi_inoutno.Text, pib_id, pib_outboxcode2, cu_print_outprod.Checked, cu_print_outpo.Checked, cu_print_outdc.Checked, cu_print_outlotno.Checked, cu_print_ordercode.Checked), "select");
  1570. //大于1行表示有需要分组的数据
  1571. if (dt.Rows.Count > 1)
  1572. {
  1573. for (int i = 0; i < dt.Rows.Count; i++)
  1574. {
  1575. GetCustRule();
  1576. string custoutboxcode = LogicHandler.BarcodeMethod1(Prefix, Suffix, SerialNumIndex, SerialNumLength, Radix);
  1577. string updateCondition = "";
  1578. //勾选了这些参数并且打印的时候需要才进行更新
  1579. if (cu_print_outprod.Checked && dt.Columns.Contains("pd_custprodcode"))
  1580. {
  1581. updateCondition += " and pd_custprodcode='" + dt.Rows[i]["pd_custprodcode"].ToString() + "'";
  1582. }
  1583. if (cu_print_outpo.Checked && dt.Columns.Contains("pd_pocode"))
  1584. {
  1585. updateCondition += " and pd_pocode='" + dt.Rows[i]["pd_pocode"].ToString() + "'";
  1586. }
  1587. if (cu_print_ordercode.Checked && dt.Columns.Contains("pd_ordercode"))
  1588. {
  1589. updateCondition += " and pd_ordercode='" + dt.Rows[i]["pd_ordercode"].ToString() + "'";
  1590. }
  1591. if (cu_print_outdc.Checked && dt.Columns.Contains("pib_datecode"))
  1592. {
  1593. updateCondition += " and pib_datecode='" + dt.Rows[i]["pib_datecode"].ToString() + "'";
  1594. }
  1595. if (cu_print_outlotno.Checked && dt.Columns.Contains("pib_lotno"))
  1596. {
  1597. updateCondition += " and pib_lotno='" + dt.Rows[i]["pib_lotno"].ToString() + "'";
  1598. }
  1599. try
  1600. {
  1601. dh.ExecuteSql("update prodiobarcode set pib_custoutboxcode='" + custoutboxcode + "' where pib_id in(select pib_id from prodiobarcode left join prodinout on pib_inoutno=pi_inoutno left join prodiodetail on pd_piid=pi_id and pib_prodcode=pd_prodcode where pib_inoutno='" + pi_inoutno.Text + "' and pib_outboxcode2='" + pib_outboxcode2 + "' " + updateCondition + " )", "update");
  1602. LogicHandler.SP_OUTCUSTBARCODE(pi_inoutno.Text, "and pib_outboxcode2='" + pib_outboxcode2 + "' " + updateCondition + " ");
  1603. dh.UpdateByCondition("RuleMaxNum", "rmn_maxnumber='" + custserialnum + "'", "rmn_nrcode='" + NrCode + "' and rmn_prefix='" + Prefix + "'");
  1604. }
  1605. catch (Exception ex)
  1606. {
  1607. Console.WriteLine(ex.Message + ex.StackTrace);
  1608. throw;
  1609. }
  1610. }
  1611. }
  1612. }
  1613. LoadGridData(true);
  1614. Print.BarTender.OutPrint(OutFormat, OutLabelParam, pi_inoutno.Text, pib_id, pib_outboxcode2, cu_print_outprod.Checked, cu_print_outpo.Checked, cu_print_outdc.Checked, cu_print_outlotno.Checked, cu_print_ordercode.Checked);
  1615. if (LabelSpace.Checked)
  1616. {
  1617. Print.BarTender.OutPrint(EmptyOutFormat, OutLabelParam, pi_inoutno.Text, pib_id, "-1", cu_print_outprod.Checked, cu_print_outpo.Checked, cu_print_outdc.Checked, cu_print_outlotno.Checked, cu_print_ordercode.Checked);
  1618. }
  1619. }
  1620. }
  1621. private void CleanDetail_Click(object sender, EventArgs e)
  1622. {
  1623. ArrayList<string> DeleteID = new ArrayList<string>();
  1624. StringBuilder pibid = new StringBuilder();
  1625. for (int i = 0; i < LabelInf.RowCount; i++)
  1626. {
  1627. if (LabelInf.Rows[i].Cells["Choose"].FormattedValue.ToString() == "True")
  1628. {
  1629. DeleteID.Add(LabelInf.Rows[i].Cells["pib_id1"].Value.ToString());
  1630. pibid.Append(LabelInf.Rows[i].Cells["pib_id1"].Value.ToString() + ",");
  1631. }
  1632. }
  1633. //勾选了删除的明细之后
  1634. if (DeleteID.ToArray().Length > 0)
  1635. {
  1636. string close = MessageBox.Show(this.ParentForm, "删除后不可恢复,是否确认删除", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question).ToString();
  1637. if (close.ToString() == "Yes")
  1638. {
  1639. pibid.Append("1");
  1640. sdh.ExecuteSql("delete from prodiobarcode where pib_id in(" + pibid + ")", "delete");
  1641. dh.BatchInsert("delete from prodiobarcode where pib_id=:pib_id", new string[] { "pib_id" }, DeleteID.ToArray());
  1642. MessageBox.Show("删除成功");
  1643. LoadGridData(sender, e);
  1644. RefreshProcessData();
  1645. }
  1646. }
  1647. else
  1648. MessageBox.Show("尚未勾选需要删除的明细");
  1649. }
  1650. private void OutBoxLabelPrint_Click(object sender, EventArgs e)
  1651. {
  1652. if (OutBoxCombox.Text != "")
  1653. {
  1654. thread = new Thread(OutBoxPrint);
  1655. stw = new SetLoadingWindow(thread, "正在打印外箱");
  1656. BaseUtil.SetFormCenter(stw);
  1657. stw.ShowDialog();
  1658. }
  1659. else
  1660. MessageBox.Show("未维护外箱标签");
  1661. }
  1662. /// <summary>
  1663. /// 刷新采集进度
  1664. /// </summary>
  1665. private void RefreshProcessData()
  1666. {
  1667. if (LabelInf.Rows.Count > 0)
  1668. {
  1669. //设置初始化的采集进度
  1670. int Count = 0;
  1671. int CurrentMidBoxCollectedCount = 0;
  1672. //当前盒号的总盘数
  1673. int CurrentMidBoxTotalCount = 0;
  1674. //未超出当前范围的时候
  1675. for (int i = 0; i < LabelInf.RowCount; i++)
  1676. {
  1677. if (LabelInf.Rows[i].Cells["pib_ifpick"].FormattedValue.ToString() == "True")
  1678. Count++;
  1679. //和当前编辑箱号相等行
  1680. if (LabelInf.Rows[i].Cells["pib_ifpick"].FormattedValue.ToString() == "True" && LabelInf.Rows[CurrentRowIndex].Cells["pib_outboxcode1"].Value.ToString() == LabelInf.Rows[i].Cells["pib_outboxcode1"].Value.ToString())
  1681. CurrentMidBoxCollectedCount++;
  1682. //当前盒号一共有几盘
  1683. if (LabelInf.Rows[CurrentRowIndex].Cells["pib_outboxcode1"].Value.ToString() == LabelInf.Rows[i].Cells["pib_outboxcode1"].Value.ToString())
  1684. CurrentMidBoxTotalCount++;
  1685. }
  1686. Capacity.Text = "可装" + CurrentMidBoxTotalCount + "盘";
  1687. Installed.Text = "已装" + CurrentMidBoxCollectedCount + "盘";
  1688. //设置当前的箱号和盒号
  1689. Process_outboxcode.Text = LabelInf.Rows[CurrentRowIndex].Cells["pib_outboxcode2"].Value.ToString();
  1690. Process_midboxcode.Text = LabelInf.Rows[CurrentRowIndex].Cells["pib_outboxcode1"].Value.ToString();
  1691. //设置当前总数和已采集数量
  1692. TotalCount.Text = LabelInf.RowCount.ToString();
  1693. CollectedCount.Text = Count.ToString();
  1694. }
  1695. }
  1696. private void LoadGridData(bool AllCollect)
  1697. {
  1698. LoadGridData(AllCollect, new EventArgs());
  1699. }
  1700. DataTable LabelInfDataTable;
  1701. /// <summary>
  1702. /// 自定义函数 加载明细行的数据,多处使用添加进函数
  1703. /// </summary>
  1704. /// <param name="sender"></param>
  1705. /// <param name="e"></param>
  1706. private void LoadGridData(object sender, EventArgs e)
  1707. {
  1708. AllCollect = sender.Equals(true);
  1709. //查询Oracle数据库
  1710. sql.Clear();
  1711. sql.Append("select t.*,rownum from prodiobarcode_view t where pib_inoutno='" + pi_inoutno.Text + "' order by PIB_OUTBOXCODE1,pib_custbarcode");
  1712. LabelInfDataTable = (DataTable)dh.ExecuteSql(sql.ToString(), "select");
  1713. //查询本地数据库
  1714. sql.Clear();
  1715. sql.Append("select count(1) from prodiobarcode where pib_inoutno='" + pi_inoutno.Text + "'");
  1716. DataTable dt = (DataTable)sdh.ExecuteSql(sql.ToString(), "select");
  1717. int rowcount = int.Parse(dt.Rows[0][0].ToString());
  1718. //如果本地没有缓存过
  1719. if (rowcount == 0 || rowcount != LabelInfDataTable.Rows.Count)
  1720. {
  1721. if (rowcount != LabelInfDataTable.Rows.Count && rowcount != 0)
  1722. {
  1723. string close = MessageBox.Show(this.ParentForm, "本地条码和服务器条码数量不一致,覆盖本地条码", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question).ToString();
  1724. if (close == "Yes")
  1725. {
  1726. sdh.ExecuteSql("delete from prodiobarcode where pib_inoutno='" + pi_inoutno.Text + "'", "delete");
  1727. //检验查询的字段和本地数据库字段是否匹配
  1728. sdh.AddColumFromDataTable(LabelInfDataTable, "prodiobarcode");
  1729. //将数据保存在本地数据库
  1730. sdh.SaveDataTable(LabelInfDataTable, "prodiobarcode");
  1731. }
  1732. }
  1733. else
  1734. {
  1735. //检验查询的字段和本地数据库字段是否匹配
  1736. sdh.AddColumFromDataTable(LabelInfDataTable, "prodiobarcode");
  1737. //将数据保存在本地数据库
  1738. sdh.SaveDataTable(LabelInfDataTable, "prodiobarcode");
  1739. }
  1740. }
  1741. else if (LabelInfDataTable.Columns.Count != dt.Columns.Count)
  1742. {
  1743. //检验查询的字段和本地数据库字段是否匹配
  1744. sdh.AddColumFromDataTable(LabelInfDataTable, "prodiobarcode");
  1745. sdh.ExecuteSql("delete from prodiobarcode where pib_inoutno='" + pi_inoutno.Text + "'", "delete");
  1746. sdh.SaveDataTable(LabelInfDataTable, "prodiobarcode");
  1747. //sdh.BatchInsert("prodiobarcode", LabelInfDataTable);
  1748. }
  1749. sql.Clear();
  1750. sql.Append("select * from prodiobarcode where pib_inoutno='" + pi_inoutno.Text + "' order by pib_custbarcode,PIB_OUTBOXCODE1");
  1751. LabelInfDataTable = (DataTable)sdh.ExecuteSql(sql.ToString(), "select");
  1752. bindingsource(LabelInf, LabelInfDataTable);
  1753. //有数据的话默认取第一条的品牌去取采集策略
  1754. TotalCount.Text = LabelInf.RowCount.ToString();
  1755. if (LabelInf.RowCount > 0)
  1756. {
  1757. Brand = LabelInf.Rows[0].Cells["pib_brand"].FormattedValue.ToString();
  1758. if (Brand != "")
  1759. sg_code.Text = dh.getFieldDataByCondition("scangroup", "sg_code", "sg_brand='" + Brand + "'").ToString();
  1760. SetOutBoxCapacity(LabelInf.Rows[0].Cells["pib_prodcode"].Value.ToString());
  1761. }
  1762. //绑定数据之后往下找到未采集的数据显示在当前采集的栏目
  1763. for (int i = 0; i < LabelInf.RowCount; i++)
  1764. {
  1765. if (LabelInf.Rows[i].Cells["pib_ifpick"].FormattedValue.ToString() != "True")
  1766. {
  1767. griddetno.Text = LabelInf.Rows[i].Cells["pib_pdno"].FormattedValue.ToString();
  1768. pr_code.Text = LabelInf.Rows[i].Cells["pib_prodcode"].FormattedValue.ToString();
  1769. pib_id.Text = LabelInf.Rows[i].Cells["pib_id1"].FormattedValue.ToString();
  1770. CurrentRowIndex = LabelInf.Rows[i].Cells["pib_prodcode"].RowIndex;
  1771. break;
  1772. }
  1773. }
  1774. }
  1775. delegate void BindDataSource(DataGridView dgv, DataTable dt);//定义委托
  1776. void bindingsource(DataGridView dgv, DataTable dt)
  1777. {
  1778. if (dgv.InvokeRequired)
  1779. {
  1780. dgv.Invoke(new BindDataSource(bindingsource), new object[] { dgv, dt });
  1781. }
  1782. else
  1783. {
  1784. dgv.AutoGenerateColumns = false;
  1785. dgv.DataSource = dt;
  1786. }
  1787. }
  1788. /// <summary>
  1789. /// 重绘Cell的颜色
  1790. /// </summary>
  1791. /// <param name="sender"></param>
  1792. /// <param name="e"></param>
  1793. private void LabelInf_CellPainting(object sender, DataGridViewCellPaintingEventArgs e)
  1794. {
  1795. bool mouseOver = e.CellBounds.Contains(this.PointToClient(Cursor.Position));
  1796. if (e.ColumnIndex > 0)
  1797. {
  1798. if (LabelInf.Columns[e.ColumnIndex].Name == "pib_madein" || LabelInf.Columns[e.ColumnIndex].Name == "pib_lotno" || LabelInf.Columns[e.ColumnIndex].Name == "pib_datecode" || LabelInf.Columns[e.ColumnIndex].Name == "pib_outboxcode1" || LabelInf.Columns[e.ColumnIndex].Name == "pib_outboxcode2" || LabelInf.Columns[e.ColumnIndex].Name == "pr_brand")
  1799. {
  1800. SolidBrush solidBrush = new SolidBrush(Color.FromArgb(51, 153, 255));
  1801. e.Graphics.FillRectangle(mouseOver ? solidBrush : Brushes.LightSeaGreen, e.CellBounds);
  1802. Rectangle border = e.CellBounds;
  1803. border.Width -= 1;
  1804. e.Graphics.DrawRectangle(Pens.White, border);
  1805. e.PaintContent(e.CellBounds);
  1806. e.Handled = true;
  1807. }
  1808. if (e.RowIndex >= 0)
  1809. {
  1810. if (LabelInf.Rows[e.RowIndex].Cells["pib_ifpick"].FormattedValue.ToString() == "True")
  1811. {
  1812. if (LabelInf.Columns[e.ColumnIndex].Name == "pib_lotno" || LabelInf.Columns[e.ColumnIndex].Name == "pib_datecode")
  1813. {
  1814. SolidBrush solidBrush = new SolidBrush(Color.FromArgb(51, 153, 255));
  1815. e.Graphics.FillRectangle(Brushes.ForestGreen, e.CellBounds);
  1816. Rectangle border = e.CellBounds;
  1817. border.Width -= 1;
  1818. e.Graphics.DrawRectangle(Pens.Black, border);
  1819. e.PaintContent(e.CellBounds);
  1820. e.Handled = true;
  1821. }
  1822. }
  1823. }
  1824. }
  1825. }
  1826. private void pr_code_SearchIconClick(object sender, EventArgs e)
  1827. {
  1828. pr_code.Condition = " pd_inoutno='" + pi_inoutno.Text + "'";
  1829. }
  1830. private void pr_code_UserControlTextChanged(object sender, EventArgs e)
  1831. {
  1832. //用户在重新勾选后重置采集项目的索引
  1833. CurrentItemIndex = 0;
  1834. for (int i = 0; i < LabelInf.RowCount; i++)
  1835. {
  1836. if (pr_code.Text == LabelInf.Rows[i].Cells["pib_prodcode"].Value.ToString() && LabelInf.Rows[i].Cells["pib_ifpick"].FormattedValue.ToString() != "True")
  1837. {
  1838. CurrentRowIndex = i;
  1839. break;
  1840. }
  1841. }
  1842. }
  1843. private void Refresh_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
  1844. {
  1845. KeyEventArgs e2 = new KeyEventArgs(Keys.Enter);
  1846. pi_inoutno_KeyDown(sender, e2);
  1847. }
  1848. /// <summary>
  1849. /// 采集明细切换
  1850. /// </summary>
  1851. /// <param name="sender"></param>
  1852. /// <param name="e"></param>
  1853. private void griddetno_KeyDown(object sender, KeyEventArgs e)
  1854. {
  1855. if (Keys.Enter == e.KeyData)
  1856. {
  1857. bool FindDetno = false;
  1858. for (int i = 0; i < LabelInf.RowCount; i++)
  1859. {
  1860. if (LabelInf.Rows[i].Cells["pib_pdno"].Value.ToString() == griddetno.Text && LabelInf.Rows[i].Cells["pib_ifpick"].FormattedValue.ToString() != "True")
  1861. {
  1862. FindDetno = true;
  1863. CurrentItemIndex = 0;
  1864. CurrentRowIndex = i;
  1865. RemindUser();
  1866. break;
  1867. }
  1868. }
  1869. if (!FindDetno)
  1870. {
  1871. MessageBox.Show("不存在未采集的明细序号" + griddetno.Text);
  1872. return;
  1873. }
  1874. }
  1875. }
  1876. private void AutoPrintMidLabel()
  1877. {
  1878. bool FullBox = true;
  1879. //判断所有盒号未该盒的是否勾选已采集
  1880. for (int i = 0; i < LabelInf.RowCount; i++)
  1881. {
  1882. if (LabelInf.Rows[i].Cells["pib_outboxcode1"].Value.ToString() == LabelInf.Rows[CurrentRowIndex].Cells["pib_outboxcode1"].Value.ToString())
  1883. {
  1884. if (LabelInf.Rows[i].Cells["pib_ifpick"].FormattedValue.ToString() != "True")
  1885. FullBox = false;
  1886. }
  1887. }
  1888. //如果当前箱号已经装满了
  1889. if (FullBox)
  1890. {
  1891. if (MidLabelCombox.SelectedValue != null)
  1892. {
  1893. MidBoxCodePrint(CurrentRowIndex);
  1894. }
  1895. else
  1896. MessageBox.Show("未维护中盒模板");
  1897. }
  1898. }
  1899. /// <summary>
  1900. /// 勾选的时候自动打印
  1901. /// </summary>
  1902. /// <param name="sender"></param>
  1903. /// <param name="e"></param>
  1904. private void LabelInf_CellValueChanged(object sender, DataGridViewCellEventArgs e)
  1905. {
  1906. if (LabelInf.Columns[e.ColumnIndex].Name == "pib_datecode")
  1907. {
  1908. string datecode = LabelInf.Rows[e.RowIndex].Cells["pib_datecode"].Value.ToString();
  1909. try
  1910. {
  1911. System.DateTime dt = System.DateTime.ParseExact(datecode, "yyyyMMdd", CultureInfo.CurrentCulture);
  1912. GregorianCalendar gc = new GregorianCalendar();
  1913. int weekOfYear = gc.GetWeekOfYear(dt, CalendarWeekRule.FirstDay, DayOfWeek.Monday);
  1914. if (weekOfYear < 10)
  1915. LabelInf.Rows[e.RowIndex].Cells["pib_datecode1"].Value = dt.Year.ToString().Substring(2, 2) + "0" + weekOfYear;
  1916. else
  1917. LabelInf.Rows[e.RowIndex].Cells["pib_datecode1"].Value = dt.Year.ToString().Substring(2, 2) + weekOfYear;
  1918. }
  1919. catch (Exception) { }
  1920. }
  1921. }
  1922. private void AllCollected_Click(object sender, EventArgs e)
  1923. {
  1924. if (AllCollect == false)
  1925. {
  1926. foreach (DataGridViewRow dr in LabelInf.Rows)
  1927. dr.Cells[1].Value = true;
  1928. AllCollect = true;
  1929. }
  1930. else
  1931. {
  1932. foreach (DataGridViewRow dr in LabelInf.Rows)
  1933. dr.Cells[1].Value = false;
  1934. AllCollect = false;
  1935. }
  1936. }
  1937. private void GetOutBoxCode_Click(object sender, EventArgs e)
  1938. {
  1939. if (dh.GetConfig("UsingPacking", "ProdInOut!Sale").ToString() != "")
  1940. {
  1941. int Current = 0;
  1942. sql.Clear();
  1943. sql.Append("select pr_qtyperplace,pd_qty,packingdetail.pd_cartonno,pr_zxbzs,packingdetail.pd_cartons from packingdetail left join packing on pd_piid=pi_id left join prodinout on ");
  1944. sql.Append("pi_packingcode=packing.pi_code left join product on pd_prodcode=pr_code where pi_inoutno='" + pi_inoutno.Text + "' order by pr_code,pd_detno");
  1945. dt = (DataTable)dh.ExecuteSql(sql.ToString(), "select");
  1946. if (dt.Rows.Count > 0)
  1947. {
  1948. try { OutboxCapacity.Value = (decimal)dt.Rows[0]["pr_qtyperplace"] / (decimal)dt.Rows[0]["pr_zxbzs"]; }
  1949. catch (Exception) { }
  1950. }
  1951. try
  1952. {
  1953. for (int i = 0; i < dt.Rows.Count; i++)
  1954. {
  1955. int pd_qty = int.Parse(dt.Rows[i]["pd_qty"].ToString());
  1956. int pr_zxbzs = int.Parse(dt.Rows[i]["pr_zxbzs"].ToString());
  1957. int pd_cartons = int.Parse(dt.Rows[i]["pd_cartons"].ToString());
  1958. for (int j = 0; j < pd_qty * pd_cartons / pr_zxbzs; j++)
  1959. {
  1960. LabelInf.Rows[Current].Cells["pib_outboxcode2"].Value = dt.Rows[i]["pd_cartonno"].ToString();
  1961. Current++;
  1962. }
  1963. }
  1964. GetPackingCode = true;
  1965. }
  1966. catch (Exception)
  1967. {
  1968. }
  1969. }
  1970. else
  1971. {
  1972. int BoxCode = 1;
  1973. for (int i = 0; i < LabelInf.Rows.Count; i++)
  1974. {
  1975. LabelInf.Rows[i].Cells["pib_outboxcode2"].Value = BoxCode;
  1976. if (i + 1 < LabelInf.Rows.Count)
  1977. {
  1978. if (int.Parse(LabelInf.Rows[i].Cells["pib_outboxcode1"].Value.ToString()) % OutboxCapacity.Value == 0 && (LabelInf.Rows[i].Cells["pib_outboxcode1"].Value.ToString() != LabelInf.Rows[i + 1].Cells["pib_outboxcode1"].Value.ToString()))
  1979. {
  1980. BoxCode = BoxCode + 1;
  1981. }
  1982. else if (cu_print_outdc.Checked)
  1983. {
  1984. if (LabelInf.Rows[i].Cells["pib_datecode"].Value.ToString() != LabelInf.Rows[i + 1].Cells["pib_datecode"].Value.ToString())
  1985. {
  1986. BoxCode = BoxCode + 1;
  1987. }
  1988. }
  1989. else if (cu_print_outlotno.Checked)
  1990. {
  1991. if (LabelInf.Rows[i].Cells["pib_lotno"].Value.ToString() != LabelInf.Rows[i + 1].Cells["pib_lotno"].Value.ToString())
  1992. {
  1993. BoxCode = BoxCode + 1;
  1994. }
  1995. }
  1996. else if (cu_print_outpo.Checked)
  1997. {
  1998. if (LabelInf.Rows[i].Cells["pd_pocode"].Value.ToString() != LabelInf.Rows[i + 1].Cells["pd_pocode"].Value.ToString())
  1999. {
  2000. BoxCode = BoxCode + 1;
  2001. }
  2002. }
  2003. else if (cu_print_outprod.Checked)
  2004. {
  2005. if (LabelInf.Rows[i].Cells["pib_custprodcode"].Value.ToString() != LabelInf.Rows[i + 1].Cells["pib_custprodcode"].Value.ToString())
  2006. {
  2007. BoxCode = BoxCode + 1;
  2008. }
  2009. }
  2010. }
  2011. }
  2012. sdh.BatchInsert("prodiobarcode", LabelInf.DataSource as DataTable);
  2013. }
  2014. DataTable dt1 = (DataTable)sdh.ExecuteSql("select pib_id,pib_outboxcode1,pib_outboxcode2,pib_custmidboxcode,pib_custoutboxcode,pib_lotno,pib_datecode,pib_ifupload,pib_ifpick,pib_ifprint from prodiobarcode where pib_inoutno='" + pi_inoutno.Text + "' ", "select");
  2015. if (dt1.Rows.Count > 0)
  2016. {
  2017. dh.CallProcedure("sp_uploadbarcode", dt1);
  2018. }
  2019. }
  2020. private void LogingOut_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
  2021. {
  2022. ChangeMaster ch = new ChangeMaster();
  2023. BaseUtil.SetFormCenter(ch);
  2024. ch.FormClosed += Ch_FormClosed;
  2025. ch.ShowDialog();
  2026. }
  2027. private void Ch_FormClosed(object sender, FormClosedEventArgs e)
  2028. {
  2029. dh = SystemInf.dh;
  2030. sdh = SystemInf.sdh;
  2031. Text = "UAS-出货标签打印-" + SystemInf.MasterName;
  2032. }
  2033. private void LabelInf_DataError(object sender, DataGridViewDataErrorEventArgs e) { }
  2034. /// <summary>
  2035. /// 切换打开的单盘文件
  2036. /// </summary>
  2037. /// <param name="sender"></param>
  2038. /// <param name="e"></param>
  2039. private void SingleLabelCombox_SelectedIndexChanged(object sender, EventArgs e)
  2040. {
  2041. try
  2042. {
  2043. if (ComBoxClickChangeLabelDoc)
  2044. {
  2045. if (SingleDoc != null)
  2046. SingleDoc.Close();
  2047. if (SingleFormat != null)
  2048. SingleFormat.Close(SaveOptions.DoNotSaveChanges);
  2049. System.DateTime time = Convert.ToDateTime(SingleLabelCombox.SelectedValue.ToString().Split('#')[2]);
  2050. if (SingleLabelCombox.Text != "" && SingleLabelCombox.SelectedValue != null && !GetGridOnly.Checked)
  2051. {
  2052. if (PrintMethod == "CodeSoft")
  2053. {
  2054. SingleDoc = lbl.Documents.Open(BaseUtil.GetLabelUrl(SingleLabelCombox.SelectedValue.ToString().Split('#')[1], SingleLabelCombox.Text, time));
  2055. SingleDoc.Printer.Name = SingleLabelPrinter.Text;
  2056. }
  2057. else
  2058. {
  2059. SingleFormat = engine.Documents.Open(BaseUtil.GetLabelUrl(SingleLabelCombox.SelectedValue.ToString().Split('#')[1], SingleLabelCombox.Text, time));
  2060. SingleFormat.PrintSetup.PrinterName = SingleLabelPrinter.Text;
  2061. EmptySingleFormat.PrintSetup.PrinterName = SingleLabelPrinter.Text;
  2062. }
  2063. }
  2064. }
  2065. }
  2066. catch (Exception) { }
  2067. }
  2068. /// <summary>
  2069. /// 切换打开的中盒文件
  2070. /// </summary>
  2071. /// <param name="sender"></param>
  2072. /// <param name="e"></param>
  2073. private void MidLabelCombox_SelectedIndexChanged(object sender, EventArgs e)
  2074. {
  2075. try
  2076. {
  2077. if (ComBoxClickChangeLabelDoc)
  2078. {
  2079. if (MidDoc != null)
  2080. MidDoc.Close();
  2081. if (MidFormat != null)
  2082. MidFormat.Close(SaveOptions.DoNotSaveChanges);
  2083. if (MidLabelCombox.Text != "" && MidLabelCombox.SelectedValue != null && !GetGridOnly.Checked)
  2084. {
  2085. System.DateTime time = Convert.ToDateTime(MidLabelCombox.SelectedValue.ToString().Split('#')[2]);
  2086. if (PrintMethod == "CodeSoft")
  2087. {
  2088. MidDoc = lbl.Documents.Open(BaseUtil.GetLabelUrl(MidLabelCombox.SelectedValue.ToString().Split('#')[1], MidLabelCombox.Text, time));
  2089. MidDoc.Printer.Name = MidLabelPrinter.Text;
  2090. }
  2091. else
  2092. {
  2093. MidFormat = engine.Documents.Open(BaseUtil.GetLabelUrl(MidLabelCombox.SelectedValue.ToString().Split('#')[1], MidLabelCombox.Text, time));
  2094. MidFormat.PrintSetup.PrinterName = MidLabelPrinter.Text;
  2095. }
  2096. }
  2097. }
  2098. }
  2099. catch (Exception) { }
  2100. }
  2101. /// <summary>
  2102. /// 切换打开的外箱文件
  2103. /// </summary>
  2104. /// <param name="sender"></param>
  2105. /// <param name="e"></param>
  2106. private void OutBoxCombox_SelectedIndexChanged(object sender, EventArgs e)
  2107. {
  2108. try
  2109. {
  2110. if (ComBoxClickChangeLabelDoc)
  2111. {
  2112. if (OutBoxDoc != null)
  2113. OutBoxDoc.Close();
  2114. if (OutFormat != null)
  2115. OutFormat.Close(SaveOptions.DoNotSaveChanges);
  2116. System.DateTime time = Convert.ToDateTime(OutBoxCombox.SelectedValue.ToString().Split('#')[2]);
  2117. if (OutBoxCombox.Text != "" && OutBoxCombox.SelectedValue != null && !GetGridOnly.Checked)
  2118. {
  2119. if (PrintMethod == "CodeSoft")
  2120. {
  2121. OutBoxDoc = lbl.Documents.Open(BaseUtil.GetLabelUrl(OutBoxCombox.SelectedValue.ToString().Split('#')[1], OutBoxCombox.Text, time));
  2122. OutBoxDoc.Printer.Name = OutBoxPrinter.Text;
  2123. }
  2124. else
  2125. {
  2126. OutFormat = engine.Documents.Open(BaseUtil.GetLabelUrl(OutBoxCombox.SelectedValue.ToString().Split('#')[1], OutBoxCombox.Text, time));
  2127. OutFormat.PrintSetup.PrinterName = OutBoxPrinter.Text;
  2128. EmptyOutFormat.PrintSetup.PrinterName = OutBoxPrinter.Text;
  2129. }
  2130. }
  2131. }
  2132. }
  2133. catch (Exception) { }
  2134. }
  2135. private void ChooseAll_Click(object sender, EventArgs e)
  2136. {
  2137. if (LabelInf.Rows.Count > 0)
  2138. {
  2139. if (LabelInf.Rows.Count > 0)
  2140. {
  2141. if (LabelInf.Rows[0].Cells["Choose"].FormattedValue.ToString() == "True")
  2142. {
  2143. foreach (DataGridViewRow dr in LabelInf.Rows)
  2144. dr.Cells[0].Value = false;
  2145. }
  2146. else
  2147. {
  2148. foreach (DataGridViewRow dr in LabelInf.Rows)
  2149. dr.Cells[0].Value = true;
  2150. }
  2151. }
  2152. }
  2153. }
  2154. private void LabelInf_CellEndEdit(object sender, DataGridViewCellEventArgs e)
  2155. {
  2156. if (e.RowIndex > 0)
  2157. {
  2158. if (LabelInf.Columns[e.ColumnIndex].Name == "pin_madein")
  2159. {
  2160. StringBuilder pibid = new StringBuilder();
  2161. string madein = LabelInf.Rows[e.RowIndex].Cells["pib_madein"].Value.ToString();
  2162. if (LabelInf.Columns[e.ColumnIndex].Name == "pib_madein" && CollectionUnit.Text == "盒")
  2163. {
  2164. string midbox = LabelInf.Rows[e.RowIndex].Cells["pib_outboxcode1"].Value.ToString();
  2165. for (int i = 0; i < LabelInf.Rows.Count; i++)
  2166. {
  2167. if (midbox == LabelInf.Rows[i].Cells["pib_outboxcode1"].Value.ToString())
  2168. {
  2169. LabelInf.Rows[i].Cells["pib_madein"].Value = madein;
  2170. pibid.Append(LabelInf.Rows[i].Cells["pib_id1"].Value + ",");
  2171. }
  2172. }
  2173. }
  2174. if (LabelInf.Columns[e.ColumnIndex].Name == "pib_madein" && CollectionUnit.Text == "全部")
  2175. {
  2176. for (int i = 0; i < LabelInf.Rows.Count; i++)
  2177. {
  2178. LabelInf.Rows[i].Cells["pib_madein"].Value = madein;
  2179. pibid.Append(LabelInf.Rows[i].Cells["pib_id1"].Value + ",");
  2180. }
  2181. }
  2182. pibid.Append("1");
  2183. sdh.ExecuteSql("update prodiobarcode set pib_madein='" + madein + "' where pib_id in (" + pibid + ")", "update");
  2184. }
  2185. }
  2186. }
  2187. private void ExportData_Click(object sender, EventArgs e)
  2188. {
  2189. }
  2190. private void MidBoxCapacity_Leave(object sender, EventArgs e)
  2191. {
  2192. NumericUpDown nup = (NumericUpDown)sender;
  2193. switch (nup.Name)
  2194. {
  2195. case "MidBoxCapacity":
  2196. Properties.Settings.Default.MidBoxCapacity = nup.Value;
  2197. Properties.Settings.Default.Save();
  2198. break;
  2199. case "OutboxCapacity":
  2200. Properties.Settings.Default.OutboxCapacity = nup.Value;
  2201. Properties.Settings.Default.Save();
  2202. break;
  2203. default:
  2204. break;
  2205. }
  2206. }
  2207. private void CleanBarCode_Click(object sender, EventArgs e)
  2208. {
  2209. string close = MessageBox.Show(this.ParentForm, "是否清除该出货单条码", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question).ToString();
  2210. if (close.ToString() == "Yes")
  2211. {
  2212. sdh.ExecuteSql("delete from prodiobarcode where pib_inoutno='" + pi_inoutno.Text + "'", "delete");
  2213. dh.ExecuteSql("delete from prodiobarcode where pib_inoutno='" + pi_inoutno.Text + "'", "delete");
  2214. LoadGridData(sender, e);
  2215. }
  2216. }
  2217. private void LabelPrinter_UserOnSelectIndexChange(object sender, EventArgs e)
  2218. {
  2219. switch ((sender as Control).Parent.Name)
  2220. {
  2221. case "SingleLabelPrinter":
  2222. if (PrintMethod == "CodeSoft")
  2223. {
  2224. if (SingleDoc != null)
  2225. SingleDoc.Printer.SwitchTo(SingleLabelPrinter.Text);
  2226. }
  2227. else
  2228. {
  2229. if (SingleFormat != null)
  2230. SingleFormat.PrintSetup.PrinterName = SingleLabelPrinter.Text;
  2231. }
  2232. Properties.Settings.Default.SinglePrinter = SingleLabelPrinter.Text;
  2233. break;
  2234. case "MidLabelPrinter":
  2235. if (PrintMethod == "CodeSoft")
  2236. {
  2237. if (MidDoc != null)
  2238. MidDoc.Printer.SwitchTo(MidLabelPrinter.Text);
  2239. }
  2240. else
  2241. {
  2242. if (MidFormat != null)
  2243. MidFormat.PrintSetup.PrinterName = MidLabelPrinter.Text;
  2244. }
  2245. Properties.Settings.Default.MidPrinter = MidLabelPrinter.Text;
  2246. break;
  2247. case "OutBoxPrinter":
  2248. if (PrintMethod == "CodeSoft")
  2249. {
  2250. if (OutBoxDoc != null)
  2251. OutBoxDoc.Printer.SwitchTo(OutBoxPrinter.Text);
  2252. }
  2253. else
  2254. {
  2255. if (OutFormat != null)
  2256. OutFormat.PrintSetup.PrinterName = OutBoxPrinter.Text;
  2257. }
  2258. Properties.Settings.Default.OutPrinter = OutBoxPrinter.Text;
  2259. break;
  2260. default:
  2261. break;
  2262. }
  2263. Properties.Settings.Default.Save();
  2264. }
  2265. private void DocRefresh_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
  2266. {
  2267. switch ((sender as Control).Name)
  2268. {
  2269. case "SingleDocRefresh":
  2270. if (SingleDoc != null)
  2271. SingleDoc.Close();
  2272. if (SingleLabelCombox.Text != "" && SingleLabelCombox.SelectedValue != null && !GetGridOnly.Checked)
  2273. {
  2274. System.DateTime time = Convert.ToDateTime(SingleLabelCombox.SelectedValue.ToString().Split('#')[2]);
  2275. SingleDoc = lbl.Documents.Open(BaseUtil.GetLabelUrl(SingleLabelCombox.SelectedValue.ToString().Split('#')[1], SingleLabelCombox.Text, time));
  2276. }
  2277. break;
  2278. case "MidDocRefresh":
  2279. if (MidDoc != null)
  2280. MidDoc.Close();
  2281. if (MidLabelCombox.Text != "" && MidLabelCombox.SelectedValue != null && !GetGridOnly.Checked)
  2282. {
  2283. System.DateTime time = Convert.ToDateTime(MidLabelCombox.SelectedValue.ToString().Split('#')[2]);
  2284. MidDoc = lbl.Documents.Open(BaseUtil.GetLabelUrl(MidLabelCombox.SelectedValue.ToString().Split('#')[1], MidLabelCombox.Text, time));
  2285. }
  2286. break;
  2287. case "OutDocRefresh":
  2288. if (OutBoxDoc != null)
  2289. OutBoxDoc.Close();
  2290. if (OutBoxCombox.Text != "" && OutBoxCombox.SelectedValue != null && !GetGridOnly.Checked)
  2291. {
  2292. System.DateTime time = Convert.ToDateTime(OutBoxCombox.SelectedValue.ToString().Split('#')[2]);
  2293. OutBoxDoc = lbl.Documents.Open(BaseUtil.GetLabelUrl(OutBoxCombox.SelectedValue.ToString().Split('#')[1], OutBoxCombox.Text, time));
  2294. }
  2295. break;
  2296. default:
  2297. break;
  2298. }
  2299. }
  2300. private void cu_code_UserControlTextChanged(object sender, EventArgs e)
  2301. {
  2302. if (!InitGetLabel)
  2303. GetInOutInfAndLabelFile();
  2304. }
  2305. private void MenuSetting_Click(object sender, EventArgs e)
  2306. {
  2307. ShowMenu.Show(new Point(MenuSetting.Location.X, MenuSetting.Location.Y + 20));
  2308. }
  2309. private void Menu_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
  2310. {
  2311. ShowMenu.Close();
  2312. DataTable dt;
  2313. DialogResult result;
  2314. switch (e.ClickedItem.Text)
  2315. {
  2316. case "采集策略设置":
  2317. 采集策略 form = new 采集策略(sg_code.Text);
  2318. form.FormClosed += sg_code_UserControlTextChanged;
  2319. BaseUtil.SetFormCenter(form);
  2320. form.ShowDialog();
  2321. break;
  2322. case "附加信息设置":
  2323. if (cu_code.Text != "")
  2324. {
  2325. 附件内容打印 att = new 附件内容打印(cu_code.Text);
  2326. att.FormClosed += Att_FormClosed;
  2327. att.ShowDialog();
  2328. }
  2329. else MessageBox.Show("请先获取出库单信息");
  2330. break;
  2331. case "标签维护":
  2332. 客户标签维护 form1 = new 客户标签维护();
  2333. BaseUtil.SetFormCenter(form1);
  2334. if (SingleDoc != null)
  2335. SingleDoc.Close();
  2336. if (MidDoc != null)
  2337. MidDoc.Close();
  2338. if (OutBoxDoc != null)
  2339. OutBoxDoc.Close();
  2340. //if (SingleFormat != null)
  2341. // SingleFormat.Close(SaveOptions.DoNotSaveChanges);
  2342. //if (MidFormat != null)
  2343. // MidFormat.Close(SaveOptions.DoNotSaveChanges);
  2344. //if (OutFormat != null)
  2345. // OutFormat.Close(SaveOptions.DoNotSaveChanges);
  2346. form1.FormClosed += LabelFormClose;
  2347. form1.ShowDialog();
  2348. break;
  2349. case "导出数据":
  2350. ExportExcel ex = new ExportExcel(pi_inoutno.Text);
  2351. ex.FormClosed += Ex_FormClosed;
  2352. switch (SystemInf.Master)
  2353. {
  2354. case "SZSI_TEST":
  2355. ex.StartPosition = FormStartPosition.CenterScreen;
  2356. ex.ShowDialog();
  2357. break;
  2358. case "SZSI_P":
  2359. ex.StartPosition = FormStartPosition.CenterScreen;
  2360. ex.ShowDialog();
  2361. break;
  2362. default:
  2363. ExportFileDialog.Description = "选择导出的路径";
  2364. result = ExportFileDialog.ShowDialog();
  2365. if (result == DialogResult.OK)
  2366. {
  2367. ExcelHandler eh = new ExcelHandler();
  2368. dt = ((DataTable)LabelInf.DataSource).Copy();
  2369. for (int i = dt.Columns.Count - 1; i >= 0; i--)
  2370. {
  2371. for (int j = 0; j < LabelInf.Columns.Count; j++)
  2372. {
  2373. //去除ID列
  2374. if (dt.Columns[i].ColumnName.ToLower().Contains("id") || dt.Columns[i].ColumnName.ToLower() == "pib_barcode" || dt.Columns[i].ColumnName.ToLower() == "pib_pdno" || dt.Columns[i].ColumnName.ToLower() == "pib_ifpick" || dt.Columns[i].ColumnName.ToLower() == "pib_ifprint" || dt.Columns[i].ColumnName.ToLower() == "pib_datecode1" || dt.Columns[i].ColumnName.ToLower() == "pr_vendprodcode")
  2375. {
  2376. dt.Columns.RemoveAt(i);
  2377. break;
  2378. }
  2379. switch (dt.Columns[i].ColumnName.ToLower())
  2380. {
  2381. case "pib_lotno":
  2382. dt.Columns[i].ColumnName = "批次号";
  2383. break;
  2384. case "pib_datecode":
  2385. dt.Columns[i].ColumnName = "生产日期";
  2386. break;
  2387. case "pib_custbarcode":
  2388. dt.Columns[i].ColumnName = "最小产品包装条码";
  2389. break;
  2390. default:
  2391. break;
  2392. }
  2393. if (dt.Columns[i].ColumnName.ToLower() == LabelInf.Columns[j].DataPropertyName.ToLower())
  2394. {
  2395. dt.Columns[i].ColumnName = LabelInf.Columns[j].HeaderText;
  2396. break;
  2397. }
  2398. }
  2399. }
  2400. eh.ExportExcel(dt, ExportFileDialog.SelectedPath, pi_date.Text + "-" + pi_inoutno.Text);
  2401. string close = MessageBox.Show(this.ParentForm, "导出成功,是否打开文件", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question).ToString();
  2402. if (close.ToString() == "Yes")
  2403. System.Diagnostics.Process.Start(ExportFileDialog.SelectedPath + "\\" + pi_date.Text + "-" + pi_inoutno.Text + ".xls");
  2404. }
  2405. break;
  2406. }
  2407. break;
  2408. case "权限设置":
  2409. PowerSetting pw = new PowerSetting();
  2410. BaseUtil.SetFormCenter(pw);
  2411. pw.ShowDialog();
  2412. break;
  2413. case "条码导入生成":
  2414. ImportExcel.Filter = "(*.xls)|*.xlsx;*.xls";
  2415. result = ImportExcel.ShowDialog();
  2416. if (result == DialogResult.OK)
  2417. {
  2418. thread = new Thread(ImportBarcode);
  2419. stw = new SetLoadingWindow(thread, "正在生成条码");
  2420. BaseUtil.SetFormCenter(stw);
  2421. stw.ShowDialog();
  2422. }
  2423. break;
  2424. case "下载模板":
  2425. ExportFileDialog.Description = "选择导出的路径";
  2426. result = ExportFileDialog.ShowDialog();
  2427. if (result == DialogResult.OK)
  2428. {
  2429. File.Copy(System.Windows.Forms.Application.StartupPath + "\\导入模板.xls", ExportFileDialog.SelectedPath + "\\导入模板.xls", true);
  2430. System.Diagnostics.Process.Start(ExportFileDialog.SelectedPath + "\\导入模板.xls");
  2431. }
  2432. break;
  2433. case "客户合并规则":
  2434. CustomerRule cust = new CustomerRule();
  2435. BaseUtil.SetFormCenter(cust);
  2436. cust.ShowDialog();
  2437. break;
  2438. case "流水调整":
  2439. if (cu_code.Text != "")
  2440. {
  2441. ReSetMaxNum reset = new ReSetMaxNum(cu_code.Text, pi_inoutno.Text);
  2442. BaseUtil.SetFormCenter(reset);
  2443. reset.ShowDialog();
  2444. }
  2445. else
  2446. {
  2447. MessageBox.Show("请先输入出货单号");
  2448. }
  2449. break;
  2450. default:
  2451. break;
  2452. }
  2453. }
  2454. private void Ex_FormClosed(object sender, FormClosedEventArgs e)
  2455. {
  2456. LoadGridData(false);
  2457. }
  2458. private void Att_FormClosed(object sender, FormClosedEventArgs e)
  2459. {
  2460. Attach = (DataTable)dh.ExecuteSql("select lap_param lp_name,lap_value lp_sql from LabelAttachPARAMETER where lap_custcode='" + cu_code.Text + "'", "select");
  2461. }
  2462. //生成客户条码
  2463. public string BarcodeMethod1(string Prefix, string Suffix, int Index, int Length, int radix)
  2464. {
  2465. string str = Prefix;
  2466. //如果是流水则需要在前面加0
  2467. string serialcode = BaseUtil.DToAny(custserialnum, radix);
  2468. for (int j = serialcode.ToString().Length; j < Length; j++)
  2469. {
  2470. serialcode = "0" + serialcode;
  2471. }
  2472. str += serialcode;
  2473. str += Suffix;
  2474. custserialnum = custserialnum + 1;
  2475. return str;
  2476. }
  2477. //前缀
  2478. public static string Prefix = "";
  2479. //后缀
  2480. public static string Suffix = "";
  2481. //编码规则编号
  2482. public static string NrCode = "";
  2483. public static string PrefixFixed = "";
  2484. //流水号的索引
  2485. public static int SerialNumIndex = 0;
  2486. //流水长度
  2487. public static int SerialNumLength = 0;
  2488. //存放键值对
  2489. public static int Radix = 10;
  2490. //客户的流水号
  2491. public static int custserialnum = 0;
  2492. public void GetCustRule()
  2493. {
  2494. //前缀
  2495. Prefix = "";
  2496. //后缀
  2497. Suffix = "";
  2498. //编码规则编号
  2499. NrCode = "";
  2500. PrefixFixed = "";
  2501. //流水号的索引
  2502. SerialNumIndex = 0;
  2503. //流水长度
  2504. SerialNumLength = 0;
  2505. //存放键值对
  2506. Radix = 10;
  2507. DataTable Nr = (DataTable)dh.ExecuteSql("select nrd_detno,nrd_name,nrd_type,nrd_radix,nrd_sql,nrd_length,nr_code,nvl(nrd_iscombine,-1)nrd_iscombine from NoRuleDetail left join norule on nrd_nrid=nr_id where nr_custcode='" + cu_code.Text + "' order by nrd_detno", "select");
  2508. //如果没有则取公共规则
  2509. if (Nr.Rows.Count == 0)
  2510. Nr = (DataTable)dh.ExecuteSql("select nrd_detno,nrd_name,nrd_radix,nrd_type,nrd_sql,nrd_length,nr_code,nvl(nrd_iscombine,-1)nrd_iscombine from NoRuleDetail left join norule on nrd_nrid=nr_id where nr_custcode is null and nr_isdefault <> 0 order by nrd_detno", "select");
  2511. //用于过滤参数的正则表达式
  2512. if (Nr.Rows.Count > 0)
  2513. {
  2514. NrCode = Nr.Rows[0]["nr_code"].ToString();
  2515. }
  2516. Regex match = new Regex("{\\w+}");
  2517. //用于存放每一项的明细的数据
  2518. string[] NrData = new string[Nr.Rows.Count];
  2519. for (int m = 0; m < Nr.Rows.Count; m++)
  2520. {
  2521. switch (Nr.Rows[m]["nrd_type"].ToString())
  2522. {
  2523. //常量直接进行拼接
  2524. case "常量":
  2525. NrData[m] = Nr.Rows[m]["nrd_sql"].ToString();
  2526. Prefix += NrData[m];
  2527. Suffix += NrData[m];
  2528. break;
  2529. case "SQL":
  2530. string SQL = Nr.Rows[m]["nrd_sql"].ToString();
  2531. DataTable Temp;
  2532. //如果不包含参数替换
  2533. if (SQL.IndexOf("{") == 0)
  2534. {
  2535. Temp = (DataTable)dh.ExecuteSql(SQL, "select");
  2536. }
  2537. else
  2538. {
  2539. //替换参数后重新执行SQL
  2540. foreach (Match mch in match.Matches(SQL))
  2541. {
  2542. SQL = SQL.Replace(mch.Value.Trim(), "'" + pi_inoutno.Text + "'");
  2543. }
  2544. Temp = (DataTable)dh.ExecuteSql(SQL, "select");
  2545. }
  2546. if (Temp.Rows.Count > 0)
  2547. {
  2548. NrData[m] = Temp.Rows[0][0].ToString();
  2549. Prefix += NrData[m];
  2550. Suffix += NrData[m];
  2551. }
  2552. else
  2553. {
  2554. NrData[m] = "";
  2555. Prefix += NrData[m];
  2556. Suffix += NrData[m];
  2557. }
  2558. break;
  2559. //流水需要通过MaxNumber去取
  2560. case "流水":
  2561. NrData[m] = dh.getFieldDataByCondition("RuleMaxNum", "rmn_maxnumber", "rmn_nrcode='" + NrCode + "'").ToString();
  2562. Suffix = "";
  2563. PrefixFixed = Prefix;
  2564. //设置当前流水
  2565. custserialnum = int.Parse(NrData[m] == "" ? "0" : NrData[m]);
  2566. SerialNumIndex = m;
  2567. SerialNumLength = int.Parse(Nr.Rows[m]["nrd_length"].ToString());
  2568. Radix = int.Parse(Nr.Rows[m]["nrd_radix"].ToString());
  2569. break;
  2570. default:
  2571. break;
  2572. }
  2573. }
  2574. string maxnum = dh.getFieldDataByCondition("RuleMaxNum", "rmn_maxnumber", "rmn_nrcode='" + NrCode + "' and rmn_prefix='" + Prefix + "'").ToString();
  2575. if (maxnum == "")
  2576. {
  2577. dh.ExecuteSql("insert into RuleMaxNum(rmn_id,rmn_nrcode,rmn_prefix,rmn_maxnumber) values(RuleMaxNum_seq.nextval,'" + NrCode + "','" + Prefix + "','1')", "insert");
  2578. maxnum = dh.getFieldDataByCondition("RuleMaxNum", "rmn_maxnumber", "rmn_nrcode='" + NrCode + "' and rmn_prefix='" + Prefix + "'").ToString();
  2579. if (maxnum == "")
  2580. {
  2581. maxnum = "0";
  2582. }
  2583. custserialnum = int.Parse(maxnum);
  2584. }//如果流水号不为空则取当前流水
  2585. else
  2586. {
  2587. custserialnum = int.Parse(maxnum);
  2588. }
  2589. }
  2590. public void ImportBarcode()
  2591. {
  2592. try
  2593. {
  2594. GetCustRule();
  2595. LogicHandler.ImportExcel(SystemInf.Master, ImportExcel.FileName, PI_ID, pi_inoutno.Text, cu_code.Text);
  2596. LoadGridData(false);
  2597. }
  2598. catch (Exception ex)
  2599. {
  2600. LogManager.DoLog(ex.StackTrace);
  2601. MessageBox.Show(ex.Message);
  2602. Console.WriteLine(ex.StackTrace);
  2603. }
  2604. }
  2605. int rowindex = 0;
  2606. private void LabelInf_CellMouseClick(object sender, DataGridViewCellMouseEventArgs e)
  2607. {
  2608. if (e.Button == MouseButtons.Right)
  2609. {
  2610. rowindex = e.RowIndex;
  2611. DateCodeSetAndPrint date = new DateCodeSetAndPrint();
  2612. date.Controls["SetValue"].Click += SetValue_ButtonClick;
  2613. //date.Controls["SetValueAndPrint"].Click += SetValueAndPrint_ButtonClick;
  2614. date.ShowDialog();
  2615. }
  2616. }
  2617. private void SetValue_ButtonClick(object sender, EventArgs e)
  2618. {
  2619. Button setvalue = sender as Button;
  2620. string pdno = LabelInf.Rows[rowindex].Cells["pib_pdno"].Value.ToString();
  2621. string pr_brand = LabelInf.Rows[rowindex].Cells["pib_brand"].Value.ToString();
  2622. string datecode = setvalue.FindForm().Controls["datecode"].Text;
  2623. string lotno = setvalue.FindForm().Controls["lotno"].Text;
  2624. string BeginRow = setvalue.FindForm().Controls["Begin"].Text;
  2625. string EndRow = setvalue.FindForm().Controls["End"].Text;
  2626. //string year = "0";
  2627. //string month = "0";
  2628. //string day = "0";
  2629. //string date = "";
  2630. //string sql = "update prodiobarcode set pib_autoset=-1,pib_ifrecheck=-1,pib_ifpick=-1,pib_ifmodify=-1,pib_lotno='" + lotno + "',pib_datecode='" + datecode + "',pib_year='" + year + "',pib_month='" + month + "',pib_day='" + day + "' where pib_id in (select pib_id from prodiobarcode where pib_inoutno='" + pi_inoutno.Text + "'";
  2631. //if (datecode != "")
  2632. //{
  2633. // //LogicHandler.GetTimeFromDatecode(datecode, pr_brand, out year, out month, out day, out date);
  2634. // sql += " and (pib_datecode='' or pib_datecode is null) ";
  2635. //}
  2636. //if (lotno != "")
  2637. //{
  2638. // sql += " and (pib_lotno='' or pib_lotno is null) ";
  2639. //}
  2640. List<string> pib_id = new List<string>();
  2641. if (BeginRow != "" || EndRow != "")
  2642. {
  2643. try
  2644. {
  2645. int begin = int.Parse(BeginRow == "" ? "1" : BeginRow);
  2646. int end = int.Parse(EndRow == "" ? LabelInf.Rows.Count.ToString() : EndRow);
  2647. if (begin > 0 && end <= LabelInf.Rows.Count && begin <= end)
  2648. {
  2649. for (int i = begin - 1; i < end; i++)
  2650. {
  2651. pib_id.Add(LabelInf.Rows[i].Cells["pib_id1"].Value.ToString());
  2652. }
  2653. }
  2654. else
  2655. {
  2656. MessageBox.Show("范围设置错误");
  2657. return;
  2658. }
  2659. LabelInf.Invalidate();
  2660. }
  2661. catch (Exception)
  2662. {
  2663. MessageBox.Show("范围设置错误");
  2664. return;
  2665. }
  2666. }
  2667. dh.BatchInsert("update prodiobarcode set pib_lotno='" + lotno + "',pib_datecode='" + datecode + "' where pib_id=:pib_id", new string[] { "pib_id" }, pib_id.ToArray());
  2668. //同步数据到本地
  2669. sdh.ExecuteSql("delete from prodiobarcode where pib_inoutno='" + pi_inoutno.Text + "'", "delete");
  2670. LoadGridData(false);
  2671. setvalue.FindForm().Close();
  2672. }
  2673. private void SetValueAndPrint_ButtonClick(object sender, EventArgs e)
  2674. {
  2675. Button setvalueandprint = sender as Button;
  2676. string pdno = LabelInf.Rows[rowindex].Cells["pib_pdno"].Value.ToString();
  2677. string pr_brand = LabelInf.Rows[rowindex].Cells["pib_brand"].Value.ToString();
  2678. string datecode = setvalueandprint.FindForm().Controls["datecode"].Text;
  2679. string lotno = setvalueandprint.FindForm().Controls["lotno"].Text;
  2680. string nums = setvalueandprint.FindForm().Controls["Nums"].Text;
  2681. string year = "0";
  2682. string month = "0";
  2683. string day = "0";
  2684. //string date = "";
  2685. string sql = "update prodiobarcode set pib_autoset=-1,pib_ifrecheck=-1,pib_ifpick=-1,pib_ifmodify=-1,pib_ifprint=-1,pib_lotno='" + lotno + "',pib_datecode='" + datecode + "',pib_year='" + year + "',pib_month='" + month + "',pib_day='" + day + "' where pib_id in (select pib_id from prodiobarcode where pib_inoutno='" + pi_inoutno.Text + "'";
  2686. string PrintSQL = "select pib_id from prodiobarcode where pib_inoutno='" + pi_inoutno.Text + "' and pib_pdno=" + pdno;
  2687. if (datecode != "")
  2688. {
  2689. //LogicHandler.GetTimeFromDatecode(datecode, pr_brand, out year, out month, out day, out date);
  2690. sql += " and (pib_datecode='' or pib_datecode is null) ";
  2691. PrintSQL += " and (pib_datecode='' or pib_datecode is null) ";
  2692. }
  2693. if (lotno != "")
  2694. {
  2695. sql += " and (pib_lotno='' or pib_lotno is null) ";
  2696. PrintSQL += " and (pib_lotno='' or pib_lotno is null) ";
  2697. }
  2698. if (nums == "")
  2699. {
  2700. sql += ")";
  2701. }
  2702. else
  2703. {
  2704. sql += " limit 0," + nums + ")";
  2705. PrintSQL += " limit 0," + nums;
  2706. }
  2707. DataTable pibid_dt = (DataTable)sdh.ExecuteSql(PrintSQL, "select");
  2708. sdh.ExecuteSql(sql, "update");
  2709. for (int i = 0; i < pibid_dt.Rows.Count; i++)
  2710. {
  2711. if (PrintMethod == "CodeSoft")
  2712. Print.CodeSoft.SinglePrint(SingleDoc, SingleLabelParam, pibid_dt.Rows[i]["pib_id"].ToString());
  2713. else
  2714. Print.BarTender.SinglePrint(SingleFormat, SingleLabelParam, pibid_dt.Rows[i]["pib_id"].ToString());
  2715. }
  2716. setvalueandprint.FindForm().Close();
  2717. }
  2718. /// <summary>
  2719. /// 特殊业务逻辑
  2720. /// </summary>
  2721. /// <param name="sender"></param>
  2722. /// <param name="e"></param>
  2723. private void CustBarCode_Click(object sender, EventArgs e)
  2724. {
  2725. string SQL = "";
  2726. LogicHandler.CustBarCode(pi_inoutno.Text, out SQL);
  2727. sdh.ExecuteSql(SQL, "update");
  2728. LoadGridData(false);
  2729. }
  2730. private void GetMidBoxCode_Click(object sender, EventArgs e)
  2731. {
  2732. int BoxCode = 1;
  2733. int innerboxcount = 1;
  2734. for (int i = 0; i < LabelInf.Rows.Count; i++)
  2735. {
  2736. string midcapa = LabelInf.Rows[i].Cells["pr_midboxcapacity_user"].Value.ToString();
  2737. if (!(midcapa == "" || midcapa == "0"))
  2738. {
  2739. //如果出现值为空或者0默认界面上填写的值
  2740. MidBoxCapacity.Value = decimal.Parse((midcapa == "" || midcapa == "0") ? MidBoxCapacity.Value.ToString() : midcapa);
  2741. LabelInf.Rows[i].Cells["pib_outboxcode1"].Value = BoxCode;
  2742. if (i + 1 < LabelInf.Rows.Count)
  2743. {
  2744. if (innerboxcount == MidBoxCapacity.Value)
  2745. {
  2746. BoxCode = BoxCode + 1;
  2747. innerboxcount = 1;
  2748. }
  2749. else if (LabelInf.Rows[i].Cells["pib_prodcode"].Value.ToString() != LabelInf.Rows[i + 1].Cells["pib_prodcode"].Value.ToString() || LabelInf.Rows[i].Cells["pib_outboxcode2"].Value.ToString() != LabelInf.Rows[i + 1].Cells["pib_outboxcode2"].Value.ToString())
  2750. {
  2751. BoxCode = BoxCode + 1;
  2752. innerboxcount = 1;
  2753. }
  2754. else
  2755. {
  2756. innerboxcount = innerboxcount + 1;
  2757. }
  2758. }
  2759. }
  2760. }
  2761. sdh.BatchInsert("prodiobarcode", LabelInf.DataSource as DataTable);
  2762. DataTable dt1 = (DataTable)sdh.ExecuteSql("select pib_id,pib_outboxcode1,pib_outboxcode2,pib_custmidboxcode,pib_custoutboxcode,pib_lotno,pib_datecode,pib_ifupload,pib_ifpick,pib_ifprint from prodiobarcode where pib_inoutno='" + pi_inoutno.Text + "' ", "select");
  2763. if (dt1.Rows.Count > 0)
  2764. {
  2765. dh.CallProcedure("sp_uploadbarcode", dt1);
  2766. }
  2767. }
  2768. private void MidLabelPreView_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
  2769. {
  2770. MidFormat = engine.Documents.Open(ftpOperater.DownLoadTo + MidLabelCombox.Text);
  2771. Resolution re = new Resolution(ImageResolution.Printer);
  2772. if (File.Exists(@"C:\打印标签\" + MidLabelCombox.Text + ".jpg"))
  2773. {
  2774. File.Delete(@"C:\打印标签\" + MidLabelCombox.Text + ".jpg");
  2775. }
  2776. MidFormat.ExportImageToFile(@"C:\打印标签\" + MidLabelCombox.Text + ".jpg", ImageType.JPEG, Seagull.BarTender.Print.ColorDepth.Mono, re, OverwriteOptions.DoNotOverwrite);
  2777. PreViewWindow pre = new PreViewWindow(MidLabelCombox.Text);
  2778. pre.StartPosition = FormStartPosition.CenterScreen;
  2779. pre.ShowDialog();
  2780. }
  2781. private void FTPModel_CheckedChanged(object sender, EventArgs e)
  2782. {
  2783. if (FTPModel.Checked)
  2784. {
  2785. if (!dh.CheckExist("configs", "caller='FTPModel' and code='PassOrNeg'"))
  2786. {
  2787. dh.ExecuteSql("insert into configs(id,caller,code,data)values(configs_seq.nextval,'FTPModel','PassOrNeg','Y')", "insert");
  2788. }
  2789. else
  2790. {
  2791. dh.ExecuteSql("update configs set data='Y' where caller='FTPModel' and code ='PassOrNeg'", "insert");
  2792. }
  2793. SystemInf.FTPModel = true;
  2794. }
  2795. else
  2796. {
  2797. dh.ExecuteSql("update configs set data='N' where caller='FTPModel' and code ='PassOrNeg'", "insert");
  2798. SystemInf.FTPModel = false;
  2799. }
  2800. }
  2801. Regex reg = new Regex(@"\d+.\d+");
  2802. ComInfoSet cis;
  2803. private void ConnectCom_Click(object sender, EventArgs e)
  2804. {
  2805. cis = new ComInfoSet();
  2806. (cis.Controls["PortName"] as SerialPortCombox).SelectedValue = Properties.Settings.Default.PortName;
  2807. cis.Controls["BaudRate"].Text = Properties.Settings.Default.BaudRate;
  2808. cis.Controls["Confirm"].Click += UAS_出货标签打印_Click;
  2809. cis.ShowDialog();
  2810. }
  2811. private void CloseSerialPort_Click(object sender, EventArgs e)
  2812. {
  2813. if (Com.IsOpen)
  2814. {
  2815. Com.Close();
  2816. Com.DataReceived -= Com_DataReceived;
  2817. }
  2818. }
  2819. private void ButtonMidWeigh_Click(object sender, EventArgs e)
  2820. {
  2821. if (Weight.Text != "" && Weight.Text != "0.000")
  2822. {
  2823. string pib_outboxcode1 = LabelInf.Rows[SelectRowIndex].Cells["pib_outboxcode1"].Value.ToString();
  2824. sql.Clear();
  2825. sql.Append("update prodiobarcode set pib_midboxweight='" + Weight.Text + "' where pib_inoutno='" + pi_inoutno.Text + "' ");
  2826. sql.Append(" and pib_outboxcode2='" + OutBoxNum.Text + "' and pib_outboxcode1='" + pib_outboxcode1 + "'");
  2827. dh.ExecuteSql(sql.ToString(), "update");
  2828. LoadGridData(sender, e);
  2829. }
  2830. else
  2831. {
  2832. MessageBox.Show("请先连接电子秤!");
  2833. }
  2834. }
  2835. private void ButtonWeigh_Click(object sender, EventArgs e)
  2836. {
  2837. if (Weight.Text != "" && Weight.Text != "0.000")
  2838. {
  2839. sql.Clear();
  2840. sql.Append("update prodiobarcode set pib_boxweight='" + Weight.Text + "' where pib_inoutno='" + pi_inoutno.Text + "' ");
  2841. sql.Append(" and pib_outboxcode2='" + OutBoxNum.Text + "'");
  2842. dh.ExecuteSql(sql.ToString(), "update");
  2843. LoadGridData(sender, e);
  2844. }
  2845. else
  2846. {
  2847. MessageBox.Show("请先连接电子秤!");
  2848. }
  2849. }
  2850. private void UAS_出货标签打印_Click(object sender, EventArgs e)
  2851. {
  2852. if (Com.IsOpen && Com.PortName == cis.Controls["PortName"].Text)
  2853. {
  2854. MessageBox.Show("串口" + Com.PortName + "已打开");
  2855. return;
  2856. }
  2857. else
  2858. {
  2859. if (Com.IsOpen)
  2860. {
  2861. Com.Close();
  2862. }
  2863. }
  2864. int BaudRate = 0;
  2865. Com.PortName = cis.Controls["PortName"].Text;
  2866. if (int.TryParse(cis.Controls["BaudRate"].Text, out BaudRate))
  2867. {
  2868. Com.BaudRate = BaudRate;
  2869. }
  2870. Properties.Settings.Default.BaudRate = BaudRate.ToString();
  2871. Properties.Settings.Default.PortName = cis.Controls["PortName"].Text;
  2872. Properties.Settings.Default.Save();
  2873. Com.DataReceived += Com_DataReceived;
  2874. Com.Open();
  2875. cis.Close();
  2876. }
  2877. private void Com_DataReceived(object sender, System.IO.Ports.SerialDataReceivedEventArgs e)
  2878. {
  2879. try
  2880. {
  2881. int len = Com.BytesToRead;
  2882. byte[] readBuffer = new byte[len];
  2883. Com.Read(readBuffer, 0, len); //将数据读入缓存
  2884. string value = reg.Match(Encoding.ASCII.GetString(readBuffer, 0, len)).Value;
  2885. if (value != "")
  2886. {
  2887. Weight.Text = value;
  2888. }
  2889. //读不到数据的时间删掉
  2890. }
  2891. catch (Exception)
  2892. {
  2893. return;
  2894. }
  2895. }
  2896. int SelectRowIndex = -1;
  2897. private void LabelInf_CellClick(object sender, DataGridViewCellEventArgs e)
  2898. {
  2899. if (e.RowIndex >= 0)
  2900. {
  2901. LabelInf.Rows[e.RowIndex].Selected = true;
  2902. SelectRowIndex = e.RowIndex;
  2903. }
  2904. }
  2905. string ShareRule;
  2906. string ReSetType = "";
  2907. private void GetBarCodeRule(out string Prefix, out string Suffix, out int MaxNum, out int SerialNumLength, out int Radix, int Count)
  2908. {
  2909. //获取编码规则
  2910. Prefix = "";
  2911. Suffix = "";
  2912. NrCode = "";
  2913. MaxNum = 0;
  2914. SerialNumLength = 0;
  2915. Radix = 0;
  2916. 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='" + cu_code.Text + "' order by nrd_detno", "select");
  2917. //如果没有则取公共规则
  2918. if (Nr.Rows.Count == 0)
  2919. 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");
  2920. //用于过滤参数的正则表达式
  2921. ReSetType = "";
  2922. if (Nr.Rows.Count > 0)
  2923. {
  2924. ShareRule = Nr.Rows[0]["nr_sharerule"].ToString();
  2925. 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");
  2926. if (dt1.Rows.Count > 0)
  2927. {
  2928. Nr = dt1;
  2929. }
  2930. else
  2931. {
  2932. if (ShareRule != "")
  2933. {
  2934. MessageBox.Show("共享规则" + ShareRule + "不存在");
  2935. return;
  2936. }
  2937. }
  2938. }
  2939. if (Nr.Rows.Count > 0)
  2940. {
  2941. switch (Nr.Rows[0]["nr_resettype"].ToString())
  2942. {
  2943. case "Year":
  2944. sql.Clear();
  2945. sql.Append("to_char(sysdate,'yyyy')");
  2946. break;
  2947. case "Month":
  2948. sql.Clear();
  2949. sql.Append("to_char(sysdate,'yyyyMM')");
  2950. break;
  2951. case "Week":
  2952. sql.Clear();
  2953. sql.Append("to_char(sysdate,'yyyyiw')");
  2954. break;
  2955. case "Day":
  2956. sql.Clear();
  2957. sql.Append("to_char(sysdate,'yyyyMMdd')");
  2958. break;
  2959. case " ":
  2960. sql.Clear();
  2961. sql.Append("' '");
  2962. break;
  2963. default:
  2964. break;
  2965. }
  2966. ReSetType = dh.getFieldDataByCondition("dual", sql.ToString(), "1=1").ToString();
  2967. }
  2968. Regex match = new Regex("{\\w+}");
  2969. //用于存放每一项的明细的数据
  2970. string[] NrData = new string[Nr.Rows.Count];
  2971. //流水长度
  2972. Dictionary<int, string> NrDic = new Dictionary<int, string>();
  2973. for (int m = 0; m < Nr.Rows.Count; m++)
  2974. {
  2975. NrCode = Nr.Rows[m]["nr_code"].ToString();
  2976. switch (Nr.Rows[m]["nrd_type"].ToString())
  2977. {
  2978. //常量直接进行拼接
  2979. case "常量":
  2980. Prefix += Nr.Rows[m]["nrd_sql"].ToString();
  2981. Suffix += Nr.Rows[m]["nrd_sql"].ToString();
  2982. break;
  2983. case "SQL":
  2984. string SQL = Nr.Rows[m]["nrd_sql"].ToString();
  2985. DataTable Temp;
  2986. //如果不包含参数替换
  2987. if (SQL.IndexOf("{") == 0)
  2988. {
  2989. Temp = (DataTable)dh.ExecuteSql(SQL, "select");
  2990. }
  2991. else
  2992. {
  2993. //替换参数后重新执行SQL
  2994. foreach (Match mch in match.Matches(SQL))
  2995. {
  2996. SQL = SQL.Replace(mch.Value.Trim(), "'" + pi_inoutno.Text + "'");
  2997. }
  2998. Temp = (DataTable)dh.ExecuteSql(SQL, "select");
  2999. }
  3000. if (Temp.Rows.Count > 0)
  3001. {
  3002. Prefix += Temp.Rows[0][0].ToString();
  3003. Suffix += Temp.Rows[0][0].ToString();
  3004. }
  3005. break;
  3006. //流水需要通过MaxNumber去取
  3007. case "流水":
  3008. string maxnum = "";
  3009. if (ReSetType != " ")
  3010. {
  3011. maxnum = dh.getFieldDataByConditionForUpdate("RuleMaxNum", "rmn_maxnumber", "rmn_nrcode='" + (NrCode == "" ? "Default" : NrCode) + "' and nvl(rmn_type,' ')='" + ReSetType + "'", "update of rmn_maxnumber nowait").ToString();
  3012. }
  3013. else
  3014. {
  3015. maxnum = dh.getFieldDataByConditionForUpdate("RuleMaxNum", "rmn_maxnumber", "rmn_nrcode='" + (NrCode == "" ? "Default" : NrCode) + "' and rmn_prefix='" + Prefix + "' ", "update of rmn_maxnumber nowait").ToString();
  3016. }
  3017. //设置当前流水
  3018. if (maxnum == "")
  3019. {
  3020. if (ReSetType != " ")
  3021. {
  3022. maxnum = dh.getFieldDataByConditionForUpdate("RuleMaxNum", "rmn_maxnumber", "rmn_nrcode='" + (NrCode == "" ? "Default" : NrCode) + "' and nvl(rmn_type,' ')='" + ReSetType + "'", "update of rmn_maxnumber nowait").ToString();
  3023. }
  3024. else
  3025. {
  3026. maxnum = dh.getFieldDataByConditionForUpdate("RuleMaxNum", "rmn_maxnumber", "rmn_nrcode='" + (NrCode == "" ? "Default" : NrCode) + "' and rmn_prefix='" + Prefix + "' ", "update of rmn_maxnumber nowait").ToString();
  3027. }
  3028. if (maxnum == "")
  3029. {
  3030. maxnum = "1";
  3031. }
  3032. Count = int.Parse(maxnum) + Count;
  3033. 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");
  3034. MaxNum = int.Parse(maxnum);
  3035. }
  3036. else
  3037. {
  3038. MaxNum = int.Parse(maxnum);
  3039. if (ReSetType != " ")
  3040. {
  3041. dh.UpdateByCondition("RULEMAXNUM", "rmn_maxnumber='" + (MaxNum + Count) + "'", "rmn_nrcode='" + (NrCode == "" ? "Default" : NrCode) + "' and nvl(rmn_type,' ')='" + ReSetType + "'");
  3042. }
  3043. else
  3044. {
  3045. dh.UpdateByCondition("RULEMAXNUM", "rmn_maxnumber='" + (MaxNum + Count) + "'", "rmn_nrcode='" + (NrCode == "" ? "Default" : NrCode) + "' and rmn_prefix='" + Prefix + "'");
  3046. }
  3047. }
  3048. SerialNumLength = int.Parse(Nr.Rows[m]["nrd_length"].ToString());
  3049. Radix = int.Parse(Nr.Rows[m]["nrd_radix"].ToString());
  3050. Suffix = "";
  3051. break;
  3052. default:
  3053. break;
  3054. }
  3055. }
  3056. }
  3057. }
  3058. }