uploadFile.aspx.cs 37 KB

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