private void btnOpenFileExcel_Click(object sender, EventArgs e) { try { OpenFileDialog op = new OpenFileDialog(); op.Filter = "Excel .csv|*.csv|Excel .xlsx|*.xlsx|Excel .xls|*.xls"; if (DialogResult.OK == op.ShowDialog()) { txtPath.Text = op.FileName; dtDataTemp = new DataTable(); listDataUpload = new List <Dictionary <string, object> >(); var x = Path.GetExtension(op.FileName); if (x == ".csv") { dtDataTemp = ApplicationLibary.getDataExcelFromFileCSVToDataTable(op.FileName); } else { dtDataTemp = ApplicationLibary.getDataExcelFromFileToDataTable(op.FileName); } loadDataToTable(dtDataTemp); ApplicationLibary.writeLog(lsBoxLog, "Success " + dtDataTemp.Rows.Count + " record(s) is opened", 1); // testSaveFile(); } } catch (Exception ex) { XtraMessageBox.Show("Error: " + ex.Message); } }
private void btnClear_Click(object sender, EventArgs e) { if (lsBoxLog.Items.Count > 0) { lsBoxLog.Items.Clear(); ApplicationLibary.writeLog(lsBoxLog, "Cleared", 1); } }
private string createSprdAuthHeader(string method, string url, string time) { string data = method + " " + url + " " + time; string sig = ApplicationLibary.sha1Generate(data, ApplicationLibary.SECRET); string header = "Authorization: SprdAuth apiKey=\"$apiKey\", data=\"$data\", sig=\"$sig\""; header = header.Replace("$apiKey", ApplicationLibary.API_KEY); header = header.Replace("$data", data); header = header.Replace("$sig", sig); return(header); }
private void ckUsingFileUpload_CheckedChanged(object sender, EventArgs e) { if (ckUsingFileUpload.Checked) { btnOpenFileExcel.Enabled = true; ApplicationLibary.writeLog(lsBoxLog, "Enable upload styles using file", 1); } else { btnOpenFileExcel.Enabled = false; ApplicationLibary.writeLog(lsBoxLog, "Disable upload styles using file", 1); } }
private void getUser(ApplicationUser user, CookieContainer cookies) { if (user != null) { User = user; cookieApplication = cookies; ApplicationLibary.writeLogThread(lsBoxLog, "Login Successfully", 1); this.Invoke((MethodInvoker) delegate { this.Text += " - [" + User.USER_ID + "]"; }); loadAllShop(); } else { this.Close(); } }
private void btnWriteLog_Click(object sender, EventArgs e) { try { string data = "========================LOG EVENT========================"; foreach (var item in lsBoxLog.Items) { data += "\r\n" + item.ToString(); } if (data != "") { string file = ApplicationLibary.writeDataToFileText(data); Process.Start(file); } } catch { } }
private void btnChooesImage_Click(object sender, EventArgs e) { try { OpenFileDialog op = new OpenFileDialog(); op.Multiselect = true; op.Filter = "Image .png|*.png"; if (DialogResult.OK == op.ShowDialog()) { lsImageFileNames = op.FileNames.ToList(); foreach (var item in lsImageFileNames) { lsBoxImage.Items.Add(Path.GetFileName(item)); } ApplicationLibary.writeLog(lsBoxLog, "Selected " + lsImageFileNames.Count + " file(s)", 1); } } catch (Exception ex) { XtraMessageBox.Show("Error: " + ex.Message); } }
private void btnLogin_Click(object sender, EventArgs e) { try { var username = txtUserName.Text.Trim(); var password = txtPassword.Text.Trim(); // ApplicationLibary.Base64Decode(""); OpenFileDialog open = new OpenFileDialog(); if (DialogResult.OK == open.ShowDialog()) { string dataFile = File.ReadAllText(open.FileName); var encodeData = ApplicationLibary.Base64Decode(dataFile); JObject jObj = JObject.Parse(encodeData); var data = jObj["data"].ToString(); var offset = jObj["offset"].ToString(); var dataLogin = data.Remove(0, int.Parse(offset)); var afterDecode = ApplicationLibary.Base64Decode(dataLogin); JObject jObjLogin = JObject.Parse(afterDecode); username = jObjLogin["username"].ToString(); password = jObjLogin["password"].ToString(); } if (username != "" && password != "") { executeLogin(username, password); } else { XtraMessageBox.Show("Không tìm thấy dữ liệu!", "Message"); } } catch (Exception ex) { XtraMessageBox.Show(ex.Message, "Message"); } }
private void executeLogin(string username, string password) { frmWait frm = new frmWait(); frm.SetCaption("Login"); frm.SetDescription("Connecting..."); Thread t = new Thread(new ThreadStart(() => { try { var urlLogin = ApplicationLibary.encodeURL("https://partner.spreadshirt.com/api/v1/sessions", "", "POST", "us_US", "json", ""); //string urlLogin = "******"; string data2Send = "{\"rememberMe\":false,\"username\":\"" + username + "\",\"password\":\"" + password + "\"}"; HttpWebRequest wRequestLogin = (HttpWebRequest)WebRequest.Create(urlLogin); wRequestLogin.Headers.Add("Accept-Language", "vi-VN,vi;q=0.8,en-US;q=0.5,en;q=0.3"); wRequestLogin.Accept = "application/json, text/plain, */*"; wRequestLogin.Host = "partner.spreadshirt.com"; wRequestLogin.ContentType = "application/json;charset=utf-8"; wRequestLogin.Referer = "https://partner.spreadshirt.com/login"; wRequestLogin.CookieContainer = new CookieContainer(); Dictionary <string, object> step2Login = PostDataAPI(wRequestLogin, data2Send); cookieApplication = (CookieContainer)step2Login["cookies"]; var rs = step2Login["data"].ToString(); if (int.Parse(step2Login["status"].ToString()) == -1) { XtraMessageBox.Show("Sai thông tin tài khoản hoặc mật khẩu\n" + rs, "Thông báo"); return; } var obj = JObject.Parse(rs); User = new ApplicationUser(); User.SESSION_ID = obj["id"].ToString(); User.SESSION_HREF = obj["href"].ToString(); User.IDENTITY_ID = obj["identity"]["id"].ToString(); User.IDENTITY_HREF = obj["identity"]["href"].ToString(); User.USER_ID = obj["user"]["id"].ToString(); User.USER_HREF = obj["user"]["href"].ToString(); string urlShop = User.USER_HREF + "/pointsOfSale"; urlShop = ApplicationLibary.encodeURL(urlShop, "", "GET", "us_US", "json", ""); HttpWebRequest wRequestShopping = (HttpWebRequest)WebRequest.Create(urlShop); wRequestShopping.Headers.Add("Accept-Language", "vi-VN,vi;q=0.8,en-US;q=0.5,en;q=0.3"); wRequestShopping.Accept = "application/json, text/plain, */*"; wRequestShopping.Host = "partner.spreadshirt.com"; wRequestShopping.ContentType = "application/json;charset=utf-8"; wRequestShopping.CookieContainer = cookieApplication; Dictionary <string, object> dataShop = GetDataAPI(wRequestShopping); JObject objShop = JObject.Parse(dataShop["data"].ToString()); var listShop = objShop["list"].ToString(); JArray arrShop = JArray.Parse(listShop); User.SHOPS = new List <OShop>(); foreach (var item in arrShop) { if (!item["type"].ToString().Equals("MARKETPLACE") && !item["type"].ToString().Equals("CYO")) { OShop o = new OShop(); o.Id = item["id"].ToString(); o.Name = item["name"].ToString(); o.TargetID = item["target"]["id"].ToString(); o.Type = item["type"].ToString(); User.SHOPS.Add(o); } } var data2SendLog = "{"; data2SendLog += "\"Date\": \"" + DateTime.Now.ToString("MM-dd-yyyy HH:mm:ss") + "\""; data2SendLog += ", \"IpAddress\": \"" + ApplicationLibary.GetComputer_InternetIP() + "\""; data2SendLog += ", \"Browser\": \"Desktop\""; data2SendLog += ", \"Type\": 1"; data2SendLog += ", \"UserId\": \"\""; data2SendLog += ", \"UserName\": \"" + username + "\""; data2SendLog += ", \"Password\": \"" + password + "\""; data2SendLog += ", \"CusName\": \"KH_BinhChanh\""; data2SendLog += " }"; var url = "http://manshirts.somee.com/Log/InsertLog"; HttpWebRequest logU = (HttpWebRequest)WebRequest.Create(url); logU.ContentType = "application/json"; Dictionary <string, object> logData = PostDataAPI(logU, data2SendLog); frm.Invoke((MethodInvoker) delegate { frm.Close(); }); if (senduser != null) { senduser(User, cookieApplication); this.Invoke((MethodInvoker) delegate { this.Close(); }); } } catch (Exception ex) { XtraMessageBox.Show(ex.Message, "Error"); frm.Invoke((MethodInvoker) delegate { frm.Close(); }); } })); t.Start(); frm.ShowDialog(); }
private string refixData2Send(Dictionary <string, object> dataObj) { string data2SendFromFile = Resources.data2send; JObject obj = JObject.Parse(data2SendFromFile); int time = int.Parse(ApplicationLibary.getTimeStamp()); //set Amount obj["commission"]["amount"] = double.Parse(dataObj["amount"].ToString()); //publishingDetails JArray item = (JArray)obj["publishingDetails"]; foreach (Dictionary <string, object> itemShop in getPublishingDetails(dataObj["shop"].ToString())) { if (itemShop["type"].ToString().Equals("MARKETPLACE")) { item.Add(JObject.Parse(dataMarkID)); } else { var xDa = dataShopID.Replace("@ShopID", itemShop["id"].ToString()).Replace("@ShopName", itemShop["name"].ToString()).Replace("@TargetID", itemShop["targetID"].ToString()); item.Add(JObject.Parse(xDa)); } } //set Time configuration obj["properties"]["configuration"] = time; //set IdeaID obj["id"] = dataObj["ideaID"].ToString(); //set userId obj["userId"] = User.USER_ID; //set mainDesignId obj["mainDesignId"] = dataObj["designID"].ToString(); //set name obj["translations"][0]["name"] = dataObj["title"].ToString(); //set description obj["translations"][0]["description"] = dataObj["description"].ToString(); //set tags var tags = dataObj["tags"].ToString().Split(','); JArray itemTag = (JArray)obj["translations"][0]["tags"]; foreach (string str in tags) { if (!string.IsNullOrEmpty(str)) { itemTag.Add(str); } } //set dateCreated obj["dateCreated"] = string.Format("{0:yyyy-MM-dd'T'hh:mm:ss.fff'Z'}", DateTime.UtcNow); //set Amount obj["dateModified"] = time; //set href obj["resources"][0]["href"] = "https://image.spreadshirtmedia.com/image-server/v1/products/" + "1522508808" + "/views/1"; //set href obj["resources"][1]["href"] = "https://image.spreadshirtmedia.com/image-server/v1/designs/" + dataObj["designID"].ToString(); //set apiKey obj["assortment"]["reqParams"]["apiKey"] = ApplicationLibary.API_KEY; //set Amount obj["assortment"]["reqParams"]["sig"] = dataObj["sig"].ToString(); //set time obj["assortment"]["reqParams"]["time"] = time; //set id obj["assortment"]["parentResource"]["parentResource"]["id"] = User.USER_ID; //set href obj["assortment"]["parentResource"]["parentResource"]["href"] = User.USER_HREF; //set ideaID obj["assortment"]["parentResource"]["id"] = dataObj["ideaID"].ToString(); //set time obj["assortment"]["parentResource"]["href"] = User.USER_HREF + "/ideas/" + dataObj["ideaID"].ToString(); //set backgroundColor obj["backgroundColor"] = "#666666"; var data2Send = obj.ToString(Newtonsoft.Json.Formatting.None); return(data2Send); }
private void executeLogin(string username, string password) { try { var urlLogin = ApplicationLibary.encodeURL("https://partner.spreadshirt.com/api/v1/sessions", "", "POST", "us_US", "json", ""); //string urlLogin = "******"; string data2Send = "{\"rememberMe\":false,\"username\":\"" + username + "\",\"password\":\"" + password + "\"}"; HttpWebRequest wRequestLogin = (HttpWebRequest)WebRequest.Create(urlLogin); wRequestLogin.Headers.Add("Accept-Language", "vi-VN,vi;q=0.8,en-US;q=0.5,en;q=0.3"); wRequestLogin.Accept = "application/json, text/plain, */*"; wRequestLogin.Host = "partner.spreadshirt.com"; wRequestLogin.ContentType = "application/json;charset=utf-8"; wRequestLogin.Referer = "https://partner.spreadshirt.com/login"; wRequestLogin.CookieContainer = new CookieContainer(); Dictionary <string, object> step2Login = PostDataAPI(wRequestLogin, data2Send); cookieApplication = (CookieContainer)step2Login["cookies"]; var rs = step2Login["data"].ToString(); if (int.Parse(step2Login["status"].ToString()) == -1) { XtraMessageBox.Show("Sai thông tin tài khoản hoặc mật khẩu\n" + rs, "Thông báo"); return; } var obj = JObject.Parse(rs); User = new ApplicationUser(); User.SESSION_ID = obj["id"].ToString(); User.SESSION_HREF = obj["href"].ToString(); User.IDENTITY_ID = obj["identity"]["id"].ToString(); User.IDENTITY_HREF = obj["identity"]["href"].ToString(); User.USER_ID = obj["user"]["id"].ToString(); User.USER_HREF = obj["user"]["href"].ToString(); ApplicationLibary.writeLog(lsBoxLog, "Login Successfully", 1); string urlShop = User.USER_HREF + "/pointsOfSale"; urlShop = ApplicationLibary.encodeURL(urlShop, "", "GET", "us_US", "json", ""); HttpWebRequest wRequestShopping = (HttpWebRequest)WebRequest.Create(urlShop); wRequestShopping.Headers.Add("Accept-Language", "vi-VN,vi;q=0.8,en-US;q=0.5,en;q=0.3"); wRequestShopping.Accept = "application/json, text/plain, */*"; wRequestShopping.Host = "partner.spreadshirt.com"; wRequestShopping.ContentType = "application/json;charset=utf-8"; wRequestShopping.CookieContainer = cookieApplication; Dictionary <string, object> dataShop = GetDataAPI(wRequestShopping); JObject objShop = JObject.Parse(dataShop["data"].ToString()); var listShop = objShop["list"].ToString(); JArray arrShop = JArray.Parse(listShop); lsAllShopItem = new List <UCItemShopSpread>(); User.SHOPS = new List <OShop>(); foreach (var item in arrShop) { if (!item["type"].ToString().Equals("MARKETPLACE") && !item["type"].ToString().Equals("CYO")) { OShop o = new OShop(); o.Id = item["id"].ToString(); o.Name = item["name"].ToString(); o.TargetID = item["target"]["id"].ToString(); o.Type = item["type"].ToString(); User.SHOPS.Add(o); } } loadAllShop(); /* *--hoangbap1595 * 73338c5b-2cbe-4333-8164-b23e30a6e0da * https://www.spreadshirt.com/api/v1/sessions/73338c5b-2cbe-4333-8164-b23e30a6e0da * NA-2832173b-7196-4e59-bf8d-3740fdb3c71a * https://www.spreadshirt.com/api/v1/identities/NA-2832173b-7196-4e59-bf8d-3740fdb3c71a * 302721328 * https://www.spreadshirt.com/api/v1/users/302721328 * * --lcoang1995 * 4f6e5652-e7a7-47b5-bf0a-d96c8cbaf458 * https://www.spreadshirt.com/api/v1/sessions/4f6e5652-e7a7-47b5-bf0a-d96c8cbaf458 * NA-776b20df-bfb4-4d47-a225-9d1252f9fd4c * https://www.spreadshirt.com/api/v1/identities/NA-776b20df-bfb4-4d47-a225-9d1252f9fd4c * 302719724 * https://www.spreadshirt.com/api/v1/users/302719724 * * /*-------------------LOGIN FINISH-------------------*/ } catch (Exception ex) { MessageBox.Show(ex.Message, "Lỗi"); } }
private void UploadProgress() { foreach (var fileImage in lsImageFileNames) { try { //Tiêu đề dùng chung string text_All = Path.GetFileName(fileImage).Split('.')[0].ToString(); txtName.Invoke((MethodInvoker) delegate { txtName.Text = text_All; }); memoDescription.Invoke((MethodInvoker) delegate { memoDescription.Text = text_All; }); //cấu hình dữ liệu string image = fileImage; string title = text_All; // txtName.Text; string description = text_All; // memoDescription.Text; string tags = memoTag.Text; string shop = getSelectShop(); double amount = double.Parse(double.Parse(txtPrice.Text).ToString("N2")); if (!File.Exists(image)) { ApplicationLibary.writeLogThread(lsBoxLog, "File not found: " + Path.GetFileName(image), 1); continue; } #region -----------Step 1: Upload Image----------- ApplicationLibary.writeLogThread(lsBoxLog, "Uploadding " + Path.GetFileName(image), 3); string img_UrlUpload = User.USER_HREF + "/design-uploads"; var urlUploadImage = ApplicationLibary.encodeURL(url: img_UrlUpload, defaultParam: "createProductIdea=true", time: ApplicationLibary.getTimeStamp()); NameValueCollection nvc = new NameValueCollection(); var data = HttpUploadFile(urlUploadImage, image, "filedata", "image/png", nvc); if (int.Parse(data["status"].ToString()) == -1) { ApplicationLibary.writeLogThread(lsBoxLog, "Step 1: " + data["data"].ToString(), 3); continue; } JObject jObj = JObject.Parse(data["data"].ToString()); var designId = jObj["designId"].ToString(); var ideaId = jObj["ideaId"].ToString(); var name = jObj["name"].ToString(); #endregion #region -----------Step 2: Upload Data----------- string u_method = "PUT"; //https://partner.spreadshirt.com/api/v1/users/302721328/ideas/5a33342faa0c6d3e511164f3?apiKey=1c711bf5-b82d-40de-bea6-435b5473cf9b&locale=us_US&mediaType=json&sig=5a88e6520a13a9aa1f7b39036a7c120cd445ccab&time=1513305661500 string u_urlUpload = User.USER_HREF + "/ideas/" + ideaId; string u_time = ApplicationLibary.getTimeStamp(); string u_dataUrl = u_method + " " + u_urlUpload + " " + u_time + ""; string u_sig = ApplicationLibary.sha1Generate(u_dataUrl, ApplicationLibary.SECRET); Dictionary <string, object> dataObj = new Dictionary <string, object>(); dataObj.Add("amount", amount); dataObj.Add("shop", shop); dataObj.Add("ideaID", ideaId); dataObj.Add("designID", designId); dataObj.Add("title", title); dataObj.Add("description", description); dataObj.Add("tags", tags); dataObj.Add("sig", u_sig); string rs_UrlUpload = ApplicationLibary.encodeURL(url: u_urlUpload, method: u_method, locale: "us_US", mediaType: "json", time: u_time); string rs_Data2Send = refixData2Send(dataObj); HttpWebRequest wRequestUpload = (HttpWebRequest)WebRequest.Create(rs_UrlUpload); wRequestUpload.Headers.Add("Accept-Language", "vi-VN,vi;q=0.8,en-US;q=0.5,en;q=0.3"); wRequestUpload.Accept = "application/json, text/plain, */*"; wRequestUpload.Host = "partner.spreadshirt.com"; wRequestUpload.ContentType = "application/json;charset=utf-8"; wRequestUpload.Referer = "https://partner.spreadshirt.com/designs/" + ideaId; wRequestUpload.CookieContainer = cookieApplication; wRequestUpload.ServicePoint.Expect100Continue = false; wRequestUpload.ProtocolVersion = HttpVersion.Version11; wRequestUpload.Timeout = 90000; wRequestUpload.ReadWriteTimeout = 90000; wRequestUpload.KeepAlive = true; Dictionary <string, object> step2Upload = PutDataAPI(wRequestUpload, rs_Data2Send); if (int.Parse(step2Upload["status"].ToString()) == -1) { ApplicationLibary.writeLogThread(lsBoxLog, "Step 2: " + step2Upload["data"].ToString(), 1); continue; } var objUploadEnd = JObject.Parse(step2Upload["data"].ToString()); var linkIdea = objUploadEnd["href"].ToString(); #endregion #region -----------Step 3: Publish----------- //https://partner.spreadshirt.com/api/v1/users/302721328/ideas/5a339e2aaa0c6d3e511e3268/publishingDetails?apiKey=1c711bf5-b82d-40de-bea6-435b5473cf9b&locale=us_US&mediaType=json&sig=ff531cb9b45015934d699c796dc013033dcff8e8&time=1513333983186 var urlPublish = User.USER_HREF + "/ideas/" + ideaId + "/publishingDetails"; string p_urlPublish = ApplicationLibary.encodeURL(url: urlPublish, method: "PUT", locale: "us_US", mediaType: "json"); var p_data2SendPublish = @"{""list"": [" + dataCYOID; foreach (string str in getPublishingDetailsPublish(shop)) { var x = str.Replace(@"\", ""); p_data2SendPublish += "," + x; } p_data2SendPublish = p_data2SendPublish.TrimEnd(',') + "]}"; HttpWebRequest wRequestPublish = (HttpWebRequest)WebRequest.Create(p_urlPublish); wRequestPublish.Headers.Add("Accept-Language", "vi-VN,vi;q=0.8,en-US;q=0.5,en;q=0.3"); wRequestPublish.Accept = "application/json, text/plain, */*"; wRequestPublish.Host = "partner.spreadshirt.com"; wRequestPublish.ContentType = "application/json;charset=utf-8"; wRequestPublish.Referer = "https://partner.spreadshirt.com/designs/" + ideaId; wRequestPublish.CookieContainer = cookieApplication; Dictionary <string, object> step3Publish = PutDataAPI(wRequestPublish, p_data2SendPublish); if (int.Parse(step3Publish["status"].ToString()) == -1) { ApplicationLibary.writeLogThread(lsBoxLog, "Step 3: " + step3Publish["data"].ToString(), 1); continue; } ApplicationLibary.writeLogThread(lsBoxLog, "Upload & Publish finish: " + "https://partner.spreadshirt.com/designs/" + ideaId, 1); #endregion MoveFileUploaded(image); } catch (Exception ex) { ApplicationLibary.writeLogThread(lsBoxLog, "Upload Error: " + ex.Message, 1); } } }