UAS_出货标签管理.cs 130 KB

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