frmSubmitDataToService.cs 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845
  1. using LYFZ.WinAPI;
  2. using Newtonsoft.Json;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Data;
  6. using System.Drawing;
  7. using System.Dynamic;
  8. using System.IO;
  9. using System.Linq;
  10. using System.Net;
  11. using System.Text;
  12. using System.Text.RegularExpressions;
  13. namespace LYFZ.Software.MainBusiness.Dresses
  14. {
  15. public class frmSubmitDataToService : Software.UI.frmSubmitDataToService
  16. {
  17. public string ProNumber = "";
  18. public string Type = "";
  19. public string EnterpriseID = "";
  20. public string saveType = "Add";
  21. public string ID = "";
  22. public string servicePath = "http://webapi.lyfz.net/";
  23. LYFZ.BLL.BLL_ErpDressFrom dressFromBll = new BLL.BLL_ErpDressFrom();
  24. LYFZ.BLL.BLL_ErpProduct productBll = new BLL.BLL_ErpProduct();
  25. DataRow dr;
  26. LYFZ.Model.Model_ErpProduct dtProduct;
  27. Dictionary<string, string> tempDicList;
  28. Dictionary<string, string> frontCoverList;
  29. Dictionary<string, string> dataChangeList;
  30. string ShortcutToolDirectoryPath = LYFZ.WinAPI.CustomPublicMethod.GetFullDirectoryPath(LYFZ.WinAPI.CustomPublicMethod.BasePath) + "CloudOSS//";
  31. LYFZ.BLL.OssCloudDiskSDK.UploadOssCloudDisk ossDisk;
  32. public frmSubmitDataToService()
  33. {
  34. this.btn_Cancel.Click += btn_Cancel_Click;
  35. this.btn_Upload.Click += btn_Upload_Click;
  36. this.cbox_Temple.SelectedIndexChanged += cbox_Temple_SelectedIndexChanged;
  37. tempDicList = new Dictionary<string, string>();
  38. frontCoverList = new Dictionary<string, string>();
  39. dataChangeList = new Dictionary<string, string>();
  40. BindDataChangeList();
  41. if (!System.IO.Directory.Exists(ShortcutToolDirectoryPath))
  42. {
  43. System.IO.Directory.CreateDirectory(ShortcutToolDirectoryPath);
  44. }
  45. ShortcutToolDirectoryPath = ShortcutToolDirectoryPath.Replace("\\", "/");
  46. GetTempleData();
  47. ossDisk = new BLL.OssCloudDiskSDK.UploadOssCloudDisk();
  48. }
  49. void BindDataChangeList()
  50. {
  51. dataChangeList.Add("[=Title]", "");
  52. dataChangeList.Add("[=SaleValue]", "");
  53. dataChangeList.Add("[=P数]", "");
  54. dataChangeList.Add("[=Type]", "");
  55. }
  56. void cbox_Temple_SelectedIndexChanged(object sender, EventArgs e)
  57. {
  58. //throw new NotImplementedException();
  59. TempleData dataModel = (TempleData)this.cbox_Temple.SelectedItem;
  60. if(dataModel!=null)
  61. {
  62. if (!string.IsNullOrEmpty(this.he_Content.BodyHtml) && dataModel.fileName != "无")
  63. {
  64. string[] imgUrlList = GetHtmlImageUrlList(this.he_Content.BodyHtml);
  65. string tempContent = dataModel.fileContent;
  66. string[] tempImgUrlList = GetHtmlImageUrlList(tempContent);
  67. int imgIndx =-1;
  68. foreach (string urlPath in tempImgUrlList)
  69. {
  70. imgIndx++;
  71. string path = DownPictureData(urlPath);
  72. if (imgUrlList.Length > imgIndx)
  73. {
  74. tempContent = tempContent.Replace(urlPath, imgUrlList[imgIndx]);
  75. }
  76. else
  77. {
  78. tempContent = tempContent.Replace(urlPath, path);
  79. }
  80. }
  81. if (imgUrlList.Length > tempImgUrlList.Length)
  82. {
  83. for(int i=(tempImgUrlList.Length);i<imgUrlList.Length;i++)
  84. {
  85. tempContent += "<img src=\"" + imgUrlList[i] + "\" style=\"width:100%;\" />";
  86. }
  87. }
  88. foreach (string key in dataChangeList.Keys)
  89. {
  90. tempContent = tempContent.Replace(key, dataChangeList[key]);
  91. }
  92. /*string imageHtml = "";
  93. foreach (string imgPath in imgUrlList)
  94. {
  95. imageHtml += "<img src=\"" + imgPath + "\" style=\"width:100%;\" />";
  96. }
  97. if (tempContent.IndexOf("[=图片内容]") == -1)
  98. {
  99. tempContent += imageHtml;
  100. }
  101. else
  102. {
  103. tempContent = tempContent.Replace("[=图片内容]", imageHtml);
  104. }*/
  105. this.he_Content.BodyHtml = tempContent;
  106. }
  107. }
  108. }
  109. string DownPictureData(string ImgUrl)
  110. {
  111. string path = ShortcutToolDirectoryPath + DateTime.Now.ToString("yyyyMMddHHmmssffff");
  112. DownLoadFile(ImgUrl, path);
  113. frontCoverList.Add(path, ImgUrl);
  114. return path;
  115. }
  116. /// <summary>
  117. /// 取得HTML中所有图片的 URL。
  118. /// </summary>
  119. /// <param name="sHtmlText">HTML代码</param>
  120. /// <returns>图片的URL列表</returns>
  121. public string[] GetHtmlImageUrlList(string sHtmlText)
  122. {
  123. // 定义正则表达式用来匹配 img 标签
  124. 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);
  125. // 搜索匹配的字符串
  126. MatchCollection matches = regImg.Matches(sHtmlText);
  127. int i = 0;
  128. string[] sUrlList = new string[matches.Count];
  129. // 取得匹配项列表
  130. foreach (Match match in matches)
  131. {
  132. string imgPath = match.Groups["imgUrl"].Value;
  133. //if (imgPath.ToLower().IndexOf("http://lyfz-yxb.oss-cn-shenzhen.aliyuncs.com") == -1)
  134. //{
  135. sUrlList[i++] = imgPath.Replace("file:///","");
  136. //}
  137. }
  138. return sUrlList;
  139. }
  140. void btn_Upload_Click(object sender, EventArgs e)
  141. {
  142. //he_Content.w
  143. try
  144. {
  145. string html = this.he_Content.BodyHtml;
  146. //if (CheckYxbLogin())
  147. //{
  148. if (!string.IsNullOrEmpty(html))
  149. {
  150. tempDicList = CreatePic(GetHtmlImageUrlList(html));
  151. }
  152. else
  153. {
  154. tempDicList = new Dictionary<string, string>();
  155. }
  156. foreach (string key in tempDicList.Keys)
  157. {
  158. if (!CheckImageWidth(key))
  159. {
  160. MessageBoxCustom.Show(key+"\r\n图片不符合\r\n图片宽度不能超过1920像素,大小不能超过4M!");
  161. return;
  162. }
  163. if (html.IndexOf("file:///" + key) > -1)
  164. {
  165. html = html.Replace("file:///" + key, tempDicList[key]);
  166. }
  167. else
  168. {
  169. html = html.Replace(key, tempDicList[key]);
  170. }
  171. }
  172. dynamic dyObj = null;
  173. string imgPath = "";
  174. foreach (string frontKey in frontCoverList.Keys)
  175. {
  176. imgPath = frontCoverList[frontKey];
  177. }
  178. switch (Type)
  179. {
  180. case "Dress":
  181. dyObj = new ExpandoObject();
  182. dyObj.ID = ID;
  183. dyObj.EnterpriseID = EnterpriseID;
  184. dyObj.ProType = Type;
  185. dyObj.ProTypeList = "";
  186. dyObj.ProNumber = ProNumber;
  187. dyObj.ProName = stb_Title.Text;
  188. dyObj.ProInfo = html;
  189. dyObj.CreateName = "";
  190. dyObj.ImgUrl = imgPath;
  191. dyObj.SellValue = stb_SellValue.Text;
  192. dyObj.PQuantity = stb_PQuantity.Text;
  193. break;
  194. case "Product":
  195. dyObj = new ExpandoObject();
  196. dyObj.ID = ID;
  197. dyObj.EnterpriseID = EnterpriseID;
  198. dyObj.ProType = Type;
  199. dyObj.ProTypeList = dtProduct.Prod_ClassName;
  200. dyObj.ProNumber = dtProduct.Prod_Number;
  201. dyObj.ProName = dtProduct.Prod_Name;
  202. dyObj.ProInfo = html;
  203. dyObj.CreateName = "";
  204. dyObj.ImgUrl = imgPath;
  205. dyObj.SellValue = stb_SellValue.Text;
  206. dyObj.PQuantity = stb_PQuantity.Text;
  207. break;
  208. }
  209. if (dyObj != null)
  210. {
  211. if (saveType == "Add")
  212. {
  213. dyObj.type = "AddScanProductInfo";
  214. }
  215. else
  216. {
  217. dyObj.type = "UpdateScanProductInfo";
  218. }
  219. string jsonData = HttpClientHelper.PostResponse(servicePath + "admin/ajax/AjaxScanProductInfoHandler.ashx", Newtonsoft.Json.JsonConvert.SerializeObject(dyObj), "application/x-www-form-urlencoded");
  220. }
  221. //}
  222. DeleteDirectoryFile();
  223. this.Close();
  224. }catch(Exception ex)
  225. {
  226. MessageBoxCustom.Show(ex.Message);
  227. }
  228. }
  229. public bool CheckImageWidth(string imgPath)
  230. {
  231. Bitmap pic = new Bitmap(imgPath);
  232. if(pic.Width>1920)
  233. {
  234. pic.Dispose();
  235. return false;
  236. }
  237. else
  238. {
  239. pic.Dispose();
  240. FileInfo fileInfo = new FileInfo(imgPath);
  241. if (fileInfo.Length>1024*1024*4)
  242. {
  243. return false;
  244. }
  245. return true;
  246. }
  247. }
  248. void GetTempleData()
  249. {
  250. try
  251. {
  252. List<TempleData> tempDataList = new List<TempleData>();
  253. dynamic dyObj = null;
  254. dyObj = new ExpandoObject();
  255. dyObj.type = "GetTempleList";
  256. string jsonData = HttpClientHelper.PostResponse(servicePath + "admin/ajax/AjaxScanProductInfoHandler.ashx", Newtonsoft.Json.JsonConvert.SerializeObject(dyObj), "application/x-www-form-urlencoded");
  257. Newtonsoft.Json.Linq.JObject jobject = (Newtonsoft.Json.Linq.JObject)JsonConvert.DeserializeObject(jsonData);
  258. tempDataList = JsonConvert.DeserializeObject<List<TempleData>>(jobject.GetValue("Data").ToString());
  259. this.cbox_Temple.Items.Add(new TempleData()
  260. {
  261. fileName = "无"
  262. });
  263. foreach (var mod in tempDataList)
  264. {
  265. this.cbox_Temple.Items.Add(mod);
  266. }
  267. this.cbox_Temple.SelectedIndex = 0;
  268. }catch(Exception e)
  269. {
  270. MessageBoxCustom.Show(e.Message);
  271. }
  272. }
  273. void DeleteDirectoryFile()
  274. {
  275. string[] files = Directory.GetFiles(ShortcutToolDirectoryPath);
  276. foreach (string file in files)
  277. {
  278. if (File.Exists(file))
  279. {
  280. File.Delete(file);
  281. }
  282. }
  283. }
  284. void btn_Cancel_Click(object sender, EventArgs e)
  285. {
  286. this.Close();
  287. }
  288. public void InitDataInfo(string _ProNumber,string _Type)
  289. {
  290. try
  291. {
  292. ProNumber = _ProNumber;
  293. Type = _Type;
  294. switch (Type)
  295. {
  296. case "Dress":
  297. BindDressData();
  298. PostDataByGetModel();
  299. break;
  300. case "Product":
  301. BindProductData();
  302. PostDataByGetModel();
  303. break;
  304. }
  305. }catch(Exception e)
  306. {
  307. MessageBoxCustom.Show(e.Message);
  308. }
  309. }
  310. public void BindDressData()
  311. {
  312. System.Data.DataTable dt = dressFromBll.GetDataByNumber(ProNumber);
  313. if(dt.Rows.Count>0)
  314. {
  315. dr = dt.Rows[0];
  316. stb_Title.Text = dt.Rows[0]["Dsfm_DressName"].ToString();
  317. stb_Type.Text = dt.Rows[0]["Sc_ClassName"].ToString();
  318. stb_SellValue.Text = dt.Rows[0]["Dsfm_SalePrice"].ToString();
  319. dataChangeList["[=Title]"] = dt.Rows[0]["Dsfm_DressName"].ToString();
  320. dataChangeList["[=Type]"] = dt.Rows[0]["Sc_ClassName"].ToString();
  321. dataChangeList["[=P数]"] = "";
  322. dataChangeList["[=SaleValue]"] = dt.Rows[0]["Dsfm_SalePrice"].ToString();
  323. stb_PQuantity.Visible = false;
  324. skinLabel9.Visible = false;
  325. skinLabel4.Visible = false;
  326. skinLabel15.Visible = false;
  327. if (!string.IsNullOrEmpty(dr["Dsfm_DressPhotoNames"].ToString().Trim()))
  328. {
  329. string[] StrArrayPhotoName = dr["Dsfm_DressPhotoNames"].ToString().Trim().Split('|');
  330. for (int i = 0; i < StrArrayPhotoName.Length; i++)
  331. {
  332. if (!string.IsNullOrEmpty(StrArrayPhotoName[i].Trim()))
  333. {
  334. string StrPhotoName = StrArrayPhotoName[i].Trim();
  335. if (i == 0)
  336. {
  337. string path = ShortcutToolDirectoryPath + DateTime.Now.ToString("yyyyMMddHHmmssffff");
  338. System.Drawing.Image img = LYFZ.Software.MainBusiness.DoorCityProcess.PublicCodeClasses.GetDressImage_Small(StrPhotoName);
  339. System.Drawing.Bitmap bitmap = new System.Drawing.Bitmap(img);
  340. bitmap.Save(path, System.Drawing.Imaging.ImageFormat.Jpeg);
  341. frontCoverList.Add(path, "");
  342. break;
  343. }
  344. }
  345. }
  346. }
  347. }
  348. }
  349. public void BindProductData()
  350. {
  351. dtProduct = productBll.GetModel("Prod_Number", ProNumber);
  352. stb_Title.Text = dtProduct.Prod_Name;
  353. stb_Type.Text = dtProduct.Prod_ClassName;
  354. stb_SellValue.Text = dtProduct.Prod_SalesPrice.ToString();
  355. stb_PQuantity.Text = dtProduct.Prod_Batch.ToString();
  356. dataChangeList["[=Title]"] = dtProduct.Prod_Name;
  357. dataChangeList["[=Type]"] = dtProduct.Prod_ClassName;
  358. dataChangeList["[=P数]"] = dtProduct.Prod_Batch.ToString();
  359. dataChangeList["[=SaleValue]"] = dtProduct.Prod_SalesPrice.ToString();
  360. if (!string.IsNullOrEmpty(dtProduct.Prod_Thumbnail))
  361. {
  362. string path = ShortcutToolDirectoryPath + DateTime.Now.ToString("yyyyMMddHHmmssffff");
  363. System.Drawing.Image img = LYFZ.Software.MainBusiness.DoorCityProcess.PublicCodeClasses.GetProductImage(dtProduct.Prod_Thumbnail);
  364. System.Drawing.Bitmap bitmap = new System.Drawing.Bitmap(img);
  365. bitmap.Save(path, System.Drawing.Imaging.ImageFormat.Jpeg);
  366. frontCoverList.Add(path, "");
  367. }
  368. }
  369. public void PostDataByGetModel()
  370. {
  371. string param = "";
  372. GetEnterpriseID();
  373. dynamic objData= new ExpandoObject();
  374. objData.type="GetScanProductInfo";
  375. objData.EnterpriseID = EnterpriseID;
  376. objData.ProNumber = ProNumber;
  377. objData.ProType = Type;
  378. //param = "type=GetScanProductInfo&EnterpriseID=" + EnterpriseID + "&ProNumber=" + ProNumber + "&ProType=" + Type;
  379. string jsonData = HttpClientHelper.PostResponse(servicePath + "admin/ajax/AjaxScanProductInfoHandler.ashx", Newtonsoft.Json.JsonConvert.SerializeObject(objData), "application/x-www-form-urlencoded");
  380. Newtonsoft.Json.Linq.JObject jsonObject = (Newtonsoft.Json.Linq.JObject)JsonConvert.DeserializeObject(jsonData);
  381. if(Convert.ToBoolean(jsonObject.GetValue("status")))
  382. {
  383. Newtonsoft.Json.Linq.JObject model = (Newtonsoft.Json.Linq.JObject)jsonObject.GetValue("Data");
  384. if(model.GetValue("ProNumber")!=null&&!string.IsNullOrEmpty(model.GetValue("ProNumber").ToString()))
  385. {
  386. saveType = "update";
  387. string htmlContent=model.GetValue("ProInfo") != null ? model.GetValue("ProInfo").ToString() : "";
  388. if (!string.IsNullOrEmpty(htmlContent))
  389. {
  390. string[] upFileLoads = GetHtmlImageUrlList(htmlContent);
  391. foreach(string value in upFileLoads)
  392. {
  393. string key = ShortcutToolDirectoryPath+DateTime.Now.ToString("yyyyMMddHHmmssffff");
  394. DownLoadFile(value, key);
  395. tempDicList.Add(key, value);
  396. htmlContent=htmlContent.Replace(value, key);
  397. }
  398. he_Content.BodyHtml = htmlContent;
  399. }
  400. stb_PQuantity.Text = model.GetValue("PQuantity") != null ? model.GetValue("PQuantity").ToString() : "0";
  401. stb_SellValue.Text = model.GetValue("SellValue") != null ? model.GetValue("SellValue").ToString() : "0";
  402. ID = model.GetValue("ID") != null ? model.GetValue("ID").ToString() : "0";
  403. string ImgUrl = model.GetValue("ImgUrl") != null ? model.GetValue("ImgUrl").ToString() : "";
  404. if(frontCoverList.Keys.Count>0)
  405. {
  406. if (!string.IsNullOrEmpty(ImgUrl))
  407. {
  408. List<string> tempKeys = new List<string>();
  409. foreach (string key in frontCoverList.Keys)
  410. {
  411. tempKeys.Add(key);
  412. }
  413. foreach (string key in tempKeys)
  414. {
  415. frontCoverList[key] = ImgUrl;
  416. }
  417. }
  418. }
  419. else if (!string.IsNullOrEmpty(ImgUrl))
  420. {
  421. string path = ShortcutToolDirectoryPath + DateTime.Now.ToString("yyyyMMddHHmmssffff");
  422. DownLoadFile(ImgUrl, path);
  423. frontCoverList.Add(path, ImgUrl);
  424. }
  425. }
  426. }
  427. }
  428. void GetEnterpriseID()
  429. {
  430. if (string.IsNullOrEmpty(EnterpriseID))
  431. {
  432. LYFZ.BLL.BLL_ErpSystemConfigure config = new BLL.BLL_ErpSystemConfigure();
  433. DataSet ds = config.GetSystemConfigure("*", "AppInterface");
  434. if (ds.Tables[0].Rows.Count > 0)
  435. {
  436. LYFZ.Model.Model_ErpSystemConfigure model = config.GetModel(Convert.ToInt32(ds.Tables[0].Rows[0]["ID"]));
  437. try
  438. {
  439. Newtonsoft.Json.Linq.JObject jobject = (Newtonsoft.Json.Linq.JObject)Newtonsoft.Json.JsonConvert.DeserializeObject(model.Sconfig_Value);
  440. EnterpriseID = jobject.GetValue("AppEnId").ToString();
  441. }
  442. catch
  443. {
  444. }
  445. }
  446. }
  447. }
  448. //#region 阿里云数据控制
  449. //string accessKeyId = "0";
  450. //string accessKeySecret = "0";
  451. //string endpoint = "https://oss-cn-shenzhen.aliyuncs.com";//Config.Endpoint;
  452. //string securityToken = "0";
  453. //string bucketName = "lyfz-yxb";
  454. //string domainName = "http://yxb.lyfz.net";
  455. //#region URL请求数据
  456. //CookieContainer myCookieContainer = new CookieContainer();
  457. ///// <summary>
  458. ///// HTTP POST方式请求数据
  459. ///// </summary>
  460. ///// <param name="url">URL.</param>
  461. ///// <param name="param">POST的数据</param>
  462. ///// <returns></returns>
  463. //public string HttpPost(string url, string param)
  464. //{
  465. // HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(url);
  466. // 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, */*";
  467. // request.Method = "POST";
  468. // request.ContentType = "application/x-www-form-urlencoded";
  469. // request.Accept = "*/*";
  470. // request.Timeout = 15000;
  471. // request.AllowAutoRedirect = false;
  472. // StreamWriter requestStream = null;
  473. // WebResponse response = null;
  474. // string responseStr = "";
  475. // request.CookieContainer = myCookieContainer;
  476. // try
  477. // {
  478. // requestStream = new StreamWriter(request.GetRequestStream());
  479. // requestStream.Write(param);
  480. // requestStream.Close();
  481. // response = request.GetResponse();
  482. // if (response != null)
  483. // {
  484. // StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.UTF8);
  485. // responseStr = reader.ReadToEnd();
  486. // reader.Close();
  487. // }
  488. // }
  489. // catch (Exception ex)
  490. // {
  491. // throw new Exception(ex.Message);
  492. // }
  493. // finally
  494. // {
  495. // request = null;
  496. // requestStream = null;
  497. // response = null;
  498. // }
  499. // return responseStr;
  500. //}
  501. //#endregion
  502. ///// <summary>
  503. ///// 获取阿里云
  504. ///// </summary>
  505. //void GetAliyunOSSAccessKey()
  506. //{
  507. // try
  508. // {
  509. // try
  510. // {
  511. // string retEndpoint = LYFZ.WinAPI.CustomPublicMethod.HttpWebRequestGET(domainName + "/api/alioss/get.php", Encoding.UTF8, myCookieContainer, isUrlDecode: false);
  512. // dynamic EndpointJson = Newtonsoft.Json.JsonConvert.DeserializeObject(retEndpoint);
  513. // endpoint = EndpointJson.endpoint;
  514. // bucketName = EndpointJson.bucketname;
  515. // }
  516. // catch { }
  517. // string retAccessKey = LYFZ.WinAPI.CustomPublicMethod.HttpWebRequestGET(domainName + "/api/alioss/getSTSaccess.php", Encoding.UTF8, myCookieContainer, isUrlDecode: false);
  518. // dynamic AccessKeyJson = Newtonsoft.Json.JsonConvert.DeserializeObject(retAccessKey);
  519. // accessKeyId = AccessKeyJson.Credentials.AccessKeyId.ToString().Trim();
  520. // accessKeySecret = AccessKeyJson.Credentials.AccessKeySecret.ToString().Trim();
  521. // securityToken = AccessKeyJson.Credentials.SecurityToken.ToString().Trim();
  522. // }
  523. // catch
  524. // {
  525. // }
  526. //}
  527. ///// <summary>
  528. ///// 检查赢销宝登录
  529. ///// </summary>
  530. //public bool CheckYxbLogin()
  531. //{
  532. // try
  533. // {
  534. // LYFZ.BLL.BaseBLL.BaseBLL_ErpCompanyInfo CompanyInfoBll = new BLL.BaseBLL.BaseBLL_ErpCompanyInfo();
  535. // DataTable dt = CompanyInfoBll.GetList("Company_DividedShop='" + LYFZ.Software.MainBusiness.CommonLogical.SuccessfulLogin.GetCompanyInfoID() + "'").Tables[0];
  536. // string password = "";
  537. // string uid = "";
  538. // if (dt.Rows.Count > 0)
  539. // {
  540. // uid = dt.Rows[0]["Company_MicroShareAccount"].ToString();
  541. // password = dt.Rows[0]["Company_MicroSharePassword"].ToString();
  542. // }
  543. // string FormData = null;
  544. // string FormUrl = null;
  545. // FormData = string.Format("username={0}&password={1}", uid, password); // 要发放的数据
  546. // FormUrl = domainName + "/index.php?m=Photo&a=login";
  547. // string ResponseHtml = HttpPost(FormUrl, FormData);
  548. // if (ResponseHtml == "2")
  549. // {
  550. // MessageBoxCustom.Show("登陆失败!请在本店信息设置账户与密码是否正确!");
  551. // return false;
  552. // }
  553. // if (ResponseHtml == "3")
  554. // {
  555. // MessageBoxCustom.Show("账号未开通权限!");
  556. // return false;
  557. // }
  558. // return true;
  559. // //创建图片
  560. // // CreatePic();
  561. // //switch (ResponseHtml)
  562. // //{
  563. // // //case "1":
  564. // // // MessageBoxCustom.Show("登录成功!");
  565. // // // break;
  566. // // case "2":
  567. // // MessageBoxCustom.Show("登陆失败!");
  568. // // break;
  569. // // case "3":
  570. // // MessageBoxCustom.Show("账号未开通权限!");
  571. // // break;
  572. // //}
  573. // }
  574. // catch (Exception ex)
  575. // {
  576. // MessageBoxCustom.Show("赢销宝帐号登录失败:" + ex.Message);
  577. // return false;
  578. // }
  579. //}
  580. //#endregion
  581. //#region 创建图片
  582. /// <summary>
  583. /// 创建图片
  584. /// </summary>
  585. public Dictionary<string, string> CreatePic(string[] uploadphotoList)
  586. {
  587. //Dictionary<string, string> dicList = new Dictionary<string, string>();
  588. try
  589. {
  590. // string ResponseHtmlUpLoad = "";
  591. /*if (myCookieContainer == null)
  592. {
  593. CheckYxbLogin();
  594. }*/
  595. string FormData = "";
  596. int FolderImageCount = uploadphotoList.Length;
  597. string UpLoadName = "";
  598. #region 获取上传图片文件音频路径
  599. System.Collections.Hashtable hastable = new System.Collections.Hashtable();
  600. //获取选中图片上传
  601. foreach (string photoPath in uploadphotoList)
  602. {
  603. if (tempDicList.ContainsKey(photoPath))
  604. {
  605. continue;
  606. }
  607. LYFZ.BLL.OssCloudDiskSDK.OSSUpdateReturnData updateReturnData = ossDisk.UpLoadFile(photoPath, BLL.OssCloudDiskSDK.OssCloudDiskFileType.ProductPicture);
  608. if(updateReturnData.State)
  609. {
  610. tempDicList.Add(photoPath, updateReturnData.OssFileWebUrl);
  611. }
  612. }
  613. var notInKeys = from notKey in tempDicList.Keys where !uploadphotoList.Contains(notKey) select notKey;
  614. List<string> notInKeyList = new List<string>(notInKeys);
  615. foreach (var notKey in notInKeyList)
  616. {
  617. tempDicList.Remove(notKey);
  618. }
  619. List<string> keyList = new List<string>();
  620. foreach (string tempKey in frontCoverList.Keys)
  621. {
  622. keyList.Add(tempKey);
  623. }
  624. foreach (string keyPath in keyList)
  625. {
  626. if (!string.IsNullOrEmpty(frontCoverList[keyPath]))
  627. {
  628. continue;
  629. }
  630. LYFZ.BLL.OssCloudDiskSDK.OSSUpdateReturnData updateReturnData = ossDisk.UpLoadFile(keyPath, BLL.OssCloudDiskSDK.OssCloudDiskFileType.ProductPicture);
  631. if (updateReturnData.State)
  632. {
  633. //tempDicList.Add(photoPath, updateReturnData.OssFileWebUrl);
  634. frontCoverList[keyPath] = updateReturnData.OssFileWebUrl;
  635. }
  636. }
  637. return tempDicList;
  638. // int fileSum = 0;
  639. //获取选中图片上传
  640. //try
  641. //{
  642. // LYFZ.ComponentLibrary.FrmLoadHandling.ExecutionDoWorkMethod(delegate(object obj, System.ComponentModel.BackgroundWorker backgroundWorker)
  643. // {
  644. // backgroundWorker.ReportProgress(0, "正在验证上传请求...");
  645. // GetAliyunOSSAccessKey();
  646. // int ForCount = 0;
  647. // backgroundWorker.ReportProgress(10, "正在上传相片,请稍等...");
  648. // var client = new Aliyun.OSS.OssClient(endpoint, accessKeyId, accessKeySecret, securityToken);
  649. // try
  650. // {
  651. // foreach (string photoPath in uploadphotoList)
  652. // {
  653. // if (tempDicList.ContainsKey(photoPath))
  654. // {
  655. // continue;
  656. // }
  657. // string photoFile = photoPath;
  658. // string imgMd5 = LYFZ.WinAPI.SDKSecurity.GetMD5HashFromFile(photoFile);
  659. // //customer-photos/<date>
  660. // string key = "bojinban/" + SDateTime.Now.ToString("yyyyMM") + "/" + imgMd5;
  661. // bool retBl = client.DoesObjectExist(bucketName, key);
  662. // if (!retBl)
  663. // {
  664. // if (".jpg,.png,.jpge".Contains(System.IO.Path.GetExtension(photoPath).ToLower().Trim()))
  665. // {
  666. // System.Drawing.Bitmap bmp = LYFZ.BLL.SelectPhotoHandling.GeneratePreviewBitmap(photoPath, 640, 960);
  667. // photoFile = LYFZ.ImageFunction.ThumbImgae.SaveTemporaryCompressionImage(bmp, System.IO.Path.GetFileName(photoPath));
  668. // }
  669. // Aliyun.OSS.PutObjectResult ret = client.PutObject(bucketName, key, photoFile);
  670. // if (".jpg,.png,.jpge".Contains(System.IO.Path.GetExtension(photoFile).ToLower().Trim()))
  671. // {
  672. // LYFZ.ImageFunction.ThumbImgae.DeleteTemporaryCompressionImage(photoFile);
  673. // }
  674. // }
  675. // //UpLoadName += GetAliyunOSSServerPath(key) + "|";
  676. // tempDicList.Add(photoPath, GetAliyunOSSServerPath(key));
  677. // try
  678. // { backgroundWorker.ReportProgress(Convert.ToInt32(1000 / FolderImageCount * (ForCount + 1))); ForCount++; }
  679. // catch { }
  680. // }
  681. // List<string> keyList = new List<string>();
  682. // foreach (string tempKey in frontCoverList.Keys)
  683. // {
  684. // keyList.Add(tempKey);
  685. // }
  686. // foreach (string keyPath in keyList)
  687. // {
  688. // if (!string.IsNullOrEmpty(frontCoverList[keyPath]))
  689. // {
  690. // continue;
  691. // }
  692. // string photoFile = keyPath;
  693. // string imgMd5 = LYFZ.WinAPI.SDKSecurity.GetMD5HashFromFile(photoFile);
  694. // //customer-photos/<date>
  695. // string key = "bojinban/" + SDateTime.Now.ToString("yyyyMM") + "/" + imgMd5;
  696. // bool retBl = client.DoesObjectExist(bucketName, key);
  697. // if (!retBl)
  698. // {
  699. // if (".jpg,.png,.jpge".Contains(System.IO.Path.GetExtension(keyPath).ToLower().Trim()))
  700. // {
  701. // System.Drawing.Bitmap bmp = LYFZ.BLL.SelectPhotoHandling.GeneratePreviewBitmap(keyPath, 640, 960);
  702. // photoFile = LYFZ.ImageFunction.ThumbImgae.SaveTemporaryCompressionImage(bmp, System.IO.Path.GetFileName(keyPath));
  703. // }
  704. // Aliyun.OSS.PutObjectResult ret = client.PutObject(bucketName, key, photoFile);
  705. // if (".jpg,.png,.jpge".Contains(System.IO.Path.GetExtension(photoFile).ToLower().Trim()))
  706. // {
  707. // LYFZ.ImageFunction.ThumbImgae.DeleteTemporaryCompressionImage(photoFile);
  708. // }
  709. // }
  710. // //UpLoadName += GetAliyunOSSServerPath(key) + "|";
  711. // frontCoverList[keyPath] = GetAliyunOSSServerPath(key);
  712. // }
  713. // }
  714. // catch (Exception ex)
  715. // {
  716. // MessageBoxCustom.Show("上传相片时失败,原因:" + ex.Message, backgroundWorker: backgroundWorker);
  717. // }
  718. // }, width: 500);
  719. // return tempDicList;
  720. //}
  721. //catch (Exception ex)
  722. //{
  723. // MessageBoxCustom.Show("上传相片时失败,原因:" + ex.Message);
  724. // return tempDicList;
  725. //}
  726. #endregion
  727. }
  728. catch (Exception ex)
  729. {
  730. MessageBoxCustom.Show("上传失败,原因:" + ex.Message);
  731. return tempDicList;
  732. }
  733. }
  734. //string GetAliyunOSSServerPath(string key)
  735. //{
  736. // //https://lyfz-yxb.oss-cn-shenzhen.aliyuncs.com/bojinban
  737. // return endpoint.ToLower().Replace("https://", "https://" + bucketName + ".")
  738. // .Replace("http://", "http://" + bucketName + ".").Trim('/') + "/" + key;
  739. //}
  740. void DownLoadFile(string url, string path)
  741. {
  742. WebClient mywebclient = new WebClient();
  743. mywebclient.DownloadFile(url, path);
  744. }
  745. //#endregion
  746. }
  747. class TempleData
  748. {
  749. public string fileName { get; set; }
  750. public string filePath { get; set; }
  751. public string fileContent { get; set; }
  752. public override string ToString()
  753. {
  754. return fileName;
  755. }
  756. }
  757. }