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)
- {
- //throw new NotImplementedException();
- 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]);
- }
- /*string imageHtml = "";
- foreach (string imgPath in imgUrlList)
- {
- imageHtml += "<img src=\"" + imgPath + "\" style=\"width:100%;\" />";
- }
- if (tempContent.IndexOf("[=图片内容]") == -1)
- {
- tempContent += imageHtml;
- }
- else
- {
- tempContent = tempContent.Replace("[=图片内容]", imageHtml);
- }*/
- 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;
- }
- /// <summary>
- /// 取得HTML中所有图片的 URL。
- /// </summary>
- /// <param name="sHtmlText">HTML代码</param>
- /// <returns>图片的URL列表</returns>
- public string[] GetHtmlImageUrlList(string sHtmlText)
- {
- // 定义正则表达式用来匹配 img 标签
- 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;
- //if (imgPath.ToLower().IndexOf("http://lyfz-yxb.oss-cn-shenzhen.aliyuncs.com") == -1)
- //{
- sUrlList[i++] = imgPath.Replace("file:///","");
- //}
- }
-
- return sUrlList;
- }
- void btn_Upload_Click(object sender, EventArgs e)
- {
- //he_Content.w
- try
- {
- string html = this.he_Content.BodyHtml;
- //if (CheckYxbLogin())
- //{
- 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;
- //param = "type=GetScanProductInfo&EnterpriseID=" + EnterpriseID + "&ProNumber=" + ProNumber + "&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
- {
- }
- }
- }
- }
- //#region 阿里云数据控制
- //string accessKeyId = "0";
- //string accessKeySecret = "0";
- //string endpoint = "https://oss-cn-shenzhen.aliyuncs.com";//Config.Endpoint;
- //string securityToken = "0";
- //string bucketName = "lyfz-yxb";
- //string domainName = "http://yxb.lyfz.net";
-
- //#region URL请求数据
- //CookieContainer myCookieContainer = new CookieContainer();
- ///// <summary>
- ///// HTTP POST方式请求数据
- ///// </summary>
- ///// <param name="url">URL.</param>
- ///// <param name="param">POST的数据</param>
- ///// <returns></returns>
- //public string HttpPost(string url, string param)
- //{
- // HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(url);
- // request.Accept = "image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, application/x-silverlight, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, application/x-ms-application, application/x-ms-xbap, application/vnd.ms-xpsdocument, application/xaml+xml, application/x-silverlight-2-b1, */*";
- // request.Method = "POST";
- // request.ContentType = "application/x-www-form-urlencoded";
- // request.Accept = "*/*";
- // request.Timeout = 15000;
- // request.AllowAutoRedirect = false;
- // StreamWriter requestStream = null;
- // WebResponse response = null;
- // string responseStr = "";
- // request.CookieContainer = myCookieContainer;
- // try
- // {
- // requestStream = new StreamWriter(request.GetRequestStream());
- // requestStream.Write(param);
- // requestStream.Close();
- // response = request.GetResponse();
- // if (response != null)
- // {
- // StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.UTF8);
- // responseStr = reader.ReadToEnd();
- // reader.Close();
- // }
- // }
- // catch (Exception ex)
- // {
- // throw new Exception(ex.Message);
- // }
- // finally
- // {
- // request = null;
- // requestStream = null;
- // response = null;
- // }
- // return responseStr;
- //}
- //#endregion
- ///// <summary>
- ///// 获取阿里云
- ///// </summary>
- //void GetAliyunOSSAccessKey()
- //{
- // try
- // {
- // try
- // {
- // string retEndpoint = LYFZ.WinAPI.CustomPublicMethod.HttpWebRequestGET(domainName + "/api/alioss/get.php", Encoding.UTF8, myCookieContainer, isUrlDecode: false);
- // dynamic EndpointJson = Newtonsoft.Json.JsonConvert.DeserializeObject(retEndpoint);
- // endpoint = EndpointJson.endpoint;
- // bucketName = EndpointJson.bucketname;
- // }
- // catch { }
- // string retAccessKey = LYFZ.WinAPI.CustomPublicMethod.HttpWebRequestGET(domainName + "/api/alioss/getSTSaccess.php", Encoding.UTF8, myCookieContainer, isUrlDecode: false);
- // dynamic AccessKeyJson = Newtonsoft.Json.JsonConvert.DeserializeObject(retAccessKey);
- // accessKeyId = AccessKeyJson.Credentials.AccessKeyId.ToString().Trim();
- // accessKeySecret = AccessKeyJson.Credentials.AccessKeySecret.ToString().Trim();
- // securityToken = AccessKeyJson.Credentials.SecurityToken.ToString().Trim();
- // }
- // catch
- // {
- // }
- //}
- ///// <summary>
- ///// 检查赢销宝登录
- ///// </summary>
- //public bool CheckYxbLogin()
- //{
- // try
- // {
- // LYFZ.BLL.BaseBLL.BaseBLL_ErpCompanyInfo CompanyInfoBll = new BLL.BaseBLL.BaseBLL_ErpCompanyInfo();
- // DataTable dt = CompanyInfoBll.GetList("Company_DividedShop='" + LYFZ.Software.MainBusiness.CommonLogical.SuccessfulLogin.GetCompanyInfoID() + "'").Tables[0];
- // string password = "";
- // string uid = "";
- // if (dt.Rows.Count > 0)
- // {
- // uid = dt.Rows[0]["Company_MicroShareAccount"].ToString();
- // password = dt.Rows[0]["Company_MicroSharePassword"].ToString();
- // }
- // string FormData = null;
- // string FormUrl = null;
- // FormData = string.Format("username={0}&password={1}", uid, password); // 要发放的数据
- // FormUrl = domainName + "/index.php?m=Photo&a=login";
- // string ResponseHtml = HttpPost(FormUrl, FormData);
- // if (ResponseHtml == "2")
- // {
- // MessageBoxCustom.Show("登陆失败!请在本店信息设置账户与密码是否正确!");
- // return false;
- // }
- // if (ResponseHtml == "3")
- // {
- // MessageBoxCustom.Show("账号未开通权限!");
- // return false;
- // }
- // return true;
- // //创建图片
- // // CreatePic();
- // //switch (ResponseHtml)
- // //{
- // // //case "1":
- // // // MessageBoxCustom.Show("登录成功!");
- // // // break;
- // // case "2":
- // // MessageBoxCustom.Show("登陆失败!");
- // // break;
- // // case "3":
- // // MessageBoxCustom.Show("账号未开通权限!");
- // // break;
- // //}
- // }
- // catch (Exception ex)
- // {
- // MessageBoxCustom.Show("赢销宝帐号登录失败:" + ex.Message);
- // return false;
- // }
- //}
- //#endregion
- //#region 创建图片
- /// <summary>
- /// 创建图片
- /// </summary>
- public Dictionary<string, string> CreatePic(string[] uploadphotoList)
- {
- //Dictionary<string, string> dicList = new Dictionary<string, string>();
- try
- {
- // string ResponseHtmlUpLoad = "";
- /*if (myCookieContainer == null)
- {
- CheckYxbLogin();
- }*/
- 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)
- {
- //tempDicList.Add(photoPath, updateReturnData.OssFileWebUrl);
- frontCoverList[keyPath] = updateReturnData.OssFileWebUrl;
- }
-
- }
- return tempDicList;
- // int fileSum = 0;
- //获取选中图片上传
- //try
- //{
- // LYFZ.ComponentLibrary.FrmLoadHandling.ExecutionDoWorkMethod(delegate(object obj, System.ComponentModel.BackgroundWorker backgroundWorker)
- // {
- // backgroundWorker.ReportProgress(0, "正在验证上传请求...");
- // GetAliyunOSSAccessKey();
- // int ForCount = 0;
- // backgroundWorker.ReportProgress(10, "正在上传相片,请稍等...");
- // var client = new Aliyun.OSS.OssClient(endpoint, accessKeyId, accessKeySecret, securityToken);
- // try
- // {
- // foreach (string photoPath in uploadphotoList)
- // {
- // if (tempDicList.ContainsKey(photoPath))
- // {
- // continue;
- // }
- // string photoFile = photoPath;
- // string imgMd5 = LYFZ.WinAPI.SDKSecurity.GetMD5HashFromFile(photoFile);
- // //customer-photos/<date>
- // string key = "bojinban/" + SDateTime.Now.ToString("yyyyMM") + "/" + imgMd5;
- // bool retBl = client.DoesObjectExist(bucketName, key);
- // if (!retBl)
- // {
- // if (".jpg,.png,.jpge".Contains(System.IO.Path.GetExtension(photoPath).ToLower().Trim()))
- // {
- // System.Drawing.Bitmap bmp = LYFZ.BLL.SelectPhotoHandling.GeneratePreviewBitmap(photoPath, 640, 960);
- // photoFile = LYFZ.ImageFunction.ThumbImgae.SaveTemporaryCompressionImage(bmp, System.IO.Path.GetFileName(photoPath));
- // }
- // Aliyun.OSS.PutObjectResult ret = client.PutObject(bucketName, key, photoFile);
- // if (".jpg,.png,.jpge".Contains(System.IO.Path.GetExtension(photoFile).ToLower().Trim()))
- // {
- // LYFZ.ImageFunction.ThumbImgae.DeleteTemporaryCompressionImage(photoFile);
- // }
- // }
- // //UpLoadName += GetAliyunOSSServerPath(key) + "|";
- // tempDicList.Add(photoPath, GetAliyunOSSServerPath(key));
- // try
- // { backgroundWorker.ReportProgress(Convert.ToInt32(1000 / FolderImageCount * (ForCount + 1))); ForCount++; }
- // catch { }
- // }
- // 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;
- // }
- // string photoFile = keyPath;
- // string imgMd5 = LYFZ.WinAPI.SDKSecurity.GetMD5HashFromFile(photoFile);
- // //customer-photos/<date>
- // string key = "bojinban/" + SDateTime.Now.ToString("yyyyMM") + "/" + imgMd5;
- // bool retBl = client.DoesObjectExist(bucketName, key);
- // if (!retBl)
- // {
- // if (".jpg,.png,.jpge".Contains(System.IO.Path.GetExtension(keyPath).ToLower().Trim()))
- // {
- // System.Drawing.Bitmap bmp = LYFZ.BLL.SelectPhotoHandling.GeneratePreviewBitmap(keyPath, 640, 960);
- // photoFile = LYFZ.ImageFunction.ThumbImgae.SaveTemporaryCompressionImage(bmp, System.IO.Path.GetFileName(keyPath));
- // }
- // Aliyun.OSS.PutObjectResult ret = client.PutObject(bucketName, key, photoFile);
- // if (".jpg,.png,.jpge".Contains(System.IO.Path.GetExtension(photoFile).ToLower().Trim()))
- // {
- // LYFZ.ImageFunction.ThumbImgae.DeleteTemporaryCompressionImage(photoFile);
- // }
- // }
- // //UpLoadName += GetAliyunOSSServerPath(key) + "|";
- // frontCoverList[keyPath] = GetAliyunOSSServerPath(key);
- // }
- // }
- // catch (Exception ex)
- // {
- // MessageBoxCustom.Show("上传相片时失败,原因:" + ex.Message, backgroundWorker: backgroundWorker);
- // }
- // }, width: 500);
- // return tempDicList;
- //}
- //catch (Exception ex)
- //{
- // MessageBoxCustom.Show("上传相片时失败,原因:" + ex.Message);
- // return tempDicList;
- //}
- #endregion
- }
- catch (Exception ex)
- {
- MessageBoxCustom.Show("上传失败,原因:" + ex.Message);
- return tempDicList;
- }
- }
- //string GetAliyunOSSServerPath(string key)
- //{
- // //https://lyfz-yxb.oss-cn-shenzhen.aliyuncs.com/bojinban
- // return endpoint.ToLower().Replace("https://", "https://" + bucketName + ".")
- // .Replace("http://", "http://" + bucketName + ".").Trim('/') + "/" + key;
- //}
- void DownLoadFile(string url, string path)
- {
- WebClient mywebclient = new WebClient();
- mywebclient.DownloadFile(url, path);
- }
- //#endregion
- }
- class TempleData
- {
- public string fileName { get; set; }
- public string filePath { get; set; }
- public string fileContent { get; set; }
- public override string ToString()
- {
- return fileName;
- }
- }
- }
|