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

244 lines
13 KiB

3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
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
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 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. /// <summary>
  13. /// 归还(生成其他入库单)
  14. /// </summary>
  15. public class ReturnDoc
  16. {
  17. private static log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
  18. private static string connString = System.Configuration.ConfigurationManager.AppSettings["ERPConnStr"];
  19. private static string ERPDB = System.Configuration.ConfigurationManager.AppSettings["ERPDB"];
  20. private static string Type = System.Configuration.ConfigurationManager.AppSettings["Type"];
  21. private static string CRNALL = System.Configuration.ConfigurationManager.AppSettings["ReturnCRDNAME"];
  22. /// <summary>
  23. /// 借用(生成其他出库单)
  24. /// </summary>
  25. /// <param name="Bills"></param>
  26. /// <returns></returns>
  27. public string ConfirmRd08(List<ICSReturnDoc> Bills)
  28. {
  29. string msg = string.Empty;
  30. string sql = string.Empty;
  31. DataTable dtNew1 = null;
  32. DataTable dtNew2 = null;
  33. SqlConnection conn = new SqlConnection();
  34. int num = 0;
  35. string connS = "";
  36. SqlCommand cmd = new SqlCommand();
  37. //List<RdRecord09> Vouchers = new List<RdRecord09>();
  38. foreach (ICSReturnDoc head in Bills)
  39. {
  40. try
  41. {
  42. string iFatherIdTwo = "";
  43. connS = string.Format(connString, head.WorkPoint);
  44. conn = new System.Data.SqlClient.SqlConnection(connS);
  45. conn.Open();
  46. SqlTransaction sqlTran = conn.BeginTransaction();
  47. cmd = new SqlCommand();
  48. cmd.Transaction = sqlTran;
  49. cmd.Connection = conn;
  50. if (DBHelper.IsInventoryConsolidation(cmd, head.WorkPoint))
  51. {
  52. }
  53. else
  54. {
  55. throw new Exception("U8正在整理现存量,请稍后再试");
  56. }
  57. string[] ss = head.WorkPoint.Split('_');
  58. ERPDB = ss[1];
  59. num = head.details.Count();
  60. string[] dd = CRNALL.Split('~');
  61. string crdname = dd[0];
  62. string carname = dd[1];
  63. string surface = dd[2];
  64. string cardnewcode = DBHelper.GetCardNumber(carname, cmd);
  65. Dictionary<string, int> dic = DBHelper.GetAllCode("" + ERPDB + "", surface, "" + num + "", head.WorkPoint);
  66. int iFatherId = Convert.ToInt32(dic["iFatherId"].ToString());
  67. int iChildId = Convert.ToInt32(dic["iChildId"].ToString());
  68. DateTime date = DateTime.Now;
  69. string iBaseCodeLen = DBHelper.GetAllRDCode(cardnewcode, "" + date + "", "admin", head.WorkPoint);
  70. string cRDcode = DBHelper.GetRDCode(crdname, cmd);
  71. //取得out库单的默认显示模版
  72. string DEF_ID08 = DBHelper.GetDefaultTemplate(cardnewcode, cmd);
  73. //取得其他出库单单据 表头ID,表体DID
  74. VouchKey key08 = new VouchKey();
  75. #region 其他出库单表头
  76. sql = @"INSERT INTO dbo.RdRecord08
  77. (ID,bRdFlag,cVouchType,cBusType,cSource,cBusCode,cWhCode,dDate,cCode,cRdCode,
  78. cHandler,cMemo,bTransFlag,cMaker,dVeriDate,bpufirst,biafirst,VT_ID,bIsSTQc,bOMFirst,
  79. bFromPreYear,bIsComplement,iDiscountTaxType,ireturncount,
  80. iverifystate,iswfcontrolled,dnmaketime,dnverifytime,bredvouch,cSourceLs,cDepCode)
  81. VALUES(@ID,1,'08','','',@cBusCode,@cWhCode,CONVERT(NVARCHAR(15),GETDATE(),23),@cCode,@cRdCode,
  82. @cHandler,@cMemo,'0',@cMaker,CONVERT(NVARCHAR(15),GETDATE(),23),'0','0',
  83. @VT_ID,'0','0','0','0','0','0','0','0',GETDATE(),GETDATE(),'0','1',@cDepCode) ";
  84. cmd.Parameters.Clear();
  85. cmd.Parameters.Add(new SqlParameter("@ID", iFatherId));
  86. cmd.Parameters.Add(new SqlParameter("@cWhCode", head.WHCode));
  87. cmd.Parameters.Add(new SqlParameter("@cCode", iBaseCodeLen));
  88. cmd.Parameters.Add(new SqlParameter("@cRdCode", cRDcode));
  89. cmd.Parameters.Add(new SqlParameter("@cDepCode", head.DepCode));
  90. cmd.Parameters.Add(new SqlParameter("@cHandler", head.User));
  91. cmd.Parameters.Add(new SqlParameter("@cMemo", head.User));
  92. cmd.Parameters.Add(new SqlParameter("@cMaker", head.User));
  93. cmd.Parameters.Add(new SqlParameter("@VT_ID", DEF_ID08));
  94. cmd.Parameters.Add(new SqlParameter("@cBusCode", head.SourceCode));
  95. cmd.CommandText = sql;
  96. try
  97. {
  98. cmd.ExecuteNonQuery();
  99. }
  100. catch (Exception ex)
  101. {
  102. log.Error("生成其他出库单失败!SQL:\r\n" + sql);
  103. throw new Exception("程序异常,请联系开发人员!");
  104. }
  105. #endregion
  106. foreach (ICSBrrowDocs body in head.details)
  107. {
  108. #region 3.5.1 表体
  109. sql = @"INSERT INTO dbo.rdrecords08
  110. (AutoID,ID,cInvCode,iQuantity,iSOutQuantity,iSOutNum,iFlag,iDebitIDs,iNQuantity,cBatch,iNum,
  111. cMassUnit,bLPUseFree,iRSRowNO,iOriTrackID,bCosting,bVMIUsed,iExpiratDateCalcu,iordertype,irowno,cbaccounter,iPUnitCost,iPPrice,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10)
  112. VALUES(@AutoID,@ID,@cInvCode,@iQuantity,'0','0','0',@iDebitIDs,'0',@cBatch,@iNum,
  113. '0','0','0','0','1','0','0','0',@irowno,null,null,null,@cFree1,@cFree2,@cFree3,@cFree4,@cFree5,@cFree6,@cFree7,@cFree8,@cFree9,@cFree10)";
  114. cmd.Parameters.Clear();
  115. cmd.Parameters.Add(new SqlParameter("@AutoID", iChildId));
  116. cmd.Parameters.Add(new SqlParameter("@ID", iFatherId));
  117. cmd.Parameters.Add(new SqlParameter("@cInvCode", body.InvCode));
  118. cmd.Parameters.Add(new SqlParameter("@iQuantity", body.Quantity));
  119. cmd.Parameters.Add(new SqlParameter("@iNum", body.Amount));
  120. cmd.Parameters.Add(new SqlParameter("@irowno", body.Sequence));
  121. cmd.Parameters.Add(new SqlParameter("@iDebitIDs", body.SourceDetailID));
  122. cmd.Parameters.Add(new SqlParameter("@cBatch", body.BatchCode));
  123. cmd.Parameters.Add(new SqlParameter("@cFree1", body.cFree1));
  124. cmd.Parameters.Add(new SqlParameter("@cFree2", body.cFree2));
  125. cmd.Parameters.Add(new SqlParameter("@cFree3", body.cFree3));
  126. cmd.Parameters.Add(new SqlParameter("@cFree4", body.cFree4));
  127. cmd.Parameters.Add(new SqlParameter("@cFree5", body.cFree5));
  128. cmd.Parameters.Add(new SqlParameter("@cFree6", body.cFree6));
  129. cmd.Parameters.Add(new SqlParameter("@cFree7", body.cFree7));
  130. cmd.Parameters.Add(new SqlParameter("@cFree8", body.cFree8));
  131. cmd.Parameters.Add(new SqlParameter("@cFree9", body.cFree9));
  132. cmd.Parameters.Add(new SqlParameter("@cFree10", body.cFree10));
  133. cmd.CommandText = sql;
  134. try
  135. {
  136. cmd.ExecuteNonQuery();
  137. }
  138. catch (Exception ex)
  139. {
  140. log.Error("生成其他出库单表体失败!SQL:\r\n" + sql);
  141. throw new Exception("程序异常,请联系开发人员!");
  142. }
  143. #endregion
  144. if (head.UpdateStock)
  145. {
  146. //更新现存量
  147. key08.cBustypeUN = "调拨入库";
  148. key08.cVouchTypeUN = "08";
  149. key08.TableName = "IA_ST_UnAccountVouch08";
  150. //DBHelper.UpdateCurrentStock(cmd, body.InvCode, head.WHCode, "", body.Quantity, key08);
  151. 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, key08);
  152. }
  153. iFatherIdTwo += "'" + iFatherId + "',";
  154. iChildId--;
  155. sql = @"UPDATE a SET iQtyRK =ISNULL(iQtyRK,0)+" + body.Quantity + @"
  156. FROM dbo.HY_DZ_BorrowOutBacks a
  157. WHERE a.Autoid='" + body.SourceDetailID + "'";
  158. DBHelper.CmdExecuteNonQuery(sql, cmd, "回写借入单数量失败!");
  159. }
  160. #region 查询
  161. sql = @"
  162. select a.ID as ID,a.ID as IDs,cBusCode as SourceCode ,
  163. cCode as OtherInCode,a.cDepCode,c.cDepName,a.cWhCode,d.cWhName,
  164. cSource as SourceType,cMaker as CreateUser,dnmaketime as CreateDateTime,
  165. cHandler as Checker,dnverifytime as CheckDateTime
  166. from rdrecord08 a
  167. left join Department c on a.cDepCode=c.cDepCode
  168. left join Warehouse d on a.cWhCode=d.cWhCode
  169. WHERE a.ID in ({0})
  170. select a.ID as IDs,b.AutoID as DetailID,irowno as Sequence,b.cInvCode as InvCode
  171. ,iQuantity as Quantity,b.iDebitIDs as SourceDetailID,iNum as Amount
  172. from rdrecord08 a
  173. left join rdrecords08 b on a.ID=b.ID
  174. left join Department c on a.cDepCode=c.cDepCode
  175. left join Warehouse d on a.cWhCode=d.cWhCode
  176. WHERE a.ID in ({0})";
  177. sql = string.Format(sql, iFatherIdTwo.TrimEnd(','));
  178. DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
  179. if (dtNew1 == null)
  180. dtNew1 = ds.Tables[0];
  181. else
  182. dtNew1.Merge(ds.Tables[0]);
  183. if (dtNew2 == null)
  184. dtNew2 = ds.Tables[1];
  185. else
  186. dtNew2.Merge(ds.Tables[1]);
  187. #endregion
  188. cmd.Transaction.Commit();
  189. }
  190. catch (Exception ex)
  191. {
  192. cmd.Transaction.Rollback();
  193. log.Error(ex.Message);
  194. throw new Exception(ex.Message);
  195. }
  196. finally
  197. {
  198. if (conn.State == ConnectionState.Open)
  199. {
  200. conn.Close();
  201. }
  202. conn.Dispose();
  203. }
  204. }
  205. string RelationName = "details";
  206. DataSet dz = new DataSet();
  207. dtNew1.TableName = "Table0";
  208. dtNew2.TableName = "Table1";
  209. dz.Tables.Add(dtNew1.Copy());
  210. dz.Tables.Add(dtNew2.Copy());
  211. DataRelation dh = new DataRelation(RelationName, dz.Tables[0].Columns["IDs"], dz.Tables[1].Columns["IDs"]);
  212. dz.Relations.Add(dh);
  213. msg = DBHelper.DataSetToJson(dz, RelationName);
  214. return msg;
  215. }
  216. /// <summary>
  217. /// 记录日志
  218. /// </summary>
  219. /// <param name="Bills"></param>
  220. private void LogInfo(List<ICSReturnDoc> Bills)
  221. {
  222. string HeadList = string.Empty;
  223. string BodyList = string.Empty;
  224. foreach (ICSReturnDoc head in Bills)
  225. {
  226. HeadList += "\r\n 借用单号:" + head.SourceCode + ",用户:" + head.User + ",站点:" + head.WorkPoint + "";
  227. }
  228. log.Info(HeadList);
  229. log.Info(BodyList);
  230. }
  231. }
  232. }