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

161 lines
7.0 KiB

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