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

425 lines
28 KiB

3 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
  1. using ICSSoft.Common;
  2. using ICSSoft.Entity;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Data;
  6. using System.Data.SqlClient;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Threading.Tasks;
  10. namespace ICSSoft.DataProject
  11. {
  12. public class CreateAssemVouch
  13. {
  14. private static log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
  15. private static string connString = System.Configuration.ConfigurationManager.AppSettings["ERPConnStr"];
  16. private static string ERPDB = System.Configuration.ConfigurationManager.AppSettings["ERPDB"];
  17. private static string CRNALL = System.Configuration.ConfigurationManager.AppSettings["AssemCRDNAME"];
  18. /// <summary>
  19. /// 生成形态转换单
  20. /// </summary>
  21. /// <param name="Bills"></param>
  22. /// <returns></returns>
  23. public string Create(List<ICSAssemVouch> Bills)
  24. {
  25. string msg = "";
  26. string connS = "";
  27. SqlConnection conn = new SqlConnection();
  28. SqlCommand cmd = new SqlCommand();
  29. DataSet ds = null;
  30. string iFatherIdTwo = "";
  31. if (Bills.Count <= 0)
  32. {
  33. throw new Exception("传送数据为空!");
  34. }
  35. string sql = "";
  36. int num = 0;
  37. List<string> result = Bills.Select(t => t.WorkPoint).Distinct().ToList();
  38. foreach (string WorkPoint in result)
  39. {
  40. try
  41. {
  42. connS = string.Format(connString, WorkPoint);
  43. conn = new System.Data.SqlClient.SqlConnection(connS);
  44. conn.Open();
  45. SqlTransaction sqlTran = conn.BeginTransaction();
  46. cmd = new SqlCommand();
  47. cmd.Transaction = sqlTran;
  48. cmd.Connection = conn;
  49. foreach (ICSAssemVouch head in Bills)
  50. {
  51. iFatherIdTwo = "";
  52. if (WorkPoint != head.WorkPoint)
  53. {
  54. continue;
  55. }
  56. string[] ss = head.WorkPoint.Split('_');
  57. ERPDB = ss[1];
  58. string[] dd = CRNALL.Split('~');
  59. string crdname1 = dd[0];
  60. string crdname2 = dd[1];
  61. string carname = dd[2];
  62. string surface = dd[3];
  63. string carname1 = dd[4];
  64. string carname2 = dd[5];
  65. string surface1 = dd[6];
  66. //string crdname1 = dd[2];
  67. //string crdname2 = dd[3];
  68. //string carname = dd[0];
  69. //string surface = dd[1];
  70. //string carname1 = dd[4];
  71. //string carname2 = dd[5];
  72. //string surface1 = dd[6];
  73. string cardnewcode = DBHelper.GetCardNumber(carname, cmd);
  74. string cardnewcode1 = DBHelper.GetCardNumber(carname1, cmd);
  75. string cardnewcode2 = DBHelper.GetCardNumber(carname2, cmd);
  76. string cRDcode08 = DBHelper.GetRDCode(crdname1, cmd);
  77. string cRDcode09 = DBHelper.GetRDCode(crdname2, cmd);
  78. ICSUserInfo userInfo = new ICSUserInfo();
  79. userInfo = DBHelper.GetPersonInfo(head.User, cmd);
  80. #region 形态转换单
  81. #region 形态转换单表头
  82. //形态转换单CartonNo:0305
  83. //取得out库单的默认显示模版
  84. string DEF_ID07 = DBHelper.GetDefaultTemplate(cardnewcode, cmd);
  85. //取得形态转换入库单单据 表头ID,表体DID
  86. num = head.details.Count();
  87. Dictionary<string, int> dic = DBHelper.GetAllCode(ERPDB, surface, num.ToString(), head.WorkPoint);
  88. int iFatherId = Convert.ToInt32(dic["iFatherId"].ToString());
  89. int iChildId = Convert.ToInt32(dic["iChildId"].ToString());
  90. DateTime date = DateTime.Now;
  91. // 取得表头单据号
  92. string Code07 = DBHelper.GetAllRDCode(cardnewcode, "" + date + "", "admin", "", head.WorkPoint);
  93. sql = @"INSERT INTO AssemVouch
  94. (cAVCode,cVouchType,dAVDate,cDepCode,cIRdCode,cORdCode,cMaker,iNetLock,
  95. ID,bTransFlag,VT_ID,cVerifyPerson,dVerifyDate,
  96. dnmaketime,dnverifytime,iPrintCount,ctransflag)
  97. VALUES
  98. (@cAVCode,'15',CONVERT(NVARCHAR(15),GETDATE(),23),@cDepCode,@cIRdCode,@cORdCode,@cMaker,0,
  99. @ID,'0',@VT_ID,@cMaker,CONVERT(NVARCHAR(15),GETDATE(),23),
  100. GETDATE(),GETDATE(),0,1)
  101. ";
  102. cmd.Parameters.Clear();
  103. cmd.Parameters.Add(new SqlParameter("@cAVCode", Code07));
  104. cmd.Parameters.Add(new SqlParameter("@cDepCode", head.DepCode));
  105. cmd.Parameters.Add(new SqlParameter("@cMaker", userInfo.UserName));
  106. cmd.Parameters.Add(new SqlParameter("@cIRdCode", cRDcode08));
  107. cmd.Parameters.Add(new SqlParameter("@cORdCode", cRDcode09));
  108. cmd.Parameters.Add(new SqlParameter("@ID", iFatherId));
  109. cmd.Parameters.Add(new SqlParameter("@VT_ID", DEF_ID07));
  110. cmd.CommandText = sql;
  111. DBHelper.CmdExecuteNonQuery(sql, cmd, "形态转换单表头保存失败!");
  112. #endregion
  113. #region 其他出库单表头
  114. //取得out库单的默认显示模版
  115. string DEF_ID09 = DBHelper.GetDefaultTemplate(cardnewcode2, cmd);
  116. //取得表头ID,表体DID
  117. Dictionary<string, int> dic09 = DBHelper.GetAllCode(ERPDB, surface1, num.ToString(), head.WorkPoint);
  118. int iFatherId09 = Convert.ToInt32(dic09["iFatherId"].ToString());
  119. int iChildId09 = Convert.ToInt32(dic09["iChildId"].ToString());
  120. // 取得表头单据号
  121. string Code09 = DBHelper.GetAllRDCode(cardnewcode2, "" + date + "", "admin", cRDcode09, head.WorkPoint);
  122. sql = @"INSERT INTO dbo.RdRecord09
  123. (ID,bRdFlag,cVouchType,cBusType,cSource,cBusCode,cWhCode,dDate,cCode,cRdCode,
  124. cHandler,cMemo,bTransFlag,cMaker,dVeriDate,bpufirst,biafirst,VT_ID,bIsSTQc,bOMFirst,
  125. bFromPreYear,bIsComplement,iDiscountTaxType,ireturncount,
  126. iverifystate,iswfcontrolled,dnmaketime,dnverifytime,bredvouch,cSourceLs,ctransflag,cDepCode)
  127. SELECT @ID,'0','09','','',@cBusCode,@cWhCode,CONVERT(NVARCHAR(15),GETDATE(),23),@cCode,@cRDcode,
  128. @cHandler,@cMemo,'0',@cMaker,CONVERT(NVARCHAR(15),GETDATE(),23),'0','0',
  129. '85','0','0','0','0','0','0','0','0',GETDATE(),GETDATE(),'0',null,'1',cDepCode from dbo.AssemVouch WHERE cAVCode='" + Code07 + "' ";
  130. cmd.Parameters.Clear();
  131. cmd.Parameters.Add(new SqlParameter("@ID", iFatherId09));
  132. cmd.Parameters.Add(new SqlParameter("@cBusCode", Code07));
  133. cmd.Parameters.Add(new SqlParameter("@cWhCode", head.OutWhCode));
  134. cmd.Parameters.Add(new SqlParameter("@cCode", Code09.ToString().PadLeft(10, '0')));
  135. cmd.Parameters.Add(new SqlParameter("@cHandler", userInfo.UserName));
  136. cmd.Parameters.Add(new SqlParameter("@cMemo", ""));
  137. cmd.Parameters.Add(new SqlParameter("@cMaker", userInfo.UserName));
  138. cmd.Parameters.Add(new SqlParameter("@VT_ID", DEF_ID09));
  139. cmd.Parameters.Add(new SqlParameter("@cRDcode", cRDcode09));
  140. cmd.CommandText = sql;
  141. DBHelper.CmdExecuteNonQuery(sql, cmd, "其他出库单表头保存失败!");
  142. #endregion
  143. #region 其他入库单表头
  144. //取得out库单的默认显示模版
  145. string DEF_ID08 = DBHelper.GetDefaultTemplate(cardnewcode1, cmd);
  146. //取得入库单单据 表头ID,表体DID
  147. Dictionary<string, int> dic08 = DBHelper.GetAllCode(ERPDB, surface1, num.ToString(), head.WorkPoint);
  148. int iFatherId08 = Convert.ToInt32(dic08["iFatherId"].ToString());
  149. int iChildId08 = Convert.ToInt32(dic08["iChildId"].ToString());
  150. // 取得表头单据号
  151. string Code08 = DBHelper.GetAllRDCode(cardnewcode1, "" + date + "", "admin", cRDcode08, head.WorkPoint);
  152. sql = @"INSERT INTO dbo.RdRecord08
  153. (ID,bRdFlag,cVouchType,cBusType,cSource,cBusCode,cWhCode,dDate,cCode,cRdCode,
  154. cHandler,cMemo,bTransFlag,cMaker,dVeriDate,bpufirst,biafirst,VT_ID,bIsSTQc,bOMFirst,
  155. bFromPreYear,bIsComplement,iDiscountTaxType,ireturncount,
  156. iverifystate,iswfcontrolled,dnmaketime,dnverifytime,bredvouch,cSourceLs,ctransflag,cDepCode)
  157. SELECT @ID,'1','08','','',@cBusCode,@cIWhCode,CONVERT(NVARCHAR(15),GETDATE(),23),@cCode,@cRDcode,
  158. @cHandler,@cMemo,'0',@cMaker,CONVERT(NVARCHAR(15),GETDATE(),23),'0','0',
  159. @VT_ID,'0','0','0','0','0','0','0','0',GETDATE(),GETDATE(),'0',null,'1',cDepCode from dbo.AssemVouch WHERE cAVCode='" + Code07 + "' ";
  160. cmd.Parameters.Clear();
  161. cmd.Parameters.Add(new SqlParameter("@ID", iFatherId08));
  162. cmd.Parameters.Add(new SqlParameter("@cBusCode", Code07));
  163. cmd.Parameters.Add(new SqlParameter("@cIWhCode", head.InWhCode));
  164. cmd.Parameters.Add(new SqlParameter("@cCode", Code08));
  165. cmd.Parameters.Add(new SqlParameter("@cHandler", userInfo.UserName));
  166. cmd.Parameters.Add(new SqlParameter("@cMemo", ""));
  167. cmd.Parameters.Add(new SqlParameter("@cMaker", userInfo.UserName));
  168. cmd.Parameters.Add(new SqlParameter("@VT_ID", DEF_ID08));
  169. cmd.Parameters.Add(new SqlParameter("@cRDcode", cRDcode08));
  170. cmd.CommandText = sql;
  171. DBHelper.CmdExecuteNonQuery(sql, cmd, "其他入库单表头保存失败!");
  172. #endregion
  173. int Rd08irowno = 0;
  174. int Rd09irowno = 0;
  175. foreach (ICSAssemVouchs body in head.details)
  176. {
  177. if (DBHelper.bInvBatch(body.InvCode, cmd) == true)
  178. {
  179. if (body.BatchCode == "")
  180. {
  181. log.Error("该物料:" + body.InvCode + "已启用批次,请重新填写!");
  182. throw new Exception("该物料:" + body.InvCode + "已启用批次,请重新填写!");
  183. }
  184. }
  185. else
  186. {
  187. if (body.BatchCode != "")
  188. {
  189. log.Error("该物料:" + body.InvCode + "未启用批次,请重新填写!");
  190. throw new Exception("该物料:" + body.InvCode + "未启用批次,请重新填写!");
  191. }
  192. }
  193. #region 形态转换单转换前表体
  194. sql = @"INSERT INTO dbo.AssemVouchs
  195. (ID,cAVCode,bAVType,cWhCode,cInvCode,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10,
  196. iAVQuantity,cAVBatch,autoID,bCosting,iExpiratDateCalcu,iAVNum,cItemCode,
  197. irowno,iGroupNO)
  198. VALUES(@ID,@cAVCode,@bAVType,@cWhCode,@cInvCode,@cFree1,@cFree2,@cFree3,@cFree4,@cFree5,@cFree6,@cFree7,@cFree8,@cFree9,@cFree10,
  199. @iAVQuantity,@cAVBatch,@autoID,0,0,@iAVNum,@cItemCode,
  200. @irowno,@iGroupNO)";
  201. cmd.Parameters.Clear();
  202. cmd.Parameters.Add(new SqlParameter("@ID", iFatherId));
  203. cmd.Parameters.Add(new SqlParameter("@cAVCode", Code07));
  204. cmd.Parameters.Add(new SqlParameter("@bAVType", body.Type));
  205. cmd.Parameters.Add(new SqlParameter("@cWhCode", body.WHCode));
  206. cmd.Parameters.Add(new SqlParameter("@cInvCode", body.InvCode));
  207. cmd.Parameters.Add(new SqlParameter("@iAVQuantity", body.Quantity));
  208. cmd.Parameters.Add(new SqlParameter("@iAVNum", body.Amount.ToString("0.00")));
  209. cmd.Parameters.Add(new SqlParameter("@cAVBatch", body.BatchCode));
  210. cmd.Parameters.Add(new SqlParameter("@cItemCode", body.ProjectCode));
  211. cmd.Parameters.Add(new SqlParameter("@autoID", iChildId));
  212. cmd.Parameters.Add(new SqlParameter("@irowno", body.Sequence));
  213. cmd.Parameters.Add(new SqlParameter("@cFree1", body.cFree1));
  214. cmd.Parameters.Add(new SqlParameter("@cFree2", body.cFree2));
  215. cmd.Parameters.Add(new SqlParameter("@cFree3", body.cFree3));
  216. cmd.Parameters.Add(new SqlParameter("@cFree4", body.cFree4));
  217. cmd.Parameters.Add(new SqlParameter("@cFree5", body.cFree5));
  218. cmd.Parameters.Add(new SqlParameter("@cFree6", body.cFree6));
  219. cmd.Parameters.Add(new SqlParameter("@cFree7", body.cFree7));
  220. cmd.Parameters.Add(new SqlParameter("@cFree8", body.cFree8));
  221. cmd.Parameters.Add(new SqlParameter("@cFree9", body.cFree9));
  222. cmd.Parameters.Add(new SqlParameter("@cFree10", body.cFree10));
  223. cmd.Parameters.Add(new SqlParameter("@iGroupNO", body.GroupNO));
  224. cmd.CommandText = sql;
  225. DBHelper.CmdExecuteNonQuery(sql, cmd, "形态转换单表体保存失败!");
  226. #endregion
  227. if (body.Type == "转换前")
  228. {
  229. Rd09irowno += 1;
  230. #region 其他出库单表体
  231. //判断物料批号与现存量表批号是否一致、数量不能超过现存量物料数量
  232. //sql = @"SELECT cBatch,iQuantity from CurrentStock WHERE cInvCode='" + body.InvCode + "'AND cBatch='" + body.BatchCode + "'and cWhCode='" + head.OutWhCode + "'";
  233. sql = @"SELECT cBatch,iQuantity from CurrentStock WHERE cInvCode='" + body.InvCode + "'AND cBatch='" + body.BatchCode + @"'AND cFree1='" + body.cFree1 + @"' AND cFree2='" + body.cFree2 + @"' AND cFree3='" + body.cFree3 + @"' AND cFree4='" + body.cFree4 + @"' AND cFree5='" + body.cFree5 + @"' AND cFree6='" + body.cFree6 + @"' AND cFree7='" + body.cFree7 + @"' AND cFree8='" + body.cFree8 + @"' AND cFree9='" + body.cFree9 + @"' AND cFree10='" + body.cFree10 + @"' and cWhCode='" + head.OutWhCode + "'";
  234. DataTable dtItem = DBHelper.SQlReturnData(sql, cmd);
  235. if (dtItem != null && dtItem.Rows.Count > 0)
  236. {
  237. if (!dtItem.Rows[0]["cBatch"].ToString().Equals(body.BatchCode))
  238. {
  239. throw new Exception("物料条码的批号与U8现存量物料批号不一致,物料:" + body.InvCode);
  240. }
  241. if (Convert.ToDecimal(dtItem.Rows[0]["iQuantity"].ToString()) < body.Quantity)
  242. {
  243. throw new Exception("物料条码的数量大于U8现存量物料数量,物料:" + body.InvCode);
  244. }
  245. }
  246. else
  247. {
  248. throw new Exception("物料:" + body.InvCode + "在现存量表中不存在!");
  249. }
  250. sql = @"INSERT INTO dbo.rdrecords09
  251. (AutoID,ID,cInvCode,iQuantity,iSOutQuantity,iSOutNum,iFlag,iTrIds,iNQuantity,iNum, cFree1, cFree2, cFree3, cFree4, cFree5, cFree6, cFree7, cFree8, cFree9, cFree10,cItemCode,
  252. cMassUnit,bLPUseFree,iRSRowNO,iOriTrackID,bCosting,bVMIUsed,iExpiratDateCalcu,iordertype,irowno,cbaccounter,cBatch,iPUnitCost,iGroupNO,iPPrice)
  253. SELECT @AutoID,@ID,cInvCode,iAVQuantity,'0','0','0',@iTrIds,null,iAVNum ,cFree1, cFree2, cFree3, cFree4, cFree5, cFree6, cFree7, cFree8, cFree9, cFree10,cItemCode,
  254. '0','0','0','0','1','0','0','0',@irowno,null,cAVBatch,iAVPCost,@iGroupNO,iAVPPrice from AssemVouchs where autoID=" + iChildId + @" ;";
  255. cmd.Parameters.Clear();
  256. cmd.Parameters.Add(new SqlParameter("@AutoID", iChildId09));
  257. cmd.Parameters.Add(new SqlParameter("@ID", iFatherId09));
  258. cmd.Parameters.Add(new SqlParameter("@iGroupNO", body.GroupNO));
  259. cmd.Parameters.Add(new SqlParameter("@iTrIds", iChildId));
  260. cmd.Parameters.Add(new SqlParameter("@irowno", Rd09irowno));
  261. cmd.CommandText = sql;
  262. DBHelper.CmdExecuteNonQuery(sql, cmd, "其他出库单表体保存失败!");
  263. sql = @"INSERT INTO dbo.rdrecords09sub
  264. ( AutoID , ID ,iBG_Ctrl , iBGSTSum )
  265. values('" + iChildId09 + "','" + iFatherId09 + "',0,0)";
  266. cmd.CommandText = sql;
  267. cmd.ExecuteNonQuery();
  268. #endregion
  269. #region 更新现存量
  270. VouchKey key09 = new VouchKey();
  271. key09.cBustypeUN = "转换出库";
  272. key09.cVouchTypeUN = "09";
  273. key09.TableName = "IA_ST_UnAccountVouch09";
  274. //DBHelper.UpdateCurrentStock(cmd, body.InvCode, head.OutWhCode, body.BatchCode, -body.Quantity, key09);
  275. //DBHelper.UpdateCurrentStockNEW(cmd, body.InvCode, head.OutWhCode, body.BatchCode, -body.Quantity, body.cFree1, body.cFree2, body.cFree3, body.cFree4, body.cFree5, body.cFree6, body.cFree7, body.cFree8, body.cFree9, body.cFree10, key09);
  276. DBHelper.UpdateCurrentStockCCGC(cmd, body.InvCode, head.OutWhCode, body.BatchCode, -body.Quantity, -body.Amount, body.cFree1,
  277. body.cFree2, body.cFree3, body.cFree4, body.cFree5, body.cFree6, body.cFree7, body.cFree8, body.cFree9, body.cFree10,
  278. "", key09, "", "", "", "", 0, 0, 0, 0, 0, 0, 0, 0, iFatherId09, iChildId09);
  279. #endregion
  280. }
  281. else
  282. {
  283. if (DBHelper.bInvBatch(body.InvCode, cmd) == true)
  284. {
  285. if (body.BatchCode == "")
  286. {
  287. log.Error("该物料:" + body.InvCode + "已启用批次,请重新填写!");
  288. throw new Exception("该物料:" + body.InvCode + "已启用批次,请重新填写!");
  289. }
  290. }
  291. else
  292. {
  293. if (body.BatchCode != "")
  294. {
  295. log.Error("该物料:" + body.InvCode + "未启用批次,请重新填写!");
  296. throw new Exception("该物料:" + body.InvCode + "未启用批次,请重新填写!");
  297. }
  298. }
  299. Rd08irowno += 1;
  300. #region 其他入库单表体
  301. sql = @"INSERT INTO dbo.rdrecords08
  302. (AutoID,ID,cInvCode,iQuantity,iSOutQuantity,iSOutNum,iFlag,iTrIds,iNQuantity,cFree1, cFree2, cFree3, cFree4, cFree5, cFree6, cFree7, cFree8, cFree9, cFree10,iNum,cItemCode,
  303. cMassUnit,bLPUseFree,iRSRowNO,iOriTrackID,bCosting,bVMIUsed,iExpiratDateCalcu,iordertype,irowno,cbaccounter,cBatch,iPUnitCost,iPPrice,iGroupNO)
  304. SELECT @AutoID,@ID,cInvCode,iAVQuantity,'0','0','0',@iTrIds,iAVQuantity,cFree1, cFree2, cFree3, cFree4, cFree5, cFree6, cFree7, cFree8, cFree9, cFree10,iAVNum,cItemCode,
  305. '0','0','0','0','1','0','0','0',@irowno,null,cAVBatch,iAVPCost,iAVPPrice,@iGroupNO from AssemVouchs where autoID=" + iChildId + @" ;";
  306. cmd.Parameters.Clear();
  307. cmd.Parameters.Add(new SqlParameter("@AutoID", iChildId08));
  308. cmd.Parameters.Add(new SqlParameter("@ID", iFatherId08));
  309. cmd.Parameters.Add(new SqlParameter("@iTrIds", iChildId));
  310. cmd.Parameters.Add(new SqlParameter("@iGroupNO", body.GroupNO));
  311. cmd.Parameters.Add(new SqlParameter("@irowno", Rd08irowno));
  312. cmd.CommandText = sql;
  313. DBHelper.CmdExecuteNonQuery(sql, cmd, "其他入库单表体保存失败!");
  314. #endregion
  315. #region 更新现存量
  316. VouchKey key08 = new VouchKey();
  317. key08.cBustypeUN = "转换入库";
  318. key08.cVouchTypeUN = "08";
  319. key08.TableName = "IA_ST_UnAccountVouch08";
  320. //DBHelper.UpdateCurrentStock(cmd, body.InvCode, head.InWhCode, body.BatchCode, body.Quantity, key08);
  321. //DBHelper.UpdateCurrentStockNEW(cmd, body.InvCode, head.InWhCode, body.BatchCode, body.Quantity, body.cFree1, body.cFree2, body.cFree3, body.cFree4, body.cFree5, body.cFree6, body.cFree7, body.cFree8, body.cFree9, body.cFree10, key08);
  322. DBHelper.UpdateCurrentStockCCGC(cmd, body.InvCode, head.InWhCode, body.BatchCode, body.Quantity, body.Amount, body.cFree1,
  323. body.cFree2, body.cFree3, body.cFree4, body.cFree5, body.cFree6, body.cFree7, body.cFree8, body.cFree9, body.cFree10,
  324. "", key08, "", "", "", "", 0, 0, 0, 0, 0, 0, 0, 0, iFatherId08, iChildId08);
  325. #endregion
  326. }
  327. iFatherIdTwo = "'" + iFatherId + "',";
  328. iChildId--;
  329. iChildId09--;
  330. iChildId08--;
  331. }
  332. #endregion
  333. #region 查询
  334. sql = @"SELECT DISTINCT a.ID AS Costre,a.ID,b.cAVCode AS MTCode,a.cDepCode AS DepCode,'' AS DepName,a.cMaker AS CreateUser,a.dnmaketime AS CreateDateTime,a.cVerifyPerson AS Checker,a.dnverifytime AS CheckDateTime,
  335. b.autoID AS DetailID,b.irowno AS Sequence,b.iGroupNO AS GroupNO,b.bAVType AS Type,b.cInvCode AS InvCode,b.cWhCode AS WHCode,b.iAVQuantity AS Quantity,0 AS Amount,isnull(b.cAVBatch,'') AS BatchCode,isnull(b.cItemCode,'') AS ProjectCode
  336. ,'' version ,'' brand,
  337. isnull(b.cFree1,'') as cFree1,
  338. isnull(b.cFree2,'') as cFree2,
  339. isnull(b.cFree3,'') as cFree3,
  340. isnull(b.cFree4,'') as cFree4,
  341. isnull(b.cFree5,'') as cFree5,
  342. isnull(b.cFree6,'') as cFree6,
  343. isnull(b.cFree7,'') as cFree7,
  344. isnull(b.cFree8,'') as cFree8,
  345. isnull(b.cFree9,'') as cFree9,
  346. isnull(b.cFree10,'') as cFree10
  347. INTO #TempERP
  348. FROM AssemVouch a
  349. INNER JOIN AssemVouchs b ON a.ID=b.ID
  350. WHERE a.ID IN({0})
  351. SELECT DISTINCT Costre,ID,MTCode,DepCode,DepName,CreateUser,CreateDateTime,Checker,CheckDateTime FROM #TempERP
  352. SELECT Costre,DetailID,Sequence,GroupNO,Type,InvCode,WHCode,BatchCode,ProjectCode,Quantity,Amount,BatchCode,ProjectCode,version,brand,
  353. cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10
  354. FROM #TempERP
  355. DROP TABLE #TempERP";
  356. sql = string.Format(sql, iFatherIdTwo.TrimEnd(','));
  357. if (ds != null)
  358. ds.Merge(DBHelper.SQlReturnDataSet(sql, cmd));
  359. else
  360. ds = DBHelper.SQlReturnDataSet(sql, cmd);
  361. #endregion
  362. }
  363. cmd.Transaction.Commit();
  364. }
  365. catch (Exception ex)
  366. {
  367. cmd.Transaction.Rollback();
  368. log.Error(ex.Message);
  369. throw new Exception(ex.Message);
  370. }
  371. finally
  372. {
  373. if (conn.State == ConnectionState.Open)
  374. {
  375. conn.Close();
  376. }
  377. conn.Dispose();
  378. }
  379. }
  380. msg = JSON.DataSetToJson(ds, "details", "Costre");
  381. return msg;
  382. }
  383. }
  384. }