BedNetHelper.cs 97 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942
  1. using DirectService.Tools;
  2. using JLHHJSvr.BLL;
  3. using JLHHJSvr.Com.Model;
  4. using JLHHJSvr.LJException;
  5. using JLHHJSvr.LJFramework.Tools;
  6. using LJLib.DAL.SQL;
  7. using System;
  8. using System.Collections.Generic;
  9. using System.Data.SqlClient;
  10. using System.Linq;
  11. using System.Text;
  12. using System.Threading.Tasks;
  13. namespace JLHHJSvr.Helper
  14. {
  15. internal class BedNetHelper : HelperBase
  16. {
  17. private Dictionary<string, object> replacements = new Dictionary<string, object>();
  18. public void CalCulateFormula(u_bednet bednet, List<u_bednetmx> mxlist, List<u_bednetmx_spring> springList)
  19. {
  20. InitBedNet(bednet);
  21. InitReplaceMents(bednet);
  22. CulcalateCost(bednet, mxlist, springList);
  23. CulcalateWeight(bednet, mxlist, springList);
  24. }
  25. private void CulcalateCost(u_bednet bednet, List<u_bednetmx> mxlist, List<u_bednetmx_spring> springList)
  26. {
  27. foreach (var mx in mxlist)
  28. {
  29. var spring = new u_spring() { springid = mx.springid };
  30. DbSqlHelper.SelectOne(cmd, spring, "line_diameter,gram_weight,height,center_diameter");
  31. // 处理相同公式部分
  32. InitMxReplaceMents(bednet, mx, spring);
  33. //计算 弹簧材料总成本
  34. #region 计算 弹簧材料总成本 开始
  35. if (!string.IsNullOrEmpty(bednet.spring_mtrl_formula))
  36. {
  37. bednet.spring_mtrl_formula = ConvertToEnglishSymbols(bednet.spring_mtrl_formula);
  38. mx.spring_mtrl_cost_replace_formula = bednet.spring_mtrl_formula;
  39. if (mx.if_part == 0)
  40. {
  41. //单分区
  42. //考虑 四周加硬和四周口袋 扣减 排列数情况
  43. if (mx.if_hard_around == 1)
  44. {
  45. decimal hard_around_row = mx.hard_around_row.Value;
  46. if (bednet.typename.IndexOf("袋装", StringComparison.Ordinal) >= 0) hard_around_row *= 2;
  47. mx.spring_mtrl_cost_replace_formula = ReplaceWith(mx.spring_mtrl_cost_replace_formula, "【弹簧排列个数-宽】", $"(【弹簧排列个数-宽】 - {hard_around_row})");
  48. mx.spring_mtrl_cost_replace_formula = ReplaceWith(mx.spring_mtrl_cost_replace_formula, "【弹簧计算个数(宽)】", $"(【弹簧计算个数(宽)】 - {hard_around_row})");
  49. mx.spring_mtrl_cost_replace_formula = ReplaceWith(mx.spring_mtrl_cost_replace_formula, "【弹簧排列个数-长】", $"(【弹簧排列个数-长】 - {hard_around_row})");
  50. mx.spring_mtrl_cost_replace_formula = ReplaceWith(mx.spring_mtrl_cost_replace_formula, "【弹簧计算个数(长)】", $"(【弹簧计算个数(长)】 - {hard_around_row})");
  51. }
  52. if (mx.if_pocket_around == 1)
  53. {
  54. decimal pocket_around_row = mx.pocket_around_row.Value;
  55. if (bednet.typename.IndexOf("袋装", StringComparison.Ordinal) >= 0) pocket_around_row *= 2;
  56. mx.spring_mtrl_cost_replace_formula = ReplaceWith(mx.spring_mtrl_cost_replace_formula, "【弹簧排列个数-宽】", $"(【弹簧排列个数-宽】 - {pocket_around_row})");
  57. mx.spring_mtrl_cost_replace_formula = ReplaceWith(mx.spring_mtrl_cost_replace_formula, "【弹簧计算个数(宽)】", $"(【弹簧计算个数(宽)】 - {pocket_around_row})");
  58. mx.spring_mtrl_cost_replace_formula = ReplaceWith(mx.spring_mtrl_cost_replace_formula, "【弹簧排列个数-长】", $"(【弹簧排列个数-长】 - {pocket_around_row})");
  59. mx.spring_mtrl_cost_replace_formula = ReplaceWith(mx.spring_mtrl_cost_replace_formula, "【弹簧计算个数(长)】", $"(【弹簧计算个数(长)】 - {pocket_around_row})");
  60. }
  61. foreach (var replacement in replacements)
  62. {
  63. mx.spring_mtrl_cost_replace_formula = ReplaceWith(mx.spring_mtrl_cost_replace_formula, replacement.Key, Convert.ToString(replacement.Value));
  64. }
  65. try
  66. {
  67. var res = LJExprParser.Parse(mx.spring_mtrl_cost_replace_formula);
  68. mx.spring_mtrl_cost = res.Result.DecimalValue;
  69. bednet.spring_mtrl_cost += mx.spring_mtrl_cost;
  70. }
  71. catch (Exception ex)
  72. {
  73. throw new LJCommonException("弹簧材料总成本公式错误!");
  74. }
  75. }
  76. else
  77. {
  78. //多分区
  79. foreach (var springItem in springList)
  80. {
  81. springItem.spring_mtrl_cost_replace_formula = bednet.spring_mtrl_formula;
  82. CalSpringMtrlCol(bednet, mx, springItem);
  83. foreach (var replacement in replacements)
  84. {
  85. mx.spring_mtrl_cost_replace_formula = ReplaceWith(springItem.spring_mtrl_cost_replace_formula, replacement.Key, Convert.ToString(replacement.Value));
  86. }
  87. try
  88. {
  89. var res = LJExprParser.Parse(springItem.spring_mtrl_cost_replace_formula);
  90. springItem.spring_mtrl_cost = res.Result.DecimalValue;
  91. mx.spring_mtrl_cost += springItem.spring_mtrl_cost;
  92. bednet.spring_mtrl_cost += mx.spring_mtrl_cost;
  93. }
  94. catch (Exception ex)
  95. {
  96. throw new LJCommonException("弹簧材料总成本公式错误!");
  97. }
  98. }
  99. }
  100. }
  101. #endregion 计算 弹簧材料总成本 结束
  102. #region 计算 弹簧人工总成本 开始
  103. if (!string.IsNullOrEmpty(bednet.spring_hr_formula))
  104. {
  105. bednet.spring_hr_formula = ConvertToEnglishSymbols(bednet.spring_hr_formula);
  106. mx.spring_hr_cost_replace_formula = bednet.spring_hr_formula;
  107. foreach (var replacement in replacements)
  108. {
  109. mx.spring_hr_cost_replace_formula = ReplaceWith(mx.spring_hr_cost_replace_formula, replacement.Key, Convert.ToString(replacement.Value));
  110. }
  111. try
  112. {
  113. var res = LJExprParser.Parse(mx.spring_hr_cost_replace_formula);
  114. mx.spring_hr_cost = res.Result.DecimalValue;
  115. bednet.spring_hr_cost += mx.spring_hr_cost;
  116. }
  117. catch (Exception ex)
  118. {
  119. throw new LJCommonException("弹簧总人工成本公式错误!");
  120. }
  121. }
  122. #endregion 计算 弹簧人工总成本 结束
  123. #region 计算 蛇线材料成本 开始
  124. if (!string.IsNullOrEmpty(bednet.spring_hr_formula))
  125. {
  126. bednet.snake_wire_mtrl_formula = ConvertToEnglishSymbols(bednet.snake_wire_mtrl_formula);
  127. bednet.snake_wire_mtrl_cost_replace_formula = bednet.snake_wire_mtrl_formula;
  128. CalSnakeCol(bednet,spring);
  129. foreach (var replacement in replacements)
  130. {
  131. bednet.snake_wire_mtrl_cost_replace_formula = ReplaceWith(bednet.snake_wire_mtrl_cost_replace_formula, replacement.Key, Convert.ToString(replacement.Value));
  132. }
  133. try
  134. {
  135. var res = LJExprParser.Parse(bednet.snake_wire_mtrl_cost_replace_formula);
  136. bednet.snake_wire_mtrl_cost += res.Result.DecimalValue;
  137. }
  138. catch (Exception ex)
  139. {
  140. throw new LJCommonException("蛇线材料成本公式错误!");
  141. }
  142. }
  143. #endregion 计算 蛇线材料成本 结束
  144. #region 计算 四周口袋弹簧成本 开始
  145. if (!string.IsNullOrEmpty(bednet.pocket_around_spring_formula) && mx.if_pocket_around > 0)
  146. {
  147. bednet.pocket_around_spring_formula = ConvertToEnglishSymbols(bednet.pocket_around_spring_formula);
  148. mx.pocket_around_spring_cost_replace_formula = bednet.pocket_around_spring_formula;
  149. foreach (var replacement in replacements)
  150. {
  151. mx.pocket_around_spring_cost_replace_formula = ReplaceWith(mx.pocket_around_spring_cost_replace_formula, replacement.Key, Convert.ToString(replacement.Value));
  152. }
  153. try
  154. {
  155. var res = LJExprParser.Parse(mx.pocket_around_spring_cost_replace_formula);
  156. mx.pocket_around_spring_cost = res.Result.DecimalValue;
  157. bednet.pocket_around_spring_cost += mx.pocket_around_spring_cost;
  158. }
  159. catch (Exception ex)
  160. {
  161. throw new LJCommonException("四周口袋弹簧成本公式错误!");
  162. }
  163. }
  164. #endregion 计算 四周口袋弹簧成本 结束
  165. #region 计算 四周口袋无纺布成本 开始
  166. if (!string.IsNullOrEmpty(bednet.pocket_around_fabrics_formula) && mx.if_pocket_around > 0)
  167. {
  168. bednet.pocket_around_fabrics_formula = ConvertToEnglishSymbols(bednet.pocket_around_fabrics_formula);
  169. mx.pocket_around_fabrics_cost_replace_formula = bednet.pocket_around_fabrics_formula;
  170. foreach (var replacement in replacements)
  171. {
  172. mx.pocket_around_fabrics_cost_replace_formula = ReplaceWith(mx.pocket_around_fabrics_cost_replace_formula, replacement.Key, Convert.ToString(replacement.Value));
  173. }
  174. try
  175. {
  176. var res = LJExprParser.Parse(mx.pocket_around_fabrics_cost_replace_formula);
  177. mx.pocket_around_fabrics_cost = res.Result.DecimalValue;
  178. bednet.pocket_around_fabrics_cost += mx.pocket_around_fabrics_cost;
  179. }
  180. catch (Exception ex)
  181. {
  182. throw new LJCommonException("四周口袋无纺布成本公式错误!");
  183. }
  184. }
  185. #endregion 计算 四周口袋无纺布成本 结束
  186. #region 计算 四周加硬材料成本 开始
  187. if (!string.IsNullOrEmpty(bednet.hard_around_mtrl_formula) && mx.if_hard_around > 0)
  188. {
  189. bednet.hard_around_mtrl_formula = ConvertToEnglishSymbols(bednet.hard_around_mtrl_formula);
  190. mx.hard_around_mtrl_cost_replace_formula = bednet.hard_around_mtrl_formula;
  191. foreach (var replacement in replacements)
  192. {
  193. mx.hard_around_mtrl_cost_replace_formula = ReplaceWith(mx.hard_around_mtrl_cost_replace_formula, replacement.Key, Convert.ToString(replacement.Value));
  194. }
  195. try
  196. {
  197. var res = LJExprParser.Parse(mx.hard_around_mtrl_cost_replace_formula);
  198. mx.hard_around_mtrl_cost = res.Result.DecimalValue;
  199. bednet.hard_around_mtrl_cost += mx.hard_around_mtrl_cost;
  200. }
  201. catch (Exception ex)
  202. {
  203. throw new LJCommonException("四周加硬材料成本公式错误!");
  204. }
  205. }
  206. #endregion 计算 四周加硬材料成本 结束
  207. #region 计算 四周加硬人力成本 开始
  208. if (!string.IsNullOrEmpty(bednet.hard_around_hr_formula) && mx.if_hard_around > 0)
  209. {
  210. bednet.hard_around_hr_formula = ConvertToEnglishSymbols(bednet.hard_around_hr_formula);
  211. mx.hard_around_hr_cost_replace_formula = bednet.hard_around_hr_formula;
  212. foreach (var replacement in replacements)
  213. {
  214. mx.hard_around_hr_cost_replace_formula = ReplaceWith(mx.hard_around_hr_cost_replace_formula, replacement.Key, Convert.ToString(replacement.Value));
  215. }
  216. try
  217. {
  218. var res = LJExprParser.Parse(mx.hard_around_hr_cost_replace_formula);
  219. mx.hard_around_hr_cost = res.Result.DecimalValue;
  220. bednet.hard_around_hr_cost += mx.hard_around_hr_cost;
  221. }
  222. catch (Exception ex)
  223. {
  224. throw new LJCommonException("四周加硬人力成本公式错误!");
  225. }
  226. }
  227. #endregion 计算 四周加硬人力成本 结束
  228. #region 计算 入袋无纺布材料成本 开始
  229. if (!string.IsNullOrEmpty(bednet.hard_around_hr_formula) && bednet.typename.IndexOf("袋装网") > -1 && mx.fabrics1_mtrlid > 0)
  230. {
  231. bednet.fabrics1_mtrl_formula = ConvertToEnglishSymbols(bednet.fabrics1_mtrl_formula);
  232. mx.fabrics1_mtrl_cost_replace_formula = bednet.fabrics1_mtrl_formula;
  233. CalSpringMtrlCol2(bednet, mx, "入袋无纺布");
  234. foreach (var replacement in replacements)
  235. {
  236. mx.fabrics1_mtrl_cost_replace_formula = ReplaceWith(mx.fabrics1_mtrl_cost_replace_formula, replacement.Key, Convert.ToString(replacement.Value));
  237. }
  238. try
  239. {
  240. var res = LJExprParser.Parse(mx.fabrics1_mtrl_cost_replace_formula);
  241. mx.fabrics1_mtrl_cost = res.Result.DecimalValue;
  242. bednet.fabrics1_mtrl_cost += mx.fabrics1_mtrl_cost;
  243. }
  244. catch (Exception ex)
  245. {
  246. throw new LJCommonException("入袋无纺布材料成本公式错误!");
  247. }
  248. }
  249. #endregion 计算 入袋无纺布材料成本 结束
  250. #region 计算 胶水材料成本 开始
  251. if (!string.IsNullOrEmpty(bednet.glue_mtrl_formula))
  252. {
  253. bednet.glue_mtrl_formula = ConvertToEnglishSymbols(bednet.glue_mtrl_formula);
  254. mx.glue_mtrl_cost_replace_formula = bednet.glue_mtrl_formula;
  255. foreach (var replacement in replacements)
  256. {
  257. mx.glue_mtrl_cost_replace_formula = ReplaceWith(mx.glue_mtrl_cost_replace_formula, replacement.Key, Convert.ToString(replacement.Value));
  258. }
  259. try
  260. {
  261. var res = LJExprParser.Parse(mx.glue_mtrl_cost_replace_formula);
  262. bednet.glue_mtrl_cost += res.Result.DecimalValue;
  263. }
  264. catch (Exception ex)
  265. {
  266. throw new LJCommonException("胶水材料成本公式错误!");
  267. }
  268. }
  269. #endregion 计算 胶水材料成本 结束
  270. #region 计算 底面无纺布材料成本 开始
  271. if (!string.IsNullOrEmpty(bednet.hard_around_hr_formula) && bednet.typename.IndexOf("袋装网") > -1 && mx.fabrics2_mtrlid > 0)
  272. {
  273. bednet.fabrics2_mtrl_formula = ConvertToEnglishSymbols(bednet.fabrics2_mtrl_formula);
  274. mx.fabrics2_mtrl_cost_replace_formula = bednet.fabrics2_mtrl_formula;
  275. CalSpringMtrlCol2(bednet, mx, "底面无纺布");
  276. foreach (var replacement in replacements)
  277. {
  278. mx.fabrics2_mtrl_cost_replace_formula = ReplaceWith(mx.fabrics2_mtrl_cost_replace_formula, replacement.Key, Convert.ToString(replacement.Value));
  279. }
  280. try
  281. {
  282. var res = LJExprParser.Parse(mx.fabrics2_mtrl_cost_replace_formula);
  283. mx.fabrics2_mtrl_cost = res.Result.DecimalValue;
  284. bednet.fabrics2_mtrl_cost += mx.fabrics2_mtrl_cost;
  285. }
  286. catch (Exception ex)
  287. {
  288. throw new LJCommonException("底面无纺布材料成本公式错误!");
  289. }
  290. }
  291. #endregion 计算 底面无纺布材料成本 结束
  292. #region 计算 边铁人力成本 开始
  293. if (!string.IsNullOrEmpty(bednet.side_iron_hr_formula) && bednet.if_side_iron == 1 && mx.if_side_iron > 0)
  294. {
  295. bednet.side_iron_hr_formula = ConvertToEnglishSymbols(bednet.side_iron_hr_formula);
  296. mx.side_iron_hr_cost_replace_formula = bednet.side_iron_hr_formula;
  297. foreach (var replacement in replacements)
  298. {
  299. mx.side_iron_hr_cost_replace_formula = ReplaceWith(mx.side_iron_hr_cost_replace_formula, replacement.Key, Convert.ToString(replacement.Value));
  300. }
  301. try
  302. {
  303. var res = LJExprParser.Parse(mx.side_iron_hr_cost_replace_formula);
  304. mx.side_iron_hr_cost += res.Result.DecimalValue;
  305. bednet.side_iron_hr_cost = mx.side_iron_hr_cost;
  306. }
  307. catch (Exception ex)
  308. {
  309. throw new LJCommonException("边铁人力成本公式错误!");
  310. }
  311. }
  312. #endregion 计算 边铁人力成本 结束
  313. #region 计算 边铁材料成本 开始
  314. if (!string.IsNullOrEmpty(bednet.side_iron_mtrl_formula) && bednet.if_side_iron == 1 && mx.if_side_iron > 0)
  315. {
  316. bednet.side_iron_mtrl_formula = ConvertToEnglishSymbols(bednet.side_iron_mtrl_formula);
  317. mx.side_iron_mtrl_cost_replace_formula = bednet.side_iron_mtrl_formula;
  318. foreach (var replacement in replacements)
  319. {
  320. mx.side_iron_mtrl_cost_replace_formula = ReplaceWith(mx.side_iron_mtrl_cost_replace_formula, replacement.Key, Convert.ToString(replacement.Value));
  321. }
  322. try
  323. {
  324. var res = LJExprParser.Parse(mx.side_iron_mtrl_cost_replace_formula);
  325. mx.side_iron_mtrl_cost = res.Result.DecimalValue;
  326. bednet.side_iron_mtrl_cost += mx.side_iron_mtrl_cost;
  327. }
  328. catch (Exception ex)
  329. {
  330. throw new LJCommonException("边铁材料成本公式错误!");
  331. }
  332. }
  333. #endregion 计算 边铁材料成本 结束
  334. #region 计算 C钉/夹码材料 开始
  335. if (!string.IsNullOrEmpty(bednet.cnail_mtrl_formula))
  336. {
  337. bednet.cnail_mtrl_formula = ConvertToEnglishSymbols(bednet.cnail_mtrl_formula);
  338. mx.cnail_mtrl_cost_replace_formula = bednet.cnail_mtrl_formula;
  339. foreach (var replacement in replacements)
  340. {
  341. mx.cnail_mtrl_cost_replace_formula = ReplaceWith(mx.cnail_mtrl_cost_replace_formula, replacement.Key, Convert.ToString(replacement.Value));
  342. }
  343. try
  344. {
  345. var res = LJExprParser.Parse(mx.cnail_mtrl_cost_replace_formula);
  346. mx.cnail_mtrl_cost = res.Result.DecimalValue;
  347. bednet.cnail_mtrl_cost += mx.cnail_mtrl_cost;
  348. }
  349. catch (Exception ex)
  350. {
  351. throw new LJCommonException("C钉/夹码材料成本公式错误!");
  352. }
  353. }
  354. #endregion 计算 C钉/夹码材料 结束
  355. #region 计算 C钉/夹码人力成本 开始
  356. if (!string.IsNullOrEmpty(bednet.cnail_hr_formula))
  357. {
  358. bednet.cnail_hr_formula = ConvertToEnglishSymbols(bednet.cnail_hr_formula);
  359. mx.cnail_hr_cost_replace_formula = bednet.cnail_hr_formula;
  360. foreach (var replacement in replacements)
  361. {
  362. mx.cnail_hr_cost_replace_formula = ReplaceWith(mx.cnail_hr_cost_replace_formula, replacement.Key, Convert.ToString(replacement.Value));
  363. }
  364. try
  365. {
  366. var res = LJExprParser.Parse(mx.cnail_hr_cost_replace_formula);
  367. mx.cnail_hr_cost = res.Result.DecimalValue;
  368. bednet.cnail_hr_cost += mx.cnail_hr_cost;
  369. }
  370. catch (Exception ex)
  371. {
  372. throw new LJCommonException("C钉/夹码人力成本公式错误!");
  373. }
  374. }
  375. #endregion 计算 C钉/夹码人力成本 结束
  376. #region 计算 海绵包边材料成本 开始
  377. if (!string.IsNullOrEmpty(bednet.sponge_mtrl_formula) && bednet.sponge_mtrlid > 0)
  378. {
  379. bednet.sponge_mtrl_formula = ConvertToEnglishSymbols(bednet.sponge_mtrl_formula);
  380. bednet.sponge_mtrl_cost_replace_formula = bednet.sponge_mtrl_formula;
  381. CalSpringMtrlCol2(bednet, mx, "海绵包边");
  382. foreach (var replacement in replacements)
  383. {
  384. bednet.sponge_mtrl_cost_replace_formula = ReplaceWith(bednet.sponge_mtrl_cost_replace_formula, replacement.Key, Convert.ToString(replacement.Value));
  385. }
  386. try
  387. {
  388. var res = LJExprParser.Parse(bednet.sponge_mtrl_cost_replace_formula);
  389. bednet.sponge_mtrl_cost += res.Result.DecimalValue;
  390. }
  391. catch (Exception ex)
  392. {
  393. throw new LJCommonException("海绵包边材料成本公式错误!");
  394. }
  395. }
  396. #endregion 计算 海绵包边材料成本 结束
  397. #region 计算 海绵包边人力成本 开始
  398. if (!string.IsNullOrEmpty(bednet.sponge_hr_formula) && bednet.sponge_mtrlid > 0)
  399. {
  400. bednet.sponge_hr_formula = ConvertToEnglishSymbols(bednet.sponge_hr_formula);
  401. bednet.sponge_hr_cost_replace_formula = bednet.sponge_hr_formula;
  402. foreach (var replacement in replacements)
  403. {
  404. bednet.sponge_hr_cost_replace_formula = ReplaceWith(bednet.sponge_hr_cost_replace_formula, replacement.Key, Convert.ToString(replacement.Value));
  405. }
  406. try
  407. {
  408. var res = LJExprParser.Parse(bednet.sponge_hr_cost_replace_formula);
  409. bednet.sponge_hr_cost += res.Result.DecimalValue;
  410. }
  411. catch (Exception ex)
  412. {
  413. throw new LJCommonException("海绵包边人力成本公式错误!");
  414. }
  415. }
  416. #endregion 计算 海绵包边人力成本 结束
  417. #region 计算 填充海绵成本 开始
  418. if (!string.IsNullOrEmpty(bednet.sponge_mtrl_tc_formula) && bednet.sponge_tc_mtrlid > 0)
  419. {
  420. bednet.sponge_mtrl_tc_formula = ConvertToEnglishSymbols(bednet.sponge_mtrl_tc_formula);
  421. bednet.sponge_mtrl_tc_cost_replace_formula = bednet.sponge_mtrl_tc_formula;
  422. CalSpringMtrlCol2(bednet, mx, "填充海绵");
  423. foreach (var replacement in replacements)
  424. {
  425. bednet.sponge_mtrl_tc_cost_replace_formula = ReplaceWith(bednet.sponge_mtrl_tc_cost_replace_formula, replacement.Key, Convert.ToString(replacement.Value));
  426. }
  427. try
  428. {
  429. var res = LJExprParser.Parse(bednet.sponge_mtrl_tc_cost_replace_formula);
  430. bednet.sponge_mtrl_tc_cost += res.Result.DecimalValue;
  431. }
  432. catch (Exception ex)
  433. {
  434. throw new LJCommonException("填充海绵成本公式错误!");
  435. }
  436. }
  437. #endregion 计算 填充海绵成本 结束
  438. #region 计算 封边材料成本 开始
  439. if (!string.IsNullOrEmpty(bednet.edge_mtrl_formula) && bednet.edge_mtrlid > 0)
  440. {
  441. bednet.edge_mtrl_formula = ConvertToEnglishSymbols(bednet.edge_mtrl_formula);
  442. bednet.edge_mtrl_cost_replace_formula = bednet.edge_mtrl_formula;
  443. CalSpringMtrlCol2(bednet, mx, "封边");
  444. foreach (var replacement in replacements)
  445. {
  446. bednet.edge_mtrl_cost_replace_formula = ReplaceWith(bednet.edge_mtrl_cost_replace_formula, replacement.Key, Convert.ToString(replacement.Value));
  447. }
  448. try
  449. {
  450. var res = LJExprParser.Parse(bednet.edge_mtrl_cost_replace_formula);
  451. bednet.edge_mtrl_cost += res.Result.DecimalValue;
  452. }
  453. catch (Exception ex)
  454. {
  455. throw new LJCommonException("封边材料成本公式错误!");
  456. }
  457. }
  458. #endregion 计算 封边材料成本 结束
  459. #region 计算 封边人力成本 开始
  460. if (!string.IsNullOrEmpty(bednet.edge_hr_formula) && bednet.edge_mtrlid > 0)
  461. {
  462. bednet.edge_hr_formula = ConvertToEnglishSymbols(bednet.edge_hr_formula);
  463. bednet.edge_hr_cost_replace_formula = bednet.edge_hr_formula;
  464. foreach (var replacement in replacements)
  465. {
  466. bednet.edge_hr_cost_replace_formula = ReplaceWith(bednet.edge_hr_cost_replace_formula, replacement.Key, Convert.ToString(replacement.Value));
  467. }
  468. try
  469. {
  470. var res = LJExprParser.Parse(bednet.edge_hr_cost_replace_formula);
  471. bednet.edge_hr_cost += res.Result.DecimalValue;
  472. }
  473. catch (Exception ex)
  474. {
  475. throw new LJCommonException("封边人力成本公式错误!");
  476. }
  477. }
  478. #endregion 计算 封边人力成本 结束
  479. #region 计算 弹叉材料成本 开始
  480. if (!string.IsNullOrEmpty(bednet.fork_mtrl_formula) && bednet.fork_qty > 0)
  481. {
  482. bednet.fork_mtrl_formula = ConvertToEnglishSymbols(bednet.fork_mtrl_formula);
  483. bednet.fork_mtrl_cost_replace_formula = bednet.fork_mtrl_formula;
  484. foreach (var replacement in replacements)
  485. {
  486. bednet.fork_mtrl_cost_replace_formula = ReplaceWith(bednet.fork_mtrl_cost_replace_formula, replacement.Key, Convert.ToString(replacement.Value));
  487. }
  488. try
  489. {
  490. var res = LJExprParser.Parse(bednet.fork_mtrl_cost_replace_formula);
  491. bednet.fork_mtrl_cost += res.Result.DecimalValue;
  492. }
  493. catch (Exception ex)
  494. {
  495. throw new LJCommonException("弹叉材料成本公式错误!");
  496. }
  497. }
  498. #endregion 计算 弹叉材料成本 结束
  499. #region 计算 弹叉人力成本 开始
  500. if (!string.IsNullOrEmpty(bednet.fork_hr_formula) && bednet.fork_qty > 0)
  501. {
  502. bednet.fork_hr_formula = ConvertToEnglishSymbols(bednet.fork_hr_formula);
  503. bednet.fork_hr_cost_replace_formula = bednet.fork_hr_formula;
  504. foreach (var replacement in replacements)
  505. {
  506. bednet.fork_hr_cost_replace_formula = ReplaceWith(bednet.fork_hr_cost_replace_formula, replacement.Key, Convert.ToString(replacement.Value));
  507. }
  508. try
  509. {
  510. var res = LJExprParser.Parse(bednet.fork_hr_cost_replace_formula);
  511. bednet.fork_hr_cost += res.Result.DecimalValue;
  512. }
  513. catch (Exception ex)
  514. {
  515. throw new LJCommonException("弹叉材料成本公式错误!");
  516. }
  517. }
  518. #endregion 计算 弹叉人力成本 结束
  519. #region 计算 胶条/包角材料成本 开始
  520. if (!string.IsNullOrEmpty(bednet.rsorwa_mtrl_formula) && bednet.if_rsorwa == 1)
  521. {
  522. bednet.rsorwa_mtrl_formula = ConvertToEnglishSymbols(bednet.rsorwa_mtrl_formula);
  523. bednet.rsorwa_mtrl_cost_replace_formula = bednet.rsorwa_mtrl_formula;
  524. foreach (var replacement in replacements)
  525. {
  526. bednet.rsorwa_mtrl_cost_replace_formula = ReplaceWith(bednet.rsorwa_mtrl_cost_replace_formula, replacement.Key, Convert.ToString(replacement.Value));
  527. }
  528. try
  529. {
  530. var res = LJExprParser.Parse(bednet.rsorwa_mtrl_cost_replace_formula);
  531. bednet.rsorwa_mtrl_cost += res.Result.DecimalValue;
  532. }
  533. catch (Exception ex)
  534. {
  535. throw new LJCommonException("胶条/包角材料成本公式错误!");
  536. }
  537. }
  538. #endregion 计算 胶条/包角材料成本 结束
  539. #region 计算 胶条/包角人力成本 开始
  540. if (!string.IsNullOrEmpty(bednet.rsorwa_hr_formula) && bednet.if_rsorwa == 1)
  541. {
  542. bednet.rsorwa_hr_formula = ConvertToEnglishSymbols(bednet.rsorwa_hr_formula);
  543. bednet.rsorwa_hr_cost_replace_formula = bednet.rsorwa_hr_formula;
  544. foreach (var replacement in replacements)
  545. {
  546. bednet.rsorwa_hr_cost_replace_formula = ReplaceWith(bednet.rsorwa_hr_cost_replace_formula, replacement.Key, Convert.ToString(replacement.Value));
  547. }
  548. try
  549. {
  550. var res = LJExprParser.Parse(bednet.rsorwa_hr_cost_replace_formula);
  551. bednet.rsorwa_hr_cost += res.Result.DecimalValue;
  552. }
  553. catch (Exception ex)
  554. {
  555. throw new LJCommonException("胶条/包角人力成本公式错误!");
  556. }
  557. }
  558. #endregion 计算 胶条/包角人力成本 结束
  559. #region 计算 海绵打孔人力成本 开始
  560. if (!string.IsNullOrEmpty(bednet.sponge_drilling_hr_formula) && bednet.if_sponge_drilling == 1)
  561. {
  562. bednet.sponge_drilling_hr_formula = ConvertToEnglishSymbols(bednet.sponge_drilling_hr_formula);
  563. bednet.sponge_drilling_hr_cost_replace_formula = bednet.sponge_drilling_hr_formula;
  564. foreach (var replacement in replacements)
  565. {
  566. bednet.sponge_drilling_hr_cost_replace_formula = ReplaceWith(bednet.sponge_drilling_hr_cost_replace_formula, replacement.Key, Convert.ToString(replacement.Value));
  567. }
  568. try
  569. {
  570. var res = LJExprParser.Parse(bednet.sponge_drilling_hr_cost_replace_formula);
  571. bednet.sponge_drilling_hr_cost += res.Result.DecimalValue;
  572. }
  573. catch (Exception ex)
  574. {
  575. throw new LJCommonException("海绵打孔人力成本公式错误!");
  576. }
  577. }
  578. #endregion 计算 海绵打孔人力成本 结束
  579. #region 计算 上垫层物料成本 开始
  580. if (!string.IsNullOrEmpty(bednet.felt_mtrl_formula) && bednet.felt_qty > 0)
  581. {
  582. bednet.felt_mtrl_formula = ConvertToEnglishSymbols(bednet.felt_mtrl_formula);
  583. bednet.felt_mtrl_cost_replace_formula = bednet.felt_mtrl_formula;
  584. CalSpringMtrlCol2(bednet, mx, "上垫层");
  585. foreach (var replacement in replacements)
  586. {
  587. bednet.felt_mtrl_cost_replace_formula = ReplaceWith(bednet.felt_mtrl_cost_replace_formula, replacement.Key, Convert.ToString(replacement.Value));
  588. }
  589. try
  590. {
  591. var res = LJExprParser.Parse(bednet.felt_mtrl_cost_replace_formula);
  592. bednet.felt_mtrl_cost += res.Result.DecimalValue;
  593. }
  594. catch (Exception ex)
  595. {
  596. throw new LJCommonException("上垫层物料成本公式错误!");
  597. }
  598. }
  599. #endregion 计算 上垫层物料成本 结束
  600. #region 计算 下垫层物料成本 开始
  601. if (!string.IsNullOrEmpty(bednet.felt_mtrl_formula) && bednet.felt_x_qty > 0)
  602. {
  603. bednet.felt_mtrl_formula = ConvertToEnglishSymbols(bednet.felt_mtrl_formula);
  604. bednet.felt_mtrl_x_cost_replace_formula = bednet.felt_mtrl_formula;
  605. CalSpringMtrlCol2(bednet, mx, "下垫层");
  606. foreach (var replacement in replacements)
  607. {
  608. bednet.felt_mtrl_x_cost_replace_formula = ReplaceWith(bednet.felt_mtrl_x_cost_replace_formula, replacement.Key, Convert.ToString(replacement.Value));
  609. }
  610. try
  611. {
  612. var res = LJExprParser.Parse(bednet.felt_mtrl_x_cost_replace_formula);
  613. bednet.felt_mtrl_x_cost += res.Result.DecimalValue;
  614. }
  615. catch (Exception ex)
  616. {
  617. throw new LJCommonException("下垫层物料成本公式错误!");
  618. }
  619. }
  620. #endregion 计算 下垫层物料成本 结束
  621. #region 计算 上垫层人力成本 开始
  622. if (!string.IsNullOrEmpty(bednet.felt_hr_formula) && bednet.felt_qty > 0)
  623. {
  624. bednet.felt_hr_formula = ConvertToEnglishSymbols(bednet.felt_hr_formula);
  625. bednet.felt_hr_cost_replace_formula = bednet.felt_hr_formula;
  626. foreach (var replacement in replacements)
  627. {
  628. bednet.felt_hr_cost_replace_formula = ReplaceWith(bednet.felt_hr_cost_replace_formula, replacement.Key, Convert.ToString(replacement.Value));
  629. }
  630. try
  631. {
  632. var res = LJExprParser.Parse(bednet.felt_hr_cost_replace_formula);
  633. bednet.felt_hr_cost += res.Result.DecimalValue;
  634. }
  635. catch (Exception ex)
  636. {
  637. throw new LJCommonException("上垫层人力成本公式错误!");
  638. }
  639. }
  640. #endregion 计算 上垫层人力成本 结束
  641. #region 计算 下垫层人力成本 开始
  642. if (!string.IsNullOrEmpty(bednet.felt_hr_formula) && bednet.felt_x_qty > 0)
  643. {
  644. bednet.felt_hr_formula = ConvertToEnglishSymbols(bednet.felt_hr_formula);
  645. bednet.felt_hr_x_cost_replace_formula = bednet.felt_hr_formula;
  646. CalSpringMtrlCol2(bednet, mx, "下垫层");
  647. foreach (var replacement in replacements)
  648. {
  649. bednet.felt_hr_x_cost_replace_formula = ReplaceWith(bednet.felt_hr_x_cost_replace_formula, replacement.Key, Convert.ToString(replacement.Value));
  650. }
  651. try
  652. {
  653. var res = LJExprParser.Parse(bednet.felt_hr_x_cost_replace_formula);
  654. bednet.felt_hr_x_cost += res.Result.DecimalValue;
  655. }
  656. catch (Exception ex)
  657. {
  658. throw new LJCommonException("下垫层物料成本公式错误!");
  659. }
  660. }
  661. #endregion 计算 下垫层人力成本 结束
  662. #region 计算 包装总成本 开始
  663. if (!string.IsNullOrEmpty(bednet.packet_mtrl_formula) && !string.IsNullOrEmpty(bednet.packtype))
  664. {
  665. bednet.packet_mtrl_formula = ConvertToEnglishSymbols(bednet.packet_mtrl_formula);
  666. bednet.packet_mtrl_cost_replace_formula = bednet.packet_mtrl_formula;
  667. bednet.packet_mtrl_cost_replace_formula = ReplaceWith(bednet.packet_mtrl_cost_replace_formula, "@@", "");
  668. foreach (var replacement in replacements)
  669. {
  670. bednet.packet_mtrl_cost_replace_formula = ReplaceWith(bednet.packet_mtrl_cost_replace_formula, replacement.Key, Convert.ToString(replacement.Value));
  671. }
  672. try
  673. {
  674. var res = LJExprParser.Parse(bednet.packet_mtrl_cost_replace_formula);
  675. bednet.packet_mtrl_cost += res.Result.DecimalValue;
  676. }
  677. catch (Exception ex)
  678. {
  679. throw new LJCommonException("包装材料成本公式错误!");
  680. }
  681. }
  682. #endregion 计算 包装总成本 结束
  683. #region 计算 包装人工成本 开始
  684. if (!string.IsNullOrEmpty(bednet.packet_hr_formula) && !string.IsNullOrEmpty(bednet.packtype))
  685. {
  686. bednet.packet_hr_formula = ConvertToEnglishSymbols(bednet.packet_hr_formula);
  687. bednet.packet_hr_cost_replace_formula = bednet.packet_hr_formula;
  688. bednet.packet_hr_cost_replace_formula = ReplaceWith(bednet.packet_hr_cost_replace_formula, "@@", "");
  689. foreach (var replacement in replacements)
  690. {
  691. bednet.packet_hr_cost_replace_formula = ReplaceWith(bednet.packet_hr_cost_replace_formula, replacement.Key, Convert.ToString(replacement.Value));
  692. }
  693. try
  694. {
  695. var res = LJExprParser.Parse(bednet.packet_hr_cost_replace_formula);
  696. bednet.packet_hr_cost += res.Result.DecimalValue;
  697. }
  698. catch (Exception ex)
  699. {
  700. throw new LJCommonException("包装材料成本公式错误!");
  701. }
  702. }
  703. #endregion 计算 包装人工成本 结束
  704. //有外销的 工厂利润率 增加 0.06
  705. if (bednet.ifsaleout == 1)
  706. {
  707. bednet.sale_point = 0.06M;
  708. }
  709. }
  710. // 计算总材料成本 total_mtrl_cost
  711. bednet.total_mtrl_cost = new decimal[]
  712. {
  713. bednet.spring_mtrl_cost.Value,
  714. bednet.snake_wire_mtrl_cost.Value,
  715. bednet.pocket_around_spring_cost.Value,
  716. bednet.pocket_around_fabrics_cost.Value,
  717. bednet.hard_around_mtrl_cost.Value,
  718. bednet.glue_mtrl_cost.Value,
  719. bednet.fabrics1_mtrl_cost.Value,
  720. bednet.fabrics2_mtrl_cost.Value,
  721. bednet.side_iron_mtrl_cost.Value,
  722. bednet.cnail_mtrl_cost.Value,
  723. bednet.sponge_mtrl_cost.Value,
  724. bednet.sponge_mtrl_tc_cost.Value,
  725. bednet.edge_mtrl_cost.Value,
  726. bednet.fork_mtrl_cost.Value,
  727. bednet.rsorwa_mtrl_cost.Value,
  728. bednet.felt_mtrl_cost.Value,
  729. bednet.felt_mtrl_x_cost.Value,
  730. bednet.packet_mtrl_cost.Value
  731. }.Sum();
  732. // 计算总人力成本 total_mtrl_cost
  733. bednet.total_hr_cost = new decimal[]
  734. {
  735. bednet.spring_hr_cost.Value,
  736. bednet.hard_around_hr_cost.Value,
  737. bednet.side_iron_hr_cost.Value,
  738. bednet.cnail_hr_cost.Value,
  739. bednet.sponge_hr_cost.Value,
  740. bednet.edge_hr_cost.Value,
  741. bednet.fork_hr_cost.Value,
  742. bednet.rsorwa_hr_cost.Value,
  743. bednet.felt_hr_cost.Value,
  744. bednet.felt_hr_x_cost.Value,
  745. bednet.packet_hr_cost.Value,
  746. bednet.sponge_drilling_hr_cost.Value
  747. }.Sum();
  748. //1.总成本=总材料成本+总人力成本+ 额外费用
  749. bednet.total_cost = bednet.total_mtrl_cost + bednet.total_hr_cost + bednet.total_fees_cost;
  750. //2-不含税出厂价=总成本* ( 工厂利润率 + 外销加点 )
  751. bednet.nottax_factory_cost = bednet.total_cost * (bednet.profitrate + bednet.sale_point);
  752. // 3 - 部门不含税价 = 不含税出厂价 / 部门利润率 * 佣金点数 * 额外点数 + fob
  753. try
  754. {
  755. bednet.nottax_dept_cost = bednet.nottax_factory_cost / bednet.dept_profitrate / (1 - (bednet.commission - 1)) * bednet.other_rate + bednet.fob;
  756. }
  757. catch (DivideByZeroException)
  758. {
  759. // 捕获除以零的异常并处理
  760. bednet.nottax_dept_cost = 0; // 或者设置为其他默认值
  761. }
  762. // 4 - 税金 = (部门不含税价 * 税率 - 1)
  763. bednet.taxes = bednet.nottax_dept_cost * (bednet.taxrate - 1);
  764. // 5 - 部门含税价 = 部门不含税价 * 税率
  765. bednet.dept_cost = bednet.nottax_dept_cost * bednet.taxrate;
  766. // 6 - 外币价 = 部门含税价 / 汇率
  767. if (bednet.moneyrate != 0)
  768. {
  769. bednet.foreign_cost = bednet.dept_cost / bednet.moneyrate;
  770. }
  771. }
  772. private void CulcalateWeight(u_bednet bednet, List<u_bednetmx> mxlist, List<u_bednetmx_spring> springList)
  773. {
  774. foreach (var mx in mxlist)
  775. {
  776. #region 计算 钢丝重量 开始
  777. if (!string.IsNullOrEmpty(bednet.spring_weight_formula))
  778. {
  779. bednet.spring_weight_formula = ConvertToEnglishSymbols(bednet.spring_weight_formula);
  780. mx.spring_weight_replace_formula = bednet.spring_weight_formula;
  781. if (mx.if_part == 0)
  782. {
  783. //单分区
  784. foreach (var replacement in replacements)
  785. {
  786. mx.spring_weight_replace_formula = ReplaceWith(mx.spring_weight_replace_formula, replacement.Key, Convert.ToString(replacement.Value));
  787. }
  788. try
  789. {
  790. var res = LJExprParser.Parse(mx.spring_weight_replace_formula);
  791. bednet.spring_weight_qty += res.Result.DecimalValue;
  792. }
  793. catch (Exception ex)
  794. {
  795. throw new LJCommonException("钢丝重量公式错误!");
  796. }
  797. }
  798. else
  799. {
  800. //多分区
  801. foreach (var springItem in springList)
  802. {
  803. springItem.spring_weight_replace_formula = bednet.spring_weight_formula;
  804. CalSpringMtrlCol(bednet, mx, springItem);
  805. foreach (var replacement in replacements)
  806. {
  807. springItem.spring_weight_replace_formula = ReplaceWith(springItem.spring_weight_replace_formula, replacement.Key, Convert.ToString(replacement.Value));
  808. }
  809. try
  810. {
  811. var res = LJExprParser.Parse(springItem.spring_mtrl_cost_replace_formula);
  812. bednet.spring_weight_qty += res.Result.DecimalValue;
  813. }
  814. catch (Exception ex)
  815. {
  816. throw new LJCommonException("钢丝重量公式错误!");
  817. }
  818. }
  819. }
  820. }
  821. #endregion 计算 钢丝重量 结束
  822. #region 计算 边铁重量 开始
  823. if (!string.IsNullOrEmpty(bednet.side_iron_weight_formula) && bednet.if_side_iron == 1 && mx.if_side_iron > 0)
  824. {
  825. bednet.side_iron_weight_formula = ConvertToEnglishSymbols(bednet.side_iron_weight_formula);
  826. bednet.side_iron_weight_replace_formula = bednet.side_iron_weight_formula;
  827. foreach (var replacement in replacements)
  828. {
  829. bednet.side_iron_weight_replace_formula = ReplaceWith(bednet.side_iron_weight_replace_formula, replacement.Key, Convert.ToString(replacement.Value));
  830. }
  831. try
  832. {
  833. var res = LJExprParser.Parse(bednet.side_iron_weight_replace_formula);
  834. bednet.side_iron_weight_qty += res.Result.DecimalValue;
  835. }
  836. catch (Exception ex)
  837. {
  838. throw new LJCommonException("边铁重量公式错误!");
  839. }
  840. }
  841. #endregion 计算 边铁重量 结束
  842. #region 计算 四周加硬重量 开始
  843. if (!string.IsNullOrEmpty(bednet.hard_around_weight_formula) && mx.if_hard_around > 0)
  844. {
  845. bednet.hard_around_weight_formula = ConvertToEnglishSymbols(bednet.hard_around_weight_formula);
  846. bednet.hard_around_weight_replace_formula = bednet.hard_around_weight_formula;
  847. foreach (var replacement in replacements)
  848. {
  849. bednet.hard_around_weight_replace_formula = ReplaceWith(bednet.hard_around_weight_replace_formula, replacement.Key, Convert.ToString(replacement.Value));
  850. }
  851. try
  852. {
  853. var res = LJExprParser.Parse(bednet.hard_around_weight_replace_formula);
  854. bednet.hard_around_weight_qty += res.Result.DecimalValue;
  855. }
  856. catch (Exception ex)
  857. {
  858. throw new LJCommonException("四周加硬重量公式错误!");
  859. }
  860. }
  861. #endregion 计算 四周加硬重量 结束
  862. #region 计算 入袋无纺布重量 开始
  863. if (!string.IsNullOrEmpty(bednet.fabrics1_weight_formula) && bednet.typename.IndexOf("袋装网") > -1 && mx.fabrics1_mtrlid > 0)
  864. {
  865. bednet.fabrics1_weight_formula = ConvertToEnglishSymbols(bednet.fabrics1_weight_formula);
  866. bednet.fabrics1_weight_replace_formula = bednet.fabrics1_weight_formula;
  867. foreach (var replacement in replacements)
  868. {
  869. bednet.fabrics1_weight_replace_formula = ReplaceWith(bednet.fabrics1_weight_replace_formula, replacement.Key, Convert.ToString(replacement.Value));
  870. }
  871. try
  872. {
  873. var res = LJExprParser.Parse(bednet.fabrics1_weight_replace_formula);
  874. bednet.fabrics1_weight_qty += res.Result.DecimalValue;
  875. }
  876. catch (Exception ex)
  877. {
  878. throw new LJCommonException("入袋无纺布重量公式错误!");
  879. }
  880. }
  881. #endregion 计算 入袋无纺布重量 结束
  882. #region 计算 面底无纺布重量 开始
  883. if (!string.IsNullOrEmpty(bednet.fabrics2_weight_formula) && bednet.typename.IndexOf("袋装网") > -1 && mx.fabrics2_mtrlid > 0)
  884. {
  885. bednet.fabrics2_weight_formula = ConvertToEnglishSymbols(bednet.fabrics2_weight_formula);
  886. bednet.fabrics2_weight_replace_formula = bednet.fabrics2_weight_formula;
  887. foreach (var replacement in replacements)
  888. {
  889. bednet.fabrics2_weight_replace_formula = ReplaceWith(bednet.fabrics2_weight_replace_formula, replacement.Key, Convert.ToString(replacement.Value));
  890. }
  891. try
  892. {
  893. var res = LJExprParser.Parse(bednet.fabrics2_weight_replace_formula);
  894. bednet.fabrics2_weight_qty += res.Result.DecimalValue;
  895. }
  896. catch (Exception ex)
  897. {
  898. throw new LJCommonException("面底无纺布重量公式错误!");
  899. }
  900. }
  901. #endregion 计算 面底无纺布重量 结束
  902. #region 计算 上垫层重量 开始
  903. string felt_weight_formula_replace_formula = "";
  904. if (!string.IsNullOrEmpty(bednet.felt_mtrl_formula) && bednet.felt_qty > 0)
  905. {
  906. bednet.felt_weight_formula = ConvertToEnglishSymbols(bednet.felt_weight_formula);
  907. felt_weight_formula_replace_formula = bednet.felt_weight_formula;
  908. CalSpringMtrlCol2(bednet, mx, "上垫层");
  909. foreach (var replacement in replacements)
  910. {
  911. felt_weight_formula_replace_formula = ReplaceWith(felt_weight_formula_replace_formula, replacement.Key, Convert.ToString(replacement.Value));
  912. }
  913. try
  914. {
  915. var res = LJExprParser.Parse(felt_weight_formula_replace_formula);
  916. bednet.felt_weight_qty += res.Result.DecimalValue;
  917. }
  918. catch (Exception ex)
  919. {
  920. throw new LJCommonException("上垫层重量公式错误!");
  921. }
  922. }
  923. #endregion 计算 上垫层重量 结束
  924. #region 计算 下垫层重量 开始
  925. string felt_x_weight_formula_replace_formula = "";
  926. if (!string.IsNullOrEmpty(bednet.felt_weight_formula) && bednet.felt_x_qty > 0)
  927. {
  928. bednet.felt_weight_formula = ConvertToEnglishSymbols(bednet.felt_weight_formula);
  929. felt_x_weight_formula_replace_formula = bednet.felt_weight_formula;
  930. CalSpringMtrlCol2(bednet, mx, "下垫层");
  931. foreach (var replacement in replacements)
  932. {
  933. felt_x_weight_formula_replace_formula = ReplaceWith(felt_x_weight_formula_replace_formula, replacement.Key, Convert.ToString(replacement.Value));
  934. }
  935. try
  936. {
  937. var res = LJExprParser.Parse(felt_x_weight_formula_replace_formula);
  938. bednet.felt_weight_qty += res.Result.DecimalValue;
  939. }
  940. catch (Exception ex)
  941. {
  942. throw new LJCommonException("下垫层重量公式错误!");
  943. }
  944. }
  945. bednet.felt_weight_replace_formula += felt_weight_formula_replace_formula;
  946. bednet.felt_weight_replace_formula += Environment.NewLine;
  947. bednet.felt_weight_replace_formula += felt_x_weight_formula_replace_formula;
  948. #endregion 计算 下垫层重量 结束
  949. #region 计算 C钉/夹码重量 开始
  950. if (!string.IsNullOrEmpty(bednet.cnail_weight_formula))
  951. {
  952. bednet.cnail_weight_formula = ConvertToEnglishSymbols(bednet.cnail_weight_formula);
  953. bednet.cnail_weight_replace_formula = bednet.cnail_weight_formula;
  954. foreach (var replacement in replacements)
  955. {
  956. bednet.cnail_weight_replace_formula = ReplaceWith(bednet.cnail_weight_replace_formula, replacement.Key, Convert.ToString(replacement.Value));
  957. }
  958. try
  959. {
  960. var res = LJExprParser.Parse(bednet.cnail_weight_replace_formula);
  961. bednet.cnail_weight_qty += res.Result.DecimalValue;
  962. }
  963. catch (Exception ex)
  964. {
  965. throw new LJCommonException("C钉/夹码重量公式错误!");
  966. }
  967. }
  968. #endregion 计算 C钉/夹码重量 结束
  969. #region 计算 海绵包边重量 开始
  970. if (!string.IsNullOrEmpty(bednet.sponge_weight_formula) && bednet.sponge_mtrlid > 0)
  971. {
  972. bednet.sponge_weight_formula = ConvertToEnglishSymbols(bednet.sponge_weight_formula);
  973. bednet.sponge_weight_replace_formula = bednet.sponge_weight_formula;
  974. foreach (var replacement in replacements)
  975. {
  976. bednet.sponge_weight_replace_formula = ReplaceWith(bednet.sponge_weight_replace_formula, replacement.Key, Convert.ToString(replacement.Value));
  977. }
  978. try
  979. {
  980. var res = LJExprParser.Parse(bednet.sponge_weight_replace_formula);
  981. bednet.sponge_weight_qty += res.Result.DecimalValue;
  982. }
  983. catch (Exception ex)
  984. {
  985. throw new LJCommonException("海绵包边重量公式错误!");
  986. }
  987. }
  988. #endregion 计算 海绵包边重量 结束
  989. #region 计算 填充海绵重量 开始
  990. if (!string.IsNullOrEmpty(bednet.sponge_weight_tc_formula) && bednet.sponge_tc_mtrlid > 0)
  991. {
  992. bednet.sponge_weight_tc_formula = ConvertToEnglishSymbols(bednet.sponge_weight_tc_formula);
  993. bednet.sponge_weight_tc_replace_formula = bednet.sponge_weight_tc_formula;
  994. CalSpringMtrlCol2(bednet, mx, "填充海绵");
  995. foreach (var replacement in replacements)
  996. {
  997. bednet.sponge_weight_tc_replace_formula = ReplaceWith(bednet.sponge_weight_tc_replace_formula, replacement.Key, Convert.ToString(replacement.Value));
  998. }
  999. try
  1000. {
  1001. var res = LJExprParser.Parse(bednet.sponge_weight_tc_replace_formula);
  1002. bednet.sponge_weight_tc_qty += res.Result.DecimalValue;
  1003. }
  1004. catch (Exception ex)
  1005. {
  1006. throw new LJCommonException("填充海绵重量公式错误!");
  1007. }
  1008. }
  1009. #endregion 计算 填充海绵重量 结束
  1010. #region 计算 封边材料重量 开始
  1011. if (!string.IsNullOrEmpty(bednet.edge_weight_formula) && bednet.edge_mtrlid > 0)
  1012. {
  1013. bednet.edge_weight_formula = ConvertToEnglishSymbols(bednet.edge_weight_formula);
  1014. bednet.edge_weight_replace_formula = bednet.edge_weight_formula;
  1015. CalSpringMtrlCol2(bednet, mx, "封边");
  1016. foreach (var replacement in replacements)
  1017. {
  1018. bednet.edge_weight_replace_formula = ReplaceWith(bednet.edge_weight_replace_formula, replacement.Key, Convert.ToString(replacement.Value));
  1019. }
  1020. try
  1021. {
  1022. var res = LJExprParser.Parse(bednet.edge_weight_replace_formula);
  1023. bednet.edge_weight_qty += res.Result.DecimalValue;
  1024. }
  1025. catch (Exception ex)
  1026. {
  1027. throw new LJCommonException("封边材料重量公式错误!");
  1028. }
  1029. }
  1030. #endregion 计算 封边材料重量 结束
  1031. #region 计算 弹叉材料重量 开始
  1032. if (!string.IsNullOrEmpty(bednet.fork_weight_formula) && bednet.fork_qty > 0)
  1033. {
  1034. bednet.fork_weight_formula = ConvertToEnglishSymbols(bednet.fork_weight_formula);
  1035. bednet.fork_weight_replace_formula = bednet.fork_weight_formula;
  1036. foreach (var replacement in replacements)
  1037. {
  1038. bednet.fork_weight_replace_formula = ReplaceWith(bednet.fork_weight_replace_formula, replacement.Key, Convert.ToString(replacement.Value));
  1039. }
  1040. try
  1041. {
  1042. var res = LJExprParser.Parse(bednet.fork_weight_replace_formula);
  1043. bednet.fork_weight_qty += res.Result.DecimalValue;
  1044. }
  1045. catch (Exception ex)
  1046. {
  1047. throw new LJCommonException("弹叉材料重量公式错误!");
  1048. }
  1049. }
  1050. #endregion 计算 弹叉材料重量 结束
  1051. }
  1052. // 计算总材料成本 total_mtrl_cost
  1053. bednet.sum_weight = new decimal[]
  1054. {
  1055. bednet.spring_weight_qty.Value,
  1056. bednet.side_iron_weight_qty.Value,
  1057. bednet.hard_around_weight_qty.Value,
  1058. bednet.fabrics1_weight_qty.Value,
  1059. bednet.fabrics2_weight_qty.Value,
  1060. bednet.felt_weight_qty.Value,
  1061. bednet.cnail_weight_qty.Value,
  1062. bednet.sponge_weight_qty.Value,
  1063. bednet.sponge_weight_tc_qty.Value,
  1064. bednet.edge_weight_qty.Value,
  1065. bednet.fork_weight_qty.Value
  1066. }.Sum();
  1067. }
  1068. private void InitBedNet(u_bednet bednet)
  1069. {
  1070. var dept = new u_dept() { deptid = bednet.deptid.Value };
  1071. DbSqlHelper.SelectOne(cmd, dept, "pricelistid");
  1072. var bednetType = new u_bednet_type() { bednettypeid = bednet.bednettypeid };
  1073. DbSqlHelper.SelectOne(cmd, bednetType, "typename");
  1074. bednet.pricelistid = dept.pricelistid;
  1075. bednet.typename = bednetType.typename;
  1076. }
  1077. private void InitReplaceMents(u_bednet bednet)
  1078. {
  1079. replacements.Clear();
  1080. var bednetVarList = new List<u_bednet_var>();
  1081. var selectStr = @"SELECT u_bednet_varmx.varid AS varid
  1082. ,varkind
  1083. ,varcode
  1084. ,varname
  1085. ,varclass
  1086. ,vartype
  1087. ,varunit
  1088. ,u_bednet_varmx.varvalue AS varvalue
  1089. FROM u_bednet_var
  1090. INNER JOIN u_bednet_varmx ON u_bednet_varmx.varid = u_bednet_var.varid";
  1091. var whereList = new List<string>();
  1092. whereList.Add("varkind = @varkind");
  1093. whereList.Add("u_bednet_varmx.pricelistid = @pricelistid");
  1094. whereList.Add(@"(u_bednet_var.varclass = 1
  1095. AND (
  1096. u_bednet_varmx.bednettypeid = @bednettypeid
  1097. OR @bednettypeid = 0
  1098. )
  1099. )
  1100. OR (u_bednet_var.varclass = 0)");
  1101. var param = new Dictionary<string, object>();
  1102. param.Add("@varkind", 0);
  1103. param.Add("@pricelistid", bednet.pricelistid);
  1104. param.Add("@bednettypeid", bednet.bednettypeid);
  1105. DbSqlHelper.SelectJoin(cmd, selectStr, ListEx.GetWhereStr(whereList), param, "varid", "varid,varkind,varcode,varname,varclass,vartype,varunit,varvalue", 0, 0, bednetVarList);
  1106. AddKeyValue("床垫宽", bednet.mattress_width);
  1107. AddKeyValue("床垫长", bednet.mattress_length);
  1108. AddKeyValue("床垫高", bednet.mattress_height);
  1109. AddKeyValue("双簧", bednet.if_doublespring);
  1110. AddKeyValue("弹叉数量", bednet.fork_qty);
  1111. AddKeyValue("包装方式", bednet.packtype);
  1112. AddKeyValue("包装数量", bednet.packqty);
  1113. AddKeyValue("运输方式", bednet.transport_type);
  1114. AddKeyValue("包装材料", bednet.packmtrl);
  1115. AddKeyValue("床网类别", bednet.typename);
  1116. foreach (var netvar in bednetVarList)
  1117. {
  1118. AddKeyValue(netvar.varname, netvar.varvalue);
  1119. }
  1120. }
  1121. private void InitMxReplaceMents(u_bednet bednet,u_bednetmx mx, u_spring spring)
  1122. {
  1123. AddKeyValue("弹簧排列个数-宽", mx.spring_qty_width);
  1124. AddKeyValue("弹簧排列个数-长", mx.spring_qty_length);
  1125. AddKeyValue("弹簧计算个数(宽)", mx.spring_qty_width);
  1126. AddKeyValue("弹簧计算个数(长)", mx.spring_qty_length);
  1127. AddKeyValue("边铁条数", mx.side_iron_qty);
  1128. AddKeyValue("条数", mx.side_iron_qty);
  1129. AddKeyValue("四周口袋-排数", mx.pocket_around_row);
  1130. AddKeyValue("四周口袋", mx.if_pocket_around);
  1131. AddKeyValue("四周加硬-排数", mx.hard_around_row);
  1132. AddKeyValue("四周加硬", mx.if_hard_around);
  1133. spring.gram_weight /= 1000;
  1134. if (spring.gram_weight > 0)
  1135. {
  1136. AddKeyValue("弹簧重/个", spring.gram_weight);
  1137. AddKeyValue("弹簧重", spring.gram_weight);
  1138. AddKeyValue("弹簧克重", spring.gram_weight * 1000);
  1139. }
  1140. if (mx.bednet_height > 0)
  1141. {
  1142. AddKeyValue("床网高", mx.bednet_height);
  1143. }
  1144. if (spring.height > 0)
  1145. {
  1146. AddKeyValue("口袋弹簧高度", spring.height);
  1147. }
  1148. if (spring.center_diameter > 0)
  1149. {
  1150. AddKeyValue("口袋弹簧心径", spring.center_diameter);
  1151. }
  1152. cmd.CommandText = @"SELECT TOP 1 isnull(u_mtrl_price_pricelist.price, 0) AS price
  1153. FROM u_mtrl_price_pricelist
  1154. INNER JOIN u_mtrl_price ON u_mtrl_price.mtrlid = u_mtrl_price_pricelist.mtrlid
  1155. WHERE cast(u_mtrl_price.name AS DECIMAL(18, 5)) = @line_diameter
  1156. AND u_mtrl_price.mtrltype = 0
  1157. AND u_mtrl_price_pricelist.pricelistid = @pricelistid";
  1158. cmd.Parameters.Clear();
  1159. cmd.Parameters.AddWithValue("@line_diameter", spring.line_diameter);
  1160. cmd.Parameters.AddWithValue("@pricelistid", bednet.pricelistid);
  1161. decimal price = 0;
  1162. using (var reader = cmd.ExecuteReader())
  1163. {
  1164. if (reader.Read())
  1165. {
  1166. price = Convert.ToDecimal(reader["price"]);
  1167. price /= 1000;
  1168. }
  1169. }
  1170. if (price > 0)
  1171. {
  1172. AddKeyValue("加硬弹簧单价", price);
  1173. AddKeyValue("口袋弹簧单价", price);
  1174. AddKeyValue("弹簧单价", price);
  1175. }
  1176. }
  1177. /// <summary>
  1178. /// 用于床网报价 弹簧材料总成本 弹簧人工总成本
  1179. /// </summary>
  1180. /// <param name="cmd"></param>
  1181. /// <param name="dept"></param>
  1182. /// <param name="mx"></param>
  1183. /// <param name="mx2"></param>
  1184. private void CalSpringMtrlCol(u_bednet bednet, u_bednetmx mx, u_bednetmx_spring mx2)
  1185. {
  1186. AddKeyValue("弹簧排列个数-宽", mx.spring_qty_width);
  1187. AddKeyValue("弹簧排列个数-长", mx.spring_qty_length);
  1188. AddKeyValue("弹簧计算个数(宽)", mx.spring_qty_width);
  1189. AddKeyValue("弹簧计算个数(长)", mx.spring_qty_length);
  1190. AddKeyValue("边铁条数", mx.side_iron_qty);
  1191. AddKeyValue("条数", mx.side_iron_qty);
  1192. var spring = new u_spring() { springid = mx.springid };
  1193. DbSqlHelper.SelectOne(cmd, spring, "line_diameter,gram_weight");
  1194. spring.gram_weight /= 1000;
  1195. if (spring.gram_weight > 0)
  1196. {
  1197. AddKeyValue("弹簧重/个", spring.gram_weight);
  1198. AddKeyValue("弹簧重", spring.gram_weight);
  1199. }
  1200. cmd.CommandText = @"SELECT TOP 1 isnull(u_mtrl_price_pricelist.price, 0) AS price
  1201. FROM u_mtrl_price_pricelist
  1202. INNER JOIN u_mtrl_price ON u_mtrl_price.mtrlid = u_mtrl_price_pricelist.mtrlid
  1203. WHERE cast(u_mtrl_price.name AS DECIMAL(18, 5)) = @line_diameter
  1204. AND u_mtrl_price.mtrltype = 0
  1205. AND u_mtrl_price_pricelist.pricelistid = @pricelistid";
  1206. cmd.Parameters.Clear();
  1207. cmd.Parameters.AddWithValue("@line_diameter", spring.line_diameter);
  1208. cmd.Parameters.AddWithValue("@pricelistid", bednet.pricelistid);
  1209. decimal price = 0;
  1210. using (var reader = cmd.ExecuteReader())
  1211. {
  1212. if (reader.Read())
  1213. {
  1214. price = Convert.ToDecimal(reader["price"]);
  1215. price /= 1000;
  1216. }
  1217. }
  1218. if (price > 0)
  1219. {
  1220. AddKeyValue("弹簧单价", price);
  1221. }
  1222. }
  1223. /// <summary>
  1224. /// 代码对照wf_replace_var_dw2
  1225. /// </summary>
  1226. /// <param name="cmd"></param>
  1227. /// <param name="mx"></param>
  1228. private void CalSpringMtrlCol2(u_bednet bednet, u_bednetmx mx, string type)
  1229. {
  1230. var spring = new u_spring() { springid = mx.springid };
  1231. DbSqlHelper.SelectOne(cmd, spring, "line_diameter,gram_weight,center_diameter");
  1232. #region 计算 底面无纺布 开始
  1233. //计算 上下无纺布方数 =(B4+C4)*(B4+D4)/10000
  1234. if ("底面无纺布".Equals(type) && mx.fabrics2_mtrlid > 0)
  1235. {
  1236. decimal fabrics = (mx.bednet_height.Value + bednet.mattress_width.Value) * (mx.bednet_height.Value + bednet.mattress_length.Value) / 10000;
  1237. AddKeyValue("上下无纺布方数", fabrics);
  1238. decimal fabrics_price = getMtrlPrice(2, bednet.pricelistid.Value, mx.fabrics2_mtrlid.Value);
  1239. if (fabrics_price > 0) AddKeyValue("无纺布单价", fabrics_price);
  1240. }
  1241. #endregion 计算 底面无纺布 结束
  1242. #region 计算 入袋无纺布 开始
  1243. //计算 入袋无纺布方数 = (B4+I4+2)*((I4*3.14)+1)/10000
  1244. if ("入袋无纺布".Equals(type) && mx.fabrics1_mtrlid > 0)
  1245. {
  1246. decimal fabrics = (mx.bednet_height.Value + spring.center_diameter.Value + 2) * (spring.center_diameter.Value * (decimal)3.14 + 1) / 10000;
  1247. AddKeyValue("入袋无纺布方数", fabrics);
  1248. decimal fabrics_price = getMtrlPrice(2, bednet.pricelistid.Value, mx.fabrics1_mtrlid.Value);
  1249. if (fabrics_price > 0) AddKeyValue("无纺布单价", fabrics_price);
  1250. }
  1251. #endregion 计算 入袋无纺布 结束
  1252. #region 计算 四周加硬弹簧 开始
  1253. // 主要是要替换 【弹簧克重】 【弹簧单价】
  1254. // 因相同部分已存在,不需要后续
  1255. #endregion 计算 四周加硬弹簧 结束
  1256. #region 计算 海绵包边 开始
  1257. if ("海绵包边".Equals(type) && bednet.sponge_thickness.Value > 0 && bednet.sponge_mtrlid.Value > 0)
  1258. {
  1259. var mtrl_price = new u_mtrl_price() { mtrlid = bednet.sponge_mtrlid };
  1260. DbSqlHelper.SelectOne(cmd, mtrl_price, "name");
  1261. AddKeyValue("物料名称", mtrl_price.name);
  1262. AddKeyValue("裥棉厚度", bednet.sponge_thickness.Value);
  1263. AddKeyValue("海绵厚度", bednet.sponge_thickness.Value);
  1264. if (bednet.sponge_height.Value > 0)
  1265. {
  1266. AddKeyValue("海绵高", bednet.sponge_height.Value);
  1267. }
  1268. cmd.CommandText = @"SELECT isnull(u_mtrl_price_pricelist.price, 0) AS price
  1269. FROM u_mtrl_price_pricelist
  1270. WHERE u_mtrl_price_pricelist.mtrlid = @mtrlid
  1271. AND u_mtrl_price_pricelist.pricelistid = @pricelistid";
  1272. cmd.Parameters.Clear();
  1273. cmd.Parameters.AddWithValue("@mtrlid", bednet.sponge_mtrlid);
  1274. cmd.Parameters.AddWithValue("@pricelistid", bednet.pricelistid);
  1275. using (var reader = cmd.ExecuteReader())
  1276. {
  1277. if (reader.Read())
  1278. {
  1279. decimal sponge_price = Convert.ToDecimal(reader["price"]);
  1280. AddKeyValue("裥棉单价", sponge_price);
  1281. AddKeyValue("海绵单价", sponge_price);
  1282. }
  1283. }
  1284. }
  1285. #endregion 计算 海绵包边 结束
  1286. #region 计算 填充海绵 开始
  1287. if ("填充海绵".Equals(type) && bednet.sponge_tc_thickness.Value > 0 && bednet.sponge_tc_mtrlid.Value > 0)
  1288. {
  1289. var mtrl_price = new u_mtrl_price() { mtrlid = bednet.sponge_tc_mtrlid };
  1290. DbSqlHelper.SelectOne(cmd, mtrl_price, "name");
  1291. AddKeyValue("物料名称", mtrl_price.name);
  1292. AddKeyValue("裥棉厚度", bednet.sponge_tc_thickness.Value);
  1293. AddKeyValue("海绵厚度", bednet.sponge_tc_thickness.Value);
  1294. if (bednet.sponge_tc_height.Value > 0)
  1295. {
  1296. AddKeyValue("海绵高", bednet.sponge_tc_height.Value);
  1297. }
  1298. cmd.CommandText = @"SELECT isnull(u_mtrl_price_pricelist.price, 0) AS price
  1299. FROM u_mtrl_price_pricelist
  1300. WHERE u_mtrl_price_pricelist.mtrlid = @mtrlid
  1301. AND u_mtrl_price_pricelist.pricelistid = @pricelistid";
  1302. cmd.Parameters.Clear();
  1303. cmd.Parameters.AddWithValue("@mtrlid", bednet.sponge_tc_mtrlid);
  1304. cmd.Parameters.AddWithValue("@pricelistid", bednet.pricelistid);
  1305. using (var reader = cmd.ExecuteReader())
  1306. {
  1307. if (reader.Read())
  1308. {
  1309. decimal sponge_price = Convert.ToDecimal(reader["price"]);
  1310. AddKeyValue("裥棉单价", sponge_price);
  1311. AddKeyValue("海绵单价", sponge_price);
  1312. }
  1313. }
  1314. }
  1315. #endregion 计算 填充海绵 结束
  1316. #region 计算 封边 开始
  1317. if ("封边".Equals(type) && bednet.edge_mtrlid > 0)
  1318. {
  1319. AddKeyValue("有边铁", mx.if_side_iron);
  1320. cmd.CommandText = @"SELECT isnull(u_mtrl_price_pricelist.price, 0) AS price
  1321. ,u_mtrl_price.gram_weight
  1322. FROM u_mtrl_price_pricelist
  1323. INNER JOIN u_mtrl_price ON u_mtrl_price.mtrlid = u_mtrl_price_pricelist.mtrlid
  1324. WHERE u_mtrl_price_pricelist.mtrlid = @mtrlid
  1325. AND u_mtrl_price_pricelist.pricelistid = @pricelistid";
  1326. cmd.Parameters.Clear();
  1327. cmd.Parameters.AddWithValue("@mtrlid", bednet.edge_mtrlid);
  1328. cmd.Parameters.AddWithValue("@pricelistid", bednet.pricelistid);
  1329. using (var reader = cmd.ExecuteReader())
  1330. {
  1331. if (reader.Read())
  1332. {
  1333. decimal edge_price = Convert.ToDecimal(reader["price"]);
  1334. decimal edge_weight = Convert.ToDecimal(reader["gram_weight"]);
  1335. if (edge_price > 0) AddKeyValue("毡单价", edge_price);
  1336. if (edge_weight > 0) AddKeyValue("毡克重", edge_weight);
  1337. }
  1338. }
  1339. if (bednet.edge_height > 0) AddKeyValue("封边高", bednet.edge_height);
  1340. }
  1341. #endregion 计算 封边 结束
  1342. #region 计算 上垫层 开始
  1343. if ("上垫层".Equals(type) && bednet.felt_mtrlid > 0)
  1344. {
  1345. cmd.CommandText = @"SELECT isnull(u_mtrl_price_pricelist.price, 0) AS price
  1346. ,u_mtrl_price.gram_weight
  1347. FROM u_mtrl_price_pricelist
  1348. INNER JOIN u_mtrl_price ON u_mtrl_price.mtrlid = u_mtrl_price_pricelist.mtrlid
  1349. WHERE u_mtrl_price_pricelist.mtrlid = @mtrlid
  1350. AND u_mtrl_price_pricelist.pricelistid = @pricelistid";
  1351. cmd.Parameters.Clear();
  1352. cmd.Parameters.AddWithValue("@mtrlid", bednet.felt_mtrlid);
  1353. cmd.Parameters.AddWithValue("@pricelistid", bednet.pricelistid);
  1354. using (var reader = cmd.ExecuteReader())
  1355. {
  1356. if (reader.Read())
  1357. {
  1358. decimal felt_price = Convert.ToDecimal(reader["price"]);
  1359. decimal felt_weight = Convert.ToDecimal(reader["gram_weight"]);
  1360. if (felt_price > 0) AddKeyValue("垫层物料单价", felt_price);
  1361. if (felt_weight > 0) AddKeyValue("垫层物料克重", felt_weight);
  1362. }
  1363. }
  1364. if (bednet.felt_qty > 0) AddKeyValue("垫层物料数量", bednet.felt_qty);
  1365. }
  1366. #endregion 计算 上垫层 结束
  1367. #region 计算 下垫层 开始
  1368. if ("下垫层".Equals(type) && bednet.felt_x_mtrlid > 0)
  1369. {
  1370. cmd.CommandText = @"SELECT isnull(u_mtrl_price_pricelist.price, 0) AS price
  1371. ,u_mtrl_price.gram_weight
  1372. FROM u_mtrl_price_pricelist
  1373. INNER JOIN u_mtrl_price ON u_mtrl_price.mtrlid = u_mtrl_price_pricelist.mtrlid
  1374. WHERE u_mtrl_price_pricelist.mtrlid = @mtrlid
  1375. AND u_mtrl_price_pricelist.pricelistid = @pricelistid";
  1376. cmd.Parameters.Clear();
  1377. cmd.Parameters.AddWithValue("@mtrlid", bednet.felt_x_mtrlid);
  1378. cmd.Parameters.AddWithValue("@pricelistid", bednet.pricelistid);
  1379. using (var reader = cmd.ExecuteReader())
  1380. {
  1381. if (reader.Read())
  1382. {
  1383. decimal felt_price = Convert.ToDecimal(reader["price"]);
  1384. decimal felt_weight = Convert.ToDecimal(reader["gram_weight"]);
  1385. if (felt_price > 0) AddKeyValue("垫层物料单价", felt_price);
  1386. if (felt_weight > 0) AddKeyValue("垫层物料克重", felt_weight);
  1387. }
  1388. }
  1389. if (bednet.felt_x_qty > 0) AddKeyValue("垫层物料数量", bednet.felt_x_qty);
  1390. }
  1391. #endregion 计算 下垫层 结束
  1392. }
  1393. private void CalSnakeCol(u_bednet bednet,u_spring spring)
  1394. {
  1395. #region 替换蛇线单价 snake_wire_diameter
  1396. cmd.CommandText = @"SELECT TOP 1 isnull(u_mtrl_price_pricelist.price, 0) AS price
  1397. FROM u_mtrl_price_pricelist
  1398. INNER JOIN u_mtrl_price ON u_mtrl_price.mtrlid = u_mtrl_price_pricelist.mtrlid
  1399. WHERE cast(u_mtrl_price.name AS DECIMAL(18, 5)) = @line_diameter
  1400. AND u_mtrl_price.mtrltype = 0
  1401. AND u_mtrl_price_pricelist.pricelistid = @pricelistid";
  1402. cmd.Parameters.Clear();
  1403. cmd.Parameters.AddWithValue("@line_diameter", spring.line_diameter);
  1404. cmd.Parameters.AddWithValue("@pricelistid", bednet.pricelistid);
  1405. decimal price = 0;
  1406. using (var reader = cmd.ExecuteReader())
  1407. {
  1408. if (reader.Read())
  1409. {
  1410. price = Convert.ToDecimal(reader["price"]);
  1411. price /= 1000;
  1412. }
  1413. }
  1414. if (price > 0)
  1415. {
  1416. AddKeyValue("蛇线单价", price);
  1417. }
  1418. #endregion
  1419. }
  1420. private decimal getMtrlPrice(int mtrltype, int pricelistid, int mtrlid)
  1421. {
  1422. decimal price = 0;
  1423. cmd.CommandText = @"SELECT TOP 1 isnull(u_mtrl_price_pricelist.price, 0) AS price
  1424. FROM u_mtrl_price_pricelist
  1425. INNER JOIN u_mtrl_price ON u_mtrl_price.mtrlid = u_mtrl_price_pricelist.mtrlid
  1426. WHERE u_mtrl_price.mtrlid = @mtrlid
  1427. AND u_mtrl_price.mtrltype = @mtrltype
  1428. AND u_mtrl_price_pricelist.pricelistid = @pricelistid";
  1429. cmd.Parameters.Clear();
  1430. cmd.Parameters.AddWithValue("@mtrlid", mtrlid);
  1431. cmd.Parameters.AddWithValue("@mtrltype", mtrltype);
  1432. cmd.Parameters.AddWithValue("@pricelistid", pricelistid);
  1433. using (var reader = cmd.ExecuteReader())
  1434. {
  1435. if (reader.Read())
  1436. {
  1437. price = Convert.ToDecimal(reader["price"]);
  1438. price /= 1000;
  1439. }
  1440. }
  1441. return price;
  1442. }
  1443. private string ConvertToEnglishSymbols(string input)
  1444. {
  1445. input = input.Replace("(", "(")
  1446. .Replace(")", ")")
  1447. .Replace(",", ",")
  1448. .Replace("。", ".")
  1449. .Replace(":", ":")
  1450. .Replace(";", ";")
  1451. .Replace("“", "\"")
  1452. .Replace("”", "\"")
  1453. .Replace("‘", "'")
  1454. .Replace("’", "'");
  1455. return input;
  1456. }
  1457. private void AddKeyValue(string key, object value, bool isReplace = true)
  1458. {
  1459. if (!replacements.ContainsKey(key))
  1460. {
  1461. replacements.Add($"【{key}】", value);
  1462. }
  1463. else if (isReplace)
  1464. {
  1465. replacements[$"【{key}】"] = value;
  1466. }
  1467. }
  1468. private string ReplaceWith(string input, string oldValue, string newValue)
  1469. {
  1470. return input.Replace(oldValue, newValue);
  1471. }
  1472. public void GetBedNet(u_bednet bednet)
  1473. {
  1474. DbSqlHelper.SelectOne(cmd, bednet, "*");
  1475. }
  1476. public List<u_bednetmx_spring> GetBedNetSpringList(int bednetid)
  1477. {
  1478. var springList = new List<u_bednetmx_spring>();
  1479. var outputFields = @"bednetmx_partid,bednetmxid,springid,spring_qty_width,spring_qty_length,fabrics1_mtrl_cost,spring_mtrl_cost,spring_hr_cost,spring_mtrl_cost_replace_formula,spring_hr_cost_replace_formula,spring_weight_replace_formula";
  1480. var selectStr = @"SELECT bednetmx_partid
  1481. ,u_bednetmx_spring.bednetmxid AS bednetmxid
  1482. ,u_bednetmx_spring.springid AS springid
  1483. ,u_bednetmx_spring.spring_qty_width AS spring_qty_width
  1484. ,u_bednetmx_spring.spring_qty_length AS spring_qty_length
  1485. ,u_bednetmx_spring.fabrics1_mtrl_cost AS fabrics1_mtrl_cost
  1486. ,u_bednetmx_spring.spring_mtrl_cost AS spring_mtrl_cost
  1487. ,u_bednetmx_spring.spring_hr_cost AS spring_hr_cost
  1488. ,u_bednetmx_spring.spring_mtrl_cost_replace_formula AS spring_mtrl_cost_replace_formula
  1489. ,u_bednetmx_spring.spring_hr_cost_replace_formula AS spring_hr_cost_replace_formula
  1490. ,u_bednetmx_spring.spring_weight_replace_formula AS spring_weight_replace_formula
  1491. FROM u_bednetmx_spring
  1492. INNER JOIN u_bednetmx ON u_bednetmx.bednetmxid = u_bednetmx_spring.bednetmxid";
  1493. DbSqlHelper.SelectJoin(cmd,selectStr, "u_bednetmx.bednetid = @bednetid",new Dictionary<string, object>() { { "@bednetid",bednetid } }, "bednetmx_partid",outputFields,0,0,springList);
  1494. return springList;
  1495. }
  1496. public List<u_bednetmx_mtrl> GetBedNetMxMtrlList(int bednetid)
  1497. {
  1498. var mxList = new List<u_bednetmx_mtrl>();
  1499. var outputFields = @"bednetmtrlid,bednetid,formulakind,formula,mtrlid,price,gram_weight,cloth_width,if_inputqty,qty,costamt,if_success,replace_formula,priceunit,shrinkage";
  1500. var selectStr = @"SELECT u_bednetmx_mtrl.bednetmtrlid AS bednetmtrlid
  1501. ,u_bednetmx_mtrl.bednetid AS bednetid
  1502. ,u_bednetmx_mtrl.formulakind AS formulakind
  1503. ,u_bednetmx_mtrl.formula AS formula
  1504. ,u_bednetmx_mtrl.mtrlid
  1505. ,u_bednetmx_mtrl.price
  1506. ,u_bednetmx_mtrl.gram_weight
  1507. ,u_bednetmx_mtrl.cloth_width
  1508. ,u_bednetmx_mtrl.if_inputqty
  1509. ,u_bednetmx_mtrl.qty
  1510. ,u_bednetmx_mtrl.costamt
  1511. ,u_bednetmx_mtrl.if_success
  1512. ,u_bednetmx_mtrl.replace_formula
  1513. ,u_bednetmx_mtrl.priceunit
  1514. ,u_bednetmx_mtrl.shrinkage
  1515. FROM u_bednetmx_mtrl";
  1516. DbSqlHelper.SelectJoin(cmd, selectStr, "u_bednetmx_mtrl.bednetid = @bednetid", new Dictionary<string, object>() { { "@bednetid", bednetid } }, "bednetmtrlid", outputFields, 0, 0, mxList);
  1517. return mxList;
  1518. }
  1519. public List<u_bednetmx> GetBedNetMxList(int bednetid)
  1520. {
  1521. var mxList = new List<u_bednetmx>();
  1522. var outputFields = @"bednetmxid,bednetid,spring_qty_width,spring_qty_length,bednet_height,wire_mtrlid,springid,if_part,if_15strip,if_pocket_around,
  1523. pocket_around_springid,pocket_around_row,pocket_around_wire_price,pocket_around_spring_cost,pocket_around_fabrics_cost,
  1524. if_hard_around,hard_around_springid,hard_around_row,hard_around_wire_price,hard_around_mtrl_cost,hard_around_hr_cost,
  1525. fabrics1_mtrlid,fabrics1_price,fabrics1_mtrl_cost,fabrics2_mtrlid,fabrics2_price,fabrics2_mtrl_cost,if_side_iron,
  1526. side_iron_qty,side_iron_mtrl_cost,side_iron_hr_cost,pocket_around_spring_cost_replace_formula,pocket_around_fabrics_cost_replace_formula,
  1527. hard_around_mtrl_cost_replace_formula,hard_around_hr_cost_replace_formula,fabrics1_mtrl_cost_replace_formula,
  1528. fabrics2_mtrl_cost_replace_formula,side_iron_mtrl_cost_replace_formula,side_iron_hr_cost_replace_formula,
  1529. cnail_mtrl_cost_replace_formula,cnail_mtrl_cost,cnail_hr_cost_replace_formula,cnail_hr_cost,
  1530. glue_mtrl_cost_replace_formula,glue_mtrl_cost,spring_mtrl_cost,spring_hr_cost,spring_mtrl_cost_replace_formula,
  1531. spring_hr_cost_replace_formula,if_show,spring_weight_replace_formula";
  1532. var selectStr = @"SELECT bednetmxid
  1533. ,bednetid
  1534. ,spring_qty_width
  1535. ,spring_qty_length
  1536. ,bednet_height
  1537. ,wire_mtrlid
  1538. ,springid
  1539. ,if_part
  1540. ,if_15strip
  1541. ,if_pocket_around
  1542. ,pocket_around_springid
  1543. ,pocket_around_row
  1544. ,pocket_around_wire_price
  1545. ,pocket_around_spring_cost
  1546. ,pocket_around_fabrics_cost
  1547. ,if_hard_around
  1548. ,hard_around_springid
  1549. ,hard_around_row
  1550. ,hard_around_wire_price
  1551. ,hard_around_mtrl_cost
  1552. ,hard_around_hr_cost
  1553. ,fabrics1_mtrlid
  1554. ,fabrics1_price
  1555. ,fabrics1_mtrl_cost
  1556. ,fabrics2_mtrlid
  1557. ,fabrics2_price
  1558. ,fabrics2_mtrl_cost
  1559. ,if_side_iron
  1560. ,side_iron_qty
  1561. ,side_iron_mtrl_cost
  1562. ,side_iron_hr_cost
  1563. ,pocket_around_spring_cost_replace_formula
  1564. ,pocket_around_fabrics_cost_replace_formula
  1565. ,hard_around_mtrl_cost_replace_formula
  1566. ,hard_around_hr_cost_replace_formula
  1567. ,fabrics1_mtrl_cost_replace_formula
  1568. ,fabrics2_mtrl_cost_replace_formula
  1569. ,side_iron_mtrl_cost_replace_formula
  1570. ,side_iron_hr_cost_replace_formula
  1571. ,cnail_mtrl_cost_replace_formula
  1572. ,cnail_mtrl_cost
  1573. ,cnail_hr_cost_replace_formula
  1574. ,cnail_hr_cost
  1575. ,glue_mtrl_cost_replace_formula
  1576. ,glue_mtrl_cost
  1577. ,spring_mtrl_cost
  1578. ,spring_hr_cost
  1579. ,spring_mtrl_cost_replace_formula
  1580. ,spring_hr_cost_replace_formula
  1581. ,1 AS if_show
  1582. ,spring_weight_replace_formula
  1583. FROM u_bednetmx";
  1584. DbSqlHelper.SelectJoin(cmd, selectStr, "u_bednetmx.bednetid = @bednetid", new Dictionary<string, object>() { { "@bednetid", bednetid } }, "bednetmxid", outputFields, 0, 0, mxList);
  1585. return mxList;
  1586. }
  1587. public void SaveBedNet(u_bednet bednet, List<u_bednetmx> mxlist, List<u_bednetmx_spring> springList)
  1588. {
  1589. var dtNow = DateTime.Now;
  1590. var fields = @"deptid,bednettypeid,mattress_width,mattress_length,mattress_height,if_doublenet,if_doublespring,snake_wire_diameter,
  1591. snake_wire_mtrl_formula,snake_wire_mtrl_cost,pocket_around_spring_formula,pocket_around_spring_cost,
  1592. pocket_around_fabrics_formula,pocket_around_fabrics_cost,hard_around_mtrl_formula,hard_around_mtrl_cost,
  1593. hard_around_hr_formula,hard_around_hr_cost,spring_mtrl_cost,spring_hr_cost,glue_price,glue_mtrl_formula,
  1594. glue_mtrl_cost,fabrics1_mtrl_formula,fabrics1_mtrl_cost,fabrics2_mtrl_formula,fabrics2_mtrl_cost,
  1595. if_side_iron,side_iron_lossrate,side_iron_price,side_iron_mtrl_formula,side_iron_mtrl_cost,side_iron_hr_formula,
  1596. side_iron_hr_cost,cnail_price,cnail_mtrl_formula,cnail_mtrl_cost,cnail_hr_formula,cnail_hr_cost,sponge_mtrlid,
  1597. sponge_thickness,sponge_price,sponge_mtrl_formula,sponge_mtrl_cost,sponge_hr_formula,sponge_hr_cost,edge_mtrlid,
  1598. edge_price,edge_mtrl_formula,edge_mtrl_cost,edge_hr_formula,edge_hr_cost,fork_qty,fork_price,fork_mtrl_formula,
  1599. fork_mtrl_cost,fork_hr_formula,fork_hr_cost,if_rsORwa,rsORwa_price,rsORwa_mtrl_formula,rsORwa_mtrl_cost,rsORwa_hr_formula,
  1600. rsORwa_hr_cost,if_sponge_drilling,sponge_drilling_hr_formula,sponge_drilling_hr_cost,total_hr_cost,total_mtrl_cost,
  1601. total_fees_cost,total_cost,createtime,createby,bednetname,spring_mtrl_formula,spring_hr_formula,
  1602. sponge_mtrl_cost_replace_formula,sponge_hr_cost_replace_formula,edge_mtrl_cost_replace_formula,edge_hr_cost_replace_formula,
  1603. fork_mtrl_cost_replace_formula,fork_hr_cost_replace_formula,rsORwa_mtrl_cost_replace_formula,rsORwa_hr_cost_replace_formula,
  1604. sponge_drilling_hr_cost_replace_formula,snake_wire_mtrl_cost_replace_formula,taxrate,taxes,commissionrate,commission,fob,
  1605. profitrate,nottax_factory_cost,nottax_dept_cost,dept_cost,foreign_cost,extras_cost,dept_profitrate,moneyrate,temp_flag,
  1606. felt_mtrlid,felt_qty,felt_price,felt_dscrp,felt_mtrl_formula,felt_mtrl_cost,felt_hr_formula,felt_hr_cost,
  1607. felt_mtrl_cost_replace_formula,felt_hr_cost_replace_formula,extras_cost_dscrp,iffork,ifsaleout,autotype,
  1608. felt_mtrl_x_cost,felt_hr_x_cost,felt_x_qty,felt_mtrl_x_cost_replace_formula,felt_hr_x_cost_replace_formula,
  1609. felt_x_mtrlid,sale_point,packtype,packqty,other_rate,transport_type,packmtrl,packet_mtrl_formula,
  1610. packet_hr_formula,packet_mtrl_cost,packet_hr_cost,packet_mtrl_cost_replace_formula,packet_hr_cost_replace_formula,
  1611. sponge_height,edge_height,sponge_tc_thickness,sponge_tc_height,sponge_tc_mtrlid,sponge_mtrl_tc_formula,
  1612. sponge_mtrl_tc_cost,sponge_mtrl_tc_cost_replace_formula,duo_qv_str,spring_weight_formula,side_iron_weight_formula,
  1613. hard_around_weight_formula,fabrics1_weight_formula,fabrics2_weight_formula,felt_weight_formula,cnail_weight_formula,
  1614. sponge_weight_formula,sponge_weight_tc_formula,edge_weight_formula,fork_weight_formula,spring_weight_replace_formula,
  1615. side_iron_weight_replace_formula,hard_around_weight_replace_formula,fabrics1_weight_replace_formula,
  1616. fabrics2_weight_replace_formula,felt_weight_replace_formula,cnail_weight_replace_formula,sponge_weight_replace_formula,
  1617. sponge_weight_tc_replace_formula,edge_weight_replace_formula,fork_weight_replace_formula,spring_weight_qty,
  1618. side_iron_weight_qty,hard_around_weight_qty,fabrics1_weight_qty,fabrics2_weight_qty,felt_weight_qty,cnail_weight_qty,
  1619. sponge_weight_qty,sponge_weight_tc_qty,edge_weight_qty,fork_weight_qty,sum_weight,if_jb";
  1620. var fieldsMx = @"bednetmxid,bednetid,spring_qty_width,spring_qty_length,bednet_height,wire_mtrlid,springid,if_part,if_15strip,
  1621. if_pocket_around,pocket_around_springid,pocket_around_row,pocket_around_wire_price,pocket_around_spring_cost,
  1622. pocket_around_fabrics_cost,if_hard_around,hard_around_springid,hard_around_row,hard_around_wire_price,
  1623. hard_around_mtrl_cost,hard_around_hr_cost,fabrics1_mtrlid,fabrics1_price,fabrics1_mtrl_cost,fabrics2_mtrlid,
  1624. fabrics2_price,fabrics2_mtrl_cost,if_side_iron,side_iron_qty,side_iron_mtrl_cost,side_iron_hr_cost,
  1625. pocket_around_spring_cost_replace_formula,pocket_around_fabrics_cost_replace_formula,hard_around_mtrl_cost_replace_formula,
  1626. hard_around_hr_cost_replace_formula,fabrics1_mtrl_cost_replace_formula,fabrics2_mtrl_cost_replace_formula,
  1627. side_iron_mtrl_cost_replace_formula,side_iron_hr_cost_replace_formula,cnail_mtrl_cost_replace_formula,cnail_mtrl_cost,
  1628. cnail_hr_cost_replace_formula,cnail_hr_cost,glue_mtrl_cost_replace_formula,glue_mtrl_cost,spring_mtrl_cost,spring_hr_cost,
  1629. spring_mtrl_cost_replace_formula,spring_hr_cost_replace_formula,spring_weight_replace_formula";
  1630. var fieldsMx_spring = @"bednetmx_partid,bednetmxid,springid,spring_qty_width,spring_qty_length,fabrics1_mtrl_cost,spring_mtrl_cost,
  1631. spring_hr_cost,spring_mtrl_cost_replace_formula,spring_hr_cost_replace_formula,spring_weight_replace_formula";
  1632. if (bednet.bednetid <= 0)
  1633. {
  1634. //新建
  1635. fields += ",bednetid,bednetcode";
  1636. bednet.bednetid = BllHelper.GetID(cmd, "u_bednet");
  1637. bednet.createtime = dtNow;
  1638. bednet.createby = context.tokendata.username;
  1639. var nettype = new u_bednet_type() { bednettypeid = bednet.bednettypeid };
  1640. DbSqlHelper.SelectOne(cmd, nettype, "typecode");
  1641. // 编号-年月日+流水
  1642. bednet.bednetcode = $"{nettype.typecode}-{dtNow.ToString("yyyyMMdd")}{(bednet.bednetid.Value % 10000).ToString("D4")}";
  1643. DbSqlHelper.Insert(cmd, "u_bednet", null, bednet, fields);
  1644. }
  1645. else
  1646. {
  1647. //修改
  1648. foreach (var mx in mxlist)
  1649. {
  1650. cmd.CommandText = @"DELETE FROM u_bednetmx_spring WHERE bednetmxid = @bednetmxid";
  1651. cmd.Parameters.Clear();
  1652. cmd.Parameters.AddWithValue("@bednetmxid", mx.bednetmxid);
  1653. cmd.ExecuteNonQuery();
  1654. }
  1655. cmd.CommandText = @"DELETE FROM u_bednetmx WHERE bednetid = @bednetid";
  1656. cmd.Parameters.Clear();
  1657. cmd.Parameters.AddWithValue("@bednetid", bednet.bednetid);
  1658. cmd.ExecuteNonQuery();
  1659. DbSqlHelper.Update(cmd, "u_bednet", null, bednet, "bednetid", fields);
  1660. }
  1661. foreach (var mx in mxlist)
  1662. {
  1663. mx.bednetid = bednet.bednetid;
  1664. mx.bednetmxid = BllHelper.GetID(cmd, "u_bednetmx");
  1665. DbSqlHelper.Insert(cmd, "u_bednetmx", null, mx, fieldsMx);
  1666. if (springList != null && springList.Any())
  1667. {
  1668. foreach (var spring in springList)
  1669. {
  1670. spring.bednetmx_partid = bednet.bednetid;
  1671. spring.bednetmxid = BllHelper.GetID(cmd, "u_bednetmx_spring");
  1672. DbSqlHelper.Insert(cmd, "u_bednetmx_spring", null, spring, fieldsMx_spring);
  1673. }
  1674. }
  1675. }
  1676. var hisprice = new u_his_price
  1677. {
  1678. bednetid_mattressid = bednet.bednetid,
  1679. typeid = 0,
  1680. cmpdate = dtNow,
  1681. cmpemp = context.tokendata.username,
  1682. nottax_dept_cost = 0,
  1683. dept_cost = 0,
  1684. foreign_cost = 0
  1685. };
  1686. var fieldsHs = "bednetid_mattressid, typeid, cmpdate, cmpemp, nottax_dept_cost, dept_cost, foreign_cost";
  1687. DbSqlHelper.Insert(cmd, "u_his_price", null, hisprice, fieldsHs);
  1688. }
  1689. }
  1690. }