UAS_出货标签管理.cs 131 KB

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