InterfaceHelper.cs 85 KB

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