InterfaceHelper.cs 113 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451
  1. using DirectService.Tools;
  2. using JLHHJSvr.BLL;
  3. using JLHHJSvr.Com;
  4. using JLHHJSvr.Com.Model;
  5. using JLHHJSvr.LJException;
  6. using JLHHJSvr.Tools;
  7. using LJLib.DAL.SQL;
  8. using Newtonsoft.Json.Linq;
  9. using System;
  10. using System.Collections.Generic;
  11. using System.Linq;
  12. using System.Text;
  13. using static JLHHJSvr.Helper.CacheHelper;
  14. namespace JLHHJSvr.Helper
  15. {
  16. internal class InterfaceHelper : HelperBase
  17. {
  18. /// <summary>
  19. /// 床垫接口-保存
  20. /// </summary>
  21. /// <param name="mattress"></param>
  22. /// <param name="mxlist"></param>
  23. /// <param name="qdlist"></param>
  24. /// <exception cref="LJCommonException"></exception>
  25. public void SaveMattressInterface(u_mattress mattress, List<u_mattress_interface> mxlist, List<u_mattress_interface_qd> qdlist)
  26. {
  27. if (mattress.mattressid <= 0)
  28. {
  29. throw new LJCommonException("错误的床垫id");
  30. }
  31. // 检查锁
  32. if (LockHelper.CheckIsLock(cmd, MattressHelper.BillKeyWord, mattress.mattressid, context.tokendata.username, out string arg_msg)) throw new LJCommonException(arg_msg);
  33. // 检测版本
  34. CheckBillVersion<u_mattress>(cmd, mattress.mattressid, mattress.version);
  35. mattress.version++;
  36. DbSqlHelper.Update(cmd, mattress, "erp_mtrlname,erp_mtrltypeid,erp_mtrlmode,erp_mtrltype,erp_mtrlunit,erp_mtrlengname,erp_configcodetype,old_mtrlname,version");
  37. // 床垫清单保存
  38. cmd.CommandText = @"DELETE u_mattress_interface WHERE mattressid = @mattressid";
  39. cmd.Parameters.Clear();
  40. cmd.Parameters.AddWithValue("@mattressid", mattress.mattressid);
  41. cmd.ExecuteNonQuery();
  42. cmd.CommandText = @"DELETE u_mattress_interface_qd WHERE mattressid = @mattressid";
  43. cmd.Parameters.Clear();
  44. cmd.Parameters.AddWithValue("@mattressid", mattress.mattressid);
  45. cmd.ExecuteNonQuery();
  46. foreach (var mx in mxlist)
  47. {
  48. mx.mattressid = mattress.mattressid;
  49. mx.actual_size = mx.actual_size ?? "";
  50. mx.sb_craft = mx.sb_craft ?? "";
  51. mx.actual_size_sb = mx.actual_size_sb ?? "";
  52. DbSqlHelper.Insert(cmd, mx, "mattressid,printid,itemname,bj_pzname,bj_namemx,actual_size,sb_craft,actual_size_sb,erp_pzid,bj_inputtype,ss_rate,ls_rate");
  53. }
  54. foreach (var mx in qdlist)
  55. {
  56. mx.mattressid = mattress.mattressid;
  57. DbSqlHelper.Insert(cmd, mx, "mattressid,printid,itemname,bj_pzname,bj_pzname_mx,bj_pzname_mx_mx,wip_type,mtrlid,erp_mtrlid,wrkgrpid,wrkgrpid2,useqty,dscrp,actual_useqty,qd_actual_size,qd_pfgroupqty,ss_rate,ls_rate,sh_rate,formulaid,wrkgrpcode1,wrkgrpcode2");
  58. }
  59. AutoUpdateBcp(mattress.mattressid);
  60. }
  61. #region 清单审核
  62. /// <summary>
  63. /// 产品补充审核
  64. /// </summary>
  65. /// <param name="mattressid"></param>
  66. /// <exception cref="LJCommonException"></exception>
  67. public void MattressJSAudit(int mattressid)
  68. {
  69. // 检查锁
  70. if (LockHelper.CheckIsLock(cmd, BillKeyWord, mattressid, context.tokendata.username, out string arg_msg)) throw new LJCommonException(arg_msg);
  71. var mattress = new u_mattress() { mattressid = mattressid };
  72. DbSqlHelper.SelectOne(cmd, mattress, "yw_flag,js1_flag,version");
  73. if (mattress.js1_flag == 1)
  74. {
  75. throw new LJCommonException("床垫已技术1审核,不能技术1审核!");
  76. }
  77. //if (mattress.yw_flag == 0)
  78. //{
  79. // throw new LJCommonException("床垫未业务审核,不能技术1审核!");
  80. //}
  81. mattress.js1_flag = 1;
  82. mattress.js1_auditingdate = context.opdate;
  83. mattress.js1_auditingrep = context.tokendata.username;
  84. mattress.version++;
  85. DbSqlHelper.Update(cmd, mattress, "js1_flag,js1_auditingdate,js1_auditingrep,version");
  86. }
  87. /// <summary>
  88. /// 产品补充撤审
  89. /// </summary>
  90. /// <param name="mattressid"></param>
  91. /// <exception cref="LJCommonException"></exception>
  92. public void MattressJSCancelAudit(int mattressid)
  93. {
  94. // 检查锁
  95. if (LockHelper.CheckIsLock(cmd, BillKeyWord, mattressid, context.tokendata.username, out string arg_msg)) throw new LJCommonException(arg_msg);
  96. var mattress = new u_mattress() { mattressid = mattressid };
  97. DbSqlHelper.SelectOne(cmd, mattress, "yw_flag,js1_flag,creatmtrl_flag");
  98. //if (mattress.creatmtrl_flag == 1)
  99. //{
  100. // throw new LJCommonException("床垫已生成产品,不能技术1撤审!");
  101. //}
  102. if (mattress.js1_flag == 0)
  103. {
  104. throw new LJCommonException("床垫未技术1撤审,不能技术1撤审!");
  105. }
  106. mattress.js1_flag = 0;
  107. mattress.js1_auditingdate = null;
  108. mattress.js1_auditingrep = string.Empty;
  109. mattress.version++;
  110. DbSqlHelper.Update(cmd, mattress, "js1_flag,js1_auditingdate,js1_auditingrep,version");
  111. }
  112. /// <summary>
  113. /// 清单补充审核
  114. /// </summary>
  115. /// <param name="mattressid"></param>
  116. /// <exception cref="LJCommonException"></exception>
  117. public void MattressJS2Audit(int mattressid)
  118. {
  119. // 检查锁
  120. if (LockHelper.CheckIsLock(cmd, BillKeyWord, mattressid, context.tokendata.username, out string arg_msg)) throw new LJCommonException(arg_msg);
  121. var mattress = new u_mattress() { mattressid = mattressid };
  122. DbSqlHelper.SelectOne(cmd, mattress, "js2_flag,version");
  123. if (mattress.js2_flag == 1)
  124. {
  125. throw new LJCommonException("床垫已技术2审核,不能技术2审核!");
  126. }
  127. mattress.js2_flag = 1;
  128. mattress.js2_auditingdate = context.opdate;
  129. mattress.js2_auditingrep = context.tokendata.username;
  130. mattress.version++;
  131. DbSqlHelper.Update(cmd, mattress, "js2_flag,js2_auditingdate,js2_auditingrep,version");
  132. }
  133. /// <summary>
  134. /// 清单补充撤审
  135. /// </summary>
  136. /// <param name="mattressid"></param>
  137. /// <exception cref="LJCommonException"></exception>
  138. public void MattressJS2CancelAudit(int mattressid)
  139. {
  140. // 检查锁
  141. if (LockHelper.CheckIsLock(cmd, BillKeyWord, mattressid, context.tokendata.username, out string arg_msg)) throw new LJCommonException(arg_msg);
  142. var mattress = new u_mattress() { mattressid = mattressid };
  143. DbSqlHelper.SelectOne(cmd, mattress, "js2_flag,version");
  144. if (mattress.js2_flag == 0)
  145. {
  146. throw new LJCommonException("床垫未技术2审核,不能技术2撤审!");
  147. }
  148. mattress.js2_flag = 0;
  149. mattress.js2_auditingdate = null;
  150. mattress.js2_auditingrep = string.Empty;
  151. mattress.version++;
  152. DbSqlHelper.Update(cmd, mattress, "js2_flag,js2_auditingdate,js2_auditingrep,version");
  153. }
  154. #endregion
  155. #region 保存半成品部件
  156. public void SaveMattressBcp(u_semi_finished_product mattress)
  157. {
  158. var dtNow = DateTime.Now;
  159. var fields = @"billdate,semi_finished_type,semi_finished_code,semi_finished_name,dscrp,production_size,hemming_process,
  160. hemmed_size,shrinkage_rate,elongation_rate,opemp,opdate,auditemp,auditdate";
  161. var fieldsMx = "billid,printid,mtrlid,formulaid,chastr,thickness,qty,erp_mtrlid,usenum,usedenom";
  162. if (mattress.billid <= 0)
  163. {
  164. //新建
  165. fields += ",billid,billcode";
  166. mattress.opdate = dtNow;
  167. mattress.opemp = context.tokendata.username;
  168. mattress.billid = BllHelper.GetID(cmd, "u_semi_finished_product");
  169. switch (mattress.semi_finished_type)
  170. {
  171. case 901:
  172. mattress.billcode = "JM";
  173. break;
  174. case 902:
  175. mattress.billcode = "JD";
  176. break;
  177. case 903:
  178. mattress.billcode = "BC";
  179. break;
  180. case 904:
  181. mattress.billcode = "XC";
  182. break;
  183. case 905:
  184. mattress.billcode = "VC";
  185. break;
  186. }
  187. // 编号-年月日+流水
  188. mattress.billcode = $"{mattress.billcode}-{dtNow.ToString("yyyyMMdd")}{(mattress.billid.Value % 10000).ToString("D4")}";
  189. DbSqlHelper.Insert(cmd, "u_semi_finished_product", null, mattress, fields);
  190. }
  191. else
  192. {
  193. //修改
  194. cmd.CommandText = @"DELETE FROM u_semi_finished_product_mx WHERE billid = @billid";
  195. cmd.Parameters.Clear();
  196. cmd.Parameters.AddWithValue("@billid", mattress.billid);
  197. cmd.ExecuteNonQuery();
  198. DbSqlHelper.Update(cmd, "u_semi_finished_product", null, mattress, "billid", fields);
  199. }
  200. var cnt = 0;
  201. foreach (var mx in mattress.mxlist)
  202. {
  203. AutoInit.AutoInitS(cmd, mx);
  204. mx.billid = mattress.billid;
  205. mx.printid = ++cnt;
  206. DbSqlHelper.Insert(cmd, "u_semi_finished_product_mx", null, mx, fieldsMx);
  207. }
  208. var hisprice = new u_his_price
  209. {
  210. bednetid_mattressid = mattress.billid,
  211. typeid = 2,
  212. cmpdate = dtNow,
  213. cmpemp = context.tokendata.username,
  214. nottax_dept_cost = 0,
  215. dept_cost = 0,
  216. foreign_cost = 0
  217. };
  218. var fieldsHs = "bednetid_mattressid, typeid, cmpdate, cmpemp, nottax_dept_cost, dept_cost, foreign_cost";
  219. DbSqlHelper.Insert(cmd, "u_his_price", null, hisprice, fieldsHs);
  220. }
  221. /// <summary>
  222. /// 自动更新半成品部件
  223. /// </summary>
  224. /// <param name="mattressid"></param>
  225. public void AutoUpdateBcp(int mattressid)
  226. {
  227. var qdList = new List<u_mattress_interface_qd>();
  228. var selectStr = @"
  229. SELECT u_mattress_interface_qd.mattressid
  230. ,u_mattress_interface_qd.printid
  231. ,u_mattress_interface_qd.itemname
  232. ,u_mattress_interface_qd.bj_pzname
  233. ,u_mattress_interface_qd.bj_pzname_mx
  234. ,u_mattress_interface_qd.bj_pzname_mx_mx
  235. ,u_mattress_interface_qd.mtrlid
  236. ,u_mattress_interface_qd.erp_mtrlid
  237. ,u_mattress_interface_qd.useqty
  238. ,u_mattress_interface_qd.dscrp
  239. ,u_mattress_interface_qd.actual_useqty
  240. ,u_mattress_interface_qd.qd_actual_size
  241. ,u_mattress_interface_qd.qd_pfgroupqty
  242. ,u_mattress_interface_qd.wrkgrpid
  243. ,u_mattress_interface_qd.ss_rate
  244. ,u_mattress_interface_qd.ls_rate
  245. ,u_mattress_interface_qd.sh_rate
  246. ,u_mattress_interface_qd.formulaid
  247. FROM u_mattress_interface_qd
  248. ";
  249. var whereList = new List<string>();
  250. whereList.Add("mattressid = @mattressid");
  251. var param = new Dictionary<string, object>();
  252. param.Add("@mattressid", mattressid);
  253. var outFields = "mattressid, printid, itemname, bj_pzname, bj_pzname_mx, bj_pzname_mx_mx, mtrlid, erp_mtrlid, useqty, dscrp, actual_useqty, qd_actual_size, qd_pfgroupqty, wrkgrpid, ss_rate, ls_rate, sh_rate, formulaid";
  254. DbSqlHelper.SelectJoin(cmd, selectStr, ListEx.GetWhereStr(whereList), param, "printid", outFields, 0, 0, qdList);
  255. var chastrArr = new List<string>() { "裥面", "裥底", "顶布裥棉", "大侧", "小侧", "V侧" };
  256. var chastrType = new Dictionary<string, int>();
  257. Dictionary<string, List<u_mattress_interface_qd>> bcpQdlist = new Dictionary<string, List<u_mattress_interface_qd>>();
  258. foreach (var mx in qdList)
  259. {
  260. if (chastrArr.Contains(mx.itemname) && !string.IsNullOrEmpty(mx.bj_pzname_mx_mx))
  261. {
  262. if (!chastrType.ContainsKey(mx.bj_pzname_mx_mx))
  263. {
  264. switch (mx.itemname)
  265. {
  266. case "裥面":
  267. chastrType.Add(mx.bj_pzname_mx_mx, 901);
  268. mx.billtype = 901;
  269. break;
  270. case "裥底":
  271. chastrType.Add(mx.bj_pzname_mx_mx, 902);
  272. mx.billtype = 902;
  273. break;
  274. case "大侧":
  275. chastrType.Add(mx.bj_pzname_mx_mx, 903);
  276. mx.billtype = 903;
  277. break;
  278. case "小侧":
  279. chastrType.Add(mx.bj_pzname_mx_mx, 904);
  280. mx.billtype = 904;
  281. break;
  282. case "V侧":
  283. chastrType.Add(mx.bj_pzname_mx_mx, 905);
  284. mx.billtype = 905;
  285. break;
  286. }
  287. }
  288. if (!bcpQdlist.ContainsKey(mx.bj_pzname_mx_mx))
  289. {
  290. List<u_mattress_interface_qd> list = new List<u_mattress_interface_qd>();
  291. list.Add(mx);
  292. bcpQdlist.Add(mx.bj_pzname_mx_mx, list);
  293. }
  294. else
  295. {
  296. bcpQdlist[mx.bj_pzname_mx_mx].Add(mx);
  297. }
  298. }
  299. }
  300. foreach (var mx in bcpQdlist)
  301. {
  302. var billid = 0;
  303. cmd.CommandText = @"SELECT TOP 1 billid
  304. FROM u_semi_finished_product
  305. WHERE semi_finished_name = @semi_finished_name";
  306. cmd.Parameters.Clear();
  307. cmd.Parameters.AddWithValue("@semi_finished_name", mx.Key);
  308. using (var reader = cmd.ExecuteReader())
  309. {
  310. if (reader.Read())
  311. {
  312. billid = Convert.ToInt32(reader["billid"]);
  313. }
  314. }
  315. if (billid == 0)
  316. {
  317. //创建
  318. var bcpMattress = new u_semi_finished_product() { billid = 0 };
  319. AutoInit.AutoInitS(cmd, bcpMattress);
  320. bcpMattress.billid = 0;
  321. bcpMattress.billdate = DateTime.Now;
  322. bcpMattress.dscrp = "自动生成,来自mattressid:" + mattressid;
  323. //bcpMattress.production_size = DateTime.Now;
  324. //bcpMattress.hemming_process = DateTime.Now;
  325. //bcpMattress.hemmed_size = DateTime.Now;
  326. //bcpMattress.shrinkage_rate = DateTime.Now;
  327. //bcpMattress.elongation_rate = DateTime.Now;
  328. bcpMattress.opemp = context.tokendata.username;
  329. bcpMattress.opdate = DateTime.Now;
  330. bcpMattress.semi_finished_type = chastrType[mx.Key];
  331. bcpMattress.semi_finished_code = mx.Key;
  332. bcpMattress.semi_finished_name = mx.Key;
  333. var bcpMxList = new List<u_semi_finished_product_mx>();
  334. foreach (var qdmx in mx.Value)
  335. {
  336. var bcpmx = new u_semi_finished_product_mx()
  337. {
  338. mtrlid = qdmx.mtrlid.Value,
  339. erp_mtrlid = qdmx.erp_mtrlid,
  340. formulaid = qdmx.formulaid
  341. };
  342. bcpMxList.Add(bcpmx);
  343. }
  344. bcpMattress.mxlist = bcpMxList;
  345. SaveMattressBcp(bcpMattress);
  346. }
  347. else
  348. {
  349. // 判断不一样,就覆盖
  350. selectStr = @"
  351. SELECT u_semi_finished_product_mx.billid
  352. ,u_semi_finished_product_mx.printid
  353. ,u_semi_finished_product_mx.mtrlid
  354. ,u_semi_finished_product_mx.formulaid
  355. ,u_semi_finished_product_mx.chastr
  356. ,u_semi_finished_product_mx.thickness
  357. ,u_semi_finished_product_mx.qty
  358. ,u_semi_finished_product_mx.erp_mtrlid
  359. ,u_semi_finished_product_mx.usenum
  360. ,u_semi_finished_product_mx.usedenom
  361. FROM u_semi_finished_product_mx
  362. ";
  363. var bcpMxList = new List<u_semi_finished_product_mx>();
  364. whereList = new List<string>();
  365. whereList.Add("u_semi_finished_product_mx.billid = @billid");
  366. param.Clear();
  367. param.Add("@billid", billid);
  368. outFields = "billid, printid, mtrlid, formulaid, chastr, thickness, qty, erp_mtrlid, usenum, usedenom, mtrlname, if_mtrl, formula, formulatype, formulakind";
  369. DbSqlHelper.SelectJoin(cmd, selectStr, ListEx.GetWhereStr(whereList), param, "formulatype, sortcode", outFields, 0, 0, bcpMxList);
  370. var ErpMtrlids = "";
  371. var BcpErpMtrlids = "";
  372. foreach (var qdmx in mx.Value)
  373. {
  374. ErpMtrlids += qdmx.erp_mtrlid + "+";
  375. }
  376. foreach (var qdmx in bcpMxList)
  377. {
  378. BcpErpMtrlids += qdmx.erp_mtrlid + "+";
  379. }
  380. if (ErpMtrlids != BcpErpMtrlids)
  381. {
  382. var bcpMattress = new u_semi_finished_product() { billid = billid };
  383. DbSqlHelper.SelectOne(cmd, bcpMattress, "billid, billdate, flag, semi_finished_type, semi_finished_code, semi_finished_name, dscrp, production_size, hemming_process, hemmed_size, shrinkage_rate, elongation_rate, opemp, opdate, auditemp, auditdate");
  384. bcpMattress.billid = billid;
  385. bcpMattress.auditemp = context.tokendata.username;
  386. bcpMattress.auditdate = DateTime.Now;
  387. foreach (var qdmx in bcpMxList)
  388. {
  389. var mtrlid = 0;
  390. var formulaid = 0;
  391. var arr = mx.Value.Where((itm) => itm.mtrlid == qdmx.mtrlid).ToList();
  392. if (arr.Count > 0)
  393. {
  394. mtrlid = arr[0].erp_mtrlid.Value;
  395. if (arr[0].formulaid != null) formulaid = arr[0].formulaid.Value;
  396. }
  397. qdmx.erp_mtrlid = mtrlid;
  398. qdmx.formulaid = formulaid;
  399. }
  400. bcpMattress.mxlist = bcpMxList;
  401. SaveMattressBcp(bcpMattress);
  402. }
  403. }
  404. }
  405. }
  406. #endregion
  407. public void AutoSetMtrlName(u_mattress mattress, List<u_mattress_interface> mxlist)
  408. {
  409. string mtrltypename = string.Empty, mtrltypecode = string.Empty;
  410. string mattresstypename = string.Empty, mattresstypecode = string.Empty;
  411. string packtypename = string.Empty, packtypecode = string.Empty;
  412. var materialCodes = new Dictionary<string, string>
  413. {
  414. { "两边单层", "21" },
  415. { "两边直出", "23" },
  416. { "三边加顶", "32" },
  417. { "三边直出", "33" },
  418. { "假三边", "34" },
  419. { "拉假边", "3C" },
  420. { "假三边加顶", "42" },
  421. { "上下假三边", "44" },
  422. { "四边双顶", "45" },
  423. { "四边顶上顶", "46" },
  424. { "四边假分体", "47" }
  425. };
  426. var mattressTypeCodes = new Dictionary<string, string>
  427. {
  428. { "袋装网", "P" },
  429. { "拉丝网", "C" },
  430. { "圆网", "B" }
  431. };
  432. var packTypeCodes = new Dictionary<string, string>
  433. {
  434. { "平压", "A" },
  435. { "卷包", "B" }
  436. };
  437. foreach (var mx in mxlist)
  438. {
  439. if (mx.bj_pzname.IndexOf("床垫类别") > -1)
  440. {
  441. mtrltypename = mx.bj_namemx;
  442. break;
  443. }
  444. }
  445. foreach (var mx in mxlist)
  446. {
  447. if (mx.bj_pzname.IndexOf("床网") > -1)
  448. {
  449. mattresstypename = mx.bj_namemx;
  450. break;
  451. }
  452. }
  453. foreach (var mx in mxlist)
  454. {
  455. if (mx.bj_pzname.IndexOf("包装方式") > -1)
  456. {
  457. packtypename = mx.bj_namemx;
  458. break;
  459. }
  460. }
  461. mtrltypecode = materialCodes.ContainsKey(mtrltypename) ? materialCodes[mtrltypename] : "99";
  462. mattresstypecode = mattressTypeCodes.ContainsKey(mtrltypename) ? mattressTypeCodes[mtrltypename] : "Z";
  463. packtypecode = packTypeCodes.ContainsKey(mtrltypename) ? packTypeCodes[mtrltypename] : "J";
  464. // 获取mxlist最后一项
  465. if (mattress.mattressid > 0)
  466. {
  467. mattress.erp_mtrlname = new StringBuilder().Append(mtrltypecode).Append(mattresstypecode).Append(packtypecode).ToString();
  468. }
  469. }
  470. public List<u_mattress_interface> GetMattressInterfaceList(int mattressid, int? configuretype)
  471. {
  472. var interfaceList = new List<u_mattress_interface>();
  473. var selectStr = @"SELECT mattressid
  474. ,printid
  475. ,itemname
  476. ,bj_pzname
  477. ,bj_namemx
  478. ,actual_size
  479. ,sb_craft
  480. ,actual_size_sb
  481. ,erp_pzid
  482. ,ss_rate
  483. ,ls_rate
  484. ,bj_inputtype
  485. FROM u_mattress_interface";
  486. DbSqlHelper.SelectJoin(cmd, selectStr, "mattressid = @mattressid", new Dictionary<string, object>() { { "@mattressid", mattressid } }, "printid", "mattressid,printid,itemname,bj_pzname,bj_namemx,actual_size,sb_craft,actual_size_sb,erp_pzid,ss_rate,ls_rate,bj_inputtype", 0, 0, interfaceList);
  487. if(interfaceList.Count <= 0)
  488. {
  489. interfaceList = RefreshMattressInterfaceList(mattressid, configuretype);
  490. foreach (var itm in interfaceList)
  491. {
  492. itm.mattressid = mattressid;
  493. itm.actual_size = itm.actual_size ?? "";
  494. itm.actual_size_sb = itm.actual_size_sb ?? "";
  495. itm.sb_craft = itm.sb_craft ?? "";
  496. itm.ss_rate = itm.ss_rate ?? 0;
  497. itm.ls_rate = itm.ls_rate ?? 0;
  498. }
  499. } else
  500. {
  501. MattressInterfaceFindERPPz(mattressid, interfaceList, configuretype);
  502. }
  503. return interfaceList;
  504. }
  505. public List<u_mattress_interface_qd> GetMattressInterfaceQdList(int mattressid)
  506. {
  507. var qdList = new List<u_mattress_interface_qd>();
  508. var selectStr = @"SELECT u_mattress_interface_qd.mattressid
  509. ,u_mattress_interface_qd.printid
  510. ,u_mattress_interface_qd.itemname
  511. ,u_mattress_interface_qd.bj_pzname
  512. ,u_mattress_interface_qd.bj_pzname_mx
  513. ,u_mattress_interface_qd.bj_pzname_mx_mx
  514. ,u_mattress_interface_qd.wip_type
  515. ,u_mattress_interface_qd.mtrlid
  516. ,u_mattress_interface_qd.erp_mtrlid
  517. ,u_mattress_interface_qd.useqty
  518. ,u_mattress_interface_qd.dscrp
  519. ,u_mtrl_price.name AS mtrlname
  520. ,u_mattress_interface_qd.actual_useqty
  521. ,u_mattress_interface_qd.qd_actual_size
  522. ,u_mattress_interface_qd.qd_pfgroupqty
  523. ,u_mattress_interface_qd.wrkgrpid
  524. ,u_mattress_interface_qd.wrkgrpcode1
  525. ,u_mattress_interface_qd.wrkgrpcode2
  526. ,u_mattress_interface_qd.wrkgrpid2
  527. ,u_mattress_interface_qd.ss_rate
  528. ,u_mattress_interface_qd.ls_rate
  529. ,u_mattress_interface_qd.sh_rate
  530. ,u_mattress_interface_qd.formulaid
  531. FROM u_mattress_interface_qd
  532. LEFT JOIN u_mtrl_price ON u_mtrl_price.mtrlid = u_mattress_interface_qd.mtrlid";
  533. var outputFields = "mattressid,printid,itemname,bj_pzname,bj_pzname_mx,bj_pzname_mx_mx,wip_type,mtrlid,erp_mtrlid,useqty,dscrp,mtrlname,actual_useqty,qd_actual_size,qd_pfgroupqty,wrkgrpid,wrkgrpid2,ss_rate,ls_rate,sh_rate,wrkgrpcode1,wrkgrpcode2";
  534. DbSqlHelper.SelectJoin(cmd, selectStr, "mattressid = @mattressid", new Dictionary<string, object>() { { "@mattressid", mattressid } }, "printid", outputFields, 0, 0, qdList);
  535. if (qdList.Count <= 0)
  536. {
  537. qdList = RefreshMattressInterfaceQdList(mattressid);
  538. }
  539. return qdList;
  540. }
  541. #region 导入配置方法
  542. /// <summary>
  543. /// 刷新带出配置
  544. /// </summary>
  545. /// <param name="mattressid"></param>
  546. /// <returns></returns>
  547. public List<u_mattress_interface> RefreshMattressInterfaceList(int mattressid, int? configcodetype = 0)
  548. {
  549. var interfaceList = new List<u_mattress_interface>();
  550. // 导入配置
  551. ImportMattressInterfaceList(mattressid, interfaceList);
  552. MattressInterfaceFindERPPz(mattressid, interfaceList, configcodetype);
  553. return interfaceList;
  554. }
  555. /// <summary>
  556. /// 导入产品配置
  557. /// </summary>
  558. /// <param name="mattressid"></param>
  559. /// <exception cref="LJCommonException"></exception>
  560. public void ImportMattressInterfaceList(int mattressid, List<u_mattress_interface> interfaceList)
  561. {
  562. if (mattressid <= 0)
  563. {
  564. throw new LJCommonException("床垫id有误");
  565. }
  566. var mattressHelper = GetHelper<MattressHelper>(cmd, new HelperBase.Context() { tokendata = context.tokendata });
  567. var mattress = mattressHelper.GetMattress(mattressid);
  568. var mattress_type = new u_mattress_type() { mattresstypeid = mattress.mattresstypeid };
  569. DbSqlHelper.SelectOne(cmd, mattress_type, "typename");
  570. var mxlist_all = mattressHelper.GetMattressMxMtrl(mattressid, new List<string>() { "u_mattress_formula.formulatype IN (0,1,2,3,99,101,104,103)" });
  571. mattressHelper.wf_sort_mx(ref mxlist_all);
  572. var mxlist = mxlist_all.Where(t => new[]{ 0, 1, 2, 3, 99, 104, 103 }.Contains(t.formulatype.Value)).ToList();
  573. var mxlist_103 = mxlist_all.Where(t => t.formulatype == 103).ToList();
  574. var mxlist_101 = mxlist_all.Where(t => t.formulatype == 101).ToList();
  575. // 高度
  576. interfaceList.Add(InserMattressInterfacePz("床垫", "高度", 2, new string[] { $"{mattress.mattress_height}" }));
  577. // 参考外观
  578. interfaceList.Add(InserMattressInterfacePz("床垫", "参考外观", 1, new string[] { "" }));
  579. // 尺寸
  580. mattress.erp_mtrlcode = $"{mattress.mattress_width}*{mattress.mattress_length}*{mattress.mattress_height}";
  581. interfaceList.Add(InserMattressInterfacePz("床垫", "尺寸", 2, new string[] { mattress.erp_mtrlcode }));
  582. // 床垫类别
  583. interfaceList.Add(InserMattressInterfacePz("床垫", "床垫类别", 2, new string[] { mattress_type.typename }));
  584. // 拆装类型
  585. var name_arr = new string[1];
  586. name_arr[0] = string.Empty;
  587. if (mattress.if_m_chai == 1) name_arr[0] = AppendToString(name_arr[0], "面拆");
  588. if (mattress.if_z_chai == 1) name_arr[0] = AppendToString(name_arr[0], "中拆");
  589. if (mattress.if_d_chai == 1) name_arr[0] = AppendToString(name_arr[0], "底拆");
  590. interfaceList.Add(InserMattressInterfacePz("床垫", "拆装类型", 1, name_arr));
  591. // 床垫分类
  592. name_arr[0] = string.Empty;
  593. if (mattress.if_haimian_type == 1) name_arr[0] = AppendToString(name_arr[0], "海绵床垫");
  594. else name_arr[0] = AppendToString(name_arr[0], "弹簧床垫");
  595. if (mattress.if_zhedie_type == 1) name_arr[0] = AppendToString(name_arr[0], "折叠床垫");
  596. interfaceList.Add(InserMattressInterfacePz("床垫", "床垫分类", 1, name_arr));
  597. // 外观布套做法
  598. name_arr[0] = string.Empty;
  599. if (mattress.if_m_wbutao_way == 1) name_arr[0] = AppendToString(name_arr[0], $"面层向大侧覆盖{mattress.s_m_cover_qty}CM、大侧向底层覆盖{mattress.z_m_cover_qty}CM、底层向大侧覆盖{mattress.x_m_cover_qty}CM");
  600. interfaceList.Add(InserMattressInterfacePz("床垫", "外观布套做法", 1, name_arr));
  601. // 边带
  602. name_arr[0] = string.Empty;
  603. interfaceList.Add(InserMattressInterfacePz("床垫", "边带", 0, name_arr));
  604. #region 面料类清单导入 AutoSetFormulaTypeZeroPz()需要优化
  605. AutoSetFormulaTypeZeroPz(mxlist, interfaceList);
  606. interfaceList.Add(InserMattressInterfacePz("车位说明", "车位说明", 1, name_arr));
  607. #endregion
  608. #region 垫层类清单导入
  609. AutoSetFormulaTypeOnePz(mxlist, interfaceList);
  610. #endregion
  611. #region 辅料类清单导入
  612. AutoSetFormulaTypeTwoPz(mxlist, interfaceList);
  613. #endregion
  614. #region 包装类清单导入
  615. AutoSetFormulaTypeThreePz(mattress, mxlist, interfaceList);
  616. #endregion
  617. #region 内布套类清单导入
  618. AutoSetFormulaType101Pz(mattress, mxlist_101, interfaceList);
  619. #endregion
  620. #region 自定义配置导入
  621. if(mattress.erp_configcodetype != null && mattress.erp_configcodetype > 0)
  622. {
  623. var erpHelper = HelperBase.GetHelper<ERPHelper>(null);
  624. var parameters = new JObject();
  625. parameters.Add("dsname", "web_configure_code_list");
  626. var queryparams = new JObject();
  627. queryparams.Add("arg_configcodetype", mattress.erp_configcodetype);
  628. queryparams.Add("arg_ifpack", 1);
  629. parameters.Add("queryparams", queryparams);
  630. var resultList = erpHelper.GetERPList<erp_configure_code>("CommonDynamicSelect", parameters);
  631. foreach(var result in resultList)
  632. {
  633. var pzname = result.name;
  634. interfaceList.Add(InserMattressInterfacePz("自定义", pzname, 1, new string[] { "" }));
  635. }
  636. }
  637. #endregion
  638. }
  639. public void MattressInterfaceFindERPPz(int mattressid, List<u_mattress_interface> interfaceList, int? configcodetype = 0)
  640. {
  641. var mattress = new u_mattress() { mattressid = mattressid };
  642. if (configcodetype != 0)
  643. {
  644. mattress.erp_configcodetype = configcodetype;
  645. } else
  646. {
  647. DbSqlHelper.SelectOne(cmd, mattress, "erp_configcodetype");
  648. }
  649. MattressInterfaceFindERPPz(mattress, interfaceList);
  650. }
  651. public void MattressInterfaceFindERPPz(u_mattress mattress,List<u_mattress_interface> interfaceList)
  652. {
  653. InterfaceFindERPPz(mattress.erp_configcodetype.Value, interfaceList);
  654. }
  655. public u_mattress_interface InserMattressInterfacePz(string itemname, string bj_pzname, byte inputtype, string[] names)
  656. {
  657. return InserInterfacePz<u_mattress_interface>(itemname,bj_pzname,inputtype,names);
  658. }
  659. private string SetInterfacePzName(string[] names)
  660. {
  661. var result = string.Empty;
  662. foreach (var name in names)
  663. {
  664. if (string.IsNullOrEmpty(name)) continue;
  665. result = AppendToString(result, name);
  666. }
  667. return result;
  668. }
  669. private void AutoSetFormulaTypeZeroPz(List<u_mattress_mx_mtrl> mxlist, List<u_mattress_interface> interfaceList)
  670. {
  671. var powerDict = new Dictionary<string, int[]>()
  672. {
  673. {"面裥绵",new int[] { 0, 40, 50, 60, 70, 80 } },
  674. {"底裥绵",new int[] { 1, 41, 51, 61, 71, 81 } },
  675. {"顶布裥棉1",new int[] { 0, 40, 50, 60, 70, 80 } },
  676. {"顶布裥棉2",new int[] { 0, 40, 50, 60, 70, 80 } },
  677. {"顶布裥棉3",new int[] { 0, 40, 50, 60, 70, 80 } },
  678. {"顶布裥棉4",new int[] { 0, 40, 50, 60, 70, 80 } },
  679. {"普通大侧",new int[] { 2, 42, 52, 62, 72, 82 } },
  680. {"上下拼侧1",new int[] { 2, 42, 52, 62, 72, 82 } },
  681. {"上下拼侧2",new int[] { 2, 42, 52, 62, 72, 82 } },
  682. {"上下拼侧3",new int[] { 2, 42, 52, 62, 72, 82 } },
  683. {"左右拼侧1",new int[] { 2, 42, 52, 62, 72, 82 } },
  684. {"左右拼侧2",new int[] { 2, 42, 52, 62, 72, 82 } },
  685. {"左右拼侧3",new int[] { 2, 42, 52, 62, 72, 82 } },
  686. {"小侧1_EMPTY",new int[] { 3, 43, 53, 63, 73, 83 } },
  687. {"小侧1",new int[] { 3, 43, 53, 63, 73, 83 } },
  688. {"小侧1-上下拼侧1",new int[] { 3, 43, 53, 63, 73, 83 } },
  689. {"小侧1-上下拼侧2",new int[] { 3, 43, 53, 63, 73, 83 } },
  690. {"小侧1-上下拼侧3",new int[] { 3, 43, 53, 63, 73, 83 } },
  691. {"小侧2",new int[] { 3, 43, 53, 63, 73, 83 } },
  692. {"小侧3",new int[] { 3, 43, 53, 63, 73, 83 } },
  693. {"V侧1_EMPTY",new int[] { 4, 44, 54, 64, 74, 84 } },
  694. {"V侧1",new int[] { 4, 44, 54, 64, 74, 84 } },
  695. {"V侧2",new int[] { 4, 44, 54, 64, 74, 84 } },
  696. {"V侧3",new int[] { 4, 44, 54, 64, 74, 84 } }
  697. };
  698. var chastrArrDict = new Dictionary<string, string[]>()
  699. {
  700. {"面裥绵",new string[] { "裥面", "面层裥棉", "面层裥棉图案", "面层裥面说明" } },
  701. {"底裥绵",new string[] { "裥底", "底层裥棉", "底层裥棉图案", "底层裥棉说明" } },
  702. {"顶布裥棉1",new string[] { "顶布裥棉", "", "顶布裥棉1图案", "顶布裥棉1说明" } },
  703. {"顶布裥棉2",new string[] { "顶布裥棉", "", "顶布裥棉2图案", "顶布裥棉2说明" } },
  704. {"顶布裥棉3",new string[] { "顶布裥棉", "", "顶布裥棉3图案", "顶布裥棉3说明" } },
  705. {"顶布裥棉4",new string[] { "顶布裥棉","", "顶布裥棉4图案", "顶布裥棉4说明" } },
  706. {"普通大侧",new string[] { "大侧", "大侧裥棉", "大侧裥棉图案" } },
  707. {"上下拼侧1",new string[] {"大侧", "大侧-上下拼侧1", "大侧-上下拼侧1裥棉图案", "大侧-上下拼侧1高度"} },
  708. {"上下拼侧2",new string[] { "大侧", "大侧-上下拼侧2", "大侧-上下拼侧2裥棉图案", "大侧-上下拼侧2高度" } },
  709. {"上下拼侧3",new string[] { "大侧", "大侧-上下拼侧3", "大侧-上下拼侧3裥棉图案", "大侧-上下拼侧3高度" } },
  710. {"左右拼侧1",new string[] { "大侧", "大侧-左右拼侧1", "大侧-左右拼侧1裥棉图案", "大侧-左右拼侧1长度" } },
  711. {"左右拼侧2",new string[] { "大侧", "大侧-左右拼侧2", "大侧-左右拼侧2裥棉图案", "大侧-左右拼侧2长度" } },
  712. {"左右拼侧3",new string[] { "大侧", "大侧-左右拼侧3", "大侧-左右拼侧3裥棉图案", "大侧-左右拼侧3长度", "大侧说明" } },
  713. {"小侧1_EMPTY",new string[] { "小侧", "小侧1裥棉", "小侧1裥棉图案" } },
  714. {"小侧1",new string[] { "小侧", "小侧1裥棉", "小侧1裥棉图案" } },
  715. {"小侧1-上下拼侧1",new string[] { "小侧", "小侧1-上下拼侧1裥棉", "小侧1-上下拼侧1裥棉图案" } },
  716. {"小侧1-上下拼侧2",new string[] { "小侧", "小侧1-上下拼侧2裥棉", "小侧1-上下拼侧2裥棉图案" } },
  717. {"小侧1-上下拼侧3",new string[] { "小侧", "小侧1-上下拼侧3裥棉", "小侧1-上下拼侧3裥棉图案" } },
  718. {"小侧2",new string[] { "小侧", "小侧2裥棉", "小侧2裥棉图案" } },
  719. {"小侧3",new string[] { "小侧", "小侧3裥棉", "小侧3裥棉图案", "小侧说明" } },
  720. {"V侧1_EMPTY",new string[] { "V侧", "V侧1裥棉", "V侧1裥棉图案" } },
  721. {"V侧1",new string[] { "V侧", "V侧1裥棉", "V侧1裥棉图案" } },
  722. {"V侧2",new string[] { "V侧", "V侧2裥棉", "V侧2裥棉图案" } },
  723. {"V侧3",new string[] { "V侧", "V侧3裥棉", "V侧3裥棉图案", "V侧说明" } }
  724. };
  725. var jianmianList = mxlist.Where(t => t.formulatype == 0).ToList();
  726. var dingbuList = mxlist.Where(t => t.formulatype == 103).ToList();
  727. #region wf_import_qingdan + wf_import_qingdan_1 面料部分
  728. foreach (var item in powerDict)
  729. {
  730. if(item.Key.Contains("顶布裥棉")) SetFormulaTypeZeroPz(dingbuList, interfaceList, item.Value, item.Key, chastrArrDict[item.Key]);
  731. else SetFormulaTypeZeroPz(jianmianList, interfaceList, item.Value, item.Key, chastrArrDict[item.Key]);
  732. }
  733. #endregion
  734. #region wf_import_qingdan_next 面料部分
  735. // 拉手
  736. var lashouList = jianmianList.Where(t => t.formulakind == 5).ToList();
  737. for (int i = 0; i < lashouList.Count; i++)
  738. {
  739. var mx = lashouList[i];
  740. if (string.IsNullOrEmpty(mx.chastr) && mx.mtrlid > 0)
  741. {
  742. interfaceList.Add(InserMattressInterfacePz("拉手刺绣及其他工艺", $"拉手{i + 1}做法", 1, new string[] { $"{mx.qty.Value.ToString("#,##0.0#")}只{mx.mtrlname}" }));
  743. interfaceList.Add(InserMattressInterfacePz("拉手刺绣及其他工艺", $"拉手{i + 1}刺绣", 0, new string[] { "" }));
  744. }
  745. }
  746. // 刺绣
  747. var cixiuList = jianmianList.Where(t => t.formulakind == 6).ToList();
  748. var ls_temp_cnt = 0;
  749. for (int i = 0; i < cixiuList.Count; i++)
  750. {
  751. var mx = cixiuList[i];
  752. if (string.IsNullOrEmpty(mx.chastr) && mx.mtrlid > 0)
  753. {
  754. for (int k = 0; k < mx.qty; k++)
  755. {
  756. ls_temp_cnt++;
  757. interfaceList.Add(InserMattressInterfacePz("拉手刺绣及其他工艺", $"侧刺绣{ls_temp_cnt}做法", 1, new string[] { "" }));
  758. interfaceList.Add(InserMattressInterfacePz("拉手刺绣及其他工艺", $"侧刺绣{ls_temp_cnt}位置", 0, new string[] { "" }));
  759. }
  760. }
  761. }
  762. // 大侧压压布
  763. var dcyybList = jianmianList.Where(t => t.formulakind == 7).ToList();
  764. for (int i = 0; i < dcyybList.Count; i++)
  765. {
  766. var mx = dcyybList[i];
  767. if (string.IsNullOrEmpty(mx.chastr) && mx.mtrlid > 0)
  768. {
  769. interfaceList.Add(InserMattressInterfacePz("拉手刺绣及其他工艺", $"大侧压压布{i + 1}", 1, new string[] { $"{mx.qty.Value.ToString("#,##0.0#")}米{mx.mtrlname}" }));
  770. }
  771. }
  772. // 大侧压边带
  773. var dcybdList = jianmianList.Where(t => t.formulakind == 8).ToList();
  774. for (int i = 0; i < dcybdList.Count; i++)
  775. {
  776. var mx = dcybdList[i];
  777. if (string.IsNullOrEmpty(mx.chastr) && mx.mtrlid > 0)
  778. {
  779. interfaceList.Add(InserMattressInterfacePz("拉手刺绣及其他工艺", $"大侧压边带{i + 1}", 1, new string[] { $"{mx.qty.Value.ToString("#,##0.0#")}米{mx.mtrlname}" }));
  780. }
  781. }
  782. // 大侧压织带
  783. var dcyzdList = jianmianList.Where(t => t.formulakind == 9).ToList();
  784. for (int i = 0; i < dcyzdList.Count; i++)
  785. {
  786. var mx = dcyzdList[i];
  787. if (string.IsNullOrEmpty(mx.chastr) && mx.mtrlid > 0)
  788. {
  789. interfaceList.Add(InserMattressInterfacePz("拉手刺绣及其他工艺", $"大侧压织带{i + 1}", 1, new string[] { $"{mx.qty.Value.ToString("#,##0.0#")}米{mx.mtrlname}" }));
  790. }
  791. }
  792. // 大侧压上下压线
  793. var dcysxyxList = jianmianList.Where(t => t.formulakind == 10).ToList();
  794. for (int i = 0; i < dcysxyxList.Count; i++)
  795. {
  796. var mx = dcysxyxList[i];
  797. if (string.IsNullOrEmpty(mx.chastr) && mx.mtrlid > 0)
  798. {
  799. interfaceList.Add(InserMattressInterfacePz("拉手刺绣及其他工艺", $"大侧压上下压线{i + 1}", 1, new string[] { $"{mx.qty.Value.ToString("#,##0.0#")}米{mx.mtrlname}" }));
  800. }
  801. }
  802. // 车花边
  803. var chbList = jianmianList.Where(t => t.formulakind == 205).ToList();
  804. for (int i = 0; i < chbList.Count; i++)
  805. {
  806. var mx = chbList[i];
  807. if (string.IsNullOrEmpty(mx.chastr) && mx.mtrlid > 0)
  808. {
  809. interfaceList.Add(InserMattressInterfacePz("拉手刺绣及其他工艺", "车花边", 1, new string[] { $"{mx.qty.Value.ToString("#,##0.0#")}米{mx.mtrlname}" }));
  810. }
  811. }
  812. // 防火线
  813. var fhxList = jianmianList.Where(t => t.formulakind == 30).ToList();
  814. for (int i = 0; i < fhxList.Count; i++)
  815. {
  816. var mx = fhxList[i];
  817. if (string.IsNullOrEmpty(mx.chastr) && mx.mtrlid > 0)
  818. {
  819. interfaceList.Add(InserMattressInterfacePz("拉手刺绣及其他工艺", "防火线", 1, new string[] { mx.mtrlname }));
  820. }
  821. }
  822. // 拉链
  823. var llList = jianmianList.Where(t => t.formulakind == 202 && string.IsNullOrEmpty(t.chastr) && t.mtrlid > 0).ToList();
  824. for (int i = 0; i < llList.Count; i++)
  825. {
  826. var mx = llList[i];
  827. if (llList.Count > 1)
  828. {
  829. interfaceList.Add(InserMattressInterfacePz("拉手刺绣及其他工艺", "拉链" + (i+1), 1, new string[] { $"{mx.qty.Value.ToString("#,##0.0#")}米{mx.mtrlname}" }));
  830. }
  831. else
  832. {
  833. interfaceList.Add(InserMattressInterfacePz("拉手刺绣及其他工艺", "拉链", 1, new string[] { $"{mx.qty.Value.ToString("#,##0.0#")}米{mx.mtrlname}" }));
  834. }
  835. }
  836. #endregion
  837. }
  838. private void SetFormulaTypeZeroPz(List<u_mattress_mx_mtrl> mxlist, List<u_mattress_interface> interfaceList, int[] powerArr, string key, string[] chastrArr)
  839. {
  840. var mianList1 = new HashSet<string> { "面裥绵", "底裥绵" };
  841. var mianList2 = new string[4] { "顶布裥棉1", "顶布裥棉2", "顶布裥棉3", "顶布裥棉4" };
  842. var mianList3 = new HashSet<string> { "普通大侧", "上下拼侧1", "上下拼侧2", "上下拼侧3", "左右拼侧1", "左右拼侧2", "左右拼侧3", "小侧1", "小侧2", "小侧3" };
  843. //var mianList4 = new HashSet<string> { "小侧1", "小侧2", "小侧3" };
  844. var name_arr = new string[5];
  845. foreach (var mx in mxlist)
  846. {
  847. SetFormulaTypeZeroPzName(mx, key, powerArr, name_arr);
  848. }
  849. if (mianList2.Contains(key))
  850. {
  851. for (int i = 0; i < mianList2.Length; i++)
  852. {
  853. DingBuLianMian.SetValue(name_arr[i], Array.IndexOf(mianList2, key),i );
  854. }
  855. }
  856. //if (mianList4.Contains(key))
  857. //{
  858. // var _index = 0;
  859. // Regex regex = new Regex(@"\d+");
  860. // Match match = regex.Match(key);
  861. // _index = Convert.ToInt32(match.Value) - 1;
  862. // for (int i = 0; i < mianList4.Count; i++)
  863. // {
  864. // XiaoCePeizhi.SetValue(name_arr[i], i, _index);
  865. // }
  866. //}
  867. var sb = new StringBuilder();
  868. foreach (var name2 in name_arr)
  869. {
  870. sb.Append(name2);
  871. }
  872. bool ifchastr3 = false;
  873. if (sb.Length > 0)
  874. {
  875. if (!string.IsNullOrEmpty(chastrArr[1])) interfaceList.Add(InserMattressInterfacePz(chastrArr[0], chastrArr[1], 2, name_arr));
  876. interfaceList.Add(InserMattressInterfacePz(chastrArr[0], chastrArr[2], 1, new string[] { "" }));
  877. if (chastrArr.Length > 3)
  878. {
  879. if (chastrArr[3].Contains("说明")) ifchastr3 = true;
  880. interfaceList.Add(InserMattressInterfacePz(chastrArr[0], chastrArr[3], 1, new string[] { "" }));
  881. }
  882. }
  883. foreach (var name in chastrArr)
  884. {
  885. if (string.IsNullOrEmpty(name)) continue;
  886. if (name.Contains("说明") && !ifchastr3)
  887. {
  888. interfaceList.Add(InserMattressInterfacePz(chastrArr[0], name, 1, new string[] { "" }));
  889. }
  890. }
  891. }
  892. private void SetFormulaTypeZeroPzName(u_mattress_mx_mtrl mx, string key, int[] powerArr, string[] name_arr)
  893. {
  894. if (key.Contains("_EMPTY")) key = "";
  895. if (mx.mtrlid > 0 && key.Equals(mx.chastr) && powerArr.Contains(mx.formulakind.Value))
  896. {
  897. if (mx.formulakind == 0 || mx.formulakind == 1 || mx.formulakind == 2 || mx.formulakind == 3 || mx.formulakind == 4)
  898. {
  899. name_arr[0] = AppendToString(name_arr[0], SplitNameCount(mx.mtrlname, Convert.ToInt32(mx.qty.Value)));
  900. }
  901. if (mx.formulakind == 40 || mx.formulakind == 41 || mx.formulakind == 42 || mx.formulakind == 43 || mx.formulakind == 44)
  902. {
  903. name_arr[1] = AppendToString(name_arr[1], SplitNameCount(mx.mtrlname, Convert.ToInt32(mx.qty.Value)));
  904. }
  905. if (mx.formulakind == 50 || mx.formulakind == 51 || mx.formulakind == 52 || mx.formulakind == 53 || mx.formulakind == 54)
  906. {
  907. var mtrlname_temp = mx.mtrlname;
  908. if (!(mx.mtrlname.IndexOf("分") > -1 && mx.thickness == 0 || mx.if_inputqty == 1))
  909. {
  910. mtrlname_temp = $"{mx.thickness.Value.ToString("#,##0.0#")}分{mx.mtrlname}";
  911. }
  912. name_arr[2] = AppendToString(name_arr[2], SplitNameCount(mtrlname_temp, Convert.ToInt32(mx.qty.Value)));
  913. }
  914. if (mx.formulakind == 60 || mx.formulakind == 61 || mx.formulakind == 62 || mx.formulakind == 63 || mx.formulakind == 64)
  915. {
  916. name_arr[3] = AppendToString(name_arr[3], SplitNameCount(mx.mtrlname, Convert.ToInt32(mx.qty.Value)));
  917. }
  918. if (mx.formulakind == 80 || mx.formulakind == 81 || mx.formulakind == 82 || mx.formulakind == 83 || mx.formulakind == 84)
  919. {
  920. name_arr[0] = string.Format("{0}({1})", name_arr[0], mx.mtrlname);
  921. }
  922. }
  923. }
  924. public void AutoSetFormulaTypeOnePz(List<u_mattress_mx_mtrl> mxlist, List<u_mattress_interface> interfaceList)
  925. {
  926. var diancengList = mxlist.Where(t => t.formulatype == 1).ToList();
  927. var kindDict = new Dictionary<int, string>()
  928. {
  929. { 32,"垫层" },
  930. { 12,"顶布" },
  931. { 13,"毡类" },
  932. { 14,"打底无纺布" },
  933. { 29,"网面布料" },
  934. { 999,"床网" },
  935. { 1201,"顶布裥棉" },
  936. };
  937. var chastrSet = new HashSet<string>() { "大侧", "小侧1", "小侧2", "小侧3", "V侧1", "V侧2", "V侧3" };
  938. var countDict = new Dictionary<string, int>();
  939. foreach (var cha in chastrSet)
  940. {
  941. foreach (var kind in kindDict)
  942. {
  943. countDict.Add($"{cha}-{kind.Value}", 0);
  944. }
  945. }
  946. foreach (var mx in diancengList)
  947. {
  948. var key = $"{mx.chastr}-{kindDict[mx.formulakind.Value]}";
  949. if (mx.formulakind == 999)
  950. {
  951. this.ProcessChuangWangPz(mx, interfaceList, mx.chastr, ++countDict[key]);
  952. }
  953. else if (mx.mtrlid > 0 && mx.formulakind == 1201)
  954. {
  955. this.ProcessDingbuLianMianPz(mx, interfaceList, mx.chastr, ++countDict[key]);
  956. }
  957. else if (mx.mtrlid > 0 && new int[] { 32, 12, 13, 14, 29 }.Contains(mx.formulakind.Value))
  958. {
  959. this.ProcessWangMianBLPz(mx, interfaceList, mx.chastr, kindDict[mx.formulakind.Value], ++countDict[key]);
  960. }
  961. }
  962. if (countDict["大侧-垫层"] > 0)
  963. {
  964. interfaceList.Add(InserMattressInterfacePz("垫层", "大侧垫层生产说明", 1, new string[1]));
  965. }
  966. if (countDict["小侧1-垫层"] > 0)
  967. {
  968. interfaceList.Add(InserMattressInterfacePz("垫层", "小侧垫层生产说明", 1, new string[1]));
  969. }
  970. if (countDict["V侧1-垫层"] > 0)
  971. {
  972. interfaceList.Add(InserMattressInterfacePz("垫层", "V侧垫层生产说明", 1, new string[1]));
  973. }
  974. }
  975. /// <summary>
  976. /// 床网
  977. /// </summary>
  978. /// <param name="mx"></param>
  979. /// <param name="interfaceList"></param>
  980. /// <param name="chastr"></param>
  981. /// <param name="count"></param>
  982. private void ProcessChuangWangPz(u_mattress_mx_mtrl mx, List<u_mattress_interface> interfaceList, string chastr, int count)
  983. {
  984. var name_arr = new string[5];
  985. int bednetid = 0;
  986. int spongeMtrlid = 0; // 是否有海绵包边物料
  987. int spongeTcMtrlid = 0; // 是否有海绵填充物料
  988. cmd.CommandText = @"SELECT u_bednetmx.bednet_height,u_bednetmx.bednetid,u_bednet.sponge_mtrlid,u_bednet.sponge_tc_mtrlid
  989. FROM u_bednetmx
  990. INNER JOIN u_bednet ON u_bednet.bednetid = u_bednetmx.bednetid
  991. INNER JOIN (
  992. SELECT mtrlid
  993. FROM u_mattress_mx_mtrl
  994. INNER JOIN u_mattress_formula ON u_mattress_formula.formulaid = u_mattress_mx_mtrl.formulaid
  995. WHERE u_mattress_formula.formulakind = 99
  996. AND u_mattress_mx_mtrl.mattressid = @mattressid
  997. AND u_mattress_mx_mtrl.mtrlid > 0
  998. ) v_mattress_mx_mtrl ON u_bednetmx.bednetid = v_mattress_mx_mtrl.mtrlid";
  999. cmd.Parameters.Clear();
  1000. cmd.Parameters.AddWithValue("@mattressid", mx.mattressid);
  1001. using (var reader = cmd.ExecuteReader())
  1002. {
  1003. while (reader.Read())
  1004. {
  1005. decimal height = Convert.ToDecimal(reader["bednet_height"]);
  1006. if (height == mx.thickness)
  1007. {
  1008. bednetid = Convert.ToInt32(reader["bednetid"]);
  1009. spongeMtrlid = Convert.ToInt32(reader["sponge_mtrlid"]);
  1010. spongeTcMtrlid = Convert.ToInt32(reader["sponge_tc_mtrlid"]);
  1011. }
  1012. }
  1013. }
  1014. if (bednetid > 0)
  1015. {
  1016. var bednetHelper = HelperBase.GetHelper<BedNetHelper>(cmd);
  1017. var bednetQdList = bednetHelper.GetBedNetQingDan(bednetid);
  1018. if (bednetQdList.Any())
  1019. {
  1020. name_arr[0] = bednetQdList[0].pznamemx;
  1021. name_arr[0] += "丨erp编码:";
  1022. cmd.CommandText = @"SELECT u_mattress.erp_mtrlcode
  1023. FROM u_mattress_mx_mtrl
  1024. INNER JOIN u_mattress_formula ON u_mattress_formula.formulaid = u_mattress_mx_mtrl.formulaid
  1025. INNER JOIN u_mattress ON u_mattress.mattressid = u_mattress_mx_mtrl.mattressid
  1026. WHERE u_mattress_formula.formulakind = 99
  1027. AND u_mattress.bcptypeid <> 0
  1028. AND u_mattress_mx_mtrl.mtrlid = @bednetid";
  1029. cmd.Parameters.Clear();
  1030. cmd.Parameters.AddWithValue("@bednetid", bednetid);
  1031. using(var reader = cmd.ExecuteReader())
  1032. {
  1033. if (reader.Read())
  1034. {
  1035. name_arr[0] += Convert.ToString(reader["erp_mtrlcode"]);
  1036. }
  1037. }
  1038. }
  1039. }
  1040. if (FuncPowerHelper.CheckFuncPower(cmd, context.tokendata.userid, 98) && "super".Equals(context.tokendata.username.ToLower()))
  1041. {
  1042. interfaceList.Add(InserMattressInterfacePz("垫层", $"{chastr}-床网{count}", 2, name_arr));
  1043. }
  1044. else
  1045. {
  1046. interfaceList.Add(InserMattressInterfacePz("垫层", $"{chastr}-床网{count}", 1, name_arr));
  1047. }
  1048. interfaceList.Add(InserMattressInterfacePz("垫层", $"{chastr}-床网{count}生产说明", 1, new string[] { "" }));
  1049. if (spongeMtrlid > 0) interfaceList.Add(InserMattressInterfacePz("垫层", $"{chastr}-床网{count}包边海绵条", 1, new string[] { "" }));
  1050. if (spongeTcMtrlid > 0) interfaceList.Add(InserMattressInterfacePz("垫层", $"{chastr}-床网{count}填充海绵条", 1, new string[] { "" }));
  1051. }
  1052. /// <summary>
  1053. /// 网面布料 / 打底无纺布 / 毡类 / 顶布 / 垫层
  1054. /// </summary>
  1055. /// <param name="mx"></param>
  1056. /// <param name="interfaceList"></param>
  1057. /// <param name="chastr"></param>
  1058. /// <param name="count"></param>
  1059. private void ProcessWangMianBLPz(u_mattress_mx_mtrl mx, List<u_mattress_interface> interfaceList, string chastr, string typename, int count)
  1060. {
  1061. var name_arr = new string[5];
  1062. var mtrlname_temp = mx.mtrlname;
  1063. var chastr_temp = string.Empty;
  1064. if ("顶布".Equals(typename) && count <= 1)
  1065. {
  1066. chastr_temp = $"{chastr}-{typename}";
  1067. }
  1068. else
  1069. {
  1070. chastr_temp = $"{chastr}-{typename}{count}";
  1071. }
  1072. if ((!mx.mtrlname.Contains("分") && mx.thickness > 0) || ("垫层".Equals(typename)))
  1073. {
  1074. mtrlname_temp = $"{mx.thickness.Value.ToString("#,##0.0#")}分{mx.mtrlname}";
  1075. }
  1076. name_arr[0] = mtrlname_temp;
  1077. interfaceList.Add(InserMattressInterfacePz("垫层", chastr_temp, 2, name_arr));
  1078. }
  1079. /// <summary>
  1080. /// 顶布裥棉
  1081. /// </summary>
  1082. /// <param name="mx"></param>
  1083. /// <param name="interfaceList"></param>
  1084. /// <param name="count"></param>
  1085. private void ProcessDingbuLianMianPz(u_mattress_mx_mtrl mx, List<u_mattress_interface> interfaceList, string chastr, int count)
  1086. {
  1087. string chastr_temp = string.Empty;
  1088. string ls_temp = "";
  1089. string[] name_arr = new string[5];
  1090. if ("顶布裥棉1".Equals(mx.mtrlname))
  1091. {
  1092. chastr_temp = $"{chastr}-顶布裥棉";
  1093. for (int i = 0; i < DingBuLianMian.GetLength(0); i++)
  1094. {
  1095. name_arr[i] = DingBuLianMian[0, i];
  1096. }
  1097. }
  1098. else if ("顶布裥棉2".Equals(mx.mtrlname))
  1099. {
  1100. chastr_temp = $"{chastr}-顶布裥棉2";
  1101. for (int i = 0; i < DingBuLianMian.GetLength(0); i++)
  1102. {
  1103. name_arr[i] = DingBuLianMian[1, i];
  1104. }
  1105. }
  1106. else if ("顶布裥棉3".Equals(mx.mtrlname))
  1107. {
  1108. chastr_temp = $"{chastr}-顶布裥棉3";
  1109. for (int i = 0; i < DingBuLianMian.GetLength(0); i++)
  1110. {
  1111. name_arr[i] = DingBuLianMian[2, i];
  1112. }
  1113. }
  1114. else if ("顶布裥棉4".Equals(mx.mtrlname))
  1115. {
  1116. chastr_temp = $"{chastr}-顶布裥棉4";
  1117. for (int i = 0; i < DingBuLianMian.GetLength(0); i++)
  1118. {
  1119. name_arr[i] = DingBuLianMian[3, i];
  1120. }
  1121. }
  1122. interfaceList.Add(InserMattressInterfacePz("垫层", chastr_temp, 2, name_arr));
  1123. }
  1124. private void AutoSetFormulaTypeTwoPz(List<u_mattress_mx_mtrl> mxlist, List<u_mattress_interface> interfaceList)
  1125. {
  1126. var nameSet = new HashSet<string>(new string[] {
  1127. "白色无字包角", "保用卡", "采购小标", "打钮钮扣", "打印小标", "合格证", "画纸", "角网+拉链",
  1128. "开箱刀+开箱说明", "开箱说明+开箱刀", "气钮", "吊标", "说明书", "斜标", "正标", "织唛",
  1129. "织唛斜标", "客供标", "空白牛皮纸包角", "空白珍珠包角"
  1130. });
  1131. // 按照nameSet排序
  1132. //Dictionary<string, int> orderDict = nameSet.Select((name, index) => new { Name = name, Index = index }).ToDictionary(x => x.Name, x => x.Index);
  1133. //var fuliaoList = mxlist.Where(t => t.formulatype == 2).OrderBy(t => orderDict.ContainsKey(t.mtrlname) ? orderDict[t.mtrlname] : int.MaxValue).ThenBy(t => !orderDict.ContainsKey(t.mtrlname) ? t.mtrlname : null).ToList();
  1134. var resultDict = new Dictionary<int, u_mattress_mx_mtrl>();
  1135. foreach (var item in mxlist.Where(t => t.formulatype == 2))
  1136. {
  1137. if (!resultDict.ContainsKey(item.mtrlid.Value))
  1138. {
  1139. resultDict.Add(item.mtrlid.Value, item);
  1140. }
  1141. else
  1142. {
  1143. resultDict[item.mtrlid.Value].qty += item.qty.Value;
  1144. }
  1145. }
  1146. var fuliaoList = new List<u_mattress_mx_mtrl>();
  1147. foreach (var kvp in resultDict)
  1148. {
  1149. fuliaoList.Add(kvp.Value);
  1150. }
  1151. //fuliaoList = fuliaoList.OrderBy(t => orderDict.ContainsKey(t.mtrlname) ? orderDict[t.mtrlname] : int.MaxValue)
  1152. // .ThenBy(t => !orderDict.ContainsKey(t.mtrlname) ? t.mtrlname : null)
  1153. // .ToList();
  1154. var extraSet = new HashSet<string>(new string[] { "采购小标", "打印小标", "合格证", "吊标", "斜标", "正标", "织唛", "织唛斜标", "客供标" });
  1155. var specialSet = new HashSet<string>(new string[] { "打钮钮扣", "气钮" });
  1156. foreach (var mx in fuliaoList)
  1157. {
  1158. if (mx.mtrlid > 0)
  1159. {
  1160. int cnt = Convert.ToInt32(Math.Abs(mx.qty.Value));
  1161. var mtrldef = Cache.GetData<u_mtrl_price, MtrlMapping>(mx.mtrlid.Value);
  1162. if(mtrldef != null) mx.erp_mtrlid = mtrldef.erp_mtrlid;
  1163. // 处理特殊辅料
  1164. if (specialSet.Any(x => mx.mtrlname.Contains(x)) || mtrldef.is_singleqty == 1)
  1165. {
  1166. interfaceList.Add(InserMattressInterfacePz("辅料", $"{mx.mtrlname}", 1, new string[] { $"{cnt.ToString("#,##0.0#")}个" }));
  1167. continue; // 跳过后续的处理
  1168. }
  1169. // 处理其他辅料
  1170. if (nameSet.Contains(mx.mtrlname))
  1171. {
  1172. for (int i = 1; i <= cnt; i++)
  1173. {
  1174. // 添加辅料接口
  1175. interfaceList.Add(InserMattressInterfacePz("辅料", $"{mx.mtrlname}{i}", 1, new string[] { "" }));
  1176. // 如果是额外的辅料,添加位置接口
  1177. if (extraSet.Contains(mx.mtrlname))
  1178. {
  1179. interfaceList.Add(InserMattressInterfacePz("辅料", $"{mx.mtrlname}{i}位置", 0, new string[] { "" }));
  1180. }
  1181. }
  1182. }else if(mx.formulakind == 15 && !nameSet.Contains(mx.mtrlname))
  1183. {
  1184. for (int i = 1; i <= cnt; i++)
  1185. {
  1186. interfaceList.Add(InserMattressInterfacePz("辅料", $"{mx.mtrlname}{i}", 1, new string[] { "" }));
  1187. interfaceList.Add(InserMattressInterfacePz("辅料", $"{mx.mtrlname}{i}位置", 0, new string[] { "" }));
  1188. }
  1189. }
  1190. }
  1191. }
  1192. }
  1193. private void AutoSetFormulaTypeThreePz(u_mattress mattress, List<u_mattress_mx_mtrl> mxlist, List<u_mattress_interface> interfaceList)
  1194. {
  1195. // 筛选 formulatype 为 3 的物料
  1196. var bzList = mxlist.Where(t => t.formulatype == 3).ToList();
  1197. var chastrDict = new Dictionary<int, string>
  1198. {
  1199. {16, "PE袋"},
  1200. {17, "外层PE"},
  1201. {18, "PVC"},
  1202. {19, "卷包包装"},
  1203. {20, "牛皮纸袋"},
  1204. {21, "蓝色PE护角"},
  1205. {22, "无纺布袋"},
  1206. {23, "牛皮袋护角"},
  1207. {24, "编织袋"},
  1208. {27, "拉手脚轮"},
  1209. {201, "无纺布护角"}
  1210. };
  1211. // 判断是否多物料
  1212. var formulaList = new List<u_mattress_formula>();
  1213. DbSqlHelper.Select(cmd, "u_mattress_formula", "formulatype = 3 AND if_mtrl = 2",null, "formulakind", 0,0, formulaList, null, "formulakind");
  1214. var countDict = new Dictionary<int, int>();
  1215. foreach (var formula in formulaList)
  1216. {
  1217. if (!countDict.ContainsKey(formula.formulakind.Value)) countDict.Add(formula.formulakind.Value, 1);
  1218. }
  1219. // 外观
  1220. interfaceList.Add(InserMattressInterfacePz("床垫", "包装方式", 1, new string[] { Enum.GetName(typeof(PackType), mattress.packtype) }));
  1221. if(mattress.packtype.Value == ((int)PackType.卷包))
  1222. {
  1223. // 卷包
  1224. interfaceList.Add(InserMattressInterfacePz("床垫", "卷包方式", 1, new string[] { "" }));
  1225. }
  1226. foreach (var mx in bzList)
  1227. {
  1228. if (mx.mtrlid > 0 && chastrDict.TryGetValue(mx.formulakind.GetValueOrDefault(), out var chastr))
  1229. {
  1230. var name_arr = new string[1];
  1231. if (mx.qty.HasValue && mx.qty.Value > 1)
  1232. {
  1233. name_arr[0] = $"{mx.qty.Value.ToString("#,##0.0#")}个{mx.mtrlname}";
  1234. }
  1235. else
  1236. {
  1237. name_arr[0] = mx.mtrlname;
  1238. }
  1239. if (countDict.ContainsKey(mx.formulakind.Value))
  1240. {
  1241. chastr += countDict[mx.formulakind.Value]++;
  1242. }
  1243. // 添加包装信息
  1244. interfaceList.Add(InserMattressInterfacePz("包装", chastr, 2, name_arr));
  1245. }
  1246. }
  1247. // 压包数量
  1248. interfaceList.Add(InserMattressInterfacePz("包装", "压包数量", 1, new string[] { $"{mattress.packqty.Value.ToString("#,##0.0#")}" }));
  1249. // 包装说明
  1250. interfaceList.Add(InserMattressInterfacePz("包装", "包装说明", 1, new string[] { "" }));
  1251. // 压包说明
  1252. if (mattress.packqty.HasValue && mattress.packqty.Value > 0) interfaceList.Add(InserMattressInterfacePz("包装", "压包说明", 1, new string[] { "" }));
  1253. // 卷包说明
  1254. if (mattress.diameter.HasValue && mattress.diameter.Value > 0) interfaceList.Add(InserMattressInterfacePz("包装", "卷包说明", 1, new string[] { "" }));
  1255. }
  1256. private void AutoSetFormulaType101Pz(u_mattress mattress, List<u_mattress_mx_mtrl> mxlist, List<u_mattress_interface> interfaceList)
  1257. {
  1258. var powerDict = new Dictionary<string, int[]>()
  1259. {
  1260. {"面裥绵",new int[] { 0, 40, 50, 60, 70 } },
  1261. {"底裥绵",new int[] { 1, 41, 51, 61, 71 } },
  1262. {"普通大侧",new int[] { 2, 42, 52, 62, 72 } }
  1263. };
  1264. var chastrDict = new Dictionary<string, string[]>()
  1265. {
  1266. {"面裥绵",new string[] { "内布套-面层裥棉", "内布套-面层裥棉裥棉图案" } },
  1267. {"底裥绵",new string[] { "内布套-底层裥棉", "内布套-底层裥棉裥棉图案" } },
  1268. {"普通大侧",new string[] { "内布套-大侧裥棉", "内布套-大侧裥棉裥棉图案" } }
  1269. };
  1270. foreach (var item in powerDict)
  1271. {
  1272. var name_arr = new string[5];
  1273. foreach (var mx in mxlist)
  1274. {
  1275. SetFormulaTypeZeroPzName(mx, "内布套", item.Value, name_arr);
  1276. }
  1277. var sb = new StringBuilder();
  1278. foreach (var name2 in name_arr)
  1279. {
  1280. sb.Append(name2);
  1281. }
  1282. if (sb.Length > 0)
  1283. {
  1284. interfaceList.Add(InserMattressInterfacePz("内布套", chastrDict[item.Key][0], 2, name_arr));
  1285. interfaceList.Add(InserMattressInterfacePz("内布套", chastrDict[item.Key][1], 1, new string[] { "" }));
  1286. }
  1287. }
  1288. // 内布套-围边边带 / 拉链
  1289. foreach (var mx in mxlist)
  1290. {
  1291. if (mx.mtrlid > 0 && "内布套".Equals(mx.chastr) && mx.formulakind == 203)
  1292. {
  1293. interfaceList.Add(InserMattressInterfacePz("内布套", "内布套-围边边带", 2, new string[] { $"{mx.thickness.Value.ToString("#,##0.0#")}条共{mx.qty.Value.ToString("#,##0.0#")}米{mx.mtrlname}" }));
  1294. }
  1295. else if (mx.mtrlid > 0 && "内布套".Equals(mx.chastr) && mx.formulakind == 202)
  1296. {
  1297. interfaceList.Add(InserMattressInterfacePz("内布套", "内布套-拉链", 2, new string[] { $"{mx.thickness.Value.ToString("#,##0.0#")}条共{mx.qty.Value.ToString("#,##0.0#")}米{mx.mtrlname}" }));
  1298. }
  1299. }
  1300. var butaostring = new string[] { };
  1301. if (mattress.if_n_butao == 1)
  1302. {
  1303. butaostring = new string[] { $"内布套面层向大侧覆盖{mattress.s_cover_qty.Value.ToString("#,##0.0#")}CM、内布套大侧向底层覆盖{mattress.z_cover_qty.Value.ToString("#,##0.0#")}CM、内布套底层向大侧覆盖{mattress.x_cover_qty.Value.ToString("#,##0.0#")}CM" };
  1304. interfaceList.Add(InserMattressInterfacePz("内布套", "内布套做法说明", 1, butaostring));
  1305. }
  1306. }
  1307. #endregion
  1308. #region 导入清单方法
  1309. public List<u_mattress_interface_qd> RefreshMattressInterfaceQdList(int mattressid)
  1310. {
  1311. var qdList = new List<u_mattress_interface_qd>();
  1312. ImportMattressInterfaceQdList(mattressid, qdList);
  1313. MattressInterfaceFindERPPrdPf(qdList,null);
  1314. return qdList;
  1315. }
  1316. /// <summary>
  1317. /// wf_fine_erp_prdpf
  1318. /// </summary>
  1319. /// <param name="qdList"></param>
  1320. /// <param name="interfaceList"></param>
  1321. public void MattressInterfaceFindERPPrdPf(List<u_mattress_interface_qd> qdList,List<u_mattress_interface> interfaceList = null)
  1322. {
  1323. InterfaceFindERPPrdPf(qdList,interfaceList);
  1324. }
  1325. /// <summary>
  1326. /// 导入产品清单
  1327. /// </summary>
  1328. /// <param name="mattressid"></param>
  1329. /// <exception cref="LJCommonException"></exception>
  1330. public void ImportMattressInterfaceQdList(int mattressid, List<u_mattress_interface_qd> qdList)
  1331. {
  1332. if (mattressid <= 0)
  1333. {
  1334. throw new LJCommonException("床垫id有误");
  1335. }
  1336. var mattressHelper = GetHelper<MattressHelper>(cmd, new HelperBase.Context() { tokendata = context.tokendata });
  1337. var mattress = mattressHelper.GetMattress(mattressid);
  1338. var mattress_type = new u_mattress_type() { mattresstypeid = mattress.mattresstypeid };
  1339. DbSqlHelper.SelectOne(cmd, mattress_type, "typename");
  1340. var mxlist = mattressHelper.GetMattressMxMtrl(mattressid, new List<string>() { "u_mattress_formula.formulatype IN (0,1,2,3,99,104)" });
  1341. var mxlist_103 = mattressHelper.GetMattressMxMtrl(mattressid, new List<string>() { "u_mattress_formula.formulatype = 103" });
  1342. var mxlist_101 = mattressHelper.GetMattressMxMtrl(mattressid, new List<string>() { "u_mattress_formula.formulatype = 101" });
  1343. #region 面料类清单导入
  1344. AutoSetFormulaTypeZeroPrdPf(mxlist, qdList);
  1345. #endregion
  1346. #region 垫层类清单导入
  1347. AutoSetFormulaTypeOnePrdPf(mxlist, qdList);
  1348. #endregion
  1349. #region 辅料类清单导入
  1350. AutoSetFormulaTypeTwoPrfPf(mxlist, qdList);
  1351. #endregion
  1352. #region 包装类清单导入
  1353. AutoSetFormulaTypeThreePrdPf(mxlist, qdList);
  1354. #endregion
  1355. #region 内布套类清单导入
  1356. AutoSetFormulaType101PrdPf(mxlist_103, qdList);
  1357. #endregion
  1358. // 最后初始化interfaceList的printid
  1359. for (var i = 0; i < qdList.Count; i++)
  1360. {
  1361. qdList[i].printid = i + 1;
  1362. }
  1363. }
  1364. /// <summary>
  1365. /// 初始化清单信息
  1366. /// </summary>
  1367. /// <param name="itemname"></param>
  1368. /// <param name="bj_pzname"></param>
  1369. /// <param name="inputtype"></param>
  1370. /// <param name="names"></param>
  1371. /// <returns></returns>
  1372. public u_mattress_interface_qd InserMattressInterfacePrdPf(string itemname, string bj_pzname, string namemx, int mtrlid, decimal useqty, int formulaid = 0)
  1373. {
  1374. var _bcpcompare = new u_bcpcompare() { pzname = bj_pzname };
  1375. var _wip_type = "";
  1376. var _wrkgrpcode2 = "";
  1377. if (DbSqlHelper.SelectOne(cmd, _bcpcompare, "wip_type, wrkgrpcode2") == 1)
  1378. {
  1379. _wip_type = _bcpcompare.wip_type;
  1380. _wrkgrpcode2 = _bcpcompare.wrkgrpcode2;
  1381. }
  1382. var mattress_interface_qd = new u_mattress_interface_qd()
  1383. {
  1384. itemname = itemname,
  1385. bj_pzname = bj_pzname,
  1386. bj_pzname_mx = namemx,
  1387. mtrlid = mtrlid,
  1388. useqty = useqty,
  1389. formulaid = formulaid,
  1390. wip_type = _wip_type,
  1391. wrkgrpcode2 = _wrkgrpcode2
  1392. };
  1393. return mattress_interface_qd;
  1394. }
  1395. public u_mattress_interface_qd InserMattressInterfacePrdPf(string itemname, string bj_pzname, string namemx)
  1396. {
  1397. var mattress_interface_qd = new u_mattress_interface_qd()
  1398. {
  1399. itemname = itemname,
  1400. bj_pzname = bj_pzname,
  1401. bj_pzname_mx = namemx
  1402. };
  1403. return mattress_interface_qd;
  1404. }
  1405. private void AutoSetFormulaTypeZeroPrdPf(List<u_mattress_mx_mtrl> mxlist, List<u_mattress_interface_qd> qdList)
  1406. {
  1407. var powerDict = new Dictionary<string, int[]>()
  1408. {
  1409. {"面裥绵",new int[] { 0, 40, 50, 60, 70, 80 } },
  1410. {"底裥绵",new int[] { 1, 41, 51, 61, 71, 81 } },
  1411. {"顶布裥棉1",new int[] { 0, 40, 50, 60, 70, 80 } },
  1412. {"顶布裥棉2",new int[] { 0, 40, 50, 60, 70, 80 } },
  1413. {"普通大侧",new int[] { 2, 42, 52, 62, 72, 82 } },
  1414. {"上下拼侧1",new int[] { 2, 42, 52, 62, 72, 82 } },
  1415. {"上下拼侧2",new int[] { 2, 42, 52, 62, 72, 82 } },
  1416. {"上下拼侧3",new int[] { 2, 42, 52, 62, 72, 82 } },
  1417. {"左右拼侧1",new int[] { 2, 42, 52, 62, 72, 82 } },
  1418. {"左右拼侧2",new int[] { 2, 42, 52, 62, 72, 82 } },
  1419. {"左右拼侧3",new int[] { 2, 42, 52, 62, 72, 82 } },
  1420. {"小侧1_EMPTY",new int[] { 3, 43, 53, 63, 73, 83 } },
  1421. {"小侧1",new int[] { 3, 43, 53, 63, 73, 83 } },
  1422. {"小侧1-上下拼侧1",new int[] { 3, 43, 53, 63, 73, 83 } },
  1423. {"小侧1-上下拼侧2",new int[] { 3, 43, 53, 63, 73, 83 } },
  1424. {"小侧1-上下拼侧3",new int[] { 3, 43, 53, 63, 73, 83 } },
  1425. {"小侧2",new int[] { 3, 43, 53, 63, 73, 83 } },
  1426. {"小侧3",new int[] { 3, 43, 53, 63, 73, 83 } },
  1427. {"V侧1_EMPTY",new int[] { 4, 44, 54, 64, 74, 84 } },
  1428. {"V侧1",new int[] { 4, 44, 54, 64, 74, 84 } },
  1429. {"V侧2",new int[] { 4, 44, 54, 64, 74, 84 } },
  1430. {"V侧3",new int[] { 4, 44, 54, 64, 74, 84 } }
  1431. };
  1432. var chastrArrDict = new Dictionary<string, string[]>()
  1433. {
  1434. {"面裥绵",new string[] { "裥面", "面层裥棉", "面层裥面说明" } },
  1435. {"底裥绵",new string[] { "裥底", "底层裥棉", "底层裥棉说明" } },
  1436. {"顶布裥棉1",new string[] { "顶布裥棉", "顶布裥棉1" } },
  1437. {"顶布裥棉2",new string[] { "顶布裥棉", "顶布裥棉2" } },
  1438. {"普通大侧",new string[] { "大侧", "大侧裥棉"} },
  1439. {"上下拼侧1",new string[] {"大侧", "大侧-上下拼侧1"} },
  1440. {"上下拼侧2",new string[] { "大侧", "大侧-上下拼侧2" } },
  1441. {"上下拼侧3",new string[] { "大侧", "大侧-上下拼侧3" } },
  1442. {"左右拼侧1",new string[] { "大侧", "大侧-左右拼侧1"} },
  1443. {"左右拼侧2",new string[] { "大侧", "大侧-左右拼侧2"} },
  1444. {"左右拼侧3",new string[] { "大侧", "大侧-左右拼侧3" ,"大侧说明" } },
  1445. {"小侧1_EMPTY",new string[] { "小侧", "小侧1裥棉" } },
  1446. {"小侧1",new string[] { "小侧", "小侧1裥棉"} },
  1447. {"小侧1-上下拼侧1",new string[] { "小侧", "小侧1-上下拼侧1裥棉" } },
  1448. {"小侧1-上下拼侧2",new string[] { "小侧", "小侧1-上下拼侧2裥棉" } },
  1449. {"小侧1-上下拼侧3",new string[] { "小侧", "小侧1-上下拼侧3裥棉" } },
  1450. {"小侧2",new string[] { "小侧", "小侧2裥棉", "小侧2裥棉图案" } },
  1451. {"小侧3",new string[] { "小侧", "小侧3裥棉", "小侧3裥棉图案", "小侧说明" } },
  1452. {"V侧1_EMPTY",new string[] { "V侧", "V侧1裥棉", "V侧1裥棉图案" } },
  1453. {"V侧1",new string[] { "V侧", "V侧1裥棉", "V侧1裥棉图案" } },
  1454. {"V侧2",new string[] { "V侧", "V侧2裥棉", "V侧2裥棉图案" } },
  1455. {"V侧3",new string[] { "V侧", "V侧3裥棉", "V侧3裥棉图案", "V侧说明" } }
  1456. };
  1457. var extreDict = new HashSet<string>() { "小侧", "V侧" };
  1458. var jianmianList = mxlist.Where(t => t.formulatype == 0).ToList();
  1459. var isEnter = false;
  1460. #region wf_import_qingdan_prdpf
  1461. foreach (var item in powerDict)
  1462. {
  1463. // 保证清单列表类别一致,从面裥绵 -> V侧3
  1464. foreach (var mx in jianmianList)
  1465. {
  1466. if (mx.mtrlid > 0 && (item.Key.Equals(mx.chastr) || (string.IsNullOrEmpty(mx.chastr) && item.Key.Contains("_EMPTY"))) && item.Value.Contains(mx.formulakind.Value))
  1467. {
  1468. if (mx.formulakind == 0 || mx.formulakind == 1 || mx.formulakind == 2 || mx.formulakind == 3 || mx.formulakind == 4)
  1469. {
  1470. qdList.Add(InserMattressInterfacePrdPf(chastrArrDict[item.Key][0], chastrArrDict[item.Key][1], "布料", mx.mtrlid.Value, mx.useqty.Value, mx.formulaid.Value));
  1471. }
  1472. if (mx.formulakind == 40 || mx.formulakind == 41 || mx.formulakind == 42 || mx.formulakind == 43 || mx.formulakind == 44)
  1473. {
  1474. qdList.Add(InserMattressInterfacePrdPf(chastrArrDict[item.Key][0], chastrArrDict[item.Key][1], "喷胶棉", mx.mtrlid.Value, mx.useqty.Value, mx.formulaid.Value));
  1475. }
  1476. if (mx.formulakind == 50 || mx.formulakind == 51 || mx.formulakind == 52 || mx.formulakind == 53 || mx.formulakind == 54)
  1477. {
  1478. qdList.Add(InserMattressInterfacePrdPf(chastrArrDict[item.Key][0], chastrArrDict[item.Key][1], "裥面海绵", mx.mtrlid.Value, mx.useqty.Value, mx.formulaid.Value));
  1479. }
  1480. if (mx.formulakind == 60 || mx.formulakind == 61 || mx.formulakind == 62 || mx.formulakind == 63 || mx.formulakind == 64)
  1481. {
  1482. qdList.Add(InserMattressInterfacePrdPf(chastrArrDict[item.Key][0], chastrArrDict[item.Key][1], "无纺布", mx.mtrlid.Value, mx.useqty.Value, mx.formulaid.Value));
  1483. }
  1484. }
  1485. }
  1486. if(item.Key.Contains("小侧3") || item.Key.Contains("V侧3"))
  1487. {
  1488. var list = qdList.FindAll(t => extreDict.Contains(t.itemname)).ToList();
  1489. if(list.Any())
  1490. {
  1491. foreach (var name in chastrArrDict[item.Key])
  1492. {
  1493. if (name.Contains("说明"))
  1494. {
  1495. qdList.Add(InserMattressInterfacePrdPf(chastrArrDict[item.Key][0], name, ""));
  1496. }
  1497. }
  1498. }
  1499. } else
  1500. {
  1501. foreach (var name in chastrArrDict[item.Key])
  1502. {
  1503. if (name.Contains("说明"))
  1504. {
  1505. qdList.Add(InserMattressInterfacePrdPf(chastrArrDict[item.Key][0], name, ""));
  1506. }
  1507. }
  1508. }
  1509. }
  1510. #endregion
  1511. #region wf_import_qingdan_next 面料部分
  1512. // 按照 formulakind 分组
  1513. var grouped = jianmianList
  1514. .Where(t => t.formulakind >= 5 && t.formulakind <= 10)
  1515. .GroupBy(t => t.formulakind);
  1516. // 需要处理的组的名称与编号映射
  1517. var groupNames = new Dictionary<int, string>
  1518. {
  1519. { 5, "拉手" },
  1520. { 6, "刺绣" },
  1521. { 7, "大侧压压布" },
  1522. { 8, "大侧压边带" },
  1523. { 9, "大侧压织带" },
  1524. { 10, "大侧压上下压线" }
  1525. };
  1526. // 处理每一组
  1527. foreach (var group in grouped)
  1528. {
  1529. var formulakind = group.Key.Value;
  1530. var name = groupNames.ContainsKey(formulakind) ? groupNames[formulakind] : "未知组";
  1531. foreach (var mx in group)
  1532. {
  1533. if (string.IsNullOrEmpty(mx.chastr) && mx.mtrlid > 0)
  1534. {
  1535. qdList.Add(InserMattressInterfacePrdPf("拉手刺绣及其他工艺",$"{name}{group.ToList().IndexOf(mx) + 1}","",
  1536. mx.mtrlid.Value,
  1537. mx.useqty.Value
  1538. ));
  1539. }
  1540. }
  1541. }
  1542. // 统一添加固定项
  1543. qdList.Add(InserMattressInterfacePrdPf("拉手刺绣及其他工艺", "拉手刺绣", ""));
  1544. qdList.Add(InserMattressInterfacePrdPf("拉手刺绣及其他工艺", "拉手无纺布", ""));
  1545. qdList.Add(InserMattressInterfacePrdPf("拉手刺绣及其他工艺", "侧刺绣做法", ""));
  1546. #endregion
  1547. }
  1548. private void AutoSetFormulaTypeOnePrdPf(List<u_mattress_mx_mtrl> mxlist, List<u_mattress_interface_qd> qdList)
  1549. {
  1550. var diancengList = mxlist.Where(t => t.formulatype == 1).ToList();
  1551. var kindDict = new Dictionary<int, string>()
  1552. {
  1553. { 32,"垫层" },
  1554. { 12,"顶布" },
  1555. { 13,"毡类" },
  1556. { 14,"打底无纺布" },
  1557. { 29,"网面布料" },
  1558. { 999,"床网" },
  1559. {1201,"顶布裥棉" }
  1560. };
  1561. var chastrSet = new HashSet<string>() { "大侧", "小侧1", "小侧2", "小侧3", "V侧1", "V侧2", "V侧3" };
  1562. var countDict = new Dictionary<string, int>();
  1563. foreach (var cha in chastrSet)
  1564. {
  1565. foreach (var kind in kindDict)
  1566. {
  1567. countDict.Add($"{cha}-{kind.Value}", 0);
  1568. }
  1569. }
  1570. foreach (var mx in diancengList)
  1571. {
  1572. var key = $"{mx.chastr}-{kindDict[mx.formulakind.Value]}";
  1573. if (mx.mtrlid > 0 && new int[] { 32, 12, 13, 14, 29 }.Contains(mx.formulakind.Value))
  1574. {
  1575. this.ProcessWangMianBLPrdPf(mx, qdList, mx.chastr, kindDict[mx.formulakind.Value], ++countDict[key]);
  1576. } else if (mx.formulakind == 999)
  1577. {
  1578. this.ProcessChuangWangPrdPf(mx, qdList, mx.chastr, ++countDict[key]);
  1579. } else if(mx.formulakind == 1201)
  1580. {
  1581. // 不需要操作
  1582. }
  1583. }
  1584. // 顶布裥面说明
  1585. qdList.Add(InserMattressInterfacePrdPf("顶布裥棉", "顶布裥面说明1", ""));
  1586. qdList.Add(InserMattressInterfacePrdPf("顶布裥棉", "顶布裥面说明2", ""));
  1587. }
  1588. /// <summary>
  1589. /// 床网
  1590. /// </summary>
  1591. /// <param name="mx"></param>
  1592. /// <param name="interfaceList"></param>
  1593. /// <param name="chastr"></param>
  1594. /// <param name="count"></param>
  1595. private void ProcessChuangWangPrdPf(u_mattress_mx_mtrl mx, List<u_mattress_interface_qd> qdList, string chastr, int count)
  1596. {
  1597. var namepz = string.Empty;
  1598. int bednetid = 0;
  1599. cmd.CommandText = @"SELECT u_bednetmx.bednet_height,u_bednetmx.bednetid
  1600. FROM u_bednetmx
  1601. INNER JOIN (
  1602. SELECT mtrlid
  1603. FROM u_mattress_mx_mtrl
  1604. INNER JOIN u_mattress_formula ON u_mattress_formula.formulaid = u_mattress_mx_mtrl.formulaid
  1605. WHERE u_mattress_formula.formulakind = 99
  1606. AND u_mattress_mx_mtrl.mattressid = @mattressid
  1607. AND u_mattress_mx_mtrl.mtrlid > 0
  1608. ) v_mattress_mx_mtrl ON u_bednetmx.bednetid = v_mattress_mx_mtrl.mtrlid";
  1609. cmd.Parameters.Clear();
  1610. cmd.Parameters.AddWithValue("@mattressid", mx.mattressid);
  1611. using (var reader = cmd.ExecuteReader())
  1612. {
  1613. while (reader.Read())
  1614. {
  1615. decimal height = Convert.ToDecimal(reader["bednet_height"]);
  1616. if (height == mx.thickness) bednetid = Convert.ToInt32(reader["bednetid"]);
  1617. }
  1618. }
  1619. if (bednetid > 0)
  1620. {
  1621. // 获取床网清单
  1622. var bednetList = new List<u_bednetmx>();
  1623. if (bednetList.Any())
  1624. {
  1625. var bednetHelper = HelperBase.GetHelper<BedNetHelper>(cmd);
  1626. var bednetQdList = bednetHelper.GetBedNetQingDan(bednetid);
  1627. if (bednetQdList.Any())
  1628. {
  1629. namepz = bednetQdList[0].pznamemx;
  1630. }
  1631. }
  1632. }
  1633. qdList.Add(InserMattressInterfacePrdPf("垫层", $"{chastr}-床网{count}", namepz, bednetid, mx.useqty.Value));
  1634. // 海绵条*4 2
  1635. qdList.Add(InserMattressInterfacePrdPf("垫层", "海绵条1", ""));
  1636. qdList.Add(InserMattressInterfacePrdPf("垫层", "海绵条2", ""));
  1637. qdList.Add(InserMattressInterfacePrdPf("垫层", "海绵条3", ""));
  1638. qdList.Add(InserMattressInterfacePrdPf("垫层", "海绵条4", ""));
  1639. }
  1640. /// <summary>
  1641. /// 网面布料 / 打底无纺布 / 毡类 / 顶布 / 垫层
  1642. /// </summary>
  1643. /// <param name="mx"></param>
  1644. /// <param name="interfaceList"></param>
  1645. /// <param name="chastr"></param>
  1646. /// <param name="count"></param>
  1647. private void ProcessWangMianBLPrdPf(u_mattress_mx_mtrl mx, List<u_mattress_interface_qd> qdList, string chastr, string typename, int count)
  1648. {
  1649. var mtrlname_temp = mx.mtrlname;
  1650. if ((!mx.mtrlname.Contains("分") && mx.thickness > 0) || ("垫层".Equals(typename)))
  1651. {
  1652. mtrlname_temp = $"{mx.thickness.Value.ToString("#,##0.0#")}分{mx.mtrlname}";
  1653. }
  1654. qdList.Add(InserMattressInterfacePrdPf("垫层", $"{chastr}-{typename}{count}", "",mx.mtrlid.Value,mx.useqty.Value));
  1655. }
  1656. private void AutoSetFormulaTypeTwoPrfPf(List<u_mattress_mx_mtrl> mxlist, List<u_mattress_interface_qd> qdList)
  1657. {
  1658. var fuliaoList = mxlist.Where(t => t.formulatype == 2).ToList();
  1659. var nameSet = new HashSet<string>(new string[] {
  1660. "保用卡", "采购小标", "打钮钮扣", "打印小标", "合格证", "画纸", "开箱说明+开箱刀", "吊标", "客供标",
  1661. "空白牛皮纸包角", "空白珍珠包角", "气钮","说明书","斜标","正标","织唛","织唛斜标"
  1662. });
  1663. var extraSet = new HashSet<string>(new string[] { "保用卡", "采购小标", "打钮钮扣", "打印小标", "合格证", "画纸", "开箱说明+开箱刀", "吊标", "客供标",
  1664. "空白牛皮纸包角", "空白珍珠包角", "气钮","说明书","斜标","正标","织唛","织唛斜标","角网+拉链","开箱刀+开箱说明" });
  1665. var specialSet = new HashSet<string>(new string[] { "打钮钮扣", "气钮" });
  1666. foreach (var mx in fuliaoList)
  1667. {
  1668. if (mx.mtrlid > 0)
  1669. {
  1670. int cnt = Convert.ToInt32(Math.Abs(mx.qty.Value));
  1671. var mtrldef = Cache.GetData<u_mtrl_price, MtrlMapping>(mx.mtrlid.Value);
  1672. // 处理特殊辅料
  1673. if (specialSet.Contains(mx.mtrlname) || (mtrldef != null && mtrldef.is_singleqty == 1))
  1674. {
  1675. qdList.Add(InserMattressInterfacePrdPf("辅料", $"{mx.mtrlname}", "", mx.mtrlid.Value, mx.useqty.Value));
  1676. continue; // 跳过后续的处理
  1677. }
  1678. // 处理其他辅料
  1679. if (nameSet.Contains(mx.mtrlname))
  1680. {
  1681. for (int i = 1; i <= cnt; i++)
  1682. {
  1683. // 添加辅料接口
  1684. qdList.Add(InserMattressInterfacePrdPf("辅料", $"{mx.mtrlname}{i}", "",mx.mtrlid.Value,mx.useqty.Value));
  1685. }
  1686. } else if(mx.formulakind == 15 && !extraSet.Contains(mx.mtrlname))
  1687. {
  1688. for (int i = 1; i <= cnt; i++)
  1689. {
  1690. // 添加辅料接口
  1691. qdList.Add(InserMattressInterfacePrdPf("辅料", $"{mx.mtrlname}{i}", "", mx.mtrlid.Value, mx.useqty.Value));
  1692. // 如果是额外的辅料,添加位置接口
  1693. qdList.Add(InserMattressInterfacePrdPf("辅料", $"{mx.mtrlname}{i}位置", "", mx.mtrlid.Value, mx.useqty.Value));
  1694. }
  1695. }
  1696. }
  1697. }
  1698. }
  1699. private void AutoSetFormulaTypeThreePrdPf(List<u_mattress_mx_mtrl> mxlist, List<u_mattress_interface_qd> qdList)
  1700. {
  1701. // 筛选 formulatype 为 3 的物料
  1702. var bzList = mxlist.Where(t => t.formulatype == 3).ToList();
  1703. var chastrDict = new Dictionary<int, string>
  1704. {
  1705. {16, "PE袋"},
  1706. {17, "外层PE"},
  1707. {18, "PVC"},
  1708. {19, "卷包包装"},
  1709. {20, "牛皮纸袋"},
  1710. {21, "蓝色PE护角"},
  1711. {22, "无纺布袋"},
  1712. {23, "牛皮袋护角"},
  1713. {24, "编织袋"},
  1714. {27, "拉手脚轮"},
  1715. {201, "无纺布护角"}
  1716. };
  1717. var countDict = new Dictionary<int, int>
  1718. {
  1719. {16, 0}
  1720. };
  1721. foreach (var mx in bzList)
  1722. {
  1723. if (mx.mtrlid > 0 && chastrDict.TryGetValue(mx.formulakind.GetValueOrDefault(), out var chastr))
  1724. {
  1725. var name_arr = new string[1];
  1726. if (mx.qty.HasValue && mx.qty.Value > 1)
  1727. {
  1728. name_arr[0] = $"{mx.qty.Value.ToString("#,##0.0#")}个{mx.mtrlname}";
  1729. }
  1730. else
  1731. {
  1732. name_arr[0] = mx.mtrlname;
  1733. }
  1734. if (countDict.ContainsKey(mx.formulakind.Value))
  1735. {
  1736. chastr += countDict[mx.formulakind.Value];
  1737. }
  1738. // 添加包装信息
  1739. qdList.Add(InserMattressInterfacePrdPf("包装", chastr,"",mx.mtrlid.Value,mx.useqty.Value));
  1740. }
  1741. }
  1742. // 包装说明
  1743. qdList.Add(InserMattressInterfacePrdPf("包装", "包装说明", ""));
  1744. // 车位说明
  1745. qdList.Add(InserMattressInterfacePrdPf("车位说明", "车位说明", ""));
  1746. }
  1747. private void AutoSetFormulaType101PrdPf(List<u_mattress_mx_mtrl> mxlist, List<u_mattress_interface_qd> qdList)
  1748. {
  1749. var powerDict = new Dictionary<string, int[]>()
  1750. {
  1751. {"面裥绵",new int[] { 0, 40, 50, 60, 70,80 } },
  1752. {"底裥绵",new int[] { 1, 41, 51, 61, 71 } },
  1753. {"普通大侧",new int[] { 2, 42, 52, 62, 72 } }
  1754. };
  1755. var chastrDict = new Dictionary<string, string[]>()
  1756. {
  1757. {"面裥绵",new string[] { "内布套-面层裥棉", "内布套-面层裥棉裥棉图案" } },
  1758. {"底裥绵",new string[] { "内布套-底层裥棉", "内布套-底层裥棉裥棉图案" } },
  1759. {"普通大侧",new string[] { "内布套-大侧裥棉", "内布套-大侧裥棉裥棉图案" } }
  1760. };
  1761. foreach (var item in powerDict)
  1762. {
  1763. var name_arr = new string[5];
  1764. foreach (var mx in mxlist)
  1765. {
  1766. if (mx.mtrlid > 0 && (item.Key.Equals(mx.chastr) || item.Key.Contains("_EMPTY")) && item.Value.Contains(mx.formulakind.Value))
  1767. {
  1768. if (mx.formulakind == 0 || mx.formulakind == 1 || mx.formulakind == 2 || mx.formulakind == 3)
  1769. {
  1770. qdList.Add(InserMattressInterfacePrdPf(chastrDict[item.Key][0], chastrDict[item.Key][1], "布料", mx.mtrlid.Value, mx.useqty.Value));
  1771. }
  1772. if (mx.formulakind == 40 || mx.formulakind == 41 || mx.formulakind == 42 || mx.formulakind == 43)
  1773. {
  1774. qdList.Add(InserMattressInterfacePrdPf(chastrDict[item.Key][0], chastrDict[item.Key][1], "喷胶棉", mx.mtrlid.Value, mx.useqty.Value));
  1775. }
  1776. if (mx.formulakind == 50 || mx.formulakind == 51 || mx.formulakind == 52 || mx.formulakind == 53)
  1777. {
  1778. qdList.Add(InserMattressInterfacePrdPf(chastrDict[item.Key][0], chastrDict[item.Key][1], "裥面海绵", mx.mtrlid.Value, mx.useqty.Value));
  1779. }
  1780. if (mx.formulakind == 60 || mx.formulakind == 61 || mx.formulakind == 62 || mx.formulakind == 63)
  1781. {
  1782. qdList.Add(InserMattressInterfacePrdPf(chastrDict[item.Key][0], chastrDict[item.Key][1], "无纺布", mx.mtrlid.Value, mx.useqty.Value));
  1783. }
  1784. }
  1785. }
  1786. }
  1787. // 内布套-围边边带 / 拉链
  1788. foreach (var mx in mxlist)
  1789. {
  1790. if (mx.mtrlid > 0 && "内布套".Equals(mx.chastr) && mx.formulakind == 203)
  1791. {
  1792. qdList.Add(InserMattressInterfacePrdPf("内布套", "内布套-围边边带", "围边",mx.mtrlid.Value,mx.useqty.Value));
  1793. }
  1794. else if (mx.mtrlid > 0 && "内布套".Equals(mx.chastr) && mx.formulakind == 202)
  1795. {
  1796. qdList.Add(InserMattressInterfacePrdPf("内布套", "内布套-拉链", "拉链", mx.mtrlid.Value, mx.useqty.Value));
  1797. }
  1798. }
  1799. }
  1800. #endregion
  1801. #region 床网清单
  1802. /// <summary>
  1803. /// 床垫接口-保存
  1804. /// </summary>
  1805. /// <param name="mattress"></param>
  1806. /// <param name="mxlist"></param>
  1807. /// <param name="qdlist"></param>
  1808. /// <exception cref="LJCommonException"></exception>
  1809. public void SaveBedNetInterface(u_bednet bednet, List<u_bednet_interface> mxlist, List<u_bednet_interface_qd> qdlist)
  1810. {
  1811. if (bednet.bednetid <= 0)
  1812. {
  1813. throw new LJCommonException("错误的床网id");
  1814. }
  1815. if (bednet.erp_mtrltypeid == null || bednet.erp_mtrltypeid <= 0)
  1816. {
  1817. throw new LJCommonException("请选择物料类别!");
  1818. }
  1819. if (bednet.erp_configcodetype == null || bednet.erp_configcodetype <= 0)
  1820. {
  1821. throw new LJCommonException("请选择配置类型!");
  1822. }
  1823. DbSqlHelper.Update(cmd, bednet, "erp_mtrlid,erp_mtrltypeid,erp_mtrlcode,erp_mtrlname,erp_mtrlmode,erp_mtrltype,erp_mtrlunit,erp_mtrlengname,erp_configcodetype,old_mtrlname");
  1824. // 保存接口数据
  1825. var bednetHelper = GetHelper<BedNetHelper>(cmd, new HelperBase.Context() { tokendata = context.tokendata });
  1826. bednetHelper.SaveBedNetInterface(bednet.bednetid.Value, mxlist, qdlist);
  1827. }
  1828. public List<u_bednet_interface> GetBedNetInterfaceList(int bednetid)
  1829. {
  1830. var interfaceList = new List<u_bednet_interface>();
  1831. var selectStr = @"SELECT bednetid
  1832. ,printid
  1833. ,itemname
  1834. ,bj_pzname
  1835. ,bj_namemx
  1836. ,actual_size
  1837. ,erp_pzid
  1838. ,Space(200) AS erp_pzcode
  1839. ,Space(200) AS erp_pzname
  1840. ,bj_inputtype AS erp_inputtype
  1841. FROM u_bednet_interface";
  1842. DbSqlHelper.SelectJoin(cmd, selectStr, "bednetid = @bednetid", new Dictionary<string, object>() { { "@bednetid", bednetid } }, "printid", "bednetid,printid,itemname,bj_pzname,bj_namemx,actual_size,erp_pzid,ss_rate,ls_rate,bj_inputtype", 0, 0, interfaceList);
  1843. if (interfaceList.Count <= 0)
  1844. {
  1845. interfaceList = RefreshBedNetInterfaceList(bednetid);
  1846. }
  1847. else
  1848. {
  1849. BedNetInterfaceFindERPPz(bednetid,interfaceList);
  1850. }
  1851. return interfaceList;
  1852. }
  1853. public List<u_bednet_interface> RefreshBedNetInterfaceList(int bednetid)
  1854. {
  1855. var interfaceList = new List<u_bednet_interface>();
  1856. // 导入配置
  1857. ImportBedNetInterfaceList(bednetid, interfaceList);
  1858. BedNetInterfaceFindERPPz(bednetid, interfaceList);
  1859. return interfaceList;
  1860. }
  1861. public List<u_bednet_interface> RefreshBedNetInterfaceList(int bednetid,int configcodetype)
  1862. {
  1863. var interfaceList = new List<u_bednet_interface>();
  1864. // 导入配置
  1865. ImportBedNetInterfaceList(bednetid, interfaceList);
  1866. InterfaceFindERPPz(configcodetype, interfaceList);
  1867. return interfaceList;
  1868. }
  1869. public void ImportBedNetInterfaceList(int bednetid, List<u_bednet_interface> interfaceList)
  1870. {
  1871. if (bednetid <= 0)
  1872. {
  1873. throw new LJCommonException("床网id有误");
  1874. }
  1875. var bednetHelper = GetHelper<BedNetHelper>(cmd, new HelperBase.Context() { tokendata = context.tokendata });
  1876. //var bednet = bednetHelper.GetBedNet(bednetid);
  1877. var qdlist = bednetHelper.GetBedNetQingDan(bednetid);
  1878. foreach(var qd in qdlist)
  1879. {
  1880. interfaceList.Add(InserBedNetInterfacePz("床网",qd.pzname,2,new string[] { qd.pznamemx }));
  1881. }
  1882. // 床网名称
  1883. // 床网类型 NOTES: 床网类型 袋装网需要区分x区
  1884. // 床网规格
  1885. // 床网排序
  1886. // 床网高度
  1887. // 弹簧线径/高度/口径/中心直径/圈数
  1888. // 多区弹簧1/线径/口径/中心直径/圈数
  1889. // 多区弹簧1排列数(长)
  1890. // 多区弹簧2/线径/口径/中心直径/圈数
  1891. // 多区弹簧2排列数(长)
  1892. // 多区弹簧3/线径/口径/中心直径/圈数
  1893. // 多区弹簧3排列数(长)
  1894. // 多区弹簧4/线径/口径/中心直径/圈数
  1895. // 多区弹簧4排列数(长)
  1896. // 多区弹簧5/线径/口径/中心直径/圈数
  1897. // 多区弹簧5排列数(长)
  1898. // 边铁条数
  1899. // 底面无纺布
  1900. // 入袋无纺布
  1901. // 上垫层物料
  1902. // 下垫层物料
  1903. // 四周加硬排数
  1904. // 四周加硬线径/高度/口径/中心直径/圈数
  1905. // 海绵包边物料
  1906. // 海绵包边物料厚度
  1907. // 填充海绵物料
  1908. // 填充包边物料厚度
  1909. // 封边物料
  1910. // 封边高度
  1911. // 胶条
  1912. // 包角
  1913. // 海绵打孔
  1914. // 加弹叉数量
  1915. // 15分布条
  1916. // 蛇线线径
  1917. // 四周口袋弹簧排数
  1918. // 四周口袋线径/高度/口径/中心直径/圈数
  1919. // 床网说明
  1920. // 包装方式
  1921. // 包装数量
  1922. // 包装材料
  1923. // 多区弹簧6/线径/口径/中心直径/圈数
  1924. // 多区弹簧7/线径/口径/中心直径/圈数
  1925. // 多区弹簧6排列数(长)
  1926. // 多区弹簧7排列数(长)
  1927. }
  1928. public void BedNetInterfaceFindERPPz(int bednetid, List<u_bednet_interface> interfaceList)
  1929. {
  1930. var bednet = new u_bednet() { bednetid = bednetid };
  1931. DbSqlHelper.SelectOne(cmd, bednet, "erp_configcodetype");
  1932. InterfaceFindERPPz(bednet.erp_configcodetype.Value, interfaceList);
  1933. }
  1934. public u_bednet_interface InserBedNetInterfacePz(string itemname, string bj_pzname, byte inputtype, string[] names)
  1935. {
  1936. return InserInterfacePz<u_bednet_interface>(itemname, bj_pzname, inputtype, names);
  1937. }
  1938. /// <summary>
  1939. /// 刷新床网产品配置清单
  1940. /// </summary>
  1941. /// <param name="bednetid"></param>
  1942. /// <returns></returns>
  1943. public List<u_bednet_interface_qd> RefreshBedNetInterfaceQdList(int bednetid)
  1944. {
  1945. var qdList = new List<u_bednet_interface_qd>();
  1946. ImportBedNetInterfaceQdList(bednetid, qdList);
  1947. InterfaceFindERPPrdPf<u_bednet_interface_qd, u_bednet_interface>(qdList);
  1948. return qdList;
  1949. }
  1950. /// <summary>
  1951. /// 导入产品清单
  1952. /// </summary>
  1953. /// <param name="bednetid"></param>
  1954. /// <exception cref="LJCommonException"></exception>
  1955. public void ImportBedNetInterfaceQdList(int bednetid, List<u_bednet_interface_qd> qdList)
  1956. {
  1957. if (bednetid <= 0)
  1958. {
  1959. throw new LJCommonException("床网id有误");
  1960. }
  1961. }
  1962. #endregion
  1963. #region 通用方法
  1964. /// <summary>
  1965. /// wf_fine_erp_prdpf
  1966. /// </summary>
  1967. /// <param name="qdList"></param>
  1968. /// <param name="interfaceList"></param>
  1969. public void InterfaceFindERPPrdPf<T, S>(List<T> qdList, List<S> interfaceList = null) where T : BaseInterfaceQd where S : BaseInterface
  1970. {
  1971. var mtrlidList = new List<int>();
  1972. foreach (var mx in qdList)
  1973. {
  1974. // 带出有设置 的erp_mtrlid
  1975. if (mx.erp_mtrlid == 0 && mx.mtrlid != null && mx.mtrlid > 0)
  1976. {
  1977. var mtrldef = new u_mtrl_price() { mtrlid = mx.mtrlid };
  1978. if (DbSqlHelper.SelectOne(cmd, mtrldef, "erp_mtrlid") == 1)
  1979. {
  1980. mx.erp_mtrlid = mtrldef.erp_mtrlid;
  1981. }
  1982. }
  1983. if (mx.erp_mtrlid > 0)
  1984. {
  1985. mtrlidList.Add(mx.erp_mtrlid.Value);
  1986. }
  1987. }
  1988. if (mtrlidList.Count > 0)
  1989. {
  1990. var erpHelper = HelperBase.GetHelper<ERPHelper>(null);
  1991. var total = 0;
  1992. var resultList = erpHelper.GetERPMtrldef(cmd, ref total, "", new L1Mtrldef(), 0, 0, 1, mtrlidList);
  1993. if (resultList != null && resultList.Any())
  1994. {
  1995. foreach (var mx in qdList)
  1996. {
  1997. var result = resultList.FirstOrDefault(o => o.mtrlid == mx.erp_mtrlid);
  1998. if (result != null)
  1999. {
  2000. mx.erp_mtrlcode = result.mtrlcode;
  2001. mx.erp_mtrlname = result.mtrlname;
  2002. mx.erp_mtrlmode = result.mtrlmode;
  2003. mx.erp_unit = result.unit;
  2004. mx.erp_mtrlengname = result.zxmtrlmode;
  2005. }
  2006. }
  2007. }
  2008. }
  2009. //更新 二级明细项目 需要产品配置列表,此部分由前端完成
  2010. if (interfaceList != null && interfaceList.Any())
  2011. {
  2012. // 使用 GroupBy 去重并选择第一个元素
  2013. var distinctList = interfaceList
  2014. .GroupBy(mb => mb.bj_pzname)
  2015. .Select(g => g.First())
  2016. .ToList();
  2017. Dictionary<string, S> interfaceDict = distinctList.ToDictionary(mb => mb.bj_pzname, mb => mb);
  2018. foreach (var mx in qdList)
  2019. {
  2020. if (interfaceDict.TryGetValue(mx.bj_pzname, out var mb))
  2021. {
  2022. mx.bj_pzname_mx_mx = mb.bj_namemx;
  2023. if (mx is u_mattress_interface_qd mattressMx && mb is u_mattress_interface mattressMx2)
  2024. {
  2025. if (mattressMx.ss_rate == 0) mattressMx.ss_rate = mattressMx2.ss_rate;
  2026. if (mattressMx.ls_rate == 0) mattressMx.ls_rate = mattressMx2.ls_rate;
  2027. }
  2028. }
  2029. }
  2030. }
  2031. }
  2032. /// <summary>
  2033. /// 初始化配置信息
  2034. /// </summary>
  2035. /// <param name="itemname"></param>
  2036. /// <param name="bj_pzname"></param>
  2037. /// <param name="inputtype"></param>
  2038. /// <param name="names"></param>
  2039. /// <returns></returns>
  2040. public T InserInterfacePz<T>(string itemname, string bj_pzname, byte inputtype, string[] names) where T : BaseInterface, new()
  2041. {
  2042. var mattress_interface = new T()
  2043. {
  2044. itemname = itemname,
  2045. bj_pzname = bj_pzname,
  2046. bj_inputtype = inputtype,
  2047. bj_namemx = names == null ? string.Empty : SetInterfacePzName(names)
  2048. };
  2049. return mattress_interface;
  2050. }
  2051. /// <summary>
  2052. /// 查询清单的配置
  2053. /// </summary>
  2054. /// <param name="configcodetype"></param>
  2055. /// <param name="interfaceList"></param>
  2056. public void InterfaceFindERPPz<T>(int configcodetype, List<T> interfaceList) where T : BaseInterface
  2057. {
  2058. var resultList = new List<erp_configure_code>();
  2059. var typeList = new List<erp_configure_code>();
  2060. // 特殊匹配林氏辅料
  2061. var ifLSAccessory = false;
  2062. foreach (var item in interfaceList)
  2063. {
  2064. typeList.Add(new erp_configure_code() { typeid = configcodetype, name = item.bj_pzname });
  2065. if (!ifLSAccessory && item.itemname == "辅料" && item.bj_pzname.Contains("林氏") && !item.bj_pzname.Contains("林氏定制正标"))
  2066. {
  2067. ifLSAccessory = true;
  2068. }
  2069. }
  2070. var configure_Type = new u_configure_type() { contfigtypeid = configcodetype };
  2071. if (DbSqlHelper.SelectOne(cmd, configure_Type, "contfigtypeid") == 1)
  2072. {
  2073. var names = new List<string>();
  2074. foreach (var item in typeList)
  2075. {
  2076. if (!names.Contains(item.name))
  2077. {
  2078. names.Add(item.name);
  2079. }
  2080. }
  2081. var whereStr = "";
  2082. if (ifLSAccessory)
  2083. {
  2084. whereStr = " OR u_configure_code.name like '%林氏辅料%' ";
  2085. }
  2086. // 查询核价系统的配置资料定义
  2087. cmd.CommandText = @"SELECT u_configure_code.pzid
  2088. ,u_configure_code.pzcode
  2089. ,u_configure_code.name
  2090. ,u_configure_code.inputtype
  2091. FROM u_configure_code
  2092. WHERE u_configure_code.typeid = @configcodetype
  2093. AND (u_configure_code.name IN " + ListEx.getString(names) + whereStr + " )";
  2094. cmd.Parameters.Clear();
  2095. cmd.Parameters.AddWithValue("@configcodetype", configcodetype);
  2096. using (var reader = cmd.ExecuteReader())
  2097. {
  2098. while (reader.Read())
  2099. {
  2100. var item = new erp_configure_code()
  2101. {
  2102. pzid = Convert.ToInt32(reader["pzid"]),
  2103. pzcode = Convert.ToString(reader["pzcode"]),
  2104. name = Convert.ToString(reader["name"]).Trim(),
  2105. inputtype = Convert.ToInt32(reader["inputtype"])
  2106. };
  2107. resultList.Add(item);
  2108. }
  2109. }
  2110. }
  2111. else
  2112. {
  2113. // 查询L1部件选配
  2114. var erpHelper = GetHelper<ERPHelper>(null);
  2115. var parameters = new JObject();
  2116. parameters.Add("typeList", JToken.FromObject(typeList));
  2117. resultList = erpHelper.GetERPList<erp_configure_code>("GetL1ConfigureCode", parameters);
  2118. }
  2119. var LSIndex = 0;
  2120. for (var i = 0; i < interfaceList.Count; i++)
  2121. {
  2122. interfaceList[i].printid = i + 1;
  2123. var matchState = false;
  2124. foreach (var result in resultList)
  2125. {
  2126. if (interfaceList[i].bj_pzname == result.name)
  2127. {
  2128. matchState = true;
  2129. if (result.pzid > 0)
  2130. {
  2131. interfaceList[i].erp_pzid = result.pzid;
  2132. interfaceList[i].erp_pzcode = result.pzcode;
  2133. interfaceList[i].erp_pzname = result.name;
  2134. }
  2135. //if (interfaceList[i].bj_inputtype != 2)
  2136. interfaceList[i].bj_inputtype = result.inputtype;
  2137. }
  2138. }
  2139. if (ifLSAccessory && !matchState && interfaceList[i].itemname == "辅料" && interfaceList[i].bj_pzname.Contains("林氏") && !interfaceList[i].bj_pzname.Contains("林氏定制正标"))
  2140. {
  2141. if (!interfaceList[i].bj_pzname.Contains("位置"))
  2142. {
  2143. LSIndex++;
  2144. }
  2145. foreach (var result in resultList)
  2146. {
  2147. var _pzname = string.Format("林氏辅料{0}{1}", LSIndex, interfaceList[i].bj_pzname.Contains("位置") ? "位置" : "");
  2148. if (result.name == _pzname)
  2149. {
  2150. matchState = true;
  2151. if (result.pzid > 0)
  2152. {
  2153. interfaceList[i].erp_pzid = result.pzid;
  2154. interfaceList[i].erp_pzcode = result.pzcode;
  2155. interfaceList[i].erp_pzname = result.name;
  2156. }
  2157. if (interfaceList[i].bj_inputtype != 2) interfaceList[i].bj_inputtype = result.inputtype;
  2158. }
  2159. }
  2160. }
  2161. }
  2162. }
  2163. /// <summary>
  2164. /// 用于 字符串 + 字符串格式
  2165. /// </summary>
  2166. /// <param name="currentString"></param>
  2167. /// <param name="newPart"></param>
  2168. /// <returns></returns>
  2169. private string AppendToString(string currentString, string newPart)
  2170. {
  2171. if (string.IsNullOrEmpty(currentString))
  2172. {
  2173. return newPart;
  2174. }
  2175. else
  2176. {
  2177. return currentString + " + " + newPart;
  2178. }
  2179. }
  2180. /// <summary>
  2181. /// 数量分割字符串
  2182. /// </summary>
  2183. /// <param name="name"></param>
  2184. /// <param name="qty"></param>
  2185. /// <returns></returns>
  2186. private string SplitNameCount(string name, int qty)
  2187. {
  2188. if (qty <= 1) return name;
  2189. var result = name;
  2190. result = AppendToString(result, SplitNameCount(name, --qty));
  2191. return result;
  2192. }
  2193. #endregion
  2194. #region 全局变量
  2195. // 储存顶布裥棉数据
  2196. private string[,] DingBuLianMian = new string[4,5];
  2197. private enum PackType
  2198. {
  2199. 压包 = 0,
  2200. 卷包,
  2201. 国内
  2202. }
  2203. private enum InputType
  2204. {
  2205. 选择 = 0,
  2206. 录入,
  2207. 带出
  2208. }
  2209. public static string BillKeyWord = BillNames.MattressInterface;
  2210. #endregion
  2211. }
  2212. }