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

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