/// <summary> /// Lấy chuỗi json màu sắc và danh mục /// </summary> /// <returns>Chuỗi json các màu sắc và category đã chọn</returns> private string getListTheme() { // themes = "{\"id\":8,\"name\":\"Guys Tee\",\"price\":19,\"colors\":[\"Orange\",\"Yellow\"]}"; string result = "["; foreach (DataRow drTheme in dtDataTempColor.Rows) { var color = ""; result += "{\"id\": " + drTheme["Id"] + ", \"name\": \"" + drTheme["Name"] + "\", \"price\": " + drTheme["Price"] + ","; result += "\"colors\":["; if (!string.IsNullOrEmpty(drTheme["Color1"].ToString())) { color += drTheme["Color1"].ToString() + ","; } if (!string.IsNullOrEmpty(drTheme["Color2"].ToString())) { color += drTheme["Color2"].ToString() + ","; } if (!string.IsNullOrEmpty(drTheme["Color3"].ToString())) { color += drTheme["Color3"].ToString() + ","; } if (!string.IsNullOrEmpty(drTheme["Color4"].ToString())) { color += drTheme["Color4"].ToString() + ","; } if (!string.IsNullOrEmpty(drTheme["Color5"].ToString())) { color += drTheme["Color5"].ToString() + ","; } result += CoreLibary.convertStringToJson(color); result += "]"; result += "},"; } result = result.TrimEnd(','); result += "]"; return(result); }
/// <summary> /// Lấy chuỗi json màu sắc và danh mục /// </summary> /// <returns>Chuỗi json các màu sắc và category đã chọn</returns> private List <string> getListThemeObject() { List <string> data = new List <string>(); // themes = "{\"id\":8,\"name\":\"Guys Tee\",\"price\":19,\"colors\":[\"Orange\",\"Yellow\"]}"; foreach (DataRow drTheme in dtDataTempColor.Rows) { var result = ""; var color = ""; result += "{\"id\": " + drTheme["Id"] + ", \"name\": \"" + drTheme["Name"] + "\", \"price\": " + drTheme["Price"] + ","; result += "\"colors\":["; if (!string.IsNullOrEmpty(drTheme["Color1"].ToString())) { color += drTheme["Color1"].ToString() + ","; } if (!string.IsNullOrEmpty(drTheme["Color2"].ToString())) { color += drTheme["Color2"].ToString() + ","; } if (!string.IsNullOrEmpty(drTheme["Color3"].ToString())) { color += drTheme["Color3"].ToString() + ","; } if (!string.IsNullOrEmpty(drTheme["Color4"].ToString())) { color += drTheme["Color4"].ToString() + ","; } if (!string.IsNullOrEmpty(drTheme["Color5"].ToString())) { color += drTheme["Color5"].ToString() + ","; } result += CoreLibary.convertStringToJson(color); result += "]}"; data.Add(result); } return(data); }
/// <summary> /// Upload file to Sunfrog /// </summary> /// <param name="dr">Nội dụng dữ liệu cần upload</param> private void UploadAndDownload(DataRow dr) { //Config Data var frontbackImage = dr["FrontBack"].ToString().Trim(); var pathImage = dr["Image"].ToString().Trim(); var title = dr["Title"].ToString().Trim(); var category = getIDCategory(dr["Category"].ToString().Trim()); var description = dr["Description"].ToString().Trim(); var keyword = CoreLibary.convertStringToJson(dr["Keyword"].ToString().Trim()); var collection = dr["Collection"].ToString().Trim(); var themes = getListTheme(); var imgBase64 = CoreLibary.ConvertImageToBase64(pathImage); //themes = "{\"id\":8,\"name\":\"Guys Tee\",\"price\":19,\"colors\":[\"Orange\",\"Yellow\"]}"; //themes += ",{\"id\":19,\"name\":\"Hoodie\",\"price\":34,\"colors\":[\"White\",\"Green\"]}"; //2. Upload Image var strBack = ""; var strFront = ""; if (frontbackImage == "B") { strBack = "";// Resources.ImageBack; } else { strFront = "";// Resources.ImageFront; } var dataToSend = ""; dataToSend = "{"; dataToSend += "\"ArtOwnerID\":\"0\",\"IAgree\":\"true\""; dataToSend += ",\"Title\":\"" + title + "\""; dataToSend += ",\"Category\":\"" + category + "\""; dataToSend += ",\"Description\":\"" + description + "\""; dataToSend += ",\"Collections\":\"" + collection + "\""; dataToSend += ",\"Keywords\": [" + keyword + "]"; dataToSend += ",\"imageFront\":\"" + strFront + "\""; dataToSend += ",\"imageBack\":\"" + strBack + "\""; dataToSend += ",\"types\":" + themes; dataToSend += ",\"images\":[{\"id\":\"__dataURI: 0__\",\"uri\":\"data:image/png;base64," + imgBase64 + "\"}]"; dataToSend += "}"; byte[] postDataBytes2 = Encoding.ASCII.GetBytes(dataToSend); string getUrl = "https://manager.sunfrogshirts.com/Designer/php/upload-handler.cfm"; HttpWebRequest getRequest = (HttpWebRequest)WebRequest.Create(getUrl); //getRequest.UserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:49.0) Gecko/20100101 Firefox/49.0"; //getRequest.Accept = "*/*"; getRequest.Method = "POST"; //getRequest.AllowWriteStreamBuffering = true; //getRequest.AllowAutoRedirect = true; getRequest.Host = "manager.sunfrogshirts.com"; getRequest.Headers.Add("X-Requested-With", "XMLHttpRequest"); //getRequest.Headers.Add("Accept-Language", "vi-VN,vi;q=0.8,en-US;q=0.5,en;q=0.3"); //getRequest.Headers.Add("Accept-Encoding", "gzip, deflate, br"); getRequest.ContentType = "application/json; charset=UTF-8"; getRequest.Referer = "https://manager.sunfrogshirts.com/Designer/"; getRequest.CookieContainer = cookieContainer; getRequest.ContentLength = postDataBytes2.Length; getRequest.Headers.Add("Origin", "https://sunfrogshirts.com"); getRequest.KeepAlive = true; using (Stream sr = getRequest.GetRequestStream()) { //sr.Write(dataToSend); sr.Write(postDataBytes2, 0, postDataBytes2.Length); sr.Flush(); sr.Close(); } HttpWebResponse getResponse = (HttpWebResponse)getRequest.GetResponse(); string sourceCode = ""; using (StreamReader sr = new StreamReader(getResponse.GetResponseStream())) { sourceCode = sr.ReadToEnd(); } //Dictionary<string, object> dataUpload = PostDataAPI(getRequest, dataToSend); //if (int.Parse(dataUpload["status"].ToString()) == -1) //{ // CoreLibary.writeLogThread(lsBoxLog, "Step 2: " + dataUpload["data"].ToString(), 1); //} //sourceCode = dataUpload["data"].ToString(); var obj = JObject.Parse(sourceCode); if (int.Parse(obj["result"].ToString()) == 0) { CoreLibary.writeLogThread(lsBoxLog, "Collection:" + obj["collectionName"].ToString() + " - " + obj["description"].ToString(), 2); } else { CoreLibary.writeLogThread(lsBoxLog, "Uploaded " + obj["description"].ToString(), 1); } //Chuyển hình sang folder Uploaded //moveImageUploaded(pathImage); }