uploadFile.aspx.cs 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736
  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.Threading;
  21. using System.Runtime.InteropServices;
  22. using System.Text.RegularExpressions;
  23. using System.Data;
  24. public partial class uploadFile : System.Web.UI.Page
  25. {
  26. public static string upPath = ConfigurationManager.AppSettings["upPath"];
  27. public static string curPath = ConfigurationManager.AppSettings["curPath"];
  28. static CdrConvert cdrConvert = new CdrConvert();
  29. private void conSuc(string msg)
  30. {
  31. Response.Write("{\"res\":\"1\",\"msg\":\"" + msg + "!\"}");
  32. //Response.End();
  33. }
  34. private void conErc(string msg)
  35. {
  36. Response.Write("{\"res\":\"0\",\"msg\":\"" + msg + "!\"}");
  37. //Response.End();
  38. }
  39. public string GetMD5HashFromFile(HttpPostedFile file)
  40. {
  41. try
  42. {
  43. System.Security.Cryptography.MD5 md5 = new System.Security.Cryptography.MD5CryptoServiceProvider();
  44. byte[] retVal = md5.ComputeHash(file.InputStream);
  45. StringBuilder sb = new StringBuilder();
  46. for (int i = 0; i < retVal.Length; i++)
  47. {
  48. sb.Append(retVal[i].ToString("x2"));
  49. }
  50. return sb.ToString();
  51. }
  52. catch (Exception ex)
  53. {
  54. XLog.SaveLog(0, "上传MD5错误!" + ex.Message);
  55. }
  56. return "";
  57. }
  58. private static byte[] GetBlobByHttpPostedFile(HttpPostedFile httpPostedFile)
  59. {
  60. var contentLength = httpPostedFile.ContentLength;
  61. var result = new byte[contentLength];
  62. var inputStream = httpPostedFile.InputStream;
  63. inputStream.Read(result, 0, contentLength);
  64. return result;
  65. }
  66. protected void Page_Load(object sender, EventArgs e)
  67. {
  68. //if (CurrentUser == null)
  69. //{
  70. // Response.Write(err);
  71. // return;
  72. //}
  73. //CeErpTradeCell.GetByCtid("1717009344450030601");
  74. if (Request.Files.Count < 1)
  75. {
  76. conErc("空文件!");
  77. return;
  78. }
  79. int userId = 0;
  80. int orgid = 0;
  81. if (Request["userid"] != null)
  82. {
  83. userId = Convert.ToInt32(Request["userid"]);
  84. }
  85. if (Request["orgid"] != null)
  86. {
  87. orgid = Convert.ToInt32(Request["orgid"]);
  88. }
  89. HttpPostedFile postFile = Request.Files[0];
  90. if (postFile != null)
  91. {
  92. string file_name = postFile.FileName;
  93. string namePattern = @"《(.*?)》";
  94. Regex nameReg = new Regex(namePattern, RegexOptions.IgnoreCase | RegexOptions.Multiline, TimeSpan.FromSeconds(2));//2秒后超时
  95. MatchCollection nameMatches = nameReg.Matches(file_name);//设定要查找的字符串
  96. if (nameMatches.Count > 0)
  97. {
  98. foreach (Match match in nameMatches)
  99. {
  100. file_name = file_name.Replace(match.Value, "");
  101. }
  102. }
  103. file_name = file_name.Replace("(", "(");
  104. file_name = file_name.Replace(")", ")");
  105. string ctid = MidStrEx(file_name, "(", ")").Trim();
  106. if (string.IsNullOrEmpty(ctid))
  107. {
  108. conErc("上传的文件名格式不正确");
  109. return;
  110. }
  111. string memoCtid = ctid;
  112. if (ctid.IndexOf("C") == -1)
  113. {
  114. if (file_name.IndexOf("[") != -1 && file_name.IndexOf("C") != -1)
  115. {
  116. if (ctid.IndexOf("S_") != -1) // (S_S_1962772776865084101)[C1] 对应ctid是 S_S_C1_1962772776865084101
  117. {
  118. int lastIndex = ctid.LastIndexOf("S_"); //最后一个S_的位置
  119. string sPre = ctid.Substring(0, lastIndex + 2); //S_S_
  120. string initTid = ctid.Substring(lastIndex + 2, ctid.Length - lastIndex - 2); //1962772776865084101
  121. string pre_ctid = MidStrEx(file_name, "[", "]"); //C1
  122. if (pre_ctid.IndexOf("+") != -1)
  123. {
  124. pre_ctid = "C" + pre_ctid.Split('+')[1];
  125. }
  126. memoCtid = sPre + pre_ctid + "_" + initTid; //S_S_ + C1 + _ +1962772776865084101
  127. }
  128. else
  129. {
  130. string pre_ctid = MidStrEx(file_name, "[", "]");
  131. if (pre_ctid.IndexOf("+") != -1)
  132. {
  133. pre_ctid = "C" + pre_ctid.Split('+')[1];
  134. }
  135. memoCtid = pre_ctid + "_" + ctid;
  136. }
  137. }
  138. }
  139. CeErpTradeCell entity = null;
  140. if (ctid != "") entity = CeErpTradeCell.GetByCode(ctid);
  141. if (entity == null) entity = CeErpTradeCell.GetByCtid(ctid);
  142. if (entity == null) entity = CeErpTradeCell.GetByCtid(memoCtid);
  143. try
  144. {
  145. if (entity != null)
  146. {
  147. string pname = Path.GetFileNameWithoutExtension(file_name);
  148. if (entity.IsRefund == 2)
  149. {
  150. StringBuilder sql = new StringBuilder();
  151. sql.AppendFormat("select refund_status from CE_ErpTradeOrder where tid='{0}'", entity.tid);
  152. DataTable dt = CeErpTradeCell.ExecuteDataset(sql.ToString()).Tables[0];
  153. bool isAll = true;
  154. foreach (DataRow dr in dt.Rows)
  155. {
  156. if ("NO_REFUND".Equals(dr["refund_status"]))
  157. {
  158. isAll = false;
  159. break;
  160. }
  161. }
  162. if (isAll)
  163. {
  164. conErc("此单退款,不允许上传");
  165. return;
  166. }
  167. }
  168. if (entity.seller_memo != pname)
  169. {
  170. conErc("上传的文件名与备注不符合!");
  171. return;
  172. }
  173. if (entity.OrderState == -1)
  174. {
  175. conErc("还未审核不允许上传");
  176. return;
  177. }
  178. if (entity.OrderState < (int)OrderState.设计中 && orgid != 10 && orgid != 4)
  179. {
  180. conErc("还未开始设计不允许上传");
  181. return;
  182. }
  183. //if (pname.IndexOf("现货") != -1)
  184. //{
  185. // conErc("设计款的单文件名不能有现货字眼");
  186. // return;
  187. //}
  188. //更新状态
  189. if (entity.OrderState >= (int)OrderState.下单完成)
  190. {
  191. conErc("已经下单无法上传!");
  192. return;
  193. }
  194. if (entity.IsVerifyToSupplier)
  195. {
  196. conErc("订单已到车间无法上传!");
  197. return;
  198. }
  199. string extend = Path.GetExtension(file_name).ToLower();
  200. if (!(extend == ".cdr" || extend == ".zip" || extend == ".rar" || extend == ".pdf"))
  201. {
  202. conErc("只允许上传zip和cdr文件!");
  203. return;
  204. }
  205. if (entity.OrderState != 5)
  206. {
  207. entity.FinishDesignTime = DateTime.Now;
  208. if (entity.isDianziOrder == 1 || entity.ProductId == 57 || entity.ProductId == 28)
  209. {
  210. entity.OrderState = 6;
  211. entity.SupplierId = 35;
  212. entity.FinishPlaceTime = DateTime.Now;
  213. bool sendResult = commonHelper.SetOrderDummyDelivery(entity.tid);
  214. if (sendResult)
  215. {
  216. entity.OrderState = 7;
  217. }
  218. }
  219. else
  220. entity.OrderState = 5; //设计完成
  221. //if (entity.IsReturn == 2) //2是下单人打回给设计的,重新上传的话,需要清除打回
  222. //{
  223. entity.IsXianHuo = 0;
  224. entity.IsVerifyToSupplier = false;
  225. //}
  226. }
  227. entity.IsReturn = 0;
  228. if (entity.MemoOpt == 1 || entity.MemoOpt == 2)
  229. {
  230. entity.MemoOpt = 0;
  231. }
  232. if (entity.payment < 500)
  233. {
  234. if (entity.seller_memo.Contains("插卡") && entity.ProductCount != null && !entity.seller_memo.Contains("S_"))
  235. {
  236. int num = 0;
  237. try
  238. {
  239. string text = entity.ProductCount;
  240. string pattern = @"(\d+)\s*张";
  241. MatchCollection matches = Regex.Matches(text, pattern);
  242. foreach (Match match in matches)
  243. {
  244. if (match.Success)
  245. {
  246. num = Convert.ToInt32(match.Groups[1].Value);
  247. break;
  248. }
  249. }
  250. }
  251. catch (Exception ex)
  252. {
  253. }
  254. if (num >= 100)
  255. {
  256. entity.IsVerifyToSupplier = true;
  257. entity.SupplierId = 3;
  258. entity.FinishPlaceTime = DateTime.Now;
  259. }
  260. }
  261. 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("帆布"))
  262. {
  263. entity.IsVerifyToSupplier = true;
  264. entity.SupplierId = 98;
  265. entity.FinishPlaceTime = DateTime.Now;
  266. }
  267. }
  268. string dPath = entity.FinishDesignTime.GetValueOrDefault().ToString("yyyyMMdd");
  269. //XLog.SaveLog(5, dPath);
  270. string sPath = Path.Combine(upPath, dPath);
  271. string cpath = Path.Combine(upPath, entity.FinishDesignTime.GetValueOrDefault().ToString("yyyyMM"));
  272. //XLog.SaveLog(5, sPath);
  273. //XLog.SaveLog(5, Directory.Exists(sPath).ToString());
  274. if (!Directory.Exists(sPath)) Directory.CreateDirectory(sPath);
  275. if (!Directory.Exists(cpath)) Directory.CreateDirectory(cpath);
  276. string saveFile = Path.Combine(sPath, file_name);
  277. string f_ext = Path.GetExtension(saveFile);
  278. string[] extArr = new string[] { ".cdr", ".zip", ".rar", ".pdf" };
  279. string _file = "";
  280. foreach (string ext in extArr)
  281. {
  282. if (f_ext != ext)
  283. {
  284. _file = saveFile.Replace(f_ext, ext);
  285. if (File.Exists(_file)) File.Delete(_file);
  286. }
  287. else
  288. {
  289. if (File.Exists(saveFile)) File.Delete(saveFile);
  290. }
  291. }
  292. //上传文件
  293. postFile.SaveAs(saveFile);
  294. entity.FileMd5 = GetMD5HashFromFile(postFile);
  295. //XLog.SaveLog(0, saveFile);
  296. entity.UpdateTime = DateTime.Now;
  297. entity.Update();
  298. //CeErpTradeCell.UpdateRelationOrder(entity);
  299. CeErpTradeCell.UpdateRelationOrder(entity.ctid);
  300. CeErpTradeLog.AddLog(entity.ctid, entity.OrderState, userId, "上传设计文件-" + saveFile);
  301. if (ctid.IndexOf("S_") >= -1)
  302. {
  303. StringBuilder sql = new StringBuilder();
  304. sql.AppendFormat("select * from Ce_ErpTradeCellExtend where ctid='{0}'", entity.ctid);
  305. DataTable cellEx = CeErpTradeCell.ExecuteDataset(sql.ToString()).Tables[0];
  306. if (cellEx.Rows.Count > 0)
  307. {
  308. string txtReprintTime = cellEx.Rows[0]["ReprintTime"].ToString();
  309. if (!string.IsNullOrEmpty(txtReprintTime) && !"null".Equals(txtReprintTime))
  310. {
  311. DateTime reprint = DateTime.Parse(txtReprintTime);
  312. if (DateTime.Compare(DateTime.Now.AddHours(-24), reprint) >= 0)
  313. {
  314. string parentId = entity.ctid.Substring(2);
  315. string update_sql = string.Format("update Ce_ErpTradeAfterSaleExtend set ReprintOut = ReprintOut+1 where tid= '{0}' ;", parentId);
  316. CeErpTradeLog.ExecuteNonQuery(update_sql);
  317. }
  318. }
  319. }
  320. }
  321. if (Path.GetExtension(saveFile).IndexOf("cdr", StringComparison.OrdinalIgnoreCase) != -1)
  322. {
  323. //string sql = string.Format("insert into s_cdrtopng(name,addtime)values('{0}',getdate()) ;", saveFile);
  324. //CeErpTradeLog.ExecuteNonQuery(sql);
  325. }
  326. else if (Path.GetExtension(saveFile).IndexOf("zip", StringComparison.OrdinalIgnoreCase) != -1 || Path.GetExtension(saveFile).IndexOf("rar", StringComparison.OrdinalIgnoreCase) != -1)
  327. {
  328. try
  329. {
  330. DecompressZIPandRAR(saveFile, sPath, file_name);
  331. }
  332. catch (Exception ex)
  333. {
  334. CeErpTradeLog.AddLog(entity.ctid, entity.OrderState, entity.DesignUserId, "解压失败!");
  335. XLog.SaveLog(0, "上传解压发生错误!" + ex.Message);
  336. }
  337. //Decompress(saveFile,sPath);
  338. }
  339. //new Thread(new ThreadStart(delegate ()
  340. //{
  341. //System.Threading.Thread.Sleep(2000);
  342. if (Path.GetExtension(saveFile).IndexOf("cdr", StringComparison.OrdinalIgnoreCase) != -1)
  343. {
  344. var identity = WindowsIdentity.GetCurrent();
  345. var principal = new WindowsPrincipal(identity);
  346. writeLog("上传完成!" + saveFile);
  347. Task.Run(async () =>
  348. {
  349. string filePath = Path.GetFullPath(saveFile);
  350. string targPath = Path.Combine(cpath, file_name);
  351. using (identity.Impersonate())
  352. {
  353. try
  354. {
  355. if (File.Exists(filePath))
  356. {
  357. cdrConvert.CdrConvertPng(filePath, targPath);
  358. }
  359. }
  360. catch (Exception ex)
  361. {
  362. XLog.SaveLog(0, filePath + ",转成图片出错:" + ex.Message);
  363. }
  364. }
  365. });
  366. }
  367. //})).Start();
  368. conSuc("上传成功!");
  369. return;
  370. }
  371. else
  372. {
  373. conErc("找不到对应的订单");
  374. return;
  375. }
  376. }
  377. catch (Exception ex)
  378. {
  379. conErc("上传发生错误!" + CommonHelper.FormatTextArea(ex.Message));
  380. CeErpTradeLog.AddLog(entity.ctid, entity.OrderState, entity.DesignUserId, "上传失败!");
  381. XLog.SaveLog(0, "上传发生错误!" + ex.Message);
  382. return;
  383. }
  384. finally
  385. {
  386. if (postFile != null)
  387. {
  388. postFile.InputStream.Close();
  389. }
  390. }
  391. }
  392. conErc("空文件!");
  393. }
  394. class CdrConvert
  395. {
  396. private object lockObject = new object();
  397. public void CdrConvertPng(string filePath, string targPath)
  398. {
  399. lock (lockObject)
  400. {
  401. writeLog("开始截图!" + filePath);
  402. targPath = targPath.Replace(".cdr", ".png");
  403. try
  404. {
  405. Application cdr = new Application();
  406. cdr.OpenDocument(filePath, 1);
  407. cdr.ActiveDocument.ExportBitmap(
  408. targPath,
  409. cdrFilter.cdrPNG,
  410. cdrExportRange.cdrCurrentPage,
  411. cdrImageType.cdrRGBColorImage,
  412. 0, 0, 72, 72,
  413. cdrAntiAliasingType.cdrNoAntiAliasing,
  414. false,
  415. true,
  416. true,
  417. false,
  418. cdrCompressionType.cdrCompressionNone,
  419. null).Finish();
  420. cdr.ActiveDocument.Close();
  421. cdr.Quit();
  422. cdr = null;
  423. }
  424. catch (Exception ex)
  425. {
  426. XLog.SaveLog(0, targPath + ",转成图片出错:" + ex.Message);
  427. }
  428. finally
  429. {
  430. KillProcessByName("CorelDRW");
  431. }
  432. }
  433. }
  434. void KillProcessByName(string processName)
  435. {
  436. Process[] processes = Process.GetProcessesByName(processName);
  437. foreach (Process process in processes)
  438. {
  439. try
  440. {
  441. process.Kill();
  442. process.WaitForExit(); // 等待进程退出
  443. }
  444. catch (Exception ex)
  445. {
  446. }
  447. }
  448. }
  449. }
  450. private void DecompressZIPandRAR(string zipFile, string targetPath, string filename)
  451. {
  452. string notExtension = filename.Substring(0, filename.Length - 4);
  453. SevenZipExtractor.SetLibraryPath(Server.MapPath("bin\\7z.dll"));
  454. LibraryFeature lf = SevenZipExtractor.CurrentLibraryFeatures;
  455. using (SevenZipExtractor szExtra = new SevenZipExtractor(zipFile))
  456. {
  457. //szExtra.ExtractArchive("d:\\temp");
  458. foreach (string afn in szExtra.ArchiveFileNames)
  459. {
  460. if (afn.IndexOf(notExtension, StringComparison.OrdinalIgnoreCase) != -1)
  461. {
  462. szExtra.ExtractFiles(targetPath, afn);
  463. break;
  464. }
  465. }
  466. }
  467. }
  468. private void Decompress(string GzipFile, string targetPath)
  469. {
  470. //string directoryName = Path.GetDirectoryName(targetPath + "\\") + "\\";
  471. string directoryName = targetPath + "\\";
  472. if (!Directory.Exists(directoryName)) Directory.CreateDirectory(directoryName);//生成解压目录
  473. //helper.writeLog(GzipFile);
  474. //helper.writeLog(directoryName);
  475. string CurrentDirectory = directoryName;
  476. byte[] data = new byte[2048];
  477. int size = 2048;
  478. ZipEntry theEntry = null;
  479. Stream _stream = File.OpenRead(GzipFile);
  480. if (_stream.Length == 0) { _stream.Close(); return; }
  481. try
  482. {
  483. using (ZipInputStream s = new ZipInputStream(_stream))
  484. {
  485. while ((theEntry = s.GetNextEntry()) != null)
  486. {
  487. if (theEntry.IsDirectory)
  488. {// 该结点是目录
  489. if (!Directory.Exists(CurrentDirectory + theEntry.Name)) Directory.CreateDirectory(CurrentDirectory + theEntry.Name);
  490. }
  491. else
  492. {
  493. if (theEntry.Name != String.Empty && (theEntry.Name.IndexOf(".png", StringComparison.OrdinalIgnoreCase) != -1 || theEntry.Name.IndexOf(".jpg", StringComparison.OrdinalIgnoreCase) != -1))
  494. {
  495. //解压文件到指定的目录
  496. using (FileStream streamWriter = File.Create(CurrentDirectory + theEntry.Name))
  497. {
  498. while (true)
  499. {
  500. size = s.Read(data, 0, data.Length);
  501. if (size <= 0) break;
  502. streamWriter.Write(data, 0, size);
  503. }
  504. streamWriter.Close();
  505. }
  506. break;
  507. }
  508. }
  509. }
  510. s.Close();
  511. }
  512. }
  513. catch (Exception ex)
  514. {
  515. XLog.SaveLog(0, "解压uncau:" + ex.Message);
  516. }
  517. }
  518. public string unCompressRAR(string unRarPatch, string rarPatch, string rarName)
  519. {
  520. string the_rar;
  521. RegistryKey the_Reg;
  522. object the_Obj;
  523. string the_Info;
  524. try
  525. {
  526. the_Reg = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\WinRAR.exe");
  527. the_Obj = the_Reg.GetValue("");
  528. the_rar = the_Obj.ToString();
  529. the_Reg.Close();
  530. if (Directory.Exists(unRarPatch) == false)
  531. {
  532. Directory.CreateDirectory(unRarPatch);
  533. }
  534. the_Info = "x " + rarName + " " + unRarPatch + " -y";
  535. ProcessStartInfo the_StartInfo = new ProcessStartInfo();
  536. the_StartInfo.FileName = the_rar;
  537. the_StartInfo.Arguments = the_Info;
  538. the_StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
  539. the_StartInfo.WorkingDirectory = rarPatch;//获取压缩包路径
  540. Process the_Process = new Process();
  541. the_Process.StartInfo = the_StartInfo;
  542. the_Process.Start();
  543. the_Process.WaitForExit();
  544. the_Process.Close();
  545. }
  546. catch (Exception ex)
  547. {
  548. throw ex;
  549. }
  550. return unRarPatch;
  551. }
  552. private void ShellCdrConvertPng(string path, string targPath)
  553. {
  554. ShellFile shellFile = ShellFile.FromFilePath(path);
  555. System.Drawing.Bitmap shellThumb = shellFile.Thumbnail.ExtraLargeBitmap;
  556. //在画板的指定位置画图
  557. targPath = targPath.Replace(".cdr", ".png");
  558. shellThumb.Save(targPath, ImageFormat.Png);
  559. shellThumb.Dispose();
  560. shellFile.Dispose();
  561. }
  562. private void CdrConvertPng(string path, string targPath)
  563. {
  564. using (Aspose.Imaging.FileFormats.Cdr.CdrImage image = (Aspose.Imaging.FileFormats.Cdr.CdrImage)Aspose.Imaging.Image.Load(path))
  565. {
  566. PngOptions options = new Aspose.Imaging.ImageOptions.PngOptions();
  567. options.ColorType = Aspose.Imaging.FileFormats.Png.PngColorType.TruecolorWithAlpha;
  568. // Set rasterization options for fileformat
  569. options.VectorRasterizationOptions = (Aspose.Imaging.ImageOptions.VectorRasterizationOptions)
  570. image.GetDefaultOptions(new object[] { Aspose.Imaging.Color.White, image.Width, image.Height });
  571. options.VectorRasterizationOptions.TextRenderingHint = TextRenderingHint.ClearTypeGridFit;
  572. options.VectorRasterizationOptions.SmoothingMode = Aspose.Imaging.SmoothingMode.None;
  573. targPath = targPath.Replace(".cdr", ".png");
  574. image.Save(targPath, options);
  575. options.Dispose();
  576. }
  577. }
  578. private string CdrExPng(string path, string targPath)
  579. {
  580. try
  581. {
  582. targPath = targPath.Replace(".cdr", ".png");
  583. Application cdr = new Application();
  584. cdr.OpenDocument(path, 1);
  585. cdr.ActiveDocument.ExportBitmap(
  586. targPath,
  587. cdrFilter.cdrPNG,
  588. cdrExportRange.cdrCurrentPage,
  589. cdrImageType.cdrRGBColorImage,
  590. 0, 0, 72, 72,
  591. cdrAntiAliasingType.cdrNoAntiAliasing,
  592. false,
  593. true,
  594. true,
  595. false,
  596. cdrCompressionType.cdrCompressionNone,
  597. null).Finish();
  598. cdr.ActiveDocument.Close();
  599. cdr.Quit();
  600. cdr = null;
  601. GC.Collect();
  602. }
  603. catch (Exception ex)
  604. {
  605. XLog.SaveLog(0, path + ",转成图片出错:" + ex.Message);
  606. }
  607. finally
  608. {
  609. }
  610. return "111";
  611. }
  612. private static object cdrpngobj = new object();
  613. private void CdrExportPng(string path, string cdrFile)
  614. {
  615. lock (cdrpngobj)
  616. {
  617. string fname = curPath + "\\" + Path.GetFileNameWithoutExtension(cdrFile) + ".png";
  618. string new_fname = path + "\\" + Path.GetFileNameWithoutExtension(cdrFile) + ".png";
  619. CorelDRAW.Application cdr = new CorelDRAW.Application();
  620. cdr.OpenDocument(cdrFile, 1);
  621. cdr.ActiveDocument.ExportBitmap(
  622. fname,
  623. CorelDRAW.cdrFilter.cdrPNG,
  624. CorelDRAW.cdrExportRange.cdrCurrentPage,
  625. CorelDRAW.cdrImageType.cdrRGBColorImage,
  626. 0, 0, 72, 72,
  627. CorelDRAW.cdrAntiAliasingType.cdrNoAntiAliasing,
  628. false,
  629. true,
  630. true,
  631. false,
  632. CorelDRAW.cdrCompressionType.cdrCompressionNone,
  633. null).Finish();
  634. cdr.ActiveDocument.Close();
  635. cdr.Quit();
  636. if (File.Exists(fname))
  637. {
  638. File.Copy(fname, new_fname);
  639. File.Delete(fname);
  640. }
  641. }
  642. }
  643. public static string MidStrEx(string sourse, string startstr, string endstr)
  644. {
  645. string result = string.Empty;
  646. int startindex, endindex;
  647. try
  648. {
  649. startindex = sourse.IndexOf(startstr);
  650. if (startindex == -1)
  651. return result;
  652. string tmpstr = sourse.Substring(startindex + startstr.Length);
  653. endindex = tmpstr.IndexOf(endstr);
  654. if (endindex == -1)
  655. return result;
  656. result = tmpstr.Remove(endindex);
  657. }
  658. catch (Exception ex)
  659. {
  660. Console.WriteLine("MidStrEx Err:" + ex.Message);
  661. }
  662. return result;
  663. }
  664. private static string logPath = ConfigurationManager.AppSettings["curPath"] + "\\log";
  665. private static object logFlag = new object();
  666. public static void writeLog(string log)
  667. {
  668. lock (logFlag)
  669. {
  670. using (FileStream fileStream = new FileStream(logPath + "\\" + DateTime.Now.ToString("yy-MM-dd") + ".log", FileMode.Append, FileAccess.Write))
  671. {
  672. using (StreamWriter sw = new StreamWriter(fileStream, Encoding.Default))
  673. {
  674. sw.Write(log + " ------时间:" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "\r\n");
  675. sw.Flush();
  676. }
  677. }
  678. }
  679. }
  680. }