SaveConfigureCodeMxExcutor.cs 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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.LJException;
  9. using JLHHJSvr.Tools;
  10. using LJLib.DAL.SQL;
  11. using LJLib.Net.SPI.Server;
  12. namespace JLHHJSvr.Excutor
  13. {
  14. internal sealed class SaveConfigureCodeMxExcutor : ExcutorBase<SaveConfigureCodeMxRequest, SaveConfigureCodeMxResponse>
  15. {
  16. protected override void ExcuteInternal(SaveConfigureCodeMxRequest request, object state, SaveConfigureCodeMxResponse rslt)
  17. {
  18. var tokendata = BllHelper.GetToken(request.token);
  19. if (tokendata == null)
  20. {
  21. rslt.ErrMsg = "会话已经中断,请重新登录";
  22. return;
  23. }
  24. if (request.configure == null)
  25. {
  26. rslt.ErrMsg = "未提交部件选配项";
  27. return;
  28. }
  29. if (string.IsNullOrEmpty(request.configure.pzcodemx))
  30. {
  31. rslt.ErrMsg = "请输入明细编号";
  32. return;
  33. }
  34. if (string.IsNullOrEmpty(request.configure.namemx))
  35. {
  36. rslt.ErrMsg = "请输入明细名称";
  37. return;
  38. }
  39. if (request.configure.pzid <= 0)
  40. {
  41. rslt.ErrMsg = "部件选配配置id错误";
  42. return;
  43. }
  44. using (var con = new SqlConnection(GlobalVar.ConnectionString))
  45. using (var cmd = con.CreateCommand())
  46. {
  47. con.Open();
  48. var dtNow = DateTime.Now;
  49. AutoInit.AutoInitS(cmd, request.configure);
  50. using (cmd.Transaction = con.BeginTransaction())
  51. {
  52. try
  53. {
  54. if (request.configure.printid <= 0)
  55. {
  56. int _printid = 0;
  57. cmd.CommandText = @"SELECT MAX(printid) AS printid FROM u_configure_codemx WHERE pzid = @pzid";
  58. cmd.Parameters.Clear();
  59. cmd.Parameters.AddWithValue("@pzid", request.configure.pzid);
  60. using (var reader = cmd.ExecuteReader())
  61. {
  62. if (reader.Read())
  63. {
  64. _printid = Convert.ToInt32(reader["printid"]);
  65. }
  66. }
  67. request.configure.printid = _printid + 1;
  68. var fields = @"pzid,printid,pzcodemx,namemx,gradestr,mtrlcode,price,ifdft,MCostRate,ProfitRate,dscrp,ifuse,ifnoch,pricerate,packqty,packvol,price_pz,grade";
  69. DbSqlHelper.Insert(cmd, "u_configure_codemx", null, request.configure, fields);
  70. }
  71. else
  72. {
  73. //修改
  74. var fields = @"pzcodemx,namemx,gradestr,mtrlcode,price,ifdft,MCostRate,ProfitRate,dscrp,ifuse,ifnoch,pricerate,packqty,packvol,price_pz,grade";
  75. DbSqlHelper.Update(cmd, "u_configure_codemx", null, request.configure, "pzid,printid", fields);
  76. }
  77. cmd.Transaction.Commit();
  78. }
  79. catch (Exception e)
  80. {
  81. cmd.Transaction.Rollback();
  82. rslt.ErrMsg = e.ToString();
  83. }
  84. }
  85. }
  86. }
  87. }
  88. }