123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845 |
- using LYFZ.WinAPI;
- using Newtonsoft.Json;
- using System;
- using System.Collections.Generic;
- using System.Data;
- using System.Drawing;
- using System.Dynamic;
- using System.IO;
- using System.Linq;
- using System.Net;
- using System.Text;
- using System.Text.RegularExpressions;
- namespace LYFZ.Software.MainBusiness.Dresses
- {
- public class frmSubmitDataToService : Software.UI.frmSubmitDataToService
- {
- public string ProNumber = "";
- public string Type = "";
- public string EnterpriseID = "";
- public string saveType = "Add";
- public string ID = "";
- public string servicePath = "http://webapi.lyfz.net/";
- LYFZ.BLL.BLL_ErpDressFrom dressFromBll = new BLL.BLL_ErpDressFrom();
- LYFZ.BLL.BLL_ErpProduct productBll = new BLL.BLL_ErpProduct();
- DataRow dr;
- LYFZ.Model.Model_ErpProduct dtProduct;
- Dictionary<string, string> tempDicList;
- Dictionary<string, string> frontCoverList;
- Dictionary<string, string> dataChangeList;
- string ShortcutToolDirectoryPath = LYFZ.WinAPI.CustomPublicMethod.GetFullDirectoryPath(LYFZ.WinAPI.CustomPublicMethod.BasePath) + "CloudOSS//";
- LYFZ.BLL.OssCloudDiskSDK.UploadOssCloudDisk ossDisk;
- public frmSubmitDataToService()
- {
- this.btn_Cancel.Click += btn_Cancel_Click;
- this.btn_Upload.Click += btn_Upload_Click;
- this.cbox_Temple.SelectedIndexChanged += cbox_Temple_SelectedIndexChanged;
- tempDicList = new Dictionary<string, string>();
- frontCoverList = new Dictionary<string, string>();
- dataChangeList = new Dictionary<string, string>();
- BindDataChangeList();
- if (!System.IO.Directory.Exists(ShortcutToolDirectoryPath))
- {
- System.IO.Directory.CreateDirectory(ShortcutToolDirectoryPath);
- }
- ShortcutToolDirectoryPath = ShortcutToolDirectoryPath.Replace("\\", "/");
- GetTempleData();
- ossDisk = new BLL.OssCloudDiskSDK.UploadOssCloudDisk();
- }
- void BindDataChangeList()
- {
- dataChangeList.Add("[=Title]", "");
- dataChangeList.Add("[=SaleValue]", "");
- dataChangeList.Add("[=P数]", "");
- dataChangeList.Add("[=Type]", "");
- }
- void cbox_Temple_SelectedIndexChanged(object sender, EventArgs e)
- {
-
- TempleData dataModel = (TempleData)this.cbox_Temple.SelectedItem;
-
- if(dataModel!=null)
- {
- if (!string.IsNullOrEmpty(this.he_Content.BodyHtml) && dataModel.fileName != "无")
- {
- string[] imgUrlList = GetHtmlImageUrlList(this.he_Content.BodyHtml);
- string tempContent = dataModel.fileContent;
- string[] tempImgUrlList = GetHtmlImageUrlList(tempContent);
- int imgIndx =-1;
- foreach (string urlPath in tempImgUrlList)
- {
- imgIndx++;
- string path = DownPictureData(urlPath);
- if (imgUrlList.Length > imgIndx)
- {
- tempContent = tempContent.Replace(urlPath, imgUrlList[imgIndx]);
- }
- else
- {
- tempContent = tempContent.Replace(urlPath, path);
- }
- }
- if (imgUrlList.Length > tempImgUrlList.Length)
- {
- for(int i=(tempImgUrlList.Length);i<imgUrlList.Length;i++)
- {
- tempContent += "<img src=\"" + imgUrlList[i] + "\" style=\"width:100%;\" />";
- }
- }
- foreach (string key in dataChangeList.Keys)
- {
- tempContent = tempContent.Replace(key, dataChangeList[key]);
- }
-
- this.he_Content.BodyHtml = tempContent;
- }
- }
- }
- string DownPictureData(string ImgUrl)
- {
- string path = ShortcutToolDirectoryPath + DateTime.Now.ToString("yyyyMMddHHmmssffff");
- DownLoadFile(ImgUrl, path);
- frontCoverList.Add(path, ImgUrl);
- return path;
- }
-
-
-
-
-
- public string[] GetHtmlImageUrlList(string sHtmlText)
- {
-
- Regex regImg = new Regex(@"<img\b[^<>]*?\bsrc[\s\t\r\n]*=[\s\t\r\n]*[""']?[\s\t\r\n]*(?<imgUrl>[^\s\t\r\n""'<>]*)[^<>]*?/?[\s\t\r\n]*>", RegexOptions.IgnoreCase);
-
- MatchCollection matches = regImg.Matches(sHtmlText);
- int i = 0;
- string[] sUrlList = new string[matches.Count];
-
- foreach (Match match in matches)
- {
- string imgPath = match.Groups["imgUrl"].Value;
-
-
- sUrlList[i++] = imgPath.Replace("file:///","");
-
- }
-
- return sUrlList;
- }
- void btn_Upload_Click(object sender, EventArgs e)
- {
-
- try
- {
- string html = this.he_Content.BodyHtml;
-
-
- if (!string.IsNullOrEmpty(html))
- {
- tempDicList = CreatePic(GetHtmlImageUrlList(html));
- }
- else
- {
- tempDicList = new Dictionary<string, string>();
- }
- foreach (string key in tempDicList.Keys)
- {
- if (!CheckImageWidth(key))
- {
- MessageBoxCustom.Show(key+"\r\n图片不符合\r\n图片宽度不能超过1920像素,大小不能超过4M!");
- return;
- }
- if (html.IndexOf("file:///" + key) > -1)
- {
-
- html = html.Replace("file:///" + key, tempDicList[key]);
- }
- else
- {
- html = html.Replace(key, tempDicList[key]);
- }
- }
- dynamic dyObj = null;
- string imgPath = "";
- foreach (string frontKey in frontCoverList.Keys)
- {
- imgPath = frontCoverList[frontKey];
- }
- switch (Type)
- {
- case "Dress":
- dyObj = new ExpandoObject();
- dyObj.ID = ID;
- dyObj.EnterpriseID = EnterpriseID;
- dyObj.ProType = Type;
- dyObj.ProTypeList = "";
- dyObj.ProNumber = ProNumber;
- dyObj.ProName = stb_Title.Text;
- dyObj.ProInfo = html;
- dyObj.CreateName = "";
- dyObj.ImgUrl = imgPath;
- dyObj.SellValue = stb_SellValue.Text;
- dyObj.PQuantity = stb_PQuantity.Text;
- break;
- case "Product":
- dyObj = new ExpandoObject();
- dyObj.ID = ID;
- dyObj.EnterpriseID = EnterpriseID;
- dyObj.ProType = Type;
- dyObj.ProTypeList = dtProduct.Prod_ClassName;
- dyObj.ProNumber = dtProduct.Prod_Number;
- dyObj.ProName = dtProduct.Prod_Name;
- dyObj.ProInfo = html;
- dyObj.CreateName = "";
- dyObj.ImgUrl = imgPath;
- dyObj.SellValue = stb_SellValue.Text;
- dyObj.PQuantity = stb_PQuantity.Text;
- break;
- }
- if (dyObj != null)
- {
- if (saveType == "Add")
- {
- dyObj.type = "AddScanProductInfo";
- }
- else
- {
- dyObj.type = "UpdateScanProductInfo";
- }
- string jsonData = HttpClientHelper.PostResponse(servicePath + "admin/ajax/AjaxScanProductInfoHandler.ashx", Newtonsoft.Json.JsonConvert.SerializeObject(dyObj), "application/x-www-form-urlencoded");
- }
-
- DeleteDirectoryFile();
- this.Close();
- }catch(Exception ex)
- {
- MessageBoxCustom.Show(ex.Message);
- }
- }
-
- public bool CheckImageWidth(string imgPath)
- {
- Bitmap pic = new Bitmap(imgPath);
- if(pic.Width>1920)
- {
- pic.Dispose();
- return false;
- }
- else
- {
- pic.Dispose();
- FileInfo fileInfo = new FileInfo(imgPath);
- if (fileInfo.Length>1024*1024*4)
- {
- return false;
- }
-
- return true;
- }
- }
- void GetTempleData()
- {
- try
- {
- List<TempleData> tempDataList = new List<TempleData>();
- dynamic dyObj = null;
- dyObj = new ExpandoObject();
- dyObj.type = "GetTempleList";
- string jsonData = HttpClientHelper.PostResponse(servicePath + "admin/ajax/AjaxScanProductInfoHandler.ashx", Newtonsoft.Json.JsonConvert.SerializeObject(dyObj), "application/x-www-form-urlencoded");
- Newtonsoft.Json.Linq.JObject jobject = (Newtonsoft.Json.Linq.JObject)JsonConvert.DeserializeObject(jsonData);
- tempDataList = JsonConvert.DeserializeObject<List<TempleData>>(jobject.GetValue("Data").ToString());
- this.cbox_Temple.Items.Add(new TempleData()
- {
- fileName = "无"
- });
- foreach (var mod in tempDataList)
- {
- this.cbox_Temple.Items.Add(mod);
- }
- this.cbox_Temple.SelectedIndex = 0;
- }catch(Exception e)
- {
- MessageBoxCustom.Show(e.Message);
- }
- }
- void DeleteDirectoryFile()
- {
- string[] files = Directory.GetFiles(ShortcutToolDirectoryPath);
- foreach (string file in files)
- {
- if (File.Exists(file))
- {
- File.Delete(file);
- }
- }
- }
- void btn_Cancel_Click(object sender, EventArgs e)
- {
- this.Close();
- }
- public void InitDataInfo(string _ProNumber,string _Type)
- {
- try
- {
- ProNumber = _ProNumber;
- Type = _Type;
- switch (Type)
- {
- case "Dress":
- BindDressData();
- PostDataByGetModel();
- break;
- case "Product":
- BindProductData();
- PostDataByGetModel();
- break;
- }
- }catch(Exception e)
- {
- MessageBoxCustom.Show(e.Message);
- }
- }
- public void BindDressData()
- {
- System.Data.DataTable dt = dressFromBll.GetDataByNumber(ProNumber);
- if(dt.Rows.Count>0)
- {
- dr = dt.Rows[0];
- stb_Title.Text = dt.Rows[0]["Dsfm_DressName"].ToString();
- stb_Type.Text = dt.Rows[0]["Sc_ClassName"].ToString();
- stb_SellValue.Text = dt.Rows[0]["Dsfm_SalePrice"].ToString();
- dataChangeList["[=Title]"] = dt.Rows[0]["Dsfm_DressName"].ToString();
- dataChangeList["[=Type]"] = dt.Rows[0]["Sc_ClassName"].ToString();
- dataChangeList["[=P数]"] = "";
- dataChangeList["[=SaleValue]"] = dt.Rows[0]["Dsfm_SalePrice"].ToString();
- stb_PQuantity.Visible = false;
- skinLabel9.Visible = false;
- skinLabel4.Visible = false;
- skinLabel15.Visible = false;
- if (!string.IsNullOrEmpty(dr["Dsfm_DressPhotoNames"].ToString().Trim()))
- {
- string[] StrArrayPhotoName = dr["Dsfm_DressPhotoNames"].ToString().Trim().Split('|');
- for (int i = 0; i < StrArrayPhotoName.Length; i++)
- {
- if (!string.IsNullOrEmpty(StrArrayPhotoName[i].Trim()))
- {
- string StrPhotoName = StrArrayPhotoName[i].Trim();
- if (i == 0)
- {
- string path = ShortcutToolDirectoryPath + DateTime.Now.ToString("yyyyMMddHHmmssffff");
- System.Drawing.Image img = LYFZ.Software.MainBusiness.DoorCityProcess.PublicCodeClasses.GetDressImage_Small(StrPhotoName);
- System.Drawing.Bitmap bitmap = new System.Drawing.Bitmap(img);
- bitmap.Save(path, System.Drawing.Imaging.ImageFormat.Jpeg);
- frontCoverList.Add(path, "");
- break;
- }
- }
- }
- }
- }
- }
- public void BindProductData()
- {
- dtProduct = productBll.GetModel("Prod_Number", ProNumber);
- stb_Title.Text = dtProduct.Prod_Name;
- stb_Type.Text = dtProduct.Prod_ClassName;
- stb_SellValue.Text = dtProduct.Prod_SalesPrice.ToString();
- stb_PQuantity.Text = dtProduct.Prod_Batch.ToString();
- dataChangeList["[=Title]"] = dtProduct.Prod_Name;
- dataChangeList["[=Type]"] = dtProduct.Prod_ClassName;
- dataChangeList["[=P数]"] = dtProduct.Prod_Batch.ToString();
- dataChangeList["[=SaleValue]"] = dtProduct.Prod_SalesPrice.ToString();
- if (!string.IsNullOrEmpty(dtProduct.Prod_Thumbnail))
- {
- string path = ShortcutToolDirectoryPath + DateTime.Now.ToString("yyyyMMddHHmmssffff");
- System.Drawing.Image img = LYFZ.Software.MainBusiness.DoorCityProcess.PublicCodeClasses.GetProductImage(dtProduct.Prod_Thumbnail);
- System.Drawing.Bitmap bitmap = new System.Drawing.Bitmap(img);
- bitmap.Save(path, System.Drawing.Imaging.ImageFormat.Jpeg);
- frontCoverList.Add(path, "");
- }
- }
- public void PostDataByGetModel()
- {
- string param = "";
- GetEnterpriseID();
- dynamic objData= new ExpandoObject();
- objData.type="GetScanProductInfo";
- objData.EnterpriseID = EnterpriseID;
- objData.ProNumber = ProNumber;
- objData.ProType = Type;
-
- string jsonData = HttpClientHelper.PostResponse(servicePath + "admin/ajax/AjaxScanProductInfoHandler.ashx", Newtonsoft.Json.JsonConvert.SerializeObject(objData), "application/x-www-form-urlencoded");
- Newtonsoft.Json.Linq.JObject jsonObject = (Newtonsoft.Json.Linq.JObject)JsonConvert.DeserializeObject(jsonData);
- if(Convert.ToBoolean(jsonObject.GetValue("status")))
- {
- Newtonsoft.Json.Linq.JObject model = (Newtonsoft.Json.Linq.JObject)jsonObject.GetValue("Data");
- if(model.GetValue("ProNumber")!=null&&!string.IsNullOrEmpty(model.GetValue("ProNumber").ToString()))
- {
- saveType = "update";
- string htmlContent=model.GetValue("ProInfo") != null ? model.GetValue("ProInfo").ToString() : "";
- if (!string.IsNullOrEmpty(htmlContent))
- {
- string[] upFileLoads = GetHtmlImageUrlList(htmlContent);
- foreach(string value in upFileLoads)
- {
- string key = ShortcutToolDirectoryPath+DateTime.Now.ToString("yyyyMMddHHmmssffff");
- DownLoadFile(value, key);
- tempDicList.Add(key, value);
- htmlContent=htmlContent.Replace(value, key);
- }
- he_Content.BodyHtml = htmlContent;
- }
- stb_PQuantity.Text = model.GetValue("PQuantity") != null ? model.GetValue("PQuantity").ToString() : "0";
- stb_SellValue.Text = model.GetValue("SellValue") != null ? model.GetValue("SellValue").ToString() : "0";
- ID = model.GetValue("ID") != null ? model.GetValue("ID").ToString() : "0";
- string ImgUrl = model.GetValue("ImgUrl") != null ? model.GetValue("ImgUrl").ToString() : "";
- if(frontCoverList.Keys.Count>0)
- {
- if (!string.IsNullOrEmpty(ImgUrl))
- {
- List<string> tempKeys = new List<string>();
- foreach (string key in frontCoverList.Keys)
- {
- tempKeys.Add(key);
- }
- foreach (string key in tempKeys)
- {
- frontCoverList[key] = ImgUrl;
- }
-
- }
- }
- else if (!string.IsNullOrEmpty(ImgUrl))
- {
- string path = ShortcutToolDirectoryPath + DateTime.Now.ToString("yyyyMMddHHmmssffff");
- DownLoadFile(ImgUrl, path);
- frontCoverList.Add(path, ImgUrl);
- }
- }
- }
- }
- void GetEnterpriseID()
- {
- if (string.IsNullOrEmpty(EnterpriseID))
- {
- LYFZ.BLL.BLL_ErpSystemConfigure config = new BLL.BLL_ErpSystemConfigure();
- DataSet ds = config.GetSystemConfigure("*", "AppInterface");
- if (ds.Tables[0].Rows.Count > 0)
- {
- LYFZ.Model.Model_ErpSystemConfigure model = config.GetModel(Convert.ToInt32(ds.Tables[0].Rows[0]["ID"]));
- try
- {
- Newtonsoft.Json.Linq.JObject jobject = (Newtonsoft.Json.Linq.JObject)Newtonsoft.Json.JsonConvert.DeserializeObject(model.Sconfig_Value);
- EnterpriseID = jobject.GetValue("AppEnId").ToString();
- }
- catch
- {
- }
- }
- }
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- public Dictionary<string, string> CreatePic(string[] uploadphotoList)
- {
-
- try
- {
-
-
- string FormData = "";
- int FolderImageCount = uploadphotoList.Length;
- string UpLoadName = "";
- #region 获取上传图片文件音频路径
- System.Collections.Hashtable hastable = new System.Collections.Hashtable();
-
- foreach (string photoPath in uploadphotoList)
- {
- if (tempDicList.ContainsKey(photoPath))
- {
- continue;
- }
- LYFZ.BLL.OssCloudDiskSDK.OSSUpdateReturnData updateReturnData = ossDisk.UpLoadFile(photoPath, BLL.OssCloudDiskSDK.OssCloudDiskFileType.ProductPicture);
- if(updateReturnData.State)
- {
- tempDicList.Add(photoPath, updateReturnData.OssFileWebUrl);
- }
- }
- var notInKeys = from notKey in tempDicList.Keys where !uploadphotoList.Contains(notKey) select notKey;
- List<string> notInKeyList = new List<string>(notInKeys);
- foreach (var notKey in notInKeyList)
- {
- tempDicList.Remove(notKey);
- }
- List<string> keyList = new List<string>();
- foreach (string tempKey in frontCoverList.Keys)
- {
- keyList.Add(tempKey);
- }
- foreach (string keyPath in keyList)
- {
- if (!string.IsNullOrEmpty(frontCoverList[keyPath]))
- {
- continue;
- }
- LYFZ.BLL.OssCloudDiskSDK.OSSUpdateReturnData updateReturnData = ossDisk.UpLoadFile(keyPath, BLL.OssCloudDiskSDK.OssCloudDiskFileType.ProductPicture);
- if (updateReturnData.State)
- {
-
- frontCoverList[keyPath] = updateReturnData.OssFileWebUrl;
- }
-
- }
- return tempDicList;
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- #endregion
- }
- catch (Exception ex)
- {
- MessageBoxCustom.Show("上传失败,原因:" + ex.Message);
- return tempDicList;
- }
- }
-
-
-
-
-
-
- void DownLoadFile(string url, string path)
- {
- WebClient mywebclient = new WebClient();
- mywebclient.DownloadFile(url, path);
- }
-
- }
- class TempleData
- {
- public string fileName { get; set; }
- public string filePath { get; set; }
- public string fileContent { get; set; }
- public override string ToString()
- {
- return fileName;
- }
- }
- }
|