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

498 lines
23 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
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
  1. using ICSSoft.Entity;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Data;
  5. using System.Data.SqlClient;
  6. using Newtonsoft.Json;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Threading.Tasks;
  10. using ICSSoft.Common;
  11. namespace ICSSoft.DataProject
  12. {
  13. public class CreatePOArrive
  14. {
  15. private static log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
  16. private static string connString = System.Configuration.ConfigurationManager.AppSettings["ERPConnStr"];
  17. private static string ConnStr = System.Configuration.ConfigurationManager.AppSettings["ConnStr"];
  18. private static string ERPDB = System.Configuration.ConfigurationManager.AppSettings["ERPDB"];
  19. private static string Type = System.Configuration.ConfigurationManager.AppSettings["Type"];
  20. //参数示例
  21. //[{
  22. // "ASNNO": "DN510852000001",
  23. // "WHCode": "11",
  24. // "User": "CC001",
  25. // "MTime": "2021-08-26 17:20:13",
  26. // "details": [
  27. // {
  28. // "LOTNO": "PO200219004100005",
  29. // "ReceiveQty": "2"
  30. // },{
  31. // "LOTNO": "PO200219004100001",
  32. // "ReceiveQty": "1"
  33. // }
  34. // ]
  35. //}]
  36. //返回参数
  37. //{
  38. //"Success": true,
  39. //"Message": "接口调用成功!",
  40. //"Data": null
  41. //}
  42. public string Get(List<ICSPOArrive> infos)
  43. {
  44. List<ICSPOArrive> szJson = new List<ICSPOArrive>();
  45. DataTable dt = null;
  46. string json = "";
  47. if (infos.Count <= 0)
  48. {
  49. throw new Exception("传送数据为空!");
  50. }
  51. string res = string.Empty;
  52. SqlConnection conn = new SqlConnection();
  53. SqlCommand cmd = new SqlCommand();
  54. string sql = string.Empty;
  55. foreach (ICSPOArrive info in infos)
  56. {
  57. try
  58. {
  59. connString = string.Format(connString, info.WorkPoint);
  60. conn = new System.Data.SqlClient.SqlConnection(connString);
  61. conn.Open();
  62. SqlTransaction sqlTran = conn.BeginTransaction();
  63. cmd = new SqlCommand();
  64. cmd.Transaction = sqlTran;
  65. cmd.Connection = conn;
  66. if (info.MTime < new DateTime(2000, 01, 01))
  67. throw new Exception("请输入正确的操作时间:" + info.MTime);
  68. sql = @" SELECT A.ID,A.cCode,A.cVenCode,D.cVenName,C.CDEPNAME,A.cDepCode,C.cDepName,A.cpocode,A.cMaker,A.cMakeTime,A.cverifier,A.caudittime,
  69. B.Autoid,B.irowno ,B.cInvCode ,B.INUM,B.iQuantity,B.fValidInQuan,B.iPOsID
  70. FROM PU_ArrivalVouch A
  71. INNER JOIN PU_ArrivalVouchs B ON A.ID=B.ID
  72. INNER JOIN DEPARTMENT C ON A.CDEPCODE=C.CDEPCODE
  73. INNER JOIN VENDOR D ON A.CVENCODE=D.CVENCODE WHERE 1=1 and A.iBillType=0";
  74. if (!string.IsNullOrWhiteSpace(info.DNCode))
  75. {
  76. sql += " and a.cCode='{0}'";
  77. }
  78. if (!string.IsNullOrWhiteSpace(info.MTime.ToString()))
  79. {
  80. sql += " and ISNULL(a.cModifyTime,ISNULL(a.cAuditTime, ISNULL(a.cModifyTime, a.cmaketime)))>='{1}'";
  81. }
  82. if (!string.IsNullOrWhiteSpace(info.User))
  83. {
  84. sql += "and a.CMAKER='{2}'";
  85. }
  86. sql = string.Format(sql, info.DNCode, info.MTime, info.User);
  87. dt = DBHelper.SQlReturnData(sql, cmd);
  88. json = JsonConvert.SerializeObject(dt);
  89. cmd.Transaction.Commit();
  90. }
  91. catch (Exception ex)
  92. {
  93. cmd.Transaction.Rollback();
  94. log.Error(ex.Message);
  95. throw new Exception(ex.Message);
  96. }
  97. finally
  98. {
  99. if (conn.State == ConnectionState.Open)
  100. {
  101. conn.Close();
  102. }
  103. conn.Dispose();
  104. }
  105. }
  106. return json;
  107. }
  108. /// <summary>
  109. /// 生成到货单
  110. /// </summary>
  111. /// <param name="infos"></param>
  112. /// <returns></returns>
  113. public string Create(List<ICSPOArrive> infos)
  114. {
  115. if (infos.Count <= 0)
  116. {
  117. throw new Exception("传送数据为空!");
  118. }
  119. string res = string.Empty;
  120. SqlConnection conn = new System.Data.SqlClient.SqlConnection(ConnStr);
  121. conn.Open();
  122. SqlTransaction sqlTran = conn.BeginTransaction();
  123. SqlCommand cmd = new SqlCommand();
  124. cmd.Transaction = sqlTran;
  125. cmd.Connection = conn;
  126. try
  127. {
  128. string sql = string.Empty;
  129. foreach (ICSPOArrive info in infos)
  130. {
  131. if (info.MTime < new DateTime(2000, 01, 01))
  132. throw new Exception("请输入正确的操作时间:" + info.MTime);
  133. string Lotnos = "";
  134. foreach (var detail in info.details)
  135. {
  136. sql = @"IF EXISTS(SELECT LOTNO FROM ICSASNDETAIL WHERE LOTNO='{1}' AND STNO='{2}' AND ISNULL(RECEIVEQTY,0)>0) and WorkPoint='{3}'
  137. RAISERROR('{1}',16,1)
  138. UPDATE ICSASNDETAIL SET RECEIVEQTY=ISNULL(RECEIVEQTY,0)+{0} WHERE LOTNO='{1}' AND STNO='{2}' and WorkPoint='{3}'
  139. --IF EXISTS(SELECT LOTNO FROM ICSASNDETAIL WHERE LOTNO='{1}' AND STNO='{2}' AND RECEIVEQTY>PLANQTY)
  140. -- RAISERROR('{1}',16,1)";
  141. sql = string.Format(sql, detail.Quantity, detail.LOTNO, info.ASNNO, info.WorkPoint);
  142. DBHelper.CmdExecuteNonQuery(sql, cmd, "送货单号:" + info.ASNNO + ",条码:" + detail.LOTNO + "未查询到对应数据!");
  143. Lotnos += "'" + detail.LOTNO + "',";
  144. }
  145. if (string.IsNullOrWhiteSpace(Lotnos))
  146. throw new Exception("送货单号:" + info.ASNNO + ",无条码信息!");
  147. CreatePUArrive(infos);
  148. }
  149. cmd.Transaction.Commit();
  150. return res;
  151. }
  152. catch (Exception ex)
  153. {
  154. cmd.Transaction.Rollback();
  155. log.Error(ex.Message);
  156. throw new Exception(ex.Message);
  157. }
  158. finally
  159. {
  160. if (conn.State == ConnectionState.Open)
  161. {
  162. conn.Close();
  163. }
  164. conn.Dispose();
  165. }
  166. }
  167. /// <summary>
  168. /// 回写U8到货单,
  169. /// </summary>
  170. /// <param name="cmd"></param>
  171. /// <param name="Lotnos"></param>
  172. /// <param name="info"></param>
  173. public string CreatePUArrive(List<ICSPOArrive> Bills)
  174. {
  175. string res = string.Empty;
  176. string str = "";
  177. DataTable dt = null;
  178. SqlConnection conn = new SqlConnection();
  179. SqlCommand cmd = new SqlCommand();
  180. int num = 0;
  181. foreach (ICSPOArrive head in Bills)
  182. {
  183. num = head.details.Count();
  184. }
  185. //int iBaseCodeLen = Convert.ToInt32(dic["iBaseCodeLen"].ToString());
  186. //int cVouchCodeBase = Convert.ToInt32(dic["cVouchCodeBase"].ToString());
  187. List<ICSPOArrive> datas = new List<ICSPOArrive>();
  188. string sql = "";
  189. int irowno = 0;
  190. foreach (ICSPOArrive head in Bills)
  191. {
  192. try
  193. {
  194. connString = string.Format(connString, head.WorkPoint);
  195. conn = new System.Data.SqlClient.SqlConnection(connString);
  196. conn.Open();
  197. SqlTransaction sqlTran = conn.BeginTransaction();
  198. cmd = new SqlCommand();
  199. cmd.Transaction = sqlTran;
  200. cmd.Connection = conn;
  201. string[] ss = head.WorkPoint.Split('_');
  202. ERPDB = ss[1];
  203. DateTime time = DateTime.Now;
  204. Dictionary<string, int> dic = DBHelper.GetAllCode("" + ERPDB + "", "PuArrival", "" + num + "");
  205. int iFatherId = Convert.ToInt32(dic["iFatherId"].ToString());
  206. int iChildId = Convert.ToInt32(dic["iChildId"].ToString());
  207. DateTime date = DateTime.Now;
  208. string iBaseCodeLen = DBHelper.GetAllRDCode("26", "" + time + "", "admin");
  209. string DEF_ID = DBHelper.GetDefaultTemplate(Type, cmd);
  210. #region 主表
  211. sql = @"INSERT INTO dbo.PU_ArrivalVouch
  212. (iVTid, ID, cCode, cPTCode, dDate, cVenCode, cDepCode, cPersonCode, cPayCode, cexch_name, iExchRate, iTaxRate, cMemo, cBusType, cMaker, bNegative,
  213. iDiscountTaxType, iBillType, cMakeTime, cAuditDate, caudittime, cverifier, iverifystateex, IsWfControlled, iflowid, iPrintCount, cpocode)
  214. SELECT @iVTid, @ID, @cCode, cPTCode, CONVERT(NVARCHAR(10), GETDATE(), 23), cVenCode, cDepCode, cPersonCode, cPayCode, cexch_name, nflat, iTaxRate, cMemo, '', @User, 0,
  215. iDiscountTaxType, 0, GETDATE(), CONVERT(NVARCHAR(10), GETDATE(), 23), GETDATE(), @User, 2, 0, 0, iPrintCount, cPOID
  216. FROM PO_Pomain WHERE 1=1 AND POID = @POID ";
  217. cmd.Parameters.Clear();
  218. cmd.Parameters.Add(new SqlParameter("@iVTid", DEF_ID));
  219. cmd.Parameters.Add(new SqlParameter("@ID", iFatherId));
  220. cmd.Parameters.Add(new SqlParameter("@cCode", iBaseCodeLen));
  221. cmd.Parameters.Add(new SqlParameter("@User", head.User));
  222. cmd.Parameters.Add(new SqlParameter("@POID", head.POCode));
  223. //cmd.Parameters.Add(new SqlParameter("@dDate", data.dMate));
  224. cmd.CommandText = sql;
  225. try
  226. {
  227. int count = cmd.ExecuteNonQuery();
  228. if (count <= 0)
  229. {
  230. log.Error("生成采购到货单表头失败,受影响行数<=0;");
  231. throw new Exception("生成采购到货单表头失败,受影响行数<=0;");
  232. }
  233. }
  234. catch (Exception ex)
  235. {
  236. log.Error("生成采购到货单表头失败!采购订单号:" + head.POCode + ";异常:" + ex.Message + ";SQL:\r\n" + sql, ex);
  237. throw new Exception("生成采购到货单表头失败!采购订单号:" + head.POCode + ";异常:" + ex.Message + ";SQL:\r\n" + sql, ex);
  238. }
  239. #endregion
  240. foreach (ICSPODetail body in head.details)
  241. {
  242. iChildId = iChildId - 1;
  243. int iMassDate = 0;
  244. int cMassUnit = 0;
  245. sql = @"SELECT cInvCode, ISNULL(iMassDate, 0) iMassDate, ISNULL(cMassUnit, 0) cMassUnit FROM Inventory WHERE cInvCode = '{0}' ";
  246. sql = string.Format(sql, body.InvCode);
  247. DataTable dts = DBHelper.SQlReturnData(sql, cmd);
  248. if (dts.Rows.Count == 0)
  249. {
  250. log.Error("存货档案不存在");
  251. throw new Exception("存货档案不存在");
  252. }
  253. else
  254. {
  255. iMassDate = Convert.ToInt16(dts.Rows[0]["iMassDate"].ToString());
  256. cMassUnit = Convert.ToInt16(dts.Rows[0]["cMassUnit"].ToString());
  257. }
  258. irowno += 1;
  259. sql = @"
  260. INSERT INTO dbo.PU_ArrivalVouchs
  261. (Autoid, ID, cInvCode, iQuantity, iOriCost, iOriTaxCost, iOriMoney, iOriTaxPrice, iOriSum, iCost, iMoney, iTaxPrice, iSum, iTaxRate,
  262. iPOsID, fValidInQuan, fRealQuantity, fValidQuantity, fRetQuantity, fInValidInQuan, bGsp, fValidNum, fValidInNum, fRealNum, bTaxCost,
  263. SoType, fInvalidInNum, iinvexchrate, cordercode, RejectSource, iExpiratDateCalcu, iordertype, ivouchrowno, bgift,
  264. dPDate, dVDate, imassdate, cmassunit, cExpirationdate, cFree1, cFree2, cFree3, cFree4, cFree5, cFree6, cFree7, cFree8,
  265. cBatch, cDefine37, fKPQuantity, finValidQuantity, fRefuseQuantity, iProductType,bexigency)
  266. SELECT @Autoid, @ID, @cInvCode, @iQuantity,pd.iUnitPrice,pd.iTaxPrice,round((pd.iTaxPrice*@iQuantity)/(1+pd.iPerTaxRate/100),2),
  267. round(pd.iTaxPrice*@iQuantity,2)-round((pd.iTaxPrice*@iQuantity)/(1+pd.iPerTaxRate/100),2),round(pd.iTaxPrice*@iQuantity,2),round((pd.iTaxPrice/(1+pd.iPerTaxRate/100)*b.nflat),2),
  268. round(round((pd.iTaxPrice*@iQuantity)/(1+pd.iPerTaxRate/100),2)*b.nflat,2),
  269. round((round(pd.iTaxPrice*@iQuantity,2)-round((pd.iTaxPrice*@iQuantity)/(1+pd.iPerTaxRate/100),2))*b.nflat,2),round(round(pd.iTaxPrice*@iQuantity,2)*b.nflat,2),pd.iPerTaxRate,
  270. pd.ID, 0, @iQuantity, @iQuantity, 0, 0, 0, null, null, null, 1,
  271. 0, null, 0, @cordercode, 0, 0, 0, @ivouchrowno, 0,
  272. @dPDate, @dVDate, @imassdate, @cmassunit, null, @cFree1, @cFree2, @cFree3, @cFree4, @cFree5, @cFree6, @cFree7, @cFree8,
  273. @Batch, @cDefine37, null, null, null, null, null FROM PO_Podetails pd
  274. left join po_pomain b on pd.poid=b.poid
  275. WHERE pd.ID = @iPOsID ";
  276. cmd.Parameters.Clear();
  277. cmd.Parameters.Add(new SqlParameter("@iPOsID", body.PODetailID));
  278. cmd.Parameters.Add(new SqlParameter("@Autoid", iChildId));
  279. cmd.Parameters.Add(new SqlParameter("@ID", iFatherId));
  280. cmd.Parameters.Add(new SqlParameter("@cInvCode", body.InvCode));
  281. cmd.Parameters.Add(new SqlParameter("@iQuantity", body.Quantity));
  282. cmd.Parameters.Add(new SqlParameter("@cordercode", head.POCode));
  283. cmd.Parameters.Add(new SqlParameter("@ivouchrowno", irowno));
  284. cmd.Parameters.Add(new SqlParameter("@dPDate", head.MTime));
  285. if (cMassUnit == 1)
  286. {
  287. cmd.Parameters.Add(new SqlParameter("@dVDate", head.MTime.AddYears(iMassDate).Date));
  288. }
  289. if (cMassUnit == 2)
  290. {
  291. cmd.Parameters.Add(new SqlParameter("@dVDate", head.MTime.AddMonths(iMassDate).Date));
  292. }
  293. if (cMassUnit == 3)
  294. {
  295. cmd.Parameters.Add(new SqlParameter("@dVDate", head.MTime.AddDays(iMassDate).Date));
  296. }
  297. cmd.Parameters.Add(new SqlParameter("@dVDate", ""));
  298. cmd.Parameters.Add(new SqlParameter("@imassdate", iMassDate));
  299. cmd.Parameters.Add(new SqlParameter("@cmassunit", cMassUnit));
  300. cmd.Parameters.Add(new SqlParameter("@Batch", ""));
  301. cmd.Parameters.Add(new SqlParameter("@cDefine37", head.MTime.AddDays(1 - DateTime.Now.Day).AddMonths(1).AddSeconds(-1)));
  302. cmd.Parameters.Add(new SqlParameter("@cFree1", body.cFree1));
  303. cmd.Parameters.Add(new SqlParameter("@cFree2", body.cFree2));
  304. cmd.Parameters.Add(new SqlParameter("@cFree3", body.cFree3));
  305. cmd.Parameters.Add(new SqlParameter("@cFree4", body.cFree4));
  306. cmd.Parameters.Add(new SqlParameter("@cFree5", body.cFree5));
  307. cmd.Parameters.Add(new SqlParameter("@cFree6", body.cFree6));
  308. cmd.Parameters.Add(new SqlParameter("@cFree7", body.cFree7));
  309. cmd.Parameters.Add(new SqlParameter("@cFree8", body.cFree8));
  310. cmd.CommandText = sql;
  311. try
  312. {
  313. int count = cmd.ExecuteNonQuery();
  314. if (count <= 0)
  315. {
  316. log.Error("生成采购到货单表体失败,受影响行数<=0;");
  317. throw new Exception("生成采购到货单表体失败,受影响行数<=0;");
  318. }
  319. }
  320. catch (Exception ex)
  321. {
  322. log.Error("生成采购到货单表体失败!采购订单号:" + head.POCode + ";异常:" + ex.Message + ";SQL:\r\n" + sql, ex);
  323. throw new Exception("生成采购到货单表体失败!采购订单号:" + head.POCode + ";异常:" + ex.Message + ";SQL:\r\n" + sql, ex);
  324. }
  325. sql = string.Format(@"UPDATE B SET B.iArrMoney = ISNULL(B.iArrMoney, 0) + A.iOriSum, B.iNatArrMoney = ISNULL(B.iNatArrMoney, 0) + A.iSum
  326. FROM dbo.PU_ArrivalVouchs A LEFT JOIN dbo.PO_Podetails B ON A.iPOsID = B.ID
  327. WHERE A.Autoid = '{0}'", iChildId);
  328. cmd.CommandText = sql;
  329. cmd.ExecuteNonQuery();
  330. }
  331. sql = @"
  332. SELECT B.Autoid, A.cCode, B.ivouchrowno, A.cVenCode, D.cVenName, A.cDepCode, C.cDepName,
  333. B.cInvCode, B.iQuantity, A.cMaker, B.cBatch, A.ID, B.cordercode, B.iPOsID, A.cBusType, E.ivouchrowno PORow,
  334. B.cFree1, B.cFree2, B.cFree3, B.cFree4, B.cFree5, B.cFree6, B.cFree7, B.cFree8, B.dPDate
  335. FROM dbo.PU_ArrivalVouch A INNER JOIN dbo.PU_ArrivalVouchs B ON A.ID = B.ID
  336. LEFT JOIN dbo.Department C ON A.cDepCode = C.cDepCode LEFT JOIN dbo.Vendor D ON A.cVenCode = D.cVenCode
  337. LEFT JOIN dbo.PO_Podetails E ON B.iPOsID = E.ID WHERE A.cverifier IS NOT NULL AND A.ID = '{0}' ";
  338. sql = string.Format(sql, iFatherId);
  339. dt = DBHelper.SQlReturnData(sql, cmd);
  340. str += JsonConvert.SerializeObject(dt);
  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. }
  350. return str;
  351. }
  352. public string Approve(List<ICSPOArrive> infos)
  353. {
  354. List<ICSPOArrive> szJson = new List<ICSPOArrive>();
  355. DataTable dt = null;
  356. string json = "";
  357. if (infos.Count <= 0)
  358. {
  359. throw new Exception("传送数据为空!");
  360. }
  361. string res = string.Empty;
  362. SqlConnection conn = new SqlConnection();
  363. SqlCommand cmd = new SqlCommand();
  364. string sql = string.Empty;
  365. foreach (ICSPOArrive info in infos)
  366. {
  367. try
  368. {
  369. connString = string.Format(connString, info.WorkPoint);
  370. conn = new System.Data.SqlClient.SqlConnection(connString);
  371. conn.Open();
  372. SqlTransaction sqlTran = conn.BeginTransaction();
  373. cmd = new SqlCommand();
  374. cmd.Transaction = sqlTran;
  375. cmd.Connection = conn;
  376. if (info.MTime < new DateTime(2000, 01, 01))
  377. throw new Exception("请输入正确的操作时间:" + info.MTime);
  378. sql = @"UPDATE dbo.PU_ArrivalVouch SET cVerifier ='" + info.User + @"' ,
  379. cAuditTime=CONVERT(VARCHAR(50),GETDATE(),112),cAuditDate=GETDATE() WHERE ID='{0}'";
  380. sql = string.Format(sql, info.ID);
  381. DBHelper.CmdExecuteNonQuery(sql, cmd, "未查询到对应数据!");
  382. cmd.Transaction.Commit();
  383. }
  384. catch (Exception ex)
  385. {
  386. cmd.Transaction.Rollback();
  387. log.Error(ex.Message);
  388. throw new Exception(ex.Message);
  389. }
  390. finally
  391. {
  392. if (conn.State == ConnectionState.Open)
  393. {
  394. conn.Close();
  395. }
  396. conn.Dispose();
  397. }
  398. }
  399. return json;
  400. }
  401. /// <summary>
  402. /// 删除请购单
  403. /// </summary>
  404. /// <param name="infos"></param>
  405. /// <returns></returns>
  406. public string Delete(List<ICSPOArrive> infos)
  407. {
  408. List<ICSPOArrive> szJson = new List<ICSPOArrive>();
  409. if (infos.Count <= 0)
  410. {
  411. throw new Exception("传送数据为空!");
  412. }
  413. string res = string.Empty;
  414. SqlConnection conn = new SqlConnection();
  415. SqlCommand cmd = new SqlCommand();
  416. string sql = string.Empty;
  417. foreach (ICSPOArrive info in infos)
  418. {
  419. try
  420. {
  421. connString = string.Format(connString, info.WorkPoint);
  422. conn = new System.Data.SqlClient.SqlConnection(connString);
  423. conn.Open();
  424. SqlTransaction sqlTran = conn.BeginTransaction();
  425. cmd = new SqlCommand();
  426. cmd.Transaction = sqlTran;
  427. cmd.Connection = conn;
  428. if (info.MTime < new DateTime(2000, 01, 01))
  429. throw new Exception("请输入正确的操作时间:" + info.MTime);
  430. sql = @" DELETE dbo.PU_ArrivalVouch WHERE ID='{0}'";
  431. sql = string.Format(sql, info.ID);
  432. DBHelper.CmdExecuteNonQuery(sql, cmd, "未查询到对应数据!");
  433. cmd.Transaction.Commit();
  434. }
  435. catch (Exception ex)
  436. {
  437. cmd.Transaction.Rollback();
  438. log.Error(ex.Message);
  439. throw new Exception(ex.Message);
  440. }
  441. finally
  442. {
  443. if (conn.State == ConnectionState.Open)
  444. {
  445. conn.Close();
  446. }
  447. conn.Dispose();
  448. }
  449. }
  450. return res;
  451. }
  452. }
  453. }