uploadFile.aspx.cs 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730
  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. string extend = Path.GetExtension(file_name).ToLower();
  195. if (!(extend == ".cdr" || extend == ".zip" || extend == ".rar" || extend == ".pdf"))
  196. {
  197. conErc("只允许上传zip和cdr文件!");
  198. return;
  199. }
  200. if (entity.OrderState != 5)
  201. {
  202. entity.FinishDesignTime = DateTime.Now;
  203. if (entity.isDianziOrder == 1 || entity.ProductId == 57 || entity.ProductId == 28)
  204. {
  205. entity.OrderState = 6;
  206. entity.SupplierId = 35;
  207. entity.FinishPlaceTime = DateTime.Now;
  208. bool sendResult = commonHelper.SetOrderDummyDelivery(entity.tid);
  209. if (sendResult)
  210. {
  211. entity.OrderState = 7;
  212. }
  213. }
  214. else
  215. entity.OrderState = 5; //设计完成
  216. //if (entity.IsReturn == 2) //2是下单人打回给设计的,重新上传的话,需要清除打回
  217. //{
  218. entity.IsReturn = 0;
  219. entity.IsXianHuo = 0;
  220. entity.IsVerifyToSupplier = false;
  221. //}
  222. }
  223. if (entity.MemoOpt == 1 || entity.MemoOpt == 2)
  224. {
  225. entity.MemoOpt = 0;
  226. }
  227. if (entity.payment < 500)
  228. {
  229. if (entity.seller_memo.Contains("插卡") && entity.ProductCount != null && !entity.seller_memo.Contains("S_"))
  230. {
  231. int num = 0;
  232. try
  233. {
  234. string text = entity.ProductCount;
  235. string pattern = @"(\d+)\s*张";
  236. MatchCollection matches = Regex.Matches(text, pattern);
  237. foreach (Match match in matches)
  238. {
  239. if (match.Success)
  240. {
  241. num = Convert.ToInt32(match.Groups[1].Value);
  242. break;
  243. }
  244. }
  245. }
  246. catch (Exception ex)
  247. {
  248. }
  249. if (num >= 100)
  250. {
  251. entity.IsVerifyToSupplier = true;
  252. entity.SupplierId = 3;
  253. entity.FinishPlaceTime = DateTime.Now;
  254. }
  255. }
  256. 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("帆布"))
  257. {
  258. entity.IsVerifyToSupplier = true;
  259. entity.SupplierId = 98;
  260. entity.FinishPlaceTime = DateTime.Now;
  261. }
  262. }
  263. string dPath = entity.FinishDesignTime.GetValueOrDefault().ToString("yyyyMMdd");
  264. //XLog.SaveLog(5, dPath);
  265. string sPath = Path.Combine(upPath, dPath);
  266. string cpath = Path.Combine(upPath, entity.FinishDesignTime.GetValueOrDefault().ToString("yyyyMM"));
  267. //XLog.SaveLog(5, sPath);
  268. //XLog.SaveLog(5, Directory.Exists(sPath).ToString());
  269. if (!Directory.Exists(sPath)) Directory.CreateDirectory(sPath);
  270. if (!Directory.Exists(cpath)) Directory.CreateDirectory(cpath);
  271. string saveFile = Path.Combine(sPath, file_name);
  272. string f_ext = Path.GetExtension(saveFile);
  273. string[] extArr = new string[] { ".cdr", ".zip", ".rar", ".pdf" };
  274. string _file = "";
  275. foreach (string ext in extArr)
  276. {
  277. if (f_ext != ext)
  278. {
  279. _file = saveFile.Replace(f_ext, ext);
  280. if (File.Exists(_file)) File.Delete(_file);
  281. }
  282. else
  283. {
  284. if (File.Exists(saveFile)) File.Delete(saveFile);
  285. }
  286. }
  287. //上传文件
  288. postFile.SaveAs(saveFile);
  289. entity.FileMd5 = GetMD5HashFromFile(postFile);
  290. //XLog.SaveLog(0, saveFile);
  291. entity.UpdateTime = DateTime.Now;
  292. entity.Update();
  293. //CeErpTradeCell.UpdateRelationOrder(entity);
  294. CeErpTradeCell.UpdateRelationOrder(entity.ctid);
  295. CeErpTradeLog.AddLog(entity.ctid, entity.OrderState, userId, "上传设计文件-" + saveFile);
  296. if (ctid.IndexOf("S_") >= -1)
  297. {
  298. StringBuilder sql = new StringBuilder();
  299. sql.AppendFormat("select * from Ce_ErpTradeCellExtend where ctid='{0}'", entity.ctid);
  300. DataTable cellEx = CeErpTradeCell.ExecuteDataset(sql.ToString()).Tables[0];
  301. if (cellEx.Rows.Count > 0)
  302. {
  303. string txtReprintTime = cellEx.Rows[0]["ReprintTime"].ToString();
  304. if (!string.IsNullOrEmpty(txtReprintTime) && !"null".Equals(txtReprintTime))
  305. {
  306. DateTime reprint = DateTime.Parse(txtReprintTime);
  307. if (DateTime.Compare(DateTime.Now.AddHours(-24), reprint) >= 0)
  308. {
  309. string parentId = entity.ctid.Substring(2);
  310. string update_sql = string.Format("update Ce_ErpTradeAfterSaleExtend set ReprintOut = ReprintOut+1 where tid= '{0}' ;", parentId);
  311. CeErpTradeLog.ExecuteNonQuery(update_sql);
  312. }
  313. }
  314. }
  315. }
  316. if (Path.GetExtension(saveFile).IndexOf("cdr", StringComparison.OrdinalIgnoreCase) != -1)
  317. {
  318. //string sql = string.Format("insert into s_cdrtopng(name,addtime)values('{0}',getdate()) ;", saveFile);
  319. //CeErpTradeLog.ExecuteNonQuery(sql);
  320. }
  321. else if (Path.GetExtension(saveFile).IndexOf("zip", StringComparison.OrdinalIgnoreCase) != -1 || Path.GetExtension(saveFile).IndexOf("rar", StringComparison.OrdinalIgnoreCase) != -1)
  322. {
  323. try
  324. {
  325. DecompressZIPandRAR(saveFile, sPath, file_name);
  326. }
  327. catch (Exception ex)
  328. {
  329. CeErpTradeLog.AddLog(entity.ctid, entity.OrderState, entity.DesignUserId, "解压失败!");
  330. XLog.SaveLog(0, "上传解压发生错误!" + ex.Message);
  331. }
  332. //Decompress(saveFile,sPath);
  333. }
  334. //new Thread(new ThreadStart(delegate ()
  335. //{
  336. //System.Threading.Thread.Sleep(2000);
  337. if (Path.GetExtension(saveFile).IndexOf("cdr", StringComparison.OrdinalIgnoreCase) != -1)
  338. {
  339. var identity = WindowsIdentity.GetCurrent();
  340. var principal = new WindowsPrincipal(identity);
  341. writeLog("上传完成!" + saveFile);
  342. Task.Run(async () =>
  343. {
  344. string filePath = Path.GetFullPath(saveFile);
  345. string targPath = Path.Combine(cpath, file_name);
  346. using (identity.Impersonate())
  347. {
  348. try
  349. {
  350. if (File.Exists(filePath))
  351. {
  352. cdrConvert.CdrConvertPng(filePath, targPath);
  353. }
  354. }
  355. catch (Exception ex)
  356. {
  357. XLog.SaveLog(0, filePath + ",转成图片出错:" + ex.Message);
  358. }
  359. }
  360. });
  361. }
  362. //})).Start();
  363. conSuc("上传成功!");
  364. return;
  365. }
  366. else
  367. {
  368. conErc("找不到对应的订单");
  369. return;
  370. }
  371. }
  372. catch (Exception ex)
  373. {
  374. conErc("上传发生错误!" + CommonHelper.FormatTextArea(ex.Message));
  375. CeErpTradeLog.AddLog(entity.ctid, entity.OrderState, entity.DesignUserId, "上传失败!");
  376. XLog.SaveLog(0, "上传发生错误!" + ex.Message);
  377. return;
  378. }
  379. finally
  380. {
  381. if (postFile != null)
  382. {
  383. postFile.InputStream.Close();
  384. }
  385. }
  386. }
  387. conErc("空文件!");
  388. }
  389. class CdrConvert
  390. {
  391. private object lockObject = new object();
  392. public void CdrConvertPng(string filePath, string targPath)
  393. {
  394. lock (lockObject)
  395. {
  396. writeLog("开始截图!" + filePath);
  397. targPath = targPath.Replace(".cdr", ".png");
  398. try
  399. {
  400. Application cdr = new Application();
  401. cdr.OpenDocument(filePath, 1);
  402. cdr.ActiveDocument.ExportBitmap(
  403. targPath,
  404. cdrFilter.cdrPNG,
  405. cdrExportRange.cdrCurrentPage,
  406. cdrImageType.cdrRGBColorImage,
  407. 0, 0, 72, 72,
  408. cdrAntiAliasingType.cdrNoAntiAliasing,
  409. false,
  410. true,
  411. true,
  412. false,
  413. cdrCompressionType.cdrCompressionNone,
  414. null).Finish();
  415. cdr.ActiveDocument.Close();
  416. cdr.Quit();
  417. cdr = null;
  418. }
  419. catch (Exception ex)
  420. {
  421. XLog.SaveLog(0, targPath + ",转成图片出错:" + ex.Message);
  422. }
  423. finally
  424. {
  425. KillProcessByName("CorelDRW");
  426. }
  427. }
  428. }
  429. void KillProcessByName(string processName)
  430. {
  431. Process[] processes = Process.GetProcessesByName(processName);
  432. foreach (Process process in processes)
  433. {
  434. try
  435. {
  436. process.Kill();
  437. process.WaitForExit(); // 等待进程退出
  438. }
  439. catch (Exception ex)
  440. {
  441. }
  442. }
  443. }
  444. }
  445. private void DecompressZIPandRAR(string zipFile, string targetPath, string filename)
  446. {
  447. string notExtension = filename.Substring(0, filename.Length - 4);
  448. SevenZipExtractor.SetLibraryPath(Server.MapPath("bin\\7z.dll"));
  449. LibraryFeature lf = SevenZipExtractor.CurrentLibraryFeatures;
  450. using (SevenZipExtractor szExtra = new SevenZipExtractor(zipFile))
  451. {
  452. //szExtra.ExtractArchive("d:\\temp");
  453. foreach (string afn in szExtra.ArchiveFileNames)
  454. {
  455. if (afn.IndexOf(notExtension, StringComparison.OrdinalIgnoreCase) != -1)
  456. {
  457. szExtra.ExtractFiles(targetPath, afn);
  458. break;
  459. }
  460. }
  461. }
  462. }
  463. private void Decompress(string GzipFile, string targetPath)
  464. {
  465. //string directoryName = Path.GetDirectoryName(targetPath + "\\") + "\\";
  466. string directoryName = targetPath + "\\";
  467. if (!Directory.Exists(directoryName)) Directory.CreateDirectory(directoryName);//生成解压目录
  468. //helper.writeLog(GzipFile);
  469. //helper.writeLog(directoryName);
  470. string CurrentDirectory = directoryName;
  471. byte[] data = new byte[2048];
  472. int size = 2048;
  473. ZipEntry theEntry = null;
  474. Stream _stream = File.OpenRead(GzipFile);
  475. if (_stream.Length == 0) { _stream.Close(); return; }
  476. try
  477. {
  478. using (ZipInputStream s = new ZipInputStream(_stream))
  479. {
  480. while ((theEntry = s.GetNextEntry()) != null)
  481. {
  482. if (theEntry.IsDirectory)
  483. {// 该结点是目录
  484. if (!Directory.Exists(CurrentDirectory + theEntry.Name)) Directory.CreateDirectory(CurrentDirectory + theEntry.Name);
  485. }
  486. else
  487. {
  488. if (theEntry.Name != String.Empty && (theEntry.Name.IndexOf(".png", StringComparison.OrdinalIgnoreCase) != -1 || theEntry.Name.IndexOf(".jpg", StringComparison.OrdinalIgnoreCase) != -1))
  489. {
  490. //解压文件到指定的目录
  491. using (FileStream streamWriter = File.Create(CurrentDirectory + theEntry.Name))
  492. {
  493. while (true)
  494. {
  495. size = s.Read(data, 0, data.Length);
  496. if (size <= 0) break;
  497. streamWriter.Write(data, 0, size);
  498. }
  499. streamWriter.Close();
  500. }
  501. break;
  502. }
  503. }
  504. }
  505. s.Close();
  506. }
  507. }
  508. catch (Exception ex)
  509. {
  510. XLog.SaveLog(0, "解压uncau:" + ex.Message);
  511. }
  512. }
  513. public string unCompressRAR(string unRarPatch, string rarPatch, string rarName)
  514. {
  515. string the_rar;
  516. RegistryKey the_Reg;
  517. object the_Obj;
  518. string the_Info;
  519. try
  520. {
  521. the_Reg = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\WinRAR.exe");
  522. the_Obj = the_Reg.GetValue("");
  523. the_rar = the_Obj.ToString();
  524. the_Reg.Close();
  525. if (Directory.Exists(unRarPatch) == false)
  526. {
  527. Directory.CreateDirectory(unRarPatch);
  528. }
  529. the_Info = "x " + rarName + " " + unRarPatch + " -y";
  530. ProcessStartInfo the_StartInfo = new ProcessStartInfo();
  531. the_StartInfo.FileName = the_rar;
  532. the_StartInfo.Arguments = the_Info;
  533. the_StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
  534. the_StartInfo.WorkingDirectory = rarPatch;//获取压缩包路径
  535. Process the_Process = new Process();
  536. the_Process.StartInfo = the_StartInfo;
  537. the_Process.Start();
  538. the_Process.WaitForExit();
  539. the_Process.Close();
  540. }
  541. catch (Exception ex)
  542. {
  543. throw ex;
  544. }
  545. return unRarPatch;
  546. }
  547. private void ShellCdrConvertPng(string path, string targPath)
  548. {
  549. ShellFile shellFile = ShellFile.FromFilePath(path);
  550. System.Drawing.Bitmap shellThumb = shellFile.Thumbnail.ExtraLargeBitmap;
  551. //在画板的指定位置画图
  552. targPath = targPath.Replace(".cdr", ".png");
  553. shellThumb.Save(targPath, ImageFormat.Png);
  554. shellThumb.Dispose();
  555. shellFile.Dispose();
  556. }
  557. private void CdrConvertPng(string path, string targPath)
  558. {
  559. using (Aspose.Imaging.FileFormats.Cdr.CdrImage image = (Aspose.Imaging.FileFormats.Cdr.CdrImage)Aspose.Imaging.Image.Load(path))
  560. {
  561. PngOptions options = new Aspose.Imaging.ImageOptions.PngOptions();
  562. options.ColorType = Aspose.Imaging.FileFormats.Png.PngColorType.TruecolorWithAlpha;
  563. // Set rasterization options for fileformat
  564. options.VectorRasterizationOptions = (Aspose.Imaging.ImageOptions.VectorRasterizationOptions)
  565. image.GetDefaultOptions(new object[] { Aspose.Imaging.Color.White, image.Width, image.Height });
  566. options.VectorRasterizationOptions.TextRenderingHint = TextRenderingHint.ClearTypeGridFit;
  567. options.VectorRasterizationOptions.SmoothingMode = Aspose.Imaging.SmoothingMode.None;
  568. targPath = targPath.Replace(".cdr", ".png");
  569. image.Save(targPath, options);
  570. options.Dispose();
  571. }
  572. }
  573. private string CdrExPng(string path, string targPath)
  574. {
  575. try
  576. {
  577. targPath = targPath.Replace(".cdr", ".png");
  578. Application cdr = new Application();
  579. cdr.OpenDocument(path, 1);
  580. cdr.ActiveDocument.ExportBitmap(
  581. targPath,
  582. cdrFilter.cdrPNG,
  583. cdrExportRange.cdrCurrentPage,
  584. cdrImageType.cdrRGBColorImage,
  585. 0, 0, 72, 72,
  586. cdrAntiAliasingType.cdrNoAntiAliasing,
  587. false,
  588. true,
  589. true,
  590. false,
  591. cdrCompressionType.cdrCompressionNone,
  592. null).Finish();
  593. cdr.ActiveDocument.Close();
  594. cdr.Quit();
  595. cdr = null;
  596. GC.Collect();
  597. }
  598. catch (Exception ex)
  599. {
  600. XLog.SaveLog(0, path + ",转成图片出错:" + ex.Message);
  601. }
  602. finally
  603. {
  604. }
  605. return "111";
  606. }
  607. private static object cdrpngobj = new object();
  608. private void CdrExportPng(string path, string cdrFile)
  609. {
  610. lock (cdrpngobj)
  611. {
  612. string fname = curPath + "\\" + Path.GetFileNameWithoutExtension(cdrFile) + ".png";
  613. string new_fname = path + "\\" + Path.GetFileNameWithoutExtension(cdrFile) + ".png";
  614. CorelDRAW.Application cdr = new CorelDRAW.Application();
  615. cdr.OpenDocument(cdrFile, 1);
  616. cdr.ActiveDocument.ExportBitmap(
  617. fname,
  618. CorelDRAW.cdrFilter.cdrPNG,
  619. CorelDRAW.cdrExportRange.cdrCurrentPage,
  620. CorelDRAW.cdrImageType.cdrRGBColorImage,
  621. 0, 0, 72, 72,
  622. CorelDRAW.cdrAntiAliasingType.cdrNoAntiAliasing,
  623. false,
  624. true,
  625. true,
  626. false,
  627. CorelDRAW.cdrCompressionType.cdrCompressionNone,
  628. null).Finish();
  629. cdr.ActiveDocument.Close();
  630. cdr.Quit();
  631. if (File.Exists(fname))
  632. {
  633. File.Copy(fname, new_fname);
  634. File.Delete(fname);
  635. }
  636. }
  637. }
  638. public static string MidStrEx(string sourse, string startstr, string endstr)
  639. {
  640. string result = string.Empty;
  641. int startindex, endindex;
  642. try
  643. {
  644. startindex = sourse.IndexOf(startstr);
  645. if (startindex == -1)
  646. return result;
  647. string tmpstr = sourse.Substring(startindex + startstr.Length);
  648. endindex = tmpstr.IndexOf(endstr);
  649. if (endindex == -1)
  650. return result;
  651. result = tmpstr.Remove(endindex);
  652. }
  653. catch (Exception ex)
  654. {
  655. Console.WriteLine("MidStrEx Err:" + ex.Message);
  656. }
  657. return result;
  658. }
  659. private static string logPath = ConfigurationManager.AppSettings["curPath"] + "\\log";
  660. private static object logFlag = new object();
  661. public static void writeLog(string log)
  662. {
  663. lock (logFlag)
  664. {
  665. using (FileStream fileStream = new FileStream(logPath + "\\" + DateTime.Now.ToString("yy-MM-dd") + ".log", FileMode.Append, FileAccess.Write))
  666. {
  667. using (StreamWriter sw = new StreamWriter(fileStream, Encoding.Default))
  668. {
  669. sw.Write(log + " ------时间:" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "\r\n");
  670. sw.Flush();
  671. }
  672. }
  673. }
  674. }
  675. }