InterfaceHelper.cs 76 KB

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