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

913 lines
53 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
2 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
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
2 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
2 years ago
2 years ago
2 years ago
2 years ago
2 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
  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 TransferDoc
  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["TransDCRDNAME"];
  23. /// <summary>
  24. /// 审核调拨单
  25. /// </summary>
  26. /// <param name="Bills"></param>
  27. /// <returns></returns>
  28. public bool ConfirmTrans(List<ICSTransferDoc> Bills)
  29. {
  30. bool ResultFlag = false;
  31. string connS = "";
  32. //int num = 0;
  33. SqlConnection conn = new SqlConnection();
  34. SqlCommand cmd = new SqlCommand();
  35. if (Bills.Count <= 0)
  36. {
  37. throw new Exception("传送数据为空!");
  38. }
  39. LogInfo(Bills);
  40. //MergeObject(Bills, cmd);
  41. foreach (ICSTransferDoc head in Bills)
  42. {
  43. try
  44. {
  45. connS = string.Format(connString, head.WorkPoint);
  46. conn = new System.Data.SqlClient.SqlConnection(connS);
  47. conn.Open();
  48. SqlTransaction sqlTran = conn.BeginTransaction();
  49. cmd = new SqlCommand();
  50. cmd.Transaction = sqlTran;
  51. cmd.Connection = conn;
  52. if (DBHelper.IsInventoryConsolidation(cmd, head.WorkPoint))
  53. {
  54. }
  55. else
  56. {
  57. throw new Exception("U8正在整理现存量,请稍后再试");
  58. }
  59. string[] ss = head.WorkPoint.Split('_');
  60. ERPDB = ss[1];
  61. string sql = "";
  62. ICSUserInfo userInfo = new ICSUserInfo();
  63. userInfo = DBHelper.GetPersonInfo(head.User, cmd);
  64. string cIWhCode = string.Empty;
  65. string cOWhCode = string.Empty;
  66. #region 检查
  67. sql = "select * from dbo.TransVouch where ID='" + head.ID + "';";
  68. DataTable dtCheck = DBHelper.SQlReturnData(sql, cmd);
  69. if (dtCheck != null && dtCheck.Rows.Count > 0)
  70. {
  71. string cHandler = dtCheck.Rows[0]["cVerifyPerson"].ToString();
  72. if (!string.IsNullOrEmpty(cHandler))
  73. {
  74. throw new Exception("调拨单ID:" + head.ID + "不是开立状态!");
  75. }
  76. cIWhCode = dtCheck.Rows[0]["cIWhCode"].ToString();
  77. cOWhCode = dtCheck.Rows[0]["cOWhCode"].ToString();
  78. sql = string.Format("select * from Warehouse where cWhCode in ('{0}','{1}')", dtCheck.Rows[0]["cOWhCode"].ToString(), dtCheck.Rows[0]["cIWhCode"].ToString());
  79. DataTable dtWh = DBHelper.SQlReturnData(sql, cmd);
  80. if (dtWh != null && dtWh.Rows.Count > 1)
  81. {
  82. }
  83. else
  84. {
  85. throw new Exception("调拨单中转入或者转出仓库不存在!");
  86. }
  87. }
  88. else
  89. {
  90. throw new Exception("调拨单ID:" + head.ID + "在U8中不存在!");
  91. }
  92. #endregion
  93. #region 审核
  94. sql = "UPDATE dbo.TransVouch SET cVerifyPerson='" + userInfo.UserName + "' ,dVerifyDate=CONVERT(VARCHAR(50),GETDATE(),112),dnverifytime=GETDATE() WHERE ID='" + head.ID + "'";
  95. cmd.CommandText = sql;
  96. try
  97. {
  98. cmd.ExecuteNonQuery();
  99. }
  100. catch (Exception ex)
  101. {
  102. log.Error("审核调拨单失败!异常:" + ex.Message + ";\r\n SQL:" + sql);
  103. throw new Exception("程序异常,请联系开发人员!");
  104. }
  105. int bodyID = 0;
  106. // foreach (ICSTransferDoc body in Bills)
  107. // {
  108. // //回写调出仓库待发数量
  109. // string fOutcBatch = string.Empty;
  110. // //bodyID = Convert.ToInt32(body);
  111. // sql = @"UPDATE a SET fTransOutQuantity=ISNULL(a.fTransOutQuantity,0)-ISNULL(a.iQuantity,0)
  112. // FROM dbo.CurrentStock a
  113. // LEFT JOIN (SELECT a.cOWhCode,a.cIWhCode,b.cInvCode,b.autoID,
  114. // ISNULL(b.cTVBatch,'') AS cTVBatch FROM dbo.TransVouch a
  115. // INNER JOIN dbo.TransVouchs b ON a.cTVCode = b.cTVCode)b
  116. // ON a.cInvCode=b.cInvCode AND a.cBatch=b.cTVBatch and a.cWhCode=b.cOWhCode WHERE b.autoID=@bodyID";
  117. // cmd.Parameters.Clear();
  118. // //cmd.Parameters.Add(new SqlParameter("@Qty", dtCheck.Rows[0]["iQuantity"].ToString()));
  119. // cmd.Parameters.Add(new SqlParameter("@bodyID",body.ID));
  120. // cmd.CommandText = sql;
  121. // try
  122. // {
  123. // cmd.ExecuteNonQuery();
  124. // }
  125. // catch (Exception ex)
  126. // {
  127. // log.Error("回写现存量表 待调拨数量!异常:" + ex.Message + ";\r\n SQL:" + sql);
  128. // throw new Exception("程序异常,请联系开发人员!");
  129. // }
  130. //// #region 判断现存量是否足够
  131. //// sql = @"IF EXISTS(SELECT AutoID FROM dbo.CurrentStock WHERE iQuantity<0 OR iNum<0 OR fTransOutQuantity<0)
  132. //// BEGIN
  133. //// DECLARE @MSG NVARCHAR(100)
  134. //// SELECT @MSG='ERP待调拨出库数量不足!AutoID:'+CAST(AutoID AS NVARCHAR(100)) FROM dbo.CurrentStock WHERE iQuantity<0 OR iNum<0 OR fTransOutQuantity<0
  135. //// RAISERROR(@MSG,16,1)
  136. //// END";
  137. //// cmd.CommandText = sql;
  138. //// cmd.ExecuteNonQuery();
  139. //// #endregion
  140. // //回写调入仓库在途数量
  141. // fOutcBatch = string.Empty;
  142. // sql = @"UPDATE a SET fTransInQuantity=ISNULL(fTransInQuantity,0)-ISNULL(a.iQuantity,0)
  143. // FROM dbo.CurrentStock a
  144. // LEFT JOIN (SELECT a.cOWhCode,a.cIWhCode,b.cInvCode,b.autoID,
  145. // ISNULL(b.cTVBatch,'') AS cTVBatch FROM dbo.TransVouch a
  146. // INNER JOIN dbo.TransVouchs b ON a.cTVCode = b.cTVCode)b
  147. // ON a.cInvCode=b.cInvCode AND a.cBatch=b.cTVBatch and a.cWhCode=b.cIWhCode WHERE b.autoID=@bodyID";
  148. // cmd.Parameters.Clear();
  149. // //cmd.Parameters.Add(new SqlParameter("@Qty", dtCheck.Rows[0]["iQuantity"].ToString()));
  150. // cmd.Parameters.Add(new SqlParameter("@bodyID", body.ID));
  151. // cmd.CommandText = sql;
  152. // try
  153. // {
  154. // cmd.ExecuteNonQuery();
  155. // }
  156. // catch (Exception ex)
  157. // {
  158. // log.Error("回写现存量表在途数量!异常:" + ex.Message + ";\r\n SQL:" + sql);
  159. // throw new Exception("程序异常,请联系开发人员!");
  160. // }
  161. //// #region 判断现存量是否足够
  162. //// sql = @"IF EXISTS(SELECT AutoID FROM dbo.CurrentStock WHERE iQuantity<0 OR iNum<0 OR fTransInQuantity<0)
  163. //// BEGIN
  164. //// DECLARE @MSG NVARCHAR(100)
  165. //// SELECT @MSG='ERP待调拨入库数量不足!AutoID:'+CAST(AutoID AS NVARCHAR(100)) FROM dbo.CurrentStock WHERE iQuantity<0 OR iNum<0 OR fTransInQuantity<0
  166. //// RAISERROR(@MSG,16,1)
  167. //// END";
  168. //// cmd.CommandText = sql;
  169. //// cmd.ExecuteNonQuery();
  170. //// #endregion
  171. // }
  172. #endregion
  173. //0305 形态转换单CartonNum
  174. sql = "select * from dbo.TransVouchs where ID='" + head.ID + "';";
  175. DataTable dtChecks = DBHelper.SQlReturnData(sql, cmd);
  176. #region 其他入库单
  177. //取得out库单的默认显示模版
  178. string[] dd = CRNALL.Split('~');
  179. string crdname = dd[2];
  180. string crdname1 = dd[3];
  181. string carname = dd[4];
  182. string carname1 = dd[5];
  183. string surface = dd[6];
  184. string cardnewcode = DBHelper.GetCardNumber(carname, cmd);
  185. string cardnewcode1 = DBHelper.GetCardNumber(carname1, cmd);
  186. VouchKey key08 = new VouchKey();
  187. //key08 = U8Helper.GetPrimaryKey("rd", ErpName, 1, cmd);
  188. //// 取得表头单据号
  189. //string Code08 = U8Helper.GetRdrecord08Code(ErpName, "QR", cmd);
  190. var num = dtChecks.Rows.Count;
  191. Dictionary<string, int> dic = DBHelper.GetAllCode("" + ERPDB + "", surface, "" + num + "", head.WorkPoint);
  192. int iFatherId = Convert.ToInt32(dic["iFatherId"].ToString());
  193. int iChildId = Convert.ToInt32(dic["iChildId"].ToString());
  194. DateTime date = DateTime.Now;
  195. string iBaseCodeLen = DBHelper.GetAllRDCode(cardnewcode1, "" + date + "", "admin", head.WorkPoint);
  196. string cRDcode08 = DBHelper.GetRDCode(crdname1, cmd);
  197. string DEF_ID08 = DBHelper.GetDefaultTemplate(cardnewcode1, cmd);
  198. #region 其他入库单表头
  199. sql = @"INSERT INTO dbo.RdRecord08
  200. (ID,bRdFlag,cVouchType,cBusType,cSource,cBusCode,cWhCode,dDate,cCode,cRdCode,
  201. cHandler,cMemo,bTransFlag,cMaker,dVeriDate,bpufirst,biafirst,VT_ID,bIsSTQc,bOMFirst,
  202. bFromPreYear,bIsComplement,iDiscountTaxType,ireturncount,
  203. iverifystate,iswfcontrolled,dnmaketime,dnverifytime,bredvouch,cSourceLs,cDepCode)
  204. SELECT @ID,'1','08','','',a.cTVCode,cIWhCode,CONVERT(NVARCHAR(15),GETDATE(),23),a.cTVCode,@cRdCode,
  205. @cHandler,@cMemo,'0',@cMaker,CONVERT(NVARCHAR(15),GETDATE(),23),'0','0',
  206. @VT_ID,'0','0','0','0','0','0','0','0',GETDATE(),GETDATE(),'0','1',cIDepCode from dbo.TransVouch a WHERE ID='" + head.ID + "' ";
  207. cmd.Parameters.Clear();
  208. cmd.Parameters.Add(new SqlParameter("@ID", iFatherId));
  209. //cmd.Parameters.Add(new SqlParameter("@cBusCode", head.ID));
  210. cmd.Parameters.Add(new SqlParameter("@cCode", iBaseCodeLen));
  211. cmd.Parameters.Add(new SqlParameter("@cHandler", userInfo.UserName));
  212. cmd.Parameters.Add(new SqlParameter("@cMemo", ""));
  213. cmd.Parameters.Add(new SqlParameter("@cMaker", userInfo.UserName));
  214. cmd.Parameters.Add(new SqlParameter("@VT_ID", DEF_ID08));
  215. cmd.Parameters.Add(new SqlParameter("@cRdCode", cRDcode08));
  216. cmd.CommandText = sql;
  217. try
  218. {
  219. cmd.ExecuteNonQuery();
  220. }
  221. catch (Exception ex)
  222. {
  223. log.Error("生成其他入库单表头失败!调拨单ID:" + head.ID + ";异常:" + ex.Message + ";SQL:\r\n" + sql);
  224. throw new Exception("程序异常,请联系开发人员!");
  225. }
  226. #endregion
  227. #region 3.5 其他入库单表体
  228. for (int i = 0; i < dtChecks.Rows.Count; i++)
  229. {
  230. #region 3.5.1 表体
  231. sql = @"INSERT INTO dbo.rdrecords08
  232. (AutoID,ID,cInvCode,iQuantity,iSOutQuantity,iSOutNum,iFlag,iTrIds,iNQuantity,iNum,
  233. cMassUnit,bLPUseFree,iRSRowNO,iOriTrackID,bCosting,bVMIUsed,iExpiratDateCalcu,iordertype,irowno,cbaccounter,cBatch,iPUnitCost,iPPrice,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10)
  234. SELECT @AutoID,@ID,cInvCode,a.iTVQuantity,'0','0','0',a.AutoID,iTVQuantity,iTVNum,
  235. '0','0','0','0','1','0','0','0',@irowno,null,cTVBatch,iTVPCost,iTVPPrice ,a.cFree1,a.cFree2,a.cFree3,a.cFree4,a.cFree5,a.cFree6,a.cFree7,a.cFree8,a.cFree9,a.cFree10
  236. from TransVouchs a
  237. inner join TransVouch b on a.ID=b.ID
  238. where a.autoid='" + dtChecks.Rows[i]["AutoID"].ToString() + @"';";
  239. cmd.Parameters.Clear();
  240. cmd.Parameters.Add(new SqlParameter("@AutoID", iChildId));
  241. cmd.Parameters.Add(new SqlParameter("@ID", iFatherId));
  242. //cmd.Parameters.Add(new SqlParameter("@iQuantity", dtCheck.Rows[0]["iQuantity"].ToString()));
  243. //cmd.Parameters.Add(new SqlParameter("@iTrIds", body.AutoID));
  244. cmd.Parameters.Add(new SqlParameter("@irowno", dtChecks.Rows[i]["irowno"].ToString()));
  245. cmd.CommandText = sql;
  246. try
  247. {
  248. cmd.ExecuteNonQuery();
  249. }
  250. catch (Exception ex)
  251. {
  252. log.Error("生成其他出库单表体失败!调拨单ID:" + head.ID + ";异常:" + ex.Message + ";SQL:\r\n" + sql);
  253. throw new Exception("程序异常,请联系开发人员!");
  254. }
  255. #endregion
  256. //更新现存量
  257. key08.cBustypeUN = "调拨入库";
  258. key08.cVouchTypeUN = "08";
  259. key08.TableName = "IA_ST_UnAccountVouch08";
  260. key08.UpdateTodoQuantity = head.UpdateTodoQuantity;
  261. DBHelper.UpdateCurrentStockNEW(cmd, dtChecks.Rows[i]["cInvCode"].ToString(), cIWhCode, dtChecks.Rows[i]["cTVBatch"].ToString(), Convert.ToDecimal(dtChecks.Rows[i]["iTVQuantity"].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(), key08);
  262. //DBHelper.UpdateCurrentStock(cmd, dtChecks.Rows[i]["cInvCode"].ToString(), cIWhCode, "", Convert.ToDecimal(dtChecks.Rows[i]["iTVQuantity"].ToString()), key08);
  263. iChildId--;
  264. }
  265. #endregion
  266. #endregion
  267. #region 其他出库单
  268. //取得采购入库单单据 表头ID,表体DID
  269. VouchKey key09 = new VouchKey();
  270. //key09 = U8Helper.GetPrimaryKey("rd", ErpName, 1, cmd);
  271. //// 取得表头单据号
  272. //string Code09 = U8Helper.GetRdrecord09Code(ErpName, "QC", cmd);
  273. var nums = dtChecks.Rows.Count;
  274. Dictionary<string, int> dics = DBHelper.GetAllCode("" + ERPDB + "", surface, "" + nums + "", head.WorkPoint);
  275. int iFatherIds = Convert.ToInt32(dics["iFatherId"].ToString());
  276. int iChildIds = Convert.ToInt32(dics["iChildId"].ToString());
  277. DateTime dates = DateTime.Now;
  278. string iBaseCodeLens = DBHelper.GetAllRDCode(cardnewcode, "" + date + "", "admin", head.WorkPoint);
  279. string cRDcode09 = DBHelper.GetRDCode(crdname, cmd);
  280. string DEF_ID09 = DBHelper.GetDefaultTemplate(cardnewcode, cmd);
  281. #region 其他出库单表头
  282. sql = @"INSERT INTO dbo.RdRecord09
  283. (ID,bRdFlag,cVouchType,cBusType,cSource,cBusCode,cWhCode,dDate,cCode,cRdCode,
  284. cHandler,cMemo,bTransFlag,cMaker,dVeriDate,bpufirst,biafirst,VT_ID,bIsSTQc,bOMFirst,
  285. bFromPreYear,bIsComplement,iDiscountTaxType,ireturncount,
  286. iverifystate,iswfcontrolled,dnmaketime,dnverifytime,bredvouch,cSourceLs,cDepCode)
  287. SELECT @ID,'0','09','','',a.cTVCode,cOWhCode,CONVERT(NVARCHAR(15),GETDATE(),23),@cCode,@cRdCode,
  288. @cHandler,@cMemo,'0',@cMaker,CONVERT(NVARCHAR(15),GETDATE(),23),'0','0',
  289. '85','0','0','0','0','0','0','0','0',GETDATE(),GETDATE(),'0','1',cODepCode from dbo.TransVouch a WHERE ID='" + head.ID + "' ";
  290. cmd.Parameters.Clear();
  291. cmd.Parameters.Add(new SqlParameter("@ID", iFatherIds));
  292. //cmd.Parameters.Add(new SqlParameter("@cBusCode", dtCheck.Rows[0]["cTVCode"].ToString()));
  293. //cmd.Parameters.Add(new SqlParameter("@cWhCode", cOWhCode));
  294. cmd.Parameters.Add(new SqlParameter("@cCode", iBaseCodeLens));
  295. cmd.Parameters.Add(new SqlParameter("@cHandler", userInfo.UserName));
  296. cmd.Parameters.Add(new SqlParameter("@cMemo", ""));
  297. cmd.Parameters.Add(new SqlParameter("@cMaker", userInfo.UserName));
  298. cmd.Parameters.Add(new SqlParameter("@VT_ID", DEF_ID09));
  299. cmd.Parameters.Add(new SqlParameter("@cRdCode", cRDcode09));
  300. cmd.CommandText = sql;
  301. try
  302. {
  303. cmd.ExecuteNonQuery();
  304. }
  305. catch (Exception ex)
  306. {
  307. log.Error("生成其他出库单失败!调拨单ID:" + head.ID + ";异常:" + ex.Message + ";SQL:\r\n" + sql);
  308. throw new Exception("程序异常,请联系开发人员!");
  309. }
  310. #endregion
  311. #region 3.5 其他出库单表体
  312. for (int i = 0; i < dtChecks.Rows.Count; i++)
  313. {
  314. #region 3.5.1 表体
  315. //判断物料批号与现存量表批号是否一致、数量不能超过现存量物料数量
  316. //sql = @"SELECT cBatch,iQuantity from CurrentStock WHERE cInvCode='" + dtCheck.Rows[0]["cInvCode"].ToString() + "'AND cWhCode='" + dtCheck.Rows[0]["cOWhCode"].ToString() + "'";
  317. //DataTable dtItem = DBHelper.SQlReturnData(sql, cmd);
  318. //if (dtItem != null && dtItem.Rows.Count > 0)
  319. //{
  320. // if (!dtItem.Rows[0]["cBatch"].ToString().Equals(body.cTVBatch))
  321. // {
  322. // throw new Exception("物料条码的批号与U8现存量物料批号不一致,物料:" + body.cInvCode);
  323. // }
  324. // if (Convert.ToDecimal(dtItem.Rows[0]["iQuantity"].ToString()) < body.iQuantity)
  325. // {
  326. // throw new Exception("物料条码的数量大于U8现存量物料数量,物料:" + body.cInvCode);
  327. // }
  328. //}
  329. //else
  330. //{
  331. // throw new Exception("物料:" + body.cInvCode + "在现存量表中不存在!");
  332. //}
  333. //key09.DID += 1;
  334. //Rd09irowno += 1;
  335. sql = @"INSERT INTO dbo.rdrecords09
  336. (AutoID,ID,cInvCode,iQuantity,iSOutQuantity,iSOutNum,iFlag,iTrIds,iNQuantity,iNum,
  337. cMassUnit,bLPUseFree,iRSRowNO,iOriTrackID,bCosting,bVMIUsed,iExpiratDateCalcu,iordertype,irowno,cbaccounter,cBatch,iPUnitCost,iPPrice,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10)
  338. SELECT @AutoID,@ID,cInvCode,a.iTVQuantity,'0','0','0',a.AutoID,iTVQuantity,iTVNum,
  339. '0','0','0','0','1','0','0','0',a.irowno,null,cTVBatch,iTVPCost,iTVPPrice ,a.cFree1,a.cFree2,a.cFree3,a.cFree4,a.cFree5,a.cFree6,a.cFree7,a.cFree8,a.cFree9,a.cFree10
  340. from TransVouchs a
  341. inner join TransVouch b on a.ID=b.ID
  342. where a.autoid='" + dtChecks.Rows[i]["AutoID"].ToString() + @"' ;";
  343. cmd.Parameters.Clear();
  344. cmd.Parameters.Add(new SqlParameter("@AutoID", iChildIds));
  345. cmd.Parameters.Add(new SqlParameter("@ID", iFatherIds));
  346. //cmd.Parameters.Add(new SqlParameter("@iQuantity", dtCheck.Rows[0]["iQuantity"].ToString()));
  347. //cmd.Parameters.Add(new SqlParameter("@iTrIds", body.AutoID));
  348. //cmd.Parameters.Add(new SqlParameter("@irowno", Rd09irowno));
  349. cmd.CommandText = sql;
  350. try
  351. {
  352. cmd.ExecuteNonQuery();
  353. }
  354. catch (Exception ex)
  355. {
  356. log.Error("生成其他出库单表体失败!调拨单ID:" + head.ID + ";异常:" + ex.Message + ";SQL:\r\n" + sql);
  357. throw new Exception("程序异常,请联系开发人员!");
  358. }
  359. sql = @"INSERT INTO dbo.rdrecords09sub
  360. ( AutoID , ID ,iBG_Ctrl , iBGSTSum )
  361. values('" + iChildIds + "','" + iFatherIds + "',0,0)";
  362. cmd.CommandText = sql;
  363. cmd.ExecuteNonQuery();
  364. #endregion
  365. if (head.UpdateStock)
  366. {
  367. //更新现存量
  368. key09.cBustypeUN = "调拨出库";
  369. key09.cVouchTypeUN = "09";
  370. key09.TableName = "IA_ST_UnAccountVouch09";
  371. //DBHelper.UpdateCurrentStock(cmd, dtChecks.Rows[i]["cInvCode"].ToString(), cOWhCode, "", -Convert.ToDecimal(dtChecks.Rows[i]["iTVQuantity"].ToString()), key09);
  372. DBHelper.UpdateCurrentStockNEW(cmd, dtChecks.Rows[i]["cInvCode"].ToString(), cOWhCode, dtChecks.Rows[i]["cTVBatch"].ToString(), -Convert.ToDecimal(dtChecks.Rows[i]["iTVQuantity"].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(), key09);
  373. }
  374. iChildIds--;
  375. }
  376. #endregion
  377. #endregion
  378. cmd.Transaction.Commit();
  379. }
  380. catch (Exception ex)
  381. {
  382. cmd.Transaction.Rollback();
  383. log.Error(ex.Message);
  384. throw new Exception(ex.Message);
  385. }
  386. finally
  387. {
  388. if (conn.State == ConnectionState.Open)
  389. {
  390. conn.Close();
  391. }
  392. conn.Dispose();
  393. }
  394. }
  395. ResultFlag = true;
  396. return ResultFlag;
  397. }
  398. /// <summary>
  399. /// 生成调拨单
  400. /// </summary>
  401. /// <param name="Bills"></param>
  402. /// <returns></returns>
  403. public bool ConfirmTransIN(List<ICSTransfer> Bills)
  404. {
  405. bool ResultFlag = false;
  406. string connS = "";
  407. SqlConnection conn = new SqlConnection();
  408. SqlCommand cmd = new SqlCommand();
  409. if (Bills.Count <= 0)
  410. {
  411. throw new Exception("传送数据为空!");
  412. }
  413. LogInfo1(Bills);
  414. //MergeObject(Bills, cmd);
  415. foreach (ICSTransfer head in Bills)
  416. {
  417. try
  418. {
  419. connS = string.Format(connString, head.WorkPoint);
  420. conn = new System.Data.SqlClient.SqlConnection(connS);
  421. conn.Open();
  422. SqlTransaction sqlTran = conn.BeginTransaction();
  423. cmd = new SqlCommand();
  424. cmd.Transaction = sqlTran;
  425. cmd.Connection = conn;
  426. if (DBHelper.IsInventoryConsolidation(cmd, head.WorkPoint))
  427. {
  428. }
  429. else
  430. {
  431. throw new Exception("U8正在整理现存量,请稍后再试");
  432. }
  433. string[] ss = head.WorkPoint.Split('_');
  434. ERPDB = ss[1];
  435. string[] dd = CRNALL.Split('~');
  436. string crdname = dd[2];
  437. string crdname1 = dd[3];
  438. string carname = dd[4];
  439. string carname1 = dd[5];
  440. string surface = dd[6];
  441. string carname2 = dd[0];
  442. string surface1 = dd[1];
  443. string cardnewcode = DBHelper.GetCardNumber(carname, cmd);
  444. string cardnewcode1 = DBHelper.GetCardNumber(carname1, cmd);
  445. string cardnewcode2 = DBHelper.GetCardNumber(carname2, cmd);
  446. int num = 0;
  447. foreach (ICSTransfer nu in Bills)
  448. {
  449. num = head.details.Count();
  450. }
  451. string sql = "";
  452. ICSUserInfo userInfo = new ICSUserInfo();
  453. userInfo = DBHelper.GetPersonInfo(head.User, cmd);
  454. string cIWhCode = string.Empty;
  455. string cOWhCode = string.Empty;
  456. #region 调拨单
  457. Dictionary<string, int> dic1 = DBHelper.GetAllCode("" + ERPDB + "", surface1, "" + num + "", head.WorkPoint);
  458. int iFather = Convert.ToInt32(dic1["iFatherId"].ToString());
  459. int iChild = Convert.ToInt32(dic1["iChildId"].ToString());
  460. DateTime date = DateTime.Now;
  461. string iBaseCode = DBHelper.GetAllRDCode(cardnewcode2, "" + date + "", "admin", head.WorkPoint);
  462. string cRDcode2 = DBHelper.GetRDCode(crdname, cmd);
  463. string cRDcode1 = DBHelper.GetRDCode(crdname1, cmd);
  464. string DEF_ID = DBHelper.GetDefaultTemplate(cardnewcode2, cmd);
  465. sql = @"INSERT INTO dbo.TransVouch
  466. (cTVCode,dTVDate,cOWhCode,cIWhCode,cODepCode,cIDepCode,cIRdCode,cORdCode,cMaker,ID
  467. ,VT_ID,itransflag,dnmaketime
  468. ,iswfcontrolled,iPrintCount)
  469. SELECT @cTVCode,CONVERT(NVARCHAR(15),GETDATE(),23),@cOWhCode,@cIWhCode,null,null,@cIRdCode,@cORdCode,@cMaker,@ID
  470. ,@VT_ID,'',GETDATE()
  471. ,0,0 ";
  472. cmd.Parameters.Clear();
  473. cmd.Parameters.Add(new SqlParameter("@ID", iFather));
  474. cmd.Parameters.Add(new SqlParameter("@cTVCode", iBaseCode));
  475. cmd.Parameters.Add(new SqlParameter("@cMaker", userInfo.UserName));
  476. cmd.Parameters.Add(new SqlParameter("@VT_ID", DEF_ID));
  477. cmd.Parameters.Add(new SqlParameter("@cIRdCode", cRDcode1));
  478. cmd.Parameters.Add(new SqlParameter("@cORdCode", cRDcode2));
  479. cmd.Parameters.Add(new SqlParameter("@cOWhCode", head.FromWHCode));
  480. cmd.Parameters.Add(new SqlParameter("@cIWhCode", head.ToWHCode));
  481. //cmd.Parameters.Add(new SqlParameter("@cODepCode", head.FromDepCode));
  482. //cmd.Parameters.Add(new SqlParameter("@cIDepCode", head.ToDepCode));
  483. cmd.CommandText = sql;
  484. try
  485. {
  486. cmd.ExecuteNonQuery();
  487. }
  488. catch (Exception ex)
  489. {
  490. log.Error("生成调拨单表头失败!调拨单:" + iBaseCode + ";异常:" + ex.Message + ";SQL:\r\n" + sql);
  491. throw new Exception("程序异常,请联系开发人员!");
  492. }
  493. foreach (ICSTransfers body in head.details)
  494. {
  495. sql = @" INSERT INTO dbo.TransVouchs
  496. (cTVCode,cInvCode,iTVNum,iTVQuantity,cTVBatch,autoID,ID,bCosting
  497. ,iExpiratDateCalcu,irowno,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10)
  498. SELECT @cTVCode,@cInvCode,@iTVNum,@iTVQuantity,@cTVBatch,@autoID,@ID,1
  499. ,0,@irowno,@cFree1,@cFree2,@cFree3,@cFree4,@cFree5,@cFree6,@cFree7,@cFree8,@cFree9,@cFree10";
  500. cmd.Parameters.Clear();
  501. cmd.Parameters.Add(new SqlParameter("@ID", iFather));
  502. cmd.Parameters.Add(new SqlParameter("@cTVCode", iBaseCode));
  503. cmd.Parameters.Add(new SqlParameter("@autoID", iChild));
  504. cmd.Parameters.Add(new SqlParameter("@cInvCode", body.InvCode));
  505. cmd.Parameters.Add(new SqlParameter("@iTVNum", body.Amount));
  506. cmd.Parameters.Add(new SqlParameter("@iTVQuantity", body.Quantity));
  507. cmd.Parameters.Add(new SqlParameter("@irowno", body.Sequence));
  508. cmd.Parameters.Add(new SqlParameter("@cTVBatch", body.BatchCode));
  509. cmd.Parameters.Add(new SqlParameter("@cFree1", body.cFree1));
  510. cmd.Parameters.Add(new SqlParameter("@cFree2", body.cFree2));
  511. cmd.Parameters.Add(new SqlParameter("@cFree3", body.cFree3));
  512. cmd.Parameters.Add(new SqlParameter("@cFree4", body.cFree4));
  513. cmd.Parameters.Add(new SqlParameter("@cFree5", body.cFree5));
  514. cmd.Parameters.Add(new SqlParameter("@cFree6", body.cFree6));
  515. cmd.Parameters.Add(new SqlParameter("@cFree7", body.cFree7));
  516. cmd.Parameters.Add(new SqlParameter("@cFree8", body.cFree8));
  517. cmd.Parameters.Add(new SqlParameter("@cFree9", body.cFree9));
  518. cmd.Parameters.Add(new SqlParameter("@cFree10", body.cFree10));
  519. cmd.CommandText = sql;
  520. iChild--;
  521. try
  522. {
  523. cmd.ExecuteNonQuery();
  524. }
  525. catch (Exception ex)
  526. {
  527. log.Error("生成调拨单子表失败!调拨单:" + iBaseCode + ",行:"+body.Sequence+";异常:" + ex.Message + ";SQL:\r\n" + sql);
  528. throw new Exception("程序异常,请联系开发人员!");
  529. }
  530. }
  531. #endregion
  532. #region 检查
  533. sql = "select * from dbo.TransVouch where ID='" + iFather + "';";
  534. DataTable dtCheck = DBHelper.SQlReturnData(sql, cmd);
  535. if (dtCheck != null && dtCheck.Rows.Count > 0)
  536. {
  537. string cHandler = dtCheck.Rows[0]["cVerifyPerson"].ToString();
  538. if (!string.IsNullOrEmpty(cHandler))
  539. {
  540. throw new Exception("调拨单:" + iBaseCode + "不是开立状态!");
  541. }
  542. cIWhCode = dtCheck.Rows[0]["cIWhCode"].ToString();
  543. cOWhCode = dtCheck.Rows[0]["cOWhCode"].ToString();
  544. sql = string.Format("select * from Warehouse where cWhCode in ('{0}','{1}')", dtCheck.Rows[0]["cOWhCode"].ToString(), dtCheck.Rows[0]["cIWhCode"].ToString());
  545. DataTable dtWh = DBHelper.SQlReturnData(sql, cmd);
  546. if (dtWh != null && dtWh.Rows.Count > 1)
  547. {
  548. }
  549. else
  550. {
  551. throw new Exception("调拨单中转入或者转出仓库不存在!");
  552. }
  553. }
  554. else
  555. {
  556. throw new Exception("调拨单:" + iBaseCode + "在U8中不存在!");
  557. }
  558. #endregion
  559. #region 审核
  560. sql = "UPDATE dbo.TransVouch SET cVerifyPerson='" + userInfo.UserName + "' ,dVerifyDate=CONVERT(VARCHAR(50),GETDATE(),112),dnverifytime=GETDATE() WHERE cTVCode='" + iBaseCode + "'";
  561. cmd.CommandText = sql;
  562. try
  563. {
  564. cmd.ExecuteNonQuery();
  565. }
  566. catch (Exception ex)
  567. {
  568. log.Error("审核调拨单失败!异常:" + ex.Message + ";\r\n SQL:" + sql);
  569. throw new Exception("程序异常,请联系开发人员!");
  570. }
  571. int bodyID = 0;
  572. #endregion
  573. sql = "select * from dbo.TransVouchs where ID='" + iFather + "';";
  574. DataTable dtChecks = DBHelper.SQlReturnData(sql, cmd);
  575. #region 其他入库单
  576. //取得out库单的默认显示模版
  577. VouchKey key08 = new VouchKey();
  578. num = dtChecks.Rows.Count;
  579. Dictionary<string, int> dic = DBHelper.GetAllCode("" + ERPDB + "", surface, "" + num + "", head.WorkPoint);
  580. int iFatherId = Convert.ToInt32(dic["iFatherId"].ToString());
  581. int iChildId = Convert.ToInt32(dic["iChildId"].ToString());
  582. DateTime date1 = DateTime.Now;
  583. string iBaseCodeLen = DBHelper.GetAllRDCode(cardnewcode1, "" + date1 + "", "admin", head.WorkPoint);
  584. string cRDcode08 = DBHelper.GetRDCode(crdname1, cmd);
  585. string DEF_ID08 = DBHelper.GetDefaultTemplate(cardnewcode1, cmd);
  586. #region 其他入库单表头
  587. sql = @"INSERT INTO dbo.RdRecord08
  588. (ID,bRdFlag,cVouchType,cBusType,cSource,cBusCode,cWhCode,dDate,cCode,cRdCode,
  589. cHandler,cMemo,bTransFlag,cMaker,dVeriDate,bpufirst,biafirst,VT_ID,bIsSTQc,bOMFirst,
  590. bFromPreYear,bIsComplement,iDiscountTaxType,ireturncount,
  591. iverifystate,iswfcontrolled,dnmaketime,dnverifytime,bredvouch,cSourceLs,cDepCode)
  592. SELECT @ID,'1','08','','',a.cTVCode,cIWhCode,CONVERT(NVARCHAR(15),GETDATE(),23),a.cTVCode,@cRdCode,
  593. @cHandler,@cMemo,'0',@cMaker,CONVERT(NVARCHAR(15),GETDATE(),23),'0','0',
  594. @VT_ID,'0','0','0','0','0','0','0','0',GETDATE(),GETDATE(),'0','1',cIDepCode from dbo.TransVouch a WHERE cTVCode='" + iBaseCode + "' ";
  595. cmd.Parameters.Clear();
  596. cmd.Parameters.Add(new SqlParameter("@ID", iFatherId));
  597. //cmd.Parameters.Add(new SqlParameter("@cBusCode", head.ID));
  598. cmd.Parameters.Add(new SqlParameter("@cCode", iBaseCodeLen));
  599. cmd.Parameters.Add(new SqlParameter("@cHandler", userInfo.UserName));
  600. cmd.Parameters.Add(new SqlParameter("@cMemo", ""));
  601. cmd.Parameters.Add(new SqlParameter("@cMaker", userInfo.UserName));
  602. cmd.Parameters.Add(new SqlParameter("@VT_ID", DEF_ID08));
  603. cmd.Parameters.Add(new SqlParameter("@cRdCode", cRDcode08));
  604. cmd.CommandText = sql;
  605. try
  606. {
  607. cmd.ExecuteNonQuery();
  608. }
  609. catch (Exception ex)
  610. {
  611. log.Error("生成其他入库单表头失败!调拨单:" + iBaseCode + ";异常:" + ex.Message + ";SQL:\r\n" + sql);
  612. throw new Exception("程序异常,请联系开发人员!");
  613. }
  614. #endregion
  615. #region 3.5 其他入库单表体
  616. for (int i = 0; i < dtChecks.Rows.Count; i++)
  617. {
  618. #region 3.5.1 表体
  619. sql = @"INSERT INTO dbo.rdrecords08
  620. (AutoID,ID,cInvCode,iQuantity,iSOutQuantity,iSOutNum,iFlag,iTrIds,iNQuantity,iNum,
  621. cMassUnit,bLPUseFree,iRSRowNO,iOriTrackID,bCosting,bVMIUsed,iExpiratDateCalcu,iordertype,irowno,cbaccounter,cBatch,iPUnitCost,iPPrice,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10)
  622. SELECT @AutoID,@ID,cInvCode,a.iTVQuantity,'0','0','0',a.AutoID,iTVQuantity,iTVNum,
  623. '0','0','0','0','1','0','0','0',@irowno,null,cTVBatch,iTVPCost,iTVPPrice ,a.cFree1,a.cFree2,a.cFree3,a.cFree4,a.cFree5,a.cFree6,a.cFree7,a.cFree8,a.cFree9,a.cFree10
  624. from TransVouchs a
  625. inner join TransVouch b on a.ID=b.ID
  626. where a.autoid='" + dtChecks.Rows[i]["AutoID"].ToString() + @"';";
  627. cmd.Parameters.Clear();
  628. cmd.Parameters.Add(new SqlParameter("@AutoID", iChildId));
  629. cmd.Parameters.Add(new SqlParameter("@ID", iFatherId));
  630. //cmd.Parameters.Add(new SqlParameter("@iQuantity", dtCheck.Rows[0]["iQuantity"].ToString()));
  631. //cmd.Parameters.Add(new SqlParameter("@iTrIds", body.AutoID));
  632. cmd.Parameters.Add(new SqlParameter("@irowno", dtChecks.Rows[i]["irowno"].ToString()));
  633. cmd.CommandText = sql;
  634. try
  635. {
  636. cmd.ExecuteNonQuery();
  637. }
  638. catch (Exception ex)
  639. {
  640. log.Error("生成其他出库单表体失败!调拨单:" + iBaseCode + ";异常:" + ex.Message + ";SQL:\r\n" + sql);
  641. throw new Exception("程序异常,请联系开发人员!");
  642. }
  643. #endregion
  644. //更新现存量
  645. key08.cBustypeUN = "调拨入库";
  646. key08.cVouchTypeUN = "08";
  647. key08.TableName = "IA_ST_UnAccountVouch08";
  648. key08.UpdateTodoQuantity = head.UpdateTodoQuantity;
  649. DBHelper.UpdateCurrentStockNEW(cmd, dtChecks.Rows[i]["cInvCode"].ToString(), cIWhCode, dtChecks.Rows[i]["cTVBatch"].ToString(), Convert.ToDecimal(dtChecks.Rows[i]["iTVQuantity"].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(), key08);
  650. //DBHelper.UpdateCurrentStock(cmd, dtChecks.Rows[i]["cInvCode"].ToString(), cIWhCode, "", Convert.ToDecimal(dtChecks.Rows[i]["iTVQuantity"].ToString()), key08);
  651. iChildId--;
  652. }
  653. #endregion
  654. #endregion
  655. #region 其他出库单
  656. //取得采购入库单单据 表头ID,表体DID
  657. VouchKey key09 = new VouchKey();
  658. //key09 = U8Helper.GetPrimaryKey("rd", ErpName, 1, cmd);
  659. //// 取得表头单据号
  660. //string Code09 = U8Helper.GetRdrecord09Code(ErpName, "QC", cmd);
  661. var nums = dtChecks.Rows.Count+num;
  662. Dictionary<string, int> dics = DBHelper.GetAllCode("" + ERPDB + "", surface, "" + nums + "", head.WorkPoint);
  663. int iFatherIds = Convert.ToInt32(dics["iFatherId"].ToString());
  664. int iChildIds = Convert.ToInt32(dics["iChildId"].ToString());
  665. DateTime dates = DateTime.Now;
  666. string iBaseCodeLens = DBHelper.GetAllRDCode(cardnewcode, "" + date + "", "admin", head.WorkPoint);
  667. string cRDcode09 = DBHelper.GetRDCode(crdname, cmd);
  668. string DEF_ID09 = DBHelper.GetDefaultTemplate(cardnewcode, cmd);
  669. #region 其他出库单表头
  670. sql = @"INSERT INTO dbo.RdRecord09
  671. (ID,bRdFlag,cVouchType,cBusType,cSource,cBusCode,cWhCode,dDate,cCode,cRdCode,
  672. cHandler,cMemo,bTransFlag,cMaker,dVeriDate,bpufirst,biafirst,VT_ID,bIsSTQc,bOMFirst,
  673. bFromPreYear,bIsComplement,iDiscountTaxType,ireturncount,
  674. iverifystate,iswfcontrolled,dnmaketime,dnverifytime,bredvouch,cSourceLs,cDepCode)
  675. SELECT @ID,'0','09','','',a.cTVCode,cOWhCode,CONVERT(NVARCHAR(15),GETDATE(),23),@cCode,@cRdCode,
  676. @cHandler,@cMemo,'0',@cMaker,CONVERT(NVARCHAR(15),GETDATE(),23),'0','0',
  677. '85','0','0','0','0','0','0','0','0',GETDATE(),GETDATE(),'0','1',cODepCode from dbo.TransVouch a WHERE cTVCode='" + iBaseCode + "' ";
  678. cmd.Parameters.Clear();
  679. cmd.Parameters.Add(new SqlParameter("@ID", iFatherIds));
  680. //cmd.Parameters.Add(new SqlParameter("@cBusCode", dtCheck.Rows[0]["cTVCode"].ToString()));
  681. //cmd.Parameters.Add(new SqlParameter("@cWhCode", cOWhCode));
  682. cmd.Parameters.Add(new SqlParameter("@cCode", iBaseCodeLens));
  683. cmd.Parameters.Add(new SqlParameter("@cHandler", userInfo.UserName));
  684. cmd.Parameters.Add(new SqlParameter("@cMemo", ""));
  685. cmd.Parameters.Add(new SqlParameter("@cMaker", userInfo.UserName));
  686. cmd.Parameters.Add(new SqlParameter("@VT_ID", DEF_ID09));
  687. cmd.Parameters.Add(new SqlParameter("@cRdCode", cRDcode09));
  688. cmd.CommandText = sql;
  689. try
  690. {
  691. cmd.ExecuteNonQuery();
  692. }
  693. catch (Exception ex)
  694. {
  695. log.Error("生成其他出库单失败!调拨单:" + iBaseCode + ";异常:" + ex.Message + ";SQL:\r\n" + sql);
  696. throw new Exception("程序异常,请联系开发人员!");
  697. }
  698. #endregion
  699. #region 3.5 其他出库单表体
  700. for (int i = 0; i < dtChecks.Rows.Count; i++)
  701. {
  702. #region 3.5.1 表体
  703. //判断物料批号与现存量表批号是否一致、数量不能超过现存量物料数量
  704. //sql = @"SELECT cBatch,iQuantity from CurrentStock WHERE cInvCode='" + dtCheck.Rows[0]["cInvCode"].ToString() + "'AND cWhCode='" + dtCheck.Rows[0]["cOWhCode"].ToString() + "'";
  705. //DataTable dtItem = DBHelper.SQlReturnData(sql, cmd);
  706. //if (dtItem != null && dtItem.Rows.Count > 0)
  707. //{
  708. // if (!dtItem.Rows[0]["cBatch"].ToString().Equals(body.cTVBatch))
  709. // {
  710. // throw new Exception("物料条码的批号与U8现存量物料批号不一致,物料:" + body.cInvCode);
  711. // }
  712. // if (Convert.ToDecimal(dtItem.Rows[0]["iQuantity"].ToString()) < body.iQuantity)
  713. // {
  714. // throw new Exception("物料条码的数量大于U8现存量物料数量,物料:" + body.cInvCode);
  715. // }
  716. //}
  717. //else
  718. //{
  719. // throw new Exception("物料:" + body.cInvCode + "在现存量表中不存在!");
  720. //}
  721. //key09.DID += 1;
  722. //Rd09irowno += 1;
  723. sql = @"INSERT INTO dbo.rdrecords09
  724. (AutoID,ID,cInvCode,iQuantity,iSOutQuantity,iSOutNum,iFlag,iTrIds,iNQuantity,iNum,
  725. cMassUnit,bLPUseFree,iRSRowNO,iOriTrackID,bCosting,bVMIUsed,iExpiratDateCalcu,iordertype,irowno,cbaccounter,cBatch,iPUnitCost,iPPrice,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10)
  726. SELECT @AutoID,@ID,cInvCode,a.iTVQuantity,'0','0','0',a.AutoID,iTVQuantity,iTVNum,
  727. '0','0','0','0','1','0','0','0',a.irowno,null,cTVBatch,iTVPCost,iTVPPrice ,a.cFree1,a.cFree2,a.cFree3,a.cFree4,a.cFree5,a.cFree6,a.cFree7,a.cFree8,a.cFree9,a.cFree10
  728. from TransVouchs a
  729. inner join TransVouch b on a.ID=b.ID
  730. where a.autoid='" + dtChecks.Rows[i]["AutoID"].ToString() + @"' ;";
  731. cmd.Parameters.Clear();
  732. cmd.Parameters.Add(new SqlParameter("@AutoID", iChildIds));
  733. cmd.Parameters.Add(new SqlParameter("@ID", iFatherIds));
  734. //cmd.Parameters.Add(new SqlParameter("@iQuantity", dtCheck.Rows[0]["iQuantity"].ToString()));
  735. //cmd.Parameters.Add(new SqlParameter("@iTrIds", body.AutoID));
  736. //cmd.Parameters.Add(new SqlParameter("@irowno", Rd09irowno));
  737. cmd.CommandText = sql;
  738. try
  739. {
  740. cmd.ExecuteNonQuery();
  741. }
  742. catch (Exception ex)
  743. {
  744. log.Error("生成其他出库单表体失败!调拨单:" + iBaseCode + ";异常:" + ex.Message + ";SQL:\r\n" + sql);
  745. throw new Exception("程序异常,请联系开发人员!");
  746. }
  747. sql = @"INSERT INTO dbo.rdrecords09sub
  748. ( AutoID , ID ,iBG_Ctrl , iBGSTSum )
  749. values('" + iChildIds + "','" + iFatherIds + "',0,0)";
  750. cmd.CommandText = sql;
  751. cmd.ExecuteNonQuery();
  752. #endregion
  753. if (head.UpdateStock)
  754. {
  755. //更新现存量
  756. key09.cBustypeUN = "调拨出库";
  757. key09.cVouchTypeUN = "09";
  758. key09.TableName = "IA_ST_UnAccountVouch09";
  759. //DBHelper.UpdateCurrentStock(cmd, dtChecks.Rows[i]["cInvCode"].ToString(), cOWhCode, "", -Convert.ToDecimal(dtChecks.Rows[i]["iTVQuantity"].ToString()), key09);
  760. DBHelper.UpdateCurrentStockNEW(cmd, dtChecks.Rows[i]["cInvCode"].ToString(), cOWhCode, dtChecks.Rows[i]["cTVBatch"].ToString(), -Convert.ToDecimal(dtChecks.Rows[i]["iTVQuantity"].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(), key09);
  761. }
  762. iChildIds--;
  763. }
  764. #endregion
  765. #endregion
  766. cmd.Transaction.Commit();
  767. }
  768. catch (Exception ex)
  769. {
  770. cmd.Transaction.Rollback();
  771. log.Error(ex.Message);
  772. throw new Exception(ex.Message);
  773. }
  774. finally
  775. {
  776. if (conn.State == ConnectionState.Open)
  777. {
  778. conn.Close();
  779. }
  780. conn.Dispose();
  781. }
  782. }
  783. ResultFlag = true;
  784. return ResultFlag;
  785. }
  786. /// <summary>
  787. /// 记录日志
  788. /// </summary>
  789. /// <param name="Bills"></param>
  790. private void LogInfo(List<ICSTransferDoc> Bills)
  791. {
  792. string HeadList = string.Empty;
  793. string BodyList = string.Empty;
  794. foreach (ICSTransferDoc head in Bills)
  795. {
  796. HeadList += "\r\n 表头调拨单号:" + head.ID + ",用户:" + head.User + ",站点:" + head.WorkPoint;
  797. foreach (ICSTransferDoc body in Bills)
  798. {
  799. BodyList += "\r\n 表体主键ID: " + body.ID + "";
  800. }
  801. }
  802. log.Info(HeadList);
  803. log.Info(BodyList);
  804. }
  805. /// <summary>
  806. /// 记录日志
  807. /// </summary>
  808. /// <param name="Bills"></param>
  809. private void LogInfo1(List<ICSTransfer> Bills)
  810. {
  811. string HeadList = string.Empty;
  812. string BodyList = string.Empty;
  813. foreach (ICSTransfer head in Bills)
  814. {
  815. HeadList += "\r\n 表头调拨单号:" + head.TACode + ",用户:" + head.User + ",站点:" + head.WorkPoint;
  816. foreach (ICSTransfer body in Bills)
  817. {
  818. BodyList += "\r\n 表体主键ID: " + body.TACode + "";
  819. }
  820. }
  821. log.Info(HeadList);
  822. log.Info(BodyList);
  823. }
  824. }
  825. }