uploadFile.aspx.cs 38 KB

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