BedNetHelper.cs 82 KB

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