SaveBedNetExcutor.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Data.SqlClient;
  4. using System.Linq;
  5. using System.Text;
  6. using JLHHJSvr.BLL;
  7. using JLHHJSvr.Com;
  8. using JLHHJSvr.Com.Model;
  9. using JLHHJSvr.LJException;
  10. using JLHHJSvr.Tools;
  11. using LJLib.DAL.SQL;
  12. using LJLib.Net.SPI.Server;
  13. namespace JLHHJSvr.Excutor
  14. {
  15. internal sealed class SaveBedNetExcutor : ExcutorBase<SaveBedNetRequest, SaveBedNetResponse>
  16. {
  17. protected override void ExcuteInternal(SaveBedNetRequest request, object state, SaveBedNetResponse rslt)
  18. {
  19. var tokendata = BllHelper.GetToken(request.token);
  20. if (tokendata == null)
  21. {
  22. rslt.ErrMsg = "会话已经中断,请重新登录";
  23. return;
  24. }
  25. if (request.bednet == null)
  26. {
  27. rslt.ErrMsg = "缺少主表信息";
  28. return;
  29. }
  30. if(request.bednet.bednettypeid <= 0)
  31. {
  32. rslt.ErrMsg = "请选择床网类型";
  33. return;
  34. }
  35. if (request.bednetMx == null || !request.bednetMx.Any())
  36. {
  37. rslt.ErrMsg = "缺少报价明细";
  38. return;
  39. }
  40. // 检查是否填写床网高度
  41. foreach(var mx in request.bednetMx)
  42. {
  43. if(mx.bednet_height == null || mx.bednet_height <= 0)
  44. {
  45. rslt.ErrMsg = "请填写床网高";
  46. return;
  47. } else
  48. {
  49. request.bednet.mattress_height = mx.bednet_height;
  50. }
  51. }
  52. using (var con = new SqlConnection(GlobalVar.ConnectionString))
  53. using (var cmd = con.CreateCommand())
  54. {
  55. con.Open();
  56. // 初始化属性
  57. AutoInit.AutoInitS(cmd, request.bednet);
  58. using (cmd.Transaction = con.BeginTransaction())
  59. {
  60. try
  61. {
  62. var dtNow = DateTime.Now;
  63. var fields = @"deptid,bednettypeid,mattress_width,mattress_length,mattress_height,if_doublenet,if_doublespring,snake_wire_diameter,
  64. snake_wire_mtrl_formula,snake_wire_mtrl_cost,pocket_around_spring_formula,pocket_around_spring_cost,
  65. pocket_around_fabrics_formula,pocket_around_fabrics_cost,hard_around_mtrl_formula,hard_around_mtrl_cost,
  66. hard_around_hr_formula,hard_around_hr_cost,spring_mtrl_cost,spring_hr_cost,glue_price,glue_mtrl_formula,
  67. glue_mtrl_cost,fabrics1_mtrl_formula,fabrics1_mtrl_cost,fabrics2_mtrl_formula,fabrics2_mtrl_cost,
  68. if_side_iron,side_iron_lossrate,side_iron_price,side_iron_mtrl_formula,side_iron_mtrl_cost,side_iron_hr_formula,
  69. side_iron_hr_cost,cnail_price,cnail_mtrl_formula,cnail_mtrl_cost,cnail_hr_formula,cnail_hr_cost,sponge_mtrlid,
  70. sponge_thickness,sponge_price,sponge_mtrl_formula,sponge_mtrl_cost,sponge_hr_formula,sponge_hr_cost,edge_mtrlid,
  71. edge_price,edge_mtrl_formula,edge_mtrl_cost,edge_hr_formula,edge_hr_cost,fork_qty,fork_price,fork_mtrl_formula,
  72. fork_mtrl_cost,fork_hr_formula,fork_hr_cost,if_rsORwa,rsORwa_price,rsORwa_mtrl_formula,rsORwa_mtrl_cost,rsORwa_hr_formula,
  73. rsORwa_hr_cost,if_sponge_drilling,sponge_drilling_hr_formula,sponge_drilling_hr_cost,total_hr_cost,total_mtrl_cost,
  74. total_fees_cost,total_cost,createtime,createby,bednetname,spring_mtrl_formula,spring_hr_formula,
  75. sponge_mtrl_cost_replace_formula,sponge_hr_cost_replace_formula,edge_mtrl_cost_replace_formula,edge_hr_cost_replace_formula,
  76. fork_mtrl_cost_replace_formula,fork_hr_cost_replace_formula,rsORwa_mtrl_cost_replace_formula,rsORwa_hr_cost_replace_formula,
  77. sponge_drilling_hr_cost_replace_formula,snake_wire_mtrl_cost_replace_formula,taxrate,taxes,commissionrate,commission,fob,
  78. profitrate,nottax_factory_cost,nottax_dept_cost,dept_cost,foreign_cost,extras_cost,dept_profitrate,moneyrate,temp_flag,
  79. felt_mtrlid,felt_qty,felt_price,felt_dscrp,felt_mtrl_formula,felt_mtrl_cost,felt_hr_formula,felt_hr_cost,
  80. felt_mtrl_cost_replace_formula,felt_hr_cost_replace_formula,extras_cost_dscrp,iffork,ifsaleout,autotype,
  81. felt_mtrl_x_cost,felt_hr_x_cost,felt_x_qty,felt_mtrl_x_cost_replace_formula,felt_hr_x_cost_replace_formula,
  82. felt_x_mtrlid,sale_point,packtype,packqty,other_rate,transport_type,packmtrl,packet_mtrl_formula,
  83. packet_hr_formula,packet_mtrl_cost,packet_hr_cost,packet_mtrl_cost_replace_formula,packet_hr_cost_replace_formula,
  84. sponge_height,edge_height,sponge_tc_thickness,sponge_tc_height,sponge_tc_mtrlid,sponge_mtrl_tc_formula,
  85. sponge_mtrl_tc_cost,sponge_mtrl_tc_cost_replace_formula,duo_qv_str,spring_weight_formula,side_iron_weight_formula,
  86. hard_around_weight_formula,fabrics1_weight_formula,fabrics2_weight_formula,felt_weight_formula,cnail_weight_formula,
  87. sponge_weight_formula,sponge_weight_tc_formula,edge_weight_formula,fork_weight_formula,spring_weight_replace_formula,
  88. side_iron_weight_replace_formula,hard_around_weight_replace_formula,fabrics1_weight_replace_formula,
  89. fabrics2_weight_replace_formula,felt_weight_replace_formula,cnail_weight_replace_formula,sponge_weight_replace_formula,
  90. sponge_weight_tc_replace_formula,edge_weight_replace_formula,fork_weight_replace_formula,spring_weight_qty,
  91. side_iron_weight_qty,hard_around_weight_qty,fabrics1_weight_qty,fabrics2_weight_qty,felt_weight_qty,cnail_weight_qty,
  92. sponge_weight_qty,sponge_weight_tc_qty,edge_weight_qty,fork_weight_qty,sum_weight,if_jb";
  93. var fieldsMx = @"bednetmxid,bednetid,spring_qty_width,spring_qty_length,bednet_height,wire_mtrlid,springid,if_part,if_15strip,
  94. if_pocket_around,pocket_around_springid,pocket_around_row,pocket_around_wire_price,pocket_around_spring_cost,
  95. pocket_around_fabrics_cost,if_hard_around,hard_around_springid,hard_around_row,hard_around_wire_price,
  96. hard_around_mtrl_cost,hard_around_hr_cost,fabrics1_mtrlid,fabrics1_price,fabrics1_mtrl_cost,fabrics2_mtrlid,
  97. fabrics2_price,fabrics2_mtrl_cost,if_side_iron,side_iron_qty,side_iron_mtrl_cost,side_iron_hr_cost,
  98. pocket_around_spring_cost_replace_formula,pocket_around_fabrics_cost_replace_formula,hard_around_mtrl_cost_replace_formula,
  99. hard_around_hr_cost_replace_formula,fabrics1_mtrl_cost_replace_formula,fabrics2_mtrl_cost_replace_formula,
  100. side_iron_mtrl_cost_replace_formula,side_iron_hr_cost_replace_formula,cnail_mtrl_cost_replace_formula,cnail_mtrl_cost,
  101. cnail_hr_cost_replace_formula,cnail_hr_cost,glue_mtrl_cost_replace_formula,glue_mtrl_cost,spring_mtrl_cost,spring_hr_cost,
  102. spring_mtrl_cost_replace_formula,spring_hr_cost_replace_formula,spring_weight_replace_formula";
  103. var fieldsMx_spring = @"bednetmx_partid,bednetmxid,springid,spring_qty_width,spring_qty_length,fabrics1_mtrl_cost,spring_mtrl_cost,
  104. spring_hr_cost,spring_mtrl_cost_replace_formula,spring_hr_cost_replace_formula,spring_weight_replace_formula";
  105. if (request.bednet.bednetid <= 0)
  106. {
  107. //新建
  108. fields += ",bednetid,bednetcode";
  109. request.bednet.bednetid = BllHelper.GetID(cmd, "u_bednet");
  110. request.bednet.createtime = dtNow;
  111. request.bednet.createby = tokendata.username;
  112. var nettype = new u_bednet_type() { bednettypeid = request.bednet.bednettypeid };
  113. DbSqlHelper.SelectOne(cmd, nettype, "typecode");
  114. // 编号-年月日+流水
  115. request.bednet.bednetcode = $"{nettype.typecode}-{dtNow.ToString("yyyyMMdd")}{(request.bednet.bednetid.Value % 10000).ToString("D4")}";
  116. DbSqlHelper.Insert(cmd, "u_bednet", null, request.bednet, fields);
  117. }
  118. else
  119. {
  120. //修改
  121. foreach (var mx in request.bednetMx)
  122. {
  123. cmd.CommandText = @"DELETE FROM u_bednetmx_spring WHERE bednetmxid = @bednetmxid";
  124. cmd.Parameters.Clear();
  125. cmd.Parameters.AddWithValue("@bednetmxid", mx.bednetmxid);
  126. cmd.ExecuteNonQuery();
  127. }
  128. cmd.CommandText = @"DELETE FROM u_bednetmx WHERE bednetid = @bednetid";
  129. cmd.Parameters.Clear();
  130. cmd.Parameters.AddWithValue("@bednetid", request.bednet.bednetid);
  131. cmd.ExecuteNonQuery();
  132. DbSqlHelper.Update(cmd, "u_bednet", null, request.bednet, "bednetid", fields);
  133. }
  134. foreach (var mx in request.bednetMx)
  135. {
  136. AutoInit.AutoInitS(cmd, mx);
  137. mx.bednetid = request.bednet.bednetid;
  138. mx.bednetmxid = BllHelper.GetID(cmd, "u_bednetmx");
  139. DbSqlHelper.Insert(cmd, "u_bednetmx", null, mx, fieldsMx);
  140. if(request.spring != null && request.spring.Any())
  141. {
  142. foreach(var spring in request.spring)
  143. {
  144. AutoInit.AutoInitS(cmd, spring);
  145. spring.bednetmx_partid = request.bednet.bednetid;
  146. spring.bednetmxid = BllHelper.GetID(cmd, "u_bednetmx_spring");
  147. DbSqlHelper.Insert(cmd, "u_bednetmx_spring", null, spring, fieldsMx_spring);
  148. }
  149. }
  150. }
  151. var hisprice = new u_his_price
  152. {
  153. bednetid_mattressid = request.bednet.bednetid,
  154. typeid = 0,
  155. cmpdate = dtNow,
  156. cmpemp = tokendata.username,
  157. nottax_dept_cost = 0,
  158. dept_cost = 0,
  159. foreign_cost = 0
  160. };
  161. var fieldsHs = "bednetid_mattressid, typeid, cmpdate, cmpemp, nottax_dept_cost, dept_cost, foreign_cost";
  162. DbSqlHelper.Insert(cmd, "u_his_price", null, hisprice, fieldsHs);
  163. cmd.Transaction.Commit();
  164. rslt.bednet = new u_bednet() { bednetid = request.bednet.bednetid, bednetcode = request.bednet.bednetcode };
  165. }
  166. catch (Exception e)
  167. {
  168. cmd.Transaction.Rollback();
  169. rslt.ErrMsg = e.ToString();
  170. }
  171. }
  172. }
  173. }
  174. }
  175. }