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

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