爱思开
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.

199 lines
12 KiB

2 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. using Newtonsoft.Json;
  11. namespace ICSSoft.DataProject
  12. {
  13. public class OtherInDoc
  14. {
  15. private static log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
  16. private static string connString = System.Configuration.ConfigurationManager.AppSettings["ERPConnStr"];
  17. private static string ERPDB = System.Configuration.ConfigurationManager.AppSettings["ERPDB"];
  18. private static string Type = System.Configuration.ConfigurationManager.AppSettings["Type"];
  19. /// <summary>
  20. /// 审核其他入库单
  21. /// </summary>
  22. /// <param name="Bills"></param>
  23. /// <returns></returns>
  24. public bool ConfirmRd08(List<ICSOtherInDoc> Bills)
  25. {
  26. bool ResultFlag = false;
  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. List<string> result = Bills.Select(t => t.WorkPoint).Distinct().ToList();
  36. foreach (string WorkPoint in result)
  37. {
  38. try
  39. {
  40. connS = string.Format(connString, WorkPoint);
  41. conn = new System.Data.SqlClient.SqlConnection(connS);
  42. conn.Open();
  43. SqlTransaction sqlTran = conn.BeginTransaction();
  44. cmd = new SqlCommand();
  45. cmd.Transaction = sqlTran;
  46. cmd.Connection = conn;
  47. foreach (ICSOtherInDoc head in Bills)
  48. {
  49. if (WorkPoint != head.WorkPoint)
  50. continue;
  51. if (!DBHelper.IsInventoryConsolidation(cmd, head.WorkPoint))
  52. throw new Exception("U8正在整理现存量,请稍后再试");
  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. #region 更新现存量
  80. for (int i = 0; i < dtChecks.Rows.Count; i++)
  81. {
  82. sql = @" select * from CurrentStock where cWhCode='" + dtChecks.Rows[i]["cWhCode"].ToString() + @"' and cInvCode='" + dtChecks.Rows[i]["cInvCode"].ToString() + @"' and cBatch='" + dtChecks.Rows[i]["cBatch"].ToString() + @"'
  83. and cVMIVenCode='' 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() + @"'
  84. 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() + @"' ";
  85. DataTable curr = DBHelper.SQlReturnData(sql, cmd);
  86. string JsonData = JsonConvert.SerializeObject(curr);
  87. log.Info(JsonData);
  88. VouchKey key = new VouchKey();
  89. key.cBustypeUN = "其他入库";
  90. key.cVouchTypeUN = "08";
  91. key.TableName = "IA_ST_UnAccountVouch08";
  92. //DBHelper.UpdateCurrentStock(cmd, dtChecks.Rows[i]["cInvCode"].ToString(), dtChecks.Rows[i]["cWhCode"].ToString(), "", Convert.ToDecimal(dtChecks.Rows[i]["iQuantity"].ToString()), key);
  93. //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);
  94. string inum = dtChecks.Rows[i]["iNum"].ToString();
  95. if (inum=="")
  96. {
  97. inum = "0";
  98. }
  99. 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(),
  100. 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(),
  101. "", key, "", "", "", "", 0, 0, head.UpdateTodoQuantity ? (-1 * Convert.ToDecimal(dtChecks.Rows[i]["iQuantity"].ToString())) : 0, head.UpdateTodoQuantity ? (-1 * Convert.ToDecimal(inum)) : 0, 0, 0, 0, 0,
  102. Convert.ToInt32(dtChecks.Rows[i]["ID"].ToString()), Convert.ToInt32(dtChecks.Rows[i]["AutoID"].ToString()));
  103. sql = @" select * from CurrentStock where cWhCode='" + dtChecks.Rows[i]["cWhCode"].ToString() + @"' and cInvCode='" + dtChecks.Rows[i]["cInvCode"].ToString() + @"' and cBatch='" + dtChecks.Rows[i]["cBatch"].ToString() + @"'
  104. and cVMIVenCode='' 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() + @"'
  105. 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() + @"' ";
  106. curr = DBHelper.SQlReturnData(sql, cmd);
  107. JsonData = JsonConvert.SerializeObject(curr);
  108. log.Info(JsonData);
  109. // //回写fInQuantity
  110. // sql = @"Update CurrentStock set fInQuantity=isnull(fInQuantity,0)-" + Convert.ToDecimal(dtChecks.Rows[i]["iQuantity"].ToString()) + @"
  111. // where cInvCode='" + dtChecks.Rows[i]["cInvCode"].ToString() + "' and cWhCode='" + dtChecks.Rows[i]["cWhCode"].ToString() + "' ";
  112. //if (body.cBatch != null)
  113. //{
  114. // sql += "and cBatch='" + body.cBatch + "'";
  115. //}
  116. //else
  117. //{
  118. // sql += "and cBatch=''";
  119. //}
  120. //DBHelper.CmdExecuteNonQuery(sql, cmd, "回写fInQuantity失败!");
  121. // if (head.UpdateTodoQuantity == true)
  122. // {
  123. // #region 判断现存量是否足够
  124. // sql = @"IF EXISTS(SELECT AutoID FROM dbo.CurrentStock WHERE iQuantity<0 OR iNum<0 OR fInQuantity<0)
  125. //BEGIN
  126. // DECLARE @MSG NVARCHAR(100)
  127. // SELECT @MSG='ERP待入库数量不足!AutoID:'+CAST(AutoID AS NVARCHAR(100)) FROM dbo.CurrentStock WHERE iQuantity<0 OR iNum<0 OR fInQuantity<0
  128. // RAISERROR(@MSG,16,1)
  129. //END";
  130. // cmd.CommandText = sql;
  131. // cmd.ExecuteNonQuery();
  132. // #endregion
  133. // }
  134. }
  135. #endregion
  136. cmd.CommandType = CommandType.Text;
  137. cmd.Parameters.Clear();
  138. }
  139. cmd.Transaction.Commit();
  140. }
  141. catch (Exception ex)
  142. {
  143. if (cmd.Transaction != null)
  144. cmd.Transaction.Rollback();
  145. log.Error(ex.Message);
  146. throw new Exception(ex.Message);
  147. }
  148. finally
  149. {
  150. if (conn.State == ConnectionState.Open)
  151. {
  152. conn.Close();
  153. }
  154. conn.Dispose();
  155. }
  156. }
  157. ResultFlag = true;
  158. return ResultFlag;
  159. }
  160. /// <summary>
  161. /// 记录日志
  162. /// </summary>
  163. /// <param name="Bills"></param>
  164. private void LogInfo(List<ICSOtherInDoc> Bills)
  165. {
  166. string HeadList = string.Empty;
  167. string BodyList = string.Empty;
  168. foreach (ICSOtherInDoc head in Bills)
  169. {
  170. HeadList += "\r\n 表头调拨单号:" + head.ID + ",用户:" + head.User + ",站点:" + head.WorkPoint;
  171. foreach (ICSOtherInDoc body in Bills)
  172. {
  173. BodyList += "\r\n 表体主键ID: " + body.ID + "";
  174. }
  175. }
  176. log.Info(HeadList);
  177. log.Info(BodyList);
  178. }
  179. }
  180. }