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