| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081 |
- using BizCom;
- using ICSharpCode.SharpZipLib.Zip;
- using Microsoft.Win32;
- using SevenZip;
- using System;
- using System.Configuration;
- using System.Diagnostics;
- using System.IO;
- using System.Text;
- using System.Web;
- using Utils;
- using SiteCore;
- using Aspose.Imaging.ImageOptions;
- using Aspose.Imaging;
- using Microsoft.WindowsAPICodePack.Shell;
- using System.Drawing.Imaging;
- using CorelDRAW;
- using System.Security.Principal;
- using System.Threading.Tasks;
- using System.Data;
- using System.Text.RegularExpressions;
- using MSharp.Framework;
- using System.Net.Http.Headers;
- using System.Net.Http;
- using SQLData;
- using NHibernate.Mapping;
- using System.Collections.Generic;
- using System.Linq;
- public partial class uploadFile : System.Web.UI.Page
- {
- public static string upPath = ConfigurationManager.AppSettings["upPath"];
- public static string curPath = ConfigurationManager.AppSettings["curPath"];
- static CdrConvert cdrConvert = new CdrConvert();
- private void conSuc(string msg)
- {
- Response.Write("{\"res\":\"1\",\"msg\":\"" + msg + "!\"}");
- //Response.End();
- }
- private void conErc(string msg)
- {
- Response.Write("{\"res\":\"0\",\"msg\":\"" + msg + "!\"}");
- //Response.End();
- }
- public string GetMD5HashFromFile(HttpPostedFile file)
- {
- try
- {
- System.Security.Cryptography.MD5 md5 = new System.Security.Cryptography.MD5CryptoServiceProvider();
- byte[] retVal = md5.ComputeHash(file.InputStream);
- StringBuilder sb = new StringBuilder();
- for (int i = 0; i < retVal.Length; i++)
- {
- sb.Append(retVal[i].ToString("x2"));
- }
- return sb.ToString();
- }
- catch (Exception ex)
- {
- XLog.SaveLog(0, "上传MD5错误!" + ex.Message);
- }
- return "";
- }
- private static byte[] GetBlobByHttpPostedFile(HttpPostedFile httpPostedFile)
- {
- var contentLength = httpPostedFile.ContentLength;
- var result = new byte[contentLength];
- var inputStream = httpPostedFile.InputStream;
- inputStream.Read(result, 0, contentLength);
- return result;
- }
- protected void Page_Load(object sender, EventArgs e)
- {
- //if (CurrentUser == null)
- //{
- // Response.Write(err);
- // return;
- //}
- //CeErpTradeCell.GetByCtid("1717009344450030601");
- if (Request.Files.Count < 1)
- {
- conErc("空文件!");
- return;
- }
- int userId = 0;
- int orgid = 0;
- if (Request["userid"] != null)
- {
- userId = Convert.ToInt32(Request["userid"]);
- }
- if (Request["orgid"] != null)
- {
- orgid = Convert.ToInt32(Request["orgid"]);
- }
- HttpPostedFile postFile = Request.Files[0];
- if (postFile != null)
- {
- string file_name = postFile.FileName;
- string namePattern = @"《(.*?)》";
- Regex nameReg = new Regex(namePattern, RegexOptions.IgnoreCase | RegexOptions.Multiline, TimeSpan.FromSeconds(2));//2秒后超时
- MatchCollection nameMatches = nameReg.Matches(file_name);//设定要查找的字符串
- if (nameMatches.Count > 0)
- {
- foreach (Match match in nameMatches)
- {
- file_name = file_name.Replace(match.Value, "");
- }
- }
- file_name = file_name.Replace("(", "(");
- file_name = file_name.Replace(")", ")");
- string ctid = MidStrEx(file_name, "(", ")").Trim();
- if (string.IsNullOrEmpty(ctid))
- {
- conErc("上传的文件名格式不正确");
- return;
- }
- string memoCtid = ctid;
- if (ctid.IndexOf("C") == -1)
- {
- if (file_name.IndexOf("[") != -1 && file_name.IndexOf("C") != -1)
- {
- if (ctid.IndexOf("S_") != -1) // (S_S_1962772776865084101)[C1] 对应ctid是 S_S_C1_1962772776865084101
- {
- int lastIndex = ctid.LastIndexOf("S_"); //最后一个S_的位置
- string sPre = ctid.Substring(0, lastIndex + 2); //S_S_
- string initTid = ctid.Substring(lastIndex + 2, ctid.Length - lastIndex - 2); //1962772776865084101
- string pre_ctid = MidStrEx(file_name, "[", "]"); //C1
- if (pre_ctid.IndexOf("+") != -1)
- {
- pre_ctid = "C" + pre_ctid.Split('+')[1];
- }
- memoCtid = sPre + pre_ctid + "_" + initTid; //S_S_ + C1 + _ +1962772776865084101
- }
- else
- {
- string pre_ctid = MidStrEx(file_name, "[", "]");
- if (pre_ctid.IndexOf("+") != -1)
- {
- pre_ctid = "C" + pre_ctid.Split('+')[1];
- }
- memoCtid = pre_ctid + "_" + ctid;
- }
- }
- }
- CeErpTradeCell entity = null;
- if (ctid != "") entity = CeErpTradeCell.GetByCode(ctid);
- if (entity == null) entity = CeErpTradeCell.GetByCtid(ctid);
- if (entity == null) entity = CeErpTradeCell.GetByCtid(memoCtid);
- try
- {
- if (entity != null)
- {
- string pname = Path.GetFileNameWithoutExtension(file_name);
- if (entity.IsRefund == 2)
- {
- StringBuilder sql = new StringBuilder();
- sql.AppendFormat("select refund_status from CE_ErpTradeOrder where tid='{0}'", entity.tid);
- DataTable dt = CeErpTradeCell.ExecuteDataset(sql.ToString()).Tables[0];
- bool isAll = true;
- foreach (DataRow dr in dt.Rows)
- {
- if ("NO_REFUND".Equals(dr["refund_status"]))
- {
- isAll = false;
- break;
- }
- }
- if (isAll)
- {
- conErc("此单退款,不允许上传");
- return;
- }
- }
- if (entity.seller_memo != pname)
- {
- conErc("上传的文件名与备注不符合!");
- return;
- }
- if (entity.OrderState == -1)
- {
- conErc("还未审核不允许上传");
- return;
- }
- if (entity.OrderState < (int)OrderState.设计中 && orgid != 10 && orgid != 4)
- {
- conErc("还未开始设计不允许上传");
- return;
- }
- //if (pname.IndexOf("现货") != -1)
- //{
- // conErc("设计款的单文件名不能有现货字眼");
- // return;
- //}
- //更新状态
- if (entity.OrderState >= (int)OrderState.下单完成)
- {
- conErc("已经下单无法上传!");
- return;
- }
- if (entity.IsVerifyToSupplier)
- {
- conErc("订单已到车间无法上传!");
- return;
- }
- string extend = Path.GetExtension(file_name).ToLower();
- if (!(extend == ".cdr" || extend == ".zip" || extend == ".rar" || extend == ".pdf"))
- {
- conErc("只允许上传zip和cdr文件!");
- return;
- }
- if (entity.OrderState != 5)
- {
- entity.FinishDesignTime = DateTime.Now;
- if (entity.isDianziOrder == 1 || entity.ProductId == 57 || entity.ProductId == 28)
- {
- entity.OrderState = 6;
- entity.SupplierId = 35;
- entity.FinishPlaceTime = DateTime.Now;
- bool sendResult = commonHelper.SetOrderDummyDelivery(entity.tid);
- if (sendResult)
- {
- entity.OrderState = 7;
- }
- }
- else
- entity.OrderState = 5; //设计完成
- //if (entity.IsReturn == 2) //2是下单人打回给设计的,重新上传的话,需要清除打回
- //{
- entity.IsXianHuo = 0;
- entity.IsVerifyToSupplier = false;
- //}
- }
- entity.IsReturn = 0;
- int num = getProductCount(entity.seller_memo);
- if (entity.MemoOpt == 1 || entity.MemoOpt == 2)
- {
- entity.MemoOpt = 0;
- }
- if (entity.payment < 500)
- {
- if (entity.seller_memo.Contains("插卡") && entity.ProductCount != null && !entity.seller_memo.Contains("S_"))
- {
- if (num >= 100)
- {
- entity.IsVerifyToSupplier = true;
- entity.SupplierId = 3;
- entity.FinishPlaceTime = DateTime.Now;
- }
- }
- 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("帆布") && !entity.seller_memo.Contains("帆布袋") && !entity.seller_memo.Contains("封边尺寸"))) && !entity.seller_memo.Contains("电子稿"))
- {
- entity.IsVerifyToSupplier = true;
- entity.SupplierId = 98;
- entity.FinishPlaceTime = DateTime.Now;
- }
- }
- string patterns = "出货|加急|顺丰|打印|专版|当天发";
- if (!Regex.IsMatch(entity.seller_memo, patterns) && string.IsNullOrEmpty(entity.OtherMemo) && !entity.ctid.Contains("S_"))
- {
- if (entity.payment <= 300 && num >= 200 && num <= 3000 && entity.ShopId != 14 && entity.ShopId != 99)
- {
- //300克铜板纸/铜版纸300克-覆哑膜/覆膜/不覆膜-直角/裁切
- if (!entity.seller_memo.Contains("opp") && !entity.seller_memo.Contains("按文件") && !entity.seller_memo.Contains("流苏") && !entity.seller_memo.Contains("排序") && !entity.seller_memo.Contains("烫金"))
- {
- if ((entity.seller_memo.Contains("直角") || entity.seller_memo.Contains("裁切")) && (entity.seller_memo.Contains("300克铜板纸") || entity.seller_memo.Contains("300克铜板纸")) && (entity.seller_memo.Contains("覆哑膜") || entity.seller_memo.Contains("覆膜") || entity.seller_memo.Contains("不覆膜")))
- {
- entity.IsVerifyToSupplier = true;
- entity.SupplierId = 14;
- entity.FinishPlaceTime = DateTime.Now;
- }
- }
- }
- if (entity.payment <= 100 && num > 500 && num <= 1500)
- {
- //数量0-1500
- //0-80*54
- string pattern = @"\b(\d{1,5}[x\*]\d{1,5}(mm|cm))\b";
- string memo = entity.seller_memo.Replace("MM", "mm").Replace("CM", "cm");
- Regex reg = new Regex(pattern, RegexOptions.IgnoreCase | RegexOptions.Multiline, TimeSpan.FromSeconds(2));//2秒后超时
- MatchCollection matches = reg.Matches(memo);//设定要查找的字符串
- string size = "";
- double min_width = 80;
- double min_height = 54;
- double width = 0;
- double height = 0;
- bool isIn = false;
- try
- {
- if (matches[0].Success)
- {
- size = matches[0].Groups[0].Value;
- size = size.Replace("mm", "");
- size = size.Replace("cm", "");
- string[] size_list = size.Split('x');
- if (size_list.Length > 1)
- {
- width = Convert.ToDouble(size_list[0]);
- height = Convert.ToDouble(size_list[1]);
- }
- if ((width <= min_width && height <= min_height) || (height <= min_width && width <= min_height))
- {
- isIn = true;
- }
- if (width < 30 || height < 30)
- {
- isIn = false;
- }
- }
- }
- catch (Exception ex)
- {
- }
- //铜版纸不干胶-覆亮膜
- if (isIn && entity.seller_memo.Contains("铜版纸不干胶") && entity.seller_memo.Contains("覆亮膜") && !entity.seller_memo.Contains("烫金") && !entity.seller_memo.Contains("排序"))
- {
- entity.IsVerifyToSupplier = true;
- entity.SupplierId = 64;
- entity.FinishPlaceTime = DateTime.Now;
- }
- }
- if (entity.payment <= 500 && num > 200 && num <= 5000)
- {
- //数量0-5000
- if (entity.seller_memo.Contains("透明不干胶"))
- {
- entity.IsVerifyToSupplier = true;
- entity.SupplierId = 64;
- entity.FinishPlaceTime = DateTime.Now;
- }
- }
- if (entity.payment <= 100 && num > 200 && num <= 1000)
- {
- //数量0-1000
- if (entity.seller_memo.Contains("铜版纸不干胶") && entity.seller_memo.Contains("覆哑膜"))
- {
- entity.IsVerifyToSupplier = true;
- entity.SupplierId = 64;
- entity.FinishPlaceTime = DateTime.Now;
- }
- }
- if (entity.payment <= 500 && num > 0 && num <= 50)
- {
- //数量0-50
- if (entity.seller_memo.Contains("领淘550灯布海报") || entity.seller_memo.Contains("领淘户外写真海报"))
- {
- entity.IsVerifyToSupplier = true;
- entity.SupplierId = 59;
- entity.FinishPlaceTime = DateTime.Now;
- }
- }
- if (entity.payment <= 500 && num > 0 && num <= 50)
- {
- //数量0-50
- 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("左缝筒") || entity.seller_memo.Contains("四角打孔") || entity.seller_memo.Contains("净裁"))))
- {
- entity.IsVerifyToSupplier = true;
- entity.SupplierId = 90;
- entity.FinishPlaceTime = DateTime.Now;
- }
- }
- }
- if (entity.ProductId == 2690)
- {
- entity.IsVerifyToSupplier = true;
- entity.SupplierId = 97;
- entity.FinishPlaceTime = DateTime.Now;
- }
- if (entity.ProductId == 2701)
- {
- entity.IsVerifyToSupplier = true;
- entity.SupplierId = 98;
- entity.FinishPlaceTime = DateTime.Now;
- }
- string dPath = entity.FinishDesignTime.GetValueOrDefault().ToString("yyyyMMdd");
- //XLog.SaveLog(5, dPath);
- string sPath = Path.Combine(upPath, dPath);
- string cpath = Path.Combine(upPath, entity.FinishDesignTime.GetValueOrDefault().ToString("yyyyMM"));
- //XLog.SaveLog(5, sPath);
- //XLog.SaveLog(5, Directory.Exists(sPath).ToString());
- if (!Directory.Exists(sPath)) Directory.CreateDirectory(sPath);
- if (!Directory.Exists(cpath)) Directory.CreateDirectory(cpath);
- string saveFile = Path.Combine(sPath, file_name);
- string f_ext = Path.GetExtension(saveFile);
- string[] extArr = new string[] { ".cdr", ".zip", ".rar", ".pdf" };
- string _file = "";
- foreach (string ext in extArr)
- {
- if (f_ext != ext)
- {
- _file = saveFile.Replace(f_ext, ext);
- if (File.Exists(_file)) File.Delete(_file);
- }
- else
- {
- if (File.Exists(saveFile)) File.Delete(saveFile);
- }
- }
- //上传文件
- postFile.SaveAs(saveFile);
- entity.FileMd5 = GetMD5HashFromFile(postFile);
- //XLog.SaveLog(0, saveFile);
- entity.UpdateTime = DateTime.Now;
- entity.Update();
- //CeErpTradeCell.UpdateRelationOrder(entity);
- CeErpTradeCell.UpdateRelationOrder(entity.ctid);
- CeErpProduct product = CeErpProduct.GetById(entity.ProductId);
- if (product != null)
- {
- string param = "[{ \"product_type\": \"" + product.PType + "\",\"remark\": \"" + entity.seller_memo + "\",\"index\": \"" + entity.OrderSn + "\",\"orderid\": \"" + entity.ctid + "\",\"price\": \"" + entity.payment + "\"}]";
- sysHttpClient(param);
- }
- CeErpTradeLog.AddLog(entity.ctid, entity.OrderState, userId, "上传设计文件-" + saveFile);
- if (ctid.IndexOf("S_") >= -1)
- {
- StringBuilder sql = new StringBuilder();
- sql.AppendFormat("select * from Ce_ErpTradeCellExtend where ctid='{0}'", entity.ctid);
- DataTable cellEx = CeErpTradeCell.ExecuteDataset(sql.ToString()).Tables[0];
- if (cellEx.Rows.Count > 0)
- {
- string txtReprintTime = cellEx.Rows[0]["ReprintTime"].ToString();
- if (!string.IsNullOrEmpty(txtReprintTime) && !"null".Equals(txtReprintTime))
- {
- DateTime reprint = DateTime.Parse(txtReprintTime);
- if (DateTime.Compare(DateTime.Now.AddHours(-24), reprint) >= 0)
- {
- string parentId = entity.ctid.Substring(2);
- string update_sql = string.Format("update Ce_ErpTradeAfterSaleExtend set ReprintOut = ReprintOut+1 where tid= '{0}' ;", parentId);
- CeErpTradeLog.ExecuteNonQuery(update_sql);
- }
- }
- }
- }
- if (Path.GetExtension(saveFile).IndexOf("cdr", StringComparison.OrdinalIgnoreCase) != -1)
- {
- //string sql = string.Format("insert into s_cdrtopng(name,addtime)values('{0}',getdate()) ;", saveFile);
- //CeErpTradeLog.ExecuteNonQuery(sql);
- }
- else if (Path.GetExtension(saveFile).IndexOf("zip", StringComparison.OrdinalIgnoreCase) != -1 || Path.GetExtension(saveFile).IndexOf("rar", StringComparison.OrdinalIgnoreCase) != -1)
- {
- try
- {
- DecompressZIPandRAR(saveFile, sPath, file_name);
- }
- catch (Exception ex)
- {
- CeErpTradeLog.AddLog(entity.ctid, entity.OrderState, entity.DesignUserId, "解压失败!");
- XLog.SaveLog(0, "上传解压发生错误!" + ex.Message);
- }
- //Decompress(saveFile,sPath);
- }
- //new Thread(new ThreadStart(delegate ()
- //{
- //System.Threading.Thread.Sleep(2000);
- if (Path.GetExtension(saveFile).IndexOf("cdr", StringComparison.OrdinalIgnoreCase) != -1)
- {
- var identity = WindowsIdentity.GetCurrent();
- var principal = new WindowsPrincipal(identity);
- Task.Run(async () =>
- {
- string filePath = Path.GetFullPath(saveFile);
- string targPath = Path.Combine(cpath, file_name);
- using (identity.Impersonate())
- {
- try
- {
- if (File.Exists(filePath))
- {
- cdrConvert.CdrConvertPng(filePath, targPath);
- }
- }
- catch (Exception ex)
- {
- XLog.SaveLog(0, filePath + ",转成图片出错:" + ex.Message);
- }
- }
- });
- }
- //})).Start();
- conSuc("上传成功!");
- return;
- }
- else
- {
- conErc("找不到对应的订单");
- return;
- }
- }
- catch (Exception ex)
- {
- conErc("上传发生错误!" + CommonHelper.FormatTextArea(ex.Message));
- CeErpTradeLog.AddLog(entity.ctid, entity.OrderState, entity.DesignUserId, "上传失败!");
- XLog.SaveLog(0, "上传发生错误!" + ex.Message);
- return;
- }
- finally
- {
- if (postFile != null)
- {
- postFile.InputStream.Close();
- }
- }
- }
- conErc("空文件!");
- }
- private int getsupplierId(CeErpTradeCell entity)
- {
- int supplierId = 0;
- StringBuilder sql = new StringBuilder();
- sql.AppendFormat("select * from CE_ErpUpFileSupplier ");
- DataTable cellEx = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
- int num = getProductCount(entity.seller_memo);
- foreach (DataRow row in cellEx.Rows)
- {
- bool isIn = true;
- //判断材质工艺都要符合
- if (Convert.IsDBNull(row["seller_memo"]))
- {
- string memo = row["seller_memo"].ToString();
- string[] memolist = memo.Split('+');
- for (int i = 0; i < memolist.Length; i++)
- {
- if (!Regex.IsMatch(entity.seller_memo, memolist[i].Replace("/", "|")))
- {
- isIn = false;
- }
- }
- }
- if (!isIn)
- {
- continue;
- }
- //判断金额符不符合
- if (!Convert.IsDBNull(row["payment"]))
- {
- string payment = row["payment"].ToString();
- string[] paymentList = payment.Split('-');
- if (!string.IsNullOrEmpty(paymentList[0]))
- {
- if (entity.payment < Convert.ToDouble(paymentList[0]))
- {
- continue;
- }
- }
- if (!string.IsNullOrEmpty(paymentList[1]))
- {
- if (entity.payment > Convert.ToDouble(paymentList[1]))
- {
- continue;
- }
- }
- }
- if (!Convert.IsDBNull(row["size"]))
- {
- string pattern = @"\b(\d{1,5}[x\*]\d{1,5}(mm|cm))\b";
- string memo = entity.seller_memo.Replace("MM", "mm").Replace("CM", "cm");
- Regex reg = new Regex(pattern, RegexOptions.IgnoreCase | RegexOptions.Multiline, TimeSpan.FromSeconds(2));//2秒后超时
- MatchCollection matches = reg.Matches(memo);//设定要查找的字符串
- double width = 0;
- double height = 0;
- try
- {
- if (matches[0].Success)
- {
- string sizematches = matches[0].Groups[0].Value;
- sizematches = sizematches.Replace("mm", "");
- sizematches = sizematches.Replace("cm", "");
- string[] size_list = sizematches.Split('x');
- if (size_list.Length > 1)
- {
- width = Convert.ToDouble(size_list[0]);
- height = Convert.ToDouble(size_list[1]);
- }
- }
- }
- catch (Exception ex)
- {
- }
- string size = row["size"].ToString();
- string[] sizeList = size.Split('-');
- if (!string.IsNullOrEmpty(sizeList[0]))
- {
- string[] sizeItemList = sizeList[0].Split('x');
- //第一个尺寸格式不正确
- if (sizeItemList.Length < 2)
- {
- continue;
- }
- double sizeWidth = Convert.ToDouble(sizeItemList[0]);
- double sizeheight = Convert.ToDouble(sizeItemList[1]);
- //备注尺寸要大于第一个尺寸
- if (!((width > sizeWidth && height > sizeheight) || (width > sizeheight && height > sizeWidth)))
- {
- continue;
- }
- }
- if (!string.IsNullOrEmpty(sizeList[1]))
- {
- string[] sizeItemList = sizeList[1].Split('x');
- //第二个尺寸格式不正确
- if (sizeItemList.Length < 2)
- {
- continue;
- }
- double sizeWidth = Convert.ToDouble(sizeItemList[0]);
- double sizeheight = Convert.ToDouble(sizeItemList[1]);
- //备注尺寸要大于第二个尺寸
- if (!((width < sizeWidth && height < sizeheight) || (width < sizeheight && height < sizeWidth)))
- {
- continue;
- }
- }
- }
- //判断数量是否符合
- if (!Convert.IsDBNull(row["number"]))
- {
- string numberText = row["number"].ToString();
- string[] numberTextList = numberText.Split('-');
- int number = 0;
- if (!string.IsNullOrEmpty(numberTextList[0]))
- {
- number = Convert.ToInt32(numberTextList[0]);
- if (number > num)
- {
- continue;
- }
- }
- if (!string.IsNullOrEmpty(numberTextList[1]))
- {
- number = Convert.ToInt32(numberTextList[1]);
- if (number < num)
- {
- continue;
- }
- }
- }
- //判断店铺符不符合
- if (!Convert.IsDBNull(row["shopIds"]))
- {
- List<string> shopids = row["shopIds"].ToString().Split(',').ToList();
- if (!shopids.Contains(entity.ShopId.ToString()))
- {
- continue;
- }
- }
- //地区不符合
- if (!Convert.IsDBNull(row["address"]))
- {
- if (!Regex.IsMatch(entity.seller_memo, row["address"].ToString().Replace("、", "|")))
- {
- continue;
- }
- }
- //限制条件
- if (!Convert.IsDBNull(row["filterText"]))
- {
- if (!Regex.IsMatch(entity.seller_memo, row["filterText"].ToString().Replace("/", "|")))
- {
- continue;
- }
- }
- }
- return supplierId;
- }
- class CdrConvert
- {
- private object lockObject = new object();
- public void CdrConvertPng(string filePath, string targPath)
- {
- lock (lockObject)
- {
- targPath = targPath.Replace(".cdr", ".png");
- try
- {
- Application cdr = new Application();
- cdr.OpenDocument(filePath, 1);
- cdr.ActiveDocument.ExportBitmap(
- targPath,
- cdrFilter.cdrPNG,
- cdrExportRange.cdrCurrentPage,
- cdrImageType.cdrRGBColorImage,
- 0, 0, 72, 72,
- cdrAntiAliasingType.cdrNoAntiAliasing,
- false,
- true,
- true,
- false,
- cdrCompressionType.cdrCompressionNone,
- null).Finish();
- cdr.ActiveDocument.Close();
- cdr.Quit();
- cdr = null;
- }
- catch (Exception ex)
- {
- XLog.SaveLog(0, targPath + ",转成图片出错:" + ex.Message);
- }
- finally
- {
- KillProcessByName("CorelDRW");
- }
- }
- }
- void KillProcessByName(string processName)
- {
- Process[] processes = Process.GetProcessesByName(processName);
- foreach (Process process in processes)
- {
- try
- {
- process.Kill();
- process.WaitForExit(); // 等待进程退出
- }
- catch (Exception ex)
- {
- }
- }
- }
- }
- public static int getProductCount(string txt)
- {
- // 提取"个"或"张"前面的数字
- int unit = 0;
- try
- {
- string unitPattern = @"(\d+)(?=个|张|本|套|件|卷|劵|条|箱 )";
- Match unitMatch = Regex.Match(txt, unitPattern);
- string unitNum = unitMatch.Success ? unitMatch.Groups[1].Value : "1";
- if (!int.TryParse(unitNum, out unit))
- {
- return 0;
- }
- }
- catch (Exception ex)
- {
- }
- return unit;
- }
- private void DecompressZIPandRAR(string zipFile, string targetPath, string filename)
- {
- string notExtension = filename.Substring(0, filename.Length - 4);
- SevenZipExtractor.SetLibraryPath(Server.MapPath("bin\\7z.dll"));
- LibraryFeature lf = SevenZipExtractor.CurrentLibraryFeatures;
- using (SevenZipExtractor szExtra = new SevenZipExtractor(zipFile))
- {
- //szExtra.ExtractArchive("d:\\temp");
- foreach (string afn in szExtra.ArchiveFileNames)
- {
- if (afn.IndexOf(notExtension, StringComparison.OrdinalIgnoreCase) != -1)
- {
- szExtra.ExtractFiles(targetPath, afn);
- break;
- }
- }
- }
- }
- public void sysHttpClient(string param)
- {
- Task.Run(async () =>
- {
- var client = new HttpClient();
- var request = new HttpRequestMessage
- {
- Method = HttpMethod.Post,
- RequestUri = new Uri("http://47.122.57.102:11004/quotations/batch"),
- Content = new StringContent(param)
- {
- Headers =
- {
- ContentType = new MediaTypeHeaderValue("application/json")
- }
- }
- };
- var task = Task.Run(() =>
- {
- try
- {
- var response = client.SendAsync(request).Result;
- response.EnsureSuccessStatusCode();
- writeLog(param + "-" + response.Content.ReadAsStringAsync().Result);
- return response.Content.ReadAsStringAsync().Result;
- }
- catch (Exception e)
- {
- return "";
- }
- });
- });
- }
- private void Decompress(string GzipFile, string targetPath)
- {
- //string directoryName = Path.GetDirectoryName(targetPath + "\\") + "\\";
- string directoryName = targetPath + "\\";
- if (!Directory.Exists(directoryName)) Directory.CreateDirectory(directoryName);//生成解压目录
- //helper.writeLog(GzipFile);
- //helper.writeLog(directoryName);
- string CurrentDirectory = directoryName;
- byte[] data = new byte[2048];
- int size = 2048;
- ZipEntry theEntry = null;
- Stream _stream = File.OpenRead(GzipFile);
- if (_stream.Length == 0) { _stream.Close(); return; }
- try
- {
- using (ZipInputStream s = new ZipInputStream(_stream))
- {
- while ((theEntry = s.GetNextEntry()) != null)
- {
- if (theEntry.IsDirectory)
- {// 该结点是目录
- if (!Directory.Exists(CurrentDirectory + theEntry.Name)) Directory.CreateDirectory(CurrentDirectory + theEntry.Name);
- }
- else
- {
- if (theEntry.Name != String.Empty && (theEntry.Name.IndexOf(".png", StringComparison.OrdinalIgnoreCase) != -1 || theEntry.Name.IndexOf(".jpg", StringComparison.OrdinalIgnoreCase) != -1))
- {
- //解压文件到指定的目录
- using (FileStream streamWriter = File.Create(CurrentDirectory + theEntry.Name))
- {
- while (true)
- {
- size = s.Read(data, 0, data.Length);
- if (size <= 0) break;
- streamWriter.Write(data, 0, size);
- }
- streamWriter.Close();
- }
- break;
- }
- }
- }
- s.Close();
- }
- }
- catch (Exception ex)
- {
- XLog.SaveLog(0, "解压uncau:" + ex.Message);
- }
- }
- public string unCompressRAR(string unRarPatch, string rarPatch, string rarName)
- {
- string the_rar;
- RegistryKey the_Reg;
- object the_Obj;
- string the_Info;
- try
- {
- the_Reg = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\WinRAR.exe");
- the_Obj = the_Reg.GetValue("");
- the_rar = the_Obj.ToString();
- the_Reg.Close();
- if (Directory.Exists(unRarPatch) == false)
- {
- Directory.CreateDirectory(unRarPatch);
- }
- the_Info = "x " + rarName + " " + unRarPatch + " -y";
- ProcessStartInfo the_StartInfo = new ProcessStartInfo();
- the_StartInfo.FileName = the_rar;
- the_StartInfo.Arguments = the_Info;
- the_StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
- the_StartInfo.WorkingDirectory = rarPatch;//获取压缩包路径
- Process the_Process = new Process();
- the_Process.StartInfo = the_StartInfo;
- the_Process.Start();
- the_Process.WaitForExit();
- the_Process.Close();
- }
- catch (Exception ex)
- {
- throw ex;
- }
- return unRarPatch;
- }
- private void ShellCdrConvertPng(string path, string targPath)
- {
- ShellFile shellFile = ShellFile.FromFilePath(path);
- System.Drawing.Bitmap shellThumb = shellFile.Thumbnail.ExtraLargeBitmap;
- //在画板的指定位置画图
- targPath = targPath.Replace(".cdr", ".png");
- shellThumb.Save(targPath, ImageFormat.Png);
- shellThumb.Dispose();
- shellFile.Dispose();
- }
- private void CdrConvertPng(string path, string targPath)
- {
- using (Aspose.Imaging.FileFormats.Cdr.CdrImage image = (Aspose.Imaging.FileFormats.Cdr.CdrImage)Aspose.Imaging.Image.Load(path))
- {
- PngOptions options = new Aspose.Imaging.ImageOptions.PngOptions();
- options.ColorType = Aspose.Imaging.FileFormats.Png.PngColorType.TruecolorWithAlpha;
- // Set rasterization options for fileformat
- options.VectorRasterizationOptions = (Aspose.Imaging.ImageOptions.VectorRasterizationOptions)
- image.GetDefaultOptions(new object[] { Aspose.Imaging.Color.White, image.Width, image.Height });
- options.VectorRasterizationOptions.TextRenderingHint = TextRenderingHint.ClearTypeGridFit;
- options.VectorRasterizationOptions.SmoothingMode = Aspose.Imaging.SmoothingMode.None;
- targPath = targPath.Replace(".cdr", ".png");
- image.Save(targPath, options);
- options.Dispose();
- }
- }
- private string CdrExPng(string path, string targPath)
- {
- try
- {
- targPath = targPath.Replace(".cdr", ".png");
- Application cdr = new Application();
- cdr.OpenDocument(path, 1);
- cdr.ActiveDocument.ExportBitmap(
- targPath,
- cdrFilter.cdrPNG,
- cdrExportRange.cdrCurrentPage,
- cdrImageType.cdrRGBColorImage,
- 0, 0, 72, 72,
- cdrAntiAliasingType.cdrNoAntiAliasing,
- false,
- true,
- true,
- false,
- cdrCompressionType.cdrCompressionNone,
- null).Finish();
- cdr.ActiveDocument.Close();
- cdr.Quit();
- cdr = null;
- GC.Collect();
- }
- catch (Exception ex)
- {
- XLog.SaveLog(0, path + ",转成图片出错:" + ex.Message);
- }
- finally
- {
- }
- return "111";
- }
- private static object cdrpngobj = new object();
- private void CdrExportPng(string path, string cdrFile)
- {
- lock (cdrpngobj)
- {
- string fname = curPath + "\\" + Path.GetFileNameWithoutExtension(cdrFile) + ".png";
- string new_fname = path + "\\" + Path.GetFileNameWithoutExtension(cdrFile) + ".png";
- CorelDRAW.Application cdr = new CorelDRAW.Application();
- cdr.OpenDocument(cdrFile, 1);
- cdr.ActiveDocument.ExportBitmap(
- fname,
- CorelDRAW.cdrFilter.cdrPNG,
- CorelDRAW.cdrExportRange.cdrCurrentPage,
- CorelDRAW.cdrImageType.cdrRGBColorImage,
- 0, 0, 72, 72,
- CorelDRAW.cdrAntiAliasingType.cdrNoAntiAliasing,
- false,
- true,
- true,
- false,
- CorelDRAW.cdrCompressionType.cdrCompressionNone,
- null).Finish();
- cdr.ActiveDocument.Close();
- cdr.Quit();
- if (File.Exists(fname))
- {
- File.Copy(fname, new_fname);
- File.Delete(fname);
- }
- }
- }
- public static string MidStrEx(string sourse, string startstr, string endstr)
- {
- string result = string.Empty;
- int startindex, endindex;
- try
- {
- startindex = sourse.IndexOf(startstr);
- if (startindex == -1)
- return result;
- string tmpstr = sourse.Substring(startindex + startstr.Length);
- endindex = tmpstr.IndexOf(endstr);
- if (endindex == -1)
- return result;
- result = tmpstr.Remove(endindex);
- }
- catch (Exception ex)
- {
- Console.WriteLine("MidStrEx Err:" + ex.Message);
- }
- return result;
- }
- private static string logPath = ConfigurationManager.AppSettings["curPath"] + "\\log";
- private static object logFlag = new object();
- public static void writeLog(string log)
- {
- lock (logFlag)
- {
- using (FileStream fileStream = new FileStream(logPath + "\\" + DateTime.Now.ToString("yy-MM-dd") + ".log", FileMode.Append, FileAccess.Write))
- {
- using (StreamWriter sw = new StreamWriter(fileStream, Encoding.Default))
- {
- sw.Write(log + " ------时间:" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "\r\n");
- sw.Flush();
- }
- }
- }
- }
- }
|