BedNetHelper.cs 125 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466
  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.Runtime.InteropServices;
  13. using System.Text;
  14. using System.Text.RegularExpressions;
  15. using System.Threading.Tasks;
  16. namespace JLHHJSvr.Helper
  17. {
  18. internal class BedNetHelper : HelperBase
  19. {
  20. private Dictionary<string, object> replacements = new Dictionary<string, object>();
  21. /// <summary>
  22. /// 默认展示公式
  23. /// </summary>
  24. private Dictionary<string, formulaItem> formula_replacements = new Dictionary<string, formulaItem>();
  25. /// <summary>
  26. /// 隐藏公式
  27. /// </summary>
  28. private Dictionary<string, formulaItem> formula_replacements_hide = new Dictionary<string, formulaItem>();
  29. /// <summary>
  30. /// 详细展示公式
  31. /// </summary>
  32. private Dictionary<string, formulaItem> formula_replacements_mx = new Dictionary<string, formulaItem>();
  33. /// <summary>
  34. /// 重量展示公式
  35. /// </summary>
  36. private Dictionary<string, formulaItem> formula_replacements_weight = new Dictionary<string, formulaItem>();
  37. public sealed class formulaItem
  38. {
  39. public string value { get; set; }
  40. public int? ifnotreplace { get; set; }
  41. }
  42. public List<replacement> Replacements
  43. {
  44. get
  45. {
  46. var res = new List<replacement>();
  47. foreach (var item in replacements)
  48. {
  49. res.Add(new replacement { label = item.Key, value = item.Value, type = 0 });
  50. }
  51. return res;
  52. }
  53. }
  54. public List<replacement> FormulaReplacements
  55. {
  56. get {
  57. var res = new List<replacement>();
  58. foreach (var item in formula_replacements)
  59. {
  60. res.Add(new replacement { label = item.Key, value = item.Value.value, type = 0, ifnotreplace = item.Value.ifnotreplace});
  61. }
  62. foreach (var item in formula_replacements_hide)
  63. {
  64. res.Add(new replacement { label = item.Key, value = item.Value.value, type = 1, ifnotreplace = item.Value.ifnotreplace });
  65. }
  66. foreach (var item in formula_replacements_mx)
  67. {
  68. res.Add(new replacement { label = item.Key, value = item.Value.value, type = 2, ifnotreplace = item.Value.ifnotreplace });
  69. }
  70. foreach (var item in formula_replacements_weight)
  71. {
  72. res.Add(new replacement { label = item.Key, value = item.Value.value, type = 3, ifnotreplace = item.Value.ifnotreplace });
  73. }
  74. return res;
  75. }
  76. }
  77. public void CalCulateFormula(u_bednet bednet, List<u_bednetmx> mxlist, List<u_bednetmx_spring> springList)
  78. {
  79. InitBedNet(bednet);
  80. InitReplaceMents(bednet);
  81. CulcalateCost(bednet, mxlist, springList);
  82. CulcalateWeight(bednet, mxlist, springList);
  83. }
  84. private void CulcalateCost(u_bednet bednet, List<u_bednetmx> mxlist, List<u_bednetmx_spring> springList)
  85. {
  86. bednet.spring_mtrl_cost = 0;
  87. bednet.spring_hr_cost = 0;
  88. bednet.snake_wire_mtrl_cost = 0;
  89. bednet.pocket_around_spring_cost = 0;
  90. bednet.pocket_around_fabrics_cost = 0;
  91. bednet.hard_around_mtrl_cost = 0;
  92. bednet.hard_around_hr_cost = 0;
  93. bednet.fabrics1_mtrl_cost = 0;
  94. bednet.glue_mtrl_cost = 0;
  95. bednet.fabrics2_mtrl_cost = 0;
  96. bednet.side_iron_hr_cost = 0;
  97. bednet.side_iron_mtrl_cost = 0;
  98. bednet.cnail_mtrl_cost = 0;
  99. bednet.cnail_hr_cost = 0;
  100. bednet.sponge_mtrl_cost = 0;
  101. bednet.sponge_hr_cost = 0;
  102. bednet.sponge_mtrl_tc_cost = 0;
  103. bednet.edge_mtrl_cost = 0;
  104. bednet.edge_hr_cost = 0;
  105. bednet.fork_mtrl_cost = 0;
  106. bednet.fork_hr_cost = 0;
  107. bednet.rsorwa_mtrl_cost = 0;
  108. bednet.rsorwa_hr_cost = 0;
  109. bednet.sponge_drilling_hr_cost = 0;
  110. bednet.felt_mtrl_cost = 0;
  111. bednet.felt_mtrl_x_cost = 0;
  112. bednet.felt_hr_cost = 0;
  113. bednet.felt_hr_x_cost = 0;
  114. bednet.packet_mtrl_cost = 0;
  115. bednet.packet_hr_cost = 0;
  116. foreach (var mx in mxlist)
  117. {
  118. var spring = new u_spring() { springid = mx.springid };
  119. DbSqlHelper.SelectOne(cmd, spring, "line_diameter,gram_weight,height,center_diameter");
  120. // 处理相同公式部分
  121. InitMxReplaceMents(bednet, mx, spring);
  122. //计算 弹簧材料总成本
  123. #region 计算 弹簧材料总成本 开始
  124. if (!string.IsNullOrEmpty(bednet.spring_mtrl_formula))
  125. {
  126. mx.spring_mtrl_cost_replace_formula = bednet.spring_mtrl_formula;
  127. if (mx.if_part == 0)
  128. {
  129. //单分区
  130. //考虑 四周加硬和四周口袋 扣减 排列数情况
  131. if (mx.if_hard_around == 1)
  132. {
  133. decimal hard_around_row = mx.hard_around_row.Value;
  134. if (bednet.typename.IndexOf("袋装", StringComparison.Ordinal) >= 0) hard_around_row *= 2;
  135. mx.spring_mtrl_cost_replace_formula = mx.spring_mtrl_cost_replace_formula.Replace("【弹簧排列个数-宽】", $"(【弹簧排列个数-宽】 - {hard_around_row})");
  136. mx.spring_mtrl_cost_replace_formula = mx.spring_mtrl_cost_replace_formula.Replace("【弹簧计算个数(宽)】", $"(【弹簧计算个数(宽)】 - {hard_around_row})");
  137. mx.spring_mtrl_cost_replace_formula = mx.spring_mtrl_cost_replace_formula.Replace("【弹簧排列个数-长】", $"(【弹簧排列个数-长】 - {hard_around_row})");
  138. mx.spring_mtrl_cost_replace_formula = mx.spring_mtrl_cost_replace_formula.Replace("【弹簧计算个数(长)】", $"(【弹簧计算个数(长)】 - {hard_around_row})");
  139. }
  140. if (mx.if_pocket_around == 1)
  141. {
  142. decimal pocket_around_row = mx.pocket_around_row.Value;
  143. if (bednet.typename.IndexOf("袋装", StringComparison.Ordinal) >= 0) pocket_around_row *= 2;
  144. mx.spring_mtrl_cost_replace_formula = mx.spring_mtrl_cost_replace_formula.Replace("【弹簧排列个数-宽】", $"(【弹簧排列个数-宽】 - {pocket_around_row})");
  145. mx.spring_mtrl_cost_replace_formula = mx.spring_mtrl_cost_replace_formula.Replace("【弹簧计算个数(宽)】", $"(【弹簧计算个数(宽)】 - {pocket_around_row})");
  146. mx.spring_mtrl_cost_replace_formula = mx.spring_mtrl_cost_replace_formula.Replace("【弹簧排列个数-长】", $"(【弹簧排列个数-长】 - {pocket_around_row})");
  147. mx.spring_mtrl_cost_replace_formula = mx.spring_mtrl_cost_replace_formula.Replace("【弹簧计算个数(长)】", $"(【弹簧计算个数(长)】 - {pocket_around_row})");
  148. }
  149. mx.spring_mtrl_cost = Calculate(mx.spring_mtrl_cost_replace_formula, "弹簧材料总成本").DecimalValue;
  150. bednet.spring_mtrl_cost += mx.spring_mtrl_cost;
  151. }
  152. else
  153. {
  154. mx.spring_mtrl_cost = 0;
  155. //多分区
  156. foreach (var springItem in springList)
  157. {
  158. springItem.spring_mtrl_cost_replace_formula = bednet.spring_mtrl_formula;
  159. CalSpringMtrlCol(bednet, mx, springItem);
  160. springItem.spring_mtrl_cost = Calculate(springItem.spring_mtrl_cost_replace_formula, "弹簧材料总成本").DecimalValue;
  161. mx.spring_mtrl_cost += springItem.spring_mtrl_cost;
  162. bednet.spring_mtrl_cost += springItem.spring_mtrl_cost;
  163. }
  164. }
  165. AddKeyValue("弹簧排列个数-宽", mx.spring_qty_width);
  166. AddKeyValue("弹簧排列个数-长", mx.spring_qty_length);
  167. AddKeyValue("弹簧计算个数(宽)", mx.spring_qty_width);
  168. AddKeyValue("弹簧计算个数(长)", mx.spring_qty_length);
  169. AddKeyValue("弹簧材料总成本", bednet.spring_mtrl_cost);
  170. AddFormulaMxKeyValue("【弹簧材料总成本】", bednet.spring_mtrl_formula, true, 1);
  171. }
  172. #endregion 计算 弹簧材料总成本 结束
  173. #region 计算 弹簧人工总成本 开始
  174. if (!string.IsNullOrEmpty(bednet.spring_hr_formula))
  175. {
  176. mx.spring_hr_cost_replace_formula = bednet.spring_hr_formula;
  177. mx.spring_hr_cost = Calculate(mx.spring_hr_cost_replace_formula, "弹簧总人工成本").DecimalValue;
  178. bednet.spring_hr_cost += mx.spring_hr_cost;
  179. AddKeyValue("弹簧总人工成本", bednet.spring_hr_cost);
  180. AddFormulaMxKeyValue("【弹簧总人工成本】", bednet.spring_hr_formula, true, 1);
  181. }
  182. #endregion 计算 弹簧人工总成本 结束
  183. #region 计算 蛇线材料成本 开始
  184. if (!string.IsNullOrEmpty(bednet.spring_hr_formula))
  185. {
  186. bednet.snake_wire_mtrl_cost_replace_formula = bednet.snake_wire_mtrl_formula;
  187. CalSnakeCol(bednet,spring);
  188. bednet.snake_wire_mtrl_cost += Calculate(bednet.snake_wire_mtrl_cost_replace_formula, "蛇线材料成本").DecimalValue;
  189. AddKeyValue("蛇线材料成本", bednet.snake_wire_mtrl_cost);
  190. AddFormulaMxKeyValue("【蛇线材料成本】", bednet.snake_wire_mtrl_formula);
  191. }
  192. #endregion 计算 蛇线材料成本 结束
  193. #region 计算 四周口袋弹簧成本 开始
  194. if (!string.IsNullOrEmpty(bednet.pocket_around_spring_formula) && mx.if_pocket_around > 0)
  195. {
  196. mx.pocket_around_spring_cost_replace_formula = bednet.pocket_around_spring_formula;
  197. mx.pocket_around_spring_cost = Calculate(mx.pocket_around_spring_cost_replace_formula, "四周口袋弹簧成本").DecimalValue;
  198. bednet.pocket_around_spring_cost += mx.pocket_around_spring_cost;
  199. AddKeyValue("四周口袋弹簧成本", bednet.pocket_around_spring_cost);
  200. AddFormulaMxKeyValue("【四周口袋弹簧成本】", bednet.pocket_around_spring_formula);
  201. }
  202. #endregion 计算 四周口袋弹簧成本 结束
  203. #region 计算 四周口袋无纺布成本 开始
  204. if (!string.IsNullOrEmpty(bednet.pocket_around_fabrics_formula) && mx.if_pocket_around > 0)
  205. {
  206. mx.pocket_around_fabrics_cost_replace_formula = bednet.pocket_around_fabrics_formula;
  207. mx.pocket_around_fabrics_cost = Calculate(mx.pocket_around_fabrics_cost_replace_formula, "四周口袋无纺布成本").DecimalValue;
  208. bednet.pocket_around_fabrics_cost += mx.pocket_around_fabrics_cost;
  209. AddKeyValue("四周口袋无纺布成本", bednet.pocket_around_fabrics_cost);
  210. AddFormulaMxKeyValue("【四周口袋无纺布成本】", bednet.pocket_around_fabrics_formula);
  211. }
  212. #endregion 计算 四周口袋无纺布成本 结束
  213. #region 计算 四周加硬材料成本 开始
  214. if (!string.IsNullOrEmpty(bednet.hard_around_mtrl_formula) && mx.if_hard_around > 0)
  215. {
  216. mx.hard_around_mtrl_cost_replace_formula = bednet.hard_around_mtrl_formula;
  217. mx.hard_around_mtrl_cost = Calculate(mx.hard_around_mtrl_cost_replace_formula, "四周加硬材料成本").DecimalValue;
  218. bednet.hard_around_mtrl_cost += mx.hard_around_mtrl_cost;
  219. AddKeyValue("四周加硬材料成本", bednet.hard_around_mtrl_cost);
  220. AddFormulaMxKeyValue("【四周加硬材料成本】", bednet.hard_around_mtrl_formula);
  221. }
  222. #endregion 计算 四周加硬材料成本 结束
  223. #region 计算 四周加硬人力成本 开始
  224. if (!string.IsNullOrEmpty(bednet.hard_around_hr_formula) && mx.if_hard_around > 0)
  225. {
  226. mx.hard_around_hr_cost_replace_formula = bednet.hard_around_hr_formula;
  227. mx.hard_around_hr_cost = Calculate(mx.hard_around_hr_cost_replace_formula, "四周加硬人力成本").DecimalValue;
  228. bednet.hard_around_hr_cost += mx.hard_around_hr_cost;
  229. AddKeyValue("四周加硬人力成本", bednet.hard_around_hr_cost);
  230. AddFormulaMxKeyValue("【四周加硬人力成本】", bednet.hard_around_hr_formula);
  231. }
  232. #endregion 计算 四周加硬人力成本 结束
  233. #region 计算 入袋无纺布材料成本 开始
  234. if (!string.IsNullOrEmpty(bednet.hard_around_hr_formula) && bednet.typename.IndexOf("袋装网") > -1 && mx.fabrics1_mtrlid > 0)
  235. {
  236. mx.fabrics1_mtrl_cost_replace_formula = bednet.fabrics1_mtrl_formula;
  237. CalSpringMtrlCol2(bednet, mx, springList, "入袋无纺布");
  238. mx.fabrics1_mtrl_cost = Calculate(mx.fabrics1_mtrl_cost_replace_formula, "入袋无纺布材料成本").DecimalValue;
  239. bednet.fabrics1_mtrl_cost += mx.fabrics1_mtrl_cost;
  240. AddKeyValue("入袋无纺布材料成本", bednet.fabrics1_mtrl_cost);
  241. AddFormulaMxKeyValue("【入袋无纺布材料成本】", bednet.fabrics1_mtrl_formula);
  242. }
  243. #endregion 计算 入袋无纺布材料成本 结束
  244. #region 计算 胶水材料成本 开始
  245. if (!string.IsNullOrEmpty(bednet.glue_mtrl_formula))
  246. {
  247. mx.glue_mtrl_cost_replace_formula = bednet.glue_mtrl_formula;
  248. bednet.glue_mtrl_cost += Calculate(mx.glue_mtrl_cost_replace_formula, "胶水材料成本").DecimalValue;
  249. AddKeyValue("胶水材料成本", bednet.glue_mtrl_cost);
  250. AddFormulaMxKeyValue("【胶水材料成本】", bednet.glue_mtrl_formula);
  251. }
  252. #endregion 计算 胶水材料成本 结束
  253. #region 计算 底面无纺布材料成本 开始
  254. if (!string.IsNullOrEmpty(bednet.hard_around_hr_formula) && bednet.typename.IndexOf("袋装网") > -1 && mx.fabrics2_mtrlid > 0)
  255. {
  256. mx.fabrics2_mtrl_cost_replace_formula = bednet.fabrics2_mtrl_formula;
  257. CalSpringMtrlCol2(bednet, mx, springList, "底面无纺布");
  258. mx.fabrics2_mtrl_cost = Calculate(mx.fabrics2_mtrl_cost_replace_formula, "底面无纺布材料成本").DecimalValue;
  259. bednet.fabrics2_mtrl_cost += mx.fabrics2_mtrl_cost;
  260. AddKeyValue("底面无纺布材料成本", bednet.fabrics2_mtrl_cost);
  261. AddFormulaMxKeyValue("【底面无纺布材料成本】", bednet.fabrics2_mtrl_formula);
  262. }
  263. #endregion 计算 底面无纺布材料成本 结束
  264. #region 计算 边铁人力成本 开始
  265. if (!string.IsNullOrEmpty(bednet.side_iron_hr_formula) && bednet.if_side_iron == 1 && mx.if_side_iron > 0)
  266. {
  267. mx.side_iron_hr_cost_replace_formula = bednet.side_iron_hr_formula;
  268. mx.side_iron_hr_cost = Calculate(mx.side_iron_hr_cost_replace_formula, "边铁人力成本").DecimalValue;
  269. bednet.side_iron_hr_cost += mx.side_iron_hr_cost;
  270. AddKeyValue("边铁人力成本", bednet.side_iron_hr_cost);
  271. AddFormulaMxKeyValue("【边铁人力成本】", bednet.side_iron_hr_formula);
  272. }
  273. #endregion 计算 边铁人力成本 结束
  274. #region 计算 边铁材料成本 开始
  275. if (!string.IsNullOrEmpty(bednet.side_iron_mtrl_formula) && bednet.if_side_iron == 1 && mx.if_side_iron > 0)
  276. {
  277. mx.side_iron_mtrl_cost_replace_formula = bednet.side_iron_mtrl_formula;
  278. mx.side_iron_mtrl_cost = Calculate(mx.side_iron_mtrl_cost_replace_formula, "边铁材料成本").DecimalValue;
  279. bednet.side_iron_mtrl_cost += mx.side_iron_mtrl_cost;
  280. AddKeyValue("边铁材料成本", bednet.side_iron_mtrl_cost);
  281. AddFormulaMxKeyValue("【边铁材料成本】", bednet.side_iron_mtrl_formula);
  282. }
  283. #endregion 计算 边铁材料成本 结束
  284. #region 计算 C钉/夹码材料 开始
  285. if (!string.IsNullOrEmpty(bednet.cnail_mtrl_formula))
  286. {
  287. mx.cnail_mtrl_cost_replace_formula = bednet.cnail_mtrl_formula;
  288. mx.cnail_mtrl_cost = Calculate(mx.cnail_mtrl_cost_replace_formula, "C钉/夹码材料成本").DecimalValue;
  289. bednet.cnail_mtrl_cost += mx.cnail_mtrl_cost;
  290. AddKeyValue("C钉/夹码材料成本", bednet.cnail_mtrl_cost);
  291. AddFormulaMxKeyValue("【C钉/夹码材料成本】", bednet.cnail_mtrl_formula);
  292. }
  293. #endregion 计算 C钉/夹码材料 结束
  294. #region 计算 C钉/夹码人力成本 开始
  295. if (!string.IsNullOrEmpty(bednet.cnail_hr_formula))
  296. {
  297. mx.cnail_hr_cost_replace_formula = bednet.cnail_hr_formula;
  298. mx.cnail_hr_cost = Calculate(mx.cnail_hr_cost_replace_formula, "C钉/夹码人力成本").DecimalValue;
  299. bednet.cnail_hr_cost += mx.cnail_hr_cost;
  300. AddKeyValue("C钉/夹码人力成本", bednet.cnail_hr_cost);
  301. AddFormulaMxKeyValue("【C钉/夹码人力成本】", bednet.cnail_hr_formula);
  302. }
  303. #endregion 计算 C钉/夹码人力成本 结束
  304. #region 计算 海绵包边材料成本 开始
  305. if (!string.IsNullOrEmpty(bednet.sponge_mtrl_formula) && bednet.sponge_mtrlid > 0)
  306. {
  307. bednet.sponge_mtrl_cost_replace_formula = bednet.sponge_mtrl_formula;
  308. CalSpringMtrlCol2(bednet, mx, springList, "海绵包边");
  309. bednet.sponge_mtrl_cost += Calculate(bednet.sponge_mtrl_cost_replace_formula, "海绵包边材料成本").DecimalValue;
  310. AddKeyValue("海绵包边材料成本", bednet.sponge_mtrl_cost);
  311. AddFormulaMxKeyValue("【海绵包边材料成本】", bednet.sponge_mtrl_formula);
  312. }
  313. #endregion 计算 海绵包边材料成本 结束
  314. #region 计算 海绵包边人力成本 开始
  315. if (!string.IsNullOrEmpty(bednet.sponge_hr_formula) && bednet.sponge_mtrlid > 0)
  316. {
  317. bednet.sponge_hr_cost_replace_formula = bednet.sponge_hr_formula;
  318. bednet.sponge_hr_cost += Calculate(bednet.sponge_hr_cost_replace_formula, "海绵包边人力成本").DecimalValue;
  319. AddKeyValue("海绵包边人力成本", bednet.sponge_hr_cost);
  320. AddFormulaMxKeyValue("【海绵包边人力成本】", bednet.sponge_hr_formula);
  321. }
  322. #endregion 计算 海绵包边人力成本 结束
  323. #region 计算 填充海绵成本 开始
  324. if (!string.IsNullOrEmpty(bednet.sponge_mtrl_tc_formula) && bednet.sponge_tc_mtrlid > 0)
  325. {
  326. bednet.sponge_mtrl_tc_cost_replace_formula = bednet.sponge_mtrl_tc_formula;
  327. CalSpringMtrlCol2(bednet, mx, springList, "填充海绵");
  328. bednet.sponge_mtrl_tc_cost += Calculate(bednet.sponge_mtrl_tc_cost_replace_formula, "填充海绵成本").DecimalValue;
  329. AddKeyValue("填充海绵成本", bednet.sponge_mtrl_tc_cost);
  330. AddFormulaMxKeyValue("【填充海绵成本】", bednet.sponge_mtrl_tc_formula);
  331. }
  332. #endregion 计算 填充海绵成本 结束
  333. #region 计算 封边材料成本 开始
  334. if (!string.IsNullOrEmpty(bednet.edge_mtrl_formula) && bednet.edge_mtrlid > 0)
  335. {
  336. bednet.edge_mtrl_cost_replace_formula = bednet.edge_mtrl_formula;
  337. CalSpringMtrlCol2(bednet, mx, springList, "封边");
  338. bednet.edge_mtrl_cost += Calculate(bednet.edge_mtrl_cost_replace_formula, "封边材料成本").DecimalValue;
  339. AddKeyValue("封边材料成本", bednet.edge_mtrl_cost);
  340. AddFormulaMxKeyValue("【封边材料成本】", bednet.edge_mtrl_formula);
  341. }
  342. #endregion 计算 封边材料成本 结束
  343. #region 计算 封边人力成本 开始
  344. if (!string.IsNullOrEmpty(bednet.edge_hr_formula) && bednet.edge_mtrlid > 0)
  345. {
  346. bednet.edge_hr_cost_replace_formula = bednet.edge_hr_formula;
  347. bednet.edge_hr_cost += Calculate(bednet.edge_hr_cost_replace_formula, "封边人力成本").DecimalValue;
  348. AddKeyValue("封边人力成本", bednet.edge_hr_cost);
  349. AddFormulaMxKeyValue("【封边人力成本】", bednet.edge_hr_formula);
  350. }
  351. #endregion 计算 封边人力成本 结束
  352. #region 计算 弹叉材料成本 开始
  353. if (!string.IsNullOrEmpty(bednet.fork_mtrl_formula) && bednet.fork_qty > 0)
  354. {
  355. bednet.fork_mtrl_cost_replace_formula = bednet.fork_mtrl_formula;
  356. bednet.fork_mtrl_cost += Calculate(bednet.fork_mtrl_cost_replace_formula, "弹叉材料成本").DecimalValue;
  357. AddKeyValue("弹叉材料成本", bednet.fork_mtrl_cost);
  358. AddFormulaMxKeyValue("【弹叉材料成本】", bednet.fork_mtrl_formula);
  359. }
  360. #endregion 计算 弹叉材料成本 结束
  361. #region 计算 弹叉人力成本 开始
  362. if (!string.IsNullOrEmpty(bednet.fork_hr_formula) && bednet.fork_qty > 0)
  363. {
  364. bednet.fork_hr_cost_replace_formula = bednet.fork_hr_formula;
  365. bednet.fork_hr_cost += Calculate(bednet.fork_hr_cost_replace_formula, "弹叉人力成本").DecimalValue;
  366. AddKeyValue("弹叉人力成本", bednet.fork_hr_cost);
  367. AddFormulaMxKeyValue("【弹叉人力成本】", bednet.fork_hr_formula);
  368. }
  369. #endregion 计算 弹叉人力成本 结束
  370. #region 计算 胶条/包角材料成本 开始
  371. if (!string.IsNullOrEmpty(bednet.rsorwa_mtrl_formula) && bednet.if_rsorwa == 1)
  372. {
  373. bednet.rsorwa_mtrl_cost_replace_formula = bednet.rsorwa_mtrl_formula;
  374. bednet.rsorwa_mtrl_cost += Calculate(bednet.rsorwa_mtrl_cost_replace_formula, "胶条/包角材料成本").DecimalValue;
  375. AddKeyValue("胶条/包角材料成本", bednet.rsorwa_mtrl_cost);
  376. AddFormulaMxKeyValue("【胶条/包角材料成本】", bednet.rsorwa_mtrl_formula);
  377. }
  378. #endregion 计算 胶条/包角材料成本 结束
  379. #region 计算 胶条/包角人力成本 开始
  380. if (!string.IsNullOrEmpty(bednet.rsorwa_hr_formula) && bednet.if_rsorwa == 1)
  381. {
  382. bednet.rsorwa_hr_cost_replace_formula = bednet.rsorwa_hr_formula;
  383. bednet.rsorwa_hr_cost += Calculate(bednet.rsorwa_hr_cost_replace_formula, "胶条/包角人力成本").DecimalValue;
  384. AddKeyValue("胶条/包角人力成本", bednet.rsorwa_hr_cost);
  385. AddFormulaMxKeyValue("【胶条/包角人力成本】", bednet.rsorwa_hr_formula);
  386. }
  387. #endregion 计算 胶条/包角人力成本 结束
  388. #region 计算 海绵打孔人力成本 开始
  389. if (!string.IsNullOrEmpty(bednet.sponge_drilling_hr_formula) && bednet.if_sponge_drilling == 1)
  390. {
  391. bednet.sponge_drilling_hr_cost_replace_formula = bednet.sponge_drilling_hr_formula;
  392. bednet.sponge_drilling_hr_cost += Calculate(bednet.sponge_drilling_hr_cost_replace_formula, "海绵打孔人力成本").DecimalValue;
  393. AddKeyValue("海绵打孔人力成本", bednet.sponge_drilling_hr_cost);
  394. AddFormulaMxKeyValue("【海绵打孔人力成本】", bednet.sponge_drilling_hr_formula);
  395. }
  396. #endregion 计算 海绵打孔人力成本 结束
  397. #region 计算 上垫层物料成本 开始
  398. if (!string.IsNullOrEmpty(bednet.felt_mtrl_formula) && bednet.felt_qty > 0)
  399. {
  400. bednet.felt_mtrl_cost_replace_formula = bednet.felt_mtrl_formula;
  401. CalSpringMtrlCol2(bednet, mx, springList, "上垫层");
  402. bednet.felt_mtrl_cost += Calculate(bednet.felt_mtrl_cost_replace_formula, "上垫层物料成本").DecimalValue;
  403. AddKeyValue("上垫层物料成本", bednet.felt_mtrl_cost);
  404. AddFormulaMxKeyValue("【上垫层物料成本】", bednet.felt_mtrl_formula);
  405. }
  406. #endregion 计算 上垫层物料成本 结束
  407. #region 计算 下垫层物料成本 开始
  408. if (!string.IsNullOrEmpty(bednet.felt_mtrl_formula) && bednet.felt_x_qty > 0)
  409. {
  410. bednet.felt_mtrl_x_cost_replace_formula = bednet.felt_mtrl_formula;
  411. CalSpringMtrlCol2(bednet, mx, springList, "下垫层");
  412. bednet.felt_mtrl_x_cost += Calculate(bednet.felt_mtrl_x_cost_replace_formula, "下垫层物料成本").DecimalValue;
  413. AddKeyValue("下垫层物料成本", bednet.felt_mtrl_x_cost);
  414. AddFormulaMxKeyValue("【下垫层物料成本】", bednet.felt_mtrl_formula);
  415. }
  416. #endregion 计算 下垫层物料成本 结束
  417. #region 计算 上垫层人力成本 开始
  418. if (!string.IsNullOrEmpty(bednet.felt_hr_formula) && bednet.felt_qty > 0)
  419. {
  420. bednet.felt_hr_cost_replace_formula = bednet.felt_hr_formula;
  421. bednet.felt_hr_cost += Calculate(bednet.felt_hr_cost_replace_formula, "上垫层人力成本").DecimalValue;
  422. AddKeyValue("上垫层人力成本", bednet.felt_hr_cost);
  423. AddFormulaMxKeyValue("【上垫层人力成本】", bednet.felt_hr_formula);
  424. }
  425. #endregion 计算 上垫层人力成本 结束
  426. #region 计算 下垫层人力成本 开始
  427. if (!string.IsNullOrEmpty(bednet.felt_hr_formula) && bednet.felt_x_qty > 0)
  428. {
  429. bednet.felt_hr_x_cost_replace_formula = bednet.felt_hr_formula;
  430. CalSpringMtrlCol2(bednet, mx, springList, "下垫层");
  431. bednet.felt_hr_x_cost += Calculate(bednet.felt_hr_x_cost_replace_formula, "下垫层人力成本").DecimalValue;
  432. AddKeyValue("下垫层人力成本", bednet.felt_hr_x_cost);
  433. AddFormulaMxKeyValue("【下垫层人力成本】", bednet.felt_hr_formula);
  434. }
  435. #endregion 计算 下垫层人力成本 结束
  436. #region 计算 包装总成本 开始
  437. if (!string.IsNullOrEmpty(bednet.packet_mtrl_formula) && !string.IsNullOrEmpty(bednet.packtype))
  438. {
  439. bednet.packet_mtrl_cost_replace_formula = bednet.packet_mtrl_formula;
  440. bool sqlCal = !string.IsNullOrEmpty(bednet.packet_mtrl_formula) && bednet.packet_mtrl_formula.Substring(0, 2) == "@@";
  441. bednet.packet_mtrl_cost_replace_formula = bednet.packet_mtrl_cost_replace_formula.Replace("@@", "");
  442. if(sqlCal) bednet.packet_mtrl_cost += Convert.ToDecimal(SqlCalculate(bednet.packet_mtrl_cost_replace_formula, "包装总成本"));
  443. else bednet.packet_mtrl_cost += Calculate(bednet.packet_mtrl_cost_replace_formula, "包装总成本").DecimalValue;
  444. AddKeyValue("包装总成本", bednet.packet_mtrl_cost);
  445. AddFormulaMxKeyValue("【包装总成本】", bednet.packet_mtrl_formula);
  446. }
  447. #endregion 计算 包装总成本 结束
  448. #region 计算 包装人工成本 开始
  449. if (!string.IsNullOrEmpty(bednet.packet_hr_formula) && !string.IsNullOrEmpty(bednet.packtype))
  450. {
  451. bednet.packet_hr_cost_replace_formula = bednet.packet_hr_formula;
  452. bool sqlCal = !string.IsNullOrEmpty(bednet.packet_hr_formula) && bednet.packet_hr_formula.Substring(0, 2) == "@@";
  453. bednet.packet_hr_cost_replace_formula = bednet.packet_hr_cost_replace_formula.Replace("@@", "");
  454. if (sqlCal) bednet.packet_hr_cost += Convert.ToDecimal(SqlCalculate(bednet.packet_hr_cost_replace_formula, "包装人工成本"));
  455. else bednet.packet_hr_cost += Calculate(bednet.packet_hr_cost_replace_formula, "包装人工成本").DecimalValue;
  456. AddKeyValue("包装人工成本", bednet.packet_hr_cost);
  457. AddFormulaMxKeyValue("【包装人工成本】", bednet.packet_hr_formula);
  458. }
  459. #endregion 计算 包装人工成本 结束
  460. //有外销的 工厂利润率 增加 0.06
  461. if (bednet.ifsaleout == 1)
  462. {
  463. bednet.sale_point = 0.06M;
  464. }
  465. AddKeyValue("外销加点", bednet.sale_point);
  466. }
  467. // 计算总材料成本 total_mtrl_cost
  468. bednet.total_mtrl_cost = new decimal[]
  469. {
  470. bednet.spring_mtrl_cost.Value,
  471. bednet.snake_wire_mtrl_cost.Value,
  472. bednet.pocket_around_spring_cost.Value,
  473. bednet.pocket_around_fabrics_cost.Value,
  474. bednet.hard_around_mtrl_cost.Value,
  475. bednet.glue_mtrl_cost.Value,
  476. bednet.fabrics1_mtrl_cost.Value,
  477. bednet.fabrics2_mtrl_cost.Value,
  478. bednet.side_iron_mtrl_cost.Value,
  479. bednet.cnail_mtrl_cost.Value,
  480. bednet.sponge_mtrl_cost.Value,
  481. bednet.sponge_mtrl_tc_cost.Value,
  482. bednet.edge_mtrl_cost.Value,
  483. bednet.fork_mtrl_cost.Value,
  484. bednet.rsorwa_mtrl_cost.Value,
  485. bednet.felt_mtrl_cost.Value,
  486. bednet.felt_mtrl_x_cost.Value,
  487. bednet.packet_mtrl_cost.Value
  488. }.Sum();
  489. AddKeyValue("总材料成本", bednet.total_mtrl_cost);
  490. // 计算总人力成本 total_mtrl_cost
  491. bednet.total_hr_cost = new decimal[]
  492. {
  493. bednet.spring_hr_cost.Value,
  494. bednet.hard_around_hr_cost.Value,
  495. bednet.side_iron_hr_cost.Value,
  496. bednet.cnail_hr_cost.Value,
  497. bednet.sponge_hr_cost.Value,
  498. bednet.edge_hr_cost.Value,
  499. bednet.fork_hr_cost.Value,
  500. bednet.rsorwa_hr_cost.Value,
  501. bednet.felt_hr_cost.Value,
  502. bednet.felt_hr_x_cost.Value,
  503. bednet.packet_hr_cost.Value,
  504. bednet.sponge_drilling_hr_cost.Value
  505. }.Sum();
  506. AddKeyValue("总人力成本", bednet.total_hr_cost);
  507. //
  508. AddKeyValue("额外费用", 0);
  509. AddKeyValue("FOB", 0);
  510. //1.总成本=总材料成本+总人力成本+ 额外费用
  511. //bednet.total_cost = bednet.total_mtrl_cost + bednet.total_hr_cost + bednet.total_fees_cost;
  512. bednet.total_cost = CalculateVarFormula("总成本").DecimalValue;
  513. AddKeyValue("总成本", bednet.total_cost);
  514. //2-不含税出厂价=总成本* ( 工厂利润率 + 外销加点 )
  515. //bednet.nottax_factory_cost = bednet.total_cost * (bednet.profitrate + bednet.sale_point);
  516. bednet.nottax_factory_cost = CalculateVarFormula("不含税出厂价").DecimalValue;
  517. AddKeyValue("不含税出厂价", bednet.nottax_factory_cost);
  518. // 3 - 部门不含税价 = 不含税出厂价 / 部门利润率 * 佣金点数 * 额外点数 + fob
  519. //bednet.nottax_dept_cost = bednet.nottax_factory_cost / bednet.dept_profitrate / (1 - (bednet.commission - 1)) * bednet.other_rate + bednet.fob;
  520. bednet.nottax_dept_cost = CalculateVarFormula("部门不含税价").DecimalValue;
  521. AddKeyValue("部门不含税价", bednet.nottax_dept_cost);
  522. // 4 - 税金 = (部门不含税价 * 税率 - 1)
  523. //bednet.taxes = bednet.nottax_dept_cost * (bednet.taxrate - 1);
  524. bednet.taxes = CalculateVarFormula("税金").DecimalValue;
  525. AddKeyValue("税金", bednet.taxes);
  526. // 5 - 部门含税价 = 部门不含税价 * 税率
  527. //bednet.dept_cost = bednet.nottax_dept_cost * bednet.taxrate;
  528. bednet.dept_cost = CalculateVarFormula("部门含税价").DecimalValue;
  529. AddKeyValue("部门含税价", bednet.dept_cost);
  530. // 6 - 外币价 = 部门含税价 / 汇率
  531. //if (bednet.moneyrate != 0)
  532. //{
  533. // bednet.foreign_cost = bednet.dept_cost / bednet.moneyrate;
  534. //}
  535. bednet.foreign_cost = CalculateVarFormula("外币价").DecimalValue;
  536. AddKeyValue("外币价", bednet.foreign_cost);
  537. decimal computed_plan = bednet.total_cost.Value - bednet.sponge_mtrl_cost.Value - bednet.felt_mtrl_cost.Value - bednet.felt_mtrl_x_cost.Value - bednet.packet_mtrl_cost.Value - bednet.packet_hr_cost.Value;
  538. AddKeyValue("计划价", computed_plan);
  539. }
  540. private void CulcalateWeight(u_bednet bednet, List<u_bednetmx> mxlist, List<u_bednetmx_spring> springList)
  541. {
  542. bednet.spring_weight_qty = 0;
  543. bednet.side_iron_weight_qty = 0;
  544. bednet.hard_around_weight_qty = 0;
  545. bednet.fabrics1_weight_qty = 0;
  546. bednet.fabrics2_weight_qty = 0;
  547. bednet.felt_weight_qty = 0;
  548. bednet.cnail_weight_qty = 0;
  549. bednet.sponge_weight_tc_qty = 0;
  550. bednet.sponge_weight_qty = 0;
  551. bednet.edge_weight_qty = 0;
  552. bednet.fork_weight_qty = 0;
  553. foreach (var mx in mxlist)
  554. {
  555. #region 计算 钢丝重量 开始
  556. if (!string.IsNullOrEmpty(bednet.spring_weight_formula))
  557. {
  558. mx.spring_weight_replace_formula = bednet.spring_weight_formula;
  559. if (mx.if_part == 0)
  560. {
  561. //单分区
  562. bednet.spring_weight_qty += Calculate(mx.spring_weight_replace_formula, "钢丝重量").DecimalValue;
  563. }
  564. else
  565. {
  566. //多分区
  567. foreach (var springItem in springList)
  568. {
  569. springItem.spring_weight_replace_formula = bednet.spring_weight_formula;
  570. CalSpringMtrlCol(bednet, mx, springItem);
  571. bednet.spring_weight_qty += Calculate(springItem.spring_weight_replace_formula, "钢丝重量").DecimalValue;
  572. }
  573. }
  574. AddKeyValue("弹簧排列个数-宽", mx.spring_qty_width);
  575. AddKeyValue("弹簧排列个数-长", mx.spring_qty_length);
  576. AddKeyValue("弹簧计算个数(宽)", mx.spring_qty_width);
  577. AddKeyValue("弹簧计算个数(长)", mx.spring_qty_length);
  578. AddKeyValue("钢丝重量", bednet.spring_weight_qty);
  579. AddFormulaWeightKeyValue("【钢丝重量】", bednet.spring_weight_formula, true, 1);
  580. }
  581. #endregion 计算 钢丝重量 结束
  582. #region 计算 边铁重量 开始
  583. if (!string.IsNullOrEmpty(bednet.side_iron_weight_formula) && bednet.if_side_iron == 1 && mx.if_side_iron > 0)
  584. {
  585. bednet.side_iron_weight_replace_formula = bednet.side_iron_weight_formula;
  586. bednet.side_iron_weight_qty += Calculate(bednet.side_iron_weight_replace_formula, "边铁重量").DecimalValue;
  587. AddKeyValue("边铁重量", bednet.side_iron_weight_qty);
  588. AddFormulaWeightKeyValue("【边铁重量】", bednet.side_iron_weight_formula);
  589. }
  590. #endregion 计算 边铁重量 结束
  591. #region 计算 四周加硬重量 开始
  592. if (!string.IsNullOrEmpty(bednet.hard_around_weight_formula) && mx.if_hard_around > 0)
  593. {
  594. bednet.hard_around_weight_replace_formula = bednet.hard_around_weight_formula;
  595. bednet.hard_around_weight_qty += Calculate(bednet.hard_around_weight_replace_formula, "四周加硬重量").DecimalValue;
  596. AddKeyValue("四周加硬重量", bednet.hard_around_weight_qty);
  597. AddFormulaWeightKeyValue("【四周加硬重量】", bednet.hard_around_weight_formula);
  598. }
  599. #endregion 计算 四周加硬重量 结束
  600. #region 计算 入袋无纺布重量 开始
  601. if (!string.IsNullOrEmpty(bednet.fabrics1_weight_formula) && bednet.typename.IndexOf("袋装网") > -1 && mx.fabrics1_mtrlid > 0)
  602. {
  603. bednet.fabrics1_weight_replace_formula = bednet.fabrics1_weight_formula;
  604. bednet.fabrics1_weight_qty += Calculate(bednet.fabrics1_weight_replace_formula, "入袋无纺布重量").DecimalValue;
  605. AddKeyValue("入袋无纺布重量", bednet.fabrics1_weight_qty);
  606. AddFormulaWeightKeyValue("【入袋无纺布重量】", bednet.fabrics1_weight_formula);
  607. }
  608. #endregion 计算 入袋无纺布重量 结束
  609. #region 计算 面底无纺布重量 开始
  610. if (!string.IsNullOrEmpty(bednet.fabrics2_weight_formula) && bednet.typename.IndexOf("袋装网") > -1 && mx.fabrics2_mtrlid > 0)
  611. {
  612. bednet.fabrics2_weight_replace_formula = bednet.fabrics2_weight_formula;
  613. bednet.fabrics2_weight_qty += Calculate(bednet.fabrics2_weight_replace_formula, "面底无纺布重量").DecimalValue;
  614. AddKeyValue("面底无纺布重量", bednet.fabrics2_weight_qty);
  615. AddFormulaWeightKeyValue("【面底无纺布重量】", bednet.fabrics2_weight_formula);
  616. }
  617. #endregion 计算 面底无纺布重量 结束
  618. #region 计算 上垫层重量 开始
  619. string felt_weight_formula_replace_formula = "";
  620. if (!string.IsNullOrEmpty(bednet.felt_mtrl_formula) && bednet.felt_qty > 0)
  621. {
  622. felt_weight_formula_replace_formula = bednet.felt_weight_formula;
  623. CalSpringMtrlCol2(bednet, mx, springList, "上垫层");
  624. bednet.felt_weight_qty += Calculate(felt_weight_formula_replace_formula, "上/下垫层重量").DecimalValue;
  625. AddKeyValue("上/下垫层重量", bednet.felt_weight_qty);
  626. AddFormulaWeightKeyValue("【上/下垫层重量】", bednet.felt_weight_formula);
  627. }
  628. #endregion 计算 上垫层重量 结束
  629. #region 计算 下垫层重量 开始
  630. string felt_x_weight_formula_replace_formula = "";
  631. if (!string.IsNullOrEmpty(bednet.felt_weight_formula) && bednet.felt_x_qty > 0)
  632. {
  633. felt_x_weight_formula_replace_formula = bednet.felt_weight_formula;
  634. CalSpringMtrlCol2(bednet, mx, springList, "下垫层");
  635. bednet.felt_weight_qty += Calculate(felt_x_weight_formula_replace_formula, "上/下垫层重量").DecimalValue;
  636. AddKeyValue("上/下垫层重量", bednet.felt_weight_qty);
  637. AddFormulaWeightKeyValue("【上/下垫层重量】", bednet.felt_weight_formula);
  638. }
  639. bednet.felt_weight_replace_formula += felt_weight_formula_replace_formula;
  640. bednet.felt_weight_replace_formula += Environment.NewLine;
  641. bednet.felt_weight_replace_formula += felt_x_weight_formula_replace_formula;
  642. #endregion 计算 下垫层重量 结束
  643. #region 计算 C钉/夹码重量 开始
  644. if (!string.IsNullOrEmpty(bednet.cnail_weight_formula))
  645. {
  646. bednet.cnail_weight_replace_formula = bednet.cnail_weight_formula;
  647. bednet.cnail_weight_qty += Calculate(bednet.cnail_weight_replace_formula, "C钉/夹码重量").DecimalValue;
  648. AddKeyValue("C钉/夹码重量", bednet.cnail_weight_qty);
  649. AddFormulaWeightKeyValue("【C钉/夹码重量】", bednet.cnail_weight_formula);
  650. }
  651. #endregion 计算 C钉/夹码重量 结束
  652. #region 计算 海绵包边重量 开始
  653. if (!string.IsNullOrEmpty(bednet.sponge_weight_formula) && bednet.sponge_mtrlid > 0)
  654. {
  655. bednet.sponge_weight_replace_formula = bednet.sponge_weight_formula;
  656. bednet.sponge_weight_qty += Calculate(bednet.sponge_weight_replace_formula, "海绵包边重量").DecimalValue;
  657. AddKeyValue("海绵包边重量", bednet.sponge_weight_qty);
  658. AddFormulaWeightKeyValue("【海绵包边重量】", bednet.sponge_weight_formula);
  659. }
  660. #endregion 计算 海绵包边重量 结束
  661. #region 计算 填充海绵重量 开始
  662. if (!string.IsNullOrEmpty(bednet.sponge_weight_tc_formula) && bednet.sponge_tc_mtrlid > 0)
  663. {
  664. bednet.sponge_weight_tc_replace_formula = bednet.sponge_weight_tc_formula;
  665. CalSpringMtrlCol2(bednet, mx, springList, "填充海绵");
  666. bednet.sponge_weight_tc_qty += Calculate(bednet.sponge_weight_tc_replace_formula, "填充海绵重量").DecimalValue;
  667. AddKeyValue("填充海绵重量", bednet.sponge_weight_tc_qty);
  668. AddFormulaWeightKeyValue("【填充海绵重量】", bednet.sponge_weight_tc_formula);
  669. }
  670. #endregion 计算 填充海绵重量 结束
  671. #region 计算 封边材料重量 开始
  672. if (!string.IsNullOrEmpty(bednet.edge_weight_formula) && bednet.edge_mtrlid > 0)
  673. {
  674. bednet.edge_weight_replace_formula = bednet.edge_weight_formula;
  675. CalSpringMtrlCol2(bednet, mx, springList, "封边");
  676. bednet.edge_weight_qty += Calculate(bednet.edge_weight_replace_formula, "封边材料重量").DecimalValue;
  677. AddKeyValue("封边材料重量", bednet.edge_weight_qty);
  678. AddFormulaWeightKeyValue("【封边材料重量】", bednet.edge_weight_formula);
  679. }
  680. #endregion 计算 封边材料重量 结束
  681. #region 计算 弹叉材料重量 开始
  682. if (!string.IsNullOrEmpty(bednet.fork_weight_formula) && bednet.fork_qty > 0)
  683. {
  684. bednet.fork_weight_replace_formula = bednet.fork_weight_formula;
  685. bednet.fork_weight_qty += Calculate(bednet.fork_weight_replace_formula, "弹叉材料重量").DecimalValue;
  686. AddKeyValue("弹叉材料重量", bednet.fork_weight_qty);
  687. AddFormulaWeightKeyValue("【弹叉材料重量】", bednet.fork_weight_formula);
  688. }
  689. #endregion 计算 弹叉材料重量 结束
  690. }
  691. // 计算总材料成本 total_mtrl_cost
  692. bednet.sum_weight = new decimal[]
  693. {
  694. bednet.spring_weight_qty.Value,
  695. bednet.side_iron_weight_qty.Value,
  696. bednet.hard_around_weight_qty.Value,
  697. bednet.fabrics1_weight_qty.Value,
  698. bednet.fabrics2_weight_qty.Value,
  699. bednet.felt_weight_qty.Value,
  700. bednet.cnail_weight_qty.Value,
  701. bednet.sponge_weight_qty.Value,
  702. bednet.sponge_weight_tc_qty.Value,
  703. bednet.edge_weight_qty.Value,
  704. bednet.fork_weight_qty.Value
  705. }.Sum();
  706. AddKeyValue("总重量", bednet.sum_weight);
  707. AddFormulaHideKeyValue("总重量", "【钢丝重量】+【边铁重量】+【四周加硬重量】+【入袋无纺布重量】+【面底无纺布重量】+【上/下垫层重量】+【C钉/夹码重量】+【海绵包边重量】+【填充海绵重量】+【封边材料重量】+【弹叉材料重量】");
  708. }
  709. private void InitBedNet(u_bednet bednet)
  710. {
  711. var dept = new u_dept() { deptid = bednet.deptid.Value };
  712. DbSqlHelper.SelectOne(cmd, dept, "pricelistid,profitrate,moneyrate,discount");
  713. //var profirate = new u_factory_profitrate() { deptid = bednet.deptid, bednettypeid_mattresstypeid = bednet.bednettypeid, bednet_or_mattress = 0 };
  714. //DbSqlHelper.SelectOne(cmd, profirate, "profitrate");
  715. decimal profitrate = 0;
  716. cmd.CommandText = @"SELECT profitrate FROM u_factory_profitrate
  717. WHERE deptid = @deptid
  718. AND bednettypeid_mattresstypeid = @bednettypeid_mattresstypeid
  719. AND bednet_or_mattress = 0";
  720. cmd.Parameters.Clear();
  721. cmd.Parameters.AddWithValue("@deptid", bednet.deptid);
  722. cmd.Parameters.AddWithValue("@bednettypeid_mattresstypeid", bednet.bednettypeid);
  723. using (var reader = cmd.ExecuteReader())
  724. {
  725. if (reader.Read())
  726. {
  727. profitrate = Convert.ToDecimal(reader["profitrate"]);
  728. }
  729. }
  730. var bednetType = new u_bednet_type() { bednettypeid = bednet.bednettypeid };
  731. DbSqlHelper.SelectOne(cmd, bednetType, "typename");
  732. bednet.pricelistid = dept.pricelistid;
  733. bednet.typename = bednetType.typename;
  734. bednet.profitrate = profitrate;
  735. bednet.dept_profitrate = dept.profitrate;
  736. bednet.moneyrate = bednet.moneyrate ?? 1;
  737. bednet.commission = bednet.commission ?? 1;
  738. bednet.taxrate = bednet.taxrate ?? 1;
  739. bednet.other_rate = bednet.other_rate ?? 1;
  740. bednet.dept_profitrate = bednet.dept_profitrate ?? 0;
  741. // 检查佣金是否小于1
  742. if (bednet.commission < 1)
  743. {
  744. throw new LJCommonException("佣金点数不能小于1!");
  745. }
  746. // 检查税率是否小于1
  747. if (bednet.taxrate < 1)
  748. {
  749. throw new LJCommonException("税率不能小于1!");
  750. }
  751. // 检查额外点数是否小于1
  752. if (bednet.other_rate < 1)
  753. {
  754. throw new LJCommonException("税率不能小于1!");
  755. }
  756. // 检查部门利润率是否为0
  757. if (bednet.dept_profitrate == 0)
  758. {
  759. throw new LJCommonException("部门利润率不能为0!");
  760. }
  761. }
  762. private void InitSptringRepaceMents(u_spring spring)
  763. {
  764. AddKeyValue("中心直径", spring.center_diameter);
  765. AddKeyValue("线径MM", spring.line_diameter);
  766. AddKeyValue("高度CM", spring.height);
  767. AddKeyValue("口径CM", spring.caliber);
  768. AddKeyValue("圈数", spring.cyclenum);
  769. AddKeyValue("克重KG", spring.gram_weight);
  770. AddKeyValue("卷排列宽", spring.roll_width);
  771. AddKeyValue("卷排列长", spring.roll_length);
  772. AddKeyValue("排列宽", spring.arrangement_width);
  773. AddKeyValue("排列长", spring.arrangement_height);
  774. }
  775. private void InitReplaceMents(u_bednet bednet)
  776. {
  777. replacements.Clear();
  778. var bednetVarList = new List<u_bednet_var>();
  779. var selectStr = @"SELECT u_bednet_varmx.varid AS varid
  780. ,varkind
  781. ,varcode
  782. ,varname
  783. ,varclass
  784. ,vartype
  785. ,varunit
  786. ,u_bednet_varmx.varvalue AS varvalue
  787. FROM u_bednet_var
  788. INNER JOIN u_bednet_varmx ON u_bednet_varmx.varid = u_bednet_var.varid";
  789. var whereList = new List<string>();
  790. whereList.Add("u_bednet_var.varclass < 2");
  791. whereList.Add("u_bednet_var.varkind = @varkind");
  792. whereList.Add("u_bednet_varmx.pricelistid = @pricelistid");
  793. whereList.Add(@"(u_bednet_var.varclass = 1
  794. AND (
  795. u_bednet_varmx.bednettypeid = @bednettypeid
  796. OR @bednettypeid = 0
  797. )
  798. )
  799. OR (u_bednet_var.varclass = 0)");
  800. var param = new Dictionary<string, object>();
  801. param.Add("@varkind", 0);
  802. param.Add("@pricelistid", bednet.pricelistid);
  803. param.Add("@bednettypeid", bednet.bednettypeid);
  804. DbSqlHelper.SelectJoin(cmd, selectStr, ListEx.GetWhereStr(whereList), param, "varid", "varid,varkind,varcode,varname,varclass,vartype,varunit,varvalue", 0, 0, bednetVarList);
  805. AddKeyValue("床垫宽", bednet.mattress_width);
  806. AddKeyValue("床垫长", bednet.mattress_length);
  807. AddKeyValue("床垫高", bednet.mattress_height);
  808. AddKeyValue("双簧", bednet.if_doublespring);
  809. AddKeyValue("弹叉数量", bednet.fork_qty);
  810. AddKeyValue("包装方式", bednet.packtype);
  811. AddKeyValue("包装数量", bednet.packqty);
  812. AddKeyValue("运输方式", bednet.transport_type);
  813. AddKeyValue("包装材料", bednet.packmtrl);
  814. AddKeyValue("床网类别", bednet.typename);
  815. AddKeyValue("工厂利润率", bednet.profitrate);
  816. AddKeyValue("部门利润率", bednet.dept_profitrate);
  817. AddKeyValue("佣金点数", bednet.commission);
  818. AddKeyValue("额外点数", bednet.other_rate);
  819. AddKeyValue("额外费用", bednet.extras_cost);
  820. AddKeyValue("汇率", bednet.moneyrate);
  821. AddKeyValue("税率", bednet.taxrate);
  822. AddKeyValue("卷包", bednet.if_jb);
  823. // 公式
  824. AddFormulaKeyValue("总成本", "【总材料成本】+【总人力成本】+ 【额外费用】");
  825. AddFormulaKeyValue("不含税出厂价", "【总成本】*(【工厂利润率】+【外销加点】)");
  826. AddFormulaKeyValue("部门不含税价", "【不含税出厂价】/【部门利润率】/( 1 - (【佣金点数】- 1))*【额外点数】+【FOB】");
  827. AddFormulaKeyValue("税金", "【部门不含税价】* (【税率】-1)");
  828. AddFormulaKeyValue("部门含税价", "【部门不含税价】*【税率】");
  829. AddFormulaKeyValue("外币价", "【部门含税价】/【汇率】");
  830. AddFormulaKeyValue("计划价", "【总成本】 - 【海绵包边材料成本】 - 【上垫层物料成本】 - 【下垫层物料成本】 - 【包装总成本】 - 【包装人工成本】");
  831. //AddFormulaHideKeyValue("总材料成本", "【弹簧材料总成本】+【蛇线材料成本】+【四周口袋弹簧成本】+【四周口袋无纺布成本】+【四周加硬材料成本】+【胶水材料成本】+【入袋无纺布材料成本】+【底面无纺布材料成本】+【边铁材料成本】+【C钉/夹码材料成本】+【海绵包边材料成本】+【填充海绵成本】+【封边材料成本】+【弹叉材料成本】+【胶条/包角材料成本】+【上垫层物料成本】+【下垫层物料成本】+【包装总成本】");
  832. //AddFormulaHideKeyValue("总人力成本", "【弹簧总人工成本】+【四周加硬人力成本】+【边铁人力成本】+【C钉/夹码人力成本】+【海绵包边人力成本】+【封边人力成本】+【弹叉人力成本】+【胶条/包角人力成本】+【上垫层人力成本】+【下垫层人力成本】+【包装人工成本】+【海绵打孔人力成本】");
  833. foreach (var netvar in bednetVarList)
  834. {
  835. AddKeyValue(netvar.varname, netvar.varvalue);
  836. }
  837. selectStr = @"SELECT varid
  838. ,varkind
  839. ,varcode
  840. ,varname
  841. ,varclass
  842. ,vartype
  843. ,varunit
  844. ,formula
  845. FROM u_bednet_var";
  846. bednetVarList = new List<u_bednet_var>();
  847. whereList = new List<string>();
  848. whereList.Add("u_bednet_var.varkind = @varkind");
  849. whereList.Add("u_bednet_var.varclass = @varclass");
  850. param = new Dictionary<string, object>();
  851. param.Add("@varkind", 0);
  852. param.Add("@varclass", 2);
  853. DbSqlHelper.SelectJoin(cmd, selectStr, ListEx.GetWhereStr(whereList), param, "varid", "varid,varkind,varcode,varname,varclass,vartype,varunit,formula", 0, 0, bednetVarList);
  854. string[] keys = { "总成本", "不含税出厂价", "部门不含税价", "税金", "部门含税价", "外币价", "计划价" };
  855. // 添加替换公式变量
  856. foreach (var netvar in bednetVarList)
  857. {
  858. if (keys.Contains(netvar.varname))
  859. {
  860. AddFormulaKeyValue(netvar.varname, netvar.formula);
  861. }
  862. AddFormulaHideKeyValue(netvar.varname, netvar.formula);
  863. }
  864. }
  865. private void InitMxReplaceMents(u_bednet bednet,u_bednetmx mx, u_spring spring)
  866. {
  867. AddKeyValue("弹簧排列个数-宽", mx.spring_qty_width);
  868. AddKeyValue("弹簧排列个数-长", mx.spring_qty_length);
  869. AddKeyValue("弹簧计算个数(宽)", mx.spring_qty_width);
  870. AddKeyValue("弹簧计算个数(长)", mx.spring_qty_length);
  871. AddKeyValue("边铁条数", mx.side_iron_qty);
  872. AddKeyValue("条数", mx.side_iron_qty);
  873. AddKeyValue("四周口袋-排数", mx.pocket_around_row);
  874. AddKeyValue("四周口袋", mx.if_pocket_around);
  875. AddKeyValue("四周加硬-排数", mx.hard_around_row);
  876. AddKeyValue("四周加硬", mx.if_hard_around);
  877. spring.gram_weight /= 1000;
  878. if (spring.gram_weight > 0)
  879. {
  880. AddKeyValue("弹簧重/个", spring.gram_weight);
  881. AddKeyValue("弹簧重", spring.gram_weight);
  882. AddKeyValue("弹簧克重", spring.gram_weight * 1000);
  883. }
  884. if (mx.bednet_height > 0)
  885. {
  886. AddKeyValue("床网高", mx.bednet_height);
  887. }
  888. if (spring.height > 0)
  889. {
  890. AddKeyValue("口袋弹簧高度", spring.height);
  891. }
  892. if (spring.center_diameter > 0)
  893. {
  894. AddKeyValue("口袋弹簧心径", spring.center_diameter);
  895. }
  896. if (spring.line_diameter == null)
  897. {
  898. spring.line_diameter = 0;
  899. }
  900. cmd.CommandText = @"SELECT TOP 1 isnull(u_mtrl_price_pricelist.price, 0) AS price
  901. FROM u_mtrl_price_pricelist
  902. INNER JOIN u_mtrl_price ON u_mtrl_price.mtrlid = u_mtrl_price_pricelist.mtrlid
  903. WHERE cast(u_mtrl_price.name AS DECIMAL(18, 5)) = @line_diameter
  904. AND u_mtrl_price.mtrltype = 0
  905. AND u_mtrl_price_pricelist.pricelistid = @pricelistid";
  906. cmd.Parameters.Clear();
  907. cmd.Parameters.AddWithValue("@line_diameter", spring.line_diameter);
  908. cmd.Parameters.AddWithValue("@pricelistid", bednet.pricelistid);
  909. decimal price = 0;
  910. using (var reader = cmd.ExecuteReader())
  911. {
  912. if (reader.Read())
  913. {
  914. price = Convert.ToDecimal(reader["price"]);
  915. price /= 1000;
  916. }
  917. }
  918. if (price > 0)
  919. {
  920. AddKeyValue("加硬弹簧单价", price);
  921. AddKeyValue("口袋弹簧单价", price);
  922. AddKeyValue("弹簧单价", price);
  923. }
  924. }
  925. /// <summary>
  926. /// 用于床网报价 弹簧材料总成本 弹簧人工总成本
  927. /// </summary>
  928. /// <param name="cmd"></param>
  929. /// <param name="dept"></param>
  930. /// <param name="mx"></param>
  931. /// <param name="mx2"></param>
  932. private void CalSpringMtrlCol(u_bednet bednet, u_bednetmx mx, u_bednetmx_spring mx2)
  933. {
  934. AddKeyValue("弹簧排列个数-宽", mx2.spring_qty_width);
  935. AddKeyValue("弹簧排列个数-长", mx2.spring_qty_length);
  936. AddKeyValue("弹簧计算个数(宽)", mx2.spring_qty_width);
  937. AddKeyValue("弹簧计算个数(长)", mx2.spring_qty_length);
  938. AddKeyValue("边铁条数", mx.side_iron_qty);
  939. AddKeyValue("条数", mx.side_iron_qty);
  940. var spring = new u_spring() { springid = mx2.springid };
  941. DbSqlHelper.SelectOne(cmd, spring, "line_diameter,gram_weight");
  942. spring.gram_weight /= 1000;
  943. if (spring.gram_weight > 0)
  944. {
  945. AddKeyValue("弹簧重/个", spring.gram_weight);
  946. AddKeyValue("弹簧重", spring.gram_weight);
  947. }
  948. cmd.CommandText = @"SELECT TOP 1 isnull(u_mtrl_price_pricelist.price, 0) AS price
  949. FROM u_mtrl_price_pricelist
  950. INNER JOIN u_mtrl_price ON u_mtrl_price.mtrlid = u_mtrl_price_pricelist.mtrlid
  951. WHERE cast(u_mtrl_price.name AS DECIMAL(18, 5)) = @line_diameter
  952. AND u_mtrl_price.mtrltype = 0
  953. AND u_mtrl_price_pricelist.pricelistid = @pricelistid";
  954. cmd.Parameters.Clear();
  955. cmd.Parameters.AddWithValue("@line_diameter", spring.line_diameter);
  956. cmd.Parameters.AddWithValue("@pricelistid", bednet.pricelistid);
  957. decimal price = 0;
  958. using (var reader = cmd.ExecuteReader())
  959. {
  960. if (reader.Read())
  961. {
  962. price = Convert.ToDecimal(reader["price"]);
  963. price /= 1000;
  964. }
  965. }
  966. if (price > 0)
  967. {
  968. AddKeyValue("弹簧单价", price);
  969. }
  970. }
  971. /// <summary>
  972. /// 代码对照wf_replace_var_dw2
  973. /// </summary>
  974. /// <param name="cmd"></param>
  975. /// <param name="mx"></param>
  976. private void CalSpringMtrlCol2(u_bednet bednet, u_bednetmx mx, List<u_bednetmx_spring> springList, string type)
  977. {
  978. var spring = new u_spring() { springid = mx.springid };
  979. DbSqlHelper.SelectOne(cmd, spring, "line_diameter,gram_weight,center_diameter");
  980. #region 计算 底面无纺布 开始
  981. //计算 上下无纺布方数 =(B4+C4)*(B4+D4)/10000
  982. if ("底面无纺布".Equals(type) && mx.fabrics2_mtrlid > 0)
  983. {
  984. decimal fabrics = (decimal)((mx.bednet_height.Value + bednet.mattress_width.Value) * (mx.bednet_height.Value + bednet.mattress_length.Value)) / 10000;
  985. AddKeyValue("上下无纺布方数", fabrics);
  986. decimal fabrics_price = getMtrlPrice(2, bednet.pricelistid.Value, mx.fabrics2_mtrlid.Value);
  987. if (fabrics_price > 0) AddKeyValue("无纺布单价", fabrics_price);
  988. }
  989. #endregion 计算 底面无纺布 结束
  990. #region 计算 入袋无纺布 开始
  991. //计算 入袋无纺布方数 = (B4+I4+2)*((I4*3.14)+1)/10000
  992. if ("入袋无纺布".Equals(type) && mx.fabrics1_mtrlid > 0)
  993. {
  994. var _springid = mx.springid;
  995. if (_springid == 0 && springList.Count > 0)
  996. {
  997. _springid = springList[0].springid;
  998. }
  999. var _spring = new u_spring() { springid = _springid };
  1000. DbSqlHelper.SelectOne(cmd, _spring, "line_diameter,gram_weight,center_diameter");
  1001. spring.center_diameter = _spring.center_diameter == null ? 0 : _spring.center_diameter;
  1002. decimal fabrics = (decimal)((mx.bednet_height.Value + _spring.center_diameter.Value + 2) * (_spring.center_diameter.Value * (decimal)3.14 + 1)) / 10000;
  1003. string fabrics_str = fabrics.ToString("###0.#####");
  1004. AddKeyValue("入袋无纺布方数", fabrics_str);
  1005. decimal fabrics_price = getMtrlPrice(2, bednet.pricelistid.Value, mx.fabrics1_mtrlid.Value);
  1006. if (fabrics_price > 0) AddKeyValue("无纺布单价", fabrics_price);
  1007. }
  1008. #endregion 计算 入袋无纺布 结束
  1009. #region 计算 四周加硬弹簧 开始
  1010. // 主要是要替换 【弹簧克重】 【弹簧单价】
  1011. // 因相同部分已存在,不需要后续
  1012. #endregion 计算 四周加硬弹簧 结束
  1013. #region 计算 海绵包边 开始
  1014. if ("海绵包边".Equals(type) && bednet.sponge_thickness.Value > 0 && bednet.sponge_mtrlid.Value > 0)
  1015. {
  1016. var mtrl_price = new u_mtrl_price() { mtrlid = bednet.sponge_mtrlid };
  1017. DbSqlHelper.SelectOne(cmd, mtrl_price, "name");
  1018. AddKeyValue("物料名称", mtrl_price.name);
  1019. AddKeyValue("裥棉厚度", bednet.sponge_thickness.Value);
  1020. AddKeyValue("海绵厚度", bednet.sponge_thickness.Value);
  1021. if (bednet.sponge_height.Value > 0)
  1022. {
  1023. AddKeyValue("海绵高", bednet.sponge_height.Value);
  1024. }
  1025. cmd.CommandText = @"SELECT isnull(u_mtrl_price_pricelist.price, 0) AS price
  1026. FROM u_mtrl_price_pricelist
  1027. WHERE u_mtrl_price_pricelist.mtrlid = @mtrlid
  1028. AND u_mtrl_price_pricelist.pricelistid = @pricelistid";
  1029. cmd.Parameters.Clear();
  1030. cmd.Parameters.AddWithValue("@mtrlid", bednet.sponge_mtrlid);
  1031. cmd.Parameters.AddWithValue("@pricelistid", bednet.pricelistid);
  1032. using (var reader = cmd.ExecuteReader())
  1033. {
  1034. if (reader.Read())
  1035. {
  1036. decimal sponge_price = Convert.ToDecimal(reader["price"]);
  1037. AddKeyValue("裥棉单价", sponge_price);
  1038. AddKeyValue("海绵单价", sponge_price);
  1039. }
  1040. }
  1041. }
  1042. #endregion 计算 海绵包边 结束
  1043. #region 计算 填充海绵 开始
  1044. if ("填充海绵".Equals(type) && bednet.sponge_tc_thickness.Value > 0 && bednet.sponge_tc_mtrlid.Value > 0)
  1045. {
  1046. var mtrl_price = new u_mtrl_price() { mtrlid = bednet.sponge_tc_mtrlid };
  1047. DbSqlHelper.SelectOne(cmd, mtrl_price, "name");
  1048. AddKeyValue("物料名称", mtrl_price.name);
  1049. AddKeyValue("裥棉厚度", bednet.sponge_tc_thickness.Value);
  1050. AddKeyValue("海绵厚度", bednet.sponge_tc_thickness.Value);
  1051. if (bednet.sponge_tc_height.Value > 0)
  1052. {
  1053. AddKeyValue("海绵高", bednet.sponge_tc_height.Value);
  1054. }
  1055. cmd.CommandText = @"SELECT isnull(u_mtrl_price_pricelist.price, 0) AS price
  1056. FROM u_mtrl_price_pricelist
  1057. WHERE u_mtrl_price_pricelist.mtrlid = @mtrlid
  1058. AND u_mtrl_price_pricelist.pricelistid = @pricelistid";
  1059. cmd.Parameters.Clear();
  1060. cmd.Parameters.AddWithValue("@mtrlid", bednet.sponge_tc_mtrlid);
  1061. cmd.Parameters.AddWithValue("@pricelistid", bednet.pricelistid);
  1062. using (var reader = cmd.ExecuteReader())
  1063. {
  1064. if (reader.Read())
  1065. {
  1066. decimal sponge_price = Convert.ToDecimal(reader["price"]);
  1067. AddKeyValue("裥棉单价", sponge_price);
  1068. AddKeyValue("海绵单价", sponge_price);
  1069. }
  1070. }
  1071. }
  1072. #endregion 计算 填充海绵 结束
  1073. #region 计算 封边 开始
  1074. if ("封边".Equals(type) && bednet.edge_mtrlid > 0)
  1075. {
  1076. AddKeyValue("有边铁", mx.if_side_iron);
  1077. cmd.CommandText = @"SELECT isnull(u_mtrl_price_pricelist.price, 0) AS price
  1078. ,u_mtrl_price.gram_weight
  1079. FROM u_mtrl_price_pricelist
  1080. INNER JOIN u_mtrl_price ON u_mtrl_price.mtrlid = u_mtrl_price_pricelist.mtrlid
  1081. WHERE u_mtrl_price_pricelist.mtrlid = @mtrlid
  1082. AND u_mtrl_price_pricelist.pricelistid = @pricelistid";
  1083. cmd.Parameters.Clear();
  1084. cmd.Parameters.AddWithValue("@mtrlid", bednet.edge_mtrlid);
  1085. cmd.Parameters.AddWithValue("@pricelistid", bednet.pricelistid);
  1086. using (var reader = cmd.ExecuteReader())
  1087. {
  1088. if (reader.Read())
  1089. {
  1090. decimal edge_price = Convert.ToDecimal(reader["price"]);
  1091. decimal edge_weight = Convert.ToDecimal(reader["gram_weight"]);
  1092. if (edge_price > 0) AddKeyValue("毡单价", edge_price);
  1093. if (edge_weight > 0) AddKeyValue("毡克重", edge_weight);
  1094. }
  1095. }
  1096. if (bednet.edge_height > 0) AddKeyValue("封边高", bednet.edge_height);
  1097. }
  1098. #endregion 计算 封边 结束
  1099. #region 计算 上垫层 开始
  1100. if ("上垫层".Equals(type) && bednet.felt_mtrlid > 0)
  1101. {
  1102. cmd.CommandText = @"SELECT isnull(u_mtrl_price_pricelist.price, 0) AS price
  1103. ,u_mtrl_price.gram_weight
  1104. FROM u_mtrl_price_pricelist
  1105. INNER JOIN u_mtrl_price ON u_mtrl_price.mtrlid = u_mtrl_price_pricelist.mtrlid
  1106. WHERE u_mtrl_price_pricelist.mtrlid = @mtrlid
  1107. AND u_mtrl_price_pricelist.pricelistid = @pricelistid";
  1108. cmd.Parameters.Clear();
  1109. cmd.Parameters.AddWithValue("@mtrlid", bednet.felt_mtrlid);
  1110. cmd.Parameters.AddWithValue("@pricelistid", bednet.pricelistid);
  1111. using (var reader = cmd.ExecuteReader())
  1112. {
  1113. if (reader.Read())
  1114. {
  1115. decimal felt_price = Convert.ToDecimal(reader["price"]);
  1116. decimal felt_weight = Convert.ToDecimal(reader["gram_weight"]);
  1117. if (felt_price > 0) AddKeyValue("垫层物料单价", felt_price);
  1118. if (felt_weight > 0) AddKeyValue("垫层物料克重", felt_weight);
  1119. }
  1120. }
  1121. if (bednet.felt_qty > 0) AddKeyValue("垫层物料数量", bednet.felt_qty);
  1122. }
  1123. #endregion 计算 上垫层 结束
  1124. #region 计算 下垫层 开始
  1125. if ("下垫层".Equals(type) && bednet.felt_x_mtrlid > 0)
  1126. {
  1127. cmd.CommandText = @"SELECT isnull(u_mtrl_price_pricelist.price, 0) AS price
  1128. ,u_mtrl_price.gram_weight
  1129. FROM u_mtrl_price_pricelist
  1130. INNER JOIN u_mtrl_price ON u_mtrl_price.mtrlid = u_mtrl_price_pricelist.mtrlid
  1131. WHERE u_mtrl_price_pricelist.mtrlid = @mtrlid
  1132. AND u_mtrl_price_pricelist.pricelistid = @pricelistid";
  1133. cmd.Parameters.Clear();
  1134. cmd.Parameters.AddWithValue("@mtrlid", bednet.felt_x_mtrlid);
  1135. cmd.Parameters.AddWithValue("@pricelistid", bednet.pricelistid);
  1136. using (var reader = cmd.ExecuteReader())
  1137. {
  1138. if (reader.Read())
  1139. {
  1140. decimal felt_price = Convert.ToDecimal(reader["price"]);
  1141. decimal felt_weight = Convert.ToDecimal(reader["gram_weight"]);
  1142. if (felt_price > 0) AddKeyValue("垫层物料单价", felt_price);
  1143. if (felt_weight > 0) AddKeyValue("垫层物料克重", felt_weight);
  1144. }
  1145. }
  1146. if (bednet.felt_x_qty > 0) AddKeyValue("垫层物料数量", bednet.felt_x_qty);
  1147. }
  1148. #endregion 计算 下垫层 结束
  1149. }
  1150. private void CalSnakeCol(u_bednet bednet,u_spring spring)
  1151. {
  1152. #region 替换蛇线单价 snake_wire_diameter
  1153. cmd.CommandText = @"SELECT TOP 1 isnull(u_mtrl_price_pricelist.price, 0) AS price
  1154. FROM u_mtrl_price_pricelist
  1155. INNER JOIN u_mtrl_price ON u_mtrl_price.mtrlid = u_mtrl_price_pricelist.mtrlid
  1156. WHERE cast(u_mtrl_price.name AS DECIMAL(18, 5)) = @line_diameter
  1157. AND u_mtrl_price.mtrltype = 0
  1158. AND u_mtrl_price_pricelist.pricelistid = @pricelistid";
  1159. cmd.Parameters.Clear();
  1160. cmd.Parameters.AddWithValue("@line_diameter", spring.line_diameter);
  1161. cmd.Parameters.AddWithValue("@pricelistid", bednet.pricelistid);
  1162. decimal price = 0;
  1163. using (var reader = cmd.ExecuteReader())
  1164. {
  1165. if (reader.Read())
  1166. {
  1167. price = Convert.ToDecimal(reader["price"]);
  1168. price /= 1000;
  1169. }
  1170. }
  1171. if (price > 0)
  1172. {
  1173. AddKeyValue("蛇线单价", price);
  1174. }
  1175. #endregion
  1176. }
  1177. private decimal getMtrlPrice(int mtrltype, int pricelistid, int mtrlid)
  1178. {
  1179. decimal price = 0;
  1180. cmd.CommandText = @"SELECT TOP 1 isnull(u_mtrl_price_pricelist.price, 0) AS price
  1181. FROM u_mtrl_price_pricelist
  1182. INNER JOIN u_mtrl_price ON u_mtrl_price.mtrlid = u_mtrl_price_pricelist.mtrlid
  1183. WHERE u_mtrl_price.mtrlid = @mtrlid
  1184. AND u_mtrl_price.mtrltype = @mtrltype
  1185. AND u_mtrl_price_pricelist.pricelistid = @pricelistid";
  1186. cmd.Parameters.Clear();
  1187. cmd.Parameters.AddWithValue("@mtrlid", mtrlid);
  1188. cmd.Parameters.AddWithValue("@mtrltype", mtrltype);
  1189. cmd.Parameters.AddWithValue("@pricelistid", pricelistid);
  1190. using (var reader = cmd.ExecuteReader())
  1191. {
  1192. if (reader.Read())
  1193. {
  1194. price = Convert.ToDecimal(reader["price"]);
  1195. //price /= 1000;
  1196. }
  1197. }
  1198. return price;
  1199. }
  1200. private string ConvertToEnglishSymbols(string input)
  1201. {
  1202. input = input.Replace("(", "(")
  1203. .Replace(")", ")")
  1204. .Replace(",", ",")
  1205. .Replace("。", ".")
  1206. .Replace(":", ":")
  1207. .Replace(";", ";")
  1208. .Replace("“", "\"")
  1209. .Replace("”", "\"")
  1210. .Replace("‘", "'")
  1211. .Replace("’", "'");
  1212. return input;
  1213. }
  1214. private void AddKeyValue(string key, object value, bool isReplace = true)
  1215. {
  1216. key = $"【{key}】";
  1217. if (!replacements.ContainsKey(key))
  1218. {
  1219. replacements.Add(key, value);
  1220. }
  1221. else if (isReplace)
  1222. {
  1223. replacements[key] = value;
  1224. }
  1225. }
  1226. private void AddFormulaKeyValue(string key, string value, bool isReplace = true, int ifnotreplace = 0)
  1227. {
  1228. var formulaItem = new formulaItem()
  1229. {
  1230. value = value,
  1231. ifnotreplace = ifnotreplace
  1232. };
  1233. key = $"【{key}】";
  1234. if (!formula_replacements.ContainsKey(key))
  1235. {
  1236. formula_replacements.Add(key, formulaItem);
  1237. }
  1238. else if (isReplace)
  1239. {
  1240. formula_replacements[key] = formulaItem;
  1241. }
  1242. }
  1243. /// <summary>
  1244. /// 记录隐藏公式
  1245. /// </summary>
  1246. /// <param name="key"></param>
  1247. /// <param name="value"></param>
  1248. /// <param name="isReplace"></param>
  1249. private void AddFormulaHideKeyValue(string key, string value, bool isReplace = true, int ifnotreplace = 0)
  1250. {
  1251. var formulaItem = new formulaItem()
  1252. {
  1253. value = value,
  1254. ifnotreplace = ifnotreplace
  1255. };
  1256. key = $"【{key}】";
  1257. if (!formula_replacements_hide.ContainsKey(key))
  1258. {
  1259. formula_replacements_hide.Add(key, formulaItem);
  1260. }
  1261. else if (isReplace)
  1262. {
  1263. formula_replacements_hide[key] = formulaItem;
  1264. }
  1265. }
  1266. /// <summary>
  1267. /// 记录详细公式
  1268. /// </summary>
  1269. /// <param name="key"></param>
  1270. /// <param name="value"></param>
  1271. /// <param name="isReplace"></param>
  1272. private void AddFormulaMxKeyValue(string key, string value, bool isReplace = true, int ifnotreplace = 0)
  1273. {
  1274. var formulaItem = new formulaItem()
  1275. {
  1276. value = value,
  1277. ifnotreplace = ifnotreplace
  1278. };
  1279. if (!formula_replacements_mx.ContainsKey(key))
  1280. {
  1281. formula_replacements_mx.Add(key, formulaItem);
  1282. }
  1283. else if (isReplace)
  1284. {
  1285. formula_replacements_mx[key] = formulaItem;
  1286. }
  1287. }
  1288. /// <summary>
  1289. /// 记录重量公式
  1290. /// </summary>
  1291. /// <param name="key"></param>
  1292. /// <param name="value"></param>
  1293. /// <param name="isReplace"></param>
  1294. private void AddFormulaWeightKeyValue(string key, string value, bool isReplace = true, int ifnotreplace = 0)
  1295. {
  1296. var formulaItem = new formulaItem()
  1297. {
  1298. value = value,
  1299. ifnotreplace = ifnotreplace
  1300. };
  1301. if (!formula_replacements_weight.ContainsKey(key))
  1302. {
  1303. formula_replacements_weight.Add(key, formulaItem);
  1304. }
  1305. else if (isReplace)
  1306. {
  1307. formula_replacements_weight[key] = formulaItem;
  1308. }
  1309. }
  1310. private string ReplaceWith(string input, string oldValue, string newValue)
  1311. {
  1312. return input.Replace(oldValue, newValue);
  1313. }
  1314. private TData CalculateVarFormula(string varname)
  1315. {
  1316. varname = $"【{varname}】";
  1317. if (!formula_replacements.ContainsKey(varname)) return null;
  1318. return Calculate(formula_replacements[varname].value, varname);
  1319. }
  1320. private void replaceFormulas(ref string expression)
  1321. {
  1322. bool hasReplace = false;
  1323. foreach (var replacement in formula_replacements)
  1324. {
  1325. if (expression.IndexOf(replacement.Key) > -1)
  1326. {
  1327. expression = expression.Replace(replacement.Key, "(" + replacement.Value.value + ")");
  1328. hasReplace = true;
  1329. }
  1330. }
  1331. if (hasReplace)
  1332. {
  1333. replaceFormulas(ref expression);
  1334. }
  1335. }
  1336. private void replaceFormulasHide(ref string expression)
  1337. {
  1338. bool hasReplace = false;
  1339. foreach (var replacement in formula_replacements_hide)
  1340. {
  1341. if (expression.IndexOf(replacement.Key) > -1)
  1342. {
  1343. expression = expression.Replace(replacement.Key, "(" + replacement.Value.value + ")");
  1344. hasReplace = true;
  1345. }
  1346. }
  1347. if (hasReplace)
  1348. {
  1349. replaceFormulasHide(ref expression);
  1350. }
  1351. }
  1352. private void FormatExpression(ref string expression)
  1353. {
  1354. // 替换相互嵌套的公式
  1355. replaceFormulas(ref expression);
  1356. replaceFormulasHide(ref expression);
  1357. expression = ConvertToEnglishSymbols(expression);
  1358. // 定义正则表达式模式,匹配包含【】的内容
  1359. string pattern = @"【(.*?)】";
  1360. // 创建正则表达式对象
  1361. Regex regex = new Regex(pattern);
  1362. // 使用正则表达式匹配输入字符串
  1363. MatchCollection matches = regex.Matches(expression);
  1364. var new_replacements = new Dictionary<string, object>();
  1365. foreach (Match match in matches)
  1366. {
  1367. if (replacements.TryGetValue(match.Value, out object value2))
  1368. {
  1369. new_replacements[match.Value] = value2;
  1370. }
  1371. }
  1372. foreach (var replacement in new_replacements)
  1373. {
  1374. expression = expression.Replace(replacement.Key, Convert.ToString(replacement.Value));
  1375. }
  1376. }
  1377. private TData Calculate(string expression,string name = "")
  1378. {
  1379. FormatExpression(ref expression);
  1380. try
  1381. {
  1382. return LJExprParser.Parse(expression).Result;
  1383. } catch (Exception ex)
  1384. {
  1385. throw new LJCommonException($"计算{name}公式错误!expression: {expression},exception: {ex.Message}");
  1386. }
  1387. }
  1388. public static bool IsNumber(string input)
  1389. {
  1390. // 正则表达式匹配数字,包括正负号和小数点
  1391. string pattern = @"^[+-]?(\d+(\.\d*)?|\.\d+)$";
  1392. return Regex.IsMatch(input, pattern);
  1393. }
  1394. private object SqlCalculate(string expression, string name = "")
  1395. {
  1396. expression = ConvertToEnglishSymbols(expression);
  1397. expression = ReplaceWith(expression, "@@", "");
  1398. // 定义正则表达式模式,匹配包含【】的内容
  1399. string pattern = @"【(.*?)】";
  1400. // 创建正则表达式对象
  1401. Regex regex = new Regex(pattern);
  1402. // 使用正则表达式匹配输入字符串
  1403. MatchCollection matches = regex.Matches(expression);
  1404. var new_formula_replacements = new Dictionary<string, string>();
  1405. var new_replacements = new Dictionary<string, object>();
  1406. foreach (Match match in matches)
  1407. {
  1408. // 检查原始字典中是否存在该键,并添加到新字典中
  1409. if (formula_replacements.TryGetValue(match.Value, out formulaItem item))
  1410. {
  1411. new_formula_replacements[match.Value] = item.value;
  1412. }
  1413. if (replacements.TryGetValue(match.Value, out object value2))
  1414. {
  1415. new_replacements[match.Value] = value2;
  1416. }
  1417. }
  1418. foreach (var replacement in new_formula_replacements)
  1419. {
  1420. expression = expression.Replace(replacement.Key, replacement.Value);
  1421. }
  1422. foreach (var replacement in new_replacements)
  1423. {
  1424. var _rep = Convert.ToString(replacement.Value);
  1425. if (!IsNumber(_rep))
  1426. {
  1427. _rep = "'" + _rep + "'";
  1428. }
  1429. expression = expression.Replace(replacement.Key, " " + _rep);
  1430. }
  1431. try
  1432. {
  1433. cmd.CommandText = $@"{expression}";
  1434. cmd.Parameters.Clear();
  1435. return cmd.ExecuteScalar();
  1436. }
  1437. catch (Exception ex)
  1438. {
  1439. throw new LJCommonException($"计算{name}公式错误!expression: {expression},exception: {ex.Message}");
  1440. }
  1441. }
  1442. public u_bednet GetBedNet(int bednetid)
  1443. {
  1444. var bednet = new u_bednet() { bednetid = bednetid };
  1445. var outputFields = @"bednetid,deptid,bednettypeid,mattress_width,mattress_length,mattress_height,if_doublenet,if_doublespring,snake_wire_diameter,
  1446. snake_wire_mtrl_formula,snake_wire_mtrl_cost,pocket_around_spring_formula,pocket_around_spring_cost,pocket_around_fabrics_formula,
  1447. pocket_around_fabrics_cost,hard_around_mtrl_formula,hard_around_mtrl_cost,hard_around_hr_formula,hard_around_hr_cost,
  1448. spring_mtrl_cost,spring_hr_cost,glue_price,glue_mtrl_formula,glue_mtrl_cost,fabrics1_mtrl_formula,fabrics1_mtrl_cost,
  1449. fabrics2_mtrl_formula,fabrics2_mtrl_cost,if_side_iron,side_iron_lossrate,side_iron_price,side_iron_mtrl_formula,
  1450. side_iron_mtrl_cost,side_iron_hr_formula,side_iron_hr_cost,cnail_price,cnail_mtrl_formula,cnail_mtrl_cost,cnail_hr_formula,
  1451. cnail_hr_cost,sponge_mtrlid,sponge_thickness,sponge_price,sponge_mtrl_formula,sponge_mtrl_cost,sponge_hr_formula,
  1452. sponge_hr_cost,edge_mtrlid,edge_price,edge_mtrl_formula,edge_mtrl_cost,edge_hr_formula,edge_hr_cost,fork_qty,fork_price,
  1453. fork_mtrl_formula,fork_mtrl_cost,fork_hr_formula,fork_hr_cost,if_rsORwa,rsORwa_price,rsORwa_mtrl_formula,rsORwa_mtrl_cost,
  1454. rsORwa_hr_formula,rsORwa_hr_cost,if_sponge_drilling,sponge_drilling_hr_formula,sponge_drilling_hr_cost,total_hr_cost,
  1455. total_mtrl_cost,total_fees_cost,total_cost,createtime,createby,bednetcode,bednetname,spring_mtrl_formula,spring_hr_formula,
  1456. sponge_mtrl_cost_replace_formula,sponge_hr_cost_replace_formula,edge_mtrl_cost_replace_formula,edge_hr_cost_replace_formula,
  1457. fork_mtrl_cost_replace_formula,fork_hr_cost_replace_formula,rsORwa_mtrl_cost_replace_formula,rsORwa_hr_cost_replace_formula,
  1458. sponge_drilling_hr_cost_replace_formula,snake_wire_mtrl_cost_replace_formula,flag,taxrate,taxes,commissionrate,commission,fob,
  1459. profitrate,nottax_factory_cost,nottax_dept_cost,dept_cost,foreign_cost,extras_cost,dept_profitrate,moneyrate,temp_flag,felt_mtrlid,
  1460. felt_qty,felt_price,felt_dscrp,felt_mtrl_formula,felt_mtrl_cost,felt_hr_formula,felt_hr_cost,felt_mtrl_cost_replace_formula,
  1461. felt_hr_cost_replace_formula,extras_cost_dscrp,iffork,ifsaleout,autotype,felt_mtrl_x_cost,felt_hr_x_cost,felt_x_qty,
  1462. felt_mtrl_x_cost_replace_formula,felt_hr_x_cost_replace_formula,felt_x_mtrlid,sale_point,packtype,packqty,other_rate,
  1463. transport_type,packmtrl,packet_mtrl_formula,packet_hr_formula,packet_mtrl_cost,packet_hr_cost,packet_mtrl_cost_replace_formula,
  1464. packet_hr_cost_replace_formula,sponge_height,edge_height,sponge_tc_thickness,sponge_tc_height,sponge_tc_mtrlid,sponge_mtrl_tc_cost,
  1465. sponge_mtrl_tc_formula,sponge_mtrl_tc_cost_replace_formula,sum_weight,spring_weight,snake_weight,side_weight,duo_qv_str,
  1466. spring_weight_formula,side_iron_weight_formula,hard_around_weight_formula,fabrics1_weight_formula,fabrics2_weight_formula,
  1467. felt_weight_formula,cnail_weight_formula,sponge_weight_formula,sponge_weight_tc_formula,edge_weight_formula,fork_weight_formula,
  1468. spring_weight_replace_formula,side_iron_weight_replace_formula,hard_around_weight_replace_formula,fabrics1_weight_replace_formula,
  1469. fabrics2_weight_replace_formula,felt_weight_replace_formula,cnail_weight_replace_formula,sponge_weight_replace_formula,
  1470. sponge_weight_tc_replace_formula,edge_weight_replace_formula,fork_weight_replace_formula,spring_weight_qty,
  1471. side_iron_weight_qty,hard_around_weight_qty,fabrics1_weight_qty,fabrics2_weight_qty,felt_weight_qty,
  1472. cnail_weight_qty,sponge_weight_qty,sponge_weight_tc_qty,edge_weight_qty,fork_weight_qty,if_jb";
  1473. DbSqlHelper.SelectOne(cmd, bednet, outputFields);
  1474. return bednet;
  1475. }
  1476. public List<u_bednetmx_spring> GetBedNetSpringList(int bednetid)
  1477. {
  1478. var springList = new List<u_bednetmx_spring>();
  1479. var outputFields = @"bednetmx_partid,bednetmxid,springid,spring_qty_width,spring_qty_length,fabrics1_mtrl_cost,spring_mtrl_cost,spring_hr_cost,spring_mtrl_cost_replace_formula,spring_hr_cost_replace_formula,spring_weight_replace_formula";
  1480. var selectStr = @"SELECT bednetmx_partid
  1481. ,u_bednetmx_spring.bednetmxid AS bednetmxid
  1482. ,u_bednetmx_spring.springid AS springid
  1483. ,u_bednetmx_spring.spring_qty_width AS spring_qty_width
  1484. ,u_bednetmx_spring.spring_qty_length AS spring_qty_length
  1485. ,u_bednetmx_spring.fabrics1_mtrl_cost AS fabrics1_mtrl_cost
  1486. ,u_bednetmx_spring.spring_mtrl_cost AS spring_mtrl_cost
  1487. ,u_bednetmx_spring.spring_hr_cost AS spring_hr_cost
  1488. ,u_bednetmx_spring.spring_mtrl_cost_replace_formula AS spring_mtrl_cost_replace_formula
  1489. ,u_bednetmx_spring.spring_hr_cost_replace_formula AS spring_hr_cost_replace_formula
  1490. ,u_bednetmx_spring.spring_weight_replace_formula AS spring_weight_replace_formula
  1491. FROM u_bednetmx_spring
  1492. INNER JOIN u_bednetmx ON u_bednetmx.bednetmxid = u_bednetmx_spring.bednetmxid";
  1493. DbSqlHelper.SelectJoin(cmd,selectStr, "u_bednetmx.bednetid = @bednetid",new Dictionary<string, object>() { { "@bednetid",bednetid } }, "bednetmx_partid",outputFields,0,0,springList);
  1494. return springList;
  1495. }
  1496. public List<u_bednetmx_mtrl> GetBedNetMxMtrlList(int bednetid)
  1497. {
  1498. var mxList = new List<u_bednetmx_mtrl>();
  1499. var outputFields = @"bednetmtrlid,bednetid,formulakind,formula,mtrlid,price,gram_weight,cloth_width,if_inputqty,qty,costamt,if_success,replace_formula,priceunit,shrinkage";
  1500. var selectStr = @"SELECT u_bednetmx_mtrl.bednetmtrlid AS bednetmtrlid
  1501. ,u_bednetmx_mtrl.bednetid AS bednetid
  1502. ,u_bednetmx_mtrl.formulakind AS formulakind
  1503. ,u_bednetmx_mtrl.formula AS formula
  1504. ,u_bednetmx_mtrl.mtrlid
  1505. ,u_bednetmx_mtrl.price
  1506. ,u_bednetmx_mtrl.gram_weight
  1507. ,u_bednetmx_mtrl.cloth_width
  1508. ,u_bednetmx_mtrl.if_inputqty
  1509. ,u_bednetmx_mtrl.qty
  1510. ,u_bednetmx_mtrl.costamt
  1511. ,u_bednetmx_mtrl.if_success
  1512. ,u_bednetmx_mtrl.replace_formula
  1513. ,u_bednetmx_mtrl.priceunit
  1514. ,u_bednetmx_mtrl.shrinkage
  1515. FROM u_bednetmx_mtrl";
  1516. DbSqlHelper.SelectJoin(cmd, selectStr, "u_bednetmx_mtrl.bednetid = @bednetid", new Dictionary<string, object>() { { "@bednetid", bednetid } }, "bednetmtrlid", outputFields, 0, 0, mxList);
  1517. return mxList;
  1518. }
  1519. public List<u_bednetmx> GetBedNetMxList(int bednetid)
  1520. {
  1521. var mxList = new List<u_bednetmx>();
  1522. var outputFields = @"bednetmxid,bednetid,spring_qty_width,spring_qty_length,bednet_height,wire_mtrlid,springid,if_part,if_15strip,if_pocket_around,
  1523. pocket_around_springid,pocket_around_row,pocket_around_wire_price,pocket_around_spring_cost,pocket_around_fabrics_cost,
  1524. if_hard_around,hard_around_springid,hard_around_row,hard_around_wire_price,hard_around_mtrl_cost,hard_around_hr_cost,
  1525. fabrics1_mtrlid,fabrics1_price,fabrics1_mtrl_cost,fabrics2_mtrlid,fabrics2_price,fabrics2_mtrl_cost,if_side_iron,
  1526. side_iron_qty,side_iron_mtrl_cost,side_iron_hr_cost,pocket_around_spring_cost_replace_formula,pocket_around_fabrics_cost_replace_formula,
  1527. hard_around_mtrl_cost_replace_formula,hard_around_hr_cost_replace_formula,fabrics1_mtrl_cost_replace_formula,
  1528. fabrics2_mtrl_cost_replace_formula,side_iron_mtrl_cost_replace_formula,side_iron_hr_cost_replace_formula,
  1529. cnail_mtrl_cost_replace_formula,cnail_mtrl_cost,cnail_hr_cost_replace_formula,cnail_hr_cost,
  1530. glue_mtrl_cost_replace_formula,glue_mtrl_cost,spring_mtrl_cost,spring_hr_cost,spring_mtrl_cost_replace_formula,
  1531. spring_hr_cost_replace_formula,if_show,spring_weight_replace_formula";
  1532. var selectStr = @"SELECT bednetmxid
  1533. ,bednetid
  1534. ,spring_qty_width
  1535. ,spring_qty_length
  1536. ,bednet_height
  1537. ,wire_mtrlid
  1538. ,springid
  1539. ,if_part
  1540. ,if_15strip
  1541. ,if_pocket_around
  1542. ,pocket_around_springid
  1543. ,pocket_around_row
  1544. ,pocket_around_wire_price
  1545. ,pocket_around_spring_cost
  1546. ,pocket_around_fabrics_cost
  1547. ,if_hard_around
  1548. ,hard_around_springid
  1549. ,hard_around_row
  1550. ,hard_around_wire_price
  1551. ,hard_around_mtrl_cost
  1552. ,hard_around_hr_cost
  1553. ,fabrics1_mtrlid
  1554. ,fabrics1_price
  1555. ,fabrics1_mtrl_cost
  1556. ,fabrics2_mtrlid
  1557. ,fabrics2_price
  1558. ,fabrics2_mtrl_cost
  1559. ,if_side_iron
  1560. ,side_iron_qty
  1561. ,side_iron_mtrl_cost
  1562. ,side_iron_hr_cost
  1563. ,pocket_around_spring_cost_replace_formula
  1564. ,pocket_around_fabrics_cost_replace_formula
  1565. ,hard_around_mtrl_cost_replace_formula
  1566. ,hard_around_hr_cost_replace_formula
  1567. ,fabrics1_mtrl_cost_replace_formula
  1568. ,fabrics2_mtrl_cost_replace_formula
  1569. ,side_iron_mtrl_cost_replace_formula
  1570. ,side_iron_hr_cost_replace_formula
  1571. ,cnail_mtrl_cost_replace_formula
  1572. ,cnail_mtrl_cost
  1573. ,cnail_hr_cost_replace_formula
  1574. ,cnail_hr_cost
  1575. ,glue_mtrl_cost_replace_formula
  1576. ,glue_mtrl_cost
  1577. ,spring_mtrl_cost
  1578. ,spring_hr_cost
  1579. ,spring_mtrl_cost_replace_formula
  1580. ,spring_hr_cost_replace_formula
  1581. ,1 AS if_show
  1582. ,spring_weight_replace_formula
  1583. FROM u_bednetmx";
  1584. DbSqlHelper.SelectJoin(cmd, selectStr, "u_bednetmx.bednetid = @bednetid", new Dictionary<string, object>() { { "@bednetid", bednetid } }, "bednetmxid", outputFields, 0, 0, mxList);
  1585. return mxList;
  1586. }
  1587. public void SaveBedNet(u_bednet bednet, List<u_bednetmx> mxlist, List<u_bednetmx_spring> springList)
  1588. {
  1589. var dtNow = DateTime.Now;
  1590. var fields = @"deptid,bednettypeid,mattress_width,mattress_length,mattress_height,if_doublenet,if_doublespring,snake_wire_diameter,
  1591. snake_wire_mtrl_formula,snake_wire_mtrl_cost,pocket_around_spring_formula,pocket_around_spring_cost,
  1592. pocket_around_fabrics_formula,pocket_around_fabrics_cost,hard_around_mtrl_formula,hard_around_mtrl_cost,
  1593. hard_around_hr_formula,hard_around_hr_cost,spring_mtrl_cost,spring_hr_cost,glue_price,glue_mtrl_formula,
  1594. glue_mtrl_cost,fabrics1_mtrl_formula,fabrics1_mtrl_cost,fabrics2_mtrl_formula,fabrics2_mtrl_cost,
  1595. if_side_iron,side_iron_lossrate,side_iron_price,side_iron_mtrl_formula,side_iron_mtrl_cost,side_iron_hr_formula,
  1596. side_iron_hr_cost,cnail_price,cnail_mtrl_formula,cnail_mtrl_cost,cnail_hr_formula,cnail_hr_cost,sponge_mtrlid,
  1597. sponge_thickness,sponge_price,sponge_mtrl_formula,sponge_mtrl_cost,sponge_hr_formula,sponge_hr_cost,edge_mtrlid,
  1598. edge_price,edge_mtrl_formula,edge_mtrl_cost,edge_hr_formula,edge_hr_cost,fork_qty,fork_price,fork_mtrl_formula,
  1599. fork_mtrl_cost,fork_hr_formula,fork_hr_cost,if_rsORwa,rsORwa_price,rsORwa_mtrl_formula,rsORwa_mtrl_cost,rsORwa_hr_formula,
  1600. rsORwa_hr_cost,if_sponge_drilling,sponge_drilling_hr_formula,sponge_drilling_hr_cost,total_hr_cost,total_mtrl_cost,
  1601. total_fees_cost,total_cost,createtime,createby,bednetname,spring_mtrl_formula,spring_hr_formula,
  1602. sponge_mtrl_cost_replace_formula,sponge_hr_cost_replace_formula,edge_mtrl_cost_replace_formula,edge_hr_cost_replace_formula,
  1603. fork_mtrl_cost_replace_formula,fork_hr_cost_replace_formula,rsORwa_mtrl_cost_replace_formula,rsORwa_hr_cost_replace_formula,
  1604. sponge_drilling_hr_cost_replace_formula,snake_wire_mtrl_cost_replace_formula,taxrate,taxes,commissionrate,commission,fob,
  1605. profitrate,nottax_factory_cost,nottax_dept_cost,dept_cost,foreign_cost,extras_cost,dept_profitrate,moneyrate,temp_flag,
  1606. felt_mtrlid,felt_qty,felt_price,felt_dscrp,felt_mtrl_formula,felt_mtrl_cost,felt_hr_formula,felt_hr_cost,
  1607. felt_mtrl_cost_replace_formula,felt_hr_cost_replace_formula,extras_cost_dscrp,iffork,ifsaleout,autotype,
  1608. felt_mtrl_x_cost,felt_hr_x_cost,felt_x_qty,felt_mtrl_x_cost_replace_formula,felt_hr_x_cost_replace_formula,
  1609. felt_x_mtrlid,sale_point,packtype,packqty,other_rate,transport_type,packmtrl,packet_mtrl_formula,
  1610. packet_hr_formula,packet_mtrl_cost,packet_hr_cost,packet_mtrl_cost_replace_formula,packet_hr_cost_replace_formula,
  1611. sponge_height,edge_height,sponge_tc_thickness,sponge_tc_height,sponge_tc_mtrlid,sponge_mtrl_tc_formula,
  1612. sponge_mtrl_tc_cost,sponge_mtrl_tc_cost_replace_formula,duo_qv_str,spring_weight_formula,side_iron_weight_formula,
  1613. hard_around_weight_formula,fabrics1_weight_formula,fabrics2_weight_formula,felt_weight_formula,cnail_weight_formula,
  1614. sponge_weight_formula,sponge_weight_tc_formula,edge_weight_formula,fork_weight_formula,spring_weight_replace_formula,
  1615. side_iron_weight_replace_formula,hard_around_weight_replace_formula,fabrics1_weight_replace_formula,
  1616. fabrics2_weight_replace_formula,felt_weight_replace_formula,cnail_weight_replace_formula,sponge_weight_replace_formula,
  1617. sponge_weight_tc_replace_formula,edge_weight_replace_formula,fork_weight_replace_formula,spring_weight_qty,
  1618. side_iron_weight_qty,hard_around_weight_qty,fabrics1_weight_qty,fabrics2_weight_qty,felt_weight_qty,cnail_weight_qty,
  1619. sponge_weight_qty,sponge_weight_tc_qty,edge_weight_qty,fork_weight_qty,sum_weight,if_jb,flag";
  1620. var fieldsMx = @"bednetmxid,bednetid,spring_qty_width,spring_qty_length,bednet_height,wire_mtrlid,springid,if_part,if_15strip,
  1621. if_pocket_around,pocket_around_springid,pocket_around_row,pocket_around_wire_price,pocket_around_spring_cost,
  1622. pocket_around_fabrics_cost,if_hard_around,hard_around_springid,hard_around_row,hard_around_wire_price,
  1623. hard_around_mtrl_cost,hard_around_hr_cost,fabrics1_mtrlid,fabrics1_price,fabrics1_mtrl_cost,fabrics2_mtrlid,
  1624. fabrics2_price,fabrics2_mtrl_cost,if_side_iron,side_iron_qty,side_iron_mtrl_cost,side_iron_hr_cost,
  1625. pocket_around_spring_cost_replace_formula,pocket_around_fabrics_cost_replace_formula,hard_around_mtrl_cost_replace_formula,
  1626. hard_around_hr_cost_replace_formula,fabrics1_mtrl_cost_replace_formula,fabrics2_mtrl_cost_replace_formula,
  1627. side_iron_mtrl_cost_replace_formula,side_iron_hr_cost_replace_formula,cnail_mtrl_cost_replace_formula,cnail_mtrl_cost,
  1628. cnail_hr_cost_replace_formula,cnail_hr_cost,glue_mtrl_cost_replace_formula,glue_mtrl_cost,spring_mtrl_cost,spring_hr_cost,
  1629. spring_mtrl_cost_replace_formula,spring_hr_cost_replace_formula,spring_weight_replace_formula";
  1630. var fieldsMx_spring = @"bednetmx_partid,bednetmxid,springid,spring_qty_width,spring_qty_length,fabrics1_mtrl_cost,spring_mtrl_cost,
  1631. spring_hr_cost,spring_mtrl_cost_replace_formula,spring_hr_cost_replace_formula,spring_weight_replace_formula";
  1632. if (bednet.bednetid <= 0)
  1633. {
  1634. //新建
  1635. fields += ",bednetid,bednetcode";
  1636. bednet.bednetid = BllHelper.GetID(cmd, "u_bednet");
  1637. bednet.createtime = dtNow;
  1638. bednet.createby = context.tokendata.username;
  1639. if(string.IsNullOrEmpty(bednet.bednetcode))
  1640. {
  1641. var nettype = new u_bednet_type() { bednettypeid = bednet.bednettypeid };
  1642. DbSqlHelper.SelectOne(cmd, nettype, "typecode");
  1643. // 编号-年月日+流水
  1644. bednet.bednetcode = $"{nettype.typecode}-{dtNow.ToString("yyyyMMdd")}{(bednet.bednetid.Value % 10000).ToString("D4")}";
  1645. }
  1646. DbSqlHelper.Insert(cmd, "u_bednet", null, bednet, fields);
  1647. }
  1648. else
  1649. {
  1650. //修改
  1651. foreach (var mx in mxlist)
  1652. {
  1653. cmd.CommandText = @"DELETE FROM u_bednetmx_spring WHERE bednetmxid = @bednetmxid";
  1654. cmd.Parameters.Clear();
  1655. cmd.Parameters.AddWithValue("@bednetmxid", mx.bednetmxid);
  1656. cmd.ExecuteNonQuery();
  1657. }
  1658. cmd.CommandText = @"DELETE FROM u_bednetmx WHERE bednetid = @bednetid";
  1659. cmd.Parameters.Clear();
  1660. cmd.Parameters.AddWithValue("@bednetid", bednet.bednetid);
  1661. cmd.ExecuteNonQuery();
  1662. DbSqlHelper.Update(cmd, "u_bednet", null, bednet, "bednetid", fields);
  1663. }
  1664. foreach (var mx in mxlist)
  1665. {
  1666. mx.bednetid = bednet.bednetid;
  1667. mx.bednetmxid = BllHelper.GetID(cmd, "u_bednetmx");
  1668. DbSqlHelper.Insert(cmd, "u_bednetmx", null, mx, fieldsMx);
  1669. if (springList != null && springList.Any())
  1670. {
  1671. foreach (var spring in springList)
  1672. {
  1673. spring.bednetmxid = mx.bednetmxid;
  1674. spring.bednetmx_partid = BllHelper.GetID(cmd, "u_bednetmx_spring");
  1675. DbSqlHelper.Insert(cmd, "u_bednetmx_spring", null, spring, fieldsMx_spring);
  1676. }
  1677. }
  1678. }
  1679. var hisprice = new u_his_price
  1680. {
  1681. bednetid_mattressid = bednet.bednetid,
  1682. typeid = 0,
  1683. cmpdate = dtNow,
  1684. cmpemp = context.tokendata.username,
  1685. nottax_dept_cost = bednet.nottax_dept_cost,
  1686. dept_cost = bednet.dept_cost,
  1687. foreign_cost = bednet.foreign_cost
  1688. };
  1689. var fieldsHs = "bednetid_mattressid, typeid, cmpdate, cmpemp, nottax_dept_cost, dept_cost, foreign_cost";
  1690. DbSqlHelper.Insert(cmd, "u_his_price", null, hisprice, fieldsHs);
  1691. }
  1692. public void CopyBedNet(u_bednet bednet,u_bednetmx bednetmx,out int newId)
  1693. {
  1694. var bedNet_copy = GetBedNet(bednet.bednetid.Value);
  1695. var bedNetMxList = GetBedNetMxList(bednet.bednetid.Value);
  1696. var springList = GetBedNetSpringList(bednet.bednetid.Value);
  1697. // 判断copy_bedNet.bednetcode是否存在@@字符串,如果存在,则删除@@后面的字符串,包括@@
  1698. if (bedNet_copy.bednetcode.IndexOf("@@") > -1)
  1699. {
  1700. bedNet_copy.bednetcode = bedNet_copy.bednetcode.Substring(bedNet_copy.bednetcode.IndexOf("@@"));
  1701. }
  1702. bedNet_copy.bednetcode += " @@";
  1703. bedNet_copy.bednetcode += DateTime.Now.ToString("yyyMMdd_mmhhss");
  1704. bedNet_copy.bednetid = 0;
  1705. bedNet_copy.mattress_width = bednet.mattress_width;
  1706. bedNet_copy.mattress_length = bednet.mattress_length;
  1707. foreach(var mx in bedNetMxList)
  1708. {
  1709. if(bednetmx.spring_qty_width > 0 && bednetmx.spring_qty_length > 0)
  1710. {
  1711. mx.spring_qty_length = bednetmx.spring_qty_length;
  1712. mx.spring_qty_width = bednetmx.spring_qty_width;
  1713. }
  1714. }
  1715. SaveBedNet(bedNet_copy, bedNetMxList, springList);
  1716. newId = bedNet_copy.bednetid.Value;
  1717. }
  1718. public List<u_bednet_qingdan> GetBedNetQingDan(int bednetid)
  1719. {
  1720. string bednetName = string.Empty;
  1721. string areaType = string.Empty;
  1722. string rollPackage = string.Empty;
  1723. string specifications = string.Empty;
  1724. string arrangement = string.Empty;
  1725. string bednetHeight = string.Empty;
  1726. string springs = string.Empty;
  1727. string edgeIron = string.Empty;
  1728. string bottomNonwovenFabric = string.Empty;
  1729. string topPadMaterial = string.Empty;
  1730. string bottomPadMaterial = string.Empty;
  1731. string bagNonwovenFabric = string.Empty;
  1732. string surroundingReinforcementRows = string.Empty;
  1733. string springPins = string.Empty;
  1734. string foamBorderMaterial = string.Empty;
  1735. string fillingFoamMaterial = string.Empty;
  1736. var bednet = GetBedNet(bednetid);
  1737. var mxList = GetBedNetMxList(bednetid);
  1738. var springList = GetBedNetSpringList(bednetid);
  1739. var dept = new u_dept() { deptid = bednet.deptid.Value };
  1740. DbSqlHelper.SelectOne(cmd, dept, "pricelistid");
  1741. if(bednet.deptid == null || bednet.deptid.Value <= 0)
  1742. {
  1743. throw new LJCommonException("获取床网清单,deptid错误");
  1744. }
  1745. if (bednet.bednettypeid == null || bednet.bednettypeid.Value <= 0)
  1746. {
  1747. throw new LJCommonException("获取床网清单,bednettypeid错误");
  1748. }
  1749. if (dept.pricelistid <= 0)
  1750. {
  1751. throw new LJCommonException("获取床网清单,pricelistid错误");
  1752. }
  1753. var bednetType = new u_bednet_type() { bednettypeid = bednet.bednettypeid };
  1754. DbSqlHelper.SelectOne(cmd, bednetType, "typename");
  1755. var mx = mxList[0];
  1756. var qdList = new List<u_bednet_qingdan>();
  1757. var nameList = new Dictionary<string,string>();
  1758. qdList.Add(new u_bednet_qingdan()
  1759. {
  1760. pzname = "床网名称"
  1761. });
  1762. qdList.Add(new u_bednet_qingdan()
  1763. {
  1764. pzname = "床网类型",
  1765. pznamemx = bednetType.typename,
  1766. amt = 0,
  1767. useqty = 0
  1768. });
  1769. bednetName = bednetType.typename;
  1770. qdList.Add(new u_bednet_qingdan()
  1771. {
  1772. pzname = "规格",
  1773. pznamemx = $"{bednet.mattress_width - 2}*{bednet.mattress_length}*{bednet.mattress_height - 2}",
  1774. amt = 0,
  1775. useqty = 0
  1776. });
  1777. specifications = $"{bednet.mattress_width - 2}*{bednet.mattress_length}";
  1778. qdList.Add(new u_bednet_qingdan()
  1779. {
  1780. pzname = "排列",
  1781. pznamemx = $"{mx.spring_qty_width}*{mx.spring_qty_length}",
  1782. amt = 0,
  1783. useqty = 0
  1784. });
  1785. arrangement = $"{mx.spring_qty_width}*{mx.spring_qty_length}";
  1786. qdList.Add(new u_bednet_qingdan()
  1787. {
  1788. pzname = "床网高度",
  1789. pznamemx = $"{mx.bednet_height.Value.ToString("#,##0.##")}高",
  1790. amt = 0,
  1791. useqty = 0
  1792. });
  1793. bednetHeight = $"{mx.bednet_height.Value.ToString("#,##0.##")}高";
  1794. qdList.Add(new u_bednet_qingdan()
  1795. {
  1796. pzname = "弹簧线径/高度/口径/中心直径/圈数",
  1797. pznamemx = mx.if_part == 0 ? GetSpringName(mx.springid.Value) : string.Empty,
  1798. amt = 0,
  1799. useqty = 0
  1800. });
  1801. if (mx.if_part == 0)
  1802. {
  1803. springs = GetSpringName(mx.springid.Value);
  1804. }
  1805. else
  1806. {
  1807. string ls_left = string.Empty;
  1808. string ls_right = string.Empty;
  1809. string ls_t_temp = string.Empty;
  1810. string ls_t_name = string.Empty;
  1811. if (springList.Count >= 1)
  1812. {
  1813. ls_t_name = GetSpringName(springList[0].springid.Value);
  1814. int pos = ls_t_name.IndexOf('/');
  1815. if (pos > 0)
  1816. {
  1817. ls_left = ls_t_name.Substring(0, pos);
  1818. ls_right = ls_t_name.Substring(pos);
  1819. ls_t_temp = ls_left;
  1820. // Use StringBuilder to efficiently build ls_t_temp
  1821. StringBuilder sb = new StringBuilder(ls_t_temp);
  1822. for (int i = 1; i <= springList.Count; i++)
  1823. {
  1824. ls_t_name = GetSpringName(springList[i].springid.Value);
  1825. pos = ls_t_name.IndexOf('/');
  1826. if (pos > 0)
  1827. {
  1828. ls_left = ls_t_name.Substring(0, pos);
  1829. sb.Append("+").Append(ls_left);
  1830. }
  1831. }
  1832. ls_t_temp = sb.ToString();
  1833. }
  1834. }
  1835. springs = ls_t_temp + "/" + ls_right;
  1836. }
  1837. for (int i = 1;i <= 5;i++)
  1838. {
  1839. qdList.Add(new u_bednet_qingdan()
  1840. {
  1841. pzname = $"多区弹簧{i}/高度/口径/中心直径/圈数",
  1842. pznamemx = springList.Count >= 1 && i <= springList.Count ? GetSpringName(springList[i - 1].springid.Value) : string.Empty,
  1843. amt = 0,
  1844. useqty = 0
  1845. });
  1846. }
  1847. qdList.Add(new u_bednet_qingdan()
  1848. {
  1849. pzname = "边铁条数",
  1850. pznamemx = mx.side_iron_qty > 0 ? $"{mx.side_iron_qty.Value.ToString("#,##0.##")}条" : string.Empty,
  1851. amt = 0,
  1852. useqty = 0
  1853. });
  1854. edgeIron = mx.side_iron_qty > 0 ? $"{mx.side_iron_qty.Value.ToString("#,##0.##")}条边铁" : "无边铁";
  1855. var mtrldef1 = new u_mtrl_price();
  1856. DbSqlHelper.SelectOne(cmd, "u_mtrl_price", "mtrltype = 2 AND mtrlid = @mtrlid", new Dictionary<string, object>() { { "mtrlid", mx.fabrics2_mtrlid } },mtrldef1, "name");
  1857. qdList.Add(new u_bednet_qingdan()
  1858. {
  1859. pzname = "底面无纺布",
  1860. pznamemx = mx.fabrics2_mtrlid > 0 ? mtrldef1.name : string.Empty,
  1861. amt = 0,
  1862. useqty = 0
  1863. });
  1864. bottomNonwovenFabric = mx.fabrics2_mtrlid > 0 ? mtrldef1.name : string.Empty;
  1865. var mtrldef2 = new u_mtrl_price();
  1866. DbSqlHelper.SelectOne(cmd, "u_mtrl_price", "mtrltype = 2 AND mtrlid = @mtrlid", new Dictionary<string, object>() { { "mtrlid", mx.fabrics1_mtrlid } }, mtrldef2, "name");
  1867. qdList.Add(new u_bednet_qingdan()
  1868. {
  1869. pzname = "入袋无纺布",
  1870. pznamemx = mx.fabrics1_mtrlid > 0 ? mtrldef2.name : string.Empty,
  1871. amt = 0,
  1872. useqty = 0
  1873. });
  1874. bagNonwovenFabric = mx.fabrics1_mtrlid > 0 ? mtrldef2.name : string.Empty;
  1875. var mtrldef3 = new u_mtrl_price();
  1876. DbSqlHelper.SelectOne(cmd, "u_mtrl_price", "mtrlid = @mtrlid", new Dictionary<string, object>() { { "mtrlid", bednet.felt_mtrlid } }, mtrldef3, "name");
  1877. qdList.Add(new u_bednet_qingdan()
  1878. {
  1879. pzname = "上垫层物料",
  1880. pznamemx = !string.IsNullOrEmpty(mtrldef3.name) ? mtrldef3.name : string.Empty,
  1881. amt = 0,
  1882. useqty = 0
  1883. });
  1884. topPadMaterial = !string.IsNullOrEmpty(mtrldef3.name) ? mtrldef3.name : string.Empty;
  1885. var mtrldef4 = new u_mtrl_price();
  1886. DbSqlHelper.SelectOne(cmd, "u_mtrl_price", "mtrlid = @mtrlid", new Dictionary<string, object>() { { "mtrlid", bednet.felt_x_mtrlid } }, mtrldef4, "name");
  1887. qdList.Add(new u_bednet_qingdan()
  1888. {
  1889. pzname = "下垫层物料",
  1890. pznamemx = !string.IsNullOrEmpty(mtrldef4.name) ? mtrldef4.name : string.Empty,
  1891. amt = 0,
  1892. useqty = 0
  1893. });
  1894. bottomPadMaterial = !string.IsNullOrEmpty(mtrldef4.name) ? mtrldef4.name : string.Empty;
  1895. qdList.Add(new u_bednet_qingdan()
  1896. {
  1897. pzname = "四周加硬排数",
  1898. pznamemx = mx.hard_around_row > 0 ? $"{mx.hard_around_row.Value.ToString("#,##0.##")}排{GetSpringName(mx.hard_around_springid.Value)}" : string.Empty,
  1899. amt = 0,
  1900. useqty = 0
  1901. });
  1902. surroundingReinforcementRows = mx.hard_around_row > 0 ? $"四周加硬{mx.hard_around_row.Value.ToString("#,##0.##")}排{GetSpringName(mx.hard_around_springid.Value)}" : string.Empty;
  1903. qdList.Add(new u_bednet_qingdan()
  1904. {
  1905. pzname = "四周加硬弹簧线径/高度/口径/中心直径/圈数",
  1906. pznamemx = mx.if_hard_around > 0 ? GetSpringName(mx.hard_around_springid.Value) : string.Empty,
  1907. amt = 0,
  1908. useqty = 0
  1909. });
  1910. var mtrldef5 = new u_mtrl_price();
  1911. DbSqlHelper.SelectOne(cmd, "u_mtrl_price", "mtrlid = @mtrlid", new Dictionary<string, object>() { { "mtrlid", bednet.sponge_mtrlid } }, mtrldef5, "name");
  1912. qdList.Add(new u_bednet_qingdan()
  1913. {
  1914. pzname = "海绵包边物料",
  1915. pznamemx = !string.IsNullOrEmpty(mtrldef5.name) ? mtrldef5.name : string.Empty,
  1916. amt = 0,
  1917. useqty = 0
  1918. });
  1919. foamBorderMaterial = !string.IsNullOrEmpty(mtrldef5.name) ? $"{bednet.sponge_thickness.Value.ToString("#,##0.##")}分{bednet.sponge_height.Value.ToString("#,##0.##")}高{mtrldef5.name}" : string.Empty;
  1920. var mtrldef6 = new u_mtrl_price();
  1921. DbSqlHelper.SelectOne(cmd, "u_mtrl_price", "mtrlid = @mtrlid", new Dictionary<string, object>() { { "mtrlid", bednet.sponge_tc_mtrlid } }, mtrldef6, "name");
  1922. qdList.Add(new u_bednet_qingdan()
  1923. {
  1924. pzname = "填充海绵物料",
  1925. pznamemx = !string.IsNullOrEmpty(mtrldef6.name) ? mtrldef6.name : string.Empty,
  1926. amt = 0,
  1927. useqty = 0
  1928. });
  1929. fillingFoamMaterial = !string.IsNullOrEmpty(mtrldef6.name) ? $"{bednet.sponge_tc_thickness.Value.ToString("#,##0.##")}分{bednet.sponge_tc_height.Value.ToString("#,##0.##")}高{mtrldef6.name}" : string.Empty;
  1930. qdList.Add(new u_bednet_qingdan()
  1931. {
  1932. pzname = "填充包边物料厚度",
  1933. pznamemx = bednet.sponge_tc_thickness > 0 ? $"{bednet.sponge_tc_thickness.Value.ToString("#,##0.##")}分厚,{bednet.sponge_tc_height.Value.ToString("#,##0.##")}分高,{mtrldef6.name}" : string.Empty,
  1934. amt = 0,
  1935. useqty = 0
  1936. });
  1937. var mtrldef7 = new u_mtrl_price();
  1938. DbSqlHelper.SelectOne(cmd, "u_mtrl_price", "mtrlid = @mtrlid", new Dictionary<string, object>() { { "mtrlid", bednet.edge_mtrlid } }, mtrldef7, "name");
  1939. qdList.Add(new u_bednet_qingdan()
  1940. {
  1941. pzname = "封边物料",
  1942. pznamemx = !string.IsNullOrEmpty(mtrldef7.name) ? mtrldef7.name : string.Empty,
  1943. amt = 0,
  1944. useqty = 0
  1945. });
  1946. qdList.Add(new u_bednet_qingdan()
  1947. {
  1948. pzname = "封边高度",
  1949. pznamemx = bednet.edge_height > 0 ? $"{bednet.edge_height.Value.ToString("#,##0.##")}高" : string.Empty,
  1950. amt = 0,
  1951. useqty = 0
  1952. });
  1953. qdList.Add(new u_bednet_qingdan()
  1954. {
  1955. pzname = "胶条包角",
  1956. pznamemx = bednet.if_rsorwa > 0 ? "有" : string.Empty,
  1957. amt = 0,
  1958. useqty = 0
  1959. });
  1960. qdList.Add(new u_bednet_qingdan()
  1961. {
  1962. pzname = "海绵打孔",
  1963. pznamemx = bednet.if_sponge_drilling > 0 ? "有" : string.Empty,
  1964. amt = 0,
  1965. useqty = 0
  1966. });
  1967. qdList.Add(new u_bednet_qingdan()
  1968. {
  1969. pzname = "弹叉数量",
  1970. pznamemx = bednet.fork_qty > 0 ? $"{bednet.fork_qty.Value.ToString("#,##0.##")}只弹叉" : string.Empty,
  1971. amt = 0,
  1972. useqty = 0
  1973. });
  1974. springPins = bednet.fork_qty > 0 ? $"{bednet.fork_qty.Value.ToString("#,##0.##")}只弹叉" : string.Empty;
  1975. qdList.Add(new u_bednet_qingdan()
  1976. {
  1977. pzname = "15分布条",
  1978. pznamemx = mx.if_15strip > 0 ? "有" : string.Empty,
  1979. amt = 0,
  1980. useqty = 0
  1981. });
  1982. qdList.Add(new u_bednet_qingdan()
  1983. {
  1984. pzname = "蛇线线径",
  1985. pznamemx = bednet.snake_wire_diameter > 0 ? $"{bednet.snake_wire_diameter}" : string.Empty,
  1986. amt = 0,
  1987. useqty = 0
  1988. });
  1989. qdList.Add(new u_bednet_qingdan()
  1990. {
  1991. pzname = "四周口袋弹簧排数",
  1992. pznamemx = mx.pocket_around_row > 0 ? $"{mx.pocket_around_row.Value.ToString("#,##0.##")}排" : string.Empty,
  1993. amt = 0,
  1994. useqty = 0
  1995. });
  1996. qdList.Add(new u_bednet_qingdan()
  1997. {
  1998. pzname = "四周口袋弹簧线径/高度/口径/中心直径/圈数",
  1999. pznamemx = mx.if_pocket_around > 0 ? GetSpringName(mx.pocket_around_springid.Value) : string.Empty,
  2000. amt = 0,
  2001. useqty = 0
  2002. });
  2003. //设置床网名称
  2004. //床网类型丨规格丨排列丨高度丨单/多区丨线径丨边铁丨海绵包边丨四周加硬丨弹叉丨底面物料
  2005. StringBuilder ls_temp_name = new StringBuilder();
  2006. ls_temp_name.Append(qdList[1].pznamemx)
  2007. .Append("丨")
  2008. .Append(qdList[3].pznamemx)
  2009. .Append("丨")
  2010. .Append(qdList[4].pznamemx);
  2011. if (!string.IsNullOrEmpty(bednet.duo_qv_str))
  2012. {
  2013. areaType = $"{bednet.duo_qv_str}区";
  2014. ls_temp_name.Append("丨")
  2015. .Append(bednet.duo_qv_str)
  2016. .Append("区");
  2017. }
  2018. else
  2019. {
  2020. areaType = string.IsNullOrEmpty(qdList[5].pznamemx) ? "多区" : "单区";
  2021. ls_temp_name.Append("丨")
  2022. .Append(string.IsNullOrEmpty(qdList[5].pznamemx) ? "多区" : "单区");
  2023. }
  2024. if (string.IsNullOrEmpty(qdList[5].pznamemx))
  2025. {
  2026. for (int i = 6; i <= 10; i++)
  2027. {
  2028. if (!string.IsNullOrEmpty(qdList[i].pznamemx))
  2029. {
  2030. ls_temp_name.Append("+" + qdList[i].pznamemx.Substring(0, Math.Min(qdList[i].pznamemx.IndexOf('/') - 1, qdList[i].pznamemx.Length)));
  2031. }
  2032. }
  2033. }
  2034. else
  2035. {
  2036. ls_temp_name.Append("丨")
  2037. .Append(qdList[5].pznamemx);
  2038. }
  2039. AppendSpecialFields(ls_temp_name,qdList);
  2040. rollPackage = bednet.if_jb == 0 ? string.Empty : "卷包";
  2041. if (ls_temp_name.ToString().Contains("袋装"))
  2042. {
  2043. ls_temp_name.Clear();
  2044. ls_temp_name.Append(bednetName)
  2045. .Append("丨")
  2046. .Append(areaType)
  2047. .Append("丨")
  2048. .Append(rollPackage)
  2049. .Append("丨")
  2050. .Append(specifications)
  2051. .Append("丨")
  2052. .Append(arrangement)
  2053. .Append("丨")
  2054. .Append(bednetHeight)
  2055. .Append("丨")
  2056. .Append(springs)
  2057. .Append("丨")
  2058. .Append(edgeIron)
  2059. .Append("丨")
  2060. .Append(bottomNonwovenFabric)
  2061. .Append("丨")
  2062. .Append(topPadMaterial)
  2063. .Append("丨")
  2064. .Append(bottomPadMaterial)
  2065. .Append("丨")
  2066. .Append(bagNonwovenFabric)
  2067. .Append("丨")
  2068. .Append(surroundingReinforcementRows)
  2069. .Append("丨")
  2070. .Append(springPins)
  2071. .Append("丨")
  2072. .Append(foamBorderMaterial)
  2073. .Append("丨")
  2074. .Append(fillingFoamMaterial);
  2075. }
  2076. qdList[0].pznamemx = ls_temp_name.ToString();
  2077. qdList[0].amt = bednet.nottax_factory_cost;
  2078. return qdList;
  2079. }
  2080. private void AppendSpecialFields(StringBuilder ls_temp_name,List<u_bednet_qingdan> qdList)
  2081. {
  2082. if (!string.IsNullOrEmpty(qdList[11].pznamemx))
  2083. {
  2084. ls_temp_name.Append("丨")
  2085. .Append(qdList[11].pznamemx == "" ? "无边铁" : "有边铁");
  2086. }
  2087. if (!string.IsNullOrEmpty(qdList[19].pznamemx))
  2088. {
  2089. ls_temp_name.Append("丨")
  2090. .Append(qdList[19].pznamemx)
  2091. .Append(qdList[19].pznamemx)
  2092. .Append("海绵包边");
  2093. }
  2094. if (!string.IsNullOrEmpty(qdList[16].pznamemx))
  2095. {
  2096. ls_temp_name.Append("丨")
  2097. .Append("四周加硬")
  2098. .Append(qdList[16].pznamemx);
  2099. }
  2100. if (!string.IsNullOrEmpty(qdList[26].pznamemx))
  2101. {
  2102. ls_temp_name.Append("丨")
  2103. .Append(qdList[26].pznamemx);
  2104. }
  2105. if (!string.IsNullOrEmpty(qdList[12].pznamemx))
  2106. {
  2107. ls_temp_name.Append("丨")
  2108. .Append("底面")
  2109. .Append(qdList[12].pznamemx);
  2110. }
  2111. else
  2112. {
  2113. if (string.IsNullOrEmpty(qdList[14].pznamemx))
  2114. {
  2115. ls_temp_name.Append("丨")
  2116. .Append("底一张")
  2117. .Append(qdList[15].pznamemx);
  2118. }
  2119. else if (string.IsNullOrEmpty(qdList[15].pznamemx))
  2120. {
  2121. ls_temp_name.Append("丨")
  2122. .Append("面一张")
  2123. .Append(qdList[14].pznamemx);
  2124. }
  2125. else
  2126. {
  2127. ls_temp_name.Append("丨")
  2128. .Append("面底各一张")
  2129. .Append(qdList[14].pznamemx);
  2130. }
  2131. }
  2132. if (!string.IsNullOrEmpty(qdList[21].pznamemx))
  2133. {
  2134. ls_temp_name.Append("丨")
  2135. .Append(qdList[21].pzname)
  2136. .Append(qdList[21].pznamemx);
  2137. }
  2138. }
  2139. public string GetSpringName(int springid)
  2140. {
  2141. var spring = new u_spring() { springid = springid };
  2142. DbSqlHelper.SelectOne(cmd, spring, "line_diameter,gram_weight,height,center_diameter,cyclenum,caliber");
  2143. return spring.name;
  2144. }
  2145. public void CalCulateSpringQty(u_bednet bednet, List<u_bednetmx> mxlist)
  2146. {
  2147. // 默认方法
  2148. AddFormulaKeyValue("弹簧排列个数-宽", "if(【卷包】=1,round (【床垫宽】/(【中心直径】-【卷排列宽】),0),round (【床垫宽】/(【中心直径】-【排列宽】),0))");
  2149. AddFormulaKeyValue("弹簧排列个数-长", "if(【卷包】=1,round (【床垫长】/(【中心直径】-【卷排列长】),0),round (【床垫长】/(【中心直径】-【排列长】),0))");
  2150. InitReplaceMents(bednet);
  2151. foreach (var mx in mxlist)
  2152. {
  2153. var spring = new u_spring() { springid = mx.springid };
  2154. DbSqlHelper.SelectOne(cmd, spring, "line_diameter,gram_weight,height,center_diameter");
  2155. // 处理相同公式部分
  2156. InitMxReplaceMents(bednet, mx, spring);
  2157. InitSptringRepaceMents(spring);
  2158. #region 弹簧排列个数-宽
  2159. mx.spring_qty_width = Convert.ToInt32(CalculateVarFormula("弹簧排列个数-宽").DecimalValue);
  2160. AddKeyValue("弹簧排列个数-宽", mx.spring_qty_width);
  2161. #endregion
  2162. #region 弹簧排列个数-长
  2163. mx.spring_qty_width = Convert.ToInt32(CalculateVarFormula("弹簧排列个数-宽").DecimalValue);
  2164. AddKeyValue("弹簧排列个数-长", mx.spring_qty_width);
  2165. #endregion
  2166. }
  2167. }
  2168. }
  2169. }