BedNetHelper.cs 82 KB

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