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