BedNetHelper.cs 105 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999
  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($"弹簧材料总成本公式错误!expression: {mx.spring_mtrl_cost_replace_formula}");
  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($"弹簧材料总成本公式错误!expression: {springItem.spring_mtrl_cost_replace_formula}");
  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($"弹簧总人工成本公式错误!expression: {mx.spring_hr_cost_replace_formula}");
  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($"蛇线材料成本公式错误!expression: {bednet.snake_wire_mtrl_cost_replace_formula}");
  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($"四周口袋弹簧成本公式错误!expression: {mx.pocket_around_spring_cost_replace_formula}");
  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($"四周口袋无纺布成本公式错误!expression: {mx.pocket_around_fabrics_cost_replace_formula}");
  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($"四周加硬材料成本公式错误!expression: {mx.hard_around_mtrl_cost_replace_formula}");
  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($"四周加硬人力成本公式错误!expression: {mx.hard_around_hr_cost_replace_formula}");
  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($"入袋无纺布材料成本公式错误!expression: {mx.fabrics1_mtrl_cost_replace_formula}");
  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($"胶水材料成本公式错误!expression: {mx.glue_mtrl_cost_replace_formula}");
  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($"底面无纺布材料成本公式错误!expression: {mx.fabrics2_mtrl_cost_replace_formula}");
  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($"边铁人力成本公式错误!expression: {mx.side_iron_hr_cost_replace_formula}");
  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($"边铁材料成本公式错误!expression: {mx.side_iron_mtrl_cost_replace_formula}");
  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钉/夹码材料成本公式错误!expression: {mx.cnail_mtrl_cost_replace_formula}");
  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钉/夹码人力成本公式错误!expression: {mx.cnail_hr_cost_replace_formula}");
  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($"海绵包边材料成本公式错误!expression: {bednet.sponge_mtrl_cost_replace_formula}");
  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($"海绵包边人力成本公式错误!expression: {bednet.sponge_hr_cost_replace_formula}");
  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($"填充海绵成本公式错误!expression: {bednet.sponge_mtrl_tc_cost_replace_formula}");
  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($"封边材料成本公式错误!expression: {bednet.edge_mtrl_cost_replace_formula}");
  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($"封边人力成本公式错误!expression: {bednet.edge_hr_cost_replace_formula}");
  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($"弹叉材料成本公式错误!expression: {bednet.fork_mtrl_cost_replace_formula}");
  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($"弹叉材料成本公式错误!expression: {bednet.fork_hr_cost_replace_formula}");
  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($"胶条/包角材料成本公式错误!expression: {bednet.rsorwa_mtrl_cost_replace_formula}");
  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($"胶条/包角人力成本公式错误!expression: {bednet.rsorwa_hr_cost_replace_formula}");
  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($"海绵打孔人力成本公式错误!expression: {bednet.sponge_drilling_hr_cost_replace_formula}");
  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($"上垫层物料成本公式错误!expression: {bednet.felt_mtrl_cost_replace_formula}");
  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($"下垫层物料成本公式错误!expression: {bednet.felt_mtrl_x_cost_replace_formula}");
  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($"上垫层人力成本公式错误!expression: {bednet.felt_hr_cost_replace_formula}");
  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($"下垫层物料成本公式错误!expression: {bednet.felt_hr_x_cost_replace_formula}");
  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. bool sqlCal = !string.IsNullOrEmpty(bednet.packet_mtrl_formula) && bednet.packet_mtrl_formula.Substring(0, 2) == "@@";
  668. bednet.packet_mtrl_cost_replace_formula = ReplaceWith(bednet.packet_mtrl_cost_replace_formula, "@@", "");
  669. foreach (var replacement in replacements)
  670. {
  671. bednet.packet_mtrl_cost_replace_formula = ReplaceWith(bednet.packet_mtrl_cost_replace_formula, replacement.Key, Convert.ToString(replacement.Value));
  672. }
  673. try
  674. {
  675. if (sqlCal)
  676. {
  677. cmd.CommandText = $@"{bednet.packet_mtrl_cost_replace_formula}";
  678. cmd.Parameters.Clear();
  679. var result = cmd.ExecuteScalar();
  680. if (result != null && result != DBNull.Value)
  681. {
  682. bednet.packet_mtrl_cost += Convert.ToDecimal(result);
  683. }
  684. }
  685. else
  686. {
  687. var res = LJExprParser.Parse(bednet.packet_mtrl_cost_replace_formula);
  688. bednet.packet_mtrl_cost += res.Result.DecimalValue;
  689. }
  690. }
  691. catch (Exception ex)
  692. {
  693. throw new LJCommonException($"包装材料成本公式错误!expression: {bednet.packet_mtrl_cost_replace_formula}");
  694. }
  695. }
  696. #endregion 计算 包装总成本 结束
  697. #region 计算 包装人工成本 开始
  698. if (!string.IsNullOrEmpty(bednet.packet_hr_formula) && !string.IsNullOrEmpty(bednet.packtype))
  699. {
  700. bednet.packet_hr_formula = ConvertToEnglishSymbols(bednet.packet_hr_formula);
  701. bednet.packet_hr_cost_replace_formula = bednet.packet_hr_formula;
  702. bool sqlCal = !string.IsNullOrEmpty(bednet.packet_hr_formula) && bednet.packet_hr_formula.Substring(0, 2) == "@@";
  703. bednet.packet_hr_cost_replace_formula = ReplaceWith(bednet.packet_hr_cost_replace_formula, "@@", "");
  704. foreach (var replacement in replacements)
  705. {
  706. bednet.packet_hr_cost_replace_formula = ReplaceWith(bednet.packet_hr_cost_replace_formula, replacement.Key, Convert.ToString(replacement.Value));
  707. }
  708. try
  709. {
  710. if (sqlCal)
  711. {
  712. cmd.CommandText = $@"{bednet.packet_hr_cost_replace_formula}";
  713. cmd.Parameters.Clear();
  714. var result = cmd.ExecuteScalar();
  715. if (result != null && result != DBNull.Value)
  716. {
  717. bednet.packet_hr_cost += Convert.ToDecimal(result);
  718. }
  719. }
  720. else
  721. {
  722. var res = LJExprParser.Parse(bednet.packet_hr_cost_replace_formula);
  723. bednet.packet_hr_cost += res.Result.DecimalValue;
  724. }
  725. }
  726. catch (Exception ex)
  727. {
  728. throw new LJCommonException($"包装材料成本公式错误!expression: {bednet.packet_hr_cost_replace_formula}");
  729. }
  730. }
  731. #endregion 计算 包装人工成本 结束
  732. //有外销的 工厂利润率 增加 0.06
  733. if (bednet.ifsaleout == 1)
  734. {
  735. bednet.sale_point = 0.06M;
  736. }
  737. }
  738. // 计算总材料成本 total_mtrl_cost
  739. bednet.total_mtrl_cost = new decimal[]
  740. {
  741. bednet.spring_mtrl_cost.Value,
  742. bednet.snake_wire_mtrl_cost.Value,
  743. bednet.pocket_around_spring_cost.Value,
  744. bednet.pocket_around_fabrics_cost.Value,
  745. bednet.hard_around_mtrl_cost.Value,
  746. bednet.glue_mtrl_cost.Value,
  747. bednet.fabrics1_mtrl_cost.Value,
  748. bednet.fabrics2_mtrl_cost.Value,
  749. bednet.side_iron_mtrl_cost.Value,
  750. bednet.cnail_mtrl_cost.Value,
  751. bednet.sponge_mtrl_cost.Value,
  752. bednet.sponge_mtrl_tc_cost.Value,
  753. bednet.edge_mtrl_cost.Value,
  754. bednet.fork_mtrl_cost.Value,
  755. bednet.rsorwa_mtrl_cost.Value,
  756. bednet.felt_mtrl_cost.Value,
  757. bednet.felt_mtrl_x_cost.Value,
  758. bednet.packet_mtrl_cost.Value
  759. }.Sum();
  760. // 计算总人力成本 total_mtrl_cost
  761. bednet.total_hr_cost = new decimal[]
  762. {
  763. bednet.spring_hr_cost.Value,
  764. bednet.hard_around_hr_cost.Value,
  765. bednet.side_iron_hr_cost.Value,
  766. bednet.cnail_hr_cost.Value,
  767. bednet.sponge_hr_cost.Value,
  768. bednet.edge_hr_cost.Value,
  769. bednet.fork_hr_cost.Value,
  770. bednet.rsorwa_hr_cost.Value,
  771. bednet.felt_hr_cost.Value,
  772. bednet.felt_hr_x_cost.Value,
  773. bednet.packet_hr_cost.Value,
  774. bednet.sponge_drilling_hr_cost.Value
  775. }.Sum();
  776. //1.总成本=总材料成本+总人力成本+ 额外费用
  777. bednet.total_cost = bednet.total_mtrl_cost + bednet.total_hr_cost + bednet.total_fees_cost;
  778. //2-不含税出厂价=总成本* ( 工厂利润率 + 外销加点 )
  779. bednet.nottax_factory_cost = bednet.total_cost * (bednet.profitrate + bednet.sale_point);
  780. // 3 - 部门不含税价 = 不含税出厂价 / 部门利润率 * 佣金点数 * 额外点数 + fob
  781. try
  782. {
  783. bednet.nottax_dept_cost = bednet.nottax_factory_cost / bednet.dept_profitrate / (1 - (bednet.commission - 1)) * bednet.other_rate + bednet.fob;
  784. }
  785. catch (DivideByZeroException)
  786. {
  787. // 捕获除以零的异常并处理
  788. bednet.nottax_dept_cost = 0; // 或者设置为其他默认值
  789. }
  790. // 4 - 税金 = (部门不含税价 * 税率 - 1)
  791. bednet.taxes = bednet.nottax_dept_cost * (bednet.taxrate - 1);
  792. // 5 - 部门含税价 = 部门不含税价 * 税率
  793. bednet.dept_cost = bednet.nottax_dept_cost * bednet.taxrate;
  794. // 6 - 外币价 = 部门含税价 / 汇率
  795. if (bednet.moneyrate != 0)
  796. {
  797. bednet.foreign_cost = bednet.dept_cost / bednet.moneyrate;
  798. }
  799. }
  800. private void CulcalateWeight(u_bednet bednet, List<u_bednetmx> mxlist, List<u_bednetmx_spring> springList)
  801. {
  802. foreach (var mx in mxlist)
  803. {
  804. #region 计算 钢丝重量 开始
  805. if (!string.IsNullOrEmpty(bednet.spring_weight_formula))
  806. {
  807. bednet.spring_weight_formula = ConvertToEnglishSymbols(bednet.spring_weight_formula);
  808. mx.spring_weight_replace_formula = bednet.spring_weight_formula;
  809. if (mx.if_part == 0)
  810. {
  811. //单分区
  812. foreach (var replacement in replacements)
  813. {
  814. mx.spring_weight_replace_formula = ReplaceWith(mx.spring_weight_replace_formula, replacement.Key, Convert.ToString(replacement.Value));
  815. }
  816. try
  817. {
  818. var res = LJExprParser.Parse(mx.spring_weight_replace_formula);
  819. bednet.spring_weight_qty += res.Result.DecimalValue;
  820. }
  821. catch (Exception ex)
  822. {
  823. throw new LJCommonException($"钢丝重量公式错误!expression: {mx.spring_weight_replace_formula}");
  824. }
  825. }
  826. else
  827. {
  828. //多分区
  829. foreach (var springItem in springList)
  830. {
  831. springItem.spring_weight_replace_formula = bednet.spring_weight_formula;
  832. CalSpringMtrlCol(bednet, mx, springItem);
  833. foreach (var replacement in replacements)
  834. {
  835. springItem.spring_weight_replace_formula = ReplaceWith(springItem.spring_weight_replace_formula, replacement.Key, Convert.ToString(replacement.Value));
  836. }
  837. try
  838. {
  839. var res = LJExprParser.Parse(springItem.spring_mtrl_cost_replace_formula);
  840. bednet.spring_weight_qty += res.Result.DecimalValue;
  841. }
  842. catch (Exception ex)
  843. {
  844. throw new LJCommonException($"钢丝重量公式错误!expression: {springItem.spring_mtrl_cost_replace_formula}");
  845. }
  846. }
  847. }
  848. }
  849. #endregion 计算 钢丝重量 结束
  850. #region 计算 边铁重量 开始
  851. if (!string.IsNullOrEmpty(bednet.side_iron_weight_formula) && bednet.if_side_iron == 1 && mx.if_side_iron > 0)
  852. {
  853. bednet.side_iron_weight_formula = ConvertToEnglishSymbols(bednet.side_iron_weight_formula);
  854. bednet.side_iron_weight_replace_formula = bednet.side_iron_weight_formula;
  855. foreach (var replacement in replacements)
  856. {
  857. bednet.side_iron_weight_replace_formula = ReplaceWith(bednet.side_iron_weight_replace_formula, replacement.Key, Convert.ToString(replacement.Value));
  858. }
  859. try
  860. {
  861. var res = LJExprParser.Parse(bednet.side_iron_weight_replace_formula);
  862. bednet.side_iron_weight_qty += res.Result.DecimalValue;
  863. }
  864. catch (Exception ex)
  865. {
  866. throw new LJCommonException($"边铁重量公式错误!expression: {bednet.side_iron_weight_replace_formula}");
  867. }
  868. }
  869. #endregion 计算 边铁重量 结束
  870. #region 计算 四周加硬重量 开始
  871. if (!string.IsNullOrEmpty(bednet.hard_around_weight_formula) && mx.if_hard_around > 0)
  872. {
  873. bednet.hard_around_weight_formula = ConvertToEnglishSymbols(bednet.hard_around_weight_formula);
  874. bednet.hard_around_weight_replace_formula = bednet.hard_around_weight_formula;
  875. foreach (var replacement in replacements)
  876. {
  877. bednet.hard_around_weight_replace_formula = ReplaceWith(bednet.hard_around_weight_replace_formula, replacement.Key, Convert.ToString(replacement.Value));
  878. }
  879. try
  880. {
  881. var res = LJExprParser.Parse(bednet.hard_around_weight_replace_formula);
  882. bednet.hard_around_weight_qty += res.Result.DecimalValue;
  883. }
  884. catch (Exception ex)
  885. {
  886. throw new LJCommonException($"四周加硬重量公式错误!expression: {bednet.hard_around_weight_replace_formula}");
  887. }
  888. }
  889. #endregion 计算 四周加硬重量 结束
  890. #region 计算 入袋无纺布重量 开始
  891. if (!string.IsNullOrEmpty(bednet.fabrics1_weight_formula) && bednet.typename.IndexOf("袋装网") > -1 && mx.fabrics1_mtrlid > 0)
  892. {
  893. bednet.fabrics1_weight_formula = ConvertToEnglishSymbols(bednet.fabrics1_weight_formula);
  894. bednet.fabrics1_weight_replace_formula = bednet.fabrics1_weight_formula;
  895. foreach (var replacement in replacements)
  896. {
  897. bednet.fabrics1_weight_replace_formula = ReplaceWith(bednet.fabrics1_weight_replace_formula, replacement.Key, Convert.ToString(replacement.Value));
  898. }
  899. try
  900. {
  901. var res = LJExprParser.Parse(bednet.fabrics1_weight_replace_formula);
  902. bednet.fabrics1_weight_qty += res.Result.DecimalValue;
  903. }
  904. catch (Exception ex)
  905. {
  906. throw new LJCommonException($"入袋无纺布重量公式错误!expression: {bednet.fabrics1_weight_replace_formula}");
  907. }
  908. }
  909. #endregion 计算 入袋无纺布重量 结束
  910. #region 计算 面底无纺布重量 开始
  911. if (!string.IsNullOrEmpty(bednet.fabrics2_weight_formula) && bednet.typename.IndexOf("袋装网") > -1 && mx.fabrics2_mtrlid > 0)
  912. {
  913. bednet.fabrics2_weight_formula = ConvertToEnglishSymbols(bednet.fabrics2_weight_formula);
  914. bednet.fabrics2_weight_replace_formula = bednet.fabrics2_weight_formula;
  915. foreach (var replacement in replacements)
  916. {
  917. bednet.fabrics2_weight_replace_formula = ReplaceWith(bednet.fabrics2_weight_replace_formula, replacement.Key, Convert.ToString(replacement.Value));
  918. }
  919. try
  920. {
  921. var res = LJExprParser.Parse(bednet.fabrics2_weight_replace_formula);
  922. bednet.fabrics2_weight_qty += res.Result.DecimalValue;
  923. }
  924. catch (Exception ex)
  925. {
  926. throw new LJCommonException($"面底无纺布重量公式错误!expression: {bednet.fabrics2_weight_replace_formula}");
  927. }
  928. }
  929. #endregion 计算 面底无纺布重量 结束
  930. #region 计算 上垫层重量 开始
  931. string felt_weight_formula_replace_formula = "";
  932. if (!string.IsNullOrEmpty(bednet.felt_mtrl_formula) && bednet.felt_qty > 0)
  933. {
  934. bednet.felt_weight_formula = ConvertToEnglishSymbols(bednet.felt_weight_formula);
  935. felt_weight_formula_replace_formula = bednet.felt_weight_formula;
  936. CalSpringMtrlCol2(bednet, mx, "上垫层");
  937. foreach (var replacement in replacements)
  938. {
  939. felt_weight_formula_replace_formula = ReplaceWith(felt_weight_formula_replace_formula, replacement.Key, Convert.ToString(replacement.Value));
  940. }
  941. try
  942. {
  943. var res = LJExprParser.Parse(felt_weight_formula_replace_formula);
  944. bednet.felt_weight_qty += res.Result.DecimalValue;
  945. }
  946. catch (Exception ex)
  947. {
  948. throw new LJCommonException($"上垫层重量公式错误!expression: {felt_weight_formula_replace_formula}");
  949. }
  950. }
  951. #endregion 计算 上垫层重量 结束
  952. #region 计算 下垫层重量 开始
  953. string felt_x_weight_formula_replace_formula = "";
  954. if (!string.IsNullOrEmpty(bednet.felt_weight_formula) && bednet.felt_x_qty > 0)
  955. {
  956. bednet.felt_weight_formula = ConvertToEnglishSymbols(bednet.felt_weight_formula);
  957. felt_x_weight_formula_replace_formula = bednet.felt_weight_formula;
  958. CalSpringMtrlCol2(bednet, mx, "下垫层");
  959. foreach (var replacement in replacements)
  960. {
  961. felt_x_weight_formula_replace_formula = ReplaceWith(felt_x_weight_formula_replace_formula, replacement.Key, Convert.ToString(replacement.Value));
  962. }
  963. try
  964. {
  965. var res = LJExprParser.Parse(felt_x_weight_formula_replace_formula);
  966. bednet.felt_weight_qty += res.Result.DecimalValue;
  967. }
  968. catch (Exception ex)
  969. {
  970. throw new LJCommonException($"下垫层重量公式错误!expression: {felt_x_weight_formula_replace_formula}");
  971. }
  972. }
  973. bednet.felt_weight_replace_formula += felt_weight_formula_replace_formula;
  974. bednet.felt_weight_replace_formula += Environment.NewLine;
  975. bednet.felt_weight_replace_formula += felt_x_weight_formula_replace_formula;
  976. #endregion 计算 下垫层重量 结束
  977. #region 计算 C钉/夹码重量 开始
  978. if (!string.IsNullOrEmpty(bednet.cnail_weight_formula))
  979. {
  980. bednet.cnail_weight_formula = ConvertToEnglishSymbols(bednet.cnail_weight_formula);
  981. bednet.cnail_weight_replace_formula = bednet.cnail_weight_formula;
  982. foreach (var replacement in replacements)
  983. {
  984. bednet.cnail_weight_replace_formula = ReplaceWith(bednet.cnail_weight_replace_formula, replacement.Key, Convert.ToString(replacement.Value));
  985. }
  986. try
  987. {
  988. var res = LJExprParser.Parse(bednet.cnail_weight_replace_formula);
  989. bednet.cnail_weight_qty += res.Result.DecimalValue;
  990. }
  991. catch (Exception ex)
  992. {
  993. throw new LJCommonException($"C钉/夹码重量公式错误!expression: {bednet.cnail_weight_replace_formula}");
  994. }
  995. }
  996. #endregion 计算 C钉/夹码重量 结束
  997. #region 计算 海绵包边重量 开始
  998. if (!string.IsNullOrEmpty(bednet.sponge_weight_formula) && bednet.sponge_mtrlid > 0)
  999. {
  1000. bednet.sponge_weight_formula = ConvertToEnglishSymbols(bednet.sponge_weight_formula);
  1001. bednet.sponge_weight_replace_formula = bednet.sponge_weight_formula;
  1002. foreach (var replacement in replacements)
  1003. {
  1004. bednet.sponge_weight_replace_formula = ReplaceWith(bednet.sponge_weight_replace_formula, replacement.Key, Convert.ToString(replacement.Value));
  1005. }
  1006. try
  1007. {
  1008. var res = LJExprParser.Parse(bednet.sponge_weight_replace_formula);
  1009. bednet.sponge_weight_qty += res.Result.DecimalValue;
  1010. }
  1011. catch (Exception ex)
  1012. {
  1013. throw new LJCommonException($"海绵包边重量公式错误!expression: {bednet.sponge_weight_replace_formula}");
  1014. }
  1015. }
  1016. #endregion 计算 海绵包边重量 结束
  1017. #region 计算 填充海绵重量 开始
  1018. if (!string.IsNullOrEmpty(bednet.sponge_weight_tc_formula) && bednet.sponge_tc_mtrlid > 0)
  1019. {
  1020. bednet.sponge_weight_tc_formula = ConvertToEnglishSymbols(bednet.sponge_weight_tc_formula);
  1021. bednet.sponge_weight_tc_replace_formula = bednet.sponge_weight_tc_formula;
  1022. CalSpringMtrlCol2(bednet, mx, "填充海绵");
  1023. foreach (var replacement in replacements)
  1024. {
  1025. bednet.sponge_weight_tc_replace_formula = ReplaceWith(bednet.sponge_weight_tc_replace_formula, replacement.Key, Convert.ToString(replacement.Value));
  1026. }
  1027. try
  1028. {
  1029. var res = LJExprParser.Parse(bednet.sponge_weight_tc_replace_formula);
  1030. bednet.sponge_weight_tc_qty += res.Result.DecimalValue;
  1031. }
  1032. catch (Exception ex)
  1033. {
  1034. throw new LJCommonException($"填充海绵重量公式错误!expression: {bednet.sponge_weight_tc_replace_formula}");
  1035. }
  1036. }
  1037. #endregion 计算 填充海绵重量 结束
  1038. #region 计算 封边材料重量 开始
  1039. if (!string.IsNullOrEmpty(bednet.edge_weight_formula) && bednet.edge_mtrlid > 0)
  1040. {
  1041. bednet.edge_weight_formula = ConvertToEnglishSymbols(bednet.edge_weight_formula);
  1042. bednet.edge_weight_replace_formula = bednet.edge_weight_formula;
  1043. CalSpringMtrlCol2(bednet, mx, "封边");
  1044. foreach (var replacement in replacements)
  1045. {
  1046. bednet.edge_weight_replace_formula = ReplaceWith(bednet.edge_weight_replace_formula, replacement.Key, Convert.ToString(replacement.Value));
  1047. }
  1048. try
  1049. {
  1050. var res = LJExprParser.Parse(bednet.edge_weight_replace_formula);
  1051. bednet.edge_weight_qty += res.Result.DecimalValue;
  1052. }
  1053. catch (Exception ex)
  1054. {
  1055. throw new LJCommonException($"封边材料重量公式错误!expression: {bednet.edge_weight_replace_formula}");
  1056. }
  1057. }
  1058. #endregion 计算 封边材料重量 结束
  1059. #region 计算 弹叉材料重量 开始
  1060. if (!string.IsNullOrEmpty(bednet.fork_weight_formula) && bednet.fork_qty > 0)
  1061. {
  1062. bednet.fork_weight_formula = ConvertToEnglishSymbols(bednet.fork_weight_formula);
  1063. bednet.fork_weight_replace_formula = bednet.fork_weight_formula;
  1064. foreach (var replacement in replacements)
  1065. {
  1066. bednet.fork_weight_replace_formula = ReplaceWith(bednet.fork_weight_replace_formula, replacement.Key, Convert.ToString(replacement.Value));
  1067. }
  1068. try
  1069. {
  1070. var res = LJExprParser.Parse(bednet.fork_weight_replace_formula);
  1071. bednet.fork_weight_qty += res.Result.DecimalValue;
  1072. }
  1073. catch (Exception ex)
  1074. {
  1075. throw new LJCommonException($"弹叉材料重量公式错误!expression: {bednet.fork_weight_replace_formula}");
  1076. }
  1077. }
  1078. #endregion 计算 弹叉材料重量 结束
  1079. }
  1080. // 计算总材料成本 total_mtrl_cost
  1081. bednet.sum_weight = new decimal[]
  1082. {
  1083. bednet.spring_weight_qty.Value,
  1084. bednet.side_iron_weight_qty.Value,
  1085. bednet.hard_around_weight_qty.Value,
  1086. bednet.fabrics1_weight_qty.Value,
  1087. bednet.fabrics2_weight_qty.Value,
  1088. bednet.felt_weight_qty.Value,
  1089. bednet.cnail_weight_qty.Value,
  1090. bednet.sponge_weight_qty.Value,
  1091. bednet.sponge_weight_tc_qty.Value,
  1092. bednet.edge_weight_qty.Value,
  1093. bednet.fork_weight_qty.Value
  1094. }.Sum();
  1095. }
  1096. private void InitBedNet(u_bednet bednet)
  1097. {
  1098. var dept = new u_dept() { deptid = bednet.deptid.Value };
  1099. DbSqlHelper.SelectOne(cmd, dept, "pricelistid");
  1100. var bednetType = new u_bednet_type() { bednettypeid = bednet.bednettypeid };
  1101. DbSqlHelper.SelectOne(cmd, bednetType, "typename");
  1102. bednet.pricelistid = dept.pricelistid;
  1103. bednet.typename = bednetType.typename;
  1104. }
  1105. private void InitReplaceMents(u_bednet bednet)
  1106. {
  1107. replacements.Clear();
  1108. var bednetVarList = new List<u_bednet_var>();
  1109. var selectStr = @"SELECT u_bednet_varmx.varid AS varid
  1110. ,varkind
  1111. ,varcode
  1112. ,varname
  1113. ,varclass
  1114. ,vartype
  1115. ,varunit
  1116. ,u_bednet_varmx.varvalue AS varvalue
  1117. FROM u_bednet_var
  1118. INNER JOIN u_bednet_varmx ON u_bednet_varmx.varid = u_bednet_var.varid";
  1119. var whereList = new List<string>();
  1120. whereList.Add("varkind = @varkind");
  1121. whereList.Add("u_bednet_varmx.pricelistid = @pricelistid");
  1122. whereList.Add(@"(u_bednet_var.varclass = 1
  1123. AND (
  1124. u_bednet_varmx.bednettypeid = @bednettypeid
  1125. OR @bednettypeid = 0
  1126. )
  1127. )
  1128. OR (u_bednet_var.varclass = 0)");
  1129. var param = new Dictionary<string, object>();
  1130. param.Add("@varkind", 0);
  1131. param.Add("@pricelistid", bednet.pricelistid);
  1132. param.Add("@bednettypeid", bednet.bednettypeid);
  1133. DbSqlHelper.SelectJoin(cmd, selectStr, ListEx.GetWhereStr(whereList), param, "varid", "varid,varkind,varcode,varname,varclass,vartype,varunit,varvalue", 0, 0, bednetVarList);
  1134. AddKeyValue("床垫宽", bednet.mattress_width);
  1135. AddKeyValue("床垫长", bednet.mattress_length);
  1136. AddKeyValue("床垫高", bednet.mattress_height);
  1137. AddKeyValue("双簧", bednet.if_doublespring);
  1138. AddKeyValue("弹叉数量", bednet.fork_qty);
  1139. AddKeyValue("包装方式", bednet.packtype);
  1140. AddKeyValue("包装数量", bednet.packqty);
  1141. AddKeyValue("运输方式", bednet.transport_type);
  1142. AddKeyValue("包装材料", bednet.packmtrl);
  1143. AddKeyValue("床网类别", bednet.typename);
  1144. foreach (var netvar in bednetVarList)
  1145. {
  1146. AddKeyValue(netvar.varname, netvar.varvalue);
  1147. }
  1148. }
  1149. private void InitMxReplaceMents(u_bednet bednet,u_bednetmx mx, u_spring spring)
  1150. {
  1151. AddKeyValue("弹簧排列个数-宽", mx.spring_qty_width);
  1152. AddKeyValue("弹簧排列个数-长", mx.spring_qty_length);
  1153. AddKeyValue("弹簧计算个数(宽)", mx.spring_qty_width);
  1154. AddKeyValue("弹簧计算个数(长)", mx.spring_qty_length);
  1155. AddKeyValue("边铁条数", mx.side_iron_qty);
  1156. AddKeyValue("条数", mx.side_iron_qty);
  1157. AddKeyValue("四周口袋-排数", mx.pocket_around_row);
  1158. AddKeyValue("四周口袋", mx.if_pocket_around);
  1159. AddKeyValue("四周加硬-排数", mx.hard_around_row);
  1160. AddKeyValue("四周加硬", mx.if_hard_around);
  1161. spring.gram_weight /= 1000;
  1162. if (spring.gram_weight > 0)
  1163. {
  1164. AddKeyValue("弹簧重/个", spring.gram_weight);
  1165. AddKeyValue("弹簧重", spring.gram_weight);
  1166. AddKeyValue("弹簧克重", spring.gram_weight * 1000);
  1167. }
  1168. if (mx.bednet_height > 0)
  1169. {
  1170. AddKeyValue("床网高", mx.bednet_height);
  1171. }
  1172. if (spring.height > 0)
  1173. {
  1174. AddKeyValue("口袋弹簧高度", spring.height);
  1175. }
  1176. if (spring.center_diameter > 0)
  1177. {
  1178. AddKeyValue("口袋弹簧心径", spring.center_diameter);
  1179. }
  1180. cmd.CommandText = @"SELECT TOP 1 isnull(u_mtrl_price_pricelist.price, 0) AS price
  1181. FROM u_mtrl_price_pricelist
  1182. INNER JOIN u_mtrl_price ON u_mtrl_price.mtrlid = u_mtrl_price_pricelist.mtrlid
  1183. WHERE cast(u_mtrl_price.name AS DECIMAL(18, 5)) = @line_diameter
  1184. AND u_mtrl_price.mtrltype = 0
  1185. AND u_mtrl_price_pricelist.pricelistid = @pricelistid";
  1186. cmd.Parameters.Clear();
  1187. cmd.Parameters.AddWithValue("@line_diameter", spring.line_diameter);
  1188. cmd.Parameters.AddWithValue("@pricelistid", bednet.pricelistid);
  1189. decimal price = 0;
  1190. using (var reader = cmd.ExecuteReader())
  1191. {
  1192. if (reader.Read())
  1193. {
  1194. price = Convert.ToDecimal(reader["price"]);
  1195. price /= 1000;
  1196. }
  1197. }
  1198. if (price > 0)
  1199. {
  1200. AddKeyValue("加硬弹簧单价", price);
  1201. AddKeyValue("口袋弹簧单价", price);
  1202. AddKeyValue("弹簧单价", price);
  1203. }
  1204. }
  1205. /// <summary>
  1206. /// 用于床网报价 弹簧材料总成本 弹簧人工总成本
  1207. /// </summary>
  1208. /// <param name="cmd"></param>
  1209. /// <param name="dept"></param>
  1210. /// <param name="mx"></param>
  1211. /// <param name="mx2"></param>
  1212. private void CalSpringMtrlCol(u_bednet bednet, u_bednetmx mx, u_bednetmx_spring mx2)
  1213. {
  1214. AddKeyValue("弹簧排列个数-宽", mx.spring_qty_width);
  1215. AddKeyValue("弹簧排列个数-长", mx.spring_qty_length);
  1216. AddKeyValue("弹簧计算个数(宽)", mx.spring_qty_width);
  1217. AddKeyValue("弹簧计算个数(长)", mx.spring_qty_length);
  1218. AddKeyValue("边铁条数", mx.side_iron_qty);
  1219. AddKeyValue("条数", mx.side_iron_qty);
  1220. var spring = new u_spring() { springid = mx.springid };
  1221. DbSqlHelper.SelectOne(cmd, spring, "line_diameter,gram_weight");
  1222. spring.gram_weight /= 1000;
  1223. if (spring.gram_weight > 0)
  1224. {
  1225. AddKeyValue("弹簧重/个", spring.gram_weight);
  1226. AddKeyValue("弹簧重", spring.gram_weight);
  1227. }
  1228. cmd.CommandText = @"SELECT TOP 1 isnull(u_mtrl_price_pricelist.price, 0) AS price
  1229. FROM u_mtrl_price_pricelist
  1230. INNER JOIN u_mtrl_price ON u_mtrl_price.mtrlid = u_mtrl_price_pricelist.mtrlid
  1231. WHERE cast(u_mtrl_price.name AS DECIMAL(18, 5)) = @line_diameter
  1232. AND u_mtrl_price.mtrltype = 0
  1233. AND u_mtrl_price_pricelist.pricelistid = @pricelistid";
  1234. cmd.Parameters.Clear();
  1235. cmd.Parameters.AddWithValue("@line_diameter", spring.line_diameter);
  1236. cmd.Parameters.AddWithValue("@pricelistid", bednet.pricelistid);
  1237. decimal price = 0;
  1238. using (var reader = cmd.ExecuteReader())
  1239. {
  1240. if (reader.Read())
  1241. {
  1242. price = Convert.ToDecimal(reader["price"]);
  1243. price /= 1000;
  1244. }
  1245. }
  1246. if (price > 0)
  1247. {
  1248. AddKeyValue("弹簧单价", price);
  1249. }
  1250. }
  1251. /// <summary>
  1252. /// 代码对照wf_replace_var_dw2
  1253. /// </summary>
  1254. /// <param name="cmd"></param>
  1255. /// <param name="mx"></param>
  1256. private void CalSpringMtrlCol2(u_bednet bednet, u_bednetmx mx, string type)
  1257. {
  1258. var spring = new u_spring() { springid = mx.springid };
  1259. DbSqlHelper.SelectOne(cmd, spring, "line_diameter,gram_weight,center_diameter");
  1260. #region 计算 底面无纺布 开始
  1261. //计算 上下无纺布方数 =(B4+C4)*(B4+D4)/10000
  1262. if ("底面无纺布".Equals(type) && mx.fabrics2_mtrlid > 0)
  1263. {
  1264. decimal fabrics = (mx.bednet_height.Value + bednet.mattress_width.Value) * (mx.bednet_height.Value + bednet.mattress_length.Value) / 10000;
  1265. AddKeyValue("上下无纺布方数", fabrics);
  1266. decimal fabrics_price = getMtrlPrice(2, bednet.pricelistid.Value, mx.fabrics2_mtrlid.Value);
  1267. if (fabrics_price > 0) AddKeyValue("无纺布单价", fabrics_price);
  1268. }
  1269. #endregion 计算 底面无纺布 结束
  1270. #region 计算 入袋无纺布 开始
  1271. //计算 入袋无纺布方数 = (B4+I4+2)*((I4*3.14)+1)/10000
  1272. if ("入袋无纺布".Equals(type) && mx.fabrics1_mtrlid > 0)
  1273. {
  1274. decimal fabrics = (mx.bednet_height.Value + spring.center_diameter.Value + 2) * (spring.center_diameter.Value * (decimal)3.14 + 1) / 10000;
  1275. AddKeyValue("入袋无纺布方数", fabrics);
  1276. decimal fabrics_price = getMtrlPrice(2, bednet.pricelistid.Value, mx.fabrics1_mtrlid.Value);
  1277. if (fabrics_price > 0) AddKeyValue("无纺布单价", fabrics_price);
  1278. }
  1279. #endregion 计算 入袋无纺布 结束
  1280. #region 计算 四周加硬弹簧 开始
  1281. // 主要是要替换 【弹簧克重】 【弹簧单价】
  1282. // 因相同部分已存在,不需要后续
  1283. #endregion 计算 四周加硬弹簧 结束
  1284. #region 计算 海绵包边 开始
  1285. if ("海绵包边".Equals(type) && bednet.sponge_thickness.Value > 0 && bednet.sponge_mtrlid.Value > 0)
  1286. {
  1287. var mtrl_price = new u_mtrl_price() { mtrlid = bednet.sponge_mtrlid };
  1288. DbSqlHelper.SelectOne(cmd, mtrl_price, "name");
  1289. AddKeyValue("物料名称", mtrl_price.name);
  1290. AddKeyValue("裥棉厚度", bednet.sponge_thickness.Value);
  1291. AddKeyValue("海绵厚度", bednet.sponge_thickness.Value);
  1292. if (bednet.sponge_height.Value > 0)
  1293. {
  1294. AddKeyValue("海绵高", bednet.sponge_height.Value);
  1295. }
  1296. cmd.CommandText = @"SELECT isnull(u_mtrl_price_pricelist.price, 0) AS price
  1297. FROM u_mtrl_price_pricelist
  1298. WHERE u_mtrl_price_pricelist.mtrlid = @mtrlid
  1299. AND u_mtrl_price_pricelist.pricelistid = @pricelistid";
  1300. cmd.Parameters.Clear();
  1301. cmd.Parameters.AddWithValue("@mtrlid", bednet.sponge_mtrlid);
  1302. cmd.Parameters.AddWithValue("@pricelistid", bednet.pricelistid);
  1303. using (var reader = cmd.ExecuteReader())
  1304. {
  1305. if (reader.Read())
  1306. {
  1307. decimal sponge_price = Convert.ToDecimal(reader["price"]);
  1308. AddKeyValue("裥棉单价", sponge_price);
  1309. AddKeyValue("海绵单价", sponge_price);
  1310. }
  1311. }
  1312. }
  1313. #endregion 计算 海绵包边 结束
  1314. #region 计算 填充海绵 开始
  1315. if ("填充海绵".Equals(type) && bednet.sponge_tc_thickness.Value > 0 && bednet.sponge_tc_mtrlid.Value > 0)
  1316. {
  1317. var mtrl_price = new u_mtrl_price() { mtrlid = bednet.sponge_tc_mtrlid };
  1318. DbSqlHelper.SelectOne(cmd, mtrl_price, "name");
  1319. AddKeyValue("物料名称", mtrl_price.name);
  1320. AddKeyValue("裥棉厚度", bednet.sponge_tc_thickness.Value);
  1321. AddKeyValue("海绵厚度", bednet.sponge_tc_thickness.Value);
  1322. if (bednet.sponge_tc_height.Value > 0)
  1323. {
  1324. AddKeyValue("海绵高", bednet.sponge_tc_height.Value);
  1325. }
  1326. cmd.CommandText = @"SELECT isnull(u_mtrl_price_pricelist.price, 0) AS price
  1327. FROM u_mtrl_price_pricelist
  1328. WHERE u_mtrl_price_pricelist.mtrlid = @mtrlid
  1329. AND u_mtrl_price_pricelist.pricelistid = @pricelistid";
  1330. cmd.Parameters.Clear();
  1331. cmd.Parameters.AddWithValue("@mtrlid", bednet.sponge_tc_mtrlid);
  1332. cmd.Parameters.AddWithValue("@pricelistid", bednet.pricelistid);
  1333. using (var reader = cmd.ExecuteReader())
  1334. {
  1335. if (reader.Read())
  1336. {
  1337. decimal sponge_price = Convert.ToDecimal(reader["price"]);
  1338. AddKeyValue("裥棉单价", sponge_price);
  1339. AddKeyValue("海绵单价", sponge_price);
  1340. }
  1341. }
  1342. }
  1343. #endregion 计算 填充海绵 结束
  1344. #region 计算 封边 开始
  1345. if ("封边".Equals(type) && bednet.edge_mtrlid > 0)
  1346. {
  1347. AddKeyValue("有边铁", mx.if_side_iron);
  1348. cmd.CommandText = @"SELECT isnull(u_mtrl_price_pricelist.price, 0) AS price
  1349. ,u_mtrl_price.gram_weight
  1350. FROM u_mtrl_price_pricelist
  1351. INNER JOIN u_mtrl_price ON u_mtrl_price.mtrlid = u_mtrl_price_pricelist.mtrlid
  1352. WHERE u_mtrl_price_pricelist.mtrlid = @mtrlid
  1353. AND u_mtrl_price_pricelist.pricelistid = @pricelistid";
  1354. cmd.Parameters.Clear();
  1355. cmd.Parameters.AddWithValue("@mtrlid", bednet.edge_mtrlid);
  1356. cmd.Parameters.AddWithValue("@pricelistid", bednet.pricelistid);
  1357. using (var reader = cmd.ExecuteReader())
  1358. {
  1359. if (reader.Read())
  1360. {
  1361. decimal edge_price = Convert.ToDecimal(reader["price"]);
  1362. decimal edge_weight = Convert.ToDecimal(reader["gram_weight"]);
  1363. if (edge_price > 0) AddKeyValue("毡单价", edge_price);
  1364. if (edge_weight > 0) AddKeyValue("毡克重", edge_weight);
  1365. }
  1366. }
  1367. if (bednet.edge_height > 0) AddKeyValue("封边高", bednet.edge_height);
  1368. }
  1369. #endregion 计算 封边 结束
  1370. #region 计算 上垫层 开始
  1371. if ("上垫层".Equals(type) && bednet.felt_mtrlid > 0)
  1372. {
  1373. cmd.CommandText = @"SELECT isnull(u_mtrl_price_pricelist.price, 0) AS price
  1374. ,u_mtrl_price.gram_weight
  1375. FROM u_mtrl_price_pricelist
  1376. INNER JOIN u_mtrl_price ON u_mtrl_price.mtrlid = u_mtrl_price_pricelist.mtrlid
  1377. WHERE u_mtrl_price_pricelist.mtrlid = @mtrlid
  1378. AND u_mtrl_price_pricelist.pricelistid = @pricelistid";
  1379. cmd.Parameters.Clear();
  1380. cmd.Parameters.AddWithValue("@mtrlid", bednet.felt_mtrlid);
  1381. cmd.Parameters.AddWithValue("@pricelistid", bednet.pricelistid);
  1382. using (var reader = cmd.ExecuteReader())
  1383. {
  1384. if (reader.Read())
  1385. {
  1386. decimal felt_price = Convert.ToDecimal(reader["price"]);
  1387. decimal felt_weight = Convert.ToDecimal(reader["gram_weight"]);
  1388. if (felt_price > 0) AddKeyValue("垫层物料单价", felt_price);
  1389. if (felt_weight > 0) AddKeyValue("垫层物料克重", felt_weight);
  1390. }
  1391. }
  1392. if (bednet.felt_qty > 0) AddKeyValue("垫层物料数量", bednet.felt_qty);
  1393. }
  1394. #endregion 计算 上垫层 结束
  1395. #region 计算 下垫层 开始
  1396. if ("下垫层".Equals(type) && bednet.felt_x_mtrlid > 0)
  1397. {
  1398. cmd.CommandText = @"SELECT isnull(u_mtrl_price_pricelist.price, 0) AS price
  1399. ,u_mtrl_price.gram_weight
  1400. FROM u_mtrl_price_pricelist
  1401. INNER JOIN u_mtrl_price ON u_mtrl_price.mtrlid = u_mtrl_price_pricelist.mtrlid
  1402. WHERE u_mtrl_price_pricelist.mtrlid = @mtrlid
  1403. AND u_mtrl_price_pricelist.pricelistid = @pricelistid";
  1404. cmd.Parameters.Clear();
  1405. cmd.Parameters.AddWithValue("@mtrlid", bednet.felt_x_mtrlid);
  1406. cmd.Parameters.AddWithValue("@pricelistid", bednet.pricelistid);
  1407. using (var reader = cmd.ExecuteReader())
  1408. {
  1409. if (reader.Read())
  1410. {
  1411. decimal felt_price = Convert.ToDecimal(reader["price"]);
  1412. decimal felt_weight = Convert.ToDecimal(reader["gram_weight"]);
  1413. if (felt_price > 0) AddKeyValue("垫层物料单价", felt_price);
  1414. if (felt_weight > 0) AddKeyValue("垫层物料克重", felt_weight);
  1415. }
  1416. }
  1417. if (bednet.felt_x_qty > 0) AddKeyValue("垫层物料数量", bednet.felt_x_qty);
  1418. }
  1419. #endregion 计算 下垫层 结束
  1420. }
  1421. private void CalSnakeCol(u_bednet bednet,u_spring spring)
  1422. {
  1423. #region 替换蛇线单价 snake_wire_diameter
  1424. cmd.CommandText = @"SELECT TOP 1 isnull(u_mtrl_price_pricelist.price, 0) AS price
  1425. FROM u_mtrl_price_pricelist
  1426. INNER JOIN u_mtrl_price ON u_mtrl_price.mtrlid = u_mtrl_price_pricelist.mtrlid
  1427. WHERE cast(u_mtrl_price.name AS DECIMAL(18, 5)) = @line_diameter
  1428. AND u_mtrl_price.mtrltype = 0
  1429. AND u_mtrl_price_pricelist.pricelistid = @pricelistid";
  1430. cmd.Parameters.Clear();
  1431. cmd.Parameters.AddWithValue("@line_diameter", spring.line_diameter);
  1432. cmd.Parameters.AddWithValue("@pricelistid", bednet.pricelistid);
  1433. decimal price = 0;
  1434. using (var reader = cmd.ExecuteReader())
  1435. {
  1436. if (reader.Read())
  1437. {
  1438. price = Convert.ToDecimal(reader["price"]);
  1439. price /= 1000;
  1440. }
  1441. }
  1442. if (price > 0)
  1443. {
  1444. AddKeyValue("蛇线单价", price);
  1445. }
  1446. #endregion
  1447. }
  1448. private decimal getMtrlPrice(int mtrltype, int pricelistid, int mtrlid)
  1449. {
  1450. decimal price = 0;
  1451. cmd.CommandText = @"SELECT TOP 1 isnull(u_mtrl_price_pricelist.price, 0) AS price
  1452. FROM u_mtrl_price_pricelist
  1453. INNER JOIN u_mtrl_price ON u_mtrl_price.mtrlid = u_mtrl_price_pricelist.mtrlid
  1454. WHERE u_mtrl_price.mtrlid = @mtrlid
  1455. AND u_mtrl_price.mtrltype = @mtrltype
  1456. AND u_mtrl_price_pricelist.pricelistid = @pricelistid";
  1457. cmd.Parameters.Clear();
  1458. cmd.Parameters.AddWithValue("@mtrlid", mtrlid);
  1459. cmd.Parameters.AddWithValue("@mtrltype", mtrltype);
  1460. cmd.Parameters.AddWithValue("@pricelistid", pricelistid);
  1461. using (var reader = cmd.ExecuteReader())
  1462. {
  1463. if (reader.Read())
  1464. {
  1465. price = Convert.ToDecimal(reader["price"]);
  1466. price /= 1000;
  1467. }
  1468. }
  1469. return price;
  1470. }
  1471. private string ConvertToEnglishSymbols(string input)
  1472. {
  1473. input = input.Replace("(", "(")
  1474. .Replace(")", ")")
  1475. .Replace(",", ",")
  1476. .Replace("。", ".")
  1477. .Replace(":", ":")
  1478. .Replace(";", ";")
  1479. .Replace("“", "\"")
  1480. .Replace("”", "\"")
  1481. .Replace("‘", "'")
  1482. .Replace("’", "'");
  1483. return input;
  1484. }
  1485. private void AddKeyValue(string key, object value, bool isReplace = true)
  1486. {
  1487. key = $"【{key}】";
  1488. if (!replacements.ContainsKey(key))
  1489. {
  1490. replacements.Add(key, value);
  1491. }
  1492. else if (isReplace)
  1493. {
  1494. replacements[key] = value;
  1495. }
  1496. }
  1497. private string ReplaceWith(string input, string oldValue, string newValue)
  1498. {
  1499. return input.Replace(oldValue, newValue);
  1500. }
  1501. public void GetBedNet(u_bednet bednet)
  1502. {
  1503. var outputFields = @"bednetid,deptid,bednettypeid,mattress_width,mattress_length,mattress_height,if_doublenet,if_doublespring,snake_wire_diameter,
  1504. snake_wire_mtrl_formula,snake_wire_mtrl_cost,pocket_around_spring_formula,pocket_around_spring_cost,pocket_around_fabrics_formula,
  1505. pocket_around_fabrics_cost,hard_around_mtrl_formula,hard_around_mtrl_cost,hard_around_hr_formula,hard_around_hr_cost,
  1506. spring_mtrl_cost,spring_hr_cost,glue_price,glue_mtrl_formula,glue_mtrl_cost,fabrics1_mtrl_formula,fabrics1_mtrl_cost,
  1507. fabrics2_mtrl_formula,fabrics2_mtrl_cost,if_side_iron,side_iron_lossrate,side_iron_price,side_iron_mtrl_formula,
  1508. side_iron_mtrl_cost,side_iron_hr_formula,side_iron_hr_cost,cnail_price,cnail_mtrl_formula,cnail_mtrl_cost,cnail_hr_formula,
  1509. cnail_hr_cost,sponge_mtrlid,sponge_thickness,sponge_price,sponge_mtrl_formula,sponge_mtrl_cost,sponge_hr_formula,
  1510. sponge_hr_cost,edge_mtrlid,edge_price,edge_mtrl_formula,edge_mtrl_cost,edge_hr_formula,edge_hr_cost,fork_qty,fork_price,
  1511. fork_mtrl_formula,fork_mtrl_cost,fork_hr_formula,fork_hr_cost,if_rsORwa,rsORwa_price,rsORwa_mtrl_formula,rsORwa_mtrl_cost,
  1512. rsORwa_hr_formula,rsORwa_hr_cost,if_sponge_drilling,sponge_drilling_hr_formula,sponge_drilling_hr_cost,total_hr_cost,
  1513. total_mtrl_cost,total_fees_cost,total_cost,createtime,createby,bednetcode,bednetname,spring_mtrl_formula,spring_hr_formula,
  1514. sponge_mtrl_cost_replace_formula,sponge_hr_cost_replace_formula,edge_mtrl_cost_replace_formula,edge_hr_cost_replace_formula,
  1515. fork_mtrl_cost_replace_formula,fork_hr_cost_replace_formula,rsORwa_mtrl_cost_replace_formula,rsORwa_hr_cost_replace_formula,
  1516. sponge_drilling_hr_cost_replace_formula,snake_wire_mtrl_cost_replace_formula,flag,taxrate,taxes,commissionrate,commission,fob,
  1517. profitrate,nottax_factory_cost,nottax_dept_cost,dept_cost,foreign_cost,extras_cost,dept_profitrate,moneyrate,temp_flag,felt_mtrlid,
  1518. felt_qty,felt_price,felt_dscrp,felt_mtrl_formula,felt_mtrl_cost,felt_hr_formula,felt_hr_cost,felt_mtrl_cost_replace_formula,
  1519. felt_hr_cost_replace_formula,extras_cost_dscrp,iffork,ifsaleout,autotype,felt_mtrl_x_cost,felt_hr_x_cost,felt_x_qty,
  1520. felt_mtrl_x_cost_replace_formula,felt_hr_x_cost_replace_formula,felt_x_mtrlid,sale_point,packtype,packqty,other_rate,
  1521. transport_type,packmtrl,packet_mtrl_formula,packet_hr_formula,packet_mtrl_cost,packet_hr_cost,packet_mtrl_cost_replace_formula,
  1522. packet_hr_cost_replace_formula,sponge_height,edge_height,sponge_tc_thickness,sponge_tc_height,sponge_tc_mtrlid,sponge_mtrl_tc_cost,
  1523. sponge_mtrl_tc_formula,sponge_mtrl_tc_cost_replace_formula,sum_weight,spring_weight,snake_weight,side_weight,duo_qv_str,
  1524. spring_weight_formula,side_iron_weight_formula,hard_around_weight_formula,fabrics1_weight_formula,fabrics2_weight_formula,
  1525. felt_weight_formula,cnail_weight_formula,sponge_weight_formula,sponge_weight_tc_formula,edge_weight_formula,fork_weight_formula,
  1526. spring_weight_replace_formula,side_iron_weight_replace_formula,hard_around_weight_replace_formula,fabrics1_weight_replace_formula,
  1527. fabrics2_weight_replace_formula,felt_weight_replace_formula,cnail_weight_replace_formula,sponge_weight_replace_formula,
  1528. sponge_weight_tc_replace_formula,edge_weight_replace_formula,fork_weight_replace_formula,spring_weight_qty,
  1529. side_iron_weight_qty,hard_around_weight_qty,fabrics1_weight_qty,fabrics2_weight_qty,felt_weight_qty,
  1530. cnail_weight_qty,sponge_weight_qty,sponge_weight_tc_qty,edge_weight_qty,fork_weight_qty,if_jb";
  1531. DbSqlHelper.SelectOne(cmd, bednet, outputFields);
  1532. }
  1533. public List<u_bednetmx_spring> GetBedNetSpringList(int bednetid)
  1534. {
  1535. var springList = new List<u_bednetmx_spring>();
  1536. 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";
  1537. var selectStr = @"SELECT bednetmx_partid
  1538. ,u_bednetmx_spring.bednetmxid AS bednetmxid
  1539. ,u_bednetmx_spring.springid AS springid
  1540. ,u_bednetmx_spring.spring_qty_width AS spring_qty_width
  1541. ,u_bednetmx_spring.spring_qty_length AS spring_qty_length
  1542. ,u_bednetmx_spring.fabrics1_mtrl_cost AS fabrics1_mtrl_cost
  1543. ,u_bednetmx_spring.spring_mtrl_cost AS spring_mtrl_cost
  1544. ,u_bednetmx_spring.spring_hr_cost AS spring_hr_cost
  1545. ,u_bednetmx_spring.spring_mtrl_cost_replace_formula AS spring_mtrl_cost_replace_formula
  1546. ,u_bednetmx_spring.spring_hr_cost_replace_formula AS spring_hr_cost_replace_formula
  1547. ,u_bednetmx_spring.spring_weight_replace_formula AS spring_weight_replace_formula
  1548. FROM u_bednetmx_spring
  1549. INNER JOIN u_bednetmx ON u_bednetmx.bednetmxid = u_bednetmx_spring.bednetmxid";
  1550. DbSqlHelper.SelectJoin(cmd,selectStr, "u_bednetmx.bednetid = @bednetid",new Dictionary<string, object>() { { "@bednetid",bednetid } }, "bednetmx_partid",outputFields,0,0,springList);
  1551. return springList;
  1552. }
  1553. public List<u_bednetmx_mtrl> GetBedNetMxMtrlList(int bednetid)
  1554. {
  1555. var mxList = new List<u_bednetmx_mtrl>();
  1556. var outputFields = @"bednetmtrlid,bednetid,formulakind,formula,mtrlid,price,gram_weight,cloth_width,if_inputqty,qty,costamt,if_success,replace_formula,priceunit,shrinkage";
  1557. var selectStr = @"SELECT u_bednetmx_mtrl.bednetmtrlid AS bednetmtrlid
  1558. ,u_bednetmx_mtrl.bednetid AS bednetid
  1559. ,u_bednetmx_mtrl.formulakind AS formulakind
  1560. ,u_bednetmx_mtrl.formula AS formula
  1561. ,u_bednetmx_mtrl.mtrlid
  1562. ,u_bednetmx_mtrl.price
  1563. ,u_bednetmx_mtrl.gram_weight
  1564. ,u_bednetmx_mtrl.cloth_width
  1565. ,u_bednetmx_mtrl.if_inputqty
  1566. ,u_bednetmx_mtrl.qty
  1567. ,u_bednetmx_mtrl.costamt
  1568. ,u_bednetmx_mtrl.if_success
  1569. ,u_bednetmx_mtrl.replace_formula
  1570. ,u_bednetmx_mtrl.priceunit
  1571. ,u_bednetmx_mtrl.shrinkage
  1572. FROM u_bednetmx_mtrl";
  1573. DbSqlHelper.SelectJoin(cmd, selectStr, "u_bednetmx_mtrl.bednetid = @bednetid", new Dictionary<string, object>() { { "@bednetid", bednetid } }, "bednetmtrlid", outputFields, 0, 0, mxList);
  1574. return mxList;
  1575. }
  1576. public List<u_bednetmx> GetBedNetMxList(int bednetid)
  1577. {
  1578. var mxList = new List<u_bednetmx>();
  1579. var outputFields = @"bednetmxid,bednetid,spring_qty_width,spring_qty_length,bednet_height,wire_mtrlid,springid,if_part,if_15strip,if_pocket_around,
  1580. pocket_around_springid,pocket_around_row,pocket_around_wire_price,pocket_around_spring_cost,pocket_around_fabrics_cost,
  1581. if_hard_around,hard_around_springid,hard_around_row,hard_around_wire_price,hard_around_mtrl_cost,hard_around_hr_cost,
  1582. fabrics1_mtrlid,fabrics1_price,fabrics1_mtrl_cost,fabrics2_mtrlid,fabrics2_price,fabrics2_mtrl_cost,if_side_iron,
  1583. side_iron_qty,side_iron_mtrl_cost,side_iron_hr_cost,pocket_around_spring_cost_replace_formula,pocket_around_fabrics_cost_replace_formula,
  1584. hard_around_mtrl_cost_replace_formula,hard_around_hr_cost_replace_formula,fabrics1_mtrl_cost_replace_formula,
  1585. fabrics2_mtrl_cost_replace_formula,side_iron_mtrl_cost_replace_formula,side_iron_hr_cost_replace_formula,
  1586. cnail_mtrl_cost_replace_formula,cnail_mtrl_cost,cnail_hr_cost_replace_formula,cnail_hr_cost,
  1587. glue_mtrl_cost_replace_formula,glue_mtrl_cost,spring_mtrl_cost,spring_hr_cost,spring_mtrl_cost_replace_formula,
  1588. spring_hr_cost_replace_formula,if_show,spring_weight_replace_formula";
  1589. var selectStr = @"SELECT bednetmxid
  1590. ,bednetid
  1591. ,spring_qty_width
  1592. ,spring_qty_length
  1593. ,bednet_height
  1594. ,wire_mtrlid
  1595. ,springid
  1596. ,if_part
  1597. ,if_15strip
  1598. ,if_pocket_around
  1599. ,pocket_around_springid
  1600. ,pocket_around_row
  1601. ,pocket_around_wire_price
  1602. ,pocket_around_spring_cost
  1603. ,pocket_around_fabrics_cost
  1604. ,if_hard_around
  1605. ,hard_around_springid
  1606. ,hard_around_row
  1607. ,hard_around_wire_price
  1608. ,hard_around_mtrl_cost
  1609. ,hard_around_hr_cost
  1610. ,fabrics1_mtrlid
  1611. ,fabrics1_price
  1612. ,fabrics1_mtrl_cost
  1613. ,fabrics2_mtrlid
  1614. ,fabrics2_price
  1615. ,fabrics2_mtrl_cost
  1616. ,if_side_iron
  1617. ,side_iron_qty
  1618. ,side_iron_mtrl_cost
  1619. ,side_iron_hr_cost
  1620. ,pocket_around_spring_cost_replace_formula
  1621. ,pocket_around_fabrics_cost_replace_formula
  1622. ,hard_around_mtrl_cost_replace_formula
  1623. ,hard_around_hr_cost_replace_formula
  1624. ,fabrics1_mtrl_cost_replace_formula
  1625. ,fabrics2_mtrl_cost_replace_formula
  1626. ,side_iron_mtrl_cost_replace_formula
  1627. ,side_iron_hr_cost_replace_formula
  1628. ,cnail_mtrl_cost_replace_formula
  1629. ,cnail_mtrl_cost
  1630. ,cnail_hr_cost_replace_formula
  1631. ,cnail_hr_cost
  1632. ,glue_mtrl_cost_replace_formula
  1633. ,glue_mtrl_cost
  1634. ,spring_mtrl_cost
  1635. ,spring_hr_cost
  1636. ,spring_mtrl_cost_replace_formula
  1637. ,spring_hr_cost_replace_formula
  1638. ,1 AS if_show
  1639. ,spring_weight_replace_formula
  1640. FROM u_bednetmx";
  1641. DbSqlHelper.SelectJoin(cmd, selectStr, "u_bednetmx.bednetid = @bednetid", new Dictionary<string, object>() { { "@bednetid", bednetid } }, "bednetmxid", outputFields, 0, 0, mxList);
  1642. return mxList;
  1643. }
  1644. public void SaveBedNet(u_bednet bednet, List<u_bednetmx> mxlist, List<u_bednetmx_spring> springList)
  1645. {
  1646. var dtNow = DateTime.Now;
  1647. var fields = @"deptid,bednettypeid,mattress_width,mattress_length,mattress_height,if_doublenet,if_doublespring,snake_wire_diameter,
  1648. snake_wire_mtrl_formula,snake_wire_mtrl_cost,pocket_around_spring_formula,pocket_around_spring_cost,
  1649. pocket_around_fabrics_formula,pocket_around_fabrics_cost,hard_around_mtrl_formula,hard_around_mtrl_cost,
  1650. hard_around_hr_formula,hard_around_hr_cost,spring_mtrl_cost,spring_hr_cost,glue_price,glue_mtrl_formula,
  1651. glue_mtrl_cost,fabrics1_mtrl_formula,fabrics1_mtrl_cost,fabrics2_mtrl_formula,fabrics2_mtrl_cost,
  1652. if_side_iron,side_iron_lossrate,side_iron_price,side_iron_mtrl_formula,side_iron_mtrl_cost,side_iron_hr_formula,
  1653. side_iron_hr_cost,cnail_price,cnail_mtrl_formula,cnail_mtrl_cost,cnail_hr_formula,cnail_hr_cost,sponge_mtrlid,
  1654. sponge_thickness,sponge_price,sponge_mtrl_formula,sponge_mtrl_cost,sponge_hr_formula,sponge_hr_cost,edge_mtrlid,
  1655. edge_price,edge_mtrl_formula,edge_mtrl_cost,edge_hr_formula,edge_hr_cost,fork_qty,fork_price,fork_mtrl_formula,
  1656. fork_mtrl_cost,fork_hr_formula,fork_hr_cost,if_rsORwa,rsORwa_price,rsORwa_mtrl_formula,rsORwa_mtrl_cost,rsORwa_hr_formula,
  1657. rsORwa_hr_cost,if_sponge_drilling,sponge_drilling_hr_formula,sponge_drilling_hr_cost,total_hr_cost,total_mtrl_cost,
  1658. total_fees_cost,total_cost,createtime,createby,bednetname,spring_mtrl_formula,spring_hr_formula,
  1659. sponge_mtrl_cost_replace_formula,sponge_hr_cost_replace_formula,edge_mtrl_cost_replace_formula,edge_hr_cost_replace_formula,
  1660. fork_mtrl_cost_replace_formula,fork_hr_cost_replace_formula,rsORwa_mtrl_cost_replace_formula,rsORwa_hr_cost_replace_formula,
  1661. sponge_drilling_hr_cost_replace_formula,snake_wire_mtrl_cost_replace_formula,taxrate,taxes,commissionrate,commission,fob,
  1662. profitrate,nottax_factory_cost,nottax_dept_cost,dept_cost,foreign_cost,extras_cost,dept_profitrate,moneyrate,temp_flag,
  1663. felt_mtrlid,felt_qty,felt_price,felt_dscrp,felt_mtrl_formula,felt_mtrl_cost,felt_hr_formula,felt_hr_cost,
  1664. felt_mtrl_cost_replace_formula,felt_hr_cost_replace_formula,extras_cost_dscrp,iffork,ifsaleout,autotype,
  1665. felt_mtrl_x_cost,felt_hr_x_cost,felt_x_qty,felt_mtrl_x_cost_replace_formula,felt_hr_x_cost_replace_formula,
  1666. felt_x_mtrlid,sale_point,packtype,packqty,other_rate,transport_type,packmtrl,packet_mtrl_formula,
  1667. packet_hr_formula,packet_mtrl_cost,packet_hr_cost,packet_mtrl_cost_replace_formula,packet_hr_cost_replace_formula,
  1668. sponge_height,edge_height,sponge_tc_thickness,sponge_tc_height,sponge_tc_mtrlid,sponge_mtrl_tc_formula,
  1669. sponge_mtrl_tc_cost,sponge_mtrl_tc_cost_replace_formula,duo_qv_str,spring_weight_formula,side_iron_weight_formula,
  1670. hard_around_weight_formula,fabrics1_weight_formula,fabrics2_weight_formula,felt_weight_formula,cnail_weight_formula,
  1671. sponge_weight_formula,sponge_weight_tc_formula,edge_weight_formula,fork_weight_formula,spring_weight_replace_formula,
  1672. side_iron_weight_replace_formula,hard_around_weight_replace_formula,fabrics1_weight_replace_formula,
  1673. fabrics2_weight_replace_formula,felt_weight_replace_formula,cnail_weight_replace_formula,sponge_weight_replace_formula,
  1674. sponge_weight_tc_replace_formula,edge_weight_replace_formula,fork_weight_replace_formula,spring_weight_qty,
  1675. side_iron_weight_qty,hard_around_weight_qty,fabrics1_weight_qty,fabrics2_weight_qty,felt_weight_qty,cnail_weight_qty,
  1676. sponge_weight_qty,sponge_weight_tc_qty,edge_weight_qty,fork_weight_qty,sum_weight,if_jb";
  1677. var fieldsMx = @"bednetmxid,bednetid,spring_qty_width,spring_qty_length,bednet_height,wire_mtrlid,springid,if_part,if_15strip,
  1678. if_pocket_around,pocket_around_springid,pocket_around_row,pocket_around_wire_price,pocket_around_spring_cost,
  1679. pocket_around_fabrics_cost,if_hard_around,hard_around_springid,hard_around_row,hard_around_wire_price,
  1680. hard_around_mtrl_cost,hard_around_hr_cost,fabrics1_mtrlid,fabrics1_price,fabrics1_mtrl_cost,fabrics2_mtrlid,
  1681. fabrics2_price,fabrics2_mtrl_cost,if_side_iron,side_iron_qty,side_iron_mtrl_cost,side_iron_hr_cost,
  1682. pocket_around_spring_cost_replace_formula,pocket_around_fabrics_cost_replace_formula,hard_around_mtrl_cost_replace_formula,
  1683. hard_around_hr_cost_replace_formula,fabrics1_mtrl_cost_replace_formula,fabrics2_mtrl_cost_replace_formula,
  1684. side_iron_mtrl_cost_replace_formula,side_iron_hr_cost_replace_formula,cnail_mtrl_cost_replace_formula,cnail_mtrl_cost,
  1685. cnail_hr_cost_replace_formula,cnail_hr_cost,glue_mtrl_cost_replace_formula,glue_mtrl_cost,spring_mtrl_cost,spring_hr_cost,
  1686. spring_mtrl_cost_replace_formula,spring_hr_cost_replace_formula,spring_weight_replace_formula";
  1687. var fieldsMx_spring = @"bednetmx_partid,bednetmxid,springid,spring_qty_width,spring_qty_length,fabrics1_mtrl_cost,spring_mtrl_cost,
  1688. spring_hr_cost,spring_mtrl_cost_replace_formula,spring_hr_cost_replace_formula,spring_weight_replace_formula";
  1689. if (bednet.bednetid <= 0)
  1690. {
  1691. //新建
  1692. fields += ",bednetid,bednetcode";
  1693. bednet.bednetid = BllHelper.GetID(cmd, "u_bednet");
  1694. bednet.createtime = dtNow;
  1695. bednet.createby = context.tokendata.username;
  1696. var nettype = new u_bednet_type() { bednettypeid = bednet.bednettypeid };
  1697. DbSqlHelper.SelectOne(cmd, nettype, "typecode");
  1698. // 编号-年月日+流水
  1699. bednet.bednetcode = $"{nettype.typecode}-{dtNow.ToString("yyyyMMdd")}{(bednet.bednetid.Value % 10000).ToString("D4")}";
  1700. DbSqlHelper.Insert(cmd, "u_bednet", null, bednet, fields);
  1701. }
  1702. else
  1703. {
  1704. //修改
  1705. foreach (var mx in mxlist)
  1706. {
  1707. cmd.CommandText = @"DELETE FROM u_bednetmx_spring WHERE bednetmxid = @bednetmxid";
  1708. cmd.Parameters.Clear();
  1709. cmd.Parameters.AddWithValue("@bednetmxid", mx.bednetmxid);
  1710. cmd.ExecuteNonQuery();
  1711. }
  1712. cmd.CommandText = @"DELETE FROM u_bednetmx WHERE bednetid = @bednetid";
  1713. cmd.Parameters.Clear();
  1714. cmd.Parameters.AddWithValue("@bednetid", bednet.bednetid);
  1715. cmd.ExecuteNonQuery();
  1716. DbSqlHelper.Update(cmd, "u_bednet", null, bednet, "bednetid", fields);
  1717. }
  1718. foreach (var mx in mxlist)
  1719. {
  1720. mx.bednetid = bednet.bednetid;
  1721. mx.bednetmxid = BllHelper.GetID(cmd, "u_bednetmx");
  1722. DbSqlHelper.Insert(cmd, "u_bednetmx", null, mx, fieldsMx);
  1723. if (springList != null && springList.Any())
  1724. {
  1725. foreach (var spring in springList)
  1726. {
  1727. spring.bednetmx_partid = bednet.bednetid;
  1728. spring.bednetmxid = BllHelper.GetID(cmd, "u_bednetmx_spring");
  1729. DbSqlHelper.Insert(cmd, "u_bednetmx_spring", null, spring, fieldsMx_spring);
  1730. }
  1731. }
  1732. }
  1733. var hisprice = new u_his_price
  1734. {
  1735. bednetid_mattressid = bednet.bednetid,
  1736. typeid = 0,
  1737. cmpdate = dtNow,
  1738. cmpemp = context.tokendata.username,
  1739. nottax_dept_cost = 0,
  1740. dept_cost = 0,
  1741. foreign_cost = 0
  1742. };
  1743. var fieldsHs = "bednetid_mattressid, typeid, cmpdate, cmpemp, nottax_dept_cost, dept_cost, foreign_cost";
  1744. DbSqlHelper.Insert(cmd, "u_his_price", null, hisprice, fieldsHs);
  1745. }
  1746. }
  1747. }