圣珀
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

115 lines
5.4 KiB

2 years ago
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Data;
  4. using System.Data.SqlClient;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. using ICS.WCF.Base;
  9. using ICSSoft.Entity;
  10. namespace ICS.PalletBoxGet
  11. {
  12. public class PallectGet
  13. {
  14. /// <summary>
  15. /// 获取物料条码信息生成条码
  16. /// </summary>
  17. public FormICSCreatedArrivalNoticeModel CustGetMaterialOutBox(PalletMox m)
  18. {
  19. FormICSCreatedArrivalNoticeModel result = new FormICSCreatedArrivalNoticeModel();
  20. using (SqlConnection conn = new SqlConnection(Appconfig.GetMESStr()))
  21. {
  22. conn.Open();
  23. using (SqlTransaction trans = conn.BeginTransaction())
  24. {
  25. try
  26. {
  27. StringBuilder strHead = new StringBuilder();
  28. strHead.AppendLine("***************接口传入参数记录****************:");
  29. strHead.AppendLine("外箱条码:" + m.CartonNO);
  30. strHead.AppendLine("栈板条码:" + m.PalletCode);
  31. strHead.AppendLine("传入站点:" + m.WorkPoint);
  32. strHead.AppendLine("***************接口传入参数记录****************:");
  33. Appconfig.WriteLogFile(strHead.ToString(), "物料栈板信息接口日志");
  34. StringBuilder resultlog = new StringBuilder();
  35. string SqlCartonNO = @"select * from ICSPallet where PalletCode = '" + m.PalletCode + "' ";
  36. DataTable flag1 = DBhlper.Query(SqlCartonNO, Appconfig.GetMESStr());
  37. if (flag1.Rows.Count <= 0)
  38. {
  39. string SqlLotNO = @"select * from ICSITEMLot2Carton where CartonNO = '" + m.CartonNO + "' ";
  40. DataTable flag2 = DBhlper.Query(SqlLotNO, Appconfig.GetMESStr());
  41. if (flag2.Rows.Count > 0)
  42. {
  43. string sql = string.Format(@"update ICSITEMLot2Carton set PalletNO='{0}'
  44. where WorkPoint = '{2}'and CartonNO='{1}'",
  45. m.PalletCode, m.CartonNO, m.WorkPoint);
  46. int dt = DBhlper.EXecute(sql, Appconfig.GetMESStr());
  47. if (dt == 0)
  48. {
  49. throw new Exception("栈板条码信息添加失败,请查看日志");
  50. }
  51. }
  52. else
  53. {
  54. throw new Exception("箱号不存在,信息添加失败");
  55. }
  56. string sql2 = string.Format(@"insert into ICSPallet (Serial,PalletCode,BatchCode,palletStatus,MUSER,MUSERName,MTIME,WorkPoint)
  57. Values
  58. (NEWID(),'{0}','','','{1}','{2}',GETDATE(),'{3}')"
  59. , m.PalletCode, m.MUSER, m.MUSERName, m.WorkPoint);
  60. int dt2 = DBhlper.EXecute(sql2, Appconfig.GetMESStr());
  61. if (dt2 > 0)
  62. {
  63. result.Code = 0;
  64. result.ResMsg = "物料栈板条码创建成功";
  65. result.ResData = "{}";
  66. result.IsCompress = false;
  67. result.IsSuccess = true;
  68. }
  69. }
  70. else
  71. {
  72. throw new Exception("栈板已经存在,信息添加失败");
  73. }
  74. }
  75. catch (Exception ex)
  76. {
  77. trans.Rollback();
  78. result.Code = -1;
  79. result.ResMsg = "物料栈板信息获取失败,请查看日志";
  80. result.ResData = "{}";
  81. result.IsCompress = false;
  82. result.IsSuccess = false;
  83. StringBuilder str = new StringBuilder();
  84. str.AppendLine("物料栈板信息获取失败");
  85. str.AppendLine("外箱条码:" + m.CartonNO);
  86. str.AppendLine("栈板条码:" + m.PalletCode);
  87. str.AppendLine("传入站点:" + m.WorkPoint);
  88. str.AppendLine("失败原因:" + ex.Message);
  89. Appconfig.WriteLogFile(str.ToString(), "物料栈板信息接口日志");
  90. }
  91. }
  92. conn.Close();
  93. }
  94. return result;
  95. }
  96. /// <summary>
  97. /// 返回值
  98. /// </summary>
  99. public class FormICSCreatedArrivalNoticeModel
  100. {
  101. //0 :正常数据,-1:失败。
  102. public int Code { get; set; }
  103. public string ResMsg { get; set; }
  104. public Object ResData { get; set; }
  105. public bool IsCompress { get; set; }
  106. public bool IsSuccess { get; set; }
  107. }
  108. }
  109. }