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

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