public DlvProfileAddEditDialog(DlvProfileDialog dlvprofile_dialog, DlvProfileVM dlvprofile = null) { InitializeComponent(); this.dlvprofile_dialog = dlvprofile_dialog; this.main_form = dlvprofile_dialog.main_form; this.form_mode = dlvprofile == null ? FORM_MODE.ADD : FORM_MODE.EDIT; this.dlvprofile = dlvprofile; }
private void DlvProfileAddEditDialog_Load(object sender, EventArgs e) { this.splashScreenManager1.ShowWaitForm(); if (this.form_mode == FORM_MODE.ADD) // Add mode { this.Text = "เพิ่มกลุ่มวิธีการจัดส่ง"; this.dlvprofile = new DlvProfileVM() { TabTyp = "D0", TypCod = string.Empty, AbbreviateEn = string.Empty, AbbreviateTh = string.Empty, TypDesEn = string.Empty, TypDesTh = string.Empty, CreBy = this.main_form.logedin_user.Id, dlv = new List <IstabVM>() }; } else // Edit mode { this.Text = "แก้ไขกลุ่มวิธีการจัดส่ง"; this.dlvprofile = this.dlvprofile_dialog.LoadSingleDlvProfileFromServer(this.dlvprofile.Id); this.txtTypcod.Enabled = false; } this.txtTypcod.Text = this.dlvprofile.TypCod; this.txtAbbrEn.Text = this.dlvprofile.AbbreviateEn; this.txtAbbrTh.Text = this.dlvprofile.AbbreviateTh; this.txtTypDesEn.Text = this.dlvprofile.TypDesEn; this.txtTypDesTh.Text = this.dlvprofile.TypDesTh; this.bs_remain = new BindingSource(); this.bs_selected = new BindingSource(); this.dlvby = this.dlvprofile_dialog.LoadDlvByFromServer(); this.dlvby_remain = this.dlvby.ConvertAll <IstabVM>(new Converter <IstabVM, IstabVM>(IstabVM2IstabVM)); foreach (var item in this.dlvprofile.dlv) { this.dlvby_remain.Remove(this.dlvby_remain.Where(d => d.Id == item.Id).FirstOrDefault()); } this.bs_remain.DataSource = this.dlvby_remain; this.gridControl1.DataSource = this.bs_remain; //this.dlvby_selected = this.dlvprofile.dlv.ConvertAll<IstabVM>(new Converter<IstabVM, IstabVM>(IstabVM2IstabVM)); //this.bs_selected.DataSource = this.dlvby_selected; this.bs_selected.DataSource = this.dlvprofile.dlv; this.gridControl2.DataSource = this.bs_selected; this.splashScreenManager1.CloseWaitForm(); }
public DlvProfileVM LoadSingleDlvProfileFromServer(int id) { APIResult get = APIClient.GET(this.main_form.config.ApiUrl + "DlvProfile/GetDlvProfileAt", this.main_form.config.ApiKey, "&id=" + id); if (get.Success) { DlvProfileVM dlvprofile = JsonConvert.DeserializeObject <DlvProfileVM>(get.ReturnValue); return(dlvprofile); } else { if (MessageBox.Show(get.ErrorMessage, "Error", MessageBoxButtons.RetryCancel, MessageBoxIcon.Error) == DialogResult.Retry) { return(this.LoadSingleDlvProfileFromServer(id)); } else { return(null); } } }
private void btnEdit_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; } DlvProfileAddEditDialog dlv = new DlvProfileAddEditDialog(this, dlvprofile); if (dlv.ShowDialog() == DialogResult.OK) { this.dlvprofile = this.LoadDlvProfileFromServer(); this.bs.ResetBindings(true); this.bs.DataSource = this.dlvprofile; } }
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(); } } } }