纽威
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.

153 lines
6.5 KiB

  1. using ICSSoft.Common;
  2. using ICSSoft.Entity;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Data;
  6. using System.Data.SqlClient;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Threading.Tasks;
  10. namespace ICSSoft.DataProject
  11. {
  12. public class MOIssueDocApprove
  13. {
  14. private static log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
  15. private static string connString = System.Configuration.ConfigurationManager.AppSettings["ERPConnStr"];
  16. private static string ERPDB = System.Configuration.ConfigurationManager.AppSettings["ERPDB"];
  17. private static string Type = System.Configuration.ConfigurationManager.AppSettings["Type"];
  18. /// <summary>
  19. /// 审核材料出库
  20. /// </summary>
  21. /// <param name="Bills"></param>
  22. /// <returns></returns>
  23. public bool ConfirmRd11(List<ICSMOIssueDocApprove> Bills)
  24. {
  25. bool ResultFlag = false;
  26. SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString);
  27. conn.Open();
  28. SqlTransaction sqlTran = conn.BeginTransaction();
  29. SqlCommand cmd = new SqlCommand();
  30. cmd.Transaction = sqlTran;
  31. cmd.Connection = conn;
  32. try
  33. {
  34. if (Bills.Count <= 0)
  35. {
  36. throw new Exception("传送数据为空!");
  37. }
  38. LogInfo(Bills);
  39. //MergeObject(Bills, cmd);
  40. foreach (ICSMOIssueDocApprove head in Bills)
  41. {
  42. string sql = "";
  43. ICSUserInfo userInfo = new ICSUserInfo();
  44. userInfo = DBHelper.GetPersonInfo(head.User, cmd);
  45. #region 检验单号是否存在
  46. sql = "select * from rdrecord11 where ID='" + head.ID + "'";
  47. DataTable dt = DBHelper.SQlReturnData(sql, cmd);
  48. if (dt != null && dt.Rows.Count > 0)
  49. {
  50. string cHandler = dt.Rows[0]["cHandler"].ToString();
  51. if (!string.IsNullOrEmpty(cHandler))
  52. {
  53. throw new Exception("单据ID:" + head.ID + "不是开立状态!");
  54. }
  55. }
  56. else
  57. {
  58. throw new Exception("单据ID:" + head.ID + "在U8中不存在!");
  59. }
  60. #endregion
  61. #region 审核其他入库单
  62. sql = @"UPDATE dbo.rdrecord11 SET cHandler='" + userInfo.UserName + @"' ,
  63. dVeriDate=CONVERT(VARCHAR(50),GETDATE(),112),dnverifytime=GETDATE() WHERE ID='" + head.ID + "'";
  64. DBHelper.CmdExecuteNonQuery(sql, cmd, "审核核材料出库单失败!");
  65. #endregion
  66. sql = "select * from dbo.rdrecords11 a inner join rdrecord11 b on a.ID=b.ID where a.ID='" + head.ID + "';";
  67. DataTable dtChecks = DBHelper.SQlReturnData(sql, cmd);
  68. #region 更新现存量
  69. for (int i = 0; i < dtChecks.Rows.Count; i++)
  70. {
  71. VouchKey key = new VouchKey();
  72. key.cBustypeUN = "领料";
  73. key.cVouchTypeUN = "11";
  74. key.TableName = "IA_ST_UnAccountVouch11";
  75. DBHelper.UpdateCurrentStock(cmd, dtChecks.Rows[i]["cInvCode"].ToString(), dtChecks.Rows[i]["cWhCode"].ToString(), "", Convert.ToDecimal(dtChecks.Rows[i]["iQuantity"].ToString()), key);
  76. // //回写fInQuantity
  77. // sql = @"Update CurrentStock set fInQuantity=isnull(fInQuantity,0)-" + Convert.ToDecimal(dtChecks.Rows[i]["iQuantity"].ToString()) + @"
  78. // where cInvCode='" + dtChecks.Rows[i]["cInvCode"].ToString() + "' and cWhCode='" + dtChecks.Rows[i]["cWhCode"].ToString() + "' ";
  79. //if (body.cBatch != null)
  80. //{
  81. // sql += "and cBatch='" + body.cBatch + "'";
  82. //}
  83. //else
  84. //{
  85. // sql += "and cBatch=''";
  86. //}
  87. //DBHelper.CmdExecuteNonQuery(sql, cmd, "回写fInQuantity失败!");
  88. if (head.UpdateTodoQuantity == true)
  89. {
  90. #region 判断现存量是否足够
  91. sql = @"IF EXISTS(SELECT AutoID FROM dbo.CurrentStock WHERE iQuantity<0 OR iNum<0 OR fInQuantity<0)
  92. BEGIN
  93. DECLARE @MSG NVARCHAR(100)
  94. SELECT @MSG='ERP待入库数量不足AutoID'+CAST(AutoID AS NVARCHAR(100)) FROM dbo.CurrentStock WHERE iQuantity<0 OR iNum<0 OR fInQuantity<0
  95. RAISERROR(@MSG,16,1)
  96. END";
  97. cmd.CommandText = sql;
  98. cmd.ExecuteNonQuery();
  99. #endregion
  100. }
  101. }
  102. #endregion
  103. }
  104. cmd.Transaction.Commit();
  105. ResultFlag = true;
  106. return ResultFlag;
  107. }
  108. catch (Exception ex)
  109. {
  110. cmd.Transaction.Rollback();
  111. log.Error(ex.Message);
  112. throw new Exception(ex.Message);
  113. }
  114. finally
  115. {
  116. if (conn.State == ConnectionState.Open)
  117. {
  118. conn.Close();
  119. }
  120. conn.Dispose();
  121. }
  122. }
  123. /// <summary>
  124. /// 记录日志
  125. /// </summary>
  126. /// <param name="Bills"></param>
  127. private void LogInfo(List<ICSMOIssueDocApprove> Bills)
  128. {
  129. string HeadList = string.Empty;
  130. string BodyList = string.Empty;
  131. foreach (ICSMOIssueDocApprove head in Bills)
  132. {
  133. HeadList += "\r\n 表头调拨单号:" + head.ID + ",用户:" + head.User;
  134. foreach (ICSMOIssueDocApprove body in Bills)
  135. {
  136. BodyList += "\r\n 表体主键ID: " + body.ID + "";
  137. }
  138. }
  139. log.Info(HeadList);
  140. log.Info(BodyList);
  141. }
  142. }
  143. }