InterfaceHelper.cs 81 KB

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