InterfaceHelper.cs 78 KB

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