纽威
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
9.5 KiB

3 years ago
3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
2 years ago
2 years ago
3 years ago
2 years ago
3 years ago
2 years ago
3 years ago
2 years ago
3 years ago
2 years ago
3 years ago
2 years ago
3 years ago
2 years ago
3 years ago
2 years ago
2 years ago
2 years ago
2 years ago
3 years ago
2 years ago
2 years ago
3 years ago
2 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. List<string> result = Bills.Select(t => t.WorkPoint).Distinct().ToList();
  35. foreach (string WorkPoint in result)
  36. {
  37. try
  38. {
  39. connS = string.Format(connString, 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. foreach (ICSOtherInDoc head in Bills)
  47. {
  48. if (WorkPoint != head.WorkPoint)
  49. continue;
  50. if (!DBHelper.IsInventoryConsolidation(cmd, head.WorkPoint))
  51. throw new Exception("U8正在整理现存量,请稍后再试");
  52. string sql = "";
  53. ICSUserInfo userInfo = new ICSUserInfo();
  54. userInfo = DBHelper.GetPersonInfo(head.User, cmd);
  55. #region 检验单号是否存在
  56. sql = "select * from RdRecord08 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.RdRecord08 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.RdRecords08 a inner join RdRecord08 b on a.ID=b.ID where a.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. VouchKey key = new VouchKey();
  84. key.cBustypeUN = "其他入库";
  85. key.cVouchTypeUN = "08";
  86. key.TableName = "IA_ST_UnAccountVouch08";
  87. //DBHelper.UpdateCurrentStock(cmd, dtChecks.Rows[i]["cInvCode"].ToString(), dtChecks.Rows[i]["cWhCode"].ToString(), "", Convert.ToDecimal(dtChecks.Rows[i]["iQuantity"].ToString()), key);
  88. //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);
  89. string inum = dtChecks.Rows[i]["iNum"].ToString();
  90. if (inum=="")
  91. {
  92. inum = "0";
  93. }
  94. DBHelper.UpdateCurrentStockCCGC(cmd, dtChecks.Rows[i]["cInvCode"].ToString(), dtChecks.Rows[i]["cWhCode"].ToString(), dtChecks.Rows[i]["cBatch"].ToString(), Convert.ToDecimal(dtChecks.Rows[i]["iQuantity"].ToString()), Convert.ToDecimal(inum), dtChecks.Rows[i]["cFree1"].ToString(),
  95. 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(),
  96. "", key, "", "", "", "", 0, 0, 0, 0, 0, 0, 0, 0,
  97. Convert.ToInt32(dtChecks.Rows[i]["ID"].ToString()), Convert.ToInt32(dtChecks.Rows[i]["AutoID"].ToString()));
  98. // //回写fInQuantity
  99. // sql = @"Update CurrentStock set fInQuantity=isnull(fInQuantity,0)-" + Convert.ToDecimal(dtChecks.Rows[i]["iQuantity"].ToString()) + @"
  100. // where cInvCode='" + dtChecks.Rows[i]["cInvCode"].ToString() + "' and cWhCode='" + dtChecks.Rows[i]["cWhCode"].ToString() + "' ";
  101. //if (body.cBatch != null)
  102. //{
  103. // sql += "and cBatch='" + body.cBatch + "'";
  104. //}
  105. //else
  106. //{
  107. // sql += "and cBatch=''";
  108. //}
  109. //DBHelper.CmdExecuteNonQuery(sql, cmd, "回写fInQuantity失败!");
  110. if (head.UpdateTodoQuantity == true)
  111. {
  112. #region 判断现存量是否足够
  113. sql = @"IF EXISTS(SELECT AutoID FROM dbo.CurrentStock WHERE iQuantity<0 OR iNum<0 OR fInQuantity<0)
  114. BEGIN
  115. DECLARE @MSG NVARCHAR(100)
  116. SELECT @MSG='ERP待入库数量不足AutoID'+CAST(AutoID AS NVARCHAR(100)) FROM dbo.CurrentStock WHERE iQuantity<0 OR iNum<0 OR fInQuantity<0
  117. RAISERROR(@MSG,16,1)
  118. END";
  119. cmd.CommandText = sql;
  120. cmd.ExecuteNonQuery();
  121. #endregion
  122. }
  123. }
  124. #endregion
  125. }
  126. }
  127. cmd.Transaction.Commit();
  128. }
  129. catch (Exception ex)
  130. {
  131. if (cmd.Transaction != null)
  132. cmd.Transaction.Rollback();
  133. log.Error(ex.Message);
  134. throw new Exception(ex.Message);
  135. }
  136. finally
  137. {
  138. if (conn.State == ConnectionState.Open)
  139. {
  140. conn.Close();
  141. }
  142. conn.Dispose();
  143. }
  144. }
  145. ResultFlag = true;
  146. return ResultFlag;
  147. }
  148. /// <summary>
  149. /// 记录日志
  150. /// </summary>
  151. /// <param name="Bills"></param>
  152. private void LogInfo(List<ICSOtherInDoc> Bills)
  153. {
  154. string HeadList = string.Empty;
  155. string BodyList = string.Empty;
  156. foreach (ICSOtherInDoc head in Bills)
  157. {
  158. HeadList += "\r\n 表头调拨单号:" + head.ID + ",用户:" + head.User + ",站点:" + head.WorkPoint;
  159. foreach (ICSOtherInDoc body in Bills)
  160. {
  161. BodyList += "\r\n 表体主键ID: " + body.ID + "";
  162. }
  163. }
  164. log.Info(HeadList);
  165. log.Info(BodyList);
  166. }
  167. }
  168. }