InterfaceHelper.cs 93 KB

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