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

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