uploadFile.aspx.cs 44 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081
  1. using BizCom;
  2. using ICSharpCode.SharpZipLib.Zip;
  3. using Microsoft.Win32;
  4. using SevenZip;
  5. using System;
  6. using System.Configuration;
  7. using System.Diagnostics;
  8. using System.IO;
  9. using System.Text;
  10. using System.Web;
  11. using Utils;
  12. using SiteCore;
  13. using Aspose.Imaging.ImageOptions;
  14. using Aspose.Imaging;
  15. using Microsoft.WindowsAPICodePack.Shell;
  16. using System.Drawing.Imaging;
  17. using CorelDRAW;
  18. using System.Security.Principal;
  19. using System.Threading.Tasks;
  20. using System.Data;
  21. using System.Text.RegularExpressions;
  22. using MSharp.Framework;
  23. using System.Net.Http.Headers;
  24. using System.Net.Http;
  25. using SQLData;
  26. using NHibernate.Mapping;
  27. using System.Collections.Generic;
  28. using System.Linq;
  29. public partial class uploadFile : System.Web.UI.Page
  30. {
  31. public static string upPath = ConfigurationManager.AppSettings["upPath"];
  32. public static string curPath = ConfigurationManager.AppSettings["curPath"];
  33. static CdrConvert cdrConvert = new CdrConvert();
  34. private void conSuc(string msg)
  35. {
  36. Response.Write("{\"res\":\"1\",\"msg\":\"" + msg + "!\"}");
  37. //Response.End();
  38. }
  39. private void conErc(string msg)
  40. {
  41. Response.Write("{\"res\":\"0\",\"msg\":\"" + msg + "!\"}");
  42. //Response.End();
  43. }
  44. public string GetMD5HashFromFile(HttpPostedFile file)
  45. {
  46. try
  47. {
  48. System.Security.Cryptography.MD5 md5 = new System.Security.Cryptography.MD5CryptoServiceProvider();
  49. byte[] retVal = md5.ComputeHash(file.InputStream);
  50. StringBuilder sb = new StringBuilder();
  51. for (int i = 0; i < retVal.Length; i++)
  52. {
  53. sb.Append(retVal[i].ToString("x2"));
  54. }
  55. return sb.ToString();
  56. }
  57. catch (Exception ex)
  58. {
  59. XLog.SaveLog(0, "上传MD5错误!" + ex.Message);
  60. }
  61. return "";
  62. }
  63. private static byte[] GetBlobByHttpPostedFile(HttpPostedFile httpPostedFile)
  64. {
  65. var contentLength = httpPostedFile.ContentLength;
  66. var result = new byte[contentLength];
  67. var inputStream = httpPostedFile.InputStream;
  68. inputStream.Read(result, 0, contentLength);
  69. return result;
  70. }
  71. protected void Page_Load(object sender, EventArgs e)
  72. {
  73. //if (CurrentUser == null)
  74. //{
  75. // Response.Write(err);
  76. // return;
  77. //}
  78. //CeErpTradeCell.GetByCtid("1717009344450030601");
  79. if (Request.Files.Count < 1)
  80. {
  81. conErc("空文件!");
  82. return;
  83. }
  84. int userId = 0;
  85. int orgid = 0;
  86. if (Request["userid"] != null)
  87. {
  88. userId = Convert.ToInt32(Request["userid"]);
  89. }
  90. if (Request["orgid"] != null)
  91. {
  92. orgid = Convert.ToInt32(Request["orgid"]);
  93. }
  94. HttpPostedFile postFile = Request.Files[0];
  95. if (postFile != null)
  96. {
  97. string file_name = postFile.FileName;
  98. string namePattern = @"《(.*?)》";
  99. Regex nameReg = new Regex(namePattern, RegexOptions.IgnoreCase | RegexOptions.Multiline, TimeSpan.FromSeconds(2));//2秒后超时
  100. MatchCollection nameMatches = nameReg.Matches(file_name);//设定要查找的字符串
  101. if (nameMatches.Count > 0)
  102. {
  103. foreach (Match match in nameMatches)
  104. {
  105. file_name = file_name.Replace(match.Value, "");
  106. }
  107. }
  108. file_name = file_name.Replace("(", "(");
  109. file_name = file_name.Replace(")", ")");
  110. string ctid = MidStrEx(file_name, "(", ")").Trim();
  111. if (string.IsNullOrEmpty(ctid))
  112. {
  113. conErc("上传的文件名格式不正确");
  114. return;
  115. }
  116. string memoCtid = ctid;
  117. if (ctid.IndexOf("C") == -1)
  118. {
  119. if (file_name.IndexOf("[") != -1 && file_name.IndexOf("C") != -1)
  120. {
  121. if (ctid.IndexOf("S_") != -1) // (S_S_1962772776865084101)[C1] 对应ctid是 S_S_C1_1962772776865084101
  122. {
  123. int lastIndex = ctid.LastIndexOf("S_"); //最后一个S_的位置
  124. string sPre = ctid.Substring(0, lastIndex + 2); //S_S_
  125. string initTid = ctid.Substring(lastIndex + 2, ctid.Length - lastIndex - 2); //1962772776865084101
  126. string pre_ctid = MidStrEx(file_name, "[", "]"); //C1
  127. if (pre_ctid.IndexOf("+") != -1)
  128. {
  129. pre_ctid = "C" + pre_ctid.Split('+')[1];
  130. }
  131. memoCtid = sPre + pre_ctid + "_" + initTid; //S_S_ + C1 + _ +1962772776865084101
  132. }
  133. else
  134. {
  135. string pre_ctid = MidStrEx(file_name, "[", "]");
  136. if (pre_ctid.IndexOf("+") != -1)
  137. {
  138. pre_ctid = "C" + pre_ctid.Split('+')[1];
  139. }
  140. memoCtid = pre_ctid + "_" + ctid;
  141. }
  142. }
  143. }
  144. CeErpTradeCell entity = null;
  145. if (ctid != "") entity = CeErpTradeCell.GetByCode(ctid);
  146. if (entity == null) entity = CeErpTradeCell.GetByCtid(ctid);
  147. if (entity == null) entity = CeErpTradeCell.GetByCtid(memoCtid);
  148. try
  149. {
  150. if (entity != null)
  151. {
  152. string pname = Path.GetFileNameWithoutExtension(file_name);
  153. if (entity.IsRefund == 2)
  154. {
  155. StringBuilder sql = new StringBuilder();
  156. sql.AppendFormat("select refund_status from CE_ErpTradeOrder where tid='{0}'", entity.tid);
  157. DataTable dt = CeErpTradeCell.ExecuteDataset(sql.ToString()).Tables[0];
  158. bool isAll = true;
  159. foreach (DataRow dr in dt.Rows)
  160. {
  161. if ("NO_REFUND".Equals(dr["refund_status"]))
  162. {
  163. isAll = false;
  164. break;
  165. }
  166. }
  167. if (isAll)
  168. {
  169. conErc("此单退款,不允许上传");
  170. return;
  171. }
  172. }
  173. if (entity.seller_memo != pname)
  174. {
  175. conErc("上传的文件名与备注不符合!");
  176. return;
  177. }
  178. if (entity.OrderState == -1)
  179. {
  180. conErc("还未审核不允许上传");
  181. return;
  182. }
  183. if (entity.OrderState < (int)OrderState.设计中 && orgid != 10 && orgid != 4)
  184. {
  185. conErc("还未开始设计不允许上传");
  186. return;
  187. }
  188. //if (pname.IndexOf("现货") != -1)
  189. //{
  190. // conErc("设计款的单文件名不能有现货字眼");
  191. // return;
  192. //}
  193. //更新状态
  194. if (entity.OrderState >= (int)OrderState.下单完成)
  195. {
  196. conErc("已经下单无法上传!");
  197. return;
  198. }
  199. if (entity.IsVerifyToSupplier)
  200. {
  201. conErc("订单已到车间无法上传!");
  202. return;
  203. }
  204. string extend = Path.GetExtension(file_name).ToLower();
  205. if (!(extend == ".cdr" || extend == ".zip" || extend == ".rar" || extend == ".pdf"))
  206. {
  207. conErc("只允许上传zip和cdr文件!");
  208. return;
  209. }
  210. if (entity.OrderState != 5)
  211. {
  212. entity.FinishDesignTime = DateTime.Now;
  213. if (entity.isDianziOrder == 1 || entity.ProductId == 57 || entity.ProductId == 28)
  214. {
  215. entity.OrderState = 6;
  216. entity.SupplierId = 35;
  217. entity.FinishPlaceTime = DateTime.Now;
  218. bool sendResult = commonHelper.SetOrderDummyDelivery(entity.tid);
  219. if (sendResult)
  220. {
  221. entity.OrderState = 7;
  222. }
  223. }
  224. else
  225. entity.OrderState = 5; //设计完成
  226. //if (entity.IsReturn == 2) //2是下单人打回给设计的,重新上传的话,需要清除打回
  227. //{
  228. entity.IsXianHuo = 0;
  229. entity.IsVerifyToSupplier = false;
  230. //}
  231. }
  232. entity.IsReturn = 0;
  233. int num = getProductCount(entity.seller_memo);
  234. if (entity.MemoOpt == 1 || entity.MemoOpt == 2)
  235. {
  236. entity.MemoOpt = 0;
  237. }
  238. if (entity.payment < 500)
  239. {
  240. if (entity.seller_memo.Contains("插卡") && entity.ProductCount != null && !entity.seller_memo.Contains("S_"))
  241. {
  242. if (num >= 100)
  243. {
  244. entity.IsVerifyToSupplier = true;
  245. entity.SupplierId = 3;
  246. entity.FinishPlaceTime = DateTime.Now;
  247. }
  248. }
  249. if (((((entity.seller_memo.Contains("条幅彩色") && !entity.seller_memo.Contains("辽宁") && !entity.seller_memo.Contains("山东")) || entity.seller_memo.Contains("贡锻布") || entity.seller_memo.Contains("贡缎布") || entity.seller_memo.Contains("旗帜布")) && !entity.seller_memo.Contains("双喷")) || (entity.seller_memo.Contains("帆布") && !entity.seller_memo.Contains("帆布袋") && !entity.seller_memo.Contains("封边尺寸"))) && !entity.seller_memo.Contains("电子稿"))
  250. {
  251. entity.IsVerifyToSupplier = true;
  252. entity.SupplierId = 98;
  253. entity.FinishPlaceTime = DateTime.Now;
  254. }
  255. }
  256. string patterns = "出货|加急|顺丰|打印|专版|当天发";
  257. if (!Regex.IsMatch(entity.seller_memo, patterns) && string.IsNullOrEmpty(entity.OtherMemo) && !entity.ctid.Contains("S_"))
  258. {
  259. if (entity.payment <= 300 && num >= 200 && num <= 3000 && entity.ShopId != 14 && entity.ShopId != 99)
  260. {
  261. //300克铜板纸/铜版纸300克-覆哑膜/覆膜/不覆膜-直角/裁切
  262. if (!entity.seller_memo.Contains("opp") && !entity.seller_memo.Contains("按文件") && !entity.seller_memo.Contains("流苏") && !entity.seller_memo.Contains("排序") && !entity.seller_memo.Contains("烫金"))
  263. {
  264. if ((entity.seller_memo.Contains("直角") || entity.seller_memo.Contains("裁切")) && (entity.seller_memo.Contains("300克铜板纸") || entity.seller_memo.Contains("300克铜板纸")) && (entity.seller_memo.Contains("覆哑膜") || entity.seller_memo.Contains("覆膜") || entity.seller_memo.Contains("不覆膜")))
  265. {
  266. entity.IsVerifyToSupplier = true;
  267. entity.SupplierId = 14;
  268. entity.FinishPlaceTime = DateTime.Now;
  269. }
  270. }
  271. }
  272. if (entity.payment <= 100 && num > 500 && num <= 1500)
  273. {
  274. //数量0-1500
  275. //0-80*54
  276. string pattern = @"\b(\d{1,5}[x\*]\d{1,5}(mm|cm))\b";
  277. string memo = entity.seller_memo.Replace("MM", "mm").Replace("CM", "cm");
  278. Regex reg = new Regex(pattern, RegexOptions.IgnoreCase | RegexOptions.Multiline, TimeSpan.FromSeconds(2));//2秒后超时
  279. MatchCollection matches = reg.Matches(memo);//设定要查找的字符串
  280. string size = "";
  281. double min_width = 80;
  282. double min_height = 54;
  283. double width = 0;
  284. double height = 0;
  285. bool isIn = false;
  286. try
  287. {
  288. if (matches[0].Success)
  289. {
  290. size = matches[0].Groups[0].Value;
  291. size = size.Replace("mm", "");
  292. size = size.Replace("cm", "");
  293. string[] size_list = size.Split('x');
  294. if (size_list.Length > 1)
  295. {
  296. width = Convert.ToDouble(size_list[0]);
  297. height = Convert.ToDouble(size_list[1]);
  298. }
  299. if ((width <= min_width && height <= min_height) || (height <= min_width && width <= min_height))
  300. {
  301. isIn = true;
  302. }
  303. if (width < 30 || height < 30)
  304. {
  305. isIn = false;
  306. }
  307. }
  308. }
  309. catch (Exception ex)
  310. {
  311. }
  312. //铜版纸不干胶-覆亮膜
  313. if (isIn && entity.seller_memo.Contains("铜版纸不干胶") && entity.seller_memo.Contains("覆亮膜") && !entity.seller_memo.Contains("烫金") && !entity.seller_memo.Contains("排序"))
  314. {
  315. entity.IsVerifyToSupplier = true;
  316. entity.SupplierId = 64;
  317. entity.FinishPlaceTime = DateTime.Now;
  318. }
  319. }
  320. if (entity.payment <= 500 && num > 200 && num <= 5000)
  321. {
  322. //数量0-5000
  323. if (entity.seller_memo.Contains("透明不干胶"))
  324. {
  325. entity.IsVerifyToSupplier = true;
  326. entity.SupplierId = 64;
  327. entity.FinishPlaceTime = DateTime.Now;
  328. }
  329. }
  330. if (entity.payment <= 100 && num > 200 && num <= 1000)
  331. {
  332. //数量0-1000
  333. if (entity.seller_memo.Contains("铜版纸不干胶") && entity.seller_memo.Contains("覆哑膜"))
  334. {
  335. entity.IsVerifyToSupplier = true;
  336. entity.SupplierId = 64;
  337. entity.FinishPlaceTime = DateTime.Now;
  338. }
  339. }
  340. if (entity.payment <= 500 && num > 0 && num <= 50)
  341. {
  342. //数量0-50
  343. if (entity.seller_memo.Contains("领淘550灯布海报") || entity.seller_memo.Contains("领淘户外写真海报"))
  344. {
  345. entity.IsVerifyToSupplier = true;
  346. entity.SupplierId = 59;
  347. entity.FinishPlaceTime = DateTime.Now;
  348. }
  349. }
  350. if (entity.payment <= 500 && num > 0 && num <= 50)
  351. {
  352. //数量0-50
  353. if ((entity.seller_memo.Contains("桌布") && (entity.seller_memo.Contains("白底") || entity.seller_memo.Contains("蓝底") || entity.seller_memo.Contains("红底"))) || (entity.seller_memo.Contains("双喷") && entity.seller_memo.Contains("班旗") && entity.seller_memo.Contains("旗帜布") && (entity.seller_memo.Contains("左缝筒") || entity.seller_memo.Contains("四角打孔") || entity.seller_memo.Contains("净裁"))))
  354. {
  355. entity.IsVerifyToSupplier = true;
  356. entity.SupplierId = 90;
  357. entity.FinishPlaceTime = DateTime.Now;
  358. }
  359. }
  360. }
  361. if (entity.ProductId == 2690)
  362. {
  363. entity.IsVerifyToSupplier = true;
  364. entity.SupplierId = 97;
  365. entity.FinishPlaceTime = DateTime.Now;
  366. }
  367. if (entity.ProductId == 2701)
  368. {
  369. entity.IsVerifyToSupplier = true;
  370. entity.SupplierId = 98;
  371. entity.FinishPlaceTime = DateTime.Now;
  372. }
  373. string dPath = entity.FinishDesignTime.GetValueOrDefault().ToString("yyyyMMdd");
  374. //XLog.SaveLog(5, dPath);
  375. string sPath = Path.Combine(upPath, dPath);
  376. string cpath = Path.Combine(upPath, entity.FinishDesignTime.GetValueOrDefault().ToString("yyyyMM"));
  377. //XLog.SaveLog(5, sPath);
  378. //XLog.SaveLog(5, Directory.Exists(sPath).ToString());
  379. if (!Directory.Exists(sPath)) Directory.CreateDirectory(sPath);
  380. if (!Directory.Exists(cpath)) Directory.CreateDirectory(cpath);
  381. string saveFile = Path.Combine(sPath, file_name);
  382. string f_ext = Path.GetExtension(saveFile);
  383. string[] extArr = new string[] { ".cdr", ".zip", ".rar", ".pdf" };
  384. string _file = "";
  385. foreach (string ext in extArr)
  386. {
  387. if (f_ext != ext)
  388. {
  389. _file = saveFile.Replace(f_ext, ext);
  390. if (File.Exists(_file)) File.Delete(_file);
  391. }
  392. else
  393. {
  394. if (File.Exists(saveFile)) File.Delete(saveFile);
  395. }
  396. }
  397. //上传文件
  398. postFile.SaveAs(saveFile);
  399. entity.FileMd5 = GetMD5HashFromFile(postFile);
  400. //XLog.SaveLog(0, saveFile);
  401. entity.UpdateTime = DateTime.Now;
  402. entity.Update();
  403. //CeErpTradeCell.UpdateRelationOrder(entity);
  404. CeErpTradeCell.UpdateRelationOrder(entity.ctid);
  405. CeErpProduct product = CeErpProduct.GetById(entity.ProductId);
  406. if (product != null)
  407. {
  408. string param = "[{ \"product_type\": \"" + product.PType + "\",\"remark\": \"" + entity.seller_memo + "\",\"index\": \"" + entity.OrderSn + "\",\"orderid\": \"" + entity.ctid + "\",\"price\": \"" + entity.payment + "\"}]";
  409. sysHttpClient(param);
  410. }
  411. CeErpTradeLog.AddLog(entity.ctid, entity.OrderState, userId, "上传设计文件-" + saveFile);
  412. if (ctid.IndexOf("S_") >= -1)
  413. {
  414. StringBuilder sql = new StringBuilder();
  415. sql.AppendFormat("select * from Ce_ErpTradeCellExtend where ctid='{0}'", entity.ctid);
  416. DataTable cellEx = CeErpTradeCell.ExecuteDataset(sql.ToString()).Tables[0];
  417. if (cellEx.Rows.Count > 0)
  418. {
  419. string txtReprintTime = cellEx.Rows[0]["ReprintTime"].ToString();
  420. if (!string.IsNullOrEmpty(txtReprintTime) && !"null".Equals(txtReprintTime))
  421. {
  422. DateTime reprint = DateTime.Parse(txtReprintTime);
  423. if (DateTime.Compare(DateTime.Now.AddHours(-24), reprint) >= 0)
  424. {
  425. string parentId = entity.ctid.Substring(2);
  426. string update_sql = string.Format("update Ce_ErpTradeAfterSaleExtend set ReprintOut = ReprintOut+1 where tid= '{0}' ;", parentId);
  427. CeErpTradeLog.ExecuteNonQuery(update_sql);
  428. }
  429. }
  430. }
  431. }
  432. if (Path.GetExtension(saveFile).IndexOf("cdr", StringComparison.OrdinalIgnoreCase) != -1)
  433. {
  434. //string sql = string.Format("insert into s_cdrtopng(name,addtime)values('{0}',getdate()) ;", saveFile);
  435. //CeErpTradeLog.ExecuteNonQuery(sql);
  436. }
  437. else if (Path.GetExtension(saveFile).IndexOf("zip", StringComparison.OrdinalIgnoreCase) != -1 || Path.GetExtension(saveFile).IndexOf("rar", StringComparison.OrdinalIgnoreCase) != -1)
  438. {
  439. try
  440. {
  441. DecompressZIPandRAR(saveFile, sPath, file_name);
  442. }
  443. catch (Exception ex)
  444. {
  445. CeErpTradeLog.AddLog(entity.ctid, entity.OrderState, entity.DesignUserId, "解压失败!");
  446. XLog.SaveLog(0, "上传解压发生错误!" + ex.Message);
  447. }
  448. //Decompress(saveFile,sPath);
  449. }
  450. //new Thread(new ThreadStart(delegate ()
  451. //{
  452. //System.Threading.Thread.Sleep(2000);
  453. if (Path.GetExtension(saveFile).IndexOf("cdr", StringComparison.OrdinalIgnoreCase) != -1)
  454. {
  455. var identity = WindowsIdentity.GetCurrent();
  456. var principal = new WindowsPrincipal(identity);
  457. Task.Run(async () =>
  458. {
  459. string filePath = Path.GetFullPath(saveFile);
  460. string targPath = Path.Combine(cpath, file_name);
  461. using (identity.Impersonate())
  462. {
  463. try
  464. {
  465. if (File.Exists(filePath))
  466. {
  467. cdrConvert.CdrConvertPng(filePath, targPath);
  468. }
  469. }
  470. catch (Exception ex)
  471. {
  472. XLog.SaveLog(0, filePath + ",转成图片出错:" + ex.Message);
  473. }
  474. }
  475. });
  476. }
  477. //})).Start();
  478. conSuc("上传成功!");
  479. return;
  480. }
  481. else
  482. {
  483. conErc("找不到对应的订单");
  484. return;
  485. }
  486. }
  487. catch (Exception ex)
  488. {
  489. conErc("上传发生错误!" + CommonHelper.FormatTextArea(ex.Message));
  490. CeErpTradeLog.AddLog(entity.ctid, entity.OrderState, entity.DesignUserId, "上传失败!");
  491. XLog.SaveLog(0, "上传发生错误!" + ex.Message);
  492. return;
  493. }
  494. finally
  495. {
  496. if (postFile != null)
  497. {
  498. postFile.InputStream.Close();
  499. }
  500. }
  501. }
  502. conErc("空文件!");
  503. }
  504. private int getsupplierId(CeErpTradeCell entity)
  505. {
  506. int supplierId = 0;
  507. StringBuilder sql = new StringBuilder();
  508. sql.AppendFormat("select * from CE_ErpUpFileSupplier ");
  509. DataTable cellEx = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  510. int num = getProductCount(entity.seller_memo);
  511. foreach (DataRow row in cellEx.Rows)
  512. {
  513. bool isIn = true;
  514. //判断材质工艺都要符合
  515. if (Convert.IsDBNull(row["seller_memo"]))
  516. {
  517. string memo = row["seller_memo"].ToString();
  518. string[] memolist = memo.Split('+');
  519. for (int i = 0; i < memolist.Length; i++)
  520. {
  521. if (!Regex.IsMatch(entity.seller_memo, memolist[i].Replace("/", "|")))
  522. {
  523. isIn = false;
  524. }
  525. }
  526. }
  527. if (!isIn)
  528. {
  529. continue;
  530. }
  531. //判断金额符不符合
  532. if (!Convert.IsDBNull(row["payment"]))
  533. {
  534. string payment = row["payment"].ToString();
  535. string[] paymentList = payment.Split('-');
  536. if (!string.IsNullOrEmpty(paymentList[0]))
  537. {
  538. if (entity.payment < Convert.ToDouble(paymentList[0]))
  539. {
  540. continue;
  541. }
  542. }
  543. if (!string.IsNullOrEmpty(paymentList[1]))
  544. {
  545. if (entity.payment > Convert.ToDouble(paymentList[1]))
  546. {
  547. continue;
  548. }
  549. }
  550. }
  551. if (!Convert.IsDBNull(row["size"]))
  552. {
  553. string pattern = @"\b(\d{1,5}[x\*]\d{1,5}(mm|cm))\b";
  554. string memo = entity.seller_memo.Replace("MM", "mm").Replace("CM", "cm");
  555. Regex reg = new Regex(pattern, RegexOptions.IgnoreCase | RegexOptions.Multiline, TimeSpan.FromSeconds(2));//2秒后超时
  556. MatchCollection matches = reg.Matches(memo);//设定要查找的字符串
  557. double width = 0;
  558. double height = 0;
  559. try
  560. {
  561. if (matches[0].Success)
  562. {
  563. string sizematches = matches[0].Groups[0].Value;
  564. sizematches = sizematches.Replace("mm", "");
  565. sizematches = sizematches.Replace("cm", "");
  566. string[] size_list = sizematches.Split('x');
  567. if (size_list.Length > 1)
  568. {
  569. width = Convert.ToDouble(size_list[0]);
  570. height = Convert.ToDouble(size_list[1]);
  571. }
  572. }
  573. }
  574. catch (Exception ex)
  575. {
  576. }
  577. string size = row["size"].ToString();
  578. string[] sizeList = size.Split('-');
  579. if (!string.IsNullOrEmpty(sizeList[0]))
  580. {
  581. string[] sizeItemList = sizeList[0].Split('x');
  582. //第一个尺寸格式不正确
  583. if (sizeItemList.Length < 2)
  584. {
  585. continue;
  586. }
  587. double sizeWidth = Convert.ToDouble(sizeItemList[0]);
  588. double sizeheight = Convert.ToDouble(sizeItemList[1]);
  589. //备注尺寸要大于第一个尺寸
  590. if (!((width > sizeWidth && height > sizeheight) || (width > sizeheight && height > sizeWidth)))
  591. {
  592. continue;
  593. }
  594. }
  595. if (!string.IsNullOrEmpty(sizeList[1]))
  596. {
  597. string[] sizeItemList = sizeList[1].Split('x');
  598. //第二个尺寸格式不正确
  599. if (sizeItemList.Length < 2)
  600. {
  601. continue;
  602. }
  603. double sizeWidth = Convert.ToDouble(sizeItemList[0]);
  604. double sizeheight = Convert.ToDouble(sizeItemList[1]);
  605. //备注尺寸要大于第二个尺寸
  606. if (!((width < sizeWidth && height < sizeheight) || (width < sizeheight && height < sizeWidth)))
  607. {
  608. continue;
  609. }
  610. }
  611. }
  612. //判断数量是否符合
  613. if (!Convert.IsDBNull(row["number"]))
  614. {
  615. string numberText = row["number"].ToString();
  616. string[] numberTextList = numberText.Split('-');
  617. int number = 0;
  618. if (!string.IsNullOrEmpty(numberTextList[0]))
  619. {
  620. number = Convert.ToInt32(numberTextList[0]);
  621. if (number > num)
  622. {
  623. continue;
  624. }
  625. }
  626. if (!string.IsNullOrEmpty(numberTextList[1]))
  627. {
  628. number = Convert.ToInt32(numberTextList[1]);
  629. if (number < num)
  630. {
  631. continue;
  632. }
  633. }
  634. }
  635. //判断店铺符不符合
  636. if (!Convert.IsDBNull(row["shopIds"]))
  637. {
  638. List<string> shopids = row["shopIds"].ToString().Split(',').ToList();
  639. if (!shopids.Contains(entity.ShopId.ToString()))
  640. {
  641. continue;
  642. }
  643. }
  644. //地区不符合
  645. if (!Convert.IsDBNull(row["address"]))
  646. {
  647. if (!Regex.IsMatch(entity.seller_memo, row["address"].ToString().Replace("、", "|")))
  648. {
  649. continue;
  650. }
  651. }
  652. //限制条件
  653. if (!Convert.IsDBNull(row["filterText"]))
  654. {
  655. if (!Regex.IsMatch(entity.seller_memo, row["filterText"].ToString().Replace("/", "|")))
  656. {
  657. continue;
  658. }
  659. }
  660. }
  661. return supplierId;
  662. }
  663. class CdrConvert
  664. {
  665. private object lockObject = new object();
  666. public void CdrConvertPng(string filePath, string targPath)
  667. {
  668. lock (lockObject)
  669. {
  670. targPath = targPath.Replace(".cdr", ".png");
  671. try
  672. {
  673. Application cdr = new Application();
  674. cdr.OpenDocument(filePath, 1);
  675. cdr.ActiveDocument.ExportBitmap(
  676. targPath,
  677. cdrFilter.cdrPNG,
  678. cdrExportRange.cdrCurrentPage,
  679. cdrImageType.cdrRGBColorImage,
  680. 0, 0, 72, 72,
  681. cdrAntiAliasingType.cdrNoAntiAliasing,
  682. false,
  683. true,
  684. true,
  685. false,
  686. cdrCompressionType.cdrCompressionNone,
  687. null).Finish();
  688. cdr.ActiveDocument.Close();
  689. cdr.Quit();
  690. cdr = null;
  691. }
  692. catch (Exception ex)
  693. {
  694. XLog.SaveLog(0, targPath + ",转成图片出错:" + ex.Message);
  695. }
  696. finally
  697. {
  698. KillProcessByName("CorelDRW");
  699. }
  700. }
  701. }
  702. void KillProcessByName(string processName)
  703. {
  704. Process[] processes = Process.GetProcessesByName(processName);
  705. foreach (Process process in processes)
  706. {
  707. try
  708. {
  709. process.Kill();
  710. process.WaitForExit(); // 等待进程退出
  711. }
  712. catch (Exception ex)
  713. {
  714. }
  715. }
  716. }
  717. }
  718. public static int getProductCount(string txt)
  719. {
  720. // 提取"个"或"张"前面的数字
  721. int unit = 0;
  722. try
  723. {
  724. string unitPattern = @"(\d+)(?=个|张|本|套|件|卷|劵|条|箱 )";
  725. Match unitMatch = Regex.Match(txt, unitPattern);
  726. string unitNum = unitMatch.Success ? unitMatch.Groups[1].Value : "1";
  727. if (!int.TryParse(unitNum, out unit))
  728. {
  729. return 0;
  730. }
  731. }
  732. catch (Exception ex)
  733. {
  734. }
  735. return unit;
  736. }
  737. private void DecompressZIPandRAR(string zipFile, string targetPath, string filename)
  738. {
  739. string notExtension = filename.Substring(0, filename.Length - 4);
  740. SevenZipExtractor.SetLibraryPath(Server.MapPath("bin\\7z.dll"));
  741. LibraryFeature lf = SevenZipExtractor.CurrentLibraryFeatures;
  742. using (SevenZipExtractor szExtra = new SevenZipExtractor(zipFile))
  743. {
  744. //szExtra.ExtractArchive("d:\\temp");
  745. foreach (string afn in szExtra.ArchiveFileNames)
  746. {
  747. if (afn.IndexOf(notExtension, StringComparison.OrdinalIgnoreCase) != -1)
  748. {
  749. szExtra.ExtractFiles(targetPath, afn);
  750. break;
  751. }
  752. }
  753. }
  754. }
  755. public void sysHttpClient(string param)
  756. {
  757. Task.Run(async () =>
  758. {
  759. var client = new HttpClient();
  760. var request = new HttpRequestMessage
  761. {
  762. Method = HttpMethod.Post,
  763. RequestUri = new Uri("http://47.122.57.102:11004/quotations/batch"),
  764. Content = new StringContent(param)
  765. {
  766. Headers =
  767. {
  768. ContentType = new MediaTypeHeaderValue("application/json")
  769. }
  770. }
  771. };
  772. var task = Task.Run(() =>
  773. {
  774. try
  775. {
  776. var response = client.SendAsync(request).Result;
  777. response.EnsureSuccessStatusCode();
  778. writeLog(param + "-" + response.Content.ReadAsStringAsync().Result);
  779. return response.Content.ReadAsStringAsync().Result;
  780. }
  781. catch (Exception e)
  782. {
  783. return "";
  784. }
  785. });
  786. });
  787. }
  788. private void Decompress(string GzipFile, string targetPath)
  789. {
  790. //string directoryName = Path.GetDirectoryName(targetPath + "\\") + "\\";
  791. string directoryName = targetPath + "\\";
  792. if (!Directory.Exists(directoryName)) Directory.CreateDirectory(directoryName);//生成解压目录
  793. //helper.writeLog(GzipFile);
  794. //helper.writeLog(directoryName);
  795. string CurrentDirectory = directoryName;
  796. byte[] data = new byte[2048];
  797. int size = 2048;
  798. ZipEntry theEntry = null;
  799. Stream _stream = File.OpenRead(GzipFile);
  800. if (_stream.Length == 0) { _stream.Close(); return; }
  801. try
  802. {
  803. using (ZipInputStream s = new ZipInputStream(_stream))
  804. {
  805. while ((theEntry = s.GetNextEntry()) != null)
  806. {
  807. if (theEntry.IsDirectory)
  808. {// 该结点是目录
  809. if (!Directory.Exists(CurrentDirectory + theEntry.Name)) Directory.CreateDirectory(CurrentDirectory + theEntry.Name);
  810. }
  811. else
  812. {
  813. if (theEntry.Name != String.Empty && (theEntry.Name.IndexOf(".png", StringComparison.OrdinalIgnoreCase) != -1 || theEntry.Name.IndexOf(".jpg", StringComparison.OrdinalIgnoreCase) != -1))
  814. {
  815. //解压文件到指定的目录
  816. using (FileStream streamWriter = File.Create(CurrentDirectory + theEntry.Name))
  817. {
  818. while (true)
  819. {
  820. size = s.Read(data, 0, data.Length);
  821. if (size <= 0) break;
  822. streamWriter.Write(data, 0, size);
  823. }
  824. streamWriter.Close();
  825. }
  826. break;
  827. }
  828. }
  829. }
  830. s.Close();
  831. }
  832. }
  833. catch (Exception ex)
  834. {
  835. XLog.SaveLog(0, "解压uncau:" + ex.Message);
  836. }
  837. }
  838. public string unCompressRAR(string unRarPatch, string rarPatch, string rarName)
  839. {
  840. string the_rar;
  841. RegistryKey the_Reg;
  842. object the_Obj;
  843. string the_Info;
  844. try
  845. {
  846. the_Reg = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\WinRAR.exe");
  847. the_Obj = the_Reg.GetValue("");
  848. the_rar = the_Obj.ToString();
  849. the_Reg.Close();
  850. if (Directory.Exists(unRarPatch) == false)
  851. {
  852. Directory.CreateDirectory(unRarPatch);
  853. }
  854. the_Info = "x " + rarName + " " + unRarPatch + " -y";
  855. ProcessStartInfo the_StartInfo = new ProcessStartInfo();
  856. the_StartInfo.FileName = the_rar;
  857. the_StartInfo.Arguments = the_Info;
  858. the_StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
  859. the_StartInfo.WorkingDirectory = rarPatch;//获取压缩包路径
  860. Process the_Process = new Process();
  861. the_Process.StartInfo = the_StartInfo;
  862. the_Process.Start();
  863. the_Process.WaitForExit();
  864. the_Process.Close();
  865. }
  866. catch (Exception ex)
  867. {
  868. throw ex;
  869. }
  870. return unRarPatch;
  871. }
  872. private void ShellCdrConvertPng(string path, string targPath)
  873. {
  874. ShellFile shellFile = ShellFile.FromFilePath(path);
  875. System.Drawing.Bitmap shellThumb = shellFile.Thumbnail.ExtraLargeBitmap;
  876. //在画板的指定位置画图
  877. targPath = targPath.Replace(".cdr", ".png");
  878. shellThumb.Save(targPath, ImageFormat.Png);
  879. shellThumb.Dispose();
  880. shellFile.Dispose();
  881. }
  882. private void CdrConvertPng(string path, string targPath)
  883. {
  884. using (Aspose.Imaging.FileFormats.Cdr.CdrImage image = (Aspose.Imaging.FileFormats.Cdr.CdrImage)Aspose.Imaging.Image.Load(path))
  885. {
  886. PngOptions options = new Aspose.Imaging.ImageOptions.PngOptions();
  887. options.ColorType = Aspose.Imaging.FileFormats.Png.PngColorType.TruecolorWithAlpha;
  888. // Set rasterization options for fileformat
  889. options.VectorRasterizationOptions = (Aspose.Imaging.ImageOptions.VectorRasterizationOptions)
  890. image.GetDefaultOptions(new object[] { Aspose.Imaging.Color.White, image.Width, image.Height });
  891. options.VectorRasterizationOptions.TextRenderingHint = TextRenderingHint.ClearTypeGridFit;
  892. options.VectorRasterizationOptions.SmoothingMode = Aspose.Imaging.SmoothingMode.None;
  893. targPath = targPath.Replace(".cdr", ".png");
  894. image.Save(targPath, options);
  895. options.Dispose();
  896. }
  897. }
  898. private string CdrExPng(string path, string targPath)
  899. {
  900. try
  901. {
  902. targPath = targPath.Replace(".cdr", ".png");
  903. Application cdr = new Application();
  904. cdr.OpenDocument(path, 1);
  905. cdr.ActiveDocument.ExportBitmap(
  906. targPath,
  907. cdrFilter.cdrPNG,
  908. cdrExportRange.cdrCurrentPage,
  909. cdrImageType.cdrRGBColorImage,
  910. 0, 0, 72, 72,
  911. cdrAntiAliasingType.cdrNoAntiAliasing,
  912. false,
  913. true,
  914. true,
  915. false,
  916. cdrCompressionType.cdrCompressionNone,
  917. null).Finish();
  918. cdr.ActiveDocument.Close();
  919. cdr.Quit();
  920. cdr = null;
  921. GC.Collect();
  922. }
  923. catch (Exception ex)
  924. {
  925. XLog.SaveLog(0, path + ",转成图片出错:" + ex.Message);
  926. }
  927. finally
  928. {
  929. }
  930. return "111";
  931. }
  932. private static object cdrpngobj = new object();
  933. private void CdrExportPng(string path, string cdrFile)
  934. {
  935. lock (cdrpngobj)
  936. {
  937. string fname = curPath + "\\" + Path.GetFileNameWithoutExtension(cdrFile) + ".png";
  938. string new_fname = path + "\\" + Path.GetFileNameWithoutExtension(cdrFile) + ".png";
  939. CorelDRAW.Application cdr = new CorelDRAW.Application();
  940. cdr.OpenDocument(cdrFile, 1);
  941. cdr.ActiveDocument.ExportBitmap(
  942. fname,
  943. CorelDRAW.cdrFilter.cdrPNG,
  944. CorelDRAW.cdrExportRange.cdrCurrentPage,
  945. CorelDRAW.cdrImageType.cdrRGBColorImage,
  946. 0, 0, 72, 72,
  947. CorelDRAW.cdrAntiAliasingType.cdrNoAntiAliasing,
  948. false,
  949. true,
  950. true,
  951. false,
  952. CorelDRAW.cdrCompressionType.cdrCompressionNone,
  953. null).Finish();
  954. cdr.ActiveDocument.Close();
  955. cdr.Quit();
  956. if (File.Exists(fname))
  957. {
  958. File.Copy(fname, new_fname);
  959. File.Delete(fname);
  960. }
  961. }
  962. }
  963. public static string MidStrEx(string sourse, string startstr, string endstr)
  964. {
  965. string result = string.Empty;
  966. int startindex, endindex;
  967. try
  968. {
  969. startindex = sourse.IndexOf(startstr);
  970. if (startindex == -1)
  971. return result;
  972. string tmpstr = sourse.Substring(startindex + startstr.Length);
  973. endindex = tmpstr.IndexOf(endstr);
  974. if (endindex == -1)
  975. return result;
  976. result = tmpstr.Remove(endindex);
  977. }
  978. catch (Exception ex)
  979. {
  980. Console.WriteLine("MidStrEx Err:" + ex.Message);
  981. }
  982. return result;
  983. }
  984. private static string logPath = ConfigurationManager.AppSettings["curPath"] + "\\log";
  985. private static object logFlag = new object();
  986. public static void writeLog(string log)
  987. {
  988. lock (logFlag)
  989. {
  990. using (FileStream fileStream = new FileStream(logPath + "\\" + DateTime.Now.ToString("yy-MM-dd") + ".log", FileMode.Append, FileAccess.Write))
  991. {
  992. using (StreamWriter sw = new StreamWriter(fileStream, Encoding.Default))
  993. {
  994. sw.Write(log + " ------时间:" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "\r\n");
  995. sw.Flush();
  996. }
  997. }
  998. }
  999. }
  1000. }