BedNetHelper.cs 159 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138
  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;
  10. using System.Collections.Generic;
  11. using System.Data.SqlClient;
  12. using System.Linq;
  13. using System.Runtime.InteropServices;
  14. using System.Text;
  15. using System.Text.RegularExpressions;
  16. using System.Threading.Tasks;
  17. using static JLHHJSvr.Helper.CacheHelper;
  18. namespace JLHHJSvr.Helper
  19. {
  20. internal class BedNetHelper : HelperBase
  21. {
  22. private Dictionary<string, object> replacements = new Dictionary<string, object>();
  23. /// <summary>
  24. /// 默认展示公式
  25. /// </summary>
  26. private Dictionary<string, formulaItem> formula_replacements = new Dictionary<string, formulaItem>();
  27. /// <summary>
  28. /// 隐藏公式
  29. /// </summary>
  30. private Dictionary<string, formulaItem> formula_replacements_hide = new Dictionary<string, formulaItem>();
  31. /// <summary>
  32. /// 详细展示公式
  33. /// </summary>
  34. private Dictionary<string, formulaItem> formula_replacements_mx = new Dictionary<string, formulaItem>();
  35. /// <summary>
  36. /// 重量展示公式
  37. /// </summary>
  38. private Dictionary<string, formulaItem> formula_replacements_weight = new Dictionary<string, formulaItem>();
  39. public sealed class formulaItem
  40. {
  41. public string value { get; set; }
  42. public int? ifnotreplace { get; set; }
  43. }
  44. public List<replacement> Replacements
  45. {
  46. get
  47. {
  48. var res = new List<replacement>();
  49. foreach (var item in replacements)
  50. {
  51. res.Add(new replacement { label = item.Key, value = item.Value, type = 0 });
  52. }
  53. return res;
  54. }
  55. }
  56. public List<replacement> FormulaReplacements
  57. {
  58. get {
  59. var res = new List<replacement>();
  60. foreach (var item in formula_replacements)
  61. {
  62. res.Add(new replacement { label = item.Key, value = item.Value.value, type = 0, ifnotreplace = item.Value.ifnotreplace});
  63. }
  64. foreach (var item in formula_replacements_hide)
  65. {
  66. res.Add(new replacement { label = item.Key, value = item.Value.value, type = 1, ifnotreplace = item.Value.ifnotreplace });
  67. }
  68. foreach (var item in formula_replacements_mx)
  69. {
  70. res.Add(new replacement { label = item.Key, value = item.Value.value, type = 2, ifnotreplace = item.Value.ifnotreplace });
  71. }
  72. foreach (var item in formula_replacements_weight)
  73. {
  74. res.Add(new replacement { label = item.Key, value = item.Value.value, type = 3, ifnotreplace = item.Value.ifnotreplace });
  75. }
  76. return res;
  77. }
  78. }
  79. /// <summary>
  80. /// 计算床网报价
  81. /// </summary>
  82. /// <param name="bednet"></param>
  83. /// <param name="mxlist"></param>
  84. /// <param name="springList"></param>
  85. /// <param name="isCalBed">是否实时获取信息</param>
  86. /// <param name="isNewFormula">是否获取新的公式计算</param>
  87. public void CalCulateFormula(u_bednet bednet, List<u_bednetmx> mxlist, List<u_bednetmx_spring> springList, Boolean isCalBed = true, Boolean isNewFormula = true)
  88. {
  89. InitBedNet(bednet, isCalBed);
  90. InitReplaceMents(bednet, isCalBed);
  91. CulcalateCost(bednet, mxlist, springList, isNewFormula);
  92. CulcalateWeight(bednet, mxlist, springList);
  93. if (formula_replacements_hide.Count > 0)
  94. {
  95. foreach (var replacement in formula_replacements_hide)
  96. {
  97. var _key = replacement.Key.Replace("【", "").Replace("】", "");
  98. var value = CalculateVarFormula(_key).DecimalValue;
  99. AddKeyValue(_key, value);
  100. }
  101. }
  102. }
  103. /// <summary>
  104. /// 获取损耗率
  105. /// </summary>
  106. /// <param name="mtrltype"></param>
  107. /// <returns></returns>
  108. public decimal GetSumhaoRate(int mtrltype)
  109. {
  110. decimal _rate = 0; //损耗率浮动数
  111. var mtrlType = new u_mtrltype() { mtrltypeid = mtrltype };
  112. DbSqlHelper.SelectOne(cmd, mtrlType, "dannum1_rate, dannum2_rate, dannum3_rate, dannum4_rate");
  113. var dannumType = 1;
  114. if (replacements.TryGetValue("【大小单类型】", out object value1))
  115. {
  116. dannumType = Convert.ToInt32(value1);
  117. }
  118. switch (dannumType)
  119. {
  120. case 1:
  121. _rate = mtrlType.dannum1_rate.Value;
  122. break;
  123. case 2:
  124. _rate = mtrlType.dannum2_rate.Value;
  125. break;
  126. case 3:
  127. _rate = mtrlType.dannum3_rate.Value;
  128. break;
  129. case 4:
  130. _rate = mtrlType.dannum4_rate.Value;
  131. break;
  132. }
  133. return _rate;
  134. }
  135. private void CulcalateCost(u_bednet bednet, List<u_bednetmx> mxlist, List<u_bednetmx_spring> springList, Boolean isNewFormula = true)
  136. {
  137. bednet.spring_mtrl_cost = 0;
  138. bednet.spring_hr_cost = 0;
  139. bednet.snake_wire_mtrl_cost = 0;
  140. bednet.pocket_around_spring_cost = 0;
  141. bednet.pocket_around_fabrics_cost = 0;
  142. bednet.hard_around_mtrl_cost = 0;
  143. bednet.hard_around_hr_cost = 0;
  144. bednet.fabrics1_mtrl_cost = 0;
  145. bednet.glue_mtrl_cost = 0;
  146. bednet.fabrics2_mtrl_cost = 0;
  147. bednet.side_iron_hr_cost = 0;
  148. bednet.side_iron_mtrl_cost = 0;
  149. bednet.cnail_mtrl_cost = 0;
  150. bednet.cnail_hr_cost = 0;
  151. bednet.sponge_mtrl_cost = 0;
  152. bednet.sponge_hr_cost = 0;
  153. bednet.sponge_mtrl_tc_cost = 0;
  154. bednet.edge_mtrl_cost = 0;
  155. bednet.edge_hr_cost = 0;
  156. bednet.fork_mtrl_cost = 0;
  157. bednet.fork_hr_cost = 0;
  158. bednet.rsorwa_mtrl_cost = 0;
  159. bednet.rsorwa_hr_cost = 0;
  160. bednet.sponge_drilling_hr_cost = 0;
  161. bednet.felt_mtrl_cost = 0;
  162. bednet.felt_mtrl_x_cost = 0;
  163. bednet.felt_hr_cost = 0;
  164. bednet.felt_hr_x_cost = 0;
  165. bednet.packet_mtrl_cost = 0;
  166. bednet.packet_hr_cost = 0;
  167. foreach (var mx in mxlist)
  168. {
  169. var spring = Cache.GetData<u_spring,SpringMapping>(mx.springid.Value);
  170. // 处理相同公式部分
  171. InitMxReplaceMents(bednet, mx, spring);
  172. //计算 弹簧材料总成本
  173. #region 计算 弹簧材料总成本 开始
  174. if (!string.IsNullOrEmpty(bednet.spring_mtrl_formula))
  175. {
  176. AddKeyValue("每米/重", 0.298);
  177. var _formula = bednet.spring_mtrl_formula;
  178. mx.spring_mtrl_cost_replace_formula = bednet.spring_mtrl_formula;
  179. if (mx.if_part == 0)
  180. {
  181. //单分区
  182. //考虑 四周加硬和四周口袋 扣减 排列数情况
  183. if (mx.if_hard_around == 1)
  184. {
  185. decimal hard_around_row = mx.hard_around_row.Value;
  186. if (bednet.typename.IndexOf("袋装", StringComparison.Ordinal) >= 0) hard_around_row *= 2;
  187. mx.spring_mtrl_cost_replace_formula = mx.spring_mtrl_cost_replace_formula.Replace("【弹簧排列个数-宽】", $"(【弹簧排列个数-宽】 - {hard_around_row})");
  188. mx.spring_mtrl_cost_replace_formula = mx.spring_mtrl_cost_replace_formula.Replace("【弹簧计算个数(宽)】", $"(【弹簧计算个数(宽)】 - {hard_around_row})");
  189. mx.spring_mtrl_cost_replace_formula = mx.spring_mtrl_cost_replace_formula.Replace("【弹簧排列个数-长】", $"(【弹簧排列个数-长】 - {hard_around_row})");
  190. mx.spring_mtrl_cost_replace_formula = mx.spring_mtrl_cost_replace_formula.Replace("【弹簧计算个数(长)】", $"(【弹簧计算个数(长)】 - {hard_around_row})");
  191. }
  192. if (mx.if_pocket_around == 1)
  193. {
  194. decimal pocket_around_row = mx.pocket_around_row.Value;
  195. if (bednet.typename.IndexOf("袋装", StringComparison.Ordinal) >= 0) pocket_around_row *= 2;
  196. mx.spring_mtrl_cost_replace_formula = mx.spring_mtrl_cost_replace_formula.Replace("【弹簧排列个数-宽】", $"(【弹簧排列个数-宽】 - {pocket_around_row})");
  197. mx.spring_mtrl_cost_replace_formula = mx.spring_mtrl_cost_replace_formula.Replace("【弹簧计算个数(宽)】", $"(【弹簧计算个数(宽)】 - {pocket_around_row})");
  198. mx.spring_mtrl_cost_replace_formula = mx.spring_mtrl_cost_replace_formula.Replace("【弹簧排列个数-长】", $"(【弹簧排列个数-长】 - {pocket_around_row})");
  199. mx.spring_mtrl_cost_replace_formula = mx.spring_mtrl_cost_replace_formula.Replace("【弹簧计算个数(长)】", $"(【弹簧计算个数(长)】 - {pocket_around_row})");
  200. }
  201. var rp_formula = "";
  202. mx.spring_mtrl_cost = Calculate(mx.spring_mtrl_cost_replace_formula, out rp_formula, "弹簧材料总成本").DecimalValue;
  203. mx.spring_mtrl_cost_replace_formula = rp_formula;
  204. #region 获取损耗率,计算
  205. if (isNewFormula)
  206. {
  207. decimal? _rate = GetSumhaoRate(0);
  208. bednet.spring_mtrl_cost += mx.spring_mtrl_cost * (1 + _rate);
  209. if (_rate != 0)
  210. {
  211. _formula = "(" + _formula + ")" + "x" + "【弹簧损耗率】";
  212. AddKeyValue("弹簧损耗率", (1 + _rate));
  213. }
  214. }
  215. else
  216. {
  217. bednet.spring_mtrl_cost += mx.spring_mtrl_cost;
  218. }
  219. #endregion
  220. }
  221. else
  222. {
  223. mx.spring_mtrl_cost = 0;
  224. decimal? _rate = GetSumhaoRate(0);
  225. //多分区
  226. var index = 1;
  227. foreach (var springItem in springList)
  228. {
  229. _formula = bednet.spring_mtrl_formula;
  230. springItem.spring_mtrl_cost_replace_formula = bednet.spring_mtrl_formula;
  231. CalSpringMtrlCol(bednet, mx, springItem,ref _formula, index);
  232. var rp_formula = "";
  233. springItem.spring_mtrl_cost = Calculate(_formula, out rp_formula, "弹簧材料总成本").DecimalValue;
  234. springItem.spring_mtrl_cost_replace_formula = rp_formula;
  235. mx.spring_mtrl_cost += springItem.spring_mtrl_cost;
  236. #region 获取损耗率,计算
  237. if (isNewFormula)
  238. {
  239. bednet.spring_mtrl_cost += springItem.spring_mtrl_cost * (1 + _rate);
  240. if (_rate != 0)
  241. {
  242. _formula = "(" + _formula + ")" + "x" + "【弹簧损耗率】";
  243. AddKeyValue("弹簧损耗率", (1 + _rate));
  244. }
  245. }
  246. else
  247. {
  248. bednet.spring_mtrl_cost += springItem.spring_mtrl_cost;
  249. }
  250. #endregion
  251. AddFormulaMxKeyValue("【" + index + "弹簧材料总成本】", _formula, true);
  252. index++;
  253. }
  254. }
  255. AddKeyValue("弹簧排列个数-宽", mx.spring_qty_width);
  256. AddKeyValue("弹簧排列个数-长", mx.spring_qty_length);
  257. AddKeyValue("弹簧计算个数(宽)", mx.spring_qty_width);
  258. AddKeyValue("弹簧计算个数(长)", mx.spring_qty_length);
  259. AddKeyValue("弹簧材料总成本", bednet.spring_mtrl_cost);
  260. AddFormulaMxKeyValue("【弹簧材料总成本】", _formula, true);
  261. }
  262. #endregion 计算 弹簧材料总成本 结束
  263. #region 计算 弹簧人工总成本 开始
  264. if (!string.IsNullOrEmpty(bednet.spring_hr_formula))
  265. {
  266. mx.spring_hr_cost_replace_formula = bednet.spring_hr_formula;
  267. var rp_formula = "";
  268. mx.spring_hr_cost = Calculate(mx.spring_hr_cost_replace_formula, out rp_formula, "弹簧总人工成本").DecimalValue;
  269. mx.spring_hr_cost_replace_formula = rp_formula;
  270. bednet.spring_hr_cost += mx.spring_hr_cost;
  271. AddKeyValue("弹簧总人工成本", bednet.spring_hr_cost);
  272. AddFormulaMxKeyValue("【弹簧总人工成本】", bednet.spring_hr_formula, true);
  273. }
  274. #endregion 计算 弹簧人工总成本 结束
  275. #region 计算 蛇线材料成本 开始
  276. if (bednet.snake_wire_diameter.Value > 0)
  277. {
  278. bednet.snake_wire_mtrl_cost_replace_formula = bednet.snake_wire_mtrl_formula;
  279. #region 替换蛇线单价 snake_wire_diameter
  280. GetSpringPrice(bednet.pricelistid.Value, "蛇线单价", 0, bednet.snake_wire_diameter.Value);
  281. #endregion
  282. var rp_formula = "";
  283. bednet.snake_wire_mtrl_cost += Calculate(bednet.snake_wire_mtrl_cost_replace_formula, out rp_formula, "蛇线材料成本").DecimalValue;
  284. bednet.snake_wire_mtrl_cost_replace_formula = rp_formula;
  285. AddKeyValue("蛇线材料成本", bednet.snake_wire_mtrl_cost);
  286. AddFormulaMxKeyValue("【蛇线材料成本】", bednet.snake_wire_mtrl_formula);
  287. }
  288. #endregion 计算 蛇线材料成本 结束
  289. #region 计算 四周口袋弹簧成本 开始
  290. if (!string.IsNullOrEmpty(bednet.pocket_around_spring_formula) && mx.if_pocket_around > 0)
  291. {
  292. mx.pocket_around_spring_cost_replace_formula = bednet.pocket_around_spring_formula;
  293. #region wf_cmp_pocket_around_dw2 口袋弹簧单价
  294. var springPocket = GetSpringPrice(bednet.pricelistid.Value, "口袋弹簧单价", mx.pocket_around_springid, 0, "口袋");
  295. if (springPocket.height > 0)
  296. {
  297. AddKeyValue("口袋弹簧高度", springPocket.height);
  298. }
  299. if (springPocket.center_diameter > 0)
  300. {
  301. AddKeyValue("口袋弹簧心径", springPocket.center_diameter);
  302. }
  303. #endregion
  304. var rp_formula = "";
  305. var mx_formula = mx.pocket_around_spring_cost_replace_formula.Replace("【弹簧重/个】", "【口袋弹簧重/个】").Replace("【弹簧重】", "【口袋弹簧重】");
  306. mx.pocket_around_spring_cost = Calculate(mx_formula, out rp_formula, "四周口袋弹簧成本").DecimalValue;
  307. mx.pocket_around_spring_cost_replace_formula = rp_formula;
  308. bednet.pocket_around_spring_cost += mx.pocket_around_spring_cost;
  309. AddKeyValue("四周口袋弹簧成本", bednet.pocket_around_spring_cost);
  310. AddFormulaMxKeyValue("【四周口袋弹簧成本】", bednet.pocket_around_spring_formula.Replace("【弹簧重/个】", "【口袋弹簧重/个】").Replace("【弹簧重】", "【口袋弹簧重】"));
  311. }
  312. else
  313. {
  314. AddKeyValue("口袋弹簧单价", 0);
  315. }
  316. #endregion 计算 四周口袋弹簧成本 结束
  317. #region 计算 四周口袋无纺布成本 开始
  318. if (!string.IsNullOrEmpty(bednet.pocket_around_fabrics_formula) && mx.if_pocket_around > 0)
  319. {
  320. mx.pocket_around_fabrics_cost_replace_formula = bednet.pocket_around_fabrics_formula;
  321. var rp_formula = "";
  322. mx.pocket_around_fabrics_cost = Calculate(mx.pocket_around_fabrics_cost_replace_formula, out rp_formula, "四周口袋无纺布成本").DecimalValue;
  323. mx.pocket_around_fabrics_cost_replace_formula = rp_formula;
  324. bednet.pocket_around_fabrics_cost += mx.pocket_around_fabrics_cost;
  325. AddKeyValue("四周口袋无纺布成本", bednet.pocket_around_fabrics_cost);
  326. AddFormulaMxKeyValue("【四周口袋无纺布成本】", bednet.pocket_around_fabrics_formula);
  327. }
  328. #endregion 计算 四周口袋无纺布成本 结束
  329. #region 计算 四周加硬材料成本 开始
  330. if (!string.IsNullOrEmpty(bednet.hard_around_mtrl_formula) && mx.if_hard_around > 0)
  331. {
  332. mx.hard_around_mtrl_cost_replace_formula = bednet.hard_around_mtrl_formula;
  333. #region wf_cmp_hard_around_dw2 四周加硬弹簧单价
  334. var springHard = GetSpringPrice(bednet.pricelistid.Value, "加硬弹簧单价", mx.hard_around_springid, 0, "加硬");
  335. #endregion
  336. var rp_formula = "";
  337. var mx_formula = mx.hard_around_mtrl_cost_replace_formula.Replace("【弹簧重/个】", "【加硬弹簧重/个】").Replace("【弹簧重】", "【加硬弹簧重】");
  338. mx.hard_around_mtrl_cost = Calculate(mx_formula, out rp_formula, "四周加硬材料成本").DecimalValue;
  339. mx.hard_around_mtrl_cost_replace_formula = rp_formula;
  340. var _formula = bednet.hard_around_mtrl_formula.Replace("【弹簧重/个】", "【加硬弹簧重/个】").Replace("【弹簧重】", "【加硬弹簧重】");
  341. #region 获取损耗率,计算
  342. if (isNewFormula)
  343. {
  344. decimal? _rate = GetSumhaoRate(0);
  345. bednet.hard_around_mtrl_cost += mx.hard_around_mtrl_cost * (1 + _rate);
  346. if (_rate != 0)
  347. {
  348. _formula = "(" + _formula + ")" + "x" + "【四周加硬损耗率】";
  349. AddKeyValue("四周加硬损耗率", (1 + _rate));
  350. }
  351. }
  352. else
  353. {
  354. bednet.hard_around_mtrl_cost += mx.hard_around_mtrl_cost;
  355. }
  356. #endregion
  357. AddKeyValue("四周加硬材料成本", bednet.hard_around_mtrl_cost);
  358. AddFormulaMxKeyValue("【四周加硬材料成本】", _formula);
  359. }
  360. else
  361. {
  362. AddKeyValue("加硬弹簧单价", 0);
  363. }
  364. #endregion 计算 四周加硬材料成本 结束
  365. #region 计算 四周加硬人力成本 开始
  366. if (!string.IsNullOrEmpty(bednet.hard_around_hr_formula) && mx.if_hard_around > 0)
  367. {
  368. mx.hard_around_hr_cost_replace_formula = bednet.hard_around_hr_formula;
  369. var rp_formula = "";
  370. mx.hard_around_hr_cost = Calculate(mx.hard_around_hr_cost_replace_formula, out rp_formula, "四周加硬人力成本").DecimalValue;
  371. mx.hard_around_hr_cost_replace_formula = rp_formula;
  372. bednet.hard_around_hr_cost += mx.hard_around_hr_cost;
  373. AddKeyValue("四周加硬人力成本", bednet.hard_around_hr_cost);
  374. AddFormulaMxKeyValue("【四周加硬人力成本】", bednet.hard_around_hr_formula);
  375. }
  376. #endregion 计算 四周加硬人力成本 结束
  377. #region 计算 入袋无纺布材料成本 开始
  378. if (!string.IsNullOrEmpty(bednet.hard_around_hr_formula) && bednet.typename.IndexOf("袋装网") > -1 && mx.fabrics1_mtrlid > 0)
  379. {
  380. mx.fabrics1_mtrl_cost_replace_formula = bednet.fabrics1_mtrl_formula;
  381. CalSpringMtrlCol2(bednet, mx, springList, "入袋无纺布");
  382. var rp_formula = "";
  383. mx.fabrics1_mtrl_cost = Calculate(mx.fabrics1_mtrl_cost_replace_formula, out rp_formula, "入袋无纺布材料成本").DecimalValue;
  384. mx.fabrics1_mtrl_cost_replace_formula = rp_formula;
  385. bednet.fabrics1_mtrl_cost += mx.fabrics1_mtrl_cost;
  386. #region 获取损耗率,计算
  387. var _formula = bednet.fabrics1_mtrl_formula;
  388. if (isNewFormula)
  389. {
  390. var mtrlPrice = new u_mtrl_price() { mtrlid = mx.fabrics1_mtrlid };
  391. DbSqlHelper.SelectOne(cmd, mtrlPrice, "mtrltype");
  392. if (mtrlPrice != null)
  393. {
  394. decimal? _rate = GetSumhaoRate(mtrlPrice.mtrltype.Value);
  395. bednet.fabrics1_mtrl_cost = bednet.fabrics1_mtrl_cost * (1 + _rate);
  396. if (_rate != 0)
  397. {
  398. _formula = "(" + _formula + ")" + "x" + "【入袋无纺布损耗率】";
  399. AddKeyValue("入袋无纺布损耗率", (1 + _rate));
  400. }
  401. }
  402. }
  403. #endregion
  404. AddKeyValue("入袋无纺布材料成本", bednet.fabrics1_mtrl_cost);
  405. AddFormulaMxKeyValue("【入袋无纺布材料成本】", _formula);
  406. }
  407. #endregion 计算 入袋无纺布材料成本 结束
  408. #region 计算 胶水材料成本 开始
  409. if (!string.IsNullOrEmpty(bednet.glue_mtrl_formula))
  410. {
  411. mx.glue_mtrl_cost_replace_formula = bednet.glue_mtrl_formula;
  412. var rp_formula = "";
  413. bednet.glue_mtrl_cost += Calculate(mx.glue_mtrl_cost_replace_formula, out rp_formula, "胶水材料成本").DecimalValue;
  414. mx.glue_mtrl_cost_replace_formula = rp_formula;
  415. AddKeyValue("胶水材料成本", bednet.glue_mtrl_cost);
  416. AddFormulaMxKeyValue("【胶水材料成本】", bednet.glue_mtrl_formula);
  417. }
  418. #endregion 计算 胶水材料成本 结束
  419. #region 计算 底面无纺布材料成本 开始
  420. if (!string.IsNullOrEmpty(bednet.hard_around_hr_formula) && bednet.typename.IndexOf("袋装网") > -1 && mx.fabrics2_mtrlid > 0)
  421. {
  422. mx.fabrics2_mtrl_cost_replace_formula = bednet.fabrics2_mtrl_formula;
  423. CalSpringMtrlCol2(bednet, mx, springList, "底面无纺布");
  424. var rp_formula = "";
  425. mx.fabrics2_mtrl_cost = Calculate(mx.fabrics2_mtrl_cost_replace_formula, out rp_formula, "底面无纺布材料成本").DecimalValue;
  426. mx.fabrics2_mtrl_cost_replace_formula = rp_formula;
  427. bednet.fabrics2_mtrl_cost += mx.fabrics2_mtrl_cost;
  428. #region 获取损耗率,计算
  429. var _formula = bednet.fabrics2_mtrl_formula;
  430. if(isNewFormula)
  431. {
  432. var mtrlPrice = new u_mtrl_price() { mtrlid = mx.fabrics2_mtrlid };
  433. DbSqlHelper.SelectOne(cmd, mtrlPrice, "mtrltype");
  434. if (mtrlPrice != null)
  435. {
  436. decimal? _rate = GetSumhaoRate(mtrlPrice.mtrltype.Value);
  437. bednet.fabrics2_mtrl_cost = bednet.fabrics2_mtrl_cost * (1 + _rate);
  438. if (_rate != 0)
  439. {
  440. _formula = "(" + _formula + ")" + "x" + "【底面无纺布损耗率】";
  441. AddKeyValue("底面无纺布损耗率", (1 + _rate));
  442. }
  443. }
  444. }
  445. #endregion
  446. AddKeyValue("底面无纺布材料成本", bednet.fabrics2_mtrl_cost);
  447. AddFormulaMxKeyValue("【底面无纺布材料成本】", _formula);
  448. }
  449. #endregion 计算 底面无纺布材料成本 结束
  450. #region 计算 边铁人力成本 开始
  451. if (!string.IsNullOrEmpty(bednet.side_iron_hr_formula) && bednet.if_side_iron == 1 && mx.if_side_iron > 0)
  452. {
  453. mx.side_iron_hr_cost_replace_formula = bednet.side_iron_hr_formula;
  454. var rp_formula = "";
  455. mx.side_iron_hr_cost = Calculate(mx.side_iron_hr_cost_replace_formula, out rp_formula, "边铁人力成本").DecimalValue;
  456. mx.side_iron_hr_cost_replace_formula = rp_formula;
  457. bednet.side_iron_hr_cost += mx.side_iron_hr_cost;
  458. AddKeyValue("边铁人力成本", bednet.side_iron_hr_cost);
  459. AddFormulaMxKeyValue("【边铁人力成本】", bednet.side_iron_hr_formula);
  460. }
  461. #endregion 计算 边铁人力成本 结束
  462. #region 计算 边铁材料成本 开始
  463. if (!string.IsNullOrEmpty(bednet.side_iron_mtrl_formula) && bednet.if_side_iron == 1 && mx.if_side_iron > 0)
  464. {
  465. mx.side_iron_mtrl_cost_replace_formula = bednet.side_iron_mtrl_formula;
  466. var rp_formula = "";
  467. mx.side_iron_mtrl_cost = Calculate(mx.side_iron_mtrl_cost_replace_formula, out rp_formula, "边铁材料成本").DecimalValue;
  468. mx.side_iron_mtrl_cost_replace_formula = rp_formula;
  469. bednet.side_iron_mtrl_cost += mx.side_iron_mtrl_cost;
  470. AddKeyValue("边铁材料成本", bednet.side_iron_mtrl_cost);
  471. AddFormulaMxKeyValue("【边铁材料成本】", bednet.side_iron_mtrl_formula);
  472. }
  473. #endregion 计算 边铁材料成本 结束
  474. #region 计算 C钉/夹码材料 开始
  475. if (!string.IsNullOrEmpty(bednet.cnail_mtrl_formula))
  476. {
  477. mx.cnail_mtrl_cost_replace_formula = bednet.cnail_mtrl_formula;
  478. var rp_formula = "";
  479. mx.cnail_mtrl_cost = Calculate(mx.cnail_mtrl_cost_replace_formula, out rp_formula, "C钉/夹码材料成本").DecimalValue;
  480. mx.cnail_mtrl_cost_replace_formula = rp_formula;
  481. bednet.cnail_mtrl_cost += mx.cnail_mtrl_cost;
  482. AddKeyValue("C钉/夹码材料成本", bednet.cnail_mtrl_cost);
  483. AddFormulaMxKeyValue("【C钉/夹码材料成本】", bednet.cnail_mtrl_formula);
  484. }
  485. #endregion 计算 C钉/夹码材料 结束
  486. #region 计算 C钉/夹码人力成本 开始
  487. if (!string.IsNullOrEmpty(bednet.cnail_hr_formula))
  488. {
  489. mx.cnail_hr_cost_replace_formula = bednet.cnail_hr_formula;
  490. var rp_formula = "";
  491. mx.cnail_hr_cost = Calculate(mx.cnail_hr_cost_replace_formula, out rp_formula, "C钉/夹码人力成本").DecimalValue;
  492. mx.cnail_hr_cost_replace_formula = rp_formula;
  493. bednet.cnail_hr_cost += mx.cnail_hr_cost;
  494. AddKeyValue("C钉/夹码人力成本", bednet.cnail_hr_cost);
  495. AddFormulaMxKeyValue("【C钉/夹码人力成本】", bednet.cnail_hr_formula);
  496. }
  497. #endregion 计算 C钉/夹码人力成本 结束
  498. #region 计算 海绵包边材料成本 开始
  499. if (!string.IsNullOrEmpty(bednet.sponge_mtrl_formula) && bednet.sponge_mtrlid > 0)
  500. {
  501. bednet.sponge_mtrl_cost_replace_formula = bednet.sponge_mtrl_formula;
  502. CalSpringMtrlCol2(bednet, mx, springList, "海绵包边");
  503. var rp_formula = "";
  504. bednet.sponge_mtrl_cost += Calculate(bednet.sponge_mtrl_cost_replace_formula, out rp_formula, "海绵包边材料成本").DecimalValue;
  505. bednet.sponge_mtrl_cost_replace_formula = rp_formula;
  506. AddKeyValue("海绵包边材料成本", bednet.sponge_mtrl_cost);
  507. AddFormulaMxKeyValue("【海绵包边材料成本】", bednet.sponge_mtrl_formula);
  508. }
  509. #endregion 计算 海绵包边材料成本 结束
  510. #region 计算 海绵包边人力成本 开始
  511. if (!string.IsNullOrEmpty(bednet.sponge_hr_formula) && bednet.sponge_mtrlid > 0)
  512. {
  513. bednet.sponge_hr_cost_replace_formula = bednet.sponge_hr_formula;
  514. var rp_formula = "";
  515. bednet.sponge_hr_cost += Calculate(bednet.sponge_hr_cost_replace_formula, out rp_formula, "海绵包边人力成本").DecimalValue;
  516. bednet.sponge_hr_cost_replace_formula = rp_formula;
  517. AddKeyValue("海绵包边人力成本", bednet.sponge_hr_cost);
  518. AddFormulaMxKeyValue("【海绵包边人力成本】", bednet.sponge_hr_formula);
  519. }
  520. #endregion 计算 海绵包边人力成本 结束
  521. #region 计算 填充海绵成本 开始
  522. if (!string.IsNullOrEmpty(bednet.sponge_mtrl_tc_formula) && bednet.sponge_tc_mtrlid > 0)
  523. {
  524. bednet.sponge_mtrl_tc_cost_replace_formula = bednet.sponge_mtrl_tc_formula;
  525. CalSpringMtrlCol2(bednet, mx, springList, "填充海绵");
  526. var rp_formula = "";
  527. bednet.sponge_mtrl_tc_cost += Calculate(bednet.sponge_mtrl_tc_cost_replace_formula, out rp_formula, "填充海绵成本").DecimalValue;
  528. bednet.sponge_mtrl_tc_cost_replace_formula = rp_formula;
  529. AddKeyValue("填充海绵成本", bednet.sponge_mtrl_tc_cost);
  530. AddFormulaMxKeyValue("【填充海绵成本】", bednet.sponge_mtrl_tc_formula);
  531. }
  532. #endregion 计算 填充海绵成本 结束
  533. #region 计算 封边材料成本 开始
  534. if (!string.IsNullOrEmpty(bednet.edge_mtrl_formula) && bednet.edge_mtrlid > 0)
  535. {
  536. bednet.edge_mtrl_cost_replace_formula = bednet.edge_mtrl_formula;
  537. CalSpringMtrlCol2(bednet, mx, springList, "封边");
  538. var rp_formula = "";
  539. bednet.edge_mtrl_cost += Calculate(bednet.edge_mtrl_cost_replace_formula, out rp_formula, "封边材料成本").DecimalValue;
  540. bednet.edge_mtrl_cost_replace_formula = rp_formula;
  541. AddKeyValue("封边材料成本", bednet.edge_mtrl_cost);
  542. AddFormulaMxKeyValue("【封边材料成本】", bednet.edge_mtrl_formula);
  543. }
  544. #endregion 计算 封边材料成本 结束
  545. #region 计算 封边人力成本 开始
  546. if (!string.IsNullOrEmpty(bednet.edge_hr_formula) && bednet.edge_mtrlid > 0)
  547. {
  548. bednet.edge_hr_cost_replace_formula = bednet.edge_hr_formula;
  549. var rp_formula = "";
  550. bednet.edge_hr_cost += Calculate(bednet.edge_hr_cost_replace_formula, out rp_formula, "封边人力成本").DecimalValue;
  551. bednet.edge_hr_cost_replace_formula = rp_formula;
  552. AddKeyValue("封边人力成本", bednet.edge_hr_cost);
  553. AddFormulaMxKeyValue("【封边人力成本】", bednet.edge_hr_formula);
  554. }
  555. #endregion 计算 封边人力成本 结束
  556. #region 计算 弹叉材料成本 开始
  557. if (!string.IsNullOrEmpty(bednet.fork_mtrl_formula) && bednet.fork_qty > 0)
  558. {
  559. bednet.fork_mtrl_cost_replace_formula = bednet.fork_mtrl_formula;
  560. var rp_formula = "";
  561. bednet.fork_mtrl_cost += Calculate(bednet.fork_mtrl_cost_replace_formula, out rp_formula, "弹叉材料成本").DecimalValue;
  562. bednet.fork_mtrl_cost_replace_formula = rp_formula;
  563. AddKeyValue("弹叉材料成本", bednet.fork_mtrl_cost);
  564. AddFormulaMxKeyValue("【弹叉材料成本】", bednet.fork_mtrl_formula);
  565. }
  566. #endregion 计算 弹叉材料成本 结束
  567. #region 计算 弹叉人力成本 开始
  568. if (!string.IsNullOrEmpty(bednet.fork_hr_formula) && bednet.fork_qty > 0)
  569. {
  570. bednet.fork_hr_cost_replace_formula = bednet.fork_hr_formula;
  571. var rp_formula = "";
  572. bednet.fork_hr_cost += Calculate(bednet.fork_hr_cost_replace_formula, out rp_formula, "弹叉人力成本").DecimalValue;
  573. bednet.fork_hr_cost_replace_formula = rp_formula;
  574. AddKeyValue("弹叉人力成本", bednet.fork_hr_cost);
  575. AddFormulaMxKeyValue("【弹叉人力成本】", bednet.fork_hr_formula);
  576. }
  577. #endregion 计算 弹叉人力成本 结束
  578. #region 计算 胶条/包角材料成本 开始
  579. if (!string.IsNullOrEmpty(bednet.rsorwa_mtrl_formula) && bednet.if_rsorwa == 1)
  580. {
  581. bednet.rsorwa_mtrl_cost_replace_formula = bednet.rsorwa_mtrl_formula;
  582. var rp_formula = "";
  583. bednet.rsorwa_mtrl_cost += Calculate(bednet.rsorwa_mtrl_cost_replace_formula, out rp_formula, "胶条/包角材料成本").DecimalValue;
  584. bednet.rsorwa_mtrl_cost_replace_formula = rp_formula;
  585. AddKeyValue("胶条/包角材料成本", bednet.rsorwa_mtrl_cost);
  586. AddFormulaMxKeyValue("【胶条/包角材料成本】", bednet.rsorwa_mtrl_formula);
  587. }
  588. #endregion 计算 胶条/包角材料成本 结束
  589. #region 计算 胶条/包角人力成本 开始
  590. if (!string.IsNullOrEmpty(bednet.rsorwa_hr_formula) && bednet.if_rsorwa == 1)
  591. {
  592. bednet.rsorwa_hr_cost_replace_formula = bednet.rsorwa_hr_formula;
  593. var rp_formula = "";
  594. bednet.rsorwa_hr_cost += Calculate(bednet.rsorwa_hr_cost_replace_formula, out rp_formula, "胶条/包角人力成本").DecimalValue;
  595. bednet.rsorwa_hr_cost_replace_formula = rp_formula;
  596. AddKeyValue("胶条/包角人力成本", bednet.rsorwa_hr_cost);
  597. AddFormulaMxKeyValue("【胶条/包角人力成本】", bednet.rsorwa_hr_formula);
  598. }
  599. #endregion 计算 胶条/包角人力成本 结束
  600. #region 计算 海绵打孔人力成本 开始
  601. if (!string.IsNullOrEmpty(bednet.sponge_drilling_hr_formula) && bednet.if_sponge_drilling == 1)
  602. {
  603. bednet.sponge_drilling_hr_cost_replace_formula = bednet.sponge_drilling_hr_formula;
  604. var rp_formula = "";
  605. bednet.sponge_drilling_hr_cost += Calculate(bednet.sponge_drilling_hr_cost_replace_formula, out rp_formula, "海绵打孔人力成本").DecimalValue;
  606. bednet.sponge_drilling_hr_cost_replace_formula = rp_formula;
  607. AddKeyValue("海绵打孔人力成本", bednet.sponge_drilling_hr_cost);
  608. AddFormulaMxKeyValue("【海绵打孔人力成本】", bednet.sponge_drilling_hr_formula);
  609. }
  610. #endregion 计算 海绵打孔人力成本 结束
  611. #region 计算 上垫层物料成本 开始
  612. if (!string.IsNullOrEmpty(bednet.felt_mtrl_formula) && bednet.felt_qty > 0)
  613. {
  614. bednet.felt_mtrl_cost_replace_formula = bednet.felt_mtrl_formula;
  615. CalSpringMtrlCol2(bednet, mx, springList, "上垫层");
  616. var rp_formula = "";
  617. bednet.felt_mtrl_cost += Calculate(bednet.felt_mtrl_cost_replace_formula, out rp_formula, "上垫层物料成本").DecimalValue;
  618. bednet.felt_mtrl_cost_replace_formula = rp_formula;
  619. AddKeyValue("上垫层物料成本", bednet.felt_mtrl_cost);
  620. AddFormulaMxKeyValue("【上垫层物料成本】", bednet.felt_mtrl_formula);
  621. }
  622. #endregion 计算 上垫层物料成本 结束
  623. #region 计算 下垫层物料成本 开始
  624. if (!string.IsNullOrEmpty(bednet.felt_mtrl_formula) && bednet.felt_x_qty > 0)
  625. {
  626. bednet.felt_mtrl_x_cost_replace_formula = bednet.felt_mtrl_formula;
  627. CalSpringMtrlCol2(bednet, mx, springList, "下垫层");
  628. var rp_formula = "";
  629. bednet.felt_mtrl_x_cost += Calculate(bednet.felt_mtrl_x_cost_replace_formula, out rp_formula, "下垫层物料成本").DecimalValue;
  630. bednet.felt_mtrl_x_cost_replace_formula = rp_formula;
  631. AddKeyValue("下垫层物料成本", bednet.felt_mtrl_x_cost);
  632. AddFormulaMxKeyValue("【下垫层物料成本】", bednet.felt_mtrl_formula);
  633. }
  634. #endregion 计算 下垫层物料成本 结束
  635. #region 计算 上垫层人力成本 开始
  636. if (!string.IsNullOrEmpty(bednet.felt_hr_formula) && bednet.felt_qty > 0)
  637. {
  638. bednet.felt_hr_cost_replace_formula = bednet.felt_hr_formula;
  639. var rp_formula = "";
  640. bednet.felt_hr_cost += Calculate(bednet.felt_hr_cost_replace_formula, out rp_formula, "上垫层人力成本").DecimalValue;
  641. bednet.felt_hr_cost_replace_formula = rp_formula;
  642. AddKeyValue("上垫层人力成本", bednet.felt_hr_cost);
  643. AddFormulaMxKeyValue("【上垫层人力成本】", bednet.felt_hr_formula);
  644. }
  645. #endregion 计算 上垫层人力成本 结束
  646. #region 计算 下垫层人力成本 开始
  647. if (!string.IsNullOrEmpty(bednet.felt_hr_formula) && bednet.felt_x_qty > 0)
  648. {
  649. bednet.felt_hr_x_cost_replace_formula = bednet.felt_hr_formula;
  650. CalSpringMtrlCol2(bednet, mx, springList, "下垫层");
  651. var rp_formula = "";
  652. bednet.felt_hr_x_cost += Calculate(bednet.felt_hr_x_cost_replace_formula, out rp_formula, "下垫层人力成本").DecimalValue;
  653. bednet.felt_hr_x_cost_replace_formula = rp_formula;
  654. AddKeyValue("下垫层人力成本", bednet.felt_hr_x_cost);
  655. AddFormulaMxKeyValue("【下垫层人力成本】", bednet.felt_hr_formula);
  656. }
  657. #endregion 计算 下垫层人力成本 结束
  658. #region 计算 包装总成本 开始
  659. if (!string.IsNullOrEmpty(bednet.packet_mtrl_formula) && !string.IsNullOrEmpty(bednet.packtype))
  660. {
  661. bednet.packet_mtrl_cost_replace_formula = bednet.packet_mtrl_formula;
  662. bool sqlCal = !string.IsNullOrEmpty(bednet.packet_mtrl_formula) && bednet.packet_mtrl_formula.TrimStart().Substring(0, 2) == "@@";
  663. bednet.packet_mtrl_cost_replace_formula = bednet.packet_mtrl_cost_replace_formula.Replace("@@", "");
  664. if(sqlCal) bednet.packet_mtrl_cost += Convert.ToDecimal(SqlCalculate(bednet.packet_mtrl_cost_replace_formula, "包装总成本"));
  665. else bednet.packet_mtrl_cost += Calculate(bednet.packet_mtrl_cost_replace_formula, "包装总成本").DecimalValue;
  666. AddKeyValue("包装总成本", bednet.packet_mtrl_cost);
  667. AddFormulaMxKeyValue("【包装总成本】", bednet.packet_mtrl_formula);
  668. }
  669. #endregion 计算 包装总成本 结束
  670. #region 计算 包装人工成本 开始
  671. if (!string.IsNullOrEmpty(bednet.packet_hr_formula) && !string.IsNullOrEmpty(bednet.packtype))
  672. {
  673. bednet.packet_hr_cost_replace_formula = bednet.packet_hr_formula;
  674. bool sqlCal = !string.IsNullOrEmpty(bednet.packet_hr_formula) && bednet.packet_hr_formula.TrimStart().Substring(0, 2) == "@@";
  675. bednet.packet_hr_cost_replace_formula = bednet.packet_hr_cost_replace_formula.Replace("@@", "");
  676. if (sqlCal) bednet.packet_hr_cost += Convert.ToDecimal(SqlCalculate(bednet.packet_hr_cost_replace_formula, "包装人工成本"));
  677. else bednet.packet_hr_cost += Calculate(bednet.packet_hr_cost_replace_formula, "包装人工成本").DecimalValue;
  678. AddKeyValue("包装人工成本", bednet.packet_hr_cost);
  679. AddFormulaMxKeyValue("【包装人工成本】", bednet.packet_hr_formula);
  680. }
  681. #endregion 计算 包装人工成本 结束
  682. //有外销的 工厂利润率 增加 0.06
  683. if (bednet.ifsaleout == 1)
  684. {
  685. bednet.sale_point = 0.06M;
  686. }
  687. AddKeyValue("外销加点", bednet.sale_point);
  688. }
  689. // 计算总材料成本 total_mtrl_cost
  690. bednet.total_mtrl_cost = new decimal[]
  691. {
  692. bednet.spring_mtrl_cost.Value,
  693. bednet.snake_wire_mtrl_cost.Value,
  694. bednet.pocket_around_spring_cost.Value,
  695. bednet.pocket_around_fabrics_cost.Value,
  696. bednet.hard_around_mtrl_cost.Value,
  697. bednet.glue_mtrl_cost.Value,
  698. bednet.fabrics1_mtrl_cost.Value,
  699. bednet.fabrics2_mtrl_cost.Value,
  700. bednet.side_iron_mtrl_cost.Value,
  701. bednet.cnail_mtrl_cost.Value,
  702. bednet.sponge_mtrl_cost.Value,
  703. bednet.sponge_mtrl_tc_cost.Value,
  704. bednet.edge_mtrl_cost.Value,
  705. bednet.fork_mtrl_cost.Value,
  706. bednet.rsorwa_mtrl_cost.Value,
  707. bednet.felt_mtrl_cost.Value,
  708. bednet.felt_mtrl_x_cost.Value,
  709. bednet.packet_mtrl_cost.Value
  710. }.Sum();
  711. AddKeyValue("总材料成本", bednet.total_mtrl_cost);
  712. // 计算总人力费用 total_mtrl_cost
  713. bednet.total_hr_cost = new decimal[]
  714. {
  715. bednet.spring_hr_cost.Value,
  716. bednet.hard_around_hr_cost.Value,
  717. bednet.side_iron_hr_cost.Value,
  718. bednet.cnail_hr_cost.Value,
  719. bednet.sponge_hr_cost.Value,
  720. bednet.edge_hr_cost.Value,
  721. bednet.fork_hr_cost.Value,
  722. bednet.rsorwa_hr_cost.Value,
  723. bednet.felt_hr_cost.Value,
  724. bednet.felt_hr_x_cost.Value,
  725. bednet.packet_hr_cost.Value,
  726. bednet.sponge_drilling_hr_cost.Value
  727. }.Sum();
  728. AddKeyValue("总人力费用", bednet.total_hr_cost);
  729. //1.总成本=总材料成本+总人力费用+ 额外费用
  730. //bednet.total_cost = bednet.total_mtrl_cost + bednet.total_hr_cost + bednet.total_fees_cost;
  731. bednet.total_cost = CalculateVarFormula("车间成本").DecimalValue;
  732. AddKeyValue("车间成本", bednet.total_cost);
  733. //2-不含税出厂价=总成本* ( 工厂利润率 + 外销加点 )
  734. //bednet.nottax_factory_cost = bednet.total_cost * (bednet.profitrate + bednet.sale_point);
  735. bednet.nottax_factory_cost = CalculateVarFormula("不含税出厂价").DecimalValue;
  736. AddKeyValue("不含税出厂价", bednet.nottax_factory_cost);
  737. // 3 - 部门不含税价 = 不含税出厂价 / 部门利润率 * 佣金点数 * 额外点数 + fob
  738. //bednet.nottax_dept_cost = bednet.nottax_factory_cost / bednet.dept_profitrate / (1 - (bednet.commission - 1)) * bednet.other_rate + bednet.fob;
  739. bednet.nottax_dept_cost = CalculateVarFormula("部门不含税价").DecimalValue;
  740. AddKeyValue("部门不含税价", bednet.nottax_dept_cost);
  741. // 4 - 税金 = (部门不含税价 * 税率 - 1)
  742. //bednet.taxes = bednet.nottax_dept_cost * (bednet.taxrate - 1);
  743. bednet.taxes = CalculateVarFormula("税金").DecimalValue;
  744. AddKeyValue("税金", bednet.taxes);
  745. // 5 - 部门含税价 = 部门不含税价 * 税率
  746. //bednet.dept_cost = bednet.nottax_dept_cost * bednet.taxrate;
  747. bednet.dept_cost = CalculateVarFormula("部门含税价").DecimalValue;
  748. AddKeyValue("部门含税价", bednet.dept_cost);
  749. // 6 - 外币价 = 部门含税价 / 汇率
  750. //if (bednet.moneyrate != 0)
  751. //{
  752. // bednet.foreign_cost = bednet.dept_cost / bednet.moneyrate;
  753. //}
  754. bednet.foreign_cost = CalculateVarFormula("外币价").DecimalValue;
  755. AddKeyValue("外币价", bednet.foreign_cost);
  756. 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;
  757. AddKeyValue("计划价", computed_plan);
  758. }
  759. private void CulcalateWeight(u_bednet bednet, List<u_bednetmx> mxlist, List<u_bednetmx_spring> springList)
  760. {
  761. bednet.spring_weight_qty = 0;
  762. bednet.side_iron_weight_qty = 0;
  763. bednet.hard_around_weight_qty = 0;
  764. bednet.fabrics1_weight_qty = 0;
  765. bednet.fabrics2_weight_qty = 0;
  766. bednet.felt_weight_qty = 0;
  767. bednet.cnail_weight_qty = 0;
  768. bednet.sponge_weight_tc_qty = 0;
  769. bednet.sponge_weight_qty = 0;
  770. bednet.edge_weight_qty = 0;
  771. bednet.fork_weight_qty = 0;
  772. foreach (var mx in mxlist)
  773. {
  774. #region 计算 钢丝重量 开始
  775. if (!string.IsNullOrEmpty(bednet.spring_weight_formula))
  776. {
  777. mx.spring_weight_replace_formula = bednet.spring_weight_formula;
  778. if (mx.if_part == 0)
  779. {
  780. //单分区
  781. bednet.spring_weight_qty += Calculate(mx.spring_weight_replace_formula, "钢丝重量").DecimalValue;
  782. }
  783. else
  784. {
  785. var index = 1;
  786. //多分区
  787. foreach (var springItem in springList)
  788. {
  789. var _formula = bednet.spring_weight_formula;
  790. springItem.spring_weight_replace_formula = bednet.spring_weight_formula;
  791. CalSpringMtrlCol(bednet, mx, springItem,ref _formula, index);
  792. var rp_formula = "";
  793. bednet.spring_weight_qty += Calculate(_formula, out rp_formula, "钢丝重量").DecimalValue;
  794. springItem.spring_weight_replace_formula = rp_formula;
  795. AddFormulaWeightKeyValue("【" + index + "钢丝重量】", _formula, true);
  796. index++;
  797. }
  798. }
  799. AddKeyValue("弹簧排列个数-宽", mx.spring_qty_width);
  800. AddKeyValue("弹簧排列个数-长", mx.spring_qty_length);
  801. AddKeyValue("弹簧计算个数(宽)", mx.spring_qty_width);
  802. AddKeyValue("弹簧计算个数(长)", mx.spring_qty_length);
  803. AddKeyValue("钢丝重量", bednet.spring_weight_qty);
  804. AddFormulaWeightKeyValue("【钢丝重量】", bednet.spring_weight_formula, true);
  805. }
  806. else
  807. {
  808. AddKeyValue("钢丝重量", 0);
  809. }
  810. #endregion 计算 钢丝重量 结束
  811. #region 计算 边铁重量 开始
  812. if (!string.IsNullOrEmpty(bednet.side_iron_weight_formula) && bednet.if_side_iron == 1 && mx.if_side_iron > 0)
  813. {
  814. bednet.side_iron_weight_replace_formula = bednet.side_iron_weight_formula;
  815. bednet.side_iron_weight_qty += Calculate(bednet.side_iron_weight_replace_formula, "边铁重量").DecimalValue;
  816. AddKeyValue("边铁重量", bednet.side_iron_weight_qty);
  817. AddFormulaWeightKeyValue("【边铁重量】", bednet.side_iron_weight_formula);
  818. }
  819. else
  820. {
  821. AddKeyValue("边铁重量", 0);
  822. }
  823. #endregion 计算 边铁重量 结束
  824. #region 计算 四周加硬重量 开始
  825. if (!string.IsNullOrEmpty(bednet.hard_around_weight_formula) && mx.if_hard_around > 0)
  826. {
  827. bednet.hard_around_weight_replace_formula = bednet.hard_around_weight_formula;
  828. bednet.hard_around_weight_replace_formula = bednet.hard_around_weight_replace_formula.Replace("【弹簧重/个】", "【加硬弹簧重/个】").Replace("【弹簧重】", "【加硬弹簧重】");
  829. bednet.hard_around_weight_qty += Calculate(bednet.hard_around_weight_replace_formula, "四周加硬重量").DecimalValue;
  830. AddKeyValue("四周加硬重量", bednet.hard_around_weight_qty);
  831. AddFormulaWeightKeyValue("【四周加硬重量】", bednet.hard_around_weight_formula.Replace("【弹簧重/个】", "【加硬弹簧重/个】").Replace("【弹簧重】", "【加硬弹簧重】"));
  832. }
  833. else
  834. {
  835. AddKeyValue("四周加硬重量", 0);
  836. }
  837. #endregion 计算 四周加硬重量 结束
  838. #region 计算 入袋无纺布重量 开始
  839. if (!string.IsNullOrEmpty(bednet.fabrics1_weight_formula) && bednet.typename.IndexOf("袋装网") > -1 && mx.fabrics1_mtrlid > 0)
  840. {
  841. bednet.fabrics1_weight_replace_formula = bednet.fabrics1_weight_formula;
  842. bednet.fabrics1_weight_qty += Calculate(bednet.fabrics1_weight_replace_formula, "入袋无纺布重量").DecimalValue;
  843. AddKeyValue("入袋无纺布重量", bednet.fabrics1_weight_qty);
  844. AddFormulaWeightKeyValue("【入袋无纺布重量】", bednet.fabrics1_weight_formula);
  845. }
  846. else
  847. {
  848. AddKeyValue("入袋无纺布重量", 0);
  849. }
  850. #endregion 计算 入袋无纺布重量 结束
  851. #region 计算 面底无纺布重量 开始
  852. if (!string.IsNullOrEmpty(bednet.fabrics2_weight_formula) && bednet.typename.IndexOf("袋装网") > -1 && mx.fabrics2_mtrlid > 0)
  853. {
  854. bednet.fabrics2_weight_replace_formula = bednet.fabrics2_weight_formula;
  855. bednet.fabrics2_weight_qty += Calculate(bednet.fabrics2_weight_replace_formula, "面底无纺布重量").DecimalValue;
  856. AddKeyValue("面底无纺布重量", bednet.fabrics2_weight_qty);
  857. AddFormulaWeightKeyValue("【面底无纺布重量】", bednet.fabrics2_weight_formula);
  858. }
  859. else
  860. {
  861. AddKeyValue("面底无纺布重量", 0);
  862. }
  863. #endregion 计算 面底无纺布重量 结束
  864. #region 计算 上垫层重量 开始
  865. string felt_weight_formula_replace_formula = "";
  866. if (!string.IsNullOrEmpty(bednet.felt_mtrl_formula) && bednet.felt_qty > 0)
  867. {
  868. felt_weight_formula_replace_formula = bednet.felt_weight_formula;
  869. CalSpringMtrlCol2(bednet, mx, springList, "上垫层");
  870. bednet.felt_weight_qty += Calculate(felt_weight_formula_replace_formula, "上/下垫层重量").DecimalValue;
  871. AddKeyValue("上/下垫层重量", bednet.felt_weight_qty);
  872. AddFormulaWeightKeyValue("【上/下垫层重量】", bednet.felt_weight_formula);
  873. }
  874. else
  875. {
  876. AddKeyValue("上/下垫层重量", 0);
  877. }
  878. #endregion 计算 上垫层重量 结束
  879. #region 计算 下垫层重量 开始
  880. string felt_x_weight_formula_replace_formula = "";
  881. if (!string.IsNullOrEmpty(bednet.felt_weight_formula) && bednet.felt_x_qty > 0)
  882. {
  883. felt_x_weight_formula_replace_formula = bednet.felt_weight_formula;
  884. CalSpringMtrlCol2(bednet, mx, springList, "下垫层");
  885. bednet.felt_weight_qty += Calculate(felt_x_weight_formula_replace_formula, "上/下垫层重量").DecimalValue;
  886. AddKeyValue("上/下垫层重量", bednet.felt_weight_qty);
  887. AddFormulaWeightKeyValue("【上/下垫层重量】", bednet.felt_weight_formula);
  888. }
  889. else
  890. {
  891. AddKeyValue("上/下垫层重量", 0);
  892. }
  893. bednet.felt_weight_replace_formula += felt_weight_formula_replace_formula;
  894. bednet.felt_weight_replace_formula += Environment.NewLine;
  895. bednet.felt_weight_replace_formula += felt_x_weight_formula_replace_formula;
  896. #endregion 计算 下垫层重量 结束
  897. #region 计算 C钉/夹码重量 开始
  898. if (!string.IsNullOrEmpty(bednet.cnail_weight_formula))
  899. {
  900. bednet.cnail_weight_replace_formula = bednet.cnail_weight_formula;
  901. bednet.cnail_weight_qty += Calculate(bednet.cnail_weight_replace_formula, "C钉/夹码重量").DecimalValue;
  902. AddKeyValue("C钉/夹码重量", bednet.cnail_weight_qty);
  903. AddFormulaWeightKeyValue("【C钉/夹码重量】", bednet.cnail_weight_formula);
  904. }
  905. else
  906. {
  907. AddKeyValue("C钉/夹码重量", 0);
  908. }
  909. #endregion 计算 C钉/夹码重量 结束
  910. #region 计算 海绵包边重量 开始
  911. if (!string.IsNullOrEmpty(bednet.sponge_weight_formula) && bednet.sponge_mtrlid > 0)
  912. {
  913. bednet.sponge_weight_replace_formula = bednet.sponge_weight_formula;
  914. bednet.sponge_weight_qty += Calculate(bednet.sponge_weight_replace_formula, "海绵包边重量").DecimalValue;
  915. AddKeyValue("海绵包边重量", bednet.sponge_weight_qty);
  916. AddFormulaWeightKeyValue("【海绵包边重量】", bednet.sponge_weight_formula);
  917. }
  918. else
  919. {
  920. AddKeyValue("海绵包边重量", 0);
  921. }
  922. #endregion 计算 海绵包边重量 结束
  923. #region 计算 填充海绵重量 开始
  924. if (!string.IsNullOrEmpty(bednet.sponge_weight_tc_formula) && bednet.sponge_tc_mtrlid > 0)
  925. {
  926. bednet.sponge_weight_tc_replace_formula = bednet.sponge_weight_tc_formula;
  927. CalSpringMtrlCol2(bednet, mx, springList, "填充海绵");
  928. bednet.sponge_weight_tc_qty += Calculate(bednet.sponge_weight_tc_replace_formula, "填充海绵重量").DecimalValue;
  929. AddKeyValue("填充海绵重量", bednet.sponge_weight_tc_qty);
  930. AddFormulaWeightKeyValue("【填充海绵重量】", bednet.sponge_weight_tc_formula);
  931. }
  932. else
  933. {
  934. AddKeyValue("填充海绵重量", 0);
  935. }
  936. #endregion 计算 填充海绵重量 结束
  937. #region 计算 封边材料重量 开始
  938. if (!string.IsNullOrEmpty(bednet.edge_weight_formula) && bednet.edge_mtrlid > 0)
  939. {
  940. bednet.edge_weight_replace_formula = bednet.edge_weight_formula;
  941. CalSpringMtrlCol2(bednet, mx, springList, "封边");
  942. bednet.edge_weight_qty += Calculate(bednet.edge_weight_replace_formula, "封边材料重量").DecimalValue;
  943. AddKeyValue("封边材料重量", bednet.edge_weight_qty);
  944. AddFormulaWeightKeyValue("【封边材料重量】", bednet.edge_weight_formula);
  945. }
  946. else
  947. {
  948. AddKeyValue("封边材料重量", 0);
  949. }
  950. #endregion 计算 封边材料重量 结束
  951. #region 计算 弹叉材料重量 开始
  952. if (!string.IsNullOrEmpty(bednet.fork_weight_formula) && bednet.fork_qty > 0)
  953. {
  954. bednet.fork_weight_replace_formula = bednet.fork_weight_formula;
  955. bednet.fork_weight_qty += Calculate(bednet.fork_weight_replace_formula, "弹叉材料重量").DecimalValue;
  956. AddKeyValue("弹叉材料重量", bednet.fork_weight_qty);
  957. AddFormulaWeightKeyValue("【弹叉材料重量】", bednet.fork_weight_formula);
  958. }
  959. else
  960. {
  961. AddKeyValue("弹叉材料重量", 0);
  962. }
  963. #endregion 计算 弹叉材料重量 结束
  964. }
  965. // 计算总材料重量
  966. bednet.sum_weight = new decimal[]
  967. {
  968. bednet.spring_weight_qty.Value,
  969. bednet.side_iron_weight_qty.Value,
  970. bednet.hard_around_weight_qty.Value,
  971. bednet.fabrics1_weight_qty.Value,
  972. bednet.fabrics2_weight_qty.Value,
  973. bednet.felt_weight_qty.Value,
  974. bednet.cnail_weight_qty.Value,
  975. bednet.sponge_weight_qty.Value,
  976. bednet.sponge_weight_tc_qty.Value,
  977. bednet.edge_weight_qty.Value,
  978. bednet.fork_weight_qty.Value
  979. }.Sum();
  980. AddKeyValue("总重量", bednet.sum_weight);
  981. if (!formula_replacements_hide.ContainsKey("【总重量】")) AddFormulaHideKeyValue("总重量", "【钢丝重量】+【边铁重量】+【四周加硬重量】+【入袋无纺布重量】+【面底无纺布重量】+【上/下垫层重量】+【C钉/夹码重量】+【海绵包边重量】+【填充海绵重量】+【封边材料重量】+【弹叉材料重量】");
  982. }
  983. private void InitBedNet(u_bednet bednet, Boolean isCalBed = true)
  984. {
  985. var dept = Cache.GetData<u_dept,DeptMapping>(bednet.deptid.Value);
  986. //var profirate = new u_factory_profitrate() { deptid = bednet.deptid, bednettypeid_mattresstypeid = bednet.bednettypeid, bednet_or_mattress = 0 };
  987. //DbSqlHelper.SelectOne(cmd, profirate, "profitrate");
  988. decimal profitrate = 0;
  989. cmd.CommandText = @"SELECT profitrate FROM u_factory_profitrate
  990. WHERE deptid = @deptid
  991. AND bednettypeid_mattresstypeid = @bednettypeid_mattresstypeid
  992. AND bednet_or_mattress = 0";
  993. cmd.Parameters.Clear();
  994. cmd.Parameters.AddWithValue("@deptid", bednet.deptid);
  995. cmd.Parameters.AddWithValue("@bednettypeid_mattresstypeid", bednet.bednettypeid);
  996. using (var reader = cmd.ExecuteReader())
  997. {
  998. if (reader.Read())
  999. {
  1000. profitrate = Convert.ToDecimal(reader["profitrate"]);
  1001. }
  1002. }
  1003. var bednetType = new u_bednet_type() { bednettypeid = bednet.bednettypeid };
  1004. DbSqlHelper.SelectOne(cmd, bednetType, "typename");
  1005. bednet.pricelistid = dept.pricelistid;
  1006. bednet.typename = bednetType.typename;
  1007. bednet.profitrate = profitrate;
  1008. bednet.dept_profitrate = dept.profitrate;
  1009. bednet.moneyrate = bednet.moneyrate ?? 1;
  1010. bednet.commission = bednet.commission ?? 1;
  1011. bednet.taxrate = bednet.taxrate ?? 1;
  1012. bednet.other_rate = bednet.other_rate ?? 1;
  1013. bednet.dept_profitrate = bednet.dept_profitrate ?? 0;
  1014. // 检查佣金是否小于1
  1015. if (bednet.commission < 1)
  1016. {
  1017. throw new LJCommonException("佣金点数不能小于1!");
  1018. }
  1019. // 检查税率是否小于1
  1020. if (bednet.taxrate < 1)
  1021. {
  1022. throw new LJCommonException("税率不能小于1!");
  1023. }
  1024. // 检查额外点数是否小于1
  1025. if (bednet.other_rate < 1)
  1026. {
  1027. throw new LJCommonException("税率不能小于1!");
  1028. }
  1029. // 检查部门利润率是否为0
  1030. if (bednet.dept_profitrate == 0)
  1031. {
  1032. throw new LJCommonException("部门利润率不能为0!");
  1033. }
  1034. }
  1035. private void InitSptringRepaceMents(u_spring spring)
  1036. {
  1037. AddKeyValue("中心直径", spring.center_diameter);
  1038. AddKeyValue("线径MM", spring.line_diameter);
  1039. AddKeyValue("高度CM", spring.height);
  1040. AddKeyValue("口径CM", spring.caliber);
  1041. AddKeyValue("圈数", spring.cyclenum);
  1042. AddKeyValue("克重KG", spring.gram_weight);
  1043. AddKeyValue("卷排列宽", spring.roll_width == null ? 0 : spring.roll_width);
  1044. AddKeyValue("卷排列长", spring.roll_length == null ? 0 : spring.roll_length);
  1045. AddKeyValue("排列宽", spring.arrangement_width == null ? 0 : spring.arrangement_width);
  1046. AddKeyValue("排列长", spring.arrangement_height == null ? 0 : spring.arrangement_height);
  1047. AddKeyValue("弹簧类型id", spring.springtypeid);
  1048. }
  1049. private void InitReplaceMents(u_bednet bednet, Boolean isCalBed = true, int dannumType = 2, decimal dannumRate = 0)
  1050. {
  1051. replacements.Clear();
  1052. var bednetVarList = new List<u_bednet_var>();
  1053. var selectStr = "";
  1054. var whereList = new List<string>();
  1055. var param = new Dictionary<string, object>();
  1056. // 公式
  1057. AddFormulaKeyValue("车间成本", "【总材料成本】+【总人力费用】+ 【额外费用】");
  1058. AddFormulaKeyValue("不含税出厂价", "【车间成本】*(【工厂利润率】+【外销加点】)");
  1059. AddFormulaKeyValue("部门不含税价", "【不含税出厂价】/【部门利润率】/( 1 - (【佣金点数】- 1))*【额外点数】+【FOB】");
  1060. AddFormulaKeyValue("税金", "【部门不含税价】* (【税率】-1)");
  1061. AddFormulaKeyValue("部门含税价", "【部门不含税价】*【税率】");
  1062. AddFormulaKeyValue("外币价", "【部门含税价】/【汇率】");
  1063. AddFormulaKeyValue("计划价", "【车间成本】 - 【海绵包边材料成本】 - 【上垫层物料成本】 - 【下垫层物料成本】 - 【包装总成本】 - 【包装人工成本】");
  1064. //AddFormulaHideKeyValue("总材料成本", "【弹簧材料总成本】+【蛇线材料成本】+【四周口袋弹簧成本】+【四周口袋无纺布成本】+【四周加硬材料成本】+【胶水材料成本】+【入袋无纺布材料成本】+【底面无纺布材料成本】+【边铁材料成本】+【C钉/夹码材料成本】+【海绵包边材料成本】+【填充海绵成本】+【封边材料成本】+【弹叉材料成本】+【胶条/包角材料成本】+【上垫层物料成本】+【下垫层物料成本】+【包装总成本】");
  1065. //AddFormulaHideKeyValue("总人力费用", "【弹簧总人工成本】+【四周加硬人力成本】+【边铁人力成本】+【C钉/夹码人力成本】+【海绵包边人力成本】+【封边人力成本】+【弹叉人力成本】+【胶条/包角人力成本】+【上垫层人力成本】+【下垫层人力成本】+【包装人工成本】+【海绵打孔人力成本】");
  1066. // 初始变量
  1067. AddKeyValue("床垫宽", bednet.mattress_width);
  1068. AddKeyValue("床垫长", bednet.mattress_length);
  1069. AddKeyValue("床垫高", bednet.mattress_height);
  1070. AddKeyValue("规格宽", bednet.mattress_width);
  1071. AddKeyValue("规格长", bednet.mattress_length);
  1072. AddKeyValue("规格高", bednet.mattress_height);
  1073. AddKeyValue("双簧", bednet.if_doublespring);
  1074. AddKeyValue("弹叉数量", bednet.fork_qty);
  1075. AddKeyValue("包装方式", bednet.packtype);
  1076. AddKeyValue("包装数量", bednet.packqty);
  1077. AddKeyValue("运输方式", bednet.transport_type);
  1078. AddKeyValue("包装材料", bednet.packmtrl);
  1079. AddKeyValue("床网类别", bednet.typename);
  1080. AddKeyValue("工厂利润率", bednet.profitrate);
  1081. AddKeyValue("部门利润率", bednet.dept_profitrate);
  1082. AddKeyValue("佣金点数", bednet.commission);
  1083. AddKeyValue("额外点数", bednet.other_rate);
  1084. AddKeyValue("额外费用", bednet.extras_cost);
  1085. AddKeyValue("FOB", bednet.fob);
  1086. AddKeyValue("汇率", bednet.moneyrate);
  1087. AddKeyValue("税率", bednet.taxrate);
  1088. AddKeyValue("卷包", bednet.if_jb);
  1089. AddKeyValue("海绵包边", !string.IsNullOrEmpty(bednet.sponge_mtrl_formula) && bednet.sponge_mtrlid > 0 ? 1 : 0);
  1090. AddKeyValue("大小单系数", bednet.dannum_rate != null ? bednet.dannum_rate : 0);
  1091. var _dannumType = 0;
  1092. // 备货床网,勾选则不按床垫大小单系数,统一使用标准系数计算
  1093. if (bednet.if_stock_up == 1)
  1094. {
  1095. _dannumType = 2;
  1096. }
  1097. else
  1098. {
  1099. _dannumType = bednet.dannum_type != null ? bednet.dannum_type.Value : 2;
  1100. }
  1101. AddKeyValue("大小单类型", _dannumType);
  1102. // 实时获取变量
  1103. selectStr = @"SELECT u_bednet_varmx.varid AS varid
  1104. ,varkind
  1105. ,varcode
  1106. ,varname
  1107. ,varclass
  1108. ,vartype
  1109. ,varunit
  1110. ,u_bednet_varmx.varvalue AS varvalue
  1111. FROM u_bednet_var
  1112. INNER JOIN u_bednet_varmx ON u_bednet_varmx.varid = u_bednet_var.varid";
  1113. whereList = new List<string>();
  1114. whereList.Add("u_bednet_var.varclass < 2"); // 非公式
  1115. whereList.Add("u_bednet_var.varkind = @varkind");
  1116. whereList.Add("u_bednet_varmx.pricelistid = @pricelistid");
  1117. whereList.Add(@"(u_bednet_var.varclass = 1
  1118. AND (
  1119. u_bednet_varmx.bednettypeid = @bednettypeid
  1120. OR @bednettypeid = 0
  1121. )
  1122. )
  1123. OR (u_bednet_var.varclass = 0)");
  1124. param = new Dictionary<string, object>();
  1125. param.Add("@varkind", 0);
  1126. param.Add("@pricelistid", bednet.pricelistid);
  1127. param.Add("@bednettypeid", bednet.bednettypeid);
  1128. DbSqlHelper.SelectJoin(cmd, selectStr, ListEx.GetWhereStr(whereList), param, "varid", "varid,varkind,varcode,varname,varclass,vartype,varunit,varvalue", 0, 0, bednetVarList);
  1129. foreach (var netvar in bednetVarList)
  1130. {
  1131. AddKeyValue(netvar.varname, netvar.varvalue);
  1132. }
  1133. if (isCalBed)
  1134. {
  1135. selectStr = @"SELECT varid
  1136. ,varkind
  1137. ,varcode
  1138. ,varname
  1139. ,varclass
  1140. ,vartype
  1141. ,varunit
  1142. ,formula
  1143. ,ifmxformula
  1144. FROM u_bednet_var";
  1145. bednetVarList = new List<u_bednet_var>();
  1146. whereList = new List<string>();
  1147. whereList.Add("u_bednet_var.varkind = @varkind");
  1148. whereList.Add("u_bednet_var.varclass = @varclass");
  1149. param = new Dictionary<string, object>();
  1150. param.Add("@varkind", 0);
  1151. param.Add("@varclass", 2); // 公式
  1152. DbSqlHelper.SelectJoin(cmd, selectStr, ListEx.GetWhereStr(whereList), param, "varid", "varid,varkind,varcode,varname,varclass,vartype,varunit,formula,ifmxformula", 0, 0, bednetVarList);
  1153. string[] keys = { "车间成本", "不含税出厂价", "部门不含税价", "税金", "部门含税价", "外币价", "计划价"};
  1154. // 添加替换公式变量
  1155. foreach (var netvar in bednetVarList)
  1156. {
  1157. if (netvar.ifmxformula > 0)
  1158. {
  1159. AddFormulaKeyValue(netvar.varname, netvar.formula);
  1160. }
  1161. else if (keys.Contains(netvar.varname))
  1162. {
  1163. AddFormulaKeyValue(netvar.varname, netvar.formula);
  1164. }
  1165. else
  1166. {
  1167. AddFormulaHideKeyValue(netvar.varname, netvar.formula);
  1168. }
  1169. }
  1170. string[] formula_keys = { "大小单系数" };
  1171. // 参数型公式,先执行
  1172. foreach (var replacement in formula_replacements_hide)
  1173. {
  1174. if (formula_keys.Contains(replacement.Key))
  1175. {
  1176. var _key = replacement.Key.Replace("【", "").Replace("】", "");
  1177. var value = CalculateVarFormula(_key).DecimalValue;
  1178. AddKeyValue(_key, value);
  1179. }
  1180. }
  1181. }
  1182. }
  1183. private void InitMxReplaceMents(u_bednet bednet,u_bednetmx mx, u_spring spring)
  1184. {
  1185. AddKeyValue("弹簧排列个数-宽", mx.spring_qty_width);
  1186. AddKeyValue("弹簧排列个数-长", mx.spring_qty_length);
  1187. AddKeyValue("弹簧计算个数(宽)", mx.spring_qty_width);
  1188. AddKeyValue("弹簧计算个数(长)", mx.spring_qty_length);
  1189. AddKeyValue("边铁条数", mx.side_iron_qty);
  1190. AddKeyValue("条数", mx.side_iron_qty);
  1191. AddKeyValue("四周口袋-排数", mx.pocket_around_row);
  1192. AddKeyValue("四周口袋", mx.if_pocket_around);
  1193. AddKeyValue("四周加硬-排数", mx.hard_around_row);
  1194. AddKeyValue("四周加硬", mx.if_hard_around);
  1195. spring.gram_weight /= 1000;
  1196. if (spring.gram_weight > 0)
  1197. {
  1198. AddKeyValue("弹簧重/个", spring.gram_weight);
  1199. AddKeyValue("弹簧重", spring.gram_weight);
  1200. AddKeyValue("弹簧克重", spring.gram_weight * 1000);
  1201. }
  1202. if (mx.bednet_height > 0)
  1203. {
  1204. AddKeyValue("床网高", mx.bednet_height);
  1205. }
  1206. GetSpringPrice(bednet.pricelistid.Value, "弹簧单价", 0, spring.line_diameter ?? 0);
  1207. }
  1208. /// <summary>
  1209. /// 用于床网报价 弹簧材料总成本 弹簧人工总成本
  1210. /// </summary>
  1211. /// <param name="cmd"></param>
  1212. /// <param name="dept"></param>
  1213. /// <param name="mx"></param>
  1214. /// <param name="mx2"></param>
  1215. private void CalSpringMtrlCol(u_bednet bednet, u_bednetmx mx, u_bednetmx_spring mx2,ref string formula, int index)
  1216. {
  1217. AddKeyValue(index + "弹簧排列个数-宽", mx2.spring_qty_width);
  1218. AddKeyValue(index + "弹簧排列个数-长", mx2.spring_qty_length);
  1219. AddKeyValue(index + "弹簧计算个数(宽)", mx2.spring_qty_width);
  1220. AddKeyValue(index + "弹簧计算个数(长)", mx2.spring_qty_length);
  1221. formula = formula.Replace("【弹簧排列个数-宽】", "【" + index +"弹簧排列个数-宽】");
  1222. formula = formula.Replace("【弹簧排列个数-长】", "【" + index + "弹簧排列个数-长】");
  1223. formula = formula.Replace("【弹簧计算个数(宽)】", "【" + index + "弹簧计算个数(宽)】");
  1224. formula = formula.Replace("【弹簧计算个数(长)】", "【" + index + "弹簧计算个数(长)】");
  1225. AddKeyValue("边铁条数", mx.side_iron_qty);
  1226. AddKeyValue("条数", mx.side_iron_qty);
  1227. var spring = Cache.GetData<u_spring,SpringMapping>(mx2.springid.Value);
  1228. spring.gram_weight /= 1000;
  1229. if (spring.gram_weight > 0)
  1230. {
  1231. AddKeyValue(index + "弹簧重/个", spring.gram_weight);
  1232. AddKeyValue(index + "弹簧重", spring.gram_weight);
  1233. formula = formula.Replace("【弹簧重/个】", "【" + index + "弹簧重/个】");
  1234. formula = formula.Replace("【弹簧重】", "【" + index + "弹簧重】");
  1235. }
  1236. cmd.CommandText = @"SELECT TOP 1 isnull(u_mtrl_price_pricelist.price, 0) AS price
  1237. FROM u_mtrl_price_pricelist
  1238. INNER JOIN u_mtrl_price ON u_mtrl_price.mtrlid = u_mtrl_price_pricelist.mtrlid
  1239. WHERE cast(u_mtrl_price.name AS DECIMAL(18, 5)) = @line_diameter
  1240. AND u_mtrl_price.mtrltype = 0
  1241. AND u_mtrl_price_pricelist.pricelistid = @pricelistid";
  1242. cmd.Parameters.Clear();
  1243. cmd.Parameters.AddWithValue("@line_diameter", spring.line_diameter);
  1244. cmd.Parameters.AddWithValue("@pricelistid", bednet.pricelistid);
  1245. decimal price = 0;
  1246. using (var reader = cmd.ExecuteReader())
  1247. {
  1248. if (reader.Read())
  1249. {
  1250. price = Convert.ToDecimal(reader["price"]);
  1251. price /= 1000;
  1252. }
  1253. }
  1254. if (price > 0)
  1255. {
  1256. AddKeyValue(index + "弹簧单价", price);
  1257. formula = formula.Replace("【弹簧单价】", "【" + index + "弹簧单价】");
  1258. }
  1259. }
  1260. /// <summary>
  1261. /// 代码对照wf_replace_var_dw2
  1262. /// </summary>
  1263. /// <param name="cmd"></param>
  1264. /// <param name="mx"></param>
  1265. private void CalSpringMtrlCol2(u_bednet bednet, u_bednetmx mx, List<u_bednetmx_spring> springList, string type)
  1266. {
  1267. var spring = Cache.GetData<u_spring, SpringMapping>(mx.springid.Value);
  1268. #region 计算 底面无纺布 开始
  1269. //计算 上下无纺布方数 =(B4+C4)*(B4+D4)/10000
  1270. if ("底面无纺布".Equals(type) && mx.fabrics2_mtrlid > 0)
  1271. {
  1272. decimal fabrics = (decimal)((mx.bednet_height.Value + bednet.mattress_width.Value) * (mx.bednet_height.Value + bednet.mattress_length.Value)) / 10000;
  1273. AddKeyValue("上下无纺布方数", fabrics);
  1274. decimal fabrics_price = getMtrlPrice(2, bednet.pricelistid.Value, mx.fabrics2_mtrlid.Value);
  1275. if (fabrics_price > 0) AddKeyValue("无纺布单价", fabrics_price);
  1276. }
  1277. #endregion 计算 底面无纺布 结束
  1278. #region 计算 入袋无纺布 开始
  1279. //计算 入袋无纺布方数 = (B4+I4+2)*((I4*3.14)+1)/10000
  1280. if ("入袋无纺布".Equals(type) && mx.fabrics1_mtrlid > 0)
  1281. {
  1282. var _springid = mx.springid;
  1283. if (_springid == 0 && springList.Count > 0)
  1284. {
  1285. _springid = springList[0].springid;
  1286. }
  1287. var _spring = Cache.GetData<u_spring, SpringMapping>(_springid.Value);
  1288. spring.center_diameter = _spring.center_diameter == null ? 0 : _spring.center_diameter;
  1289. decimal fabrics = (decimal)((mx.bednet_height.Value + _spring.center_diameter.Value + 2) * (_spring.center_diameter.Value * (decimal)3.14 + 1)) / 10000;
  1290. string fabrics_str = fabrics.ToString("###0.#####");
  1291. AddKeyValue("入袋无纺布方数", fabrics_str);
  1292. decimal fabrics_price = getMtrlPrice(2, bednet.pricelistid.Value, mx.fabrics1_mtrlid.Value);
  1293. if (fabrics_price > 0) AddKeyValue("无纺布单价", fabrics_price);
  1294. }
  1295. #endregion 计算 入袋无纺布 结束
  1296. #region 计算 四周加硬弹簧 开始
  1297. // 主要是要替换 【弹簧克重】 【弹簧单价】
  1298. // 因相同部分已存在,不需要后续
  1299. #endregion 计算 四周加硬弹簧 结束
  1300. #region 计算 海绵包边 开始
  1301. if ("海绵包边".Equals(type) && bednet.sponge_thickness.Value > 0 && bednet.sponge_mtrlid.Value > 0)
  1302. {
  1303. var mtrl_price = new u_mtrl_price() { mtrlid = bednet.sponge_mtrlid };
  1304. DbSqlHelper.SelectOne(cmd, mtrl_price, "name");
  1305. AddKeyValue("物料名称", mtrl_price.name);
  1306. AddKeyValue("裥棉厚度", bednet.sponge_thickness.Value);
  1307. AddKeyValue("海绵厚度", bednet.sponge_thickness.Value);
  1308. AddKeyValue("海绵包边厚度", bednet.sponge_thickness.Value);
  1309. if (bednet.sponge_height.Value > 0)
  1310. {
  1311. AddKeyValue("海绵高", bednet.sponge_height.Value);
  1312. }
  1313. cmd.CommandText = @"SELECT isnull(u_mtrl_price_pricelist.price, 0) AS price
  1314. FROM u_mtrl_price_pricelist
  1315. WHERE u_mtrl_price_pricelist.mtrlid = @mtrlid
  1316. AND u_mtrl_price_pricelist.pricelistid = @pricelistid";
  1317. cmd.Parameters.Clear();
  1318. cmd.Parameters.AddWithValue("@mtrlid", bednet.sponge_mtrlid);
  1319. cmd.Parameters.AddWithValue("@pricelistid", bednet.pricelistid);
  1320. using (var reader = cmd.ExecuteReader())
  1321. {
  1322. if (reader.Read())
  1323. {
  1324. decimal sponge_price = Convert.ToDecimal(reader["price"]);
  1325. AddKeyValue("裥棉单价", sponge_price);
  1326. AddKeyValue("海绵单价", sponge_price);
  1327. }
  1328. }
  1329. }
  1330. else
  1331. {
  1332. AddKeyValue("海绵包边厚度", 0);
  1333. }
  1334. #endregion 计算 海绵包边 结束
  1335. #region 计算 填充海绵 开始
  1336. if ("填充海绵".Equals(type) && bednet.sponge_tc_thickness.Value > 0 && bednet.sponge_tc_mtrlid.Value > 0)
  1337. {
  1338. var mtrl_price = new u_mtrl_price() { mtrlid = bednet.sponge_tc_mtrlid };
  1339. DbSqlHelper.SelectOne(cmd, mtrl_price, "name");
  1340. AddKeyValue("物料名称", mtrl_price.name);
  1341. AddKeyValue("裥棉厚度", bednet.sponge_tc_thickness.Value);
  1342. AddKeyValue("海绵厚度", bednet.sponge_tc_thickness.Value);
  1343. AddKeyValue("填充海绵厚度", bednet.sponge_tc_thickness.Value);
  1344. if (bednet.sponge_tc_height.Value > 0)
  1345. {
  1346. AddKeyValue("海绵高", bednet.sponge_tc_height.Value);
  1347. }
  1348. cmd.CommandText = @"SELECT isnull(u_mtrl_price_pricelist.price, 0) AS price
  1349. FROM u_mtrl_price_pricelist
  1350. WHERE u_mtrl_price_pricelist.mtrlid = @mtrlid
  1351. AND u_mtrl_price_pricelist.pricelistid = @pricelistid";
  1352. cmd.Parameters.Clear();
  1353. cmd.Parameters.AddWithValue("@mtrlid", bednet.sponge_tc_mtrlid);
  1354. cmd.Parameters.AddWithValue("@pricelistid", bednet.pricelistid);
  1355. using (var reader = cmd.ExecuteReader())
  1356. {
  1357. if (reader.Read())
  1358. {
  1359. decimal sponge_price = Convert.ToDecimal(reader["price"]);
  1360. AddKeyValue("裥棉单价", sponge_price);
  1361. AddKeyValue("海绵单价", sponge_price);
  1362. }
  1363. }
  1364. }
  1365. else
  1366. {
  1367. AddKeyValue("填充海绵厚度", 0);
  1368. }
  1369. #endregion 计算 填充海绵 结束
  1370. #region 计算 封边 开始
  1371. if ("封边".Equals(type) && bednet.edge_mtrlid > 0)
  1372. {
  1373. AddKeyValue("有边铁", mx.if_side_iron);
  1374. cmd.CommandText = @"SELECT isnull(u_mtrl_price_pricelist.price, 0) AS price
  1375. ,u_mtrl_price.gram_weight
  1376. FROM u_mtrl_price_pricelist
  1377. INNER JOIN u_mtrl_price ON u_mtrl_price.mtrlid = u_mtrl_price_pricelist.mtrlid
  1378. WHERE u_mtrl_price_pricelist.mtrlid = @mtrlid
  1379. AND u_mtrl_price_pricelist.pricelistid = @pricelistid";
  1380. cmd.Parameters.Clear();
  1381. cmd.Parameters.AddWithValue("@mtrlid", bednet.edge_mtrlid);
  1382. cmd.Parameters.AddWithValue("@pricelistid", bednet.pricelistid);
  1383. using (var reader = cmd.ExecuteReader())
  1384. {
  1385. if (reader.Read())
  1386. {
  1387. decimal edge_price = Convert.ToDecimal(reader["price"]);
  1388. decimal edge_weight = Convert.ToDecimal(reader["gram_weight"]);
  1389. if (edge_price > 0) AddKeyValue("毡单价", edge_price);
  1390. if (edge_weight > 0) AddKeyValue("毡克重", edge_weight);
  1391. }
  1392. }
  1393. if (bednet.edge_height > 0) AddKeyValue("封边高", bednet.edge_height);
  1394. }
  1395. #endregion 计算 封边 结束
  1396. #region 计算 上垫层 开始
  1397. if ("上垫层".Equals(type) && bednet.felt_mtrlid > 0)
  1398. {
  1399. cmd.CommandText = @"SELECT isnull(u_mtrl_price_pricelist.price, 0) AS price
  1400. ,u_mtrl_price.gram_weight
  1401. FROM u_mtrl_price_pricelist
  1402. INNER JOIN u_mtrl_price ON u_mtrl_price.mtrlid = u_mtrl_price_pricelist.mtrlid
  1403. WHERE u_mtrl_price_pricelist.mtrlid = @mtrlid
  1404. AND u_mtrl_price_pricelist.pricelistid = @pricelistid";
  1405. cmd.Parameters.Clear();
  1406. cmd.Parameters.AddWithValue("@mtrlid", bednet.felt_mtrlid);
  1407. cmd.Parameters.AddWithValue("@pricelistid", bednet.pricelistid);
  1408. using (var reader = cmd.ExecuteReader())
  1409. {
  1410. if (reader.Read())
  1411. {
  1412. decimal felt_price = Convert.ToDecimal(reader["price"]);
  1413. decimal felt_weight = Convert.ToDecimal(reader["gram_weight"]);
  1414. if (felt_price > 0) AddKeyValue("垫层物料单价", felt_price);
  1415. if (felt_weight > 0) AddKeyValue("垫层物料克重", felt_weight);
  1416. }
  1417. }
  1418. if (bednet.felt_qty > 0) AddKeyValue("垫层物料数量", bednet.felt_qty);
  1419. }
  1420. #endregion 计算 上垫层 结束
  1421. #region 计算 下垫层 开始
  1422. if ("下垫层".Equals(type) && bednet.felt_x_mtrlid > 0)
  1423. {
  1424. cmd.CommandText = @"SELECT isnull(u_mtrl_price_pricelist.price, 0) AS price
  1425. ,u_mtrl_price.gram_weight
  1426. FROM u_mtrl_price_pricelist
  1427. INNER JOIN u_mtrl_price ON u_mtrl_price.mtrlid = u_mtrl_price_pricelist.mtrlid
  1428. WHERE u_mtrl_price_pricelist.mtrlid = @mtrlid
  1429. AND u_mtrl_price_pricelist.pricelistid = @pricelistid";
  1430. cmd.Parameters.Clear();
  1431. cmd.Parameters.AddWithValue("@mtrlid", bednet.felt_x_mtrlid);
  1432. cmd.Parameters.AddWithValue("@pricelistid", bednet.pricelistid);
  1433. using (var reader = cmd.ExecuteReader())
  1434. {
  1435. if (reader.Read())
  1436. {
  1437. decimal felt_price = Convert.ToDecimal(reader["price"]);
  1438. decimal felt_weight = Convert.ToDecimal(reader["gram_weight"]);
  1439. if (felt_price > 0) AddKeyValue("垫层物料单价", felt_price);
  1440. if (felt_weight > 0) AddKeyValue("垫层物料克重", felt_weight);
  1441. }
  1442. }
  1443. if (bednet.felt_x_qty > 0) AddKeyValue("垫层物料数量", bednet.felt_x_qty);
  1444. }
  1445. #endregion 计算 下垫层 结束
  1446. }
  1447. private u_spring GetSpringPrice(int pricelistid, string KeyName, int? springId, decimal line_diameter = 0, string springName = "")
  1448. {
  1449. var spring = new u_spring() { springid = springId };
  1450. if (line_diameter == 0)
  1451. {
  1452. spring = Cache.GetData<u_spring, SpringMapping>(springId.Value);
  1453. AddKeyValue(springName + "弹簧重/个", spring.gram_weight / 1000);
  1454. AddKeyValue(springName + "弹簧重", spring.gram_weight / 1000);
  1455. }
  1456. else
  1457. {
  1458. spring.line_diameter = line_diameter;
  1459. }
  1460. cmd.CommandText = @"SELECT TOP 1 isnull(u_mtrl_price_pricelist.price, 0) AS price
  1461. FROM u_mtrl_price_pricelist
  1462. INNER JOIN u_mtrl_price ON u_mtrl_price.mtrlid = u_mtrl_price_pricelist.mtrlid
  1463. WHERE cast(u_mtrl_price.name AS DECIMAL(18, 5)) = @line_diameter
  1464. AND u_mtrl_price.mtrltype = 0
  1465. AND u_mtrl_price_pricelist.pricelistid = @pricelistid";
  1466. cmd.Parameters.Clear();
  1467. cmd.Parameters.AddWithValue("@line_diameter", spring.line_diameter ?? 0);
  1468. cmd.Parameters.AddWithValue("@pricelistid", pricelistid);
  1469. decimal price = 0;
  1470. using (var reader = cmd.ExecuteReader())
  1471. {
  1472. if (reader.Read())
  1473. {
  1474. price = Convert.ToDecimal(reader["price"]);
  1475. price /= 1000;
  1476. }
  1477. }
  1478. AddKeyValue(KeyName, price);
  1479. return spring;
  1480. }
  1481. private decimal getMtrlPrice(int mtrltype, int pricelistid, int mtrlid)
  1482. {
  1483. decimal price = 0;
  1484. cmd.CommandText = @"SELECT TOP 1 isnull(u_mtrl_price_pricelist.price, 0) AS price
  1485. FROM u_mtrl_price_pricelist
  1486. INNER JOIN u_mtrl_price ON u_mtrl_price.mtrlid = u_mtrl_price_pricelist.mtrlid
  1487. WHERE u_mtrl_price.mtrlid = @mtrlid
  1488. AND u_mtrl_price.mtrltype = @mtrltype
  1489. AND u_mtrl_price_pricelist.pricelistid = @pricelistid";
  1490. cmd.Parameters.Clear();
  1491. cmd.Parameters.AddWithValue("@mtrlid", mtrlid);
  1492. cmd.Parameters.AddWithValue("@mtrltype", mtrltype);
  1493. cmd.Parameters.AddWithValue("@pricelistid", pricelistid);
  1494. using (var reader = cmd.ExecuteReader())
  1495. {
  1496. if (reader.Read())
  1497. {
  1498. price = Convert.ToDecimal(reader["price"]);
  1499. //price /= 1000;
  1500. }
  1501. }
  1502. return price;
  1503. }
  1504. private string ConvertToEnglishSymbols(string input)
  1505. {
  1506. input = input.Replace("(", "(")
  1507. .Replace(")", ")")
  1508. .Replace(",", ",")
  1509. .Replace("。", ".")
  1510. .Replace(":", ":")
  1511. .Replace(";", ";")
  1512. .Replace("“", "\"")
  1513. .Replace("”", "\"")
  1514. .Replace("‘", "'")
  1515. .Replace("’", "'");
  1516. return input;
  1517. }
  1518. private void AddKeyValue(string key, object value, bool isReplace = true)
  1519. {
  1520. key = $"【{key}】";
  1521. if (!replacements.ContainsKey(key))
  1522. {
  1523. replacements.Add(key, value);
  1524. }
  1525. else if (isReplace)
  1526. {
  1527. replacements[key] = value;
  1528. }
  1529. }
  1530. private void AddFormulaKeyValue(string key, string value, bool isReplace = true, int ifnotreplace = 0)
  1531. {
  1532. var formulaItem = new formulaItem()
  1533. {
  1534. value = value,
  1535. ifnotreplace = ifnotreplace
  1536. };
  1537. key = $"【{key}】";
  1538. if (!formula_replacements.ContainsKey(key))
  1539. {
  1540. formula_replacements.Add(key, formulaItem);
  1541. }
  1542. else if (isReplace)
  1543. {
  1544. formula_replacements[key] = formulaItem;
  1545. }
  1546. }
  1547. /// <summary>
  1548. /// 记录隐藏公式
  1549. /// </summary>
  1550. /// <param name="key"></param>
  1551. /// <param name="value"></param>
  1552. /// <param name="isReplace"></param>
  1553. private void AddFormulaHideKeyValue(string key, string value, bool isReplace = true, int ifnotreplace = 0)
  1554. {
  1555. var formulaItem = new formulaItem()
  1556. {
  1557. value = value,
  1558. ifnotreplace = ifnotreplace
  1559. };
  1560. key = $"【{key}】";
  1561. if (!formula_replacements_hide.ContainsKey(key))
  1562. {
  1563. formula_replacements_hide.Add(key, formulaItem);
  1564. }
  1565. else if (isReplace)
  1566. {
  1567. formula_replacements_hide[key] = formulaItem;
  1568. }
  1569. }
  1570. /// <summary>
  1571. /// 记录详细公式
  1572. /// </summary>
  1573. /// <param name="key"></param>
  1574. /// <param name="value"></param>
  1575. /// <param name="isReplace"></param>
  1576. private void AddFormulaMxKeyValue(string key, string value, bool isReplace = true, int ifnotreplace = 0)
  1577. {
  1578. var formulaItem = new formulaItem()
  1579. {
  1580. value = value,
  1581. ifnotreplace = ifnotreplace
  1582. };
  1583. if (!formula_replacements_mx.ContainsKey(key))
  1584. {
  1585. formula_replacements_mx.Add(key, formulaItem);
  1586. }
  1587. else if (isReplace)
  1588. {
  1589. formula_replacements_mx[key] = formulaItem;
  1590. }
  1591. }
  1592. /// <summary>
  1593. /// 记录重量公式
  1594. /// </summary>
  1595. /// <param name="key"></param>
  1596. /// <param name="value"></param>
  1597. /// <param name="isReplace"></param>
  1598. private void AddFormulaWeightKeyValue(string key, string value, bool isReplace = true, int ifnotreplace = 0)
  1599. {
  1600. var formulaItem = new formulaItem()
  1601. {
  1602. value = value,
  1603. ifnotreplace = ifnotreplace
  1604. };
  1605. if (!formula_replacements_weight.ContainsKey(key))
  1606. {
  1607. formula_replacements_weight.Add(key, formulaItem);
  1608. }
  1609. else if (isReplace)
  1610. {
  1611. formula_replacements_weight[key] = formulaItem;
  1612. }
  1613. }
  1614. private string ReplaceWith(string input, string oldValue, string newValue)
  1615. {
  1616. return input.Replace(oldValue, newValue);
  1617. }
  1618. private TData CalculateVarFormula(string varname)
  1619. {
  1620. varname = $"【{varname}】";
  1621. if (formula_replacements.ContainsKey(varname)) return Calculate(formula_replacements[varname].value, varname);
  1622. if (formula_replacements_hide.ContainsKey(varname)) return Calculate(formula_replacements_hide[varname].value, varname);
  1623. return null;
  1624. }
  1625. private void replaceFormulas(ref string expression)
  1626. {
  1627. bool hasReplace = false;
  1628. foreach (var replacement in formula_replacements)
  1629. {
  1630. if (expression.IndexOf(replacement.Key) > -1)
  1631. {
  1632. expression = expression.Replace(replacement.Key, "(" + replacement.Value.value + ")");
  1633. hasReplace = true;
  1634. }
  1635. }
  1636. if (hasReplace)
  1637. {
  1638. replaceFormulas(ref expression);
  1639. }
  1640. }
  1641. private void replaceFormulasHide(ref string expression)
  1642. {
  1643. bool hasReplace = false;
  1644. foreach (var replacement in formula_replacements_hide)
  1645. {
  1646. if (expression.IndexOf(replacement.Key) > -1)
  1647. {
  1648. expression = expression.Replace(replacement.Key, "(" + replacement.Value.value + ")");
  1649. hasReplace = true;
  1650. }
  1651. }
  1652. if (hasReplace)
  1653. {
  1654. replaceFormulasHide(ref expression);
  1655. }
  1656. }
  1657. private void FormatExpression(ref string expression)
  1658. {
  1659. // 替换相互嵌套的公式
  1660. replaceFormulas(ref expression);
  1661. replaceFormulasHide(ref expression);
  1662. expression = ConvertToEnglishSymbols(expression);
  1663. // 定义正则表达式模式,匹配包含【】的内容
  1664. string pattern = @"【(.*?)】";
  1665. // 创建正则表达式对象
  1666. Regex regex = new Regex(pattern);
  1667. // 使用正则表达式匹配输入字符串
  1668. MatchCollection matches = regex.Matches(expression);
  1669. var new_replacements = new Dictionary<string, object>();
  1670. foreach (Match match in matches)
  1671. {
  1672. if (replacements.TryGetValue(match.Value, out object value2))
  1673. {
  1674. new_replacements[match.Value] = value2;
  1675. }
  1676. }
  1677. foreach (var replacement in new_replacements)
  1678. {
  1679. expression = expression.Replace(replacement.Key, Convert.ToString(replacement.Value));
  1680. }
  1681. }
  1682. private TData Calculate(string expression,string name = "")
  1683. {
  1684. FormatExpression(ref expression);
  1685. try
  1686. {
  1687. return LJExprParser.Parse(expression).Result;
  1688. } catch (Exception ex)
  1689. {
  1690. throw new LJCommonException($"计算{name}公式错误!expression: {expression},exception: {ex.Message}");
  1691. }
  1692. }
  1693. private TData Calculate(string expression, out string expressionOut, string name = "")
  1694. {
  1695. FormatExpression(ref expression);
  1696. expressionOut = expression;
  1697. try
  1698. {
  1699. return LJExprParser.Parse(expression).Result;
  1700. }
  1701. catch (Exception ex)
  1702. {
  1703. throw new LJCommonException($"计算{name}公式错误!expression: {expression},exception: {ex.Message}");
  1704. }
  1705. }
  1706. public static bool IsNumber(string input)
  1707. {
  1708. // 正则表达式匹配数字,包括正负号和小数点
  1709. string pattern = @"^[+-]?(\d+(\.\d*)?|\.\d+)$";
  1710. return Regex.IsMatch(input, pattern);
  1711. }
  1712. private object SqlCalculate(string expression, string name = "")
  1713. {
  1714. expression = ConvertToEnglishSymbols(expression);
  1715. expression = ReplaceWith(expression, "@@", "");
  1716. // 定义正则表达式模式,匹配包含【】的内容
  1717. string pattern = @"【(.*?)】";
  1718. // 创建正则表达式对象
  1719. Regex regex = new Regex(pattern);
  1720. // 使用正则表达式匹配输入字符串
  1721. MatchCollection matches = regex.Matches(expression);
  1722. var new_formula_replacements = new Dictionary<string, string>();
  1723. var new_replacements = new Dictionary<string, object>();
  1724. foreach (Match match in matches)
  1725. {
  1726. // 检查原始字典中是否存在该键,并添加到新字典中
  1727. if (formula_replacements.TryGetValue(match.Value, out formulaItem item))
  1728. {
  1729. new_formula_replacements[match.Value] = item.value;
  1730. }
  1731. if (replacements.TryGetValue(match.Value, out object value2))
  1732. {
  1733. new_replacements[match.Value] = value2;
  1734. }
  1735. }
  1736. foreach (var replacement in new_formula_replacements)
  1737. {
  1738. expression = expression.Replace(replacement.Key, replacement.Value);
  1739. }
  1740. foreach (var replacement in new_replacements)
  1741. {
  1742. var _rep = Convert.ToString(replacement.Value);
  1743. if (!IsNumber(_rep))
  1744. {
  1745. _rep = "'" + _rep + "'";
  1746. }
  1747. expression = expression.Replace(replacement.Key, " " + _rep);
  1748. }
  1749. try
  1750. {
  1751. cmd.CommandText = $@"{expression}";
  1752. cmd.Parameters.Clear();
  1753. var result = cmd.ExecuteScalar();
  1754. return result != null && result != DBNull.Value ? result : 0;
  1755. }
  1756. catch (Exception ex)
  1757. {
  1758. throw new LJCommonException($"计算{name}公式错误!expression: {expression},exception: {ex.Message}");
  1759. }
  1760. }
  1761. public u_bednet GetBedNet(int bednetid)
  1762. {
  1763. var bednet = new u_bednet() { bednetid = bednetid };
  1764. var outputFields = @"bednetid,deptid,bednettypeid,mattress_width,mattress_length,mattress_height,if_doublenet,if_doublespring,snake_wire_diameter,
  1765. snake_wire_mtrl_formula,snake_wire_mtrl_cost,pocket_around_spring_formula,pocket_around_spring_cost,pocket_around_fabrics_formula,
  1766. pocket_around_fabrics_cost,hard_around_mtrl_formula,hard_around_mtrl_cost,hard_around_hr_formula,hard_around_hr_cost,
  1767. spring_mtrl_cost,spring_hr_cost,glue_price,glue_mtrl_formula,glue_mtrl_cost,fabrics1_mtrl_formula,fabrics1_mtrl_cost,
  1768. fabrics2_mtrl_formula,fabrics2_mtrl_cost,if_side_iron,side_iron_lossrate,side_iron_price,side_iron_mtrl_formula,
  1769. side_iron_mtrl_cost,side_iron_hr_formula,side_iron_hr_cost,cnail_price,cnail_mtrl_formula,cnail_mtrl_cost,cnail_hr_formula,
  1770. cnail_hr_cost,sponge_mtrlid,sponge_thickness,sponge_price,sponge_mtrl_formula,sponge_mtrl_cost,sponge_hr_formula,
  1771. sponge_hr_cost,edge_mtrlid,edge_price,edge_mtrl_formula,edge_mtrl_cost,edge_hr_formula,edge_hr_cost,fork_qty,fork_price,
  1772. fork_mtrl_formula,fork_mtrl_cost,fork_hr_formula,fork_hr_cost,if_rsORwa,rsORwa_price,rsORwa_mtrl_formula,rsORwa_mtrl_cost,
  1773. rsORwa_hr_formula,rsORwa_hr_cost,if_sponge_drilling,sponge_drilling_hr_formula,sponge_drilling_hr_cost,total_hr_cost,
  1774. total_mtrl_cost,total_fees_cost,total_cost,createtime,createby,bednetcode,bednetname,spring_mtrl_formula,spring_hr_formula,
  1775. sponge_mtrl_cost_replace_formula,sponge_hr_cost_replace_formula,edge_mtrl_cost_replace_formula,edge_hr_cost_replace_formula,
  1776. fork_mtrl_cost_replace_formula,fork_hr_cost_replace_formula,rsORwa_mtrl_cost_replace_formula,rsORwa_hr_cost_replace_formula,
  1777. sponge_drilling_hr_cost_replace_formula,snake_wire_mtrl_cost_replace_formula,flag,taxrate,taxes,commissionrate,commission,fob,
  1778. profitrate,nottax_factory_cost,nottax_dept_cost,dept_cost,foreign_cost,extras_cost,dept_profitrate,moneyrate,temp_flag,felt_mtrlid,
  1779. felt_qty,felt_price,felt_dscrp,felt_mtrl_formula,felt_mtrl_cost,felt_hr_formula,felt_hr_cost,felt_mtrl_cost_replace_formula,
  1780. felt_hr_cost_replace_formula,extras_cost_dscrp,iffork,ifsaleout,autotype,felt_mtrl_x_cost,felt_hr_x_cost,felt_x_qty,
  1781. felt_mtrl_x_cost_replace_formula,felt_hr_x_cost_replace_formula,felt_x_mtrlid,sale_point,packtype,packqty,other_rate,
  1782. transport_type,packmtrl,packet_mtrl_formula,packet_hr_formula,packet_mtrl_cost,packet_hr_cost,packet_mtrl_cost_replace_formula,
  1783. packet_hr_cost_replace_formula,sponge_height,edge_height,sponge_tc_thickness,sponge_tc_height,sponge_tc_mtrlid,sponge_mtrl_tc_cost,
  1784. sponge_mtrl_tc_formula,sponge_mtrl_tc_cost_replace_formula,sum_weight,spring_weight,snake_weight,side_weight,duo_qv_str,
  1785. spring_weight_formula,side_iron_weight_formula,hard_around_weight_formula,fabrics1_weight_formula,fabrics2_weight_formula,
  1786. felt_weight_formula,cnail_weight_formula,sponge_weight_formula,sponge_weight_tc_formula,edge_weight_formula,fork_weight_formula,
  1787. spring_weight_replace_formula,side_iron_weight_replace_formula,hard_around_weight_replace_formula,fabrics1_weight_replace_formula,
  1788. fabrics2_weight_replace_formula,felt_weight_replace_formula,cnail_weight_replace_formula,sponge_weight_replace_formula,
  1789. sponge_weight_tc_replace_formula,edge_weight_replace_formula,fork_weight_replace_formula,spring_weight_qty,
  1790. side_iron_weight_qty,hard_around_weight_qty,fabrics1_weight_qty,fabrics2_weight_qty,felt_weight_qty,
  1791. cnail_weight_qty,sponge_weight_qty,sponge_weight_tc_qty,edge_weight_qty,fork_weight_qty,if_jb,if_stock_up";
  1792. DbSqlHelper.SelectOne(cmd, bednet, outputFields);
  1793. return bednet;
  1794. }
  1795. public u_bednet GetBedNet(int bednetid,string fields)
  1796. {
  1797. if (bednetid <= 0)
  1798. {
  1799. throw new LJCommonException("查找床网报价失败,ID错误!");
  1800. }
  1801. var bednet = new u_bednet() { bednetid = bednetid };
  1802. var outputFields = fields ?? @"bednetid,deptid,bednettypeid,mattress_width,mattress_length,mattress_height,if_doublenet,if_doublespring,snake_wire_diameter,
  1803. snake_wire_mtrl_formula,snake_wire_mtrl_cost,pocket_around_spring_formula,pocket_around_spring_cost,pocket_around_fabrics_formula,
  1804. pocket_around_fabrics_cost,hard_around_mtrl_formula,hard_around_mtrl_cost,hard_around_hr_formula,hard_around_hr_cost,
  1805. spring_mtrl_cost,spring_hr_cost,glue_price,glue_mtrl_formula,glue_mtrl_cost,fabrics1_mtrl_formula,fabrics1_mtrl_cost,
  1806. fabrics2_mtrl_formula,fabrics2_mtrl_cost,if_side_iron,side_iron_lossrate,side_iron_price,side_iron_mtrl_formula,
  1807. side_iron_mtrl_cost,side_iron_hr_formula,side_iron_hr_cost,cnail_price,cnail_mtrl_formula,cnail_mtrl_cost,cnail_hr_formula,
  1808. cnail_hr_cost,sponge_mtrlid,sponge_thickness,sponge_price,sponge_mtrl_formula,sponge_mtrl_cost,sponge_hr_formula,
  1809. sponge_hr_cost,edge_mtrlid,edge_price,edge_mtrl_formula,edge_mtrl_cost,edge_hr_formula,edge_hr_cost,fork_qty,fork_price,
  1810. fork_mtrl_formula,fork_mtrl_cost,fork_hr_formula,fork_hr_cost,if_rsORwa,rsORwa_price,rsORwa_mtrl_formula,rsORwa_mtrl_cost,
  1811. rsORwa_hr_formula,rsORwa_hr_cost,if_sponge_drilling,sponge_drilling_hr_formula,sponge_drilling_hr_cost,total_hr_cost,
  1812. total_mtrl_cost,total_fees_cost,total_cost,createtime,createby,bednetcode,bednetname,spring_mtrl_formula,spring_hr_formula,
  1813. sponge_mtrl_cost_replace_formula,sponge_hr_cost_replace_formula,edge_mtrl_cost_replace_formula,edge_hr_cost_replace_formula,
  1814. fork_mtrl_cost_replace_formula,fork_hr_cost_replace_formula,rsORwa_mtrl_cost_replace_formula,rsORwa_hr_cost_replace_formula,
  1815. sponge_drilling_hr_cost_replace_formula,snake_wire_mtrl_cost_replace_formula,flag,taxrate,taxes,commissionrate,commission,fob,
  1816. profitrate,nottax_factory_cost,nottax_dept_cost,dept_cost,foreign_cost,extras_cost,dept_profitrate,moneyrate,temp_flag,felt_mtrlid,
  1817. felt_qty,felt_price,felt_dscrp,felt_mtrl_formula,felt_mtrl_cost,felt_hr_formula,felt_hr_cost,felt_mtrl_cost_replace_formula,
  1818. felt_hr_cost_replace_formula,extras_cost_dscrp,iffork,ifsaleout,autotype,felt_mtrl_x_cost,felt_hr_x_cost,felt_x_qty,
  1819. felt_mtrl_x_cost_replace_formula,felt_hr_x_cost_replace_formula,felt_x_mtrlid,sale_point,packtype,packqty,other_rate,
  1820. transport_type,packmtrl,packet_mtrl_formula,packet_hr_formula,packet_mtrl_cost,packet_hr_cost,packet_mtrl_cost_replace_formula,
  1821. packet_hr_cost_replace_formula,sponge_height,edge_height,sponge_tc_thickness,sponge_tc_height,sponge_tc_mtrlid,sponge_mtrl_tc_cost,
  1822. sponge_mtrl_tc_formula,sponge_mtrl_tc_cost_replace_formula,sum_weight,spring_weight,snake_weight,side_weight,duo_qv_str,
  1823. spring_weight_formula,side_iron_weight_formula,hard_around_weight_formula,fabrics1_weight_formula,fabrics2_weight_formula,
  1824. felt_weight_formula,cnail_weight_formula,sponge_weight_formula,sponge_weight_tc_formula,edge_weight_formula,fork_weight_formula,
  1825. spring_weight_replace_formula,side_iron_weight_replace_formula,hard_around_weight_replace_formula,fabrics1_weight_replace_formula,
  1826. fabrics2_weight_replace_formula,felt_weight_replace_formula,cnail_weight_replace_formula,sponge_weight_replace_formula,
  1827. sponge_weight_tc_replace_formula,edge_weight_replace_formula,fork_weight_replace_formula,spring_weight_qty,
  1828. side_iron_weight_qty,hard_around_weight_qty,fabrics1_weight_qty,fabrics2_weight_qty,felt_weight_qty,
  1829. cnail_weight_qty,sponge_weight_qty,sponge_weight_tc_qty,edge_weight_qty,fork_weight_qty,if_jb,if_stock_up";
  1830. DbSqlHelper.SelectOne(cmd, bednet, outputFields);
  1831. return bednet;
  1832. }
  1833. public List<u_bednetmx_spring> GetBedNetSpringList(int bednetid)
  1834. {
  1835. var springList = new List<u_bednetmx_spring>();
  1836. 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";
  1837. var selectStr = @"SELECT bednetmx_partid
  1838. ,u_bednetmx_spring.bednetmxid AS bednetmxid
  1839. ,u_bednetmx_spring.springid AS springid
  1840. ,u_bednetmx_spring.spring_qty_width AS spring_qty_width
  1841. ,u_bednetmx_spring.spring_qty_length AS spring_qty_length
  1842. ,u_bednetmx_spring.fabrics1_mtrl_cost AS fabrics1_mtrl_cost
  1843. ,u_bednetmx_spring.spring_mtrl_cost AS spring_mtrl_cost
  1844. ,u_bednetmx_spring.spring_hr_cost AS spring_hr_cost
  1845. ,u_bednetmx_spring.spring_mtrl_cost_replace_formula AS spring_mtrl_cost_replace_formula
  1846. ,u_bednetmx_spring.spring_hr_cost_replace_formula AS spring_hr_cost_replace_formula
  1847. ,u_bednetmx_spring.spring_weight_replace_formula AS spring_weight_replace_formula
  1848. FROM u_bednetmx_spring
  1849. INNER JOIN u_bednetmx ON u_bednetmx.bednetmxid = u_bednetmx_spring.bednetmxid";
  1850. DbSqlHelper.SelectJoin(cmd,selectStr, "u_bednetmx.bednetid = @bednetid",new Dictionary<string, object>() { { "@bednetid",bednetid } }, "bednetmx_partid",outputFields,0,0,springList);
  1851. return springList;
  1852. }
  1853. /// <summary>
  1854. /// 获取床网分区系数
  1855. /// </summary>
  1856. /// <param name="areaid"></param>
  1857. /// <returns></returns>
  1858. public u_bednet_area GetBedNetArea(int areaid)
  1859. {
  1860. var outputFields = @"u_bednet_area.areaid, u_bednet_area.areaname, u_bednet_area.area_1, u_bednet_area.area_2, u_bednet_area.area_3, u_bednet_area.area_4, u_bednet_area.area_5, u_bednet_area.area_6, u_bednet_area.area_7, u_bednet_area.area_8, u_bednet_area.area_9, u_bednet_area.area_10, u_bednet_area.area_11, u_bednet_area.area_12, u_bednet_area.area_13, u_bednet_area.area_14, u_bednet_area.area_15
  1861. ,u_bednet_area.sponge_1 ,u_bednet_area.sponge_2 ,u_bednet_area.sponge_3 ,u_bednet_area.sponge_4 ,u_bednet_area.sponge_5 ,u_bednet_area.sponge_6 ,u_bednet_area.sponge_7 ,u_bednet_area.sponge_8 ,u_bednet_area.sponge_9 ,u_bednet_area.sponge_10 ,u_bednet_area.sponge_11 ,u_bednet_area.sponge_12 ,u_bednet_area.sponge_13 ,u_bednet_area.sponge_14 ,u_bednet_area.sponge_15";
  1862. var bedentArea = new u_bednet_area() { areaid = areaid };
  1863. DbSqlHelper.SelectOne(cmd, bedentArea, outputFields);
  1864. return bedentArea;
  1865. }
  1866. /// <summary>
  1867. /// 计算分配弹簧分区
  1868. /// </summary>
  1869. /// <param name="areaid"></param>
  1870. public void GetSpringListQty(u_bednet bednet, u_bednetmx bednetMx, ref List<u_bednetmx_spring> springList)
  1871. {
  1872. if (bednetMx.if_part == 1 && springList.Count > 0)
  1873. {
  1874. if (!new List<string> { "2", "3", "5", "7", "三", "三区", "五", "五区", "七", "七区","左右区" }.Contains(bednet.duo_qv_str))
  1875. {
  1876. throw new LJCommonException("主规格的床网多区设置有误,请重新设置");
  1877. return;
  1878. }
  1879. var _duoQty = bednet.duo_qv_str;
  1880. if (new List<string> { "2", "左右", "左右区" }.Contains(bednet.duo_qv_str))
  1881. {
  1882. _duoQty = "2";
  1883. } else if (new List<string> { "三", "三区" }.Contains(bednet.duo_qv_str))
  1884. {
  1885. _duoQty = "3";
  1886. }
  1887. else if (new List<string> { "五", "五区" }.Contains(bednet.duo_qv_str))
  1888. {
  1889. _duoQty = "5";
  1890. }
  1891. else if (new List<string> { "七", "七区" }.Contains(bednet.duo_qv_str))
  1892. {
  1893. _duoQty = "7";
  1894. }
  1895. var _areaid = Convert.ToInt32(_duoQty);
  1896. var bedentArea = GetBedNetArea(_areaid);
  1897. if (bedentArea.area_1 == null) {
  1898. // 无匹配终止
  1899. throw new LJCommonException("主规格的床网多区设置有误,请重新设置");
  1900. return;
  1901. }
  1902. var attrKey = "area_";
  1903. if (bednet.sponge_mtrlid > 0)
  1904. {
  1905. // 有包边读取另外的配置
  1906. attrKey = "sponge_";
  1907. }
  1908. var bednetAreaDic = ToDictionary(bedentArea);
  1909. var rateList = GetDuoquVal(bednetAreaDic, attrKey);
  1910. if(bednet.sponge_mtrlid > 0 && rateList.Count <= 0)
  1911. {
  1912. throw new LJCommonException("包边物料没有设置床网分区包边比例");
  1913. }
  1914. rateList = rateList.GetRange(0, springList.Count);
  1915. var totality = rateList.Sum();
  1916. var index = 0;
  1917. var lengthValSum = 0;
  1918. var sumLength = bednetMx.spring_qty_length.Value;
  1919. var sumWidth = bednetMx.spring_qty_width.Value;
  1920. if (bednetMx.if_hard_around > 0 && bednetMx.hard_around_row.Value > 0)
  1921. {
  1922. sumLength = sumLength - bednetMx.hard_around_row.Value * 2;
  1923. sumWidth = sumWidth - bednetMx.hard_around_row.Value * 2;
  1924. }
  1925. foreach (var _spr in springList)
  1926. {
  1927. var lengthVal = 0;
  1928. if (rateList.Count >= index + 1)
  1929. {
  1930. if (index <= rateList.Count - 1)
  1931. {
  1932. if (index == rateList.Count - 1)
  1933. {
  1934. lengthVal = sumLength - lengthValSum;
  1935. }
  1936. else
  1937. {
  1938. lengthVal = (int)Math.Round((rateList[index] / totality) * sumLength);
  1939. lengthValSum += lengthVal;
  1940. }
  1941. }
  1942. else
  1943. {
  1944. lengthVal = 0;
  1945. }
  1946. }
  1947. _spr.spring_qty_width = sumWidth;
  1948. _spr.spring_qty_length = lengthVal;
  1949. index++;
  1950. }
  1951. }
  1952. }
  1953. public Dictionary<string, object> ToDictionary(object obj)
  1954. {
  1955. var result = new Dictionary<string, object>();
  1956. if (obj == null) return result;
  1957. foreach (var prop in obj.GetType().GetProperties())
  1958. {
  1959. result[prop.Name] = prop.GetValue(obj);
  1960. }
  1961. return result;
  1962. }
  1963. public List<decimal> GetDuoquVal(Dictionary<string, object> item, string attr = "area_")
  1964. {
  1965. var arr = new List<decimal>();
  1966. foreach (var key in item.Keys)
  1967. {
  1968. if (key.Contains(attr))
  1969. {
  1970. // 尝试将值转换为 double
  1971. if (decimal.TryParse(item[key]?.ToString(), out decimal value))
  1972. {
  1973. arr.Add(value);
  1974. }
  1975. }
  1976. }
  1977. // 忽略数组末尾连续的 0
  1978. int i = arr.Count - 1;
  1979. while (i >= 0 && arr[i] == 0)
  1980. {
  1981. i--;
  1982. }
  1983. return arr.Take(i + 1).ToList();
  1984. }
  1985. public List<u_bednetmx_mtrl> GetBedNetMxMtrlList(int bednetid)
  1986. {
  1987. var mxList = new List<u_bednetmx_mtrl>();
  1988. var outputFields = @"bednetmtrlid,bednetid,formulakind,formula,mtrlid,price,gram_weight,cloth_width,if_inputqty,qty,costamt,if_success,replace_formula,priceunit,shrinkage";
  1989. var selectStr = @"SELECT u_bednetmx_mtrl.bednetmtrlid AS bednetmtrlid
  1990. ,u_bednetmx_mtrl.bednetid AS bednetid
  1991. ,u_bednetmx_mtrl.formulakind AS formulakind
  1992. ,u_bednetmx_mtrl.formula AS formula
  1993. ,u_bednetmx_mtrl.mtrlid
  1994. ,u_bednetmx_mtrl.price
  1995. ,u_bednetmx_mtrl.gram_weight
  1996. ,u_bednetmx_mtrl.cloth_width
  1997. ,u_bednetmx_mtrl.if_inputqty
  1998. ,u_bednetmx_mtrl.qty
  1999. ,u_bednetmx_mtrl.costamt
  2000. ,u_bednetmx_mtrl.if_success
  2001. ,u_bednetmx_mtrl.replace_formula
  2002. ,u_bednetmx_mtrl.priceunit
  2003. ,u_bednetmx_mtrl.shrinkage
  2004. FROM u_bednetmx_mtrl";
  2005. DbSqlHelper.SelectJoin(cmd, selectStr, "u_bednetmx_mtrl.bednetid = @bednetid", new Dictionary<string, object>() { { "@bednetid", bednetid } }, "bednetmtrlid", outputFields, 0, 0, mxList);
  2006. return mxList;
  2007. }
  2008. public List<u_bednetmx> GetBedNetMxList(int bednetid)
  2009. {
  2010. var mxList = new List<u_bednetmx>();
  2011. var outputFields = @"bednetmxid,bednetid,spring_qty_width,spring_qty_length,bednet_height,wire_mtrlid,springid,if_part,if_15strip,if_pocket_around,
  2012. pocket_around_springid,pocket_around_row,pocket_around_wire_price,pocket_around_spring_cost,pocket_around_fabrics_cost,
  2013. if_hard_around,hard_around_springid,hard_around_row,hard_around_wire_price,hard_around_mtrl_cost,hard_around_hr_cost,
  2014. fabrics1_mtrlid,fabrics1_price,fabrics1_mtrl_cost,fabrics2_mtrlid,fabrics2_price,fabrics2_mtrl_cost,if_side_iron,
  2015. side_iron_qty,side_iron_mtrl_cost,side_iron_hr_cost,pocket_around_spring_cost_replace_formula,pocket_around_fabrics_cost_replace_formula,
  2016. hard_around_mtrl_cost_replace_formula,hard_around_hr_cost_replace_formula,fabrics1_mtrl_cost_replace_formula,
  2017. fabrics2_mtrl_cost_replace_formula,side_iron_mtrl_cost_replace_formula,side_iron_hr_cost_replace_formula,
  2018. cnail_mtrl_cost_replace_formula,cnail_mtrl_cost,cnail_hr_cost_replace_formula,cnail_hr_cost,
  2019. glue_mtrl_cost_replace_formula,glue_mtrl_cost,spring_mtrl_cost,spring_hr_cost,spring_mtrl_cost_replace_formula,
  2020. spring_hr_cost_replace_formula,if_show,spring_weight_replace_formula";
  2021. var selectStr = @"SELECT bednetmxid
  2022. ,bednetid
  2023. ,spring_qty_width
  2024. ,spring_qty_length
  2025. ,bednet_height
  2026. ,wire_mtrlid
  2027. ,springid
  2028. ,if_part
  2029. ,if_15strip
  2030. ,if_pocket_around
  2031. ,pocket_around_springid
  2032. ,pocket_around_row
  2033. ,pocket_around_wire_price
  2034. ,pocket_around_spring_cost
  2035. ,pocket_around_fabrics_cost
  2036. ,if_hard_around
  2037. ,hard_around_springid
  2038. ,hard_around_row
  2039. ,hard_around_wire_price
  2040. ,hard_around_mtrl_cost
  2041. ,hard_around_hr_cost
  2042. ,fabrics1_mtrlid
  2043. ,fabrics1_price
  2044. ,fabrics1_mtrl_cost
  2045. ,fabrics2_mtrlid
  2046. ,fabrics2_price
  2047. ,fabrics2_mtrl_cost
  2048. ,if_side_iron
  2049. ,side_iron_qty
  2050. ,side_iron_mtrl_cost
  2051. ,side_iron_hr_cost
  2052. ,pocket_around_spring_cost_replace_formula
  2053. ,pocket_around_fabrics_cost_replace_formula
  2054. ,hard_around_mtrl_cost_replace_formula
  2055. ,hard_around_hr_cost_replace_formula
  2056. ,fabrics1_mtrl_cost_replace_formula
  2057. ,fabrics2_mtrl_cost_replace_formula
  2058. ,side_iron_mtrl_cost_replace_formula
  2059. ,side_iron_hr_cost_replace_formula
  2060. ,cnail_mtrl_cost_replace_formula
  2061. ,cnail_mtrl_cost
  2062. ,cnail_hr_cost_replace_formula
  2063. ,cnail_hr_cost
  2064. ,glue_mtrl_cost_replace_formula
  2065. ,glue_mtrl_cost
  2066. ,spring_mtrl_cost
  2067. ,spring_hr_cost
  2068. ,spring_mtrl_cost_replace_formula
  2069. ,spring_hr_cost_replace_formula
  2070. ,1 AS if_show
  2071. ,spring_weight_replace_formula
  2072. FROM u_bednetmx";
  2073. DbSqlHelper.SelectJoin(cmd, selectStr, "u_bednetmx.bednetid = @bednetid", new Dictionary<string, object>() { { "@bednetid", bednetid } }, "bednetmxid", outputFields, 0, 0, mxList);
  2074. return mxList;
  2075. }
  2076. public void SaveBedNet(u_bednet bednet, List<u_bednetmx> mxlist, List<u_bednetmx_spring> springList)
  2077. {
  2078. //
  2079. CalCulateFormula(bednet, mxlist, springList);
  2080. //
  2081. SaveBedNetCheck(bednet, mxlist,springList);
  2082. var dtNow = DateTime.Now;
  2083. var fields = @"deptid,bednettypeid,mattress_width,mattress_length,mattress_height,if_doublenet,if_doublespring,snake_wire_diameter,
  2084. snake_wire_mtrl_formula,snake_wire_mtrl_cost,pocket_around_spring_formula,pocket_around_spring_cost,
  2085. pocket_around_fabrics_formula,pocket_around_fabrics_cost,hard_around_mtrl_formula,hard_around_mtrl_cost,
  2086. hard_around_hr_formula,hard_around_hr_cost,spring_mtrl_cost,spring_hr_cost,glue_price,glue_mtrl_formula,
  2087. glue_mtrl_cost,fabrics1_mtrl_formula,fabrics1_mtrl_cost,fabrics2_mtrl_formula,fabrics2_mtrl_cost,
  2088. if_side_iron,side_iron_lossrate,side_iron_price,side_iron_mtrl_formula,side_iron_mtrl_cost,side_iron_hr_formula,
  2089. side_iron_hr_cost,cnail_price,cnail_mtrl_formula,cnail_mtrl_cost,cnail_hr_formula,cnail_hr_cost,sponge_mtrlid,
  2090. sponge_thickness,sponge_price,sponge_mtrl_formula,sponge_mtrl_cost,sponge_hr_formula,sponge_hr_cost,edge_mtrlid,
  2091. edge_price,edge_mtrl_formula,edge_mtrl_cost,edge_hr_formula,edge_hr_cost,fork_qty,fork_price,fork_mtrl_formula,
  2092. fork_mtrl_cost,fork_hr_formula,fork_hr_cost,if_rsORwa,rsORwa_price,rsORwa_mtrl_formula,rsORwa_mtrl_cost,rsORwa_hr_formula,
  2093. rsORwa_hr_cost,if_sponge_drilling,sponge_drilling_hr_formula,sponge_drilling_hr_cost,total_hr_cost,total_mtrl_cost,
  2094. total_fees_cost,total_cost,createtime,createby,bednetname,spring_mtrl_formula,spring_hr_formula,
  2095. sponge_mtrl_cost_replace_formula,sponge_hr_cost_replace_formula,edge_mtrl_cost_replace_formula,edge_hr_cost_replace_formula,
  2096. fork_mtrl_cost_replace_formula,fork_hr_cost_replace_formula,rsORwa_mtrl_cost_replace_formula,rsORwa_hr_cost_replace_formula,
  2097. sponge_drilling_hr_cost_replace_formula,snake_wire_mtrl_cost_replace_formula,taxrate,taxes,commissionrate,commission,fob,
  2098. profitrate,nottax_factory_cost,nottax_dept_cost,dept_cost,foreign_cost,extras_cost,dept_profitrate,moneyrate,temp_flag,
  2099. felt_mtrlid,felt_qty,felt_price,felt_dscrp,felt_mtrl_formula,felt_mtrl_cost,felt_hr_formula,felt_hr_cost,
  2100. felt_mtrl_cost_replace_formula,felt_hr_cost_replace_formula,extras_cost_dscrp,iffork,ifsaleout,autotype,
  2101. felt_mtrl_x_cost,felt_hr_x_cost,felt_x_qty,felt_mtrl_x_cost_replace_formula,felt_hr_x_cost_replace_formula,
  2102. felt_x_mtrlid,sale_point,packtype,packqty,other_rate,transport_type,packmtrl,packet_mtrl_formula,
  2103. packet_hr_formula,packet_mtrl_cost,packet_hr_cost,packet_mtrl_cost_replace_formula,packet_hr_cost_replace_formula,
  2104. sponge_height,edge_height,sponge_tc_thickness,sponge_tc_height,sponge_tc_mtrlid,sponge_mtrl_tc_formula,
  2105. sponge_mtrl_tc_cost,sponge_mtrl_tc_cost_replace_formula,duo_qv_str,spring_weight_formula,side_iron_weight_formula,
  2106. hard_around_weight_formula,fabrics1_weight_formula,fabrics2_weight_formula,felt_weight_formula,cnail_weight_formula,
  2107. sponge_weight_formula,sponge_weight_tc_formula,edge_weight_formula,fork_weight_formula,spring_weight_replace_formula,
  2108. side_iron_weight_replace_formula,hard_around_weight_replace_formula,fabrics1_weight_replace_formula,
  2109. fabrics2_weight_replace_formula,felt_weight_replace_formula,cnail_weight_replace_formula,sponge_weight_replace_formula,
  2110. sponge_weight_tc_replace_formula,edge_weight_replace_formula,fork_weight_replace_formula,spring_weight_qty,
  2111. side_iron_weight_qty,hard_around_weight_qty,fabrics1_weight_qty,fabrics2_weight_qty,felt_weight_qty,cnail_weight_qty,
  2112. sponge_weight_qty,sponge_weight_tc_qty,edge_weight_qty,fork_weight_qty,sum_weight,if_jb,flag,if_stock_up,version";
  2113. var fieldsMx = @"bednetmxid,bednetid,spring_qty_width,spring_qty_length,bednet_height,wire_mtrlid,springid,if_part,if_15strip,
  2114. if_pocket_around,pocket_around_springid,pocket_around_row,pocket_around_wire_price,pocket_around_spring_cost,
  2115. pocket_around_fabrics_cost,if_hard_around,hard_around_springid,hard_around_row,hard_around_wire_price,
  2116. hard_around_mtrl_cost,hard_around_hr_cost,fabrics1_mtrlid,fabrics1_price,fabrics1_mtrl_cost,fabrics2_mtrlid,
  2117. fabrics2_price,fabrics2_mtrl_cost,if_side_iron,side_iron_qty,side_iron_mtrl_cost,side_iron_hr_cost,
  2118. pocket_around_spring_cost_replace_formula,pocket_around_fabrics_cost_replace_formula,hard_around_mtrl_cost_replace_formula,
  2119. hard_around_hr_cost_replace_formula,fabrics1_mtrl_cost_replace_formula,fabrics2_mtrl_cost_replace_formula,
  2120. side_iron_mtrl_cost_replace_formula,side_iron_hr_cost_replace_formula,cnail_mtrl_cost_replace_formula,cnail_mtrl_cost,
  2121. cnail_hr_cost_replace_formula,cnail_hr_cost,glue_mtrl_cost_replace_formula,glue_mtrl_cost,spring_mtrl_cost,spring_hr_cost,
  2122. spring_mtrl_cost_replace_formula,spring_hr_cost_replace_formula,spring_weight_replace_formula";
  2123. var fieldsMx_spring = @"bednetmx_partid,bednetmxid,springid,spring_qty_width,spring_qty_length,fabrics1_mtrl_cost,spring_mtrl_cost,
  2124. spring_hr_cost,spring_mtrl_cost_replace_formula,spring_hr_cost_replace_formula,spring_weight_replace_formula";
  2125. if (bednet.if_stock_up == null)
  2126. {
  2127. bednet.if_stock_up = 0;
  2128. }
  2129. if (bednet.bednetid <= 0)
  2130. {
  2131. //新建
  2132. fields += ",bednetid,bednetcode";
  2133. bednet.bednetid = BllHelper.GetID(cmd, "u_bednet");
  2134. bednet.createtime = dtNow;
  2135. bednet.createby = context.tokendata.username;
  2136. bednet.version = 1;
  2137. if (string.IsNullOrEmpty(bednet.bednetcode))
  2138. {
  2139. var nettype = new u_bednet_type() { bednettypeid = bednet.bednettypeid };
  2140. DbSqlHelper.SelectOne(cmd, nettype, "typecode");
  2141. // 编号-年月日+流水
  2142. bednet.bednetcode = $"{nettype.typecode}-{dtNow.ToString("yyyyMMdd")}{(bednet.bednetid.Value % 10000).ToString("D4")}";
  2143. }
  2144. DbSqlHelper.Insert(cmd, "u_bednet", null, bednet, fields);
  2145. }
  2146. else
  2147. {
  2148. //修改
  2149. foreach (var mx in mxlist)
  2150. {
  2151. cmd.CommandText = @"DELETE FROM u_bednetmx_spring WHERE bednetmxid = @bednetmxid";
  2152. cmd.Parameters.Clear();
  2153. cmd.Parameters.AddWithValue("@bednetmxid", mx.bednetmxid);
  2154. cmd.ExecuteNonQuery();
  2155. }
  2156. cmd.CommandText = @"DELETE FROM u_bednetmx WHERE bednetid = @bednetid";
  2157. cmd.Parameters.Clear();
  2158. cmd.Parameters.AddWithValue("@bednetid", bednet.bednetid);
  2159. cmd.ExecuteNonQuery();
  2160. bednet.update_date = dtNow;
  2161. bednet.update_emp = context.tokendata.username;
  2162. bednet.version++;
  2163. fields += ",update_date,update_emp";
  2164. DbSqlHelper.Update(cmd, "u_bednet", null, bednet, "bednetid", fields);
  2165. }
  2166. foreach (var mx in mxlist)
  2167. {
  2168. mx.bednetid = bednet.bednetid;
  2169. mx.bednetmxid = BllHelper.GetID(cmd, "u_bednetmx");
  2170. DbSqlHelper.Insert(cmd, "u_bednetmx", null, mx, fieldsMx);
  2171. if (springList != null && springList.Any())
  2172. {
  2173. foreach (var spring in springList)
  2174. {
  2175. spring.bednetmxid = mx.bednetmxid;
  2176. spring.bednetmx_partid = BllHelper.GetID(cmd, "u_bednetmx_spring");
  2177. DbSqlHelper.Insert(cmd, "u_bednetmx_spring", null, spring, fieldsMx_spring);
  2178. }
  2179. }
  2180. }
  2181. var hisprice = new u_his_price
  2182. {
  2183. bednetid_mattressid = bednet.bednetid,
  2184. typeid = 0,
  2185. cmpdate = dtNow,
  2186. cmpemp = context.tokendata.username,
  2187. nottax_dept_cost = bednet.nottax_dept_cost,
  2188. dept_cost = bednet.dept_cost,
  2189. foreign_cost = bednet.foreign_cost
  2190. };
  2191. var fieldsHs = "bednetid_mattressid, typeid, cmpdate, cmpemp, nottax_dept_cost, dept_cost, foreign_cost";
  2192. DbSqlHelper.Insert(cmd, "u_his_price", null, hisprice, fieldsHs);
  2193. // 解锁
  2194. LockHelper.UnLockBill(cmd, BillKeyWord, bednet.bednetid.Value, context.tokendata.username, 0);
  2195. }
  2196. /// <summary>
  2197. /// 保存床网检测
  2198. /// </summary>
  2199. /// <param name="mattress"></param>
  2200. /// <exception cref="LJCommonException"></exception>
  2201. public void SaveBedNetCheck(u_bednet bednet, List<u_bednetmx> mxlist, List<u_bednetmx_spring> springList)
  2202. {
  2203. if (bednet == null) throw new LJCommonException("床网报价保存失败,数据异常!");
  2204. if (mxlist == null || mxlist.Count <= 0) throw new LJCommonException("床网报价保存失败,明细内容为空!");
  2205. if (bednet.bednetid > 0)
  2206. {
  2207. // 检查锁
  2208. if (LockHelper.CheckIsLock(cmd, MattressHelper.BillKeyWord, bednet.bednetid.Value, context.tokendata.username, out string arg_msg)) throw new LJCommonException(arg_msg);
  2209. // 检测版本控制
  2210. CheckBillVersion<u_bednet>(cmd, bednet.bednetid.Value, bednet.version);
  2211. }
  2212. }
  2213. public void CopyBedNet(u_bednet bednet,u_bednetmx bednetmx,out int newId)
  2214. {
  2215. var bedNet_copy = GetBedNet(bednet.bednetid.Value);
  2216. var bedNetMxList = GetBedNetMxList(bednet.bednetid.Value);
  2217. var springList = GetBedNetSpringList(bednet.bednetid.Value);
  2218. // 判断copy_bedNet.bednetcode是否存在@@字符串,如果存在,则删除@@后面的字符串,包括@@
  2219. if (bedNet_copy.bednetcode.IndexOf("@@") > -1)
  2220. {
  2221. bedNet_copy.bednetcode = bedNet_copy.bednetcode.Substring(bedNet_copy.bednetcode.IndexOf("@@"));
  2222. }
  2223. bedNet_copy.bednetcode += " @@";
  2224. bedNet_copy.bednetcode += DateTime.Now.ToString("yyyMMdd_mmhhss");
  2225. bedNet_copy.bednetid = 0;
  2226. bedNet_copy.mattress_width = bednet.mattress_width;
  2227. bedNet_copy.mattress_length = bednet.mattress_length;
  2228. foreach(var mx in bedNetMxList)
  2229. {
  2230. if(bednetmx.spring_qty_width > 0 && bednetmx.spring_qty_length > 0)
  2231. {
  2232. mx.spring_qty_length = bednetmx.spring_qty_length;
  2233. mx.spring_qty_width = bednetmx.spring_qty_width;
  2234. }
  2235. }
  2236. SaveBedNet(bedNet_copy, bedNetMxList, springList);
  2237. newId = bedNet_copy.bednetid.Value;
  2238. }
  2239. public List<u_bednet_qingdan> GetBedNetQingDan(int bednetid)
  2240. {
  2241. string bednetName = string.Empty;
  2242. string areaType = string.Empty;
  2243. string rollPackage = string.Empty;
  2244. string specifications = string.Empty;
  2245. string arrangement = string.Empty;
  2246. string bednetHeight = string.Empty;
  2247. string springs = string.Empty;
  2248. string edgeIron = string.Empty;
  2249. string bottomNonwovenFabric = string.Empty;
  2250. string topPadMaterial = string.Empty;
  2251. string bottomPadMaterial = string.Empty;
  2252. string bagNonwovenFabric = string.Empty;
  2253. string surroundingReinforcementRows = string.Empty;
  2254. string springPins = string.Empty;
  2255. string foamBorderMaterial = string.Empty;
  2256. string fillingFoamMaterial = string.Empty;
  2257. var bednet = GetBedNet(bednetid);
  2258. var mxList = GetBedNetMxList(bednetid);
  2259. var springList = GetBedNetSpringList(bednetid);
  2260. var dept = Cache.GetData<u_dept, DeptMapping>(bednet.deptid.Value); ;
  2261. if(bednet.deptid == null || bednet.deptid.Value <= 0)
  2262. {
  2263. throw new LJCommonException("获取床网清单,deptid错误");
  2264. }
  2265. if (bednet.bednettypeid == null || bednet.bednettypeid.Value <= 0)
  2266. {
  2267. throw new LJCommonException("获取床网清单,bednettypeid错误");
  2268. }
  2269. if (dept.pricelistid <= 0)
  2270. {
  2271. throw new LJCommonException("获取床网清单,pricelistid错误");
  2272. }
  2273. var bednetType = new u_bednet_type() { bednettypeid = bednet.bednettypeid };
  2274. DbSqlHelper.SelectOne(cmd, bednetType, "typename");
  2275. var mx = mxList[0];
  2276. var qdList = new List<u_bednet_qingdan>();
  2277. var nameList = new Dictionary<string,string>();
  2278. qdList.Add(new u_bednet_qingdan()
  2279. {
  2280. pzname = "床网名称"
  2281. });
  2282. var sprint_type_name = GetSpringTypeName(mx.springid.Value);
  2283. bednetName = $"{("高压缩".Equals(sprint_type_name) ? "高压缩" + bednetType.typename : bednetType.typename)}";
  2284. qdList.Add(new u_bednet_qingdan()
  2285. {
  2286. pzname = "床网类型",
  2287. pznamemx = bednetName,
  2288. amt = 0,
  2289. useqty = 0
  2290. });
  2291. qdList.Add(new u_bednet_qingdan()
  2292. {
  2293. pzname = "规格",
  2294. pznamemx = $"{bednet.mattress_width}*{bednet.mattress_length}*{bednet.mattress_height}",
  2295. amt = 0,
  2296. useqty = 0
  2297. });
  2298. specifications = $"{bednet.mattress_width}*{bednet.mattress_length}";
  2299. qdList.Add(new u_bednet_qingdan()
  2300. {
  2301. pzname = "排列",
  2302. pznamemx = $"{mx.spring_qty_width}*{mx.spring_qty_length}",
  2303. amt = 0,
  2304. useqty = 0
  2305. });
  2306. arrangement = $"{mx.spring_qty_width}*{mx.spring_qty_length}";
  2307. qdList.Add(new u_bednet_qingdan()
  2308. {
  2309. pzname = "床网高度",
  2310. pznamemx = $"{mx.bednet_height.Value.ToString("#,##0.##")}高",
  2311. amt = 0,
  2312. useqty = 0
  2313. });
  2314. bednetHeight = $"{mx.bednet_height.Value.ToString("#,##0.##")}高";
  2315. qdList.Add(new u_bednet_qingdan()
  2316. {
  2317. pzname = "弹簧线径/高度/口径/中心直径/圈数",
  2318. pznamemx = mx.if_part == 0 ? GetSpringName(mx.springid.Value) : string.Empty,
  2319. amt = 0,
  2320. useqty = 0
  2321. });
  2322. if (mx.if_part == 0)
  2323. {
  2324. springs = GetSpringName(mx.springid.Value);
  2325. }
  2326. else
  2327. {
  2328. string ls_left = string.Empty;
  2329. string ls_right = string.Empty;
  2330. string ls_t_temp = string.Empty;
  2331. string ls_t_name = string.Empty;
  2332. if (springList.Count >= 1)
  2333. {
  2334. ls_t_name = GetSpringName(springList[0].springid.Value);
  2335. int pos = ls_t_name.IndexOf('/');
  2336. if (pos > 0 && springList.Count > 1)
  2337. {
  2338. ls_left = ls_t_name.Substring(0, pos);
  2339. ls_right = ls_t_name.Substring(pos);
  2340. ls_t_temp = ls_left;
  2341. // Use StringBuilder to efficiently build ls_t_temp
  2342. StringBuilder sb = new StringBuilder(ls_t_temp);
  2343. for (int i = 1; i < springList.Count; i++)
  2344. {
  2345. ls_t_name = GetSpringName(springList[i].springid.Value);
  2346. pos = ls_t_name.IndexOf('/');
  2347. if (pos > 0)
  2348. {
  2349. ls_left = ls_t_name.Substring(0, pos);
  2350. sb.Append("+").Append(ls_left);
  2351. }
  2352. }
  2353. ls_t_temp = sb.ToString();
  2354. }
  2355. }
  2356. springs = ls_t_temp + "/" + ls_right;
  2357. }
  2358. for (int i = 1;i <= 5;i++)
  2359. {
  2360. qdList.Add(new u_bednet_qingdan()
  2361. {
  2362. pzname = $"多区弹簧{i}/高度/口径/中心直径/圈数",
  2363. pznamemx = springList.Count >= 1 && i <= springList.Count ? GetSpringName(springList[i - 1].springid.Value) : string.Empty,
  2364. amt = 0,
  2365. useqty = 0
  2366. });
  2367. }
  2368. qdList.Add(new u_bednet_qingdan()
  2369. {
  2370. pzname = "边铁条数",
  2371. pznamemx = mx.side_iron_qty > 0 ? $"{mx.side_iron_qty.Value.ToString("#,##0.##")}条" : string.Empty,
  2372. amt = 0,
  2373. useqty = 0
  2374. });
  2375. edgeIron = mx.side_iron_qty > 0 ? $"{mx.side_iron_qty.Value.ToString("#,##0.##")}条边铁" : "无边铁";
  2376. var mtrldef1 = new u_mtrl_price();
  2377. DbSqlHelper.SelectOne(cmd, "u_mtrl_price", "mtrltype = 2 AND mtrlid = @mtrlid", new Dictionary<string, object>() { { "mtrlid", mx.fabrics2_mtrlid } },mtrldef1, "name");
  2378. qdList.Add(new u_bednet_qingdan()
  2379. {
  2380. pzname = "底面无纺布",
  2381. pznamemx = mx.fabrics2_mtrlid > 0 ? mtrldef1.name : string.Empty,
  2382. amt = 0,
  2383. useqty = 0
  2384. });
  2385. bottomNonwovenFabric = mx.fabrics2_mtrlid > 0 ? mtrldef1.name : string.Empty;
  2386. var mtrldef2 = new u_mtrl_price();
  2387. DbSqlHelper.SelectOne(cmd, "u_mtrl_price", "mtrltype = 2 AND mtrlid = @mtrlid", new Dictionary<string, object>() { { "mtrlid", mx.fabrics1_mtrlid } }, mtrldef2, "name");
  2388. qdList.Add(new u_bednet_qingdan()
  2389. {
  2390. pzname = "入袋无纺布",
  2391. pznamemx = mx.fabrics1_mtrlid > 0 ? mtrldef2.name : string.Empty,
  2392. amt = 0,
  2393. useqty = 0
  2394. });
  2395. bagNonwovenFabric = mx.fabrics1_mtrlid > 0 ? mtrldef2.name : string.Empty;
  2396. var mtrldef3 = new u_mtrl_price();
  2397. DbSqlHelper.SelectOne(cmd, "u_mtrl_price", "mtrlid = @mtrlid", new Dictionary<string, object>() { { "mtrlid", bednet.felt_mtrlid } }, mtrldef3, "name");
  2398. qdList.Add(new u_bednet_qingdan()
  2399. {
  2400. pzname = "上垫层物料",
  2401. pznamemx = !string.IsNullOrEmpty(mtrldef3.name) ? mtrldef3.name : string.Empty,
  2402. amt = 0,
  2403. useqty = 0
  2404. });
  2405. topPadMaterial = !string.IsNullOrEmpty(mtrldef3.name) ? mtrldef3.name : string.Empty;
  2406. var mtrldef4 = new u_mtrl_price();
  2407. DbSqlHelper.SelectOne(cmd, "u_mtrl_price", "mtrlid = @mtrlid", new Dictionary<string, object>() { { "mtrlid", bednet.felt_x_mtrlid } }, mtrldef4, "name");
  2408. qdList.Add(new u_bednet_qingdan()
  2409. {
  2410. pzname = "下垫层物料",
  2411. pznamemx = !string.IsNullOrEmpty(mtrldef4.name) ? mtrldef4.name : string.Empty,
  2412. amt = 0,
  2413. useqty = 0
  2414. });
  2415. bottomPadMaterial = !string.IsNullOrEmpty(mtrldef4.name) ? mtrldef4.name : string.Empty;
  2416. qdList.Add(new u_bednet_qingdan()
  2417. {
  2418. pzname = "四周加硬排数",
  2419. pznamemx = mx.hard_around_row > 0 ? $"{mx.hard_around_row.Value.ToString("#,##0.##")}排{GetSpringName(mx.hard_around_springid.Value)}" : string.Empty,
  2420. amt = 0,
  2421. useqty = 0
  2422. });
  2423. surroundingReinforcementRows = mx.hard_around_row > 0 ? $"四周加硬{mx.hard_around_row.Value.ToString("#,##0.##")}排{GetSpringName(mx.hard_around_springid.Value)}" : string.Empty;
  2424. qdList.Add(new u_bednet_qingdan()
  2425. {
  2426. pzname = "四周加硬弹簧线径/高度/口径/中心直径/圈数",
  2427. pznamemx = mx.if_hard_around > 0 ? GetSpringName(mx.hard_around_springid.Value) : string.Empty,
  2428. amt = 0,
  2429. useqty = 0
  2430. });
  2431. var mtrldef5 = new u_mtrl_price();
  2432. DbSqlHelper.SelectOne(cmd, "u_mtrl_price", "mtrlid = @mtrlid", new Dictionary<string, object>() { { "mtrlid", bednet.sponge_mtrlid } }, mtrldef5, "name");
  2433. qdList.Add(new u_bednet_qingdan()
  2434. {
  2435. pzname = "海绵包边物料",
  2436. pznamemx = !string.IsNullOrEmpty(mtrldef5.name) ? mtrldef5.name : string.Empty,
  2437. amt = 0,
  2438. useqty = 0
  2439. });
  2440. foamBorderMaterial = !string.IsNullOrEmpty(mtrldef5.name) ? $"{bednet.sponge_thickness.Value.ToString("#,##0.##")}分{bednet.sponge_height.Value.ToString("#,##0.##")}高{mtrldef5.name}" : string.Empty;
  2441. var mtrldef6 = new u_mtrl_price();
  2442. DbSqlHelper.SelectOne(cmd, "u_mtrl_price", "mtrlid = @mtrlid", new Dictionary<string, object>() { { "mtrlid", bednet.sponge_tc_mtrlid } }, mtrldef6, "name");
  2443. qdList.Add(new u_bednet_qingdan()
  2444. {
  2445. pzname = "填充海绵物料",
  2446. pznamemx = !string.IsNullOrEmpty(mtrldef6.name) ? mtrldef6.name : string.Empty,
  2447. amt = 0,
  2448. useqty = 0
  2449. });
  2450. fillingFoamMaterial = !string.IsNullOrEmpty(mtrldef6.name) ? $"{bednet.sponge_tc_thickness.Value.ToString("#,##0.##")}分{bednet.sponge_tc_height.Value.ToString("#,##0.##")}高{mtrldef6.name}" : string.Empty;
  2451. qdList.Add(new u_bednet_qingdan()
  2452. {
  2453. pzname = "填充包边物料厚度",
  2454. pznamemx = bednet.sponge_tc_thickness > 0 ? $"{bednet.sponge_tc_thickness.Value.ToString("#,##0.##")}分厚,{bednet.sponge_tc_height.Value.ToString("#,##0.##")}分高,{mtrldef6.name}" : string.Empty,
  2455. amt = 0,
  2456. useqty = 0
  2457. });
  2458. var mtrldef7 = new u_mtrl_price();
  2459. DbSqlHelper.SelectOne(cmd, "u_mtrl_price", "mtrlid = @mtrlid", new Dictionary<string, object>() { { "mtrlid", bednet.edge_mtrlid } }, mtrldef7, "name");
  2460. qdList.Add(new u_bednet_qingdan()
  2461. {
  2462. pzname = "封边物料",
  2463. pznamemx = !string.IsNullOrEmpty(mtrldef7.name) ? mtrldef7.name : string.Empty,
  2464. amt = 0,
  2465. useqty = 0
  2466. });
  2467. qdList.Add(new u_bednet_qingdan()
  2468. {
  2469. pzname = "封边高度",
  2470. pznamemx = bednet.edge_height > 0 ? $"{bednet.edge_height.Value.ToString("#,##0.##")}高" : string.Empty,
  2471. amt = 0,
  2472. useqty = 0
  2473. });
  2474. qdList.Add(new u_bednet_qingdan()
  2475. {
  2476. pzname = "胶条包角",
  2477. pznamemx = bednet.if_rsorwa > 0 ? "有" : string.Empty,
  2478. amt = 0,
  2479. useqty = 0
  2480. });
  2481. qdList.Add(new u_bednet_qingdan()
  2482. {
  2483. pzname = "海绵打孔",
  2484. pznamemx = bednet.if_sponge_drilling > 0 ? "有" : string.Empty,
  2485. amt = 0,
  2486. useqty = 0
  2487. });
  2488. qdList.Add(new u_bednet_qingdan()
  2489. {
  2490. pzname = "弹叉数量",
  2491. pznamemx = bednet.fork_qty > 0 ? $"{bednet.fork_qty.Value.ToString("#,##0.##")}只弹叉" : string.Empty,
  2492. amt = 0,
  2493. useqty = 0
  2494. });
  2495. springPins = bednet.fork_qty > 0 ? $"{bednet.fork_qty.Value.ToString("#,##0.##")}只弹叉" : string.Empty;
  2496. qdList.Add(new u_bednet_qingdan()
  2497. {
  2498. pzname = "15分布条",
  2499. pznamemx = mx.if_15strip > 0 ? "有" : string.Empty,
  2500. amt = 0,
  2501. useqty = 0
  2502. });
  2503. qdList.Add(new u_bednet_qingdan()
  2504. {
  2505. pzname = "蛇线线径",
  2506. pznamemx = bednet.snake_wire_diameter > 0 ? $"{bednet.snake_wire_diameter}" : string.Empty,
  2507. amt = 0,
  2508. useqty = 0
  2509. });
  2510. qdList.Add(new u_bednet_qingdan()
  2511. {
  2512. pzname = "四周口袋弹簧排数",
  2513. pznamemx = mx.pocket_around_row > 0 ? $"{mx.pocket_around_row.Value.ToString("#,##0.##")}排" : string.Empty,
  2514. amt = 0,
  2515. useqty = 0
  2516. });
  2517. qdList.Add(new u_bednet_qingdan()
  2518. {
  2519. pzname = "四周口袋弹簧线径/高度/口径/中心直径/圈数",
  2520. pznamemx = mx.if_pocket_around > 0 ? GetSpringName(mx.pocket_around_springid.Value) : string.Empty,
  2521. amt = 0,
  2522. useqty = 0
  2523. });
  2524. //设置床网名称
  2525. //床网类型丨规格丨排列丨高度丨单/多区丨线径丨边铁丨海绵包边丨四周加硬丨弹叉丨底面物料
  2526. StringBuilder ls_temp_name = new StringBuilder();
  2527. ls_temp_name.Append(qdList[1].pznamemx)
  2528. .Append("丨")
  2529. .Append(qdList[3].pznamemx)
  2530. .Append("丨")
  2531. .Append(qdList[4].pznamemx);
  2532. if (!string.IsNullOrEmpty(bednet.duo_qv_str))
  2533. {
  2534. areaType = $"{bednet.duo_qv_str}区";
  2535. ls_temp_name.Append("丨")
  2536. .Append(bednet.duo_qv_str)
  2537. .Append("区");
  2538. }
  2539. else
  2540. {
  2541. areaType = string.IsNullOrEmpty(qdList[5].pznamemx) ? "多区" : "单区";
  2542. ls_temp_name.Append("丨")
  2543. .Append(string.IsNullOrEmpty(qdList[5].pznamemx) ? "多区" : "单区");
  2544. }
  2545. if (string.IsNullOrEmpty(qdList[5].pznamemx))
  2546. {
  2547. for (int i = 6; i <= 10; i++)
  2548. {
  2549. if (!string.IsNullOrEmpty(qdList[i].pznamemx))
  2550. {
  2551. ls_temp_name.Append("+" + qdList[i].pznamemx.Substring(0, Math.Min(qdList[i].pznamemx.IndexOf('/') - 1, qdList[i].pznamemx.Length)));
  2552. }
  2553. }
  2554. }
  2555. else
  2556. {
  2557. ls_temp_name.Append("丨")
  2558. .Append(qdList[5].pznamemx);
  2559. }
  2560. AppendSpecialFields(ls_temp_name,qdList);
  2561. rollPackage = bednet.if_jb == 0 ? string.Empty : "卷包";
  2562. if (ls_temp_name.ToString().Contains("袋装"))
  2563. {
  2564. ls_temp_name.Clear();
  2565. ls_temp_name.Append(bednetName)
  2566. .Append("丨")
  2567. .Append(areaType)
  2568. .Append("丨")
  2569. .Append(rollPackage)
  2570. .Append("丨")
  2571. .Append(specifications)
  2572. .Append("丨")
  2573. .Append(arrangement)
  2574. .Append("丨")
  2575. .Append(bednetHeight)
  2576. .Append("丨")
  2577. .Append(springs)
  2578. .Append("丨")
  2579. .Append(edgeIron)
  2580. .Append("丨")
  2581. .Append(bottomNonwovenFabric)
  2582. .Append("丨")
  2583. .Append(topPadMaterial)
  2584. .Append("丨")
  2585. .Append(bottomPadMaterial)
  2586. .Append("丨")
  2587. .Append(bagNonwovenFabric)
  2588. .Append("丨")
  2589. .Append(surroundingReinforcementRows)
  2590. .Append("丨")
  2591. .Append(springPins)
  2592. .Append("丨")
  2593. .Append(foamBorderMaterial)
  2594. .Append("丨")
  2595. .Append(fillingFoamMaterial);
  2596. }
  2597. qdList[0].pznamemx = ls_temp_name.ToString();
  2598. qdList[0].amt = bednet.nottax_factory_cost;
  2599. return qdList;
  2600. }
  2601. private void AppendSpecialFields(StringBuilder ls_temp_name,List<u_bednet_qingdan> qdList)
  2602. {
  2603. if (!string.IsNullOrEmpty(qdList[11].pznamemx))
  2604. {
  2605. ls_temp_name.Append("丨")
  2606. .Append(qdList[11].pznamemx == "" ? "无边铁" : "有边铁");
  2607. }
  2608. if (!string.IsNullOrEmpty(qdList[19].pznamemx))
  2609. {
  2610. ls_temp_name.Append("丨")
  2611. .Append(qdList[19].pznamemx)
  2612. .Append(qdList[19].pznamemx)
  2613. .Append("海绵包边");
  2614. }
  2615. if (!string.IsNullOrEmpty(qdList[16].pznamemx))
  2616. {
  2617. ls_temp_name.Append("丨")
  2618. .Append("四周加硬")
  2619. .Append(qdList[16].pznamemx);
  2620. }
  2621. if (!string.IsNullOrEmpty(qdList[26].pznamemx))
  2622. {
  2623. ls_temp_name.Append("丨")
  2624. .Append(qdList[26].pznamemx);
  2625. }
  2626. if (!string.IsNullOrEmpty(qdList[12].pznamemx))
  2627. {
  2628. ls_temp_name.Append("丨")
  2629. .Append("底面")
  2630. .Append(qdList[12].pznamemx);
  2631. }
  2632. else
  2633. {
  2634. if (string.IsNullOrEmpty(qdList[14].pznamemx))
  2635. {
  2636. ls_temp_name.Append("丨")
  2637. .Append("底一张")
  2638. .Append(qdList[15].pznamemx);
  2639. }
  2640. else if (string.IsNullOrEmpty(qdList[15].pznamemx))
  2641. {
  2642. ls_temp_name.Append("丨")
  2643. .Append("面一张")
  2644. .Append(qdList[14].pznamemx);
  2645. }
  2646. else
  2647. {
  2648. ls_temp_name.Append("丨")
  2649. .Append("面底各一张")
  2650. .Append(qdList[14].pznamemx);
  2651. }
  2652. }
  2653. if (!string.IsNullOrEmpty(qdList[21].pznamemx))
  2654. {
  2655. ls_temp_name.Append("丨")
  2656. .Append(qdList[21].pzname)
  2657. .Append(qdList[21].pznamemx);
  2658. }
  2659. }
  2660. public string GetSpringName(int springid)
  2661. {
  2662. //var spring = new u_spring() { springid = springid };
  2663. //DbSqlHelper.SelectOne(cmd, spring, "line_diameter,gram_weight,height,center_diameter,cyclenum,caliber");
  2664. var spring = Cache.GetData<u_spring, SpringMapping>(springid);
  2665. return spring.name;
  2666. }
  2667. public string GetSpringTypeName(int springid)
  2668. {
  2669. string sprintname = "";
  2670. cmd.CommandText = @"SELECT u_springtype.springtypename FROM u_spring INNER JOIN u_springtype ON u_springtype.springtypeid = u_spring.springtypeid WHERE u_spring.springid = @springid";
  2671. cmd.Parameters.Clear();
  2672. cmd.Parameters.AddWithValue("@springid", springid);
  2673. using(var reader = cmd.ExecuteReader())
  2674. {
  2675. if(reader.Read())
  2676. {
  2677. sprintname = Convert.ToString(reader["springtypename"]);
  2678. }
  2679. }
  2680. return sprintname;
  2681. }
  2682. public void CalCulateSpringQty(u_bednet bednet, List<u_bednetmx> mxlist, List<u_bednetmx_spring> springList)
  2683. {
  2684. // 默认方法
  2685. AddFormulaKeyValue("计算弹簧排列个数-宽", "if(【卷包】=1,round((【床垫宽】- 2)/(【中心直径】-【卷排列宽】),0),round((【床垫宽】- 2)/(【中心直径】-【排列宽】),0))");
  2686. AddFormulaKeyValue("计算弹簧排列个数-长", "if(【卷包】=1,round((【床垫长】- 2)/(【中心直径】-【卷排列长】),0),round((【床垫长】- 2)/(【中心直径】-【排列长】),0))");
  2687. InitReplaceMents(bednet);
  2688. foreach (var mx in mxlist)
  2689. {
  2690. var _springid = mx.springid;
  2691. if (mx.if_part.Value == 1 && springList.Count > 0)
  2692. {
  2693. //多区
  2694. _springid = springList[0].springid;
  2695. }
  2696. var spring = Cache.GetData<u_spring, SpringMapping>(_springid.Value);
  2697. // 处理相同公式部分
  2698. InitMxReplaceMents(bednet, mx, spring);
  2699. InitSptringRepaceMents(spring);
  2700. #region 计算 海绵包边材料成本 开始
  2701. CalSpringMtrlCol2(bednet, mx, springList, "海绵包边");
  2702. #endregion 计算 海绵包边材料成本 结束
  2703. #region 弹簧排列个数-宽
  2704. mx.spring_qty_width = Convert.ToInt32(CalculateVarFormula("计算弹簧排列个数-宽").DecimalValue);
  2705. AddKeyValue("弹簧排列个数-宽", mx.spring_qty_width);
  2706. #endregion
  2707. #region 弹簧排列个数-长
  2708. mx.spring_qty_length = Convert.ToInt32(CalculateVarFormula("计算弹簧排列个数-长").DecimalValue);
  2709. AddKeyValue("弹簧排列个数-长", mx.spring_qty_length);
  2710. #endregion
  2711. }
  2712. }
  2713. public void SaveBedNetInterface(int bednetid, List<u_bednet_interface> mxlist, List<u_bednet_interface_qd> qdlist)
  2714. {
  2715. cmd.CommandText = @"DELETE u_bednet_interface WHERE bednetid = @bednetid";
  2716. cmd.Parameters.Clear();
  2717. cmd.Parameters.AddWithValue("@bednetid", bednetid);
  2718. cmd.ExecuteNonQuery();
  2719. cmd.CommandText = @"DELETE u_bednet_interface_qd WHERE bednetid = @bednetid";
  2720. cmd.Parameters.Clear();
  2721. cmd.Parameters.AddWithValue("@bednetid", bednetid);
  2722. cmd.ExecuteNonQuery();
  2723. foreach (var mx in mxlist)
  2724. {
  2725. mx.bednetid = bednetid;
  2726. DbSqlHelper.Insert(cmd, mx, "bednetid,printid,itemname,bj_pzname,bj_namemx,actual_size,erp_pzid,bj_inputtype");
  2727. }
  2728. foreach (var mx in qdlist)
  2729. {
  2730. mx.bednetid = bednetid;
  2731. DbSqlHelper.Insert(cmd, mx, "bednetid,printid,itemname,bj_pzname,bj_pzname_mx,bj_pzname_mx_mx,mtrlid,erp_mtrlid,wrkgrpid,wrkgrpid2,useqty,dscrp,actual_useqty,qd_actual_size,qd_pfgroupqty,formulaid,wrkgrpcode1,wrkgrpcode2");
  2732. }
  2733. }
  2734. /// <summary>
  2735. /// 床网报价审核
  2736. /// </summary>
  2737. /// <param name="bednetid"></param>
  2738. /// <exception cref="LJCommonException"></exception>
  2739. public void BedNetAudit(int bednetid)
  2740. {
  2741. var power63 = UserHelper.CheckFuncPower(cmd, context.tokendata.empid, 63);
  2742. if (!power63)
  2743. {
  2744. throw new LJCommonException("你没有审核权限");
  2745. }
  2746. // 检查锁
  2747. if (LockHelper.CheckIsLock(cmd, MattressHelper.BillKeyWord, bednetid, context.tokendata.username, out string arg_msg)) throw new LJCommonException(arg_msg);
  2748. var bednet = GetBedNet(bednetid, "flag,bednetcode,version");
  2749. if (bednet.flag == 1)
  2750. {
  2751. throw new LJCommonException($"床网报价【{bednet.bednetcode}】已审核,不能审核!");
  2752. }
  2753. bednet.flag = 1;
  2754. bednet.version++;
  2755. DbSqlHelper.Update(cmd, "u_bednet", null, bednet, "bednetid", "flag,version");
  2756. }
  2757. /// <summary>
  2758. /// 床网报价撤销审核
  2759. /// </summary>
  2760. /// <param name="bednetid"></param>
  2761. /// <exception cref="LJCommonException"></exception>
  2762. public void BedNetCAudit(int bednetid)
  2763. {
  2764. var power64 = UserHelper.CheckFuncPower(cmd, context.tokendata.empid, 64);
  2765. if (!power64)
  2766. {
  2767. throw new LJCommonException("你没有审核权限");
  2768. }
  2769. // 检查锁
  2770. if (LockHelper.CheckIsLock(cmd, MattressHelper.BillKeyWord, bednetid, context.tokendata.username, out string arg_msg)) throw new LJCommonException(arg_msg);
  2771. var bednet = GetBedNet(bednetid, "flag,bednetcode,version");
  2772. if (bednet.flag == 0)
  2773. {
  2774. throw new LJCommonException($"床网报价【{bednet.bednetcode}】未审核,不能撤审!");
  2775. }
  2776. bednet.flag = 0;
  2777. bednet.version++;
  2778. DbSqlHelper.Update(cmd, "u_bednet", null, bednet, "bednetid", "flag,version");
  2779. }
  2780. #region 常量
  2781. private static string BillKeyWord = BillNames.BedNetQuote;
  2782. #endregion
  2783. }
  2784. }