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

1421 lines
74 KiB

3 years ago
2 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
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
2 years ago
3 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
2 years ago
2 years ago
2 years ago
2 years ago
3 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
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
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
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
3 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
2 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 OutsourcingReceiveDoc
  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. private static string CRNALL = System.Configuration.ConfigurationManager.AppSettings["OutIssRCRDNAME"];
  23. private static string CRNA = System.Configuration.ConfigurationManager.AppSettings["MoICRDNAME"];
  24. /// <summary>
  25. /// 获取委外采购入库单
  26. /// </summary>
  27. /// <param name="infos"></param>
  28. /// <returns></returns>
  29. public string Get(List<ICSOutsourcingReceiveDoc> infos)
  30. {
  31. List<ICSOutsourcingReceiveDoc> szJson = new List<ICSOutsourcingReceiveDoc>();
  32. DataTable dt = null;
  33. DataTable dtNew = null;
  34. string connS = "";
  35. string json = "";
  36. if (infos.Count <= 0)
  37. {
  38. throw new Exception("传送数据为空!");
  39. }
  40. string res = string.Empty;
  41. SqlConnection conn = new SqlConnection();
  42. SqlCommand cmd = new SqlCommand();
  43. string sql = string.Empty;
  44. foreach (ICSOutsourcingReceiveDoc info in infos)
  45. {
  46. try
  47. {
  48. connS = string.Format(connString, info.WorkPoint);
  49. conn = new System.Data.SqlClient.SqlConnection(connS);
  50. conn.Open();
  51. SqlTransaction sqlTran = conn.BeginTransaction();
  52. cmd = new SqlCommand();
  53. cmd.Transaction = sqlTran;
  54. cmd.Connection = conn;
  55. if (info.MTime < new DateTime(2000, 01, 01))
  56. throw new Exception("请输入正确的操作时间:" + info.MTime);
  57. sql = @" select a.ID,iMPoIds,iordercode,a.cCode,a.cDepCode,c.cDepName,a.cWhCode,
  58. d.cWhName,a.cSource,a.cMaker,dnmaketime,cHandler,dnverifytime,cSourceCodeLs,
  59. b.AutoID ,b.irowno,b.cInvCode,b.iQuantity,e.MoDetailsID,b.iNum,e.csocode
  60. from rdrecord11 a
  61. left join rdrecords11 b on a.ID=b.ID
  62. left join Department c on a.cDepCode=c.cDepCode
  63. left join Warehouse d on a.cWhCode=d.cWhCode
  64. left join OM_MODetails e on b.iOMoDID=e.MoDetailsID
  65. where a.cBusType=''";
  66. if (!string.IsNullOrWhiteSpace(info.ORCVTCode))
  67. {
  68. sql += " and a.cCode='{0}'";
  69. }
  70. if (!string.IsNullOrWhiteSpace(info.MTime.ToString()))
  71. {
  72. sql += " and ISNULL(a.dnmodifytime,ISNULL(a.dnverifytime, ISNULL(a.dnmodifytime, a.dnmaketime)))>='{1}'";
  73. }
  74. if (!string.IsNullOrWhiteSpace(info.User))
  75. {
  76. sql += "and a.CMAKER='{2}'";
  77. }
  78. sql = string.Format(sql, info.ORCVTCode, info.MTime, info.User);
  79. dt = DBHelper.SQlReturnData(sql, cmd);
  80. if (dt.Rows.Count <= 0 || dt == null)
  81. throw new Exception("委外发料单:" + info.ORCVTCode + ",无信息!");
  82. if (dtNew == null)
  83. dtNew = dt;
  84. else
  85. dtNew.Merge(dt);
  86. cmd.Transaction.Commit();
  87. }
  88. catch (Exception ex)
  89. {
  90. cmd.Transaction.Rollback();
  91. log.Error(ex.Message);
  92. throw new Exception(ex.Message);
  93. }
  94. finally
  95. {
  96. if (conn.State == ConnectionState.Open)
  97. {
  98. conn.Close();
  99. }
  100. conn.Dispose();
  101. }
  102. }
  103. json = JsonConvert.SerializeObject(dtNew);
  104. return json;
  105. }
  106. /// <summary>
  107. /// 创建委外采购入(到货单)
  108. /// </summary>
  109. /// <param name="Bills"></param>
  110. /// <returns></returns>
  111. public string CreateOutsourcingReceiveDocByPOArrive(List<ICSOutsourcingReceiveDoc> Bills)
  112. {
  113. string msg = "";
  114. DataTable dtNew1 = null;
  115. DataTable dtNew2 = null;
  116. string connS = "";
  117. string sql = "";
  118. string iFatherIdTwo = "";
  119. int num = 0;
  120. //取得out库单的默认显示模版
  121. //取得采购入库单单据 表头ID,表体DID
  122. VouchKey key = new VouchKey();
  123. SqlConnection conn = new SqlConnection();
  124. SqlCommand cmd = new SqlCommand();
  125. if (Bills.Count <= 0)
  126. {
  127. throw new Exception("传送数据为空!");
  128. }
  129. LogInfo(Bills);
  130. foreach (ICSOutsourcingReceiveDoc head in Bills)
  131. {
  132. try
  133. {
  134. num = head.details.Count();
  135. connS = string.Format(connString, head.WorkPoint);
  136. conn = new System.Data.SqlClient.SqlConnection(connS);
  137. conn.Open();
  138. SqlTransaction sqlTran = conn.BeginTransaction();
  139. cmd = new SqlCommand();
  140. cmd.Transaction = sqlTran;
  141. cmd.Connection = conn;
  142. if (DBHelper.IsInventoryConsolidation(cmd, head.WorkPoint))
  143. {
  144. }
  145. else
  146. {
  147. throw new Exception("U8正在整理现存量,请稍后再试");
  148. }
  149. string[] ss = head.WorkPoint.Split('_');
  150. ERPDB = ss[1];
  151. string[] dd = CRNALL.Split('~');
  152. string crdname = dd[0];
  153. string carname = dd[1];
  154. string surface = dd[2];
  155. string cardnewcode = DBHelper.GetCardNumber(carname, cmd);
  156. //取得out库单的默认显示模版
  157. Dictionary<string, int> dic = DBHelper.GetAllCode("" + ERPDB + "", surface, "" + num + "", head.WorkPoint);
  158. int iFatherId = Convert.ToInt32(dic["iFatherId"].ToString());
  159. int iChildId = Convert.ToInt32(dic["iChildId"].ToString());
  160. DateTime date = DateTime.Now;
  161. string iBaseCodeLen = DBHelper.GetAllRDCode(cardnewcode, "" + date + "", "admin", head.WorkPoint);
  162. string cRDcode = DBHelper.GetRDCode(crdname, cmd);
  163. string DEF_ID = DBHelper.GetDefaultTemplate(cardnewcode, cmd);
  164. #region 验证数量不能大于到货单数量
  165. //foreach (ICSOutsourcingReceiveDocs body in head.details)
  166. // {
  167. // sql = "SELECT isnull(-iQuantity,0) FROM dbo.PU_ArrivalVouchs WHERE Autoid='" + body.ODNDetailID + "'";
  168. // DataTable dtQty = DBHelper.SQlReturnData(sql, cmd);
  169. // if (dtQty != null && dtQty.Rows.Count > 0)
  170. // {
  171. // //到货单可入数量
  172. // decimal PUQty = Convert.ToDecimal(dtQty.Rows[0][0]);
  173. // sql = "SELECT ISNULL(SUM(-iQuantity),0) FROM dbo.RdRecords01 WHERE iArrsId='" + body.ODNDetailID + "'";
  174. // DataTable dtReceQty = DBHelper.SQlReturnData(sql, cmd);
  175. // decimal ReceQty = Convert.ToDecimal(dtReceQty.Rows[0][0]);
  176. // if (ReceQty + body.Quantity > PUQty)
  177. // {
  178. // throw new Exception("入库数量大于当前到货单行可入库数量!");
  179. // }
  180. // }
  181. // else
  182. // {
  183. // throw new Exception("U8不存在该到货单行!");
  184. // }
  185. // }
  186. #endregion
  187. #region 委外采购入库单 表头
  188. sql = @"INSERT INTO dbo.RdRecord01
  189. ( ID ,bRdFlag ,cVouchType ,cBusType ,cSource ,cWhCode ,
  190. dDate ,cCode ,cRdCode ,cDepCode ,cPersonCode ,cPTCode ,
  191. cVenCode ,cOrderCode ,cARVCode ,cHandler ,cMemo ,
  192. bTransFlag ,cMaker ,cDefine1 ,cDefine2 ,cDefine3 ,
  193. cDefine4 ,cDefine5 ,cDefine6 ,cDefine7 ,cDefine8 ,
  194. cDefine9 ,cDefine10 ,dVeriDate ,bpufirst ,biafirst ,
  195. dARVDate ,VT_ID ,bIsSTQc ,cDefine11 ,cDefine12 ,
  196. cDefine13 ,cDefine14 ,cDefine15 ,cDefine16 ,
  197. ipurarriveid ,iTaxRate ,iExchRate ,cExch_Name ,bOMFirst,
  198. bFromPreYear ,bIsComplement ,iDiscountTaxType ,
  199. ireturncount ,iverifystate ,iswfcontrolled ,
  200. cModifyPerson ,dnmaketime ,dnverifytime ,
  201. bredvouch ,bCredit ,iPrintCount)
  202. SELECT @ID,1,'01','','',@cWhCode,
  203. CONVERT(NVARCHAR(15),GETDATE(),23),@cCode,@cRdCode,@cDepCode,a.cPersonCode,'01',
  204. a.cVenCode,b.cCode,a.cCode,@cHandler,a.cMemo,
  205. 0,@cMaker,a.cDefine1,a.cDefine2,a.cDefine3,
  206. a.cDefine4,a.cDefine5,a.cDefine6,a.cDefine7,a.cDefine8,
  207. a.cDefine9,a.cDefine10,CONVERT(NVARCHAR(15),GETDATE(),23),0,0,
  208. a.dDate,@VT_ID,0,a.cDefine11,a.cDefine12,
  209. a.cDefine13,a.cDefine14,a.cDefine15,a.cDefine16,
  210. a.ID,a.iTaxRate,a.iExchRate,a.cexch_name,0,
  211. 0,0,0,
  212. 0,0,0,
  213. '',GETDATE(),GETDATE(),
  214. 0,0,0
  215. FROM dbo.PU_ArrivalVouch a LEFT JOIN dbo.OM_MOMain b ON a.cpocode=b.cCode WHERE a.cCode='" + head.ODNCode + "'";
  216. cmd.Parameters.Clear();
  217. cmd.Parameters.Add(new SqlParameter("@ID", iFatherId));
  218. cmd.Parameters.Add(new SqlParameter("@cWhCode", head.WHCode));
  219. cmd.Parameters.Add(new SqlParameter("@cCode", iBaseCodeLen));
  220. cmd.Parameters.Add(new SqlParameter("@cDepCode", ""));
  221. cmd.Parameters.Add(new SqlParameter("@cHandler", head.User));
  222. cmd.Parameters.Add(new SqlParameter("@cMaker", head.User));
  223. cmd.Parameters.Add(new SqlParameter("@VT_ID", DEF_ID));
  224. cmd.Parameters.Add(new SqlParameter("@cRdCode", cRDcode));
  225. cmd.CommandText = sql;
  226. try
  227. {
  228. int count = cmd.ExecuteNonQuery();
  229. if (count <= 0)
  230. {
  231. log.Error("委外采购入库单表头失败,受影响行数<=0;");
  232. throw new Exception("委外采购入库单表头失败,受影响行数<=0;");
  233. }
  234. }
  235. catch (Exception ex)
  236. {
  237. log.Error("委外采购入库单表头失败!SQL:\r\n" + sql, ex);
  238. throw new Exception("委外采购入库单表头失败!SQL:\r\n" + sql, ex);
  239. }
  240. #endregion
  241. #region 采购入库单 表体
  242. foreach (ICSOutsourcingReceiveDocs body in head.details)
  243. {
  244. sql = @"INSERT INTO dbo.rdrecords01
  245. ( AutoID ,ID ,cInvCode ,iQuantity ,iUnitCost ,iPrice ,iAPrice ,
  246. iFlag ,iSQuantity ,iSNum ,iMoney ,
  247. cDefine22 ,cDefine23 ,cDefine24 ,cDefine25 ,cDefine26 ,cDefine27 ,
  248. cItem_class ,cItemCode ,iPOsID ,fACost ,cName ,iNQuantity ,
  249. chVencode ,iArrsId ,iOriTaxCost ,iOriCost ,iOriMoney ,iOriTaxPrice ,
  250. ioriSum ,iTaxRate ,iTaxPrice ,iSum ,bTaxCost ,cPOID ,iMatSettleState ,
  251. iBillSettleCount ,bLPUseFree ,iOriTrackID ,bCosting ,cbarvcode ,
  252. dbarvdate ,iExpiratDateCalcu ,iordertype ,isotype ,irowno ,bgift,cBatch,iProcessFee, iProcessCost,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10 )
  253. SELECT @AutoID,@ID1,@cInvCode,@iQuantity,0,0,0,
  254. 0,0,0,0,
  255. a.cDefine22,a.cDefine23,a.cDefine24,a.cDefine25,a.cDefine26,a.cDefine27,
  256. a.cItem_class,a.cItemCode,a.iPOsID,0,a.cItemName,a.iQuantity,
  257. c.cVenCode,a.Autoid,0,0,0,0,
  258. 0,a.iTaxRate,0,0,1,d.cCode,0,
  259. 0,0,0,1,c.cCode,
  260. c.dDate,0,0,0,@irowno,0,@cBatch,a.iCost*convert(decimal, @iQuantity),a.iCost,@cFree1,@cFree2,@cFree3,@cFree4,@cFree5,@cFree6,@cFree7,@cFree8,@cFree9,@cFree10
  261. FROM dbo.PU_ArrivalVouchs a LEFT JOIN dbo.OM_MODetails b ON a.iPOsID=b.MODetailsID
  262. INNER JOIN dbo.OM_MOMain d ON b.MOID=d.MOID
  263. INNER JOIN dbo.PU_ArrivalVouch c ON a.ID=c.ID where a.Autoid='" + body.ODNDetailID + @"'
  264. EXEC PROC_Update_OM_RdRecord01 @ID= @ID1
  265. ";
  266. cmd.Parameters.Clear();
  267. cmd.Parameters.Add(new SqlParameter("@AutoID", iChildId));
  268. cmd.Parameters.Add(new SqlParameter("@ID1", iFatherId));
  269. cmd.Parameters.Add(new SqlParameter("@cInvCode", body.InvCode));
  270. cmd.Parameters.Add(new SqlParameter("@iQuantity", body.Quantity));
  271. cmd.Parameters.Add(new SqlParameter("@irowno", body.Sequence));
  272. cmd.Parameters.Add(new SqlParameter("@cBatch", body.BatchCode));
  273. cmd.Parameters.Add(new SqlParameter("@cFree1", body.cFree1));
  274. cmd.Parameters.Add(new SqlParameter("@cFree2", body.cFree2));
  275. cmd.Parameters.Add(new SqlParameter("@cFree3", body.cFree3));
  276. cmd.Parameters.Add(new SqlParameter("@cFree4", body.cFree4));
  277. cmd.Parameters.Add(new SqlParameter("@cFree5", body.cFree5));
  278. cmd.Parameters.Add(new SqlParameter("@cFree6", body.cFree6));
  279. cmd.Parameters.Add(new SqlParameter("@cFree7", body.cFree7));
  280. cmd.Parameters.Add(new SqlParameter("@cFree8", body.cFree8));
  281. cmd.Parameters.Add(new SqlParameter("@cFree9", body.cFree9));
  282. cmd.Parameters.Add(new SqlParameter("@cFree10", body.cFree10));
  283. cmd.CommandText = sql;
  284. try
  285. {
  286. int count = cmd.ExecuteNonQuery();
  287. if (count <= 0)
  288. {
  289. log.Error("委外采购入库单表头失败,受影响行数<=0;");
  290. throw new Exception("委外采购入库单表头失败,受影响行数<=0;");
  291. }
  292. }
  293. catch (Exception ex)
  294. {
  295. log.Error("委外采购入库单表头失败!SQL:\r\n" + sql, ex);
  296. throw new Exception("委外采购入库单表头失败!SQL:\r\n" + sql, ex);
  297. }
  298. if (head.UpdateStock)
  299. {
  300. //更新现存量
  301. key.cBustypeUN = "委外加工";
  302. key.cVouchTypeUN = "01";
  303. key.TableName = "IA_ST_UnAccountVouch01";
  304. //DBHelper.UpdateCurrentStock(cmd, body.InvCode, head.WHCode, "", body.Quantity, key);
  305. 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);
  306. }
  307. //OM_MODetails
  308. sql = @"UPDATE b SET freceivedqty=ISNULL(freceivedqty,0)+" + body.Quantity + @"
  309. FROM dbo.PU_ArrivalVouchs a LEFT JOIN dbo.OM_MODetails b ON a.iPOsID=b.MODetailsID
  310. WHERE a.Autoid='" + body.ODNDetailID + "'";
  311. DBHelper.CmdExecuteNonQuery(sql, cmd, "回写OM_MODetails失败!");
  312. //回写PU_ArrivalVouchs失败
  313. sql = "UPDATE dbo.PU_ArrivalVouchs SET fValidInQuan=ISNULL(fValidInQuan,0)+" + body.Quantity + " WHERE Autoid='" + body.ODNDetailID + "'";
  314. DBHelper.CmdExecuteNonQuery(sql, cmd, "回写PU_ArrivalVouchs失败!");
  315. iFatherIdTwo += "'" + iFatherId + "',";
  316. iChildId--;
  317. }
  318. #endregion
  319. sql = @" select a.ID as ID,a.ID as IDs,a.cCode as ORCVTCode ,a.cVenCode,d.cVenName,a.cOrderCode as OOCode,
  320. a.cMaker as CreateUser,dnmaketime as CreateDateTime,cHandler as Checker,dnverifytime as CheckDateTime
  321. from rdrecord01 a
  322. left join Department c on a.cDepCode=c.cDepCode
  323. left join Vendor d on a.cVenCode=d.cVenCode
  324. where a.cBusType='' AND A.ID in ({0})
  325. select a.ID as IDs,b.AutoID as DetailID,b.irowno as Sequence,b.cInvCode as InvCode,b.iQuantity as Quantity,iNum as Amount,iArrsId as ODNDetailID
  326. from rdrecord01 a
  327. left join rdrecords01 b on a.ID=b.ID
  328. left join Department c on a.cDepCode=c.cDepCode
  329. left join Vendor d on a.cVenCode=d.cVenCode
  330. where a.cBusType='' AND A.ID in ({0}) ";
  331. sql = string.Format(sql, iFatherIdTwo.TrimEnd(','));
  332. DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
  333. if (dtNew1 == null)
  334. dtNew1 = ds.Tables[0];
  335. else
  336. dtNew1.Merge(ds.Tables[0]);
  337. if (dtNew2 == null)
  338. dtNew2 = ds.Tables[1];
  339. else
  340. dtNew2.Merge(ds.Tables[1]);
  341. cmd.Transaction.Commit();
  342. }
  343. catch (Exception ex)
  344. {
  345. cmd.Transaction.Rollback();
  346. log.Error(ex.Message);
  347. throw new Exception(ex.Message);
  348. }
  349. finally
  350. {
  351. if (conn.State == ConnectionState.Open)
  352. {
  353. conn.Close();
  354. }
  355. conn.Dispose();
  356. }
  357. }
  358. string RelationName = "details";
  359. DataSet dz = new DataSet();
  360. dtNew1.TableName = "Table0";
  361. dtNew2.TableName = "Table1";
  362. dz.Tables.Add(dtNew1.Copy());
  363. dz.Tables.Add(dtNew2.Copy());
  364. DataRelation dh = new DataRelation(RelationName, dz.Tables[0].Columns["IDs"], dz.Tables[1].Columns["IDs"]);
  365. dz.Relations.Add(dh);
  366. msg = DBHelper.DataSetToJson(dz, RelationName);
  367. return msg;
  368. }
  369. /// <summary>
  370. /// 创建委外采购入(委外到货单)
  371. /// </summary>
  372. /// <param name="Bills"></param>
  373. /// <returns></returns>
  374. public string CreateOutsourcingReceiveDocByPU(List<ICSOutsourcingReceiveDoc> Bills)
  375. {
  376. string msg = "";
  377. string connS = "";
  378. int num = 0;
  379. //取得out库单的默认显示模版
  380. //取得采购入库单单据 表头ID,表体DID
  381. VouchKey key = new VouchKey();
  382. SqlConnection conn = new SqlConnection();
  383. SqlCommand cmd = new SqlCommand();
  384. if (Bills.Count <= 0)
  385. {
  386. throw new Exception("传送数据为空!");
  387. }
  388. LogInfo(Bills);
  389. foreach (ICSOutsourcingReceiveDoc head in Bills)
  390. {
  391. try
  392. {
  393. num = head.details.Count();
  394. connS = string.Format(connString, head.WorkPoint);
  395. conn = new System.Data.SqlClient.SqlConnection(connS);
  396. conn.Open();
  397. SqlTransaction sqlTran = conn.BeginTransaction();
  398. cmd = new SqlCommand();
  399. cmd.Transaction = sqlTran;
  400. cmd.Connection = conn;
  401. string[] ss = head.WorkPoint.Split('_');
  402. ERPDB = ss[1];
  403. string[] dd = CRNALL.Split('~');
  404. string crdname = dd[0];
  405. string carname = dd[1];
  406. string surface = dd[2];
  407. string cardnewcode = DBHelper.GetCardNumber(carname, cmd);
  408. //取得out库单的默认显示模版
  409. Dictionary<string, int> dic = DBHelper.GetAllCode("" + ERPDB + "", surface, "" + num + "", head.WorkPoint);
  410. int iFatherId = Convert.ToInt32(dic["iFatherId"].ToString());
  411. int iChildId = Convert.ToInt32(dic["iChildId"].ToString());
  412. DateTime date = DateTime.Now;
  413. string iBaseCodeLen = DBHelper.GetAllRDCode(cardnewcode, "" + date + "", "admin", head.WorkPoint);
  414. string cRDcode = DBHelper.GetRDCode(crdname, cmd);
  415. string DEF_ID = DBHelper.GetDefaultTemplate(cardnewcode, cmd);
  416. string sql = "";
  417. #region 验证数量不能大于到货单数量
  418. foreach (ICSOutsourcingReceiveDocs body in head.details)
  419. {
  420. sql = "SELECT isnull(-iQuantity,0) FROM dbo.PU_ArrivalVouchs WHERE Autoid='" + body.ODNDetailID + "'";
  421. DataTable dtQty = DBHelper.SQlReturnData(sql, cmd);
  422. if (dtQty != null && dtQty.Rows.Count > 0)
  423. {
  424. //到货单可入数量
  425. decimal PUQty = Convert.ToDecimal(dtQty.Rows[0][0]);
  426. sql = "SELECT ISNULL(SUM(-iQuantity),0) FROM dbo.RdRecords01 WHERE iArrsId='" + body.ODNDetailID + "'";
  427. DataTable dtReceQty = DBHelper.SQlReturnData(sql, cmd);
  428. decimal ReceQty = Convert.ToDecimal(dtReceQty.Rows[0][0]);
  429. if (ReceQty + body.Quantity > PUQty)
  430. {
  431. throw new Exception("入库数量大于当前到货单行可入库数量!");
  432. }
  433. }
  434. else
  435. {
  436. throw new Exception("U8不存在该到货单行!");
  437. }
  438. }
  439. #endregion
  440. #region 委外采购入库单 表头
  441. sql = @"INSERT INTO dbo.RdRecord01
  442. ( ID ,bRdFlag ,cVouchType ,cBusType ,cSource ,cWhCode ,
  443. dDate ,cCode ,cRdCode ,cDepCode ,cPersonCode ,cPTCode ,
  444. cVenCode ,cOrderCode ,cARVCode ,cHandler ,cMemo ,
  445. bTransFlag ,cMaker ,cDefine1 ,cDefine2 ,cDefine3 ,
  446. cDefine4 ,cDefine5 ,cDefine6 ,cDefine7 ,cDefine8 ,
  447. cDefine9 ,cDefine10 ,dVeriDate ,bpufirst ,biafirst ,
  448. dARVDate ,VT_ID ,bIsSTQc ,cDefine11 ,cDefine12 ,
  449. cDefine13 ,cDefine14 ,cDefine15 ,cDefine16 ,
  450. ipurarriveid ,iTaxRate ,iExchRate ,cExch_Name ,bOMFirst,
  451. bFromPreYear ,bIsComplement ,iDiscountTaxType ,
  452. ireturncount ,iverifystate ,iswfcontrolled ,
  453. cModifyPerson ,dnmaketime ,dnverifytime ,
  454. bredvouch ,bCredit ,iPrintCount)
  455. SELECT @ID,1,'01','','',@cWhCode,
  456. CONVERT(NVARCHAR(15),GETDATE(),23),@cCode,@cRdCode,@cDepCode,a.cPersonCode,'01',
  457. a.cVenCode,b.cCode,a.cCode,@cHandler,a.cMemo,
  458. 0,@cMaker,a.cDefine1,a.cDefine2,a.cDefine3,
  459. a.cDefine4,a.cDefine5,a.cDefine6,a.cDefine7,a.cDefine8,
  460. a.cDefine9,a.cDefine10,CONVERT(NVARCHAR(15),GETDATE(),23),0,0,
  461. a.dDate,@VT_ID,0,a.cDefine11,a.cDefine12,
  462. a.cDefine13,a.cDefine14,a.cDefine15,a.cDefine16,
  463. a.ID,a.iTaxRate,a.iExchRate,a.cexch_name,0,
  464. 0,0,0,
  465. 0,0,0,
  466. '',GETDATE(),GETDATE(),
  467. 0,0,0
  468. FROM dbo.PU_ArrivalVouch a LEFT JOIN dbo.OM_MOMain b ON a.cpocode=b.cCode WHERE a.cCode ='" + head.ODNCode + "'";
  469. cmd.Parameters.Clear();
  470. cmd.Parameters.Add(new SqlParameter("@ID", iFatherId));
  471. cmd.Parameters.Add(new SqlParameter("@cWhCode", head.WHCode));
  472. cmd.Parameters.Add(new SqlParameter("@cCode", iBaseCodeLen));
  473. cmd.Parameters.Add(new SqlParameter("@cDepCode", ""));
  474. cmd.Parameters.Add(new SqlParameter("@cHandler", head.User));
  475. cmd.Parameters.Add(new SqlParameter("@cMaker", head.User));
  476. cmd.Parameters.Add(new SqlParameter("@VT_ID", DEF_ID));
  477. cmd.Parameters.Add(new SqlParameter("@cRdCode", cRDcode));
  478. cmd.CommandText = sql;
  479. try
  480. {
  481. int count = cmd.ExecuteNonQuery();
  482. if (count <= 0)
  483. {
  484. log.Error("委外采购入库单表头失败,受影响行数<=0;");
  485. throw new Exception("委外采购入库单表头失败,受影响行数<=0;");
  486. }
  487. }
  488. catch (Exception ex)
  489. {
  490. log.Error("委外采购入库单表头失败!SQL:\r\n" + sql, ex);
  491. throw new Exception("委外采购入库单表头失败!SQL:\r\n" + sql, ex);
  492. }
  493. #endregion
  494. #region 采购入库单 表体
  495. int irowno = 0;
  496. foreach (ICSOutsourcingReceiveDocs body in head.details)
  497. {
  498. sql = @"INSERT INTO dbo.rdrecords01
  499. ( AutoID ,ID ,cInvCode ,iQuantity ,iUnitCost ,iPrice ,iAPrice ,
  500. iFlag ,iSQuantity ,iSNum ,iMoney ,
  501. cDefine22 ,cDefine23 ,cDefine24 ,cDefine25 ,cDefine26 ,cDefine27 ,
  502. cItem_class ,cItemCode ,iPOsID ,fACost ,cName ,iNQuantity ,
  503. chVencode ,iArrsId ,iOriTaxCost ,iOriCost ,iOriMoney ,iOriTaxPrice ,
  504. ioriSum ,iTaxRate ,iTaxPrice ,iSum ,bTaxCost ,cPOID ,iMatSettleState ,
  505. iBillSettleCount ,bLPUseFree ,iOriTrackID ,bCosting ,cbarvcode ,
  506. dbarvdate ,iExpiratDateCalcu ,iordertype ,isotype ,irowno ,bgift,cBatch,iProcessFee, iProcessCost,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10 )
  507. SELECT @AutoID,@ID1,@cInvCode,@iQuantity,0,0,0,
  508. 0,0,0,0,
  509. a.cDefine22,a.cDefine23,a.cDefine24,a.cDefine25,a.cDefine26,a.cDefine27,
  510. a.cItem_class,a.cItemCode,a.iPOsID,0,a.cItemName,a.iQuantity,
  511. c.cVenCode,a.Autoid,0,0,0,0,
  512. 0,a.iTaxRate,0,0,1,d.cCode,0,
  513. 0,0,0,1,c.cCode,
  514. c.dDate,0,0,0,@irowno,0,@cBatch,a.iCost*convert(decimal, @iQuantity),a.iCost,@cFree1,@cFree2,@cFree3,@cFree4,@cFree5,@cFree6,@cFree7,@cFree8,@cFree9,@cFree10
  515. FROM dbo.PU_ArrivalVouchs a LEFT JOIN dbo.OM_MODetails b ON a.iPOsID=b.MODetailsID
  516. INNER JOIN dbo.OM_MOMain d ON b.MOID=d.MOID
  517. INNER JOIN dbo.PU_ArrivalVouch c ON a.ID=c.ID where a.Autoid='" + body.ODNDetailID + @"'
  518. EXEC PROC_Update_OM_RdRecord01 @ID= @ID1
  519. ";
  520. cmd.Parameters.Clear();
  521. cmd.Parameters.Add(new SqlParameter("@AutoID", iChildId));
  522. cmd.Parameters.Add(new SqlParameter("@ID1", iFatherId));
  523. cmd.Parameters.Add(new SqlParameter("@cInvCode", body.InvCode));
  524. cmd.Parameters.Add(new SqlParameter("@iQuantity", body.Quantity));
  525. cmd.Parameters.Add(new SqlParameter("@irowno", irowno));
  526. cmd.Parameters.Add(new SqlParameter("@cBatch", body.BatchCode));
  527. cmd.Parameters.Add(new SqlParameter("@cFree1", body.cFree1));
  528. cmd.Parameters.Add(new SqlParameter("@cFree2", body.cFree2));
  529. cmd.Parameters.Add(new SqlParameter("@cFree3", body.cFree3));
  530. cmd.Parameters.Add(new SqlParameter("@cFree4", body.cFree4));
  531. cmd.Parameters.Add(new SqlParameter("@cFree5", body.cFree5));
  532. cmd.Parameters.Add(new SqlParameter("@cFree6", body.cFree6));
  533. cmd.Parameters.Add(new SqlParameter("@cFree7", body.cFree7));
  534. cmd.Parameters.Add(new SqlParameter("@cFree8", body.cFree8));
  535. cmd.Parameters.Add(new SqlParameter("@cFree9", body.cFree9));
  536. cmd.Parameters.Add(new SqlParameter("@cFree10", body.cFree10));
  537. cmd.CommandText = sql;
  538. try
  539. {
  540. int count = cmd.ExecuteNonQuery();
  541. if (count <= 0)
  542. {
  543. log.Error("委外采购入库单表头失败,受影响行数<=0;");
  544. throw new Exception("委外采购入库单表头失败,受影响行数<=0;");
  545. }
  546. }
  547. catch (Exception ex)
  548. {
  549. log.Error("委外采购入库单表头失败!SQL:\r\n" + sql, ex);
  550. throw new Exception("委外采购入库单表头失败!SQL:\r\n" + sql, ex);
  551. }
  552. if (head.UpdateStock)
  553. {
  554. //更新现存量
  555. key.cBustypeUN = "委外加工";
  556. key.cVouchTypeUN = "01";
  557. key.TableName = "IA_ST_UnAccountVouch01";
  558. //DBHelper.UpdateCurrentStock(cmd, body.InvCode, head.WHCode, "", body.Quantity, key);
  559. 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);
  560. }
  561. //OM_MODetails
  562. sql = @"UPDATE b SET freceivedqty=ISNULL(freceivedqty,0)+" + body.Quantity + @"
  563. FROM dbo.PU_ArrivalVouchs a LEFT JOIN dbo.OM_MODetails b ON a.iPOsID=b.MODetailsID
  564. WHERE a.Autoid='" + body.ODNDetailID + "'";
  565. DBHelper.CmdExecuteNonQuery(sql, cmd, "回写OM_MODetails失败!");
  566. //回写PU_ArrivalVouchs失败
  567. sql = "UPDATE dbo.PU_ArrivalVouchs SET fValidInQuan=ISNULL(fValidInQuan,0)+" + body.Quantity + " WHERE Autoid='" + body.ODNDetailID + "'";
  568. DBHelper.CmdExecuteNonQuery(sql, cmd, "回写PU_ArrivalVouchs失败!");
  569. //更新待入库数量
  570. sql = "UPDATE dbo.CurrentStock SET fInQuantity=ISNULL(fInQuantity,0)-" + body.Quantity + " WHERE cInvCode='" + body.InvCode + "' AND cWhCode ='" + head.WHCode + "'";
  571. if (DBHelper.bInvBatch(body.InvCode, cmd) == true)
  572. {
  573. //if (!string.IsNullOrWhiteSpace(body.cBatch))
  574. //{
  575. // sql += " and cBatch='" + body.cBatch + "'";
  576. //}
  577. }
  578. DBHelper.CmdExecuteNonQuery(sql, cmd, "更新待入库数量失败!");
  579. // #region 判断现存量是否足够
  580. // sql = @"IF EXISTS(SELECT AutoID FROM dbo.CurrentStock WHERE iQuantity<0 OR iNum<0 OR fInQuantity<0)
  581. // BEGIN
  582. // DECLARE @MSG NVARCHAR(100)
  583. // SELECT @MSG='ERP待入库数量不足!AutoID:'+CAST(AutoID AS NVARCHAR(100)) FROM dbo.CurrentStock WHERE iQuantity<0 OR iNum<0 OR fInQuantity<0
  584. // RAISERROR(@MSG,16,1)
  585. // END";
  586. // cmd.CommandText = sql;
  587. // cmd.ExecuteNonQuery();
  588. // #endregion
  589. }
  590. #endregion
  591. cmd.Transaction.Commit();
  592. }
  593. catch (Exception ex)
  594. {
  595. cmd.Transaction.Rollback();
  596. log.Error(ex.Message);
  597. throw new Exception(ex.Message);
  598. }
  599. finally
  600. {
  601. if (conn.State == ConnectionState.Open)
  602. {
  603. conn.Close();
  604. }
  605. conn.Dispose();
  606. }
  607. //GetSerialCode(iFatherId.ToString());
  608. }
  609. return msg;
  610. }
  611. /// <summary>
  612. /// 创建委外采购入(委外到货单)
  613. /// </summary>
  614. /// <param name="Bills"></param>
  615. /// <returns></returns>
  616. public string CreateOutsourcingReceiveDocByPO(List<ICSOutsourcingReceiveDoc> Bills)
  617. {
  618. string msg = "";
  619. string connS = "";
  620. string mocode = "";
  621. string seq = "";
  622. int num = 0;
  623. int out11 = 0;
  624. int irownnew = 0;
  625. int news = 0;
  626. string iFatherIdTwo = "";
  627. string sql = "";
  628. DataTable dt = null;
  629. DataTable dtNew1 = null;
  630. DataTable dtNew2 = null;
  631. VouchKey key = new VouchKey();
  632. SqlConnection conn = new SqlConnection();
  633. SqlCommand cmd = new SqlCommand();
  634. if (Bills.Count <= 0)
  635. {
  636. throw new Exception("传送数据为空!");
  637. }
  638. LogInfo(Bills);
  639. foreach (ICSOutsourcingReceiveDoc head in Bills)
  640. {
  641. foreach (ICSOutsourcingReceiveDocs load in head.details)
  642. {
  643. foreach (ICSOutsourcingReceiveDocss loads in load.detailss)
  644. {
  645. news++;
  646. }
  647. }
  648. }
  649. foreach (ICSOutsourcingReceiveDoc head in Bills)
  650. {
  651. try
  652. {
  653. connS = string.Format(connString, head.WorkPoint);
  654. conn = new System.Data.SqlClient.SqlConnection(connS);
  655. conn.Open();
  656. SqlTransaction sqlTran = conn.BeginTransaction();
  657. cmd = new SqlCommand();
  658. cmd.Transaction = sqlTran;
  659. cmd.Connection = conn;
  660. if (DBHelper.IsInventoryConsolidation(cmd, head.WorkPoint))
  661. {
  662. }
  663. else
  664. {
  665. throw new Exception("U8正在整理现存量,请稍后再试");
  666. }
  667. string[] ss = head.WorkPoint.Split('_');
  668. ERPDB = ss[1];
  669. string[] dd = CRNALL.Split('~');
  670. string crdname = dd[0];
  671. string carname = dd[1];
  672. string surface = dd[2];
  673. string[] d = CRNA.Split('~');
  674. string crdname1 = d[0];
  675. string carname1 = d[1];
  676. string surface1 = d[2];
  677. string cardnewcode = DBHelper.GetCardNumber(carname, cmd);
  678. string cardnewcode1 = DBHelper.GetCardNumber(carname1, cmd);
  679. //取得out库单的默认显示模版
  680. Dictionary<string, int> dic = DBHelper.GetAllCode("" + ERPDB + "", surface, "" + num + "", head.WorkPoint);
  681. int iFatherId = Convert.ToInt32(dic["iFatherId"].ToString());
  682. int iChildId = Convert.ToInt32(dic["iChildId"].ToString());
  683. DateTime date = DateTime.Now;
  684. string iBaseCodeLen = DBHelper.GetAllRDCode(cardnewcode, "" + date + "", "admin", head.WorkPoint);
  685. string cRDcode = DBHelper.GetRDCode(crdname, cmd);
  686. string DEF_ID = DBHelper.GetDefaultTemplate(cardnewcode, cmd);
  687. Dictionary<string, int> dic1 = DBHelper.GetAllCode("" + ERPDB + "", surface1, "1", head.WorkPoint);
  688. int iFatherId1 = Convert.ToInt32(dic1["iFatherId"].ToString());
  689. out11 = iFatherId1;
  690. int iChildId1 = Convert.ToInt32(dic1["iChildId"].ToString());
  691. DateTime date1 = DateTime.Now;
  692. string iBaseCodeLen1 = DBHelper.GetAllRDCode(cardnewcode1, "" + date1 + "", "admin", head.WorkPoint);
  693. string cRDcode1 = DBHelper.GetRDCode(crdname1, cmd);
  694. string DEF_ID1 = DBHelper.GetDefaultTemplate(cardnewcode1, cmd);
  695. #region 验证数量不能大于到货单数量
  696. //foreach (ICSOutsourcingReceiveDocs body in head.details)
  697. //{
  698. // sql = "SELECT isnull(-iQuantity,0) FROM dbo.PU_ArrivalVouchs WHERE Autoid='" + body.ODNDetailID + "'";
  699. // DataTable dtQty = DBHelper.SQlReturnData(sql, cmd);
  700. // if (dtQty != null && dtQty.Rows.Count > 0)
  701. // {
  702. // //到货单可入数量
  703. // decimal PUQty = Convert.ToDecimal(dtQty.Rows[0][0]);
  704. // sql = "SELECT ISNULL(SUM(-iQuantity),0) FROM dbo.RdRecords01 WHERE iArrsId='" + body.ODNDetailID + "'";
  705. // DataTable dtReceQty = DBHelper.SQlReturnData(sql, cmd);
  706. // decimal ReceQty = Convert.ToDecimal(dtReceQty.Rows[0][0]);
  707. // if (ReceQty + body.Quantity > PUQty)
  708. // {
  709. // throw new Exception("入库数量大于当前到货单行可入库数量!");
  710. // }
  711. // }
  712. // else
  713. // {
  714. // throw new Exception("U8不存在该到货单行!");
  715. // }
  716. //}
  717. #endregion
  718. #region 委外采购入库单 表头
  719. sql = @"INSERT INTO dbo.RdRecord01
  720. ( ID ,bRdFlag ,cVouchType ,cBusType ,cSource ,cWhCode ,
  721. dDate ,cCode ,cRdCode ,cDepCode ,cPersonCode ,cPTCode ,
  722. cVenCode ,cOrderCode ,cARVCode ,cHandler ,cMemo ,
  723. bTransFlag ,cMaker ,cDefine1 ,cDefine2 ,cDefine3 ,
  724. cDefine4 ,cDefine5 ,cDefine6 ,cDefine7 ,cDefine8 ,
  725. cDefine9 ,cDefine10 ,dVeriDate ,bpufirst ,biafirst ,
  726. dARVDate ,VT_ID ,bIsSTQc ,cDefine11 ,cDefine12 ,
  727. cDefine13 ,cDefine14 ,cDefine15 ,cDefine16 ,
  728. ipurarriveid ,iTaxRate ,iExchRate ,cExch_Name ,bOMFirst,
  729. bFromPreYear ,bIsComplement ,iDiscountTaxType ,
  730. ireturncount ,iverifystate ,iswfcontrolled ,
  731. cModifyPerson ,dnmaketime ,dnverifytime ,
  732. bredvouch ,bCredit ,iPrintCount)
  733. SELECT @ID,1,'01','','',@cWhCode,
  734. CONVERT(NVARCHAR(15),GETDATE(),23),@cCode,@RdCode,@cDepCode,a.cPersonCode,'01',
  735. a.cVenCode,'',a.cCode,@cHandler,a.cMemo,
  736. 0,@cMaker,a.cDefine1,a.cDefine2,a.cDefine3,
  737. a.cDefine4,a.cDefine5,a.cDefine6,a.cDefine7,a.cDefine8,
  738. a.cDefine9,a.cDefine10,CONVERT(NVARCHAR(15),GETDATE(),23),0,0,
  739. a.dDate,@VT_ID,0,a.cDefine11,a.cDefine12,
  740. a.cDefine13,a.cDefine14,a.cDefine15,a.cDefine16,
  741. '',a.iTaxRate,a.nflat,a.cexch_name,0,
  742. 0,0,0,
  743. 0,0,0,
  744. '',GETDATE(),GETDATE(),
  745. 0,0,0
  746. FROM dbo.OM_MOMain a WHERE a.cCode='" + head.OOCode + "'";
  747. cmd.Parameters.Clear();
  748. cmd.Parameters.Add(new SqlParameter("@ID", iFatherId));
  749. cmd.Parameters.Add(new SqlParameter("@cWhCode", head.WHCode));
  750. cmd.Parameters.Add(new SqlParameter("@cCode", iBaseCodeLen));
  751. cmd.Parameters.Add(new SqlParameter("@cDepCode", ""));
  752. cmd.Parameters.Add(new SqlParameter("@cHandler", head.User));
  753. cmd.Parameters.Add(new SqlParameter("@cMaker", head.User));
  754. cmd.Parameters.Add(new SqlParameter("@VT_ID", DEF_ID));
  755. cmd.Parameters.Add(new SqlParameter("@RdCode", cRDcode));
  756. cmd.CommandText = sql;
  757. try
  758. {
  759. int count = cmd.ExecuteNonQuery();
  760. if (count <= 0)
  761. {
  762. log.Error("委外采购入库单表头失败,受影响行数<=0;");
  763. throw new Exception("委外采购入库单表头失败,受影响行数<=0;");
  764. }
  765. }
  766. catch (Exception ex)
  767. {
  768. log.Error("委外采购入库单表头失败!SQL:\r\n" + sql, ex);
  769. throw new Exception("委外采购入库单表头失败!SQL:\r\n" + sql, ex);
  770. }
  771. #endregion
  772. if (news != 0)
  773. {
  774. #region 材料出库单表头
  775. sql = @"
  776. INSERT INTO dbo.rdrecord11
  777. ( ID ,bRdFlag ,cVouchType ,cBusType ,cSource ,
  778. cWhCode ,dDate ,cCode ,cRdCode ,cDepCode,
  779. cPersonCode,cHandler ,bTransFlag ,cMaker ,dVeriDate ,
  780. bpufirst ,biafirst ,VT_ID ,bIsSTQc ,cPsPcode ,
  781. cMPoCode ,iproorderid ,bFromPreYear ,bIsLsQuery ,bIsComplement ,
  782. iDiscountTaxType ,ireturncount ,iverifystate ,iswfcontrolled ,dnmaketime ,
  783. dnverifytime ,bredvouch ,iPrintCount,cVenCode,iMQuantity)
  784. SELECT distinct @ID,0,'11','','',
  785. @cWhCode,CONVERT(NVARCHAR(15),GETDATE(),23),@cCode,@cRdCode,c.cDepCode,
  786. c.cPersonCode,@cHandler,0,@cMaker,CONVERT(NVARCHAR(15),GETDATE(),23),
  787. 0,0,@VT_ID,0,null,
  788. c.cCode,a.MoId,0,0,0,
  789. 0,0,0,0,GETDATE(),
  790. GETDATE(),@bredvouch,0,c.cVenCode,null
  791. from dbo.OM_MOMaterials a
  792. INNER JOIN dbo.OM_MODetails b ON a.MoDetailsID = b.MoDetailsID
  793. LEFT JOIN dbo.OM_MOMain c ON b.MOID = c.MOID
  794. WHERE c.cCode='" + head.OOCode + "'";
  795. cmd.Parameters.Clear();
  796. cmd.Parameters.Add(new SqlParameter("@ID", out11));
  797. cmd.Parameters.Add(new SqlParameter("@cWhCode", head.WHCode));
  798. cmd.Parameters.Add(new SqlParameter("@cCode", iBaseCodeLen1));
  799. cmd.Parameters.Add(new SqlParameter("@cHandler", head.User));
  800. cmd.Parameters.Add(new SqlParameter("@cMaker", head.User));
  801. cmd.Parameters.Add(new SqlParameter("@VT_ID", DEF_ID1));
  802. cmd.Parameters.Add(new SqlParameter("@bredvouch", "0"));
  803. cmd.Parameters.Add(new SqlParameter("@cRdCode", cRDcode1));
  804. cmd.CommandText = sql;
  805. try
  806. {
  807. int count = cmd.ExecuteNonQuery();
  808. if (count <= 0)
  809. {
  810. log.Error("生成成品入库单表头失败,受影响行数<=0;");
  811. throw new Exception("生成成品入库单表头失败,受影响行数<=0;");
  812. }
  813. }
  814. catch (Exception ex)
  815. {
  816. log.Error("生成成品入库单表头失败!SQL:\r\n" + sql, ex);
  817. throw new Exception("生成成品入库单表头失败!SQL:\r\n" + sql, ex);
  818. }
  819. #endregion
  820. }
  821. #region 采购入库单 表体
  822. foreach (ICSOutsourcingReceiveDocs body in head.details)
  823. {
  824. sql = @"SELECT b.cCode,a.iVouchRowNo FROM dbo.OM_MODetails a INNER JOIN
  825. dbo.OM_MOMain b ON b.MoId = a.MoId WHERE a.MODetailsID = '" + body.OODetailID + "'";
  826. DataTable dtCheck = DBHelper.SQlReturnData(sql, cmd);
  827. if (dtCheck != null && dtCheck.Rows.Count > 0)
  828. {
  829. mocode = dtCheck.Rows[0]["cCode"].ToString();
  830. seq = dtCheck.Rows[0]["iVouchRowNo"].ToString();
  831. }
  832. sql = @"INSERT INTO dbo.rdrecords01
  833. ( AutoID ,ID ,cInvCode ,iQuantity ,iUnitCost ,iPrice ,iAPrice ,
  834. iFlag ,iSQuantity ,iSNum ,iMoney ,
  835. cDefine22 ,cDefine23 ,cDefine24 ,cDefine25 ,cDefine26 ,cDefine27 ,
  836. cItem_class ,cItemCode ,iOMoDID ,fACost ,cName ,iNQuantity ,
  837. chVencode ,iArrsId ,iOriTaxCost ,iOriCost ,iOriMoney ,iOriTaxPrice ,
  838. ioriSum ,iTaxRate ,iTaxPrice ,iSum ,bTaxCost ,cPOID ,iMatSettleState ,
  839. iBillSettleCount ,bLPUseFree ,iOriTrackID ,bCosting ,cbarvcode
  840. ,iExpiratDateCalcu ,iordertype ,isotype ,irowno ,bgift,cBatch,iProcessFee, iProcessCost,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10 )
  841. SELECT @AutoID,@ID1,@cInvCode,@iQuantity,0,0,0,
  842. 0,0,0,0,
  843. a.cDefine22,a.cDefine23,a.cDefine24,a.cDefine25,a.cDefine26,a.cDefine27,
  844. a.cItem_class,a.cItemCode,a.MODetailsID,0,a.cItemName,a.iQuantity,
  845. @VenCode,'',0,0,0,0,
  846. 0,d.nflat,0,0,1,'',0,
  847. 0,0,0,1,'',
  848. 0,0,0,@irowno,0,@cBatch,a.iNatUnitPrice *convert(decimal, @iQuantity),a.iNatUnitPrice ,@cFree1,@cFree2,@cFree3,@cFree4,@cFree5,@cFree6,@cFree7,@cFree8,@cFree9,@cFree10
  849. FROM dbo.OM_MODetails a
  850. INNER JOIN dbo.OM_MOMain d ON a.MOID=d.MOID
  851. where a.MODetailsID='" + body.OODetailID + @"'
  852. ";
  853. cmd.Parameters.Clear();
  854. cmd.Parameters.Add(new SqlParameter("@AutoID", iChildId));
  855. cmd.Parameters.Add(new SqlParameter("@ID1", iFatherId));
  856. cmd.Parameters.Add(new SqlParameter("@cInvCode", body.InvCode));
  857. cmd.Parameters.Add(new SqlParameter("@iQuantity", body.Quantity));
  858. cmd.Parameters.Add(new SqlParameter("@irowno", body.Sequence));
  859. cmd.Parameters.Add(new SqlParameter("@cBatch", body.BatchCode));
  860. cmd.Parameters.Add(new SqlParameter("@VenCode", head.VenCode));
  861. cmd.Parameters.Add(new SqlParameter("@cFree1", body.cFree1));
  862. cmd.Parameters.Add(new SqlParameter("@cFree2", body.cFree2));
  863. cmd.Parameters.Add(new SqlParameter("@cFree3", body.cFree3));
  864. cmd.Parameters.Add(new SqlParameter("@cFree4", body.cFree4));
  865. cmd.Parameters.Add(new SqlParameter("@cFree5", body.cFree5));
  866. cmd.Parameters.Add(new SqlParameter("@cFree6", body.cFree6));
  867. cmd.Parameters.Add(new SqlParameter("@cFree7", body.cFree7));
  868. cmd.Parameters.Add(new SqlParameter("@cFree8", body.cFree8));
  869. cmd.Parameters.Add(new SqlParameter("@cFree9", body.cFree9));
  870. cmd.Parameters.Add(new SqlParameter("@cFree10", body.cFree10));
  871. cmd.CommandText = sql;
  872. try
  873. {
  874. int count = cmd.ExecuteNonQuery();
  875. if (count <= 0)
  876. {
  877. log.Error("委外采购入库单表头失败,受影响行数<=0;");
  878. throw new Exception("委外采购入库单表头失败,受影响行数<=0;");
  879. }
  880. }
  881. catch (Exception ex)
  882. {
  883. log.Error("委外采购入库单表头失败!SQL:\r\n" + sql, ex);
  884. throw new Exception("委外采购入库单表头失败!SQL:\r\n" + sql, ex);
  885. }
  886. if (head.CompleteVerification)
  887. {
  888. #region 齐套检验
  889. sql = @" select cValue from AccInformation where cName=N'iMOProInCtrlBySet' ";
  890. DataTable qt = DBHelper.SQlReturnData(sql, cmd);
  891. if (qt != null && qt.Rows.Count > 0)
  892. {
  893. if (qt.Rows[0]["cValue"].ToString() == "1")
  894. {
  895. sql = @"select cCode,iVouchRowNo,MIN(lotqty) min_lotqty from
  896. (
  897. select
  898. a.cCode,b.iVouchRowNo,
  899. c.MOMaterialsID as AllocateId,sum(c.iQuantity) as Qty,SUM(c.iSendQTY) IssQty,SUM(c.iSendQTY)/(SUM(c.iQuantity)/b.iQuantity) lotqty
  900. from DBO.OM_MOMain a
  901. left join DBO.OM_MODetails b on a.moid = b.moid
  902. left join DBO.OM_MOMaterials c on b.MODetailsID = c.MODetailsID
  903. left join DBO.Inventory_Sub f on c.cInvCode=f.cInvSubCode
  904. where a.cCode='{0}' and b.iVouchRowNo='{1}'
  905. and c.iQuantity<>0
  906. group by a.cCode,b.iVouchRowNo,c.MOMaterialsID,b.iQuantity
  907. ) tt
  908. group by cCode,iVouchRowNo";
  909. sql = string.Format(sql, mocode, seq);
  910. qt = DBHelper.SQlReturnData(sql, cmd);
  911. if (qt == null || qt.Rows.Count == 0)
  912. {
  913. throw new Exception("该物料:" + body.InvCode + @"在订单内未领料!");
  914. }
  915. else
  916. {
  917. if (Convert.ToDecimal(qt.Rows[0]["min_lotqty"]) <= 0)
  918. {
  919. throw new Exception("该物料:" + body.InvCode + @"在订单内未领料<=0!");
  920. }
  921. }
  922. }
  923. else if (qt.Rows[0]["cValue"].ToString() == "2")
  924. {
  925. sql = @"select cValue from AccInformation where cName=N'bControlKeyMaterial'";
  926. qt = DBHelper.SQlReturnData(sql, cmd);
  927. if (qt != null && qt.Rows.Count > 0)
  928. {
  929. if (qt.Rows[0]["cValue"].ToString() == "true")
  930. {
  931. sql = @"select cCode,iVouchRowNo,MIN(lotqty) min_lotqty from
  932. (
  933. select
  934. a.cCode,b.iVouchRowNo,
  935. c.MOMaterialsID as AllocateId,sum(c.iQuantity) as Qty,SUM(c.iSendQTY) IssQty,SUM(c.iSendQTY)/(SUM(c.iQuantity)/b.iQuantity) lotqty
  936. from DBO.OM_MOMain a
  937. left join DBO.OM_MODetails b on a.moid = b.moid
  938. left join DBO.OM_MOMaterials c on b.MODetailsID = c.MODetailsID
  939. left join DBO.Inventory_Sub f on c.cInvCode=f.cInvSubCode
  940. where a.cCode='{0}' and b.iVouchRowNo='{1}'
  941. and c.iQuantity<>0
  942. group by a.cCode,b.iVouchRowNo,c.MOMaterialsID,b.iQuantity
  943. ) tt
  944. group by cCode,iVouchRowNo";
  945. sql = string.Format(sql, mocode, seq);
  946. qt = DBHelper.SQlReturnData(sql, cmd);
  947. if (qt == null || qt.Rows.Count == 0)
  948. {
  949. throw new Exception("该物料:" + body.InvCode + @"在订单内未有可用领料!");
  950. }
  951. else
  952. {
  953. if (Convert.ToDecimal(qt.Rows[0]["min_lotqty"]) <= 0)
  954. {
  955. throw new Exception("该物料:" + body.InvCode + @"在订单内未领料!");
  956. }
  957. else if (Convert.ToDecimal(qt.Rows[0]["min_lotqty"]) - body.Quantity <= 0)
  958. {
  959. throw new Exception("该物料:" + body.InvCode + @"入库数量大于关键物料领料套数!");
  960. }
  961. }
  962. }
  963. else
  964. {
  965. sql = @"select cCode,iVouchRowNo,MIN(lotqty) min_lotqty from
  966. (
  967. select
  968. a.cCode,b.iVouchRowNo,
  969. c.MOMaterialsID as AllocateId,sum(c.iQuantity) as Qty,SUM(c.iSendQTY) IssQty,SUM(c.iSendQTY)/(SUM(c.iQuantity)/b.iQuantity) lotqty
  970. from DBO.OM_MOMain a
  971. left join DBO.OM_MODetails b on a.moid = b.moid
  972. left join DBO.OM_MOMaterials c on b.MODetailsID = c.MODetailsID
  973. left join DBO.Inventory_Sub f on c.cInvCode=f.cInvSubCode
  974. where a.cCode='{0}' and b.iVouchRowNo='{1}'
  975. and c.iQuantity<>0
  976. group by a.cCode,b.iVouchRowNo,c.MOMaterialsID,b.iQuantity
  977. ) tt
  978. group by cCode,iVouchRowNo";
  979. sql = string.Format(sql, mocode, seq);
  980. qt = DBHelper.SQlReturnData(sql, cmd);
  981. if (qt == null || qt.Rows.Count == 0)
  982. {
  983. throw new Exception("该物料:" + body.InvCode + @"在订单内未有可用领料!");
  984. }
  985. else
  986. {
  987. if (Convert.ToDecimal(qt.Rows[0]["min_lotqty"]) <= 0)
  988. {
  989. throw new Exception("该物料:" + body.InvCode + @"在订单内未领料!");
  990. }
  991. else if (Convert.ToDecimal(qt.Rows[0]["min_lotqty"]) - body.Quantity <= 0)
  992. {
  993. throw new Exception("该物料:" + body.InvCode + @"入库数量大于领料套数!");
  994. }
  995. }
  996. }
  997. }
  998. }
  999. }
  1000. #endregion
  1001. }
  1002. if (head.UpdateStock)
  1003. {
  1004. //更新现存量
  1005. key.cBustypeUN = "委外加工";
  1006. key.cVouchTypeUN = "01";
  1007. key.TableName = "IA_ST_UnAccountVouch01";
  1008. //DBHelper.UpdateCurrentStock(cmd, body.InvCode, head.WHCode, "", body.Quantity, key);
  1009. 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);
  1010. }
  1011. //OM_MODetails
  1012. sql = @"UPDATE a SET freceivedqty=ISNULL(freceivedqty,0)+" + body.Quantity + @"
  1013. FROM dbo.OM_MODetails a
  1014. WHERE a.MODetailsID='" + body.OODetailID + "'";
  1015. DBHelper.CmdExecuteNonQuery(sql, cmd, "回写OM_MODetails失败!");
  1016. //更新待入库数量
  1017. sql = "UPDATE dbo.CurrentStock SET fInQuantity=ISNULL(fInQuantity,0)-" + body.Quantity + " WHERE cInvCode='" + body.InvCode + "' AND cWhCode ='" + head.WHCode + "'";
  1018. if (DBHelper.bInvBatch(body.InvCode, cmd) == true)
  1019. {
  1020. if (!string.IsNullOrWhiteSpace(body.BatchCode))
  1021. {
  1022. sql += " and cBatch='" + body.BatchCode + "'";
  1023. }
  1024. }
  1025. DBHelper.CmdExecuteNonQuery(sql, cmd, "更新待入库数量失败!");
  1026. num = body.detailss.Count();
  1027. Dictionary<string, int> dic2 = DBHelper.GetAllCode("" + ERPDB + "", surface1, "" + num + "", head.WorkPoint);
  1028. int iFatherId2 = Convert.ToInt32(dic2["iFatherId"].ToString());
  1029. int iChildId2 = Convert.ToInt32(dic2["iChildId"].ToString());
  1030. foreach (ICSOutsourcingReceiveDocss item in body.detailss)
  1031. {
  1032. irownnew++;
  1033. sql = @"INSERT INTO dbo.rdrecords11
  1034. ( AutoID,ID ,cInvCode,iQuantity ,cBatch ,
  1035. iFlag ,cItemCode ,cName ,iNQuantity ,iMPoIds ,
  1036. bLPUseFree ,iOriTrackID ,bCosting ,bVMIUsed ,cmocode ,
  1037. invcode ,imoseq ,iopseq ,iExpiratDateCalcu ,iorderdid ,
  1038. iordertype ,isotype ,ipesodid ,ipesotype ,cpesocode ,
  1039. ipesoseq ,irowno ,bcanreplace ,iposflag,iOMoDID,
  1040. iOMoMID,comcode,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10)
  1041. SELECT distinct
  1042. @AutoID,@ID,a.cInvCode,@iQuantity,@cBatch,
  1043. 0,null,null,@iQuantity,NULL,
  1044. 0,0,1,0,NULL,
  1045. b.cInvCode,NULL,NULL,0,0,
  1046. 0,0,a.MOMaterialsID,'6',c.cCode,
  1047. NULL, @irowno,0,NULL,b.MODetailsID,
  1048. a.MOMaterialsID,c.cCode,@cFree1,@cFree2,@cFree3,@cFree4,@cFree5,@cFree6,@cFree7,@cFree8,@cFree9,@cFree10
  1049. FROM dbo.OM_MOMaterials a
  1050. INNER JOIN dbo.OM_MODetails b ON a.MoDetailsID=b.MODetailsID
  1051. INNER JOIN dbo.OM_MOMain c ON b.MOID=c.MOID
  1052. WHERE a.MOMaterialsID='" + body.OODetailID + "'";
  1053. cmd.Parameters.Clear();
  1054. cmd.Parameters.Add(new SqlParameter("@AutoID", iChildId2));
  1055. cmd.Parameters.Add(new SqlParameter("@ID", out11));
  1056. cmd.Parameters.Add(new SqlParameter("@iQuantity", item.Quantity));
  1057. cmd.Parameters.Add(new SqlParameter("@cBatch", item.BatchCode));
  1058. cmd.Parameters.Add(new SqlParameter("@irowno", irownnew));
  1059. cmd.Parameters.Add(new SqlParameter("@cFree1", item.cFree1));
  1060. cmd.Parameters.Add(new SqlParameter("@cFree2", item.cFree2));
  1061. cmd.Parameters.Add(new SqlParameter("@cFree3", item.cFree3));
  1062. cmd.Parameters.Add(new SqlParameter("@cFree4", item.cFree4));
  1063. cmd.Parameters.Add(new SqlParameter("@cFree5", item.cFree5));
  1064. cmd.Parameters.Add(new SqlParameter("@cFree6", item.cFree6));
  1065. cmd.Parameters.Add(new SqlParameter("@cFree7", item.cFree7));
  1066. cmd.Parameters.Add(new SqlParameter("@cFree8", item.cFree8));
  1067. cmd.Parameters.Add(new SqlParameter("@cFree9", item.cFree9));
  1068. cmd.Parameters.Add(new SqlParameter("@cFree10", item.cFree10));
  1069. cmd.CommandText = sql;
  1070. try
  1071. {
  1072. int count = cmd.ExecuteNonQuery();
  1073. if (count <= 0)
  1074. {
  1075. log.Error("生成材料出库单表体失败,受影响行数<=0;");
  1076. throw new Exception("生成材料出库单表体失败,受影响行数<=0;");
  1077. }
  1078. }
  1079. catch (Exception ex)
  1080. {
  1081. log.Error("生成材料出库单表体失败" + sql, ex);
  1082. throw new Exception("生成材料出库单表体失败 " + sql, ex);
  1083. }
  1084. //更新现存量
  1085. key.cBustypeUN = "领料";
  1086. key.cVouchTypeUN = "11";
  1087. key.TableName = "IA_ST_UnAccountVouch11";
  1088. DBHelper.UpdateCurrentStockNEW(cmd, item.InvCode, head.WHCode, item.BatchCode, item.Quantity, item.cFree1, item.cFree2, item.cFree3, item.cFree4, item.cFree5, item.cFree6, item.cFree7, item.cFree8, item.cFree9, item.cFree10, key);
  1089. #region 回写工单子件已领数量
  1090. sql = "update mom_moallocate set IssQty=isnull(IssQty,0)+" + item.Quantity + ",RequisitionIssQty=isnull(RequisitionIssQty,0)+(" + item.Quantity + ") where AllocateId='" + item.OODetailID + "' ";
  1091. DBHelper.CmdExecuteNonQuery(sql, cmd, "回写工单子件已领数量失败!");
  1092. #endregion
  1093. iChildId2--;
  1094. }
  1095. iFatherIdTwo += "'" + iFatherId + "',";
  1096. iChildId--;
  1097. }
  1098. #endregion
  1099. #region 查询
  1100. sql = @" select a.ID as ID,a.ID as IDs,a.cCode as ORCVTCode ,a.cVenCode,d.cVenName,a.cOrderCode as OOCode,
  1101. a.cMaker as CreateUser,dnmaketime as CreateDateTime,cHandler as Checker,dnverifytime as CheckDateTime
  1102. from rdrecord01 a
  1103. left join Department c on a.cDepCode=c.cDepCode
  1104. left join Vendor d on a.cVenCode=d.cVenCode
  1105. where a.cBusType='' AND A.ID in ({0})
  1106. select a.ID as IDs,b.AutoID as DetailID,b.irowno as Sequence,b.cInvCode as InvCode,b.iQuantity as Quantity,iNum as Amount,b.iOMoDID as OODetailID
  1107. from rdrecord01 a
  1108. left join rdrecords01 b on a.ID=b.ID
  1109. left join Department c on a.cDepCode=c.cDepCode
  1110. left join Vendor d on a.cVenCode=d.cVenCode
  1111. where a.cBusType='' AND A.ID in ({0}) ";
  1112. sql = string.Format(sql, iFatherIdTwo.TrimEnd(','));
  1113. DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
  1114. if (dtNew1 == null)
  1115. dtNew1 = ds.Tables[0];
  1116. else
  1117. dtNew1.Merge(ds.Tables[0]);
  1118. if (dtNew2 == null)
  1119. dtNew2 = ds.Tables[1];
  1120. else
  1121. dtNew2.Merge(ds.Tables[1]);
  1122. #endregion
  1123. cmd.Transaction.Commit();
  1124. }
  1125. catch (Exception ex)
  1126. {
  1127. cmd.Transaction.Rollback();
  1128. log.Error(ex.Message);
  1129. throw new Exception(ex.Message);
  1130. }
  1131. finally
  1132. {
  1133. if (conn.State == ConnectionState.Open)
  1134. {
  1135. conn.Close();
  1136. }
  1137. conn.Dispose();
  1138. }
  1139. }
  1140. string RelationName = "details";
  1141. DataSet dz = new DataSet();
  1142. dtNew1.TableName = "Table0";
  1143. dtNew2.TableName = "Table1";
  1144. dz.Tables.Add(dtNew1.Copy());
  1145. dz.Tables.Add(dtNew2.Copy());
  1146. DataRelation dh = new DataRelation(RelationName, dz.Tables[0].Columns["IDs"], dz.Tables[1].Columns["IDs"]);
  1147. dz.Relations.Add(dh);
  1148. msg = DBHelper.DataSetToJson(dz, RelationName);
  1149. return msg;
  1150. }
  1151. /// <summary>
  1152. /// 审核委外采购入库
  1153. /// </summary>
  1154. /// <param name="infos"></param>
  1155. /// <returns></returns>
  1156. public string Approve(List<ICSOutsourcingReceiveDoc> infos)
  1157. {
  1158. List<ICSSalesShipmentDoc> szJson = new List<ICSSalesShipmentDoc>();
  1159. string json = "";
  1160. DataTable dtNew = null;
  1161. string connS = "";
  1162. if (infos.Count <= 0)
  1163. {
  1164. throw new Exception("传送数据为空!");
  1165. }
  1166. string res = string.Empty;
  1167. SqlConnection conn = new SqlConnection();
  1168. SqlCommand cmd = new SqlCommand();
  1169. string sql = string.Empty;
  1170. foreach (ICSOutsourcingReceiveDoc info in infos)
  1171. {
  1172. try
  1173. {
  1174. connS = string.Format(connString, info.WorkPoint);
  1175. conn = new System.Data.SqlClient.SqlConnection(connS);
  1176. conn.Open();
  1177. SqlTransaction sqlTran = conn.BeginTransaction();
  1178. cmd = new SqlCommand();
  1179. cmd.Transaction = sqlTran;
  1180. cmd.Connection = conn;
  1181. if (info.MTime < new DateTime(2000, 01, 01))
  1182. throw new Exception("请输入正确的操作时间:" + info.MTime);
  1183. sql = @"UPDATE RdRecord01 SET cHandler ='" + info.User + @"' ,
  1184. dnverifytime=CONVERT(VARCHAR(50),GETDATE(),112),dVeriDate=GETDATE() WHERE ID='{0}'";
  1185. sql = string.Format(sql, info.ID);
  1186. DBHelper.CmdExecuteNonQuery(sql, cmd, "审核委外采购入库单失败!");
  1187. cmd.Transaction.Commit();
  1188. }
  1189. catch (Exception ex)
  1190. {
  1191. cmd.Transaction.Rollback();
  1192. log.Error(ex.Message);
  1193. throw new Exception(ex.Message);
  1194. }
  1195. finally
  1196. {
  1197. if (conn.State == ConnectionState.Open)
  1198. {
  1199. conn.Close();
  1200. }
  1201. conn.Dispose();
  1202. }
  1203. }
  1204. return json;
  1205. }
  1206. /// <summary>
  1207. /// 删除委外采购入库单
  1208. /// </summary>
  1209. /// <param name="infos"></param>
  1210. /// <returns></returns>
  1211. public string Delete(List<ICSOutsourcingReceiveDoc> infos)
  1212. {
  1213. string connS = "";
  1214. List<ICSSalesShipmentDoc> szJson = new List<ICSSalesShipmentDoc>();
  1215. if (infos.Count <= 0)
  1216. {
  1217. throw new Exception("传送数据为空!");
  1218. }
  1219. string res = string.Empty;
  1220. SqlConnection conn = new SqlConnection();
  1221. SqlCommand cmd = new SqlCommand();
  1222. string sql = string.Empty;
  1223. foreach (ICSOutsourcingReceiveDoc info in infos)
  1224. {
  1225. try
  1226. {
  1227. connS = string.Format(connString, info.WorkPoint);
  1228. conn = new System.Data.SqlClient.SqlConnection(connS);
  1229. conn.Open();
  1230. SqlTransaction sqlTran = conn.BeginTransaction();
  1231. cmd = new SqlCommand();
  1232. cmd.Transaction = sqlTran;
  1233. cmd.Connection = conn;
  1234. if (info.MTime < new DateTime(2000, 01, 01))
  1235. throw new Exception("请输入正确的操作时间:" + info.MTime);
  1236. sql = @"delete RdRecord01 where RdRecord01.ID='" + info.ID + "'";
  1237. sql += @"delete RdRecords01 where RdRecords01.ID='" + info.ID + "'";
  1238. //UPDATE dbo.rdrecord11 a SET cHandler='" + info.User + @"' ,
  1239. // dVeriDate=CONVERT(VARCHAR(50),GETDATE(),112),dnverifytime=GETDATE()
  1240. // WHERE a.ID='" + info.ID + "'";
  1241. DBHelper.CmdExecuteNonQuery(sql, cmd, "删除委外采购入库单失败!");
  1242. cmd.Transaction.Commit();
  1243. }
  1244. catch (Exception ex)
  1245. {
  1246. cmd.Transaction.Rollback();
  1247. log.Error(ex.Message);
  1248. throw new Exception(ex.Message);
  1249. }
  1250. finally
  1251. {
  1252. if (conn.State == ConnectionState.Open)
  1253. {
  1254. conn.Close();
  1255. }
  1256. conn.Dispose();
  1257. }
  1258. }
  1259. return res;
  1260. }
  1261. /// <summary>
  1262. ///
  1263. /// 记录日志
  1264. /// </summary>
  1265. /// <param name="Bills"></param>
  1266. private void LogInfo(List<ICSOutsourcingReceiveDoc> Bills)
  1267. {
  1268. string HeadList = string.Empty;
  1269. string BodyList = string.Empty;
  1270. foreach (ICSOutsourcingReceiveDoc head in Bills)
  1271. {
  1272. HeadList += "\r\n 表头主键ID:" + head.ID + ",仓库:" + head.WHCode + ",用户:" + head.User + ",站点:" + head.WorkPoint;
  1273. foreach (ICSOutsourcingReceiveDocs body in head.details)
  1274. {
  1275. BodyList += "\r\n 表体主键ID: " + body.ODNDetailID + ",数量:" + body.Quantity;
  1276. }
  1277. }
  1278. log.Info(HeadList);
  1279. log.Info(BodyList);
  1280. }
  1281. public string GetSerialCode(string ID, string connS)
  1282. {
  1283. string sql = "EXEC Addins_GetSerialCode '{0}'";
  1284. sql = string.Format(sql, new object[] { ID });
  1285. return DBHelper.ExecuteScalar(CommandType.Text, sql, connS).ToString();
  1286. }
  1287. }
  1288. }