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.

1906 lines
105 KiB

1 month ago
  1. using Newtonsoft.Json;
  2. using Newtonsoft.Json.Linq;
  3. using NFine.Code;
  4. using NFine.Data.Extensions;
  5. using NFine.Domain._03_Entity.SRM;
  6. using NFine.Repository;
  7. using System;
  8. using System.Collections.Generic;
  9. using System.Configuration;
  10. using System.Data;
  11. using System.Data.Common;
  12. using System.Data.SqlClient;
  13. using System.IO;
  14. using System.Linq;
  15. using System.Net;
  16. using System.Text;
  17. using System.Threading.Tasks;
  18. namespace NFine.Application.PNSRM
  19. {
  20. public class PNBicDoc_SellerApp : RepositoryFactory<ICSVendor>
  21. {
  22. public string SellerSubmitOARejict(string BidCode, string WorkPoint)
  23. {
  24. string sql = "";
  25. string UserCode = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
  26. string msg = "";
  27. DataTable dt = new DataTable();
  28. var reqInterNme = "http://172.16.8.33/seeyon/rest/token/SRMTEST/25eba5c2-95e9-4bf8-92f5-0f42595255ba?loginName=" + UserCode;
  29. var responseStr = httpGet(reqInterNme);
  30. try
  31. {
  32. string Pre = "HH-SRM" + WorkPoint;
  33. string BIDCodes = GetSerialCode(WorkPoint, "ICSBidDoc", "code", Pre, 3);
  34. //JObject res = (JObject)JsonConvert.DeserializeObject(dtsql.Rows[0]["searchKey"].ToString());
  35. JObject res = (JObject)JsonConvert.DeserializeObject(responseStr);
  36. string ID = res["id"].ToString();//获取Tockn
  37. JObject resultbidUser = (JObject)JsonConvert.DeserializeObject(res["bindingUser"].ToString());
  38. string id = resultbidUser["id"].ToString(); //用户ID
  39. string departmentId = resultbidUser["departmentId"].ToString(); //部门ID
  40. string postId = resultbidUser["postId"].ToString(); //岗位ID
  41. //string Message = res["Message"].ToString();
  42. if (!string.IsNullOrWhiteSpace(ID))
  43. {
  44. NFine.Domain._03_Entity.SRM.ICSBicDocSellerOA.thirdAttachments ths = new NFine.Domain._03_Entity.SRM.ICSBicDocSellerOA.thirdAttachments();
  45. List<NFine.Domain._03_Entity.SRM.ICSBicDocSellerOA.thirdAttachments> thirdAttachments = new List<NFine.Domain._03_Entity.SRM.ICSBicDocSellerOA.thirdAttachments>();
  46. NFine.Domain._03_Entity.SRM.ICSBicDocSellerOA.datadetail dat = new NFine.Domain._03_Entity.SRM.ICSBicDocSellerOA.datadetail();
  47. NFine.Domain._03_Entity.SRM.ICSBicDocSellerOA.datass dds = new NFine.Domain._03_Entity.SRM.ICSBicDocSellerOA.datass();
  48. string sqlFile = "SELECT FileName FROM ICSBidDoc Where BidCode='" + BidCode + "'and WorkPoint='" + WorkPoint + "'";
  49. DataTable dts = SqlHelper.GetDataTableBySql(sqlFile);
  50. string fileName = dts.Rows[0]["FileName"].ToString().TrimEnd(';');
  51. string[] PrintParas = fileName.Split(';');
  52. int subReference = 0;
  53. Random rd = new Random();  //无参即为使用系统时钟为种子
  54. subReference = rd.Next();
  55. int sort = 1;
  56. string fileUrl = "";
  57. if (!string.IsNullOrWhiteSpace(fileName))
  58. {
  59. foreach (var p in PrintParas)
  60. {
  61. string filePath = System.Web.HttpContext.Current.Server.MapPath("~\\File\\ZTBFile\\" + BidCode + "\\" + p.ToString());
  62. string APIURL = "http://172.16.8.33/seeyon/rest/attachment?token=" + ID;
  63. var IDFile = UploadLog(filePath, APIURL);
  64. JObject resFile = (JObject)JsonConvert.DeserializeObject(IDFile);
  65. JArray result = (JArray)JsonConvert.DeserializeObject(resFile["atts"].ToString());
  66. foreach (var item in result)
  67. {
  68. JObject jo = (JObject)item;
  69. fileUrl = jo["fileUrl"].ToString(); //地址
  70. }
  71. //JObject result = (JObject)JsonConvert.DeserializeObject(resFile["atts"].ToString());//企业信息
  72. ths.subReference = subReference;
  73. ths.fileUrl = fileUrl;
  74. ths.sort = sort;
  75. thirdAttachments.Add(ths);
  76. sort++;
  77. }
  78. dds.thirdAttachments.Add(ths);
  79. }
  80. ICSBicDocSellerOA da = new ICSBicDocSellerOA();
  81. da.appName = "collaboration";
  82. List<NFine.Domain._03_Entity.SRM.ICSBicDocSellerOA.attachments> attachmentsdetail = new List<NFine.Domain._03_Entity.SRM.ICSBicDocSellerOA.attachments>();
  83. NFine.Domain._03_Entity.SRM.ICSBicDocSellerOA.attachments attachments = new NFine.Domain._03_Entity.SRM.ICSBicDocSellerOA.attachments();
  84. attachments.ID = "";
  85. attachmentsdetail.Add(attachments);
  86. dat.templateCode = "SRM02";
  87. dat.draft = "0";
  88. dat.relateDoc = "";//(OA 公文附件 ID,默认为空,不使用)
  89. dat.subject = "";//(OA 流程标题,默认为空,OA 端自动生成标题)
  90. sql = @"SELECT c.cvencode,c.cVenName,c.cVenRegCode,'ERP' as Source,SUM(b.CastPrice) as CastPrice,
  91. (CASE d.BidStatus WHEN '' THEN (CASE b.IsDid WHEN '1' THEN '1' WHEN '0' THEN '0' ELSE '' END) ELSE '' END) AS ISDID
  92. FROM ICSBidInfo a
  93. LEFT JOIN ICSBidInfoDetail b ON a.ID = b.InfoID and a.WorkPoint=b.WorkPoint
  94. LEFT JOIN ICSVendor c ON a.SupplierCode = c.cvencode and b.WorkPoint=c.WorkPoint
  95. LEFT JOIN ICSBidDoc d ON d.BidCode = a.BidCode and c.WorkPoint=d.WorkPoint
  96. WHERE a.BidCode='" + BidCode + @"'
  97. AND b.IsCast = 1
  98. AND a.IsSub = 1
  99. AND a.WorkPoint in ('" + WorkPoint + @"')
  100. GROUP BY c.cvencode,c.cVenName,c.cVenRegCode,d.BidStatus,b.IsDid";
  101. DataTable dtVenDor = SqlHelper.GetDataTableBySql(sql);
  102. for (int i = 0; i < dtVenDor.Rows.Count; i++)
  103. {
  104. List<NFine.Domain._03_Entity.SRM.ICSBicDocSellerOA.formson_0033> formson_0033 = new List<NFine.Domain._03_Entity.SRM.ICSBicDocSellerOA.formson_0033>();
  105. Domain._03_Entity.SRM.ICSBicDocSellerOA.formson_0033 dm0023 = new Domain._03_Entity.SRM.ICSBicDocSellerOA.formson_0033();
  106. dm0023. = dtVenDor.Rows[i]["cvencode"].ToString();
  107. dm0023. = dtVenDor.Rows[i]["cVenRegCode"].ToString();
  108. dm0023. = dtVenDor.Rows[i]["cVenName"].ToString();
  109. dm0023. = "";
  110. dm0023. = Convert.ToInt32(dtVenDor.Rows[i]["ISDID"].ToString());
  111. dm0023. = Convert.ToDecimal(dtVenDor.Rows[i]["CastPrice"].ToString());
  112. dds.formson_0033.Add(dm0023);
  113. }
  114. //string sqls = " SELECT ZBVendorCode FROM ICSBidInfoDetail WHERE BidCode='" + BidCode + "' and WorkPoint='" + WorkPoint + "'";
  115. //DataTable dtZBVendor = SqlHelper.GetDataTableBySql(sqls);
  116. sql = @"SELECT distinct a.InvCode,b.INVNAME,b.INVSTD,b.INVUOM,a.Quantity,a.DeliveryTime,a.Remark,isnull(d.CastPrice,0) as CastPrice
  117. FROM ICSBidDocBD a
  118. LEFT JOIN ICSBidDoc j on a.BidCode=j.BidCode
  119. LEFT JOIN ICSINVENTORY b ON a.InvCode=b.InvCode
  120. LEFT JOIN ICSBidInfo c ON c.BidCode = a.BidCode
  121. LEFT JOIN (
  122. SELECT X.* FROM ICSBidInfoDetail X
  123. inner JOIN (
  124. SELECT MAX(a.MTIME) AS Mtime ,a.BDID,a.MUSERName FROM ICSBidInfoDetail a
  125. --WHERE a.BDID='6e17547d-0e77-4bed-b4bf-d1fe9ed75470'
  126. GROUP BY a.BDID,a.MUSERName
  127. ) Y
  128. ON X.Mtime=Y.Mtime AND X.BDID=Y.BDID AND X.MUSERName=Y.MUSERName) d ON d.InfoID = c.ID AND d.BDID = a.ID and c.WorkPoint=d.WorkPoint
  129. LEFT JOIN ICSVendor e ON e.VenCode = c.SupplierCode
  130. LEFT JOIN Sys_SRM_User f ON f.F_VenCode = e.VenCode
  131. WHERE a.BidCode='" + BidCode + "' and a.WorkPoint='" + WorkPoint + "' AND e.cVenName=d.ZBVendorCode";
  132. DataTable dtDB = SqlHelper.GetDataTableBySql(sql);
  133. for (int i = 0; i < dtDB.Rows.Count; i++)
  134. {
  135. List<NFine.Domain._03_Entity.SRM.ICSBicDocSellerOA.formson_0032> formson_0022 = new List<NFine.Domain._03_Entity.SRM.ICSBicDocSellerOA.formson_0032>();
  136. Domain._03_Entity.SRM.ICSBicDocSellerOA.formson_0032 dm0022 = new Domain._03_Entity.SRM.ICSBicDocSellerOA.formson_0032();
  137. dm0022. = dtDB.Rows[i]["InvCode"].ToString();
  138. dm0022. = dtDB.Rows[i]["INVNAME"].ToString();
  139. dm0022. = dtDB.Rows[i]["INVSTD"].ToString();
  140. dm0022. = dtDB.Rows[i]["INVUOM"].ToString();
  141. dm0022. = Convert.ToDecimal(dtDB.Rows[i]["Quantity"].ToString());
  142. dm0022. = Convert.ToDateTime(dtDB.Rows[i]["DeliveryTime"]).ToString("yyyy-MM-dd HH:mm:ss.fff");
  143. dm0022. = dtDB.Rows[i]["Remark"].ToString();
  144. dm0022. = dtDB.Rows[i]["CastPrice"].ToString();
  145. dds.formson_0032.Add(dm0022);
  146. }
  147. sql = @"SELECT BidCode,BidName,StarTime,EndTime,b.ID,a.Remark FROM dbo.ICSBidDoc a
  148. LEFT JOIN ICSOAEnum b ON a.WorkPoint=b.WorkPoint
  149. WHERE a.BidCode='" + BidCode + "' and a.WorkPoint='" + WorkPoint + "'";
  150. DataTable dtDBDoc = SqlHelper.GetDataTableBySql(sql);
  151. Domain._03_Entity.SRM.ICSBicDocSellerOA.formmain_0031 dm0021 = new Domain._03_Entity.SRM.ICSBicDocSellerOA.formmain_0031();
  152. dm0021. = DateTime.Now.ToString("yyyy-MM-dd");
  153. dm0021. = dtDBDoc.Rows[0]["ID"].ToString();
  154. dm0021. = BIDCodes;
  155. dm0021. = id;
  156. dm0021. = departmentId;
  157. dm0021. = postId;
  158. dm0021. = dtDBDoc.Rows[0]["BidCode"].ToString();
  159. dm0021. = dtDBDoc.Rows[0]["BidName"].ToString();
  160. dm0021. = dtDBDoc.Rows[0]["ID"].ToString();
  161. dm0021. = id;
  162. dm0021. = Convert.ToDateTime(dtDBDoc.Rows[0]["StarTime"]).ToString("yyyy-MM-dd HH:mm:ss.fff");
  163. dm0021. = Convert.ToDateTime(dtDBDoc.Rows[0]["EndTime"]).ToString("yyyy-MM-dd HH:mm:ss.fff");
  164. dm0021. = "";
  165. dm0021. = "";
  166. dm0021. = dtDBDoc.Rows[0]["Remark"].ToString();
  167. dm0021. = subReference;
  168. dds.formmain_0031 = dm0021;
  169. dat.data = dds;
  170. da.data = dat;
  171. string input = JsonConvert.SerializeObject(da);
  172. //}
  173. string APIURLBid = "http://172.16.8.33/seeyon/rest/bpm/process/start?token=" + ID;
  174. string resultBid = HttpPost(APIURLBid, input);
  175. JObject resBId = (JObject)JsonConvert.DeserializeObject(resultBid);
  176. string Code = resBId["code"].ToString();//获取Tockn
  177. if (Code == "0")
  178. {
  179. sql = "Update ICSBidDoc set BidOAStatus='OA审核中' Where BidCode='" + BidCode + "'";
  180. SqlHelper.CmdExecuteNonQueryLi(sql);
  181. }
  182. else
  183. {
  184. msg = "OA上传OA失败!";
  185. }
  186. }
  187. else
  188. {
  189. msg = "获取Token失败";
  190. }
  191. }
  192. catch (Exception ex)
  193. {
  194. msg = ex.Message;
  195. }
  196. return msg;
  197. }
  198. public string GetSerialCode(string workPointCode, string tbName, string colName, string Pre, int numLen)
  199. {
  200. string sql = "EXEC Addins_GetSerialCode '{0}','{1}','{2}','{3}',{4}";
  201. sql = string.Format(sql, new object[] { workPointCode, tbName, colName, Pre, numLen });
  202. return DbHelper.ExecuteScalar(CommandType.Text, sql).ToString();
  203. }
  204. public static string HttpPost(string url, string body)
  205. {
  206. try
  207. {
  208. Encoding encoding = Encoding.UTF8;
  209. HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
  210. request.Method = "POST";
  211. request.Accept = "application/json, text/javascript, */*"; //"text/html, application/xhtml+xml, */*";
  212. request.ContentType = "application/json; charset=utf-8";
  213. byte[] buffer = encoding.GetBytes(body);
  214. request.ContentLength = buffer.Length;
  215. request.GetRequestStream().Write(buffer, 0, buffer.Length);
  216. HttpWebResponse response = (HttpWebResponse)request.GetResponse();
  217. using (StreamReader reader = new StreamReader(response.GetResponseStream(), encoding))
  218. {
  219. return reader.ReadToEnd();
  220. }
  221. }
  222. catch (WebException ex)
  223. {
  224. throw new Exception(ex.Message);
  225. }
  226. }
  227. /// <summary>
  228. /// Http Get请求
  229. /// </summary>
  230. /// <param name="url"></param>
  231. /// <param name="headerValue"></param>
  232. /// <returns></returns>
  233. static String httpGet(string url)
  234. {
  235. HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
  236. WebHeaderCollection headers = new WebHeaderCollection();
  237. //headers.Add("Token", headerValue[0]);
  238. //headers.Add("Timespan", headerValue[1]);
  239. request.UserAgent = null;
  240. request.Headers = headers;
  241. request.Method = "GET";
  242. HttpWebResponse response = (HttpWebResponse)request.GetResponse();
  243. var httpStatusCode = (int)response.StatusCode;
  244. Console.WriteLine("返回码为 {0}", httpStatusCode);
  245. if (httpStatusCode == 200)
  246. {
  247. Stream myResponseStream = response.GetResponseStream();
  248. StreamReader myStreamReader = new StreamReader(myResponseStream, Encoding.GetEncoding("utf-8"));
  249. string retString = myStreamReader.ReadToEnd();
  250. myStreamReader.Close();
  251. myResponseStream.Close();
  252. return retString;
  253. }
  254. else
  255. {
  256. Console.WriteLine("未返回数据 {0}", httpStatusCode);
  257. throw new Exception("no data response");
  258. }
  259. }
  260. /// <summary>
  261. /// Http P0st请求
  262. /// </summary>
  263. /// <param name="url"></param>
  264. /// <param name="headerValue"></param>
  265. /// <returns></returns>
  266. public static string UploadLog(string file, string fileippath)
  267. {
  268. var uploadUrl = fileippath;
  269. HttpWebRequest request = WebRequest.Create(uploadUrl) as HttpWebRequest;
  270. request.AllowAutoRedirect = true;
  271. request.Method = "POST";
  272. //这段代码不是必须,请求头传输内容,看业务情况
  273. //request.Headers.Add("iauth", ia);//加鉴权
  274. string boundary = DateTime.Now.Ticks.ToString("X"); // 随机分隔线
  275. request.ContentType = "multipart/form-data;charset=utf-8;boundary=" + boundary;
  276. byte[] itemBoundaryBytes = Encoding.UTF8.GetBytes("\r\n--" + boundary + "\r\n");
  277. byte[] endBoundaryBytes = Encoding.UTF8.GetBytes("\r\n--" + boundary + "--\r\n");
  278. int pos = file.LastIndexOf("\\");
  279. string fileName = file.Substring(pos + 1);
  280. //请求头部信息
  281. StringBuilder sbHeader = new StringBuilder(string.Format("Content-Disposition:form-data;name=\"file\";filename=\"{0}\"\r\nContent-Type:application/octet-stream\r\n\r\n", fileName));
  282. byte[] postHeaderBytes = Encoding.UTF8.GetBytes(sbHeader.ToString());
  283. FileStream fs = new FileStream(file, FileMode.Open, FileAccess.Read);
  284. byte[] bArr = new byte[fs.Length];
  285. fs.Read(bArr, 0, bArr.Length);
  286. fs.Close();
  287. Stream postStream = request.GetRequestStream();
  288. postStream.Write(itemBoundaryBytes, 0, itemBoundaryBytes.Length);
  289. postStream.Write(postHeaderBytes, 0, postHeaderBytes.Length);
  290. postStream.Write(bArr, 0, bArr.Length);
  291. postStream.Write(endBoundaryBytes, 0, endBoundaryBytes.Length);
  292. postStream.Close();
  293. HttpWebResponse response = request.GetResponse() as HttpWebResponse;
  294. Stream instream = response.GetResponseStream();
  295. StreamReader sr = new StreamReader(instream, Encoding.UTF8);
  296. string content = sr.ReadToEnd();
  297. return content;
  298. }
  299. public DataTable GetGridJson(string queryJson, ref Pagination jqgridparam)
  300. {
  301. DataTable dt = new DataTable();
  302. var queryParam = queryJson.ToJObject();
  303. List<DbParameter> parameter = new List<DbParameter>();
  304. string sql = @"SELECT DISTINCT
  305. a.ID,
  306. b.ID AS IID,
  307. a.BidCode,
  308. a.BidName,
  309. a.BidUser as F_RealName,
  310. --c.F_RealName,
  311. a.StarTime ,
  312. a.EndTime,
  313. a.BidStatus ,
  314. a.Remark ,
  315. a.MTIME,
  316. b.TBCount,
  317. a.ZTBCount,
  318. --b.BidUser
  319. CASE WHEN b.IsSub=1 THEN '' ELSE '' END AS Status,
  320. CASE WHEN b.IsSub=1 THEN '' ELSE '' END AS Statuss,
  321. d.VenName AS cVenName ,
  322. b.BidTime,
  323. CASE WHEN b.IsLock = 1 THEN '是' ELSE '否' END AS IsLocks,
  324. a.WorkPoint,
  325. a.BidType
  326. FROM ICSBidDoc a
  327. LEFT JOIN ICSBidInfo b ON b.BidCode=a.BidCode and a.WorkPoint=b.WorkPoint
  328. LEFT JOIN Sys_SRM_User c ON a.BidUser=c.F_Account and b.WorkPoint=c.F_Location
  329. LEFT JOIN ICSVendor d ON b.SupplierCode=d.VenCode and c.F_Location=d.WorkPoint
  330. WHERE 1=1 and a.Status<>'0' AND a.BidStatus<>'' AND a.BidStatus<>''";
  331. if (!string.IsNullOrWhiteSpace(queryJson))
  332. {
  333. if (!string.IsNullOrWhiteSpace(queryParam["BidCode"].ToString()))
  334. {
  335. sql += " and b.BidCode like '%" + queryParam["BidCode"].ToString() + "%' ";
  336. }
  337. if (!string.IsNullOrWhiteSpace(queryParam["TimeFrom"].ToString()))
  338. {
  339. sql += " and a.StarTime >= '" + queryParam["TimeFrom"].ToString() + "' ";
  340. }
  341. if (!string.IsNullOrWhiteSpace(queryParam["TimeTo"].ToString()))
  342. {
  343. sql += " and a.EndTime <= '" + queryParam["TimeTo"].ToString() + "' ";
  344. }
  345. if (!string.IsNullOrWhiteSpace(queryParam["BidStatus"].ToString()))
  346. {
  347. sql += "and b.IsSub='" + queryParam["BidStatus"].ToString() + "'";
  348. }
  349. }
  350. if (NFine.Code.OperatorProvider.Provider.GetCurrent().RoleEnCode != "admin")
  351. {
  352. sql += " and a.WorkPoint in (" + NFine.Code.OperatorProvider.Provider.GetCurrent().Location.TrimEnd(',') + ")";
  353. }
  354. if (NFine.Code.OperatorProvider.Provider.GetCurrent().RoleEnCode.Contains("Vendor"))
  355. {
  356. sql += " and b.SupplierCode in(SELECT VenCode FROM ICSVendor where VenName ='" + NFine.Code.OperatorProvider.Provider.GetCurrent().UserName + "'AND WorkPoint=a.WorkPoint)";
  357. }
  358. return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
  359. }
  360. public DataTable GetSubGridJson(string queryJson, ref Pagination jqgridparam, string WorkPoint)
  361. {
  362. DataTable dt = new DataTable();
  363. //string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location.TrimEnd(',');
  364. List<DbParameter> parameter = new List<DbParameter>();
  365. string sql = @"SELECT distinct a.*,b.INVNAME AS InvName,b.INVSTD AS InvStd,b.INVUOM AS Unit,
  366. 'ERP'as Source FROM ICSBidDocBD a
  367. LEFT JOIN ICSInventory b ON a.InvCode = b.INVCODE
  368. WHERE a.BidCode = '{0}' and a.WorkPoint =({1})";
  369. sql = string.Format(sql, queryJson, WorkPoint);
  370. return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
  371. }
  372. public DataTable SelectColumnName(string BidCode)
  373. {
  374. string sql = @"declare @sql varchar(8000)
  375. select a.InvCode,c.VenName as SupplierCode,isnull(d.CastPrice,0) as CastPrice
  376. into #Temp
  377. from
  378. ICSBidDocBD a
  379. left join ICSBidDocGYS b on a.BidCode=b.BidCode and a.WorkPoint=b.WorkPoint
  380. left join ICSVendor c on b.SupplierCode=c.VenCode and b.WorkPoint=c.WorkPoint
  381. LEFT JOIN ICSBidInfoDetail d ON d.BDID = a.ID
  382. where a.BidCode='{0}'
  383. select distinct SupplierCode as ColCaption,SupplierCode as ColFiledName from #Temp
  384. drop table #Temp";
  385. sql = string.Format(sql, BidCode);
  386. DataTable dt = SqlHelper.GetDataTableBySql(sql);
  387. return dt;
  388. }
  389. public DataTable GetListGridJsonTOZ(string BidCode, ref Pagination jqgridparam)
  390. {
  391. DataTable dt = new DataTable();
  392. //var queryParam = queryJson.ToJObject();
  393. List<DbParameter> parameter = new List<DbParameter>();
  394. string sql = @"
  395. declare @sql varchar(8000)
  396. SELECT distinct d.BDID,a.InvCode,b.INVNAME,e.VenName as SupplierCode,isnull(d.CastPrice,0) as CastPrice,g.VendorFileName,g.BidCode,d.isCast
  397. into #Temp
  398. FROM ICSBidDocBD a
  399. LEFT JOIN ICSBidDoc g on a.BidCode=g.BidCode and a.WorkPoint=g.WorkPoint
  400. LEFT JOIN ICSINVENTORY b ON a.InvCode=b.InvCode and g.WorkPoint=b.WorkPoint
  401. LEFT JOIN ICSBidInfo c ON c.BidCode = a.BidCode and b.WorkPoint=c.WorkPoint
  402. LEFT JOIN ICSBidInfoDetail d ON d.InfoID = c.ID AND d.BDID = a.ID and c.WorkPoint=d.WorkPoint
  403. LEFT JOIN ICSVendor e ON e.VenCode = c.SupplierCode and a.WorkPoint=e.WorkPoint
  404. LEFT JOIN Sys_SRM_User f ON f.F_Account = e.VenCode
  405. where a.BidCode='{0}'
  406. select @sql=isnull(@sql+',','')+' ['+SupplierCode+']'
  407. from(select distinct SupplierCode from #Temp)as a
  408. set @sql='SELECT *,'''' as ZBVendor FROM #Temp PIVOT(MAX(CastPrice) FOR SupplierCode IN ('+@sql+'))a Where a.BDID<>'''' and a.iscast<>0'
  409. exec(@sql)
  410. ";
  411. sql = string.Format(sql, BidCode);
  412. DataTable dtr = SqlHelper.FindTablePageBySql_OtherTempByZTB(sql.ToString(), " " + "#Temp" + " ", " drop table #Temp", parameter.ToArray(), ref jqgridparam);
  413. string name = "";
  414. foreach (DataRow dr in dtr.Rows)
  415. {
  416. decimal qty = decimal.MaxValue;
  417. foreach (DataColumn col in dtr.Columns)
  418. {
  419. if (col.Caption == "InvCode" || col.Caption == "ZBVendor" || col.Caption == "INVNAME" || col.Caption == "BDID" || col.Caption == "VendorFileName" || col.Caption == "BidCode" || col.Caption == "isCast")
  420. continue;
  421. if (Convert.ToDecimal(string.IsNullOrWhiteSpace(dr[col.Caption].ToString()) ? 0 : dr[col.Caption]) < qty && Convert.ToDecimal(string.IsNullOrWhiteSpace(dr[col.Caption].ToString()) ? 0 : dr[col.Caption]) > 0)
  422. {
  423. qty = Convert.ToDecimal(dr[col.Caption]);
  424. name = col.Caption;
  425. }
  426. }
  427. dr["ZBVendor"] = name;
  428. }
  429. return dtr;
  430. //return SqlServerHelper.FindTablePageBySql_OtherTemp(sql.ToString(), parameter.ToArray(), ref jqgridparam);
  431. }
  432. public DataTable GetListGridJsonTOZSUM(string BidCode, ref Pagination jqgridparam)
  433. {
  434. string msg = string.Empty;
  435. DataTable dt = new DataTable();
  436. //var queryParam = queryJson.ToJObject();
  437. List<DbParameter> parameter = new List<DbParameter>();
  438. string sql = @"
  439. declare @sql varchar(8000)
  440. SELECT distinct d.BDID,a.InvCode,b.INVNAME,e.VenName as SupplierCode,isnull(d.CastPrice,0) as CastPrice,a.Quantity,d.isCast
  441. into #Temp
  442. FROM ICSBidDocBD a
  443. LEFT JOIN ICSINVENTORY b ON a.InvCode=b.InvCode and a.WorkPoint=b.WorkPoint
  444. LEFT JOIN ICSBidInfo c ON c.BidCode = a.BidCode and b.WorkPoint=c.WorkPoint
  445. LEFT JOIN ICSBidInfoDetail d ON d.InfoID = c.ID AND d.BDID = a.ID and c.WorkPoint=d.WorkPoint
  446. LEFT JOIN ICSVendor e ON e.VenCode = c.SupplierCode and a.WorkPoint=e.WorkPoint
  447. LEFT JOIN Sys_SRM_User f ON f.F_Account = e.VenCode
  448. where a.BidCode='{0}'
  449. select @sql=isnull(@sql+',','')+' ['+SupplierCode+']'
  450. from(select distinct SupplierCode from #Temp)as a
  451. set @sql='SELECT STUFF((select'','' + SupplierCode from (SELECT DISTINCT SupplierCode FROM #Temp where isCast=0 ) DD for xml path('''')),1,1,'''') as IsTou,* FROM #Temp PIVOT(MAX(CastPrice) FOR SupplierCode IN ('+@sql+'))a Where a.BDID<>'''' and a.iscast<>0 '
  452. exec(@sql)
  453. ";
  454. sql = string.Format(sql, BidCode);
  455. DataTable dtr = SqlHelper.FindTablePageBySql_OtherTempByZTB(sql.ToString(), " " + "#Temp" + " ", " drop table #Temp", parameter.ToArray(), ref jqgridparam);
  456. Dictionary<string, decimal> dic = new Dictionary<string, decimal>();
  457. foreach (DataRow dr in dtr.Rows)
  458. {
  459. foreach (DataColumn col in dtr.Columns)
  460. {
  461. if (col.Caption == "InvCode" || col.Caption == "ZBVendor" || col.Caption == "INVNAME" || col.Caption == "BDID" || col.Caption == "Quantity" || col.Caption == "IsTou" || col.Caption == "isCast")
  462. continue;
  463. if (dic.Keys.Contains(col.Caption))
  464. dic[col.Caption] += Convert.ToDecimal(Convert.ToDecimal(string.IsNullOrWhiteSpace(dr[col.Caption].ToString()) ? 0 : dr[col.Caption]) * Convert.ToDecimal(dr["Quantity"]));
  465. else
  466. {
  467. dic.Add(col.Caption, Convert.ToDecimal(Convert.ToDecimal(string.IsNullOrWhiteSpace(dr[col.Caption].ToString()) ? 0 : dr[col.Caption]) * Convert.ToDecimal(dr["Quantity"])));
  468. }
  469. }
  470. }
  471. if (!string.IsNullOrWhiteSpace(msg))
  472. {
  473. throw new Exception(msg);
  474. }
  475. DataRow drNew = dtr.NewRow();
  476. string name = "";
  477. decimal qty = decimal.MaxValue;
  478. foreach (var item in dic)
  479. {
  480. drNew[item.Key] = item.Value;
  481. if (Convert.ToDecimal(item.Value) < qty && Convert.ToDecimal(item.Value) > 0)
  482. {
  483. qty = Convert.ToDecimal(item.Value);
  484. name = item.Key;
  485. }
  486. }
  487. DataColumn dataColumn = new DataColumn("ZBVendor", typeof(string));
  488. dataColumn.DefaultValue = name; //为列设置默认值
  489. dtr.Columns.Add(dataColumn);
  490. dtr.Rows.Add(drNew);
  491. return dtr;
  492. //return SqlServerHelper.FindTablePageBySql_OtherTemp(sql.ToString(), parameter.ToArray(), ref jqgridparam);
  493. }
  494. //public DataTable GetICSBidDoc(string BidCode, string WorkPoint)
  495. //{
  496. // string sql = @"SELECT * FROM ICSBidDoc WHERE BidCode = '{0}' and WorkPoint='{1}'";
  497. // sql = string.Format(sql, BidCode, WorkPoint);
  498. // return Repository().FindTableBySql(sql.ToString());
  499. //}
  500. public DataTable SearchBidDocBDInfoByBidCodeSeller(string BidCode, string WorkPoint, ref Pagination jqgridparam)
  501. {
  502. string UserCode = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName;
  503. string sql = @"SELECT distinct a.ID,
  504. a.BidCode,
  505. a.RowNo,
  506. a.Quantity,
  507. a.DeliveryTime,
  508. a.InvCode,
  509. b.INVNAME AS InvName
  510. ,b.INVSTD AS InvStd,
  511. b.InvUnit AS Unit,
  512. 'ERP'as Source ,
  513. case When IsCast=1 Then '是' When IsCast is null Then '是' Else '否' END as IsCast,
  514. isnull(d.CastPrice,0) as CastPrice ,
  515. c.ID AS IID,isnull(d.ID,'') AS DID,
  516. n.RowNum AS Ranking,
  517. a.ENTTRIBUTE1,
  518. d.ENTTRIBUTE1 AS Remark,
  519. a.ItemType,
  520. a.Remark as Remarks,
  521. isnull(d.CastPrice,0) as CastPriceHidd,
  522. c.TBCount,j.FileName,
  523. d.WSCastPrice,
  524. d.TaxAmount,
  525. d.Currency,
  526. d.MinPackQuantity,
  527. d.MOQ,
  528. d.Futures,
  529. d.VenFullName,
  530. d.Purchaser,
  531. d.Origin,
  532. d.DailyMetalPrices,
  533. d.ProcessingFee,
  534. d.ExchangeRate,
  535. d.Tariff,
  536. d.VAT,
  537. d.TransportFee,
  538. d.TradeMethod
  539. FROM ICSBidDocBD a
  540. LEFT JOIN ICSBidDoc j on a.BidCode=j.BidCode
  541. LEFT JOIN ICSINVENTORY b ON a.InvCode=b.InvCode
  542. LEFT JOIN ICSBidInfo c ON c.BidCode = a.BidCode
  543. LEFT JOIN (
  544. SELECT X.* FROM ICSBidInfoDetail X
  545. inner JOIN (
  546. SELECT MAX(a.MTIME) AS Mtime ,a.BDID,a.MUSERName FROM ICSBidInfoDetail a
  547. --WHERE a.BDID='6e17547d-0e77-4bed-b4bf-d1fe9ed75470'
  548. GROUP BY a.BDID,a.MUSERName
  549. ) Y
  550. ON X.Mtime=Y.Mtime AND X.BDID=Y.BDID AND X.MUSERName=Y.MUSERName) d ON d.InfoID = c.ID AND d.BDID = a.ID and c.WorkPoint=d.WorkPoint
  551. LEFT JOIN ICSVendor e ON e.VenCode = c.SupplierCode
  552. LEFT JOIN Sys_SRM_User f ON f.F_VenCode = e.VenCode
  553. LEFT JOIN
  554. (SELECT ROW_NUMBER () OVER (partition BY m.ID ORDER BY m.CastPrice*m.Quantity) AS RowNum,m.CastPrice,m.ID FROM
  555. (
  556. SELECT DISTINCT z.CastPrice,x.ID,x.Quantity
  557. FROM ICSBidDocBD x
  558. LEFT JOIN ICSBidInfo y ON x.BidCode = y.BidCode
  559. LEFT JOIN ICSBidInfoDetail z ON x.ID = z.BDID AND y.ID = z.InfoID
  560. WHERE z.CastPrice IS NOT NULL AND z.CastPrice <> 0
  561. AND z.IsCast = 1 AND y.IsSub = 1
  562. ) m
  563. ) n ON n.CastPrice = d.CastPrice AND n.ID = a.ID
  564. WHERE a.WorkPoint = '{0}' AND c.BidCode='{2}' AND f.F_VenCode in (SELECT VenCode FROM ICSVendor where VenName ='" + NFine.Code.OperatorProvider.Provider.GetCurrent().UserName + "') and j.WorkPoint='{0}'";
  565. sql = string.Format(sql, WorkPoint, UserCode, BidCode);
  566. return Repository().FindTablePageBySql(sql.ToString(), ref jqgridparam);
  567. }
  568. public DataTable GetGridJsonBid(string queryJson, ref Pagination jqgridparam)
  569. {
  570. DataTable dt = new DataTable();
  571. var queryParam = queryJson.ToJObject();
  572. List<DbParameter> parameter = new List<DbParameter>();
  573. string sql = @"SELECT DISTINCT
  574. a.ID,
  575. a.BidCode,
  576. a.BidName,
  577. a.BidUser AS ZUser,
  578. --b.F_RealName as ZUser,
  579. a.StarTime,
  580. a.EndTime,
  581. a.BidStatus,
  582. a.BidStatus as BidStatuss,
  583. a.Remark ,
  584. --Tenders AS ,
  585. c.F_RealName AS KUser,
  586. a.OpenTime,
  587. a.BidUser AS JUser,
  588. a.BidTime,
  589. a.WorkPoint
  590. FROM ICSBidDoc a
  591. LEFT JOIN Sys_SRM_User b ON a.BidUser=b.F_Account
  592. LEFT JOIN Sys_SRM_User c ON a.Tenders=c.F_Account
  593. LEFT JOIN ICSVendor d ON a.Bidder = d.VenCode
  594. WHERE 1=1 and a.Status<>'0' ";
  595. if (!string.IsNullOrWhiteSpace(queryJson))
  596. {
  597. if (!string.IsNullOrWhiteSpace(queryParam["BidCode"].ToString()))
  598. {
  599. sql += " and a.BidCode like '%" + queryParam["BidCode"].ToString() + "%' ";
  600. }
  601. if (!string.IsNullOrWhiteSpace(queryParam["TimeFrom"].ToString()))
  602. {
  603. sql += " and a.StarTime >= '" + queryParam["TimeFrom"].ToString() + "' ";
  604. }
  605. if (!string.IsNullOrWhiteSpace(queryParam["TimeTo"].ToString()))
  606. {
  607. sql += " and a.EndTime <= '" + queryParam["TimeTo"].ToString() + "' ";
  608. }
  609. if (!string.IsNullOrWhiteSpace(queryParam["BidStatus"].ToString()))
  610. {
  611. //if (queryParam["BidStatus"].ToString() == "已结束")
  612. //{
  613. sql += " and a.BidStatus ='" + queryParam["BidStatus"].ToString() + "'";
  614. //}
  615. //else if (queryParam["BidStatus"].ToString() == "已保存" || queryParam["BidStatus"].ToString() == "招标中" || queryParam["BidStatus"].ToString() == "已关闭")
  616. //{
  617. // sql += " and (a.BidStatus ='" + queryParam["BidStatus"].ToString() + "' and a.BidTime IS NOT NULL) ";
  618. //}
  619. //else if (queryParam["BidStatus"].ToString() == "已决标")
  620. //{
  621. // sql += " and (a.BidStatus ='" + queryParam["BidStatus"].ToString() + "' and a.BidTime IS NOT NULL) ";
  622. //}
  623. }
  624. }
  625. if (NFine.Code.OperatorProvider.Provider.GetCurrent().RoleEnCode != "admin")
  626. {
  627. sql += " and a.WorkPoint in (" + NFine.Code.OperatorProvider.Provider.GetCurrent().Location.TrimEnd(',') + ")";
  628. }
  629. if (NFine.Code.OperatorProvider.Provider.GetCurrent().RoleEnCode.Contains("Vendor"))
  630. {
  631. sql += " and d.UserName in (SELECT VenCode FROM ICSVendor where VenName ='" + NFine.Code.OperatorProvider.Provider.GetCurrent().UserName + "'AND WorkPoint=a.WorkPoint)";
  632. }
  633. return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
  634. }
  635. public DataTable GetSubGridJsonBid(string queryJson, ref Pagination jqgridparam, string WorkPoint)
  636. {
  637. DataTable dt = new DataTable();
  638. //string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location.TrimEnd(',');
  639. List<DbParameter> parameter = new List<DbParameter>();
  640. string sql = @" SELECT a.ID,b.INVCODE, b.INVNAME AS InvName,b.INVStd AS InvStd,b.INVUOM AS Unit,a.Quantity ,a.DeliveryTime,'ERP'as Source,a.ENTTRIBUTE1,d.VenCode,d.VenName cVenName
  641. FROM ICSBidDocBD a
  642. LEFT JOIN ICSInventory b ON a.InvCode = b.INVCODE and a.WorkPoint=b.WorkPoint
  643. left join ICSBidDocGYS c on a.BidCode=c.BidCode and b.WorkPoint=c.WorkPoint
  644. LEFT JOIN ICSVendor d on c.SupplierCode=d.VenCode and c.WorkPoint=d.WorkPoint
  645. WHERE a.BidCode = '{0}' and a.WorkPoint = ({1})";
  646. sql = string.Format(sql, queryJson, WorkPoint);
  647. return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
  648. }
  649. public DataTable GetECNSubmitPerson(string BidCode)
  650. {
  651. string sql = @"SELECT distinct b.VenName as cVenName, b.VenName as SupplierCode
  652. from ICSBidInfo a
  653. LEFT JOIN ICSVendor b ON a.SupplierCode = b.VenCode
  654. where BidCode='{0}'";
  655. sql = string.Format(sql, BidCode);
  656. DataTable table = SqlHelper.GetDataTableBySql(sql);
  657. return table;
  658. }
  659. // public DataTable GetICSBidDocInfoSum(string BidCode, string WorkPoint)
  660. // {
  661. // string Vendor = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
  662. // DataTable dt = new DataTable();
  663. // //var queryParam = queryJson.ToJObject();
  664. // List<DbParameter> parameter = new List<DbParameter>();
  665. // string sql = @"
  666. //SELECT c.SupplierCode as SupplierCode,a.BidCode,
  667. //sum( isnull(d.CastPrice,0) *g.Quantity )as SumPrice,
  668. //ROW_NUMBER () OVER (partition BY a.BidCode ORDER BY sum( isnull(d.CastPrice,0) *g.Quantity )) AS RowNum
  669. //into #Temps
  670. //FROM ICSBidDoc a
  671. //left join ICSBidDocBD g on a.BidCode=g.BidCode and a.WorkPoint=g.WorkPoint
  672. //left JOIN ICSINVENTORY b ON g.InvCode=b.InvCode and a.WorkPoint=b.WorkPoint
  673. //left JOIN ICSBidInfo c ON c.BidCode = g.BidCode and b.WorkPoint=c.WorkPoint
  674. //left JOIN ICSBidInfoDetail d ON d.InfoID = c.ID AND d.BDID = g.ID and c.WorkPoint=d.WorkPoint
  675. //left JOIN ICSVendor e ON e.cVenCode = c.SupplierCode and d.WorkPoint=e.WorkPoint
  676. //left JOIN Sys_SRM_User f ON f.F_Account = e.cVenCode and e.WorkPoint=f.F_Location
  677. //where d.IsCast=1
  678. //group by c.SupplierCode,a.BidCode
  679. //
  680. //
  681. //SELECT distinct a.BidCode,a.BidName,a.BidUser, a.StarTime, a.EndTime, a.BidStatus, a.Remark,g.InvCode
  682. //,c.SupplierCode as SupplierCode,
  683. //isnull(d.CastPrice,0) as CastPrice,g.Quantity,h.RowNum,
  684. //case when d.IsCast=1 then sum(cast(d.IsCast as int )) else 0 end as YBBCounrt,
  685. //case when d.IsCast=0 then count(g.invCode)- sum(cast(d.IsCast as int)) else 0 end as WYBCounrt,
  686. //sum( isnull(d.CastPrice,0) *g.Quantity )as SumPrice
  687. //,(select count(*) from (SELECT distinct a.BidCode,a.BidName,a.BidUser, a.StarTime, a.EndTime, a.BidStatus, g.Remark,g.InvCode
  688. //,c.SupplierCode as SupplierCode,
  689. //isnull(d.CastPrice,0) as CastPrice,g.Quantity,
  690. //case when d.IsCast=1 then sum(cast(d.IsCast as int )) else 0 end as YBBCounrt,
  691. //case when d.IsCast=0 then count(g.invCode)- sum(cast(d.IsCast as int)) else 0 end as WYBCounrt,
  692. //sum( isnull(d.CastPrice,0) *g.Quantity )as SumPrice
  693. //FROM ICSBidDoc a
  694. //left join ICSBidDocBD g on a.BidCode=g.BidCode and a.WorkPoint=g.WorkPoint
  695. //LEFT JOIN ICSINVENTORY b ON g.InvCode=b.InvCode and a.WorkPoint=b.WorkPoint
  696. //LEFT JOIN ICSBidInfo c ON c.BidCode = g.BidCode and b.WorkPoint=c.WorkPoint
  697. //LEFT JOIN ICSBidInfoDetail d ON d.InfoID = c.ID AND d.BDID = g.ID and c.WorkPoint=d.WorkPoint
  698. //LEFT JOIN ICSVendor e ON e.cVenCode = c.SupplierCode and d.WorkPoint=e.WorkPoint
  699. //LEFT JOIN Sys_SRM_User f ON f.F_Account = e.cVenCode and e.WorkPoint=f.F_Location
  700. //where a.BidCode='{0}'and c.SupplierCode ='{1}'
  701. //group by a.BidCode,a.BidName,a.BidUser, a.StarTime, a.EndTime, a.BidStatus, g.Remark
  702. //,c.SupplierCode,d.CastPrice,g.Quantity,d.IsCast,g.InvCode
  703. //)aaa)RowCounts
  704. //FROM ICSBidDoc a
  705. //left join ICSBidDocBD g on a.BidCode=g.BidCode and a.WorkPoint=g.WorkPoint
  706. //LEFT JOIN ICSINVENTORY b ON g.InvCode=b.InvCode and a.WorkPoint=b.WorkPoint
  707. //LEFT JOIN ICSBidInfo c ON c.BidCode = g.BidCode and b.WorkPoint=c.WorkPoint
  708. //LEFT JOIN ICSBidInfoDetail d ON d.InfoID = c.ID AND d.BDID = g.ID and c.WorkPoint=d.WorkPoint
  709. //LEFT JOIN ICSVendor e ON e.cVenCode = c.SupplierCode and d.WorkPoint=e.WorkPoint
  710. //LEFT JOIN Sys_SRM_User f ON f.F_Account = e.cVenCode and e.WorkPoint=f.F_Location
  711. //LEFT JOIN #Temps h on e.cVenCode=h.SupplierCode
  712. //where a.BidCode='{0}'and c.SupplierCode ='{1}'
  713. //group by a.BidCode,a.BidName,a.BidUser, a.StarTime, a.EndTime, a.BidStatus, a.Remark
  714. //,c.SupplierCode,d.CastPrice,g.Quantity,d.IsCast,g.InvCode,h.RowNum
  715. //
  716. //drop table #Temps
  717. //";
  718. // sql = string.Format(sql, BidCode,Vendor);
  719. // DataTable dtr = SqlHelper.GetDataTableBySql(sql);
  720. // decimal qty = 0;
  721. // int Count = 0;
  722. // foreach (DataRow dr in dtr.Rows)
  723. // {
  724. // foreach (DataColumn col in dtr.Columns)
  725. // {
  726. // if (col.Caption == "YBBCounrt")
  727. // {
  728. // Count += Convert.ToInt32(dr[col.Caption]);
  729. // }
  730. // else if (col.Caption == "SumPrice")
  731. // {
  732. // qty += Convert.ToDecimal(dr[col.Caption]);
  733. // }
  734. // }
  735. // }
  736. // DataRow drNew = dtr.NewRow();
  737. // DataColumn dataColumn = new DataColumn("Zong", typeof(decimal));
  738. // dataColumn.DefaultValue = qty; //为列设置默认值
  739. // dtr.Columns.Add(dataColumn);
  740. // DataColumn dataColumns = new DataColumn("YBBCount", typeof(decimal));
  741. // dataColumns.DefaultValue = Count; //为列设置默认值
  742. // dtr.Columns.Add(dataColumns);
  743. // dtr.Rows.Add(drNew);
  744. // return dtr;
  745. //// string sql = @"SELECT ID, BidCode, BidCurrenCY, BidName, BidUser, StarTime, EndTime, BidStatus,
  746. //// BidType, Remark, Tenders, OpenTime, Bidder, BidTime, LogTime,
  747. //// LogUser, WorkPoint, MUSER, MUSERName, MTIME, ENTTRIBUTE1 from dbo.ICSBidDoc
  748. //// WHERE 1=1
  749. //// and BidCode='" + BidCode + "' and WorkPoint='" + WorkPoint + "'";
  750. //// return Repository().FindTableBySql(sql.ToString());
  751. // }
  752. /// <summary>
  753. /// 两段sql不一致不可删除 某一行 modifly 2023-02-09 lacy.xu
  754. /// </summary>
  755. /// <param name="BidCode"></param>
  756. /// <param name="WorkPoint"></param>
  757. /// <param name="Status"></param>
  758. /// <returns></returns>
  759. public DataTable GetICSBidDocInfoSum(string BidCode, string WorkPoint, string Status)
  760. {
  761. string VendorName = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName;
  762. DataTable dt = new DataTable();
  763. string sql = string.Empty;
  764. //var queryParam = queryJson.ToJObject();
  765. List<DbParameter> parameter = new List<DbParameter>();
  766. if (Status == "已投标")
  767. {
  768. sql = @"
  769. SELECT distinct a.BidCode,a.BidName,a.BidUser, a.StarTime, a.EndTime, a.BidStatus,
  770. CASE WHEN c.IsSub=1 THEN '' ELSE '' END AS Statuss,a.Remark,g.InvCode
  771. ,c.SupplierCode as SupplierCode,
  772. isnull(d.CastPrice,0) as CastPrice,g.Quantity,
  773. case when d.IsCast=1 then sum(cast(d.IsCast as int )) else 0 end as YBBCounrt,
  774. case when d.IsCast=0 then count(g.invCode)- sum(cast(d.IsCast as int)) else 0 end as WYBCounrt,
  775. sum( isnull(d.CastPrice,0) *g.Quantity )as SumPrice
  776. ,(select count(*) from (SELECT distinct a.BidCode,a.BidName,a.BidUser, a.StarTime, a.EndTime, a.BidStatus, g.Remark,g.InvCode
  777. ,c.SupplierCode as SupplierCode,
  778. isnull(d.CastPrice,0) as CastPrice,g.Quantity,
  779. case when d.IsCast=1 then sum(cast(d.IsCast as int )) else 0 end as YBBCounrt,
  780. case when d.IsCast=0 then count(g.invCode)- sum(cast(d.IsCast as int)) else 0 end as WYBCounrt,
  781. sum( isnull(d.CastPrice,0) *g.Quantity )as SumPrice
  782. FROM ICSBidDoc a
  783. left join ICSBidDocBD g on a.BidCode=g.BidCode and a.WorkPoint=g.WorkPoint
  784. LEFT JOIN ICSINVENTORY b ON g.InvCode=b.InvCode and a.WorkPoint=b.WorkPoint
  785. LEFT JOIN ICSBidInfo c ON c.BidCode = g.BidCode and a.WorkPoint=c.WorkPoint
  786. LEFT JOIN (
  787. SELECT X.* FROM ICSBidInfoDetail X
  788. inner JOIN (
  789. SELECT MAX(a.MTIME) AS Mtime ,a.BDID,a.MUSERName FROM ICSBidInfoDetail a
  790. --WHERE a.BDID='6e17547d-0e77-4bed-b4bf-d1fe9ed75470'
  791. GROUP BY a.BDID,a.MUSERName
  792. ) Y
  793. ON X.Mtime=Y.Mtime AND X.BDID=Y.BDID AND X.MUSERName=Y.MUSERName) d ON d.InfoID = c.ID AND d.BDID = g.ID and c.WorkPoint=d.WorkPoint
  794. LEFT JOIN ICSVendor e ON e.VenCode = c.SupplierCode and d.WorkPoint=e.WorkPoint
  795. LEFT JOIN Sys_SRM_User f ON f.F_Account = e.VenCode and e.WorkPoint=f.F_Location
  796. where a.BidCode='{0}'and c.SupplierCode IN(SELECT VenCode FROM ICSVendor where VenName ='{1}' AND WorkPoint=a.WorkPoint)
  797. group by a.BidCode,a.BidName,a.BidUser, a.StarTime, a.EndTime, a.BidStatus, g.Remark
  798. ,c.SupplierCode,d.CastPrice,g.Quantity,d.IsCast,g.InvCode
  799. )aaa)RowCounts
  800. into #TempOO
  801. FROM ICSBidDoc a
  802. left join ICSBidDocBD g on a.BidCode=g.BidCode and a.WorkPoint=g.WorkPoint
  803. LEFT JOIN ICSINVENTORY b ON g.InvCode=b.InvCode and a.WorkPoint=b.WorkPoint
  804. LEFT JOIN ICSBidInfo c ON c.BidCode = g.BidCode and a.WorkPoint=c.WorkPoint
  805. LEFT JOIN (
  806. SELECT X.* FROM ICSBidInfoDetail X
  807. inner JOIN (
  808. SELECT MAX(a.MTIME) AS Mtime ,a.BDID,a.MUSERName FROM ICSBidInfoDetail a
  809. --WHERE a.BDID='6e17547d-0e77-4bed-b4bf-d1fe9ed75470'
  810. GROUP BY a.BDID,a.MUSERName
  811. ) Y
  812. ON X.Mtime=Y.Mtime AND X.BDID=Y.BDID AND X.MUSERName=Y.MUSERName) d ON d.InfoID = c.ID AND d.BDID = g.ID and c.WorkPoint=d.WorkPoint
  813. LEFT JOIN ICSVendor e ON e.VenCode = c.SupplierCode and d.WorkPoint=e.WorkPoint
  814. LEFT JOIN Sys_SRM_User f ON f.F_Account = e.VenCode and e.WorkPoint=f.F_Location
  815. where a.BidCode='{0}'
  816. group by a.BidCode,a.BidName,a.BidUser, a.StarTime, a.EndTime,c.IsSub, a.BidStatus, a.Remark
  817. ,c.SupplierCode,d.CastPrice,g.Quantity,d.IsCast,g.InvCode
  818. selecT distinct oo.SupplierCode ,(select sum(Quantity* AA.CastPrice) FROM #TempOO AA WHERE AA.SupplierCode=OO.SupplierCode) Amount
  819. into #TempZZ
  820. from #TempOO OO
  821. select zz.*,
  822. row_number() over (order by zz.amount ,gg.SupplierCode) rn
  823. into #qusiba
  824. from(
  825. select distinct oo.SupplierCode
  826. from #TempOO OO
  827. where not exists(select 1 from #TempOO xx where oo.SupplierCode=xx.SupplierCode and isnull(xx.YBBCounrt,0)!='1')
  828. ) gg
  829. left join #TempZZ zz on zz.SupplierCode=gg.SupplierCode
  830. select distinct * from #TempOO yy left join #qusiba qq on yy.SupplierCode=qq.SupplierCode WHERE yy.SupplierCode IN (SELECT VenCode FROM ICSVendor where VenName ='{1}')
  831. drop table #TempOO drop table #TempZZ drop table #qusiba
  832. ";
  833. }
  834. else
  835. {
  836. sql = @"
  837. SELECT distinct a.BidCode,a.BidName,a.BidUser, a.StarTime, a.EndTime, a.BidStatus,
  838. CASE WHEN c.IsSub=1 THEN '' ELSE '' END AS Statuss,a.Remark,g.InvCode
  839. ,c.SupplierCode as SupplierCode,
  840. isnull(d.CastPrice,0) as CastPrice,g.Quantity,
  841. case when d.IsCast=1 then sum(cast(d.IsCast as int )) else 0 end as YBBCounrt,
  842. case when d.IsCast=0 then count(g.invCode)- sum(cast(d.IsCast as int)) else 0 end as WYBCounrt,
  843. sum( isnull(d.CastPrice,0) *g.Quantity )as SumPrice
  844. ,(select count(*) from (SELECT distinct a.BidCode,a.BidName,a.BidUser, a.StarTime, a.EndTime, a.BidStatus, g.Remark,g.InvCode
  845. ,c.SupplierCode as SupplierCode,
  846. isnull(d.CastPrice,0) as CastPrice,g.Quantity,
  847. case when d.IsCast=1 then sum(cast(d.IsCast as int )) else 0 end as YBBCounrt,
  848. case when d.IsCast=0 then count(g.invCode)- sum(cast(d.IsCast as int)) else 0 end as WYBCounrt,
  849. sum( isnull(d.CastPrice,0) *g.Quantity )as SumPrice
  850. FROM ICSBidDoc a
  851. left join ICSBidDocBD g on a.BidCode=g.BidCode and a.WorkPoint=g.WorkPoint
  852. LEFT JOIN ICSINVENTORY b ON g.InvCode=b.InvCode and a.WorkPoint=b.WorkPoint
  853. LEFT JOIN ICSBidInfo c ON c.BidCode = g.BidCode and a.WorkPoint=c.WorkPoint
  854. LEFT JOIN (
  855. SELECT X.* FROM ICSBidInfoDetail X
  856. inner JOIN (
  857. SELECT MAX(a.MTIME) AS Mtime ,a.BDID,a.MUSERName FROM ICSBidInfoDetail a
  858. --WHERE a.BDID='6e17547d-0e77-4bed-b4bf-d1fe9ed75470'
  859. GROUP BY a.BDID,a.MUSERName
  860. ) Y
  861. ON X.Mtime=Y.Mtime AND X.BDID=Y.BDID AND X.MUSERName=Y.MUSERName) d ON d.InfoID = c.ID AND d.BDID = g.ID and c.WorkPoint=d.WorkPoint
  862. LEFT JOIN ICSVendor e ON e.VenCode = c.SupplierCode and d.WorkPoint=e.WorkPoint
  863. LEFT JOIN Sys_SRM_User f ON f.F_Account = e.VenCode and e.WorkPoint=f.F_Location
  864. where a.BidCode='{0}'and c.SupplierCode IN (SELECT VenCode FROM ICSVendor where VenName ='{1}'AND WorkPoint=a.WorkPoint)
  865. group by a.BidCode,a.BidName,a.BidUser, a.StarTime, a.EndTime, a.BidStatus, g.Remark
  866. ,c.SupplierCode,d.CastPrice,g.Quantity,d.IsCast,g.InvCode
  867. )aaa)RowCounts
  868. into #TempOO
  869. FROM ICSBidDoc a
  870. left join ICSBidDocBD g on a.BidCode=g.BidCode and a.WorkPoint=g.WorkPoint
  871. LEFT JOIN ICSINVENTORY b ON g.InvCode=b.InvCode and a.WorkPoint=b.WorkPoint
  872. LEFT JOIN ICSBidInfo c ON c.BidCode = g.BidCode and a.WorkPoint=c.WorkPoint
  873. LEFT JOIN (
  874. SELECT X.* FROM ICSBidInfoDetail X
  875. inner JOIN (
  876. SELECT MAX(a.MTIME) AS Mtime ,a.BDID,a.MUSERName FROM ICSBidInfoDetail a
  877. --WHERE a.BDID='6e17547d-0e77-4bed-b4bf-d1fe9ed75470'
  878. GROUP BY a.BDID,a.MUSERName
  879. ) Y
  880. ON X.Mtime=Y.Mtime AND X.BDID=Y.BDID AND X.MUSERName=Y.MUSERName) d ON d.InfoID = c.ID AND d.BDID = g.ID and c.WorkPoint=d.WorkPoint
  881. LEFT JOIN ICSVendor e ON e.VenCode = c.SupplierCode and d.WorkPoint=e.WorkPoint
  882. LEFT JOIN Sys_SRM_User f ON f.F_Account = e.VenCode and e.WorkPoint=f.F_Location
  883. where a.BidCode='{0}'
  884. group by a.BidCode,a.BidName,a.BidUser, a.StarTime, a.EndTime, a.BidStatus,c.IsSub, a.Remark
  885. ,c.SupplierCode,d.CastPrice,g.Quantity,d.IsCast,g.InvCode
  886. selecT distinct oo.SupplierCode ,(select sum(Quantity* AA.CastPrice) FROM #TempOO AA WHERE AA.SupplierCode=OO.SupplierCode) Amount
  887. into #TempZZ
  888. from #TempOO OO
  889. select distinct * from #TempOO yy left join #TempZZ qq on yy.SupplierCode=qq.SupplierCode WHERE yy.SupplierCode IN (SELECT VenCode FROM ICSVendor where VenName ='{1}')
  890. drop table #TempOO drop table #TempZZ
  891. ";
  892. }
  893. sql = string.Format(sql, BidCode, VendorName);
  894. DataTable dtr = SqlHelper.GetDataTableBySql(sql);
  895. decimal qty = 0;
  896. int Count = 0;
  897. foreach (DataRow dr in dtr.Rows)
  898. {
  899. foreach (DataColumn col in dtr.Columns)
  900. {
  901. if (col.Caption == "YBBCounrt")
  902. {
  903. Count += Convert.ToInt32(dr[col.Caption]);
  904. }
  905. //else if (col.Caption == "SumPrice")
  906. //{
  907. // qty += Convert.ToDecimal(dr[col.Caption]);
  908. //}
  909. }
  910. }
  911. DataRow drNew = dtr.NewRow();
  912. //DataColumn dataColumn = new DataColumn("Zong", typeof(decimal));
  913. //dataColumn.DefaultValue = qty; //为列设置默认值
  914. //dtr.Columns.Add(dataColumn);
  915. DataColumn dataColumns = new DataColumn("YBBCount", typeof(decimal));
  916. dataColumns.DefaultValue = Count; //为列设置默认值
  917. dtr.Columns.Add(dataColumns);
  918. dtr.Rows.Add(drNew);
  919. return dtr;
  920. // string sql = @"SELECT ID, BidCode, BidCurrenCY, BidName, BidUser, StarTime, EndTime, BidStatus,
  921. // BidType, Remark, Tenders, OpenTime, Bidder, BidTime, LogTime,
  922. // LogUser, WorkPoint, MUSER, MUSERName, MTIME, ENTTRIBUTE1 from dbo.ICSBidDoc
  923. // WHERE 1=1
  924. // and BidCode='" + BidCode + "' and WorkPoint='" + WorkPoint + "'";
  925. // return Repository().FindTableBySql(sql.ToString());
  926. }
  927. public void SaveForm(ICSBidInfoDetail details)
  928. {
  929. string sql = string.Empty;
  930. bool IsDid = false;
  931. try
  932. {
  933. List<ICSBidInfoDetail> list_BD = JsonConvert.DeserializeObject<List<ICSBidInfoDetail>>(details.arrayShellFabricDetail);
  934. //List<ICSBidDocGYS> list_GYS = JsonConvert.DeserializeObject<List<ICSBidDocGYS>>(details.arrayBidDocGYS);
  935. string Muser = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
  936. string MuserName = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName;
  937. //string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location.TrimEnd(',');
  938. string connString = ConfigurationManager.ConnectionStrings["connstr"].ConnectionString;
  939. SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString);
  940. conn.Open();
  941. SqlTransaction sqlTran = conn.BeginTransaction();
  942. SqlCommand cmd = new SqlCommand();
  943. cmd.Transaction = sqlTran;
  944. cmd.Connection = conn;
  945. try
  946. {
  947. for (int i = 0; i < list_BD.Count; i++)
  948. {
  949. if (!string.IsNullOrEmpty(list_BD[i].IsDid.ToString()))
  950. IsDid = details.IsDid;
  951. sql = @"IF NOT EXISTS(SELECT * FROM dbo.ICSBidInfoDetail WHERE ID=@ID)
  952. BEGIN
  953. INSERT INTO dbo.ICSBidInfoDetail
  954. ( ID,InfoID,BDID,IsCast,CastPrice,IsDid,ENTTRIBUTE1,WorkPoint,MUSER,
  955. MUSERName,MTIME,WSCastPrice,TaxAmount,Currency,MinPackQuantity,MOQ,
  956. Futures,VenFullName,Purchaser,Origin,DailyMetalPrices,ProcessingFee,
  957. ExchangeRate,Tariff,VAT,TransportFee,TradeMethod)
  958. VALUES ( NEWID(),@InfoID,@BDID,@IsCast,@CastPrice,@IsDid ,@ENTTRIBUTE1 ,@WorkPoint, @MUSER,
  959. @MUSERName,@MTIME,@WSCastPrice,@TaxAmount,@Currency,@MinPackQuantity,@MOQ,
  960. @Futures,@VenFullName,@Purchaser,@Origin,@DailyMetalPrices,@ProcessingFee,
  961. @ExchangeRate,@Tariff,@VAT,@TransportFee,@TradeMethod)
  962. END
  963. ELSE
  964. BEGIN
  965. UPDATE dbo.ICSBidInfoDetail SET
  966. InfoID=@InfoID ,
  967. BDID=@BDID ,
  968. IsCast=@IsCast,
  969. CastPrice=@CastPrice ,
  970. IsDid=@IsDid ,
  971. ENTTRIBUTE1=@ENTTRIBUTE1,
  972. WSCastPrice=@WSCastPrice,
  973. TaxAmount=@TaxAmount,
  974. Currency=@Currency,
  975. MinPackQuantity=@MinPackQuantity,
  976. MOQ=@MOQ,
  977. Futures=@Futures,
  978. VenFullName=@VenFullName,
  979. Purchaser=@Purchaser,
  980. Origin=@Origin,
  981. DailyMetalPrices=@DailyMetalPrices,
  982. ProcessingFee=@ProcessingFee,
  983. ExchangeRate=@ExchangeRate,
  984. Tariff=@Tariff,
  985. VAT=@VAT,
  986. TransportFee=@TransportFee,
  987. TradeMethod=@TradeMethod
  988. WHERE ID=@ID
  989. END";
  990. SqlParameter[] sp_Detail = {
  991. new SqlParameter("@ID",list_BD[i].ID),
  992. new SqlParameter("@InfoID",list_BD[i].InfoID),
  993. new SqlParameter("@BDID",list_BD[i].BDID),
  994. new SqlParameter("@IsCast",list_BD[i].IsCast),
  995. new SqlParameter("@CastPrice",list_BD[i].CastPrice),
  996. new SqlParameter("@IsDid",IsDid),
  997. new SqlParameter("@ENTTRIBUTE1",list_BD[i].Remarks),
  998. new SqlParameter("@WorkPoint",list_BD[i].WorkPoint),
  999. new SqlParameter("@MUSER",Muser),
  1000. new SqlParameter("@MUSERName",MuserName),
  1001. //new SqlParameter("@Remark",list_BD[i].Remarks),
  1002. new SqlParameter("@MTIME",DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")),
  1003. new SqlParameter("@WSCastPrice",list_BD[i].WSCastPrice),
  1004. new SqlParameter("@TaxAmount",list_BD[i].TaxAmount),
  1005. new SqlParameter("@Currency",list_BD[i].Currency),
  1006. new SqlParameter("@MinPackQuantity",list_BD[i].MinPackQuantity),
  1007. new SqlParameter("@MOQ",list_BD[i].MOQ),
  1008. new SqlParameter("@Futures",list_BD[i].Futures),
  1009. new SqlParameter("@VenFullName",list_BD[i].VenFullName),
  1010. new SqlParameter("@Purchaser",list_BD[i].Purchaser),
  1011. new SqlParameter("@Origin",list_BD[i].Origin),
  1012. new SqlParameter("@DailyMetalPrices",list_BD[i].DailyMetalPrices),
  1013. new SqlParameter("@ProcessingFee",list_BD[i].ProcessingFee),
  1014. new SqlParameter("@ExchangeRate",list_BD[i].ExchangeRate),
  1015. new SqlParameter("@Tariff",list_BD[i].Tariff),
  1016. new SqlParameter("@VAT",list_BD[i].VAT),
  1017. new SqlParameter("@TransportFee",list_BD[i].TransportFee),
  1018. new SqlParameter("@TradeMethod",list_BD[i].TradeMethod),
  1019. };
  1020. SqlCommandHelper.CmdExecuteNonQuery(sql, sp_Detail, cmd);
  1021. }
  1022. #region 标案状态变更记录
  1023. sql = @"
  1024. INSERT INTO dbo.ICSBidLog
  1025. ( ID, BidCode, LogType, LogDes, LogTime, LogUser, WorkPoint, MUSER, MUSERName, MTIME )
  1026. VALUES ( NEWID(), @BidCode, @LogType , @LogDes , getdate() , @LogUser , @WorkPoint ,@MUSER , @MUSERName , getdate())";
  1027. SqlParameter[] sp_BidLog = {
  1028. //new SqlParameter("@ID","NEWID()"),
  1029. new SqlParameter("@BidCode", list_BD[0].BidCode),
  1030. new SqlParameter("@LogType", "企业"),
  1031. new SqlParameter("@LogDes", "招标书-变更"),
  1032. new SqlParameter("@LogUser", Muser),
  1033. new SqlParameter("@WorkPoint", details.WorkPoint),
  1034. new SqlParameter("@MUSER", Muser),
  1035. new SqlParameter("@MUSERName", MuserName)
  1036. };
  1037. SqlCommandHelper.CmdExecuteNonQuery(sql, sp_BidLog, cmd);
  1038. #endregion
  1039. string sqls = @"SELECT
  1040. a.BDID,
  1041. a.IsCast,
  1042. a.CastPrice,
  1043. a.WSCastPrice,
  1044. a.TaxAmount,
  1045. a.Currency,
  1046. a.MinPackQuantity,
  1047. a.MOQ,
  1048. a.Futures,
  1049. a.VenFullName,
  1050. a.Purchaser,
  1051. a.Origin,
  1052. a.DailyMetalPrices,
  1053. a.ProcessingFee,
  1054. a.ExchangeRate,
  1055. a.Tariff,
  1056. a.VAT,
  1057. a.TransportFee,
  1058. a.TradeMethod
  1059. FROM ICSBidInfoDetail a with (nolock)
  1060. LEFT JOIN ICSBidInfo b with (nolock) ON a.InfoID = b.ID AND a.WorkPoint=b.WorkPoint
  1061. WHERE b.BidCode = '{0}' AND b.ID = '{1}' AND a.WorkPoint ='{2}'";
  1062. sqls = string.Format(sqls, list_BD[0].BidCode, list_BD[0].InfoID, list_BD[0].WorkPoint);
  1063. DataTable dt = SqlHelper.GetDataTableBySql(sqls);
  1064. List<ICSBidInfoLog> list = new List<ICSBidInfoLog>();
  1065. //List<ICSBidInfoDetail> list_BD = JsonConvert.DeserializeObject<List<ICSBidInfoDetail>>(details.arrayShellFabricDetail);
  1066. //List<ICSBidDocGYS> list_GYS = JsonConvert.DeserializeObject<List<ICSBidDocGYS>>(details.arrayBidDocGYS);
  1067. //string Muser = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
  1068. //string MuserName = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName;
  1069. //string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location.TrimEnd(',');
  1070. if (dt != null && dt.Rows.Count > 0)
  1071. {
  1072. foreach (DataRow item in dt.Rows)
  1073. {
  1074. ICSBidInfoLog model = new ICSBidInfoLog();
  1075. model.BidCode = list_BD[0].BidCode;
  1076. model.InfoID = list_BD[0].InfoID;
  1077. model.BDID = item["BDID"].ToString();
  1078. if (!string.IsNullOrEmpty(item["IsCast"].ToString()))
  1079. model.IsCast = bool.Parse(item["IsCast"].ToString());
  1080. if (!string.IsNullOrEmpty(item["CastPrice"].ToString()))
  1081. model.CastPrice = decimal.Parse(item["CastPrice"].ToString());
  1082. if (!string.IsNullOrEmpty(item["WSCastPrice"].ToString()))
  1083. model.WSCastPrice = decimal.Parse(item["WSCastPrice"].ToString());
  1084. if (!string.IsNullOrEmpty(item["TaxAmount"].ToString()))
  1085. model.TaxAmount = int.Parse(item["TaxAmount"].ToString());
  1086. if (!string.IsNullOrEmpty(item["Currency"].ToString()))
  1087. model.Currency = item["Currency"].ToString();
  1088. if (!string.IsNullOrEmpty(item["MinPackQuantity"].ToString()))
  1089. model.MinPackQuantity = decimal.Parse(item["MinPackQuantity"].ToString());
  1090. if (!string.IsNullOrEmpty(item["MOQ"].ToString()))
  1091. model.MOQ = decimal.Parse(item["MOQ"].ToString());
  1092. if (!string.IsNullOrEmpty(item["Futures"].ToString()))
  1093. model.Futures = item["Futures"].ToString();
  1094. if (!string.IsNullOrEmpty(item["VenFullName"].ToString()))
  1095. model.VenFullName = item["VenFullName"].ToString();
  1096. if (!string.IsNullOrEmpty(item["Purchaser"].ToString()))
  1097. model.Purchaser = item["Purchaser"].ToString();
  1098. if (!string.IsNullOrEmpty(item["Origin"].ToString()))
  1099. model.Origin = item["Origin"].ToString();
  1100. if (!string.IsNullOrEmpty(item["DailyMetalPrices"].ToString()))
  1101. model.DailyMetalPrices = decimal.Parse(item["DailyMetalPrices"].ToString());
  1102. if (!string.IsNullOrEmpty(item["ProcessingFee"].ToString()))
  1103. model.ProcessingFee = decimal.Parse(item["ProcessingFee"].ToString());
  1104. if (!string.IsNullOrEmpty(item["ExchangeRate"].ToString()))
  1105. model.ExchangeRate = decimal.Parse(item["ExchangeRate"].ToString());
  1106. if (!string.IsNullOrEmpty(item["Tariff"].ToString()))
  1107. model.Tariff = decimal.Parse(item["Tariff"].ToString());
  1108. if (!string.IsNullOrEmpty(item["VAT"].ToString()))
  1109. model.VAT = decimal.Parse(item["VAT"].ToString());
  1110. if (!string.IsNullOrEmpty(item["TransportFee"].ToString()))
  1111. model.TransportFee = decimal.Parse(item["TransportFee"].ToString());
  1112. if (!string.IsNullOrEmpty(item["TradeMethod"].ToString()))
  1113. model.TradeMethod = item["TradeMethod"].ToString();
  1114. list.Add(model);
  1115. }
  1116. }
  1117. sql = @"IF EXISTS(SELECT * FROM dbo.ICSBidInfo WHERE ID=@ID and BidCode=@BidCode)
  1118. BEGIN
  1119. UPDATE dbo.ICSBidInfo SET
  1120. IsSub=@IsSub , BidUser=@BidUser ,BidTime=@BidTime
  1121. WHERE ID=@ID and BidCode=@BidCode
  1122. END ";
  1123. SqlParameter[] sp_Detailss = {
  1124. new SqlParameter("@ID",list_BD[0].InfoID),
  1125. new SqlParameter("@BidCode",list_BD[0].BidCode),
  1126. new SqlParameter("@IsSub",true),
  1127. new SqlParameter("@BidUser",Muser),
  1128. new SqlParameter("@BidTime",DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")),
  1129. };
  1130. SqlCommandHelper.CmdExecuteNonQuery(sql, sp_Detailss, cmd);
  1131. for (int i = 0; i < list.Count; i++)
  1132. {
  1133. sql = @"IF NOT EXISTS(SELECT * FROM dbo.ICSBidInfoLog WHERE ID=@ID)
  1134. BEGIN
  1135. INSERT INTO dbo.ICSBidInfoLog
  1136. ( ID,BidCode,InfoID,BDID,IsCast,CastPrice,WorkPoint,MUSER,
  1137. MUSERName,MTIME,WSCastPrice,TaxAmount,Currency,MinPackQuantity,MOQ,
  1138. Futures,VenFullName,Purchaser,Origin,DailyMetalPrices,ProcessingFee,
  1139. ExchangeRate,Tariff,VAT,TransportFee,TradeMethod)
  1140. VALUES ( NEWID(),@BidCode,@InfoID,@BDID,@IsCast,@CastPrice ,@WorkPoint, @MUSER,
  1141. @MUSERName,@MTIME,@WSCastPrice,@TaxAmount,@Currency,@MinPackQuantity,@MOQ,
  1142. @Futures,@VenFullName,@Purchaser,@Origin,@DailyMetalPrices,@ProcessingFee,
  1143. @ExchangeRate,@Tariff,@VAT,@TransportFee,@TradeMethod)
  1144. END
  1145. ELSE
  1146. BEGIN
  1147. UPDATE dbo.ICSBidInfoLog SET
  1148. BidCode=@BidCode,
  1149. InfoID=@InfoID ,
  1150. BDID=@BDID ,
  1151. IsCast=@IsCast,
  1152. CastPrice=@CastPrice,
  1153. WSCastPrice=@WSCastPrice,
  1154. TaxAmount=@TaxAmount,
  1155. Currency=@Currency,
  1156. MinPackQuantity=@MinPackQuantity,
  1157. MOQ=@MOQ,
  1158. Futures=@Futures,
  1159. VenFullName=@VenFullName,
  1160. Purchaser=@Purchaser,
  1161. Origin=@Origin,
  1162. DailyMetalPrices=@DailyMetalPrices,
  1163. ProcessingFee=@ProcessingFee,
  1164. ExchangeRate=@ExchangeRate,
  1165. Tariff=@Tariff,
  1166. VAT=@VAT,
  1167. TransportFee=@TransportFee,
  1168. TradeMethod=@TradeMethod
  1169. WHERE ID=@ID
  1170. END";
  1171. SqlParameter[] sp_Details = {
  1172. new SqlParameter("@ID",list[i].ID),
  1173. new SqlParameter("@BidCode",list[i].BidCode),
  1174. new SqlParameter("@InfoID",list[i].InfoID),
  1175. new SqlParameter("@BDID",list[i].BDID),
  1176. new SqlParameter("@IsCast",list[i].IsCast),
  1177. new SqlParameter("@CastPrice",list[i].CastPrice),
  1178. new SqlParameter("@WorkPoint",list_BD[0].WorkPoint),
  1179. new SqlParameter("@MUSER",Muser),
  1180. new SqlParameter("@MUSERName",MuserName),
  1181. new SqlParameter("@MTIME",DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")),
  1182. new SqlParameter("@WSCastPrice",list[i].WSCastPrice),
  1183. new SqlParameter("@TaxAmount",list[i].TaxAmount),
  1184. new SqlParameter("@Currency",list[i].Currency),
  1185. new SqlParameter("@MinPackQuantity",list[i].MinPackQuantity),
  1186. new SqlParameter("@MOQ",list[i].MOQ),
  1187. new SqlParameter("@Futures",list[i].Futures),
  1188. new SqlParameter("@VenFullName",list[i].VenFullName),
  1189. new SqlParameter("@Purchaser",list[i].Purchaser),
  1190. new SqlParameter("@Origin",list[i].Origin),
  1191. new SqlParameter("@DailyMetalPrices",list[i].DailyMetalPrices),
  1192. new SqlParameter("@ProcessingFee",list[i].ProcessingFee),
  1193. new SqlParameter("@ExchangeRate",list[i].ExchangeRate),
  1194. new SqlParameter("@Tariff",list[i].Tariff),
  1195. new SqlParameter("@VAT",list[i].VAT),
  1196. new SqlParameter("@TransportFee",list[i].TransportFee),
  1197. new SqlParameter("@TradeMethod",list[i].TradeMethod),
  1198. };
  1199. SqlCommandHelper.CmdExecuteNonQuery(sql, sp_Details, cmd);
  1200. }
  1201. cmd.Transaction.Commit();
  1202. }
  1203. catch (Exception ex)
  1204. {
  1205. cmd.Transaction.Rollback();
  1206. throw new Exception(ex.Message);
  1207. }
  1208. finally
  1209. {
  1210. if (conn.State == ConnectionState.Open)
  1211. {
  1212. conn.Close();
  1213. }
  1214. conn.Dispose();
  1215. }
  1216. }
  1217. catch (Exception ex)
  1218. {
  1219. throw new Exception(ex.Message);
  1220. }
  1221. }
  1222. public DataTable SearchBidDocBDInfoByBidCode(string BidCode, ref Pagination jqgridparam)
  1223. {
  1224. DataTable dt = new DataTable();
  1225. List<DbParameter> parameter = new List<DbParameter>();
  1226. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location.TrimEnd(',');
  1227. string sql = @"SELECT a.*,b.INVNAME AS InvName,b.INVSTD AS InvStd,b.INVUOM AS Unit,'ERP' as Source FROM ICSBidDocBD a
  1228. LEFT JOIN ICSInventory b ON a.InvCode = b.INVCODE and a.WorkPoint=b.WorkPoint
  1229. WHERE a.BidCode = '{0}' and a.WorkPoint in ({1})";
  1230. sql = string.Format(sql, BidCode, WorkPoint);
  1231. return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
  1232. }
  1233. public DataTable SearchBidDocGYSInfoByBidCode(string BidCode, ref Pagination jqgridparam)
  1234. {
  1235. DataTable dt = new DataTable();
  1236. List<DbParameter> parameter = new List<DbParameter>();
  1237. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location.TrimEnd(',');
  1238. string sql = @"SELECT a.*,b.VenName cVenName,'ERP' as Source FROM ICSBidDocGYS a
  1239. LEFT JOIN ICSVendor b on a.SupplierCode=b.VenCode
  1240. WHERE a.BidCode = '{0}' and a.WorkPoint in ({1})";
  1241. sql = string.Format(sql, BidCode, WorkPoint);
  1242. return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
  1243. }
  1244. public void SaveFormTiJiao(string keyValue, string BidCode, string TBCount, string WorkPoint)
  1245. {
  1246. string sql = string.Empty;
  1247. try
  1248. {
  1249. List<ICSBidInfoLog> list = new List<ICSBidInfoLog>();
  1250. //List<ICSBidInfoDetail> list_BD = JsonConvert.DeserializeObject<List<ICSBidInfoDetail>>(details.arrayShellFabricDetail);
  1251. //List<ICSBidDocGYS> list_GYS = JsonConvert.DeserializeObject<List<ICSBidDocGYS>>(details.arrayBidDocGYS);
  1252. string Muser = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
  1253. string MuserName = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName;
  1254. //string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location.TrimEnd(',');
  1255. string connString = ConfigurationManager.ConnectionStrings["connstr"].ConnectionString;
  1256. SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString);
  1257. conn.Open();
  1258. SqlTransaction sqlTran = conn.BeginTransaction();
  1259. SqlCommand cmd = new SqlCommand();
  1260. cmd.Transaction = sqlTran;
  1261. cmd.Connection = conn;
  1262. try
  1263. {
  1264. string sqls = @"SELECT
  1265. a.BDID,
  1266. a.IsCast,
  1267. a.CastPrice
  1268. FROM ICSBidInfoDetail a
  1269. LEFT JOIN ICSBidInfo b ON a.InfoID = b.ID AND a.WorkPoint=b.WorkPoint
  1270. WHERE b.BidCode = '{0}' AND b.ID = '{1}' AND a.WorkPoint ='{2}'";
  1271. sqls = string.Format(sqls, BidCode, keyValue, WorkPoint);
  1272. DataTable dt = SqlHelper.GetDataTableBySql(sqls);
  1273. if (dt != null && dt.Rows.Count > 0)
  1274. {
  1275. foreach (DataRow item in dt.Rows)
  1276. {
  1277. ICSBidInfoLog model = new ICSBidInfoLog();
  1278. model.BidCode = BidCode;
  1279. model.InfoID = keyValue;
  1280. model.BDID = item["BDID"].ToString();
  1281. if (!string.IsNullOrEmpty(item["IsCast"].ToString()))
  1282. model.IsCast = bool.Parse(item["IsCast"].ToString());
  1283. if (!string.IsNullOrEmpty(item["CastPrice"].ToString()))
  1284. model.CastPrice = decimal.Parse(item["CastPrice"].ToString());
  1285. list.Add(model);
  1286. }
  1287. }
  1288. sql = @"IF EXISTS(SELECT * FROM dbo.ICSBidInfo WHERE ID=@ID and BidCode=@BidCode)
  1289. BEGIN
  1290. UPDATE dbo.ICSBidInfo SET
  1291. IsSub=@IsSub , BidUser=@BidUser ,BidTime=@BidTime
  1292. WHERE ID=@ID and BidCode=@BidCode
  1293. END ";
  1294. SqlParameter[] sp_Detail = {
  1295. new SqlParameter("@ID",keyValue),
  1296. new SqlParameter("@BidCode",BidCode),
  1297. new SqlParameter("@IsSub",true),
  1298. new SqlParameter("@BidUser",Muser),
  1299. new SqlParameter("@BidTime",DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")),
  1300. };
  1301. SqlCommandHelper.CmdExecuteNonQuery(sql, sp_Detail, cmd);
  1302. for (int i = 0; i < list.Count; i++)
  1303. {
  1304. sql = @"IF NOT EXISTS(SELECT * FROM dbo.ICSBidInfoLog WHERE ID=@ID)
  1305. BEGIN
  1306. INSERT INTO dbo.ICSBidInfoLog
  1307. ( ID,BidCode,InfoID,BDID,IsCast,CastPrice,WorkPoint,MUSER,
  1308. MUSERName,MTIME)
  1309. VALUES ( NEWID(),@BidCode,@InfoID,@BDID,@IsCast,@CastPrice ,@WorkPoint, @MUSER,
  1310. @MUSERName,@MTIME)
  1311. END
  1312. ELSE
  1313. BEGIN
  1314. UPDATE dbo.ICSBidInfoLog SET
  1315. BidCode=@BidCode,InfoID=@InfoID ,BDID=@BDID ,IsCast=@IsCast, CastPrice=@CastPrice
  1316. WHERE ID=@ID
  1317. END";
  1318. SqlParameter[] sp_Details = {
  1319. new SqlParameter("@ID",list[i].ID),
  1320. new SqlParameter("@BidCode",list[i].BidCode),
  1321. new SqlParameter("@InfoID",list[i].InfoID),
  1322. new SqlParameter("@BDID",list[i].BDID),
  1323. new SqlParameter("@IsCast",list[i].IsCast),
  1324. new SqlParameter("@CastPrice",list[i].CastPrice),
  1325. new SqlParameter("@WorkPoint",WorkPoint),
  1326. new SqlParameter("@MUSER",Muser),
  1327. new SqlParameter("@MUSERName",MuserName),
  1328. new SqlParameter("@MTIME",DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")),
  1329. };
  1330. SqlCommandHelper.CmdExecuteNonQuery(sql, sp_Details, cmd);
  1331. }
  1332. //if (TBCount != "0")
  1333. //{
  1334. // //变更投标次数
  1335. // sql = @"Update ICSBidInfo set TBCount=TBCount-1 WHERE ID=@ID and BidCode=@BidCode";
  1336. // SqlParameter[] sp_UPdateDetail = {
  1337. // new SqlParameter("@ID",keyValue),
  1338. // new SqlParameter("@BidCode",BidCode),
  1339. //};
  1340. // SqlCommandHelper.CmdExecuteNonQuery(sql, sp_UPdateDetail, cmd);
  1341. //}
  1342. #region 标案状态变更记录
  1343. sql = @"
  1344. INSERT INTO dbo.ICSBidLog
  1345. ( ID, BidCode, LogType, LogDes, LogTime, LogUser, WorkPoint, MUSER, MUSERName, MTIME )
  1346. VALUES ( NEWID(), @BidCode, @LogType , @LogDes , getdate() , @LogUser , @WorkPoint ,@MUSER , @MUSERName , getdate())";
  1347. SqlParameter[] sp_BidLog = {
  1348. //new SqlParameter("@ID","NEWID()"),
  1349. new SqlParameter("@BidCode",BidCode),
  1350. new SqlParameter("@LogType", "企业"),
  1351. new SqlParameter("@LogDes", "招标书-提交"),
  1352. new SqlParameter("@LogUser", Muser),
  1353. new SqlParameter("@WorkPoint", WorkPoint),
  1354. new SqlParameter("@MUSER", Muser),
  1355. new SqlParameter("@MUSERName", MuserName)
  1356. };
  1357. SqlCommandHelper.CmdExecuteNonQuery(sql, sp_BidLog, cmd);
  1358. #endregion
  1359. cmd.Transaction.Commit();
  1360. }
  1361. catch (Exception ex)
  1362. {
  1363. cmd.Transaction.Rollback();
  1364. throw new Exception(ex.Message);
  1365. }
  1366. finally
  1367. {
  1368. if (conn.State == ConnectionState.Open)
  1369. {
  1370. conn.Close();
  1371. }
  1372. conn.Dispose();
  1373. }
  1374. }
  1375. catch (Exception ex)
  1376. {
  1377. throw new Exception(ex.Message);
  1378. }
  1379. }
  1380. public void SaveFormQTiJiao(string keyValue, string BidCode)
  1381. {
  1382. string sql = string.Empty;
  1383. try
  1384. {
  1385. List<ICSBidInfoLog> list = new List<ICSBidInfoLog>();
  1386. //List<ICSBidInfoDetail> list_BD = JsonConvert.DeserializeObject<List<ICSBidInfoDetail>>(details.arrayShellFabricDetail);
  1387. //List<ICSBidDocGYS> list_GYS = JsonConvert.DeserializeObject<List<ICSBidDocGYS>>(details.arrayBidDocGYS);
  1388. string Muser = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
  1389. string MuserName = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName;
  1390. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  1391. string connString = ConfigurationManager.ConnectionStrings["connstr"].ConnectionString;
  1392. SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString);
  1393. conn.Open();
  1394. SqlTransaction sqlTran = conn.BeginTransaction();
  1395. SqlCommand cmd = new SqlCommand();
  1396. cmd.Transaction = sqlTran;
  1397. cmd.Connection = conn;
  1398. try
  1399. {
  1400. sql = @"IF EXISTS(SELECT * FROM dbo.ICSBidInfo WHERE ID=@ID and BidCode=@BidCode)
  1401. BEGIN
  1402. UPDATE dbo.ICSBidInfo SET
  1403. IsSub=@IsSub , BidUser=@BidUser ,BidTime=@BidTime
  1404. WHERE ID=@ID and BidCode=@BidCode
  1405. END ";
  1406. SqlParameter[] sp_Detail = {
  1407. new SqlParameter("@ID",keyValue),
  1408. new SqlParameter("@BidCode",BidCode),
  1409. new SqlParameter("@IsSub","0"),
  1410. new SqlParameter("@BidUser",null),
  1411. new SqlParameter("@BidTime",null),
  1412. };
  1413. SqlCommandHelper.CmdExecuteNonQuery(sql, sp_Detail, cmd);
  1414. #region 标案状态变更记录
  1415. sql = @"
  1416. INSERT INTO dbo.ICSBidLog
  1417. ( ID, BidCode, LogType, LogDes, LogTime, LogUser, WorkPoint, MUSER, MUSERName, MTIME )
  1418. VALUES ( NEWID(), @BidCode, @LogType , @LogDes , getdate() , @LogUser , @WorkPoint ,@MUSER , @MUSERName , getdate())";
  1419. SqlParameter[] sp_BidLog = {
  1420. //new SqlParameter("@ID","NEWID()"),
  1421. new SqlParameter("@BidCode",BidCode),
  1422. new SqlParameter("@LogType", "企业"),
  1423. new SqlParameter("@LogDes", "招标书-取消提交"),
  1424. new SqlParameter("@LogUser", Muser),
  1425. new SqlParameter("@WorkPoint", WorkPoint),
  1426. new SqlParameter("@MUSER", Muser),
  1427. new SqlParameter("@MUSERName", MuserName)
  1428. };
  1429. SqlCommandHelper.CmdExecuteNonQuery(sql, sp_BidLog, cmd);
  1430. #endregion
  1431. cmd.Transaction.Commit();
  1432. }
  1433. catch (Exception ex)
  1434. {
  1435. cmd.Transaction.Rollback();
  1436. throw new Exception(ex.Message);
  1437. }
  1438. finally
  1439. {
  1440. if (conn.State == ConnectionState.Open)
  1441. {
  1442. conn.Close();
  1443. }
  1444. conn.Dispose();
  1445. }
  1446. }
  1447. catch (Exception ex)
  1448. {
  1449. throw new Exception(ex.Message);
  1450. }
  1451. }
  1452. public DataTable SearchBidDocBDInfoByBidCodeAndID(string BidCode, string ID, string WorkPoint)
  1453. {
  1454. WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location.TrimEnd(',');
  1455. string sql = @"SELECT a.ID,a.InvCode,b.InvName AS InvName,b.InvStd AS InvStd,b.INVUOM AS InvUnit,
  1456. a.Quantity,a.DeliveryTime,a.ENTTRIBUTE1,a.ItemType,a.Remark,c.BidCode,c.BidName
  1457. FROM ICSBidDocBD a
  1458. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode and a.WorkPoint=b.WorkPoint
  1459. LEFT JOIN ICSBidDoc c ON a.BidCode = c.BidCode and b.WorkPoint=c.WorkPoint
  1460. WHERE a.BidCode='{0}' AND a.ID ='{1}' AND a.WorkPoint in ({2})";
  1461. sql = string.Format(sql, BidCode, ID, WorkPoint);
  1462. return Repository().FindTableBySql(sql.ToString());
  1463. }
  1464. public DataTable GetBidInfoByBidCodeAndBDID(string BidCode, string ID, string WorkPoint)
  1465. {
  1466. WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location.TrimEnd(',');
  1467. string sql = @"SELECT b.ID,c.cvencode,c.VenName cVenName,'ERP' as Source,b.CastPrice,b.IsDid,a.ID AS InfoID,b.BDID,d.BidStatus,b.ENTTRIBUTE1 AS Remark,
  1468. (CASE d.BidStatus WHEN '' THEN (CASE b.IsDid WHEN '1' THEN '' WHEN '0' THEN '' ELSE '' END) ELSE '' END) AS ISDID
  1469. FROM ICSBidInfo a
  1470. LEFT JOIN ICSBidInfoDetail b ON a.ID = b.InfoID and a.WorkPoint=b.WorkPoint
  1471. LEFT JOIN ICSVendor c ON a.SupplierCode = c.cvencode and b.WorkPoint=c.WorkPoint
  1472. LEFT JOIN ICSBidDoc d ON d.BidCode = a.BidCode and c.WorkPoint=d.WorkPoint
  1473. WHERE a.BidCode='{0}' AND b.BDID='{1}'
  1474. AND b.IsCast = 1
  1475. AND a.IsSub = 1
  1476. AND a.WorkPoint in ({2})
  1477. ORDER BY c.cvencode, b.CastPrice";//AND a.IsSub = 1
  1478. sql = string.Format(sql, BidCode, ID, WorkPoint);
  1479. return Repository().FindTableBySql(sql.ToString());
  1480. }
  1481. public void SaveFormZB(ICSBidInfoDetail details)
  1482. {
  1483. string sql = string.Empty;
  1484. bool IsDid = false;
  1485. try
  1486. {
  1487. List<ICSBidInfoDetail> list = new List<ICSBidInfoDetail>();
  1488. List<ICSBidInfoDetail> list_BD = JsonConvert.DeserializeObject<List<ICSBidInfoDetail>>(details.arrayShellFabricDetail);
  1489. //List<ICSBidInfoDetail> list_BD = JsonConvert.DeserializeObject<List<ICSBidInfoDetail>>(details.arrayShellFabricDetail);
  1490. //List<ICSBidDocGYS> list_GYS = JsonConvert.DeserializeObject<List<ICSBidDocGYS>>(details.arrayBidDocGYS);
  1491. string Muser = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
  1492. string MuserName = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName;
  1493. //string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location.TrimEnd(',').Replace("'","");
  1494. string connString = ConfigurationManager.ConnectionStrings["connstr"].ConnectionString;
  1495. SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString);
  1496. conn.Open();
  1497. SqlTransaction sqlTran = conn.BeginTransaction();
  1498. SqlCommand cmd = new SqlCommand();
  1499. cmd.Transaction = sqlTran;
  1500. cmd.Connection = conn;
  1501. try
  1502. {
  1503. for (int i = 0; i < list_BD.Count; i++)
  1504. {
  1505. sql = @"SELECT * FROM ICSBidInfoDetail WHERE BDID = '{0}' and WorkPoint in ('{1}')";
  1506. sql = string.Format(sql, list_BD[i].ID, list_BD[i].WorkPoint);
  1507. DataTable dt = SqlHelper.GetDataSetBySql(sql, cmd);
  1508. if (dt != null && dt.Rows.Count > 0)
  1509. {
  1510. DataRow dr = dt.Rows[0];
  1511. ICSBidInfoDetail model = new ICSBidInfoDetail();
  1512. model.ID = dr["ID"].ToString();
  1513. model.InfoID = dr["InfoID"].ToString();
  1514. model.BDID = dr["BDID"].ToString();
  1515. model.IsCast = string.IsNullOrEmpty(dr["IsCast"].ToString()) ? false : Convert.ToBoolean(dr["IsCast"].ToString());
  1516. model.CastPrice = string.IsNullOrEmpty(dr["CastPrice"].ToString()) ? 0 : Convert.ToDecimal(dr["CastPrice"].ToString());
  1517. model.IsDid = string.IsNullOrEmpty(dr["IsDid"].ToString()) ? false : Convert.ToBoolean(dr["IsDid"].ToString());
  1518. model.WorkPoint = dr["WorkPoint"].ToString();
  1519. model.MUSER = dr["MUSER"].ToString();
  1520. model.MUSERName = dr["MUSERName"].ToString();
  1521. model.MTIME = Convert.ToDateTime(dr["MTIME"].ToString());
  1522. list.Add(model);
  1523. }
  1524. sql = @"IF EXISTS(SELECT * FROM dbo.ICSBidInfo WHERE ID=@ID and BidCode=@BidCode)
  1525. BEGIN
  1526. UPDATE dbo.ICSBidInfo SET
  1527. IsLock=@IsLock
  1528. WHERE ID=@ID and BidCode=@BidCode
  1529. END ";
  1530. SqlParameter[] sp_Detail = {
  1531. new SqlParameter("@ID",list[0].InfoID),
  1532. new SqlParameter("@BidCode",list_BD[0].BidCode),
  1533. new SqlParameter("@IsLock",true),
  1534. };
  1535. SqlCommandHelper.CmdExecuteNonQuery(sql, sp_Detail, cmd);
  1536. if (!string.IsNullOrEmpty(list_BD[i].IsDid.ToString()))
  1537. IsDid = list_BD[i].IsDid;
  1538. sql = @"IF NOT EXISTS(SELECT * FROM dbo.ICSBidInfoDetail WHERE BDID=@ID)
  1539. BEGIN
  1540. INSERT INTO dbo.ICSBidInfoDetail
  1541. ( ID,InfoID,BDID,ZBVendorCode,ENTTRIBUTE1,WorkPoint,MUSER,
  1542. MUSERName,MTIME)
  1543. VALUES ( NEWID(),@InfoID,@ID,@ZBVendorCode ,@ENTTRIBUTE1 ,@WorkPoint, @MUSER,
  1544. @MUSERName,@MTIME)
  1545. END
  1546. ELSE
  1547. BEGIN
  1548. UPDATE dbo.ICSBidInfoDetail SET
  1549. ZBVendorCode=@ZBVendorCode , ENTTRIBUTE1=@ENTTRIBUTE1
  1550. WHERE BDID=@ID
  1551. END";
  1552. SqlParameter[] sp_Details = {
  1553. new SqlParameter("@ID",list_BD[i].ID),
  1554. new SqlParameter("@InfoID",list[i].InfoID),
  1555. new SqlParameter("@BDID",list[i].BDID),
  1556. //new SqlParameter("@IsCast","1"),
  1557. //new SqlParameter("@CastPrice",list_BD[i].CastPrice),
  1558. //new SqlParameter("@IsDid",IsDid),
  1559. new SqlParameter("@ZBVendorCode",list_BD[i].ZBVendorCode),
  1560. new SqlParameter("@ENTTRIBUTE1",list_BD[i].ENTTRIBUTE1),
  1561. new SqlParameter("@WorkPoint",list_BD[i].WorkPoint),
  1562. new SqlParameter("@MUSER",Muser),
  1563. new SqlParameter("@MUSERName",MuserName),
  1564. new SqlParameter("@MTIME",DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")),
  1565. };
  1566. SqlCommandHelper.CmdExecuteNonQuery(sql, sp_Details, cmd);
  1567. #region 标案状态变更记录
  1568. sql = @"
  1569. INSERT INTO dbo.ICSBidLog
  1570. ( ID, BidCode, LogType, LogDes, LogTime, LogUser, WorkPoint, MUSER, MUSERName, MTIME )
  1571. VALUES ( NEWID(), @BidCode, @LogType , @LogDes , getdate() , @LogUser , @WorkPoint ,@MUSER , @MUSERName , getdate())";
  1572. SqlParameter[] sp_BidLog = {
  1573. //new SqlParameter("@ID","NEWID()"),
  1574. new SqlParameter("@BidCode",list_BD[0].BidCode),
  1575. new SqlParameter("@LogType", "企业"),
  1576. new SqlParameter("@LogDes", "招标书-变更"),
  1577. new SqlParameter("@LogUser", Muser),
  1578. new SqlParameter("@WorkPoint", list_BD[i].WorkPoint),
  1579. new SqlParameter("@MUSER", Muser),
  1580. new SqlParameter("@MUSERName", MuserName)
  1581. };
  1582. SqlCommandHelper.CmdExecuteNonQuery(sql, sp_BidLog, cmd);
  1583. #endregion
  1584. }
  1585. cmd.Transaction.Commit();
  1586. }
  1587. catch (Exception ex)
  1588. {
  1589. cmd.Transaction.Rollback();
  1590. throw new Exception(ex.Message);
  1591. }
  1592. finally
  1593. {
  1594. if (conn.State == ConnectionState.Open)
  1595. {
  1596. conn.Close();
  1597. }
  1598. conn.Dispose();
  1599. }
  1600. }
  1601. catch (Exception ex)
  1602. {
  1603. throw new Exception(ex.Message);
  1604. }
  1605. }
  1606. public void SaveFormTiJiaoZB(string BidCode, ICSBidInfoDetail details)
  1607. {
  1608. string sql = string.Empty;
  1609. try
  1610. {
  1611. SaveFormZB(details);
  1612. List<ICSBidInfoDetail> list_BD = JsonConvert.DeserializeObject<List<ICSBidInfoDetail>>(details.arrayShellFabricDetail);
  1613. //List<ICSBidDocGYS> list_GYS = JsonConvert.DeserializeObject<List<ICSBidDocGYS>>(details.arrayBidDocGYS);
  1614. string Muser = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
  1615. string MuserName = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName;
  1616. //string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location.TrimEnd(',').Replace("'", "");
  1617. string connString = ConfigurationManager.ConnectionStrings["connstr"].ConnectionString;
  1618. SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString);
  1619. conn.Open();
  1620. SqlTransaction sqlTran = conn.BeginTransaction();
  1621. SqlCommand cmd = new SqlCommand();
  1622. cmd.Transaction = sqlTran;
  1623. cmd.Connection = conn;
  1624. try
  1625. {
  1626. sql = @"IF EXISTS(SELECT * FROM dbo.ICSBidDoc WHERE BidCode=@BidCode)
  1627. BEGIN
  1628. UPDATE dbo.ICSBidDoc SET
  1629. LogUser=@LogUser , LogTime=@LogTime ,Bidder=@Bidder,BidTime=@BidTime,BidStatus=@BidStatus
  1630. WHERE BidCode=@BidCode
  1631. END ";
  1632. SqlParameter[] sp_Detail = {
  1633. new SqlParameter("@LogUser",Muser),
  1634. new SqlParameter("@LogTime",DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")),
  1635. new SqlParameter("@Bidder",Muser),
  1636. new SqlParameter("@BidCode",list_BD[0].BidCode),
  1637. new SqlParameter("@BidTime",DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")),
  1638. new SqlParameter("@BidStatus","已决标"),
  1639. };
  1640. SqlCommandHelper.CmdExecuteNonQuery(sql, sp_Detail, cmd);
  1641. #region 标案状态变更记录
  1642. sql = @"
  1643. INSERT INTO dbo.ICSBidLog
  1644. ( ID, BidCode, LogType, LogDes, LogTime, LogUser, WorkPoint, MUSER, MUSERName, MTIME )
  1645. VALUES ( NEWID(), @BidCode, @LogType , @LogDes , getdate() , @LogUser , @WorkPoint ,@MUSER , @MUSERName , getdate())";
  1646. SqlParameter[] sp_BidLog = {
  1647. //new SqlParameter("@ID","NEWID()"),
  1648. new SqlParameter("@BidCode",list_BD[0].BidCode),
  1649. new SqlParameter("@LogType", "企业"),
  1650. new SqlParameter("@LogDes", "招标书-决标"),
  1651. new SqlParameter("@LogUser", Muser),
  1652. new SqlParameter("@WorkPoint",list_BD[0].WorkPoint),
  1653. new SqlParameter("@MUSER", Muser),
  1654. new SqlParameter("@MUSERName", MuserName)
  1655. };
  1656. SqlCommandHelper.CmdExecuteNonQuery(sql, sp_BidLog, cmd);
  1657. #endregion
  1658. cmd.Transaction.Commit();
  1659. }
  1660. catch (Exception ex)
  1661. {
  1662. cmd.Transaction.Rollback();
  1663. throw new Exception(ex.Message);
  1664. }
  1665. finally
  1666. {
  1667. if (conn.State == ConnectionState.Open)
  1668. {
  1669. conn.Close();
  1670. }
  1671. conn.Dispose();
  1672. }
  1673. }
  1674. catch (Exception ex)
  1675. {
  1676. throw new Exception(ex.Message);
  1677. }
  1678. }
  1679. public void SaveFormQuX(string BidCode, string WorkPoint)
  1680. {
  1681. string sql = string.Empty;
  1682. try
  1683. {
  1684. //List<ICSBidInfoDetail> list_BD = JsonConvert.DeserializeObject<List<ICSBidInfoDetail>>(details.arrayShellFabricDetail);
  1685. //List<ICSBidDocGYS> list_GYS = JsonConvert.DeserializeObject<List<ICSBidDocGYS>>(details.arrayBidDocGYS);
  1686. string Muser = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
  1687. string MuserName = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName;
  1688. //string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  1689. string connString = ConfigurationManager.ConnectionStrings["connstr"].ConnectionString;
  1690. SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString);
  1691. conn.Open();
  1692. SqlTransaction sqlTran = conn.BeginTransaction();
  1693. SqlCommand cmd = new SqlCommand();
  1694. cmd.Transaction = sqlTran;
  1695. cmd.Connection = conn;
  1696. try
  1697. {
  1698. sql = @"IF EXISTS(SELECT * FROM dbo.ICSBidDoc WHERE BidCode=@BidCode)
  1699. BEGIN
  1700. UPDATE dbo.ICSBidDoc SET
  1701. LogUser=@LogUser , LogTime=@LogTime,BidStatus=@BidStatus
  1702. WHERE BidCode=@BidCode
  1703. END ";
  1704. SqlParameter[] sp_Detail = {
  1705. new SqlParameter("@LogUser",Muser),
  1706. new SqlParameter("@LogTime",DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")),
  1707. new SqlParameter("@BidCode",BidCode),
  1708. //new SqlParameter("@Bidder",Muser),
  1709. //new SqlParameter("@BidTime",DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")),
  1710. new SqlParameter("@BidStatus","已关闭"),
  1711. };
  1712. SqlCommandHelper.CmdExecuteNonQuery(sql, sp_Detail, cmd);
  1713. #region 标案状态变更记录
  1714. sql = @"
  1715. INSERT INTO dbo.ICSBidLog
  1716. ( ID, BidCode, LogType, LogDes, LogTime, LogUser, WorkPoint, MUSER, MUSERName, MTIME )
  1717. VALUES ( NEWID(), @BidCode, @LogType , @LogDes , getdate() , @LogUser , @WorkPoint ,@MUSER , @MUSERName , getdate())";
  1718. SqlParameter[] sp_BidLog = {
  1719. //new SqlParameter("@ID","NEWID()"),
  1720. new SqlParameter("@BidCode",BidCode),
  1721. new SqlParameter("@LogType", "企业"),
  1722. new SqlParameter("@LogDes", "招标书-关闭"),
  1723. new SqlParameter("@LogUser", Muser),
  1724. new SqlParameter("@WorkPoint", WorkPoint),
  1725. new SqlParameter("@MUSER", Muser),
  1726. new SqlParameter("@MUSERName", MuserName)
  1727. };
  1728. SqlCommandHelper.CmdExecuteNonQuery(sql, sp_BidLog, cmd);
  1729. #endregion
  1730. cmd.Transaction.Commit();
  1731. }
  1732. catch (Exception ex)
  1733. {
  1734. cmd.Transaction.Rollback();
  1735. throw new Exception(ex.Message);
  1736. }
  1737. finally
  1738. {
  1739. if (conn.State == ConnectionState.Open)
  1740. {
  1741. conn.Close();
  1742. }
  1743. conn.Dispose();
  1744. }
  1745. }
  1746. catch (Exception ex)
  1747. {
  1748. throw new Exception(ex.Message);
  1749. }
  1750. }
  1751. /// <summary>
  1752. /// 上传招标文件
  1753. /// </summary>
  1754. /// <param name="keyValue"></param>
  1755. /// <returns></returns>
  1756. public int UpLoadFile(string FilePath, string FileName, string BidCode)
  1757. {
  1758. DataTable dt = new DataTable();
  1759. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  1760. string Vendor = NFine.Code.OperatorProvider.Provider.GetCurrent().VenCode;
  1761. string sql = "";
  1762. sql = string.Format(@"update ICSBidDoc set VendorFileName=isnull(VendorFileName,'')+'{0}'
  1763. where BidCode='{1}'",
  1764. FilePath, BidCode);
  1765. sql += string.Format(@"update ICSBidInfo set VendorFileName=isnull(VendorFileName,'')+'{0}'
  1766. where BidCode='{1}' and SupplierCode='{2}'",
  1767. FilePath, BidCode, Vendor);
  1768. StringBuilder Str = new StringBuilder(sql);
  1769. return Repository().ExecuteBySql(Str);
  1770. }
  1771. /// <summary>
  1772. /// 获取文件名
  1773. /// </summary>
  1774. /// <param name="BidCode"></param>
  1775. /// <param name="WorkPoint"></param>
  1776. /// <returns></returns>
  1777. public DataTable GetCGFile(string BidCode, string WorkPoint)
  1778. {
  1779. DataTable dt = new DataTable();
  1780. string sql = @"SELECT Filename FROM ICSBIdDoc WHERE BIdCode='{0}' and WorkPoint='{1}'";
  1781. sql = string.Format(sql, BidCode, WorkPoint);
  1782. dt = SqlHelper.GetDataTableBySql(sql);
  1783. return dt;
  1784. }
  1785. public DataTable GetVenDorFile(string BidCode, string WorkPoint)
  1786. {
  1787. DataTable dt = new DataTable();
  1788. string sql = @"SELECT VendorFileName FROM ICSBIdDoc WHERE BIdCode='{0}' and WorkPoint='{1}'";
  1789. sql = string.Format(sql, BidCode, WorkPoint);
  1790. dt = SqlHelper.GetDataTableBySql(sql);
  1791. return dt;
  1792. }
  1793. public DataTable GetVenDorFileTB(string BidCode, string WorkPoint)
  1794. {
  1795. string Vendor = NFine.Code.OperatorProvider.Provider.GetCurrent().VenCode;
  1796. DataTable dt = new DataTable();
  1797. string sql = @"SELECT VendorFileName FROM ICSBidInfo WHERE BIdCode='{0}' and WorkPoint='{1}' and SupplierCode='{2}'";
  1798. sql = string.Format(sql, BidCode, WorkPoint, Vendor);
  1799. dt = SqlHelper.GetDataTableBySql(sql);
  1800. return dt;
  1801. }
  1802. }
  1803. }