private bool ImportData(StmasImportVM stmas, bool update_existing) { ApiAccessibilities acc = new ApiAccessibilities { API_KEY = this.main_form.config.ApiKey, USER_ID = this.main_form.logedin_user.Id, stmas_import = stmas }; APIResult post; if (update_existing == false) // add mode { post = APIClient.POST(this.main_form.config.ApiUrl + "Stmas/ImportAdd", acc); } else // edit mode { post = APIClient.POST(this.main_form.config.ApiUrl + "Stmas/ImportUpdate", acc); } if (post.Success) { return(true); } else { if (MessageBox.Show(post.ErrorMessage, "Error", MessageBoxButtons.RetryCancel, MessageBoxIcon.Error) == DialogResult.Retry) { return(this.ImportData(stmas, update_existing)); } return(false); } }
private void Edit() { string url = this.main_form.config.ApiUrl + "users/Edit"; var api_acc = new ApiAccessibilities { API_KEY = this.main_form.config.ApiKey, internalUsers = new InternalUsers { Id = this.user.Id, UserName = this.user.UserName, Email = "", PasswordHash = "", FullName = this.user.FullName, Department = this.user.Department, Status = this.user.Status, } }; APIResult result = APIClient.PUT(url, api_acc); InternalUsers user; if (result.Success) { user = JsonConvert.DeserializeObject <InternalUsers>(result.ReturnValue); this.DialogResult = DialogResult.OK; this.Close(); } else { MessageBox.Show(result.ErrorMessage.RemoveBeginAndEndQuote()); this.txtUserName.Focus(); } }
private void btnDelete_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) { if (MessageBox.Show("ลบรหัสสินค้า '" + this.current_stmas.Stkcod + "' ทำต่อหรือไม่?", "", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK) { ApiAccessibilities acc = new ApiAccessibilities { API_KEY = this.main_form.config.ApiKey, stmas = this.current_stmas }; APIResult delete = APIClient.DELETE(this.main_form.config.ApiUrl + "Stmas/DeleteStmas", acc); if (delete.Success) { StmasVM stmas = JsonConvert.DeserializeObject <StmasVM>(delete.ReturnValue); this.current_stmas = stmas; this.FillForm(this.current_stmas); } else { if (MessageBox.Show(delete.ErrorMessage, "Error", MessageBoxButtons.RetryCancel, MessageBoxIcon.Error) == DialogResult.Retry) { this.btnDelete.PerformClick(); } } } }
private void btnOK_Click(object sender, EventArgs e) { if (this.dealer.DealerCode.Trim().Length == 0) { MessageBox.Show("กรุณาระบุรหัสตัวแทนฯ", "", MessageBoxButtons.OK, MessageBoxIcon.Stop); this.txtDealerCode.Focus(); return; } if (this.dealer.DealerType == null) { MessageBox.Show("กรุณาระบุประเภทตัวแทนฯ", "", MessageBoxButtons.OK, MessageBoxIcon.Stop); this.cbDealerType.Focus(); return; } if (this.dealer.PriceCode.Trim().Length == 0) { MessageBox.Show("กรุณาระบุตารางราคา", "", MessageBoxButtons.OK, MessageBoxIcon.Stop); this.cbPriceCode.Focus(); return; } if (this.dealer.DlvProfile == null) { MessageBox.Show("กรุณาระบุกลุ่มวิธีการจัดส่ง", "", MessageBoxButtons.OK, MessageBoxIcon.Stop); this.cbDlvProfile.Focus(); return; } if (this.dealer.Status.Trim().Length == 0) { MessageBox.Show("กรุณาระบุสถานะ", "", MessageBoxButtons.OK, MessageBoxIcon.Stop); this.cbStatus.Focus(); return; } this.splashScreenManager1.ShowWaitForm(); ApiAccessibilities acc = new ApiAccessibilities() { API_KEY = this.main_form.config.ApiKey, dealer = this.dealer }; APIResult put = APIClient.PUT(this.main_form.config.ApiUrl + "Dealers/Update", acc); if (put.Success) { this.DialogResult = DialogResult.OK; this.Close(); } else { if (MessageBox.Show(put.ErrorMessage.RemoveBeginAndEndQuote(), "Error", MessageBoxButtons.RetryCancel, MessageBoxIcon.Error) == DialogResult.Retry) { this.btnOK.PerformClick(); } } this.splashScreenManager1.CloseWaitForm(); }
private void btnOK_Click(object sender, EventArgs e) { if (this.dlvprofile.TypCod.Trim().Length == 0) { MessageBox.Show("กรุณาป้อนรหัสกลุ่ม", "", MessageBoxButtons.OK, MessageBoxIcon.Stop); this.txtTypcod.Focus(); return; } this.splashScreenManager1.ShowWaitForm(); ApiAccessibilities acc = new ApiAccessibilities { API_KEY = this.main_form.config.ApiKey, dlvprofile = this.dlvprofile }; if (this.form_mode == FORM_MODE.ADD) { APIResult post = APIClient.POST(this.main_form.config.ApiUrl + "DlvProfile/AddDlvProfile", acc); if (post.Success) { this.splashScreenManager1.CloseWaitForm(); this.DialogResult = DialogResult.OK; this.Close(); } else { this.splashScreenManager1.CloseWaitForm(); if (MessageBox.Show(post.ErrorMessage.RemoveBeginAndEndQuote(), "Error", MessageBoxButtons.RetryCancel, MessageBoxIcon.Error) == DialogResult.Retry) { this.btnOK.PerformClick(); } } } if (this.form_mode == FORM_MODE.EDIT) { APIResult put = APIClient.PUT(this.main_form.config.ApiUrl + "DlvProfile/UpdateDlvProfile", acc); if (put.Success) { this.splashScreenManager1.CloseWaitForm(); this.DialogResult = DialogResult.OK; this.Close(); } else { this.splashScreenManager1.CloseWaitForm(); if (MessageBox.Show(put.ErrorMessage.RemoveBeginAndEndQuote(), "Error", MessageBoxButtons.RetryCancel, MessageBoxIcon.Error) == DialogResult.Retry) { this.btnOK.PerformClick(); } } } }
private void btnDelete_Click(object sender, EventArgs e) { if (this.gridViewIstab.GetRow(this.gridViewIstab.FocusedRowHandle) == null) { return; } IstabVM istab = this.istab.Where(i => i.Id == (int)this.gridViewIstab.GetRowCellValue(this.gridViewIstab.FocusedRowHandle, this.colId)).FirstOrDefault(); if (istab == null) { return; } if (MessageBox.Show("ลบรหัส \"" + istab.TypCod + "\" ทำต่อหรือไม่?", "", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK) { this.splashScreenManager1.ShowWaitForm(); ApiAccessibilities acc = new ApiAccessibilities { API_KEY = this.main_form.config.ApiKey, istab = istab }; APIResult delete = APIClient.DELETE(this.main_form.config.ApiUrl + "Istab/DeleteIstab", acc); if (delete.Success) { this.istab = this.LoadIstabFromServer(); this.bs.ResetBindings(true); this.bs.DataSource = this.istab; this.splashScreenManager1.CloseWaitForm(); } else { this.splashScreenManager1.CloseWaitForm(); if (MessageBox.Show(delete.ErrorMessage.RemoveBeginAndEndQuote(), "Error", MessageBoxButtons.RetryCancel, MessageBoxIcon.Error) == DialogResult.Retry) { this.btnDelete.PerformClick(); } } } }
public static APIResult DELETE(string url, ApiAccessibilities api_accessibilities) { APIResult result = new APIResult(); try { HttpWebRequest http = (HttpWebRequest)WebRequest.Create(new Uri(url)); http.Accept = "application/json"; http.ContentType = "application/json"; http.Method = "POST"; string parsedContent = JsonConvert.SerializeObject(api_accessibilities); Encoding encoding = Encoding.GetEncoding("utf-8"); Byte[] bytes = encoding.GetBytes(parsedContent); Stream newStream = http.GetRequestStream(); newStream.Write(bytes, 0, bytes.Length); newStream.Close(); var response = http.GetResponse(); var stream = response.GetResponseStream(); var sr = new StreamReader(stream); var content = sr.ReadToEnd(); http = null; result.Success = true; result.ReturnValue = content; result.ErrorMessage = null; result.ErrorCode = null; } catch (WebException ex) { result.Success = false; result.ReturnValue = null; result.FormatError(ex); } return(result); }
private void btnDelete_Click(object sender, EventArgs e) { int user_id = (int)this.gridView1.GetRowCellValue(this.gridView1.FocusedRowHandle, colId); string user_name = (string)this.gridView1.GetRowCellValue(this.gridView1.FocusedRowHandle, colUserName); InternalUsers user = this.users.Where(u => u.Id == user_id).FirstOrDefault(); if (user == null) { return; } if (MessageBox.Show("ลบรหัสผู้ใช้ \"" + user_name + "\"", "Delete", MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1) == DialogResult.OK) { try { ApiAccessibilities acc = new ApiAccessibilities { API_KEY = this.main_form.config.ApiKey, internalUsers = user }; APIResult result = APIClient.DELETE(this.main_form.config.ApiUrl + "users/delete", acc); if (result.Success) { this.RefreshGridUsers(); } else { MessageBox.Show(result.ErrorMessage.RemoveBeginAndEndQuote()); } } catch (Exception ex) { MessageBox.Show(ex.Message); } } }
private void btnDelete_Click(object sender, EventArgs e) { if (this.gridViewDlvProfile.GetRow(this.gridViewDlvProfile.FocusedRowHandle) == null) { return; } DlvProfileVM dlvprofile = this.dlvprofile.Where(d => d.Id == (int)this.gridViewDlvProfile.GetRowCellValue(this.gridViewDlvProfile.FocusedRowHandle, this.colProfileId)).FirstOrDefault(); if (dlvprofile == null) { return; } if (MessageBox.Show("ลบรหัสกลุ่ม \"" + dlvprofile.TypCod + "\" ทำต่อหรือไม่?", "", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK) { ApiAccessibilities acc = new ApiAccessibilities { API_KEY = this.main_form.config.ApiKey, dlvprofile = dlvprofile }; APIResult delete = APIClient.DELETE(this.main_form.config.ApiUrl + "DlvProfile/DeleteDlvProfile", acc); if (delete.Success) { this.dlvprofile = this.LoadDlvProfileFromServer(); this.bs.ResetBindings(true); this.bs.DataSource = this.dlvprofile; } else { if (MessageBox.Show(delete.ErrorMessage.RemoveBeginAndEndQuote(), "Error", MessageBoxButtons.RetryCancel, MessageBoxIcon.Error) == DialogResult.Retry) { this.btnDelete.PerformClick(); } } } }
private void btnOK_Click(object sender, EventArgs e) { if (this.stpri.PriceCode.Trim().Length == 0) { MessageBox.Show("กรุณาป้อนรหัส", "", MessageBoxButtons.OK, MessageBoxIcon.Stop); this.txtPriceCode.Focus(); return; } if (this.stpri.DiscPerc1.Value == true && this.stpri.Disc1 >= 100m) { if (MessageBox.Show("ส่วนลดตามเป้า กำหนดไว้มากกว่าหรือเท่ากับ 100%, ทำการการบันทึกข้อมูลต่อหรือไม่?", "", MessageBoxButtons.OKCancel, MessageBoxIcon.Stop) != DialogResult.OK) { return; } } if (this.stpri.DiscPerc2.Value == true && this.stpri.Disc2 >= 100m) { if (MessageBox.Show("ส่วนลดตัวเทนฯ ต่างจังหวัด กำหนดไว้มากกว่าหรือเท่ากับ 100%, ทำการการบันทึกข้อมูลต่อหรือไม่?", "", MessageBoxButtons.OKCancel, MessageBoxIcon.Stop) != DialogResult.OK) { return; } } this.splashScreenManager1.ShowWaitForm(); ApiAccessibilities acc = new ApiAccessibilities { API_KEY = this.main_form.config.ApiKey, stpri = this.stpri }; if (this.form_mode == FORM_MODE.ADD) // Perform Add { APIResult post = APIClient.POST(this.main_form.config.ApiUrl + "Stpri/AddStpri", acc); if (post.Success) { this.splashScreenManager1.CloseWaitForm(); this.DialogResult = DialogResult.OK; this.Close(); } else { this.splashScreenManager1.CloseWaitForm(); if (MessageBox.Show(post.ErrorMessage.RemoveBeginAndEndQuote(), "Error", MessageBoxButtons.RetryCancel, MessageBoxIcon.Error) == DialogResult.Retry) { this.btnOK.PerformClick(); } } } else // Perform Edit { APIResult put = APIClient.PUT(this.main_form.config.ApiUrl + "Stpri/UpdateStpri", acc); if (put.Success) { this.splashScreenManager1.CloseWaitForm(); this.DialogResult = DialogResult.OK; this.Close(); } else { this.splashScreenManager1.CloseWaitForm(); if (MessageBox.Show(put.ErrorMessage.RemoveBeginAndEndQuote(), "Error", MessageBoxButtons.RetryCancel, MessageBoxIcon.Error) == DialogResult.Retry) { this.btnOK.PerformClick(); } } } }
private void btnSave_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) { this.splashScreenManager1.ShowWaitForm(); ApiAccessibilities acc = new ApiAccessibilities { API_KEY = this.main_form.config.ApiKey, stmas = this.current_stmas }; APIResult add_edit; if (this.form_mode == FORM_MODE.ADD) // Add mode { add_edit = APIClient.POST(this.main_form.config.ApiUrl + "Stmas/AddStmas", acc); } else // Edit mode { add_edit = APIClient.PUT(this.main_form.config.ApiUrl + "Stmas/UpdateStmas", acc); } if (add_edit.Success) { StmasVM added_item = JsonConvert.DeserializeObject <StmasVM>(add_edit.ReturnValue); if (this.img_file_path.Trim().Length > 0 && !(this.img_file_path.StartsWith("http://") || this.img_file_path.StartsWith("https://"))) // have image { var upload = FIleUpload.Upload(this.main_form.config.ApiUrl + "Stmas/UploadImage", File.OpenRead(this.img_file_path), "file1", added_item.Id.ToString() + Path.GetExtension(this.img_file_path)); if (upload.Success) { acc.stmas = added_item; acc.stmas.ProductImg = acc.stmas.Id.ToString() + Path.GetExtension(this.img_file_path); APIResult update = APIClient.PUT(this.main_form.config.ApiUrl + "Stmas/UpdateStmas", acc); if (update.Success) { APIResult create_resize_img = APIClient.GET(this.main_form.config.ApiUrl + "Stmas/CreateResizedImage", this.main_form.config.ApiKey, "&id=" + acc.stmas.Id.ToString()); if (!create_resize_img.Success) { if (this.splashScreenManager1.IsSplashFormVisible) { this.splashScreenManager1.CloseWaitForm(); } MessageBox.Show("บันทึกข้อมูลสำเร็จ, แต่การอัพโหลดรูปภาพอาจมีปัญหา กรุณาตรวจสอบรูปภาพอีกครั้งในภายหลัง", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } else { if (this.splashScreenManager1.IsSplashFormVisible) { this.splashScreenManager1.CloseWaitForm(); } MessageBox.Show("บันทึกข้อมูลสำเร็จ, แต่การอัพโหลดรูปภาพล้มเหลว กรุณาอัพโหลดรูปภาพอีกครั้งในภายหลัง", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } else { if (this.splashScreenManager1.IsSplashFormVisible) { this.splashScreenManager1.CloseWaitForm(); } MessageBox.Show("บันทึกข้อมูลสำเร็จ, แต่การอัพโหลดรูปภาพล้มเหลว กรุณาอัพโหลดรูปภาพอีกครั้งในภายหลัง", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); } this.current_stmas = added_item; this.FillForm(this.current_stmas); } else // don't have image { this.current_stmas = added_item; this.FillForm(this.current_stmas); } this.form_mode = FORM_MODE.READ; this.SetFormControlState(); } else { if (this.splashScreenManager1.IsSplashFormVisible) { this.splashScreenManager1.CloseWaitForm(); } if (MessageBox.Show(add_edit.ErrorMessage, "Error", MessageBoxButtons.RetryCancel, MessageBoxIcon.Error) == DialogResult.Retry) { this.btnSave.PerformClick(); } else { this.current_stmas = this.backup_stmas.Clone(); this.FillForm(this.current_stmas); this.form_mode = FORM_MODE.READ; this.SetFormControlState(); } } if (this.splashScreenManager1.IsSplashFormVisible) { this.splashScreenManager1.CloseWaitForm(); } }