UAS_出货标签管理.cs 132 KB

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