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

574 lines
30 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
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
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
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
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 Newtonsoft.Json;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Data;
  7. using System.Data.SqlClient;
  8. using System.Linq;
  9. using System.Text;
  10. using System.Threading.Tasks;
  11. namespace ICSSoft.DataProject
  12. {
  13. /// <summary>
  14. /// 成品入库单
  15. /// </summary>
  16. public class ManufactureReceiveDoc
  17. {
  18. private static log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
  19. private static string connString = System.Configuration.ConfigurationManager.AppSettings["ERPConnStr"];
  20. private static string ERPDB = System.Configuration.ConfigurationManager.AppSettings["ERPDB"];
  21. private static string Type = System.Configuration.ConfigurationManager.AppSettings["Type"];
  22. /// <summary>
  23. /// 获取成品入库单
  24. /// </summary>
  25. /// <param name="infos"></param>
  26. /// <returns></returns>
  27. public string Get(List<ICSManufactureReceiveDoc> infos)
  28. {
  29. List<ICSManufactureReceiveDoc> szJson = new List<ICSManufactureReceiveDoc>();
  30. DataTable dt = null;
  31. DataTable dtNew = null;
  32. string connS = "";
  33. string json = "";
  34. if (infos.Count <= 0)
  35. {
  36. throw new Exception("传送数据为空!");
  37. }
  38. string res = string.Empty;
  39. SqlConnection conn = new SqlConnection();
  40. SqlCommand cmd = new SqlCommand();
  41. string sql = string.Empty;
  42. foreach (ICSManufactureReceiveDoc info in infos)
  43. {
  44. try
  45. {
  46. connS = string.Format(connString, info.WorkPoint);
  47. conn = new System.Data.SqlClient.SqlConnection(connS);
  48. conn.Open();
  49. SqlTransaction sqlTran = conn.BeginTransaction();
  50. cmd = new SqlCommand();
  51. cmd.Transaction = sqlTran;
  52. cmd.Connection = conn;
  53. if (info.MTime < new DateTime(2000, 01, 01))
  54. throw new Exception("请输入正确的操作时间:" + info.MTime);
  55. sql = @" select a.ID,a.cCode,a.cDepCode,c.cDepName,a.cWhCode,d.cWhName,a.cMPoCode ,a.cMaker ,a.dnmaketime ,a.cHandler ,a.dnverifytime ,
  56. b.AutoID,b.iRSRowNO ,b.cInvCode ,b.iQuantity ,b.iNum ,b.iMPoIds from rdrecord10 a
  57. left join rdrecords10 b on a.ID=b.ID
  58. left join Department c on a.cDepCode=c.cDepCode
  59. left join Warehouse d on a.cWhCode=d.cWhCode WHERE 1=1";
  60. if (!string.IsNullOrWhiteSpace(info.MRCVCode))
  61. {
  62. sql += " and a.cCode='{0}'";
  63. }
  64. if (!string.IsNullOrWhiteSpace(info.MTime.ToString()))
  65. {
  66. sql += " and ISNULL(a.dnmodifytime,ISNULL(a.dnverifytime, ISNULL(a.dnmodifytime, a.dnmaketime)))>='{1}'";
  67. }
  68. if (!string.IsNullOrWhiteSpace(info.User))
  69. {
  70. sql += "and a.CMAKER='{2}'";
  71. }
  72. sql = string.Format(sql, info.MRCVCode, info.MTime, info.User);
  73. dt = DBHelper.SQlReturnData(sql, cmd);
  74. if (dt.Rows.Count <= 0 || dt == null)
  75. throw new Exception("成品入库单:" + info.MRCVCode + ",无信息!");
  76. dtNew.Merge(dt);
  77. cmd.Transaction.Commit();
  78. }
  79. catch (Exception ex)
  80. {
  81. cmd.Transaction.Rollback();
  82. log.Error(ex.Message);
  83. throw new Exception(ex.Message);
  84. }
  85. finally
  86. {
  87. if (conn.State == ConnectionState.Open)
  88. {
  89. conn.Close();
  90. }
  91. conn.Dispose();
  92. }
  93. }
  94. json = JsonConvert.SerializeObject(dtNew);
  95. return json;
  96. }
  97. /// <summary>
  98. /// 创建成品入库单
  99. /// </summary>
  100. /// <param name="Bills"></param>
  101. /// <returns></returns>
  102. public string CreateManufactureReceiveDoc(List<ICSManufactureReceiveDoc> Bills)
  103. {
  104. string msg = "";
  105. DataTable dtNew1 = null;
  106. DataTable dtNew2 = null;
  107. string connS = "";
  108. int num = 0;
  109. string sql = string.Empty;
  110. //取得out库单的默认显示模版
  111. //取得采购入库单单据 表头ID,表体DID
  112. VouchKey key = new VouchKey();
  113. SqlConnection conn = new SqlConnection();
  114. SqlCommand cmd = new SqlCommand();
  115. if (Bills.Count <= 0)
  116. {
  117. throw new Exception("传送数据为空!");
  118. }
  119. LogInfo(Bills);
  120. //MergeObject(Bills, cmd);
  121. //string ERPName = U8Helper.GetERPName();
  122. foreach (ICSManufactureReceiveDoc head in Bills)
  123. {
  124. try
  125. {
  126. string iFatherIdTwo = "";
  127. connS = string.Format(connString, head.WorkPoint);
  128. conn = new System.Data.SqlClient.SqlConnection(connS);
  129. conn.Open();
  130. SqlTransaction sqlTran = conn.BeginTransaction();
  131. cmd = new SqlCommand();
  132. cmd.Transaction = sqlTran;
  133. cmd.Connection = conn;
  134. string[] ss = head.WorkPoint.Split('_');
  135. ERPDB = ss[1];
  136. num = head.details.Count();
  137. Dictionary<string, int> dic = DBHelper.GetAllCode("" + ERPDB + "", "ReceiveDoc", "" + num + "");
  138. int iFatherId = Convert.ToInt32(dic["iFatherId"].ToString());
  139. int iChildId = Convert.ToInt32(dic["iChildId"].ToString());
  140. DateTime date = DateTime.Now;
  141. string DEF_ID = DBHelper.GetDefaultTemplate("0411", cmd);
  142. string cRDcode = DBHelper.GetRDCode("生产入库", cmd);
  143. string iBaseCodeLen = DBHelper.GetAllRDCode("0411", "" + date + "", "admin");
  144. //Person personEntity = new Person();
  145. //personEntity = U8Helper.GetDepCodeByUserCode(head.UserCode, cmd);
  146. DateTime dvDate = DateTime.Now.Date;
  147. #region 产成品入库单表头
  148. sql = @"INSERT INTO dbo.rdrecord10
  149. ( ID ,bRdFlag ,cVouchType ,cBusType ,cSource ,cWhCode ,dDate ,
  150. cCode ,cRdCode ,cDepCode ,cHandler ,bTransFlag ,cMaker ,
  151. cDefine1 ,cDefine2 ,cDefine3 ,cDefine4 ,cDefine5 ,cDefine6 ,
  152. cDefine7 ,cDefine8 ,cDefine9 ,cDefine10 ,dVeriDate ,bpufirst ,
  153. biafirst ,VT_ID ,bIsSTQc ,cDefine11 ,cDefine12 ,cDefine13 ,
  154. cDefine14 ,cDefine15 ,cDefine16 ,cMPoCode ,iproorderid ,
  155. bFromPreYear ,bIsComplement ,iDiscountTaxType ,ireturncount ,
  156. iverifystate ,iswfcontrolled ,cModifyPerson ,dnmaketime ,
  157. dnverifytime ,bredvouch ,iPrintCount )
  158. SELECT @ID,1,'10','','',@cWhCode,convert(datetime,convert(varchar(10),getdate(),120)),
  159. @cCode,@RdCode,@DepCode,@cHandler,0,@cMaker,
  160. a.Define1,a.Define2,a.Define3,a.Define4,a.Define5,a.Define6,
  161. a.Define7,a.Define8,a.Define9,a.Define10,@dDate,0,
  162. 0,@VT_ID,0,a.Define11,a.Define12,a.Define13,
  163. a.Define14,a.Define15,a.Define16,a.MoCode,a.MoId,
  164. 0,0,0,0,
  165. 0,0,'',@dDate,
  166. @dDate,0,0
  167. FROM dbo.mom_order a
  168. WHERE a.MoCode='" + head.MOCode + "'";
  169. cmd.Parameters.Clear();
  170. cmd.Parameters.Add(new SqlParameter("@ID", iFatherId));
  171. cmd.Parameters.Add(new SqlParameter("@cWhCode", head.WHCode));
  172. cmd.Parameters.Add(new SqlParameter("@cCode", iBaseCodeLen));
  173. cmd.Parameters.Add(new SqlParameter("@cDepCode", head.DepCode));
  174. cmd.Parameters.Add(new SqlParameter("@cHandler", head.User));
  175. cmd.Parameters.Add(new SqlParameter("@cMaker", head.User));
  176. cmd.Parameters.Add(new SqlParameter("@VT_ID", DEF_ID));
  177. cmd.Parameters.Add(new SqlParameter("@DepCode", head.DepCode));
  178. cmd.Parameters.Add(new SqlParameter("@dDate", dvDate));
  179. cmd.Parameters.Add(new SqlParameter("@RdCode", cRDcode));
  180. cmd.CommandText = sql;
  181. try
  182. {
  183. int count = cmd.ExecuteNonQuery();
  184. if (count <= 0)
  185. {
  186. log.Error("生成成品入库单表头失败,受影响行数<=0;");
  187. throw new Exception("生成成品入库单表头失败,受影响行数<=0;");
  188. }
  189. }
  190. catch (Exception ex)
  191. {
  192. log.Error("生成成品入库单表头失败!SQL:\r\n" + sql, ex);
  193. throw new Exception("生成成品入库单表头失败!SQL:\r\n" + sql, ex);
  194. }
  195. #endregion
  196. #region 产成品入库单表体
  197. foreach (ICSManufactureReceiveDocs body in head.details)
  198. {
  199. #region 判断工单行是否关闭,关闭不能入库
  200. sql = @"SELECT ISNULL(a.CloseUser,'') as CloseUser,b.MoCode,a.SortSeq FROM dbo.mom_orderdetail a INNER JOIN
  201. dbo.mom_order b ON b.MoId = a.MoId WHERE a.MoDId = '" + body.MODetailID + "'";
  202. DataTable dtCheck = DBHelper.SQlReturnData(sql, cmd);
  203. if (dtCheck != null && dtCheck.Rows.Count > 0)
  204. {
  205. if (!string.IsNullOrEmpty(dtCheck.Rows[0]["CloseUser"].ToString()))
  206. {
  207. throw new Exception("工单号:" + dtCheck.Rows[0]["MoCode"].ToString() + ",行号:" + dtCheck.Rows[0]["SortSeq"].ToString() + ",已关闭,无法入库!");
  208. }
  209. }
  210. #endregion
  211. #region 生成产成品入库单表体
  212. //if (head.IsReturn == "1")
  213. //{
  214. // body.iQuantity = -body.iQuantity;
  215. //}
  216. sql = @"INSERT INTO dbo.rdrecords10
  217. ( AutoID ,ID ,cInvCode ,iQuantity ,cBatch ,iFlag ,
  218. cDefine22 ,cDefine23 ,cDefine24 ,cDefine25 ,cDefine26 ,cDefine27 ,
  219. cItemCode ,cName ,iNQuantity ,cDefine28 ,
  220. cDefine29 ,cDefine30 ,cDefine31 ,cDefine32 ,cDefine33 ,cDefine34 ,
  221. cDefine35 ,cDefine36 ,cDefine37 ,iMPoIds ,bRelated ,bLPUseFree ,
  222. iRSRowNO ,iOriTrackID ,bCosting ,cmocode ,imoseq ,iExpiratDateCalcu ,
  223. iorderdid ,iordertype,iordercode,iorderseq,isodid,isotype,csocode,isoseq,irowno ,iposflag ,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10)
  224. SELECT @AutoID,@ID,@cInvCode,@iQuantity,@cBatch,0,
  225. a.Define22,a.Define23,a.Define24,a.Define25,a.Define26,a.Define27,
  226. null,null,a.Qty,a.Define28,
  227. a.Define29,a.Define30,a.Define31,a.Define32,a.Define33,a.Define34,
  228. a.Define35,a.Define36,a.Define37,a.MoDId,0,0,
  229. 0,0,1,b.MoCode,a.SortSeq,0,
  230. a.OrderDid,a.OrderType,a.OrderCode,a.OrderSeq,a.SoDId,a.SoType,a.SoCode,a.SoSeq,@irowno,0,@cFree1,@cFree2,@cFree3,@cFree4,@cFree5,@cFree6,@cFree7,@cFree8,@cFree9,@cFree10
  231. FROM dbo.mom_orderdetail a
  232. INNER JOIN dbo.mom_order b ON a.MoId=b.MoId WHERE a.MoDId='" + body.MODetailID + "'";
  233. cmd.Parameters.Clear();
  234. cmd.Parameters.Add(new SqlParameter("@AutoID", iChildId));
  235. cmd.Parameters.Add(new SqlParameter("@ID", iFatherId));
  236. cmd.Parameters.Add(new SqlParameter("@cInvCode", body.InvCode));
  237. cmd.Parameters.Add(new SqlParameter("@iQuantity", body.Quantity));
  238. cmd.Parameters.Add(new SqlParameter("@cBatch", body.BatchCode));
  239. cmd.Parameters.Add(new SqlParameter("@irowno", body.Sequence));
  240. cmd.Parameters.Add(new SqlParameter("@cFree1", body.cFree1));
  241. cmd.Parameters.Add(new SqlParameter("@cFree2", body.cFree2));
  242. cmd.Parameters.Add(new SqlParameter("@cFree3", body.cFree3));
  243. cmd.Parameters.Add(new SqlParameter("@cFree4", body.cFree4));
  244. cmd.Parameters.Add(new SqlParameter("@cFree5", body.cFree5));
  245. cmd.Parameters.Add(new SqlParameter("@cFree6", body.cFree6));
  246. cmd.Parameters.Add(new SqlParameter("@cFree7", body.cFree7));
  247. cmd.Parameters.Add(new SqlParameter("@cFree8", body.cFree8));
  248. cmd.Parameters.Add(new SqlParameter("@cFree9", body.cFree9));
  249. cmd.Parameters.Add(new SqlParameter("@cFree10", body.cFree10));
  250. cmd.CommandText = sql;
  251. try
  252. {
  253. int count = cmd.ExecuteNonQuery();
  254. if (count <= 0)
  255. {
  256. log.Error("生成材料出库单表头失败,受影响行数<=0;");
  257. throw new Exception("生成材料出库单表头失败,受影响行数<=0;");
  258. }
  259. }
  260. catch (Exception ex)
  261. {
  262. log.Error("生成材料出库单表头失败!SQL:\r\n" + sql, ex);
  263. throw new Exception("生成材料出库单表头失败!SQL:\r\n" + sql, ex);
  264. }
  265. #endregion
  266. if (head.UpdateStock)
  267. {
  268. #region 更新现存量
  269. key.cBustypeUN = "成品入库";
  270. key.cVouchTypeUN = "10";
  271. key.TableName = "IA_ST_UnAccountVouch10";
  272. //DBHelper.UpdateCurrentStock(cmd, body.InvCode, head.WHCode, "", body.Quantity, key);
  273. DBHelper.UpdateCurrentStockNEW(cmd, body.InvCode, head.WHCode, body.BatchCode, body.Quantity, body.cFree1, body.cFree2, body.cFree3, body.cFree4, body.cFree5, body.cFree6, body.cFree7, body.cFree8, body.cFree9, body.cFree10, key);
  274. #endregion
  275. }
  276. #region 回写生产订单入库数量
  277. sql = @"UPDATE dbo.mom_orderdetail SET QualifiedInQty=ISNULL(QualifiedInQty,0)+" + body.Quantity + " where MoDId='" + body.MODetailID + "'";
  278. DBHelper.CmdExecuteNonQuery(sql, cmd, "回写生产订单入库数量失败!");
  279. #endregion
  280. #region 判断工单行是否全部入库
  281. sql = "SELECT (QualifiedInQty - Qty) as qty,QualifiedInQty FROM dbo.mom_orderdetail WHERE MoDId='" + body.MODetailID + "'";
  282. DataTable dtClose = DBHelper.SQlReturnData(sql, cmd);
  283. foreach (DataRow dr in dtClose.Rows)
  284. {
  285. if (Convert.ToDecimal(dr["qty"]) >= 0)
  286. {
  287. sql = "update mom_orderdetail set CloseTime = GETDATE(),CloseDate= CONVERT(NVARCHAR(15),GETDATE(),23), CloseUser ='" + head.User + "',Status=4 where MODId='" + body.MODetailID + "'";
  288. DBHelper.CmdExecuteNonQuery(sql, cmd, "生产订单行关闭失败!");
  289. }
  290. }
  291. #endregion
  292. iFatherIdTwo += "'" + iFatherId + "',";
  293. iChildId--;
  294. }
  295. #endregion
  296. #region 查询
  297. sql = @" select a.ID as ID,a.ID as IDs,a.cCode as MRCVCode,a.cDepCode,c.cDepName,a.cWhCode,d.cWhName
  298. ,a.cMPoCode as MOCode ,a.cMaker as CreateUser ,a.dnmaketime as CreateDateTime
  299. ,a.cHandler as Checker ,a.dnverifytime as CheckDateTime
  300. from rdrecord10 a
  301. left join Department c on a.cDepCode=c.cDepCode
  302. left join Warehouse d on a.cWhCode=d.cWhCode WHERE A.cHandler IS NOT NULL AND A.ID in({0})
  303. select a.ID as IDs, b.AutoID as DetailID,b.irowno as Sequence ,b.cInvCode as InvCode ,
  304. b.iQuantity as Quantity ,b.iNum as Amount,b.iMPoIds as MODetailID
  305. from rdrecord10 a
  306. left join rdrecords10 b on a.ID=b.ID
  307. left join Department c on a.cDepCode=c.cDepCode
  308. left join Warehouse d on a.cWhCode=d.cWhCode WHERE A.cHandler IS NOT NULL AND A.ID in({0}) ";
  309. sql = string.Format(sql, iFatherIdTwo.TrimEnd(','));
  310. DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
  311. dtNew1.Merge(ds.Tables[0]);
  312. dtNew2.Merge(ds.Tables[1]);
  313. #endregion
  314. cmd.Transaction.Commit();
  315. }
  316. catch (Exception ex)
  317. {
  318. cmd.Transaction.Rollback();
  319. log.Error(ex.Message);
  320. throw new Exception(ex.Message);
  321. }
  322. finally
  323. {
  324. if (conn.State == ConnectionState.Open)
  325. {
  326. conn.Close();
  327. }
  328. conn.Dispose();
  329. }
  330. }
  331. string RelationName = "details";
  332. DataRelation dh = new DataRelation(RelationName, dtNew1.Columns["IDs"], dtNew2.Columns["IDs"]);
  333. DataSet dz = new DataSet();
  334. dz.Relations.Add(dh);
  335. msg = DBHelper.DataSetToJson(dz, RelationName);
  336. return msg;
  337. }
  338. /// <summary>
  339. /// 审核成品入库单
  340. /// </summary>
  341. /// <param name="infos"></param>
  342. /// <returns></returns>
  343. public bool Approve(List<ICSManufactureReceiveDoc> infos)
  344. {
  345. bool ResultFlag = false;
  346. List<ICSManufactureReceiveDoc> szJson = new List<ICSManufactureReceiveDoc>();
  347. string connS = "";
  348. if (infos.Count <= 0)
  349. {
  350. throw new Exception("传送数据为空!");
  351. }
  352. LogInfo(infos);
  353. string res = string.Empty;
  354. SqlConnection conn = new SqlConnection();
  355. SqlCommand cmd = new SqlCommand();
  356. string sql = string.Empty;
  357. foreach (ICSManufactureReceiveDoc head in infos)
  358. {
  359. try
  360. {
  361. connS = string.Format(connString, head.WorkPoint);
  362. conn = new System.Data.SqlClient.SqlConnection(connS);
  363. conn.Open();
  364. SqlTransaction sqlTran = conn.BeginTransaction();
  365. cmd = new SqlCommand();
  366. cmd.Transaction = sqlTran;
  367. cmd.Connection = conn;
  368. ICSUserInfo userInfo = new ICSUserInfo();
  369. userInfo = DBHelper.GetPersonInfo(head.User, cmd);
  370. #region 检验单号是否存在
  371. sql = "select * from rdrecord10 where ID='" + head.ID + "'";
  372. DataTable dt = DBHelper.SQlReturnData(sql, cmd);
  373. if (dt != null && dt.Rows.Count > 0)
  374. {
  375. string cHandler = dt.Rows[0]["cHandler"].ToString();
  376. if (!string.IsNullOrEmpty(cHandler))
  377. {
  378. throw new Exception("单据ID:" + head.ID + "不是开立状态!");
  379. }
  380. }
  381. else
  382. {
  383. throw new Exception("单据ID:" + head.ID + "在U8中不存在!");
  384. }
  385. #endregion
  386. #region 审核其他出库单
  387. sql = @"UPDATE dbo.rdrecord10 SET cHandler='" + userInfo.UserName + @"' ,
  388. dVeriDate=CONVERT(VARCHAR(50),GETDATE(),112),dnverifytime=GETDATE() WHERE ID='" + head.ID + "'";
  389. DBHelper.CmdExecuteNonQuery(sql, cmd, "审核其他出库单失败!");
  390. #endregion
  391. sql = "select * from dbo.rdrecords10 a inner join rdrecord10 b on a.ID=b.ID where b.ID='" + head.ID + "';";
  392. DataTable dtChecks = DBHelper.SQlReturnData(sql, cmd);
  393. if (head.UpdateStock)
  394. {
  395. #region 更新现存量
  396. for (int i = 0; i < dtChecks.Rows.Count; i++)
  397. {
  398. //判断物料批号与现存量表批号是否一致、数量不能超过现存量物料数量
  399. 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() + "'";
  400. DataTable dtItem = DBHelper.SQlReturnData(sql, cmd);
  401. if (dtItem != null && dtItem.Rows.Count > 0)
  402. {
  403. //if (!dtItem.Rows[0]["cBatch"].ToString().Equals(body.cBatch))
  404. //{
  405. // throw new Exception("物料条码的批号与U8现存量物料批号不一致,物料:" + body.cInvCode);
  406. //}
  407. if (Convert.ToDecimal(dtItem.Rows[0]["iQuantity"].ToString()) < Convert.ToDecimal(dtChecks.Rows[i]["iQuantity"].ToString()))
  408. {
  409. throw new Exception("物料条码的数量大于U8现存量物料数量,物料:" + dtChecks.Rows[i]["cInvCode"].ToString());
  410. }
  411. }
  412. else
  413. {
  414. throw new Exception("物料:" + dtChecks.Rows[i]["cInvCode"].ToString() + "在现存量表中不存在!");
  415. }
  416. VouchKey key = new VouchKey();
  417. key.cBustypeUN = "成品入库";
  418. key.cVouchTypeUN = "10";
  419. key.TableName = "IA_ST_UnAccountVouch10";
  420. //DBHelper.UpdateCurrentStock(cmd, dtChecks.Rows[i]["cInvCode"].ToString(), dtChecks.Rows[i]["cWhCode"].ToString(), "", Convert.ToDecimal(dtChecks.Rows[i]["iQuantity"].ToString()), key);
  421. 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);
  422. //回写fOutQuantityy
  423. // sql = @"Update CurrentStock set fOutQuantity=isnull(fOutQuantity,0)-" + Convert.ToDecimal(dtChecks.Rows[i]["iQuantity"].ToString()) + @"
  424. // where cInvCode='" + dtChecks.Rows[i]["cInvCode"].ToString() + "' and cWhCode='" + dtChecks.Rows[i]["cWhCode"].ToString() + "' ";
  425. //if (body.cBatch != null)
  426. //{
  427. // sql += "and cBatch='" + body.cBatch + "'";
  428. //}
  429. //else
  430. //{
  431. // sql += "and cBatch=''";
  432. //}
  433. //DBHelper.CmdExecuteNonQuery(sql, cmd, "回写fOutQuantity失败!");
  434. //if (head.UpdateTodoQuantity == true)
  435. //{
  436. }
  437. #endregion
  438. }
  439. cmd.Transaction.Commit();
  440. }
  441. catch (Exception ex)
  442. {
  443. cmd.Transaction.Rollback();
  444. log.Error(ex.Message);
  445. throw new Exception(ex.Message);
  446. }
  447. finally
  448. {
  449. if (conn.State == ConnectionState.Open)
  450. {
  451. conn.Close();
  452. }
  453. conn.Dispose();
  454. }
  455. ResultFlag = true;
  456. }
  457. return ResultFlag;
  458. }
  459. /// <summary>
  460. /// 删除成品入库单
  461. /// </summary>
  462. /// <param name="infos"></param>
  463. /// <returns></returns>
  464. public string Delete(List<ICSManufactureReceiveDoc> infos)
  465. {
  466. List<ICSManufactureReceiveDoc> szJson = new List<ICSManufactureReceiveDoc>();
  467. if (infos.Count <= 0)
  468. {
  469. throw new Exception("传送数据为空!");
  470. }
  471. string connS = "";
  472. string res = string.Empty;
  473. SqlConnection conn = new SqlConnection();
  474. SqlCommand cmd = new SqlCommand();
  475. string sql = string.Empty;
  476. foreach (ICSManufactureReceiveDoc info in infos)
  477. {
  478. try
  479. {
  480. connS = string.Format(connString, info.WorkPoint);
  481. conn = new System.Data.SqlClient.SqlConnection(connS);
  482. conn.Open();
  483. SqlTransaction sqlTran = conn.BeginTransaction();
  484. cmd = new SqlCommand();
  485. cmd.Transaction = sqlTran;
  486. cmd.Connection = conn;
  487. if (info.MTime < new DateTime(2000, 01, 01))
  488. throw new Exception("请输入正确的操作时间:" + info.MTime);
  489. sql = @" DELETE rdrecord10 WHERE ID={0}";
  490. sql = string.Format(sql, info.ID);
  491. DBHelper.CmdExecuteNonQuery(sql, cmd, "未查询到对应数据!");
  492. cmd.Transaction.Commit();
  493. }
  494. catch (Exception ex)
  495. {
  496. cmd.Transaction.Rollback();
  497. log.Error(ex.Message);
  498. throw new Exception(ex.Message);
  499. }
  500. finally
  501. {
  502. if (conn.State == ConnectionState.Open)
  503. {
  504. conn.Close();
  505. }
  506. conn.Dispose();
  507. }
  508. }
  509. return res;
  510. }
  511. /// <summary>
  512. ///
  513. /// 记录日志
  514. /// </summary>
  515. /// <param name="Bills"></param>
  516. private void LogInfo(List<ICSManufactureReceiveDoc> Bills)
  517. {
  518. string HeadList = string.Empty;
  519. string BodyList = string.Empty;
  520. foreach (ICSManufactureReceiveDoc head in Bills)
  521. {
  522. HeadList += "\r\n 表头主键ID:" + head.ID + ",仓库:" + head.WHCode + ",用户:" + head.User + ",站点:" + head.WorkPoint;
  523. foreach (ICSManufactureReceiveDocs body in head.details)
  524. {
  525. BodyList += "\r\n 表体主键ID: " + body.MODetailID + ",数量:" + body.Quantity;
  526. }
  527. }
  528. log.Info(HeadList);
  529. log.Info(BodyList);
  530. }
  531. }
  532. }