UAS_出货标签管理.cs 134 KB

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