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

159 lines
7.6 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
  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 OtherInDoc
  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 ConfirmRd08(List<ICSOtherInDoc> 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 (ICSOtherInDoc 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 RdRecord08 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.RdRecord08 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.RdRecords08 a inner join RdRecord08 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 = "08";
  80. key.TableName = "IA_ST_UnAccountVouch08";
  81. //DBHelper.UpdateCurrentStock(cmd, dtChecks.Rows[i]["cInvCode"].ToString(), dtChecks.Rows[i]["cWhCode"].ToString(), "", Convert.ToDecimal(dtChecks.Rows[i]["iQuantity"].ToString()), key);
  82. DBHelper.UpdateCurrentStockNEW(cmd, dtChecks.Rows[i]["cInvCode"].ToString(), dtChecks.Rows[i]["cWhCode"].ToString(), dtChecks.Rows[i]["cBatch"].ToString(), Convert.ToDecimal(dtChecks.Rows[i]["iQuantity"].ToString()), dtChecks.Rows[i]["cFree1"].ToString(), dtChecks.Rows[i]["cFree2"].ToString(), dtChecks.Rows[i]["cFree3"].ToString(), dtChecks.Rows[i]["cFree4"].ToString(), dtChecks.Rows[i]["cFree5"].ToString(), dtChecks.Rows[i]["cFree6"].ToString(), dtChecks.Rows[i]["cFree7"].ToString(), dtChecks.Rows[i]["cFree8"].ToString(), dtChecks.Rows[i]["cFree9"].ToString(), dtChecks.Rows[i]["cFree10"].ToString(), key);
  83. // //回写fInQuantity
  84. // sql = @"Update CurrentStock set fInQuantity=isnull(fInQuantity,0)-" + Convert.ToDecimal(dtChecks.Rows[i]["iQuantity"].ToString()) + @"
  85. // where cInvCode='" + dtChecks.Rows[i]["cInvCode"].ToString() + "' and cWhCode='" + dtChecks.Rows[i]["cWhCode"].ToString() + "' ";
  86. //if (body.cBatch != null)
  87. //{
  88. // sql += "and cBatch='" + body.cBatch + "'";
  89. //}
  90. //else
  91. //{
  92. // sql += "and cBatch=''";
  93. //}
  94. //DBHelper.CmdExecuteNonQuery(sql, cmd, "回写fInQuantity失败!");
  95. if (head.UpdateTodoQuantity == true)
  96. {
  97. #region 判断现存量是否足够
  98. sql = @"IF EXISTS(SELECT AutoID FROM dbo.CurrentStock WHERE iQuantity<0 OR iNum<0 OR fInQuantity<0)
  99. BEGIN
  100. DECLARE @MSG NVARCHAR(100)
  101. SELECT @MSG='ERP待入库数量不足AutoID'+CAST(AutoID AS NVARCHAR(100)) FROM dbo.CurrentStock WHERE iQuantity<0 OR iNum<0 OR fInQuantity<0
  102. RAISERROR(@MSG,16,1)
  103. END";
  104. cmd.CommandText = sql;
  105. cmd.ExecuteNonQuery();
  106. #endregion
  107. }
  108. }
  109. #endregion
  110. }
  111. cmd.Transaction.Commit();
  112. }
  113. catch (Exception ex)
  114. {
  115. cmd.Transaction.Rollback();
  116. log.Error(ex.Message);
  117. throw new Exception(ex.Message);
  118. }
  119. finally
  120. {
  121. if (conn.State == ConnectionState.Open)
  122. {
  123. conn.Close();
  124. }
  125. conn.Dispose();
  126. }
  127. }
  128. ResultFlag = true;
  129. return ResultFlag;
  130. }
  131. /// <summary>
  132. /// 记录日志
  133. /// </summary>
  134. /// <param name="Bills"></param>
  135. private void LogInfo(List<ICSOtherInDoc> Bills)
  136. {
  137. string HeadList = string.Empty;
  138. string BodyList = string.Empty;
  139. foreach (ICSOtherInDoc head in Bills)
  140. {
  141. HeadList += "\r\n 表头调拨单号:" + head.ID + ",用户:" + head.User + ",站点:" + head.WorkPoint;
  142. foreach (ICSOtherInDoc body in Bills)
  143. {
  144. BodyList += "\r\n 表体主键ID: " + body.ID + "";
  145. }
  146. }
  147. log.Info(HeadList);
  148. log.Info(BodyList);
  149. }
  150. }
  151. }