private void StpriAddEditDialog_Load(object sender, EventArgs e) { this.splashScreenManager1.ShowWaitForm(); foreach (var item in this.GetTabPrObject()) { this.cbTabPr.Properties.Items.Add(item); } foreach (var item in this.GetIsPercentObject()) { this.cbDisc1Perc.Properties.Items.Add(item); this.cbDisc2Perc.Properties.Items.Add(item); } if (this.form_mode == FORM_MODE.ADD) { this.Text = "เพิ่มตารางราคา"; this.stpri = new StpriVM() { PriceCode = string.Empty, Description = string.Empty, TabPr = 0, Disc1 = 0, DiscPerc1 = false, Disc2 = 0, DiscPerc2 = false, CreBy = this.main_form.logedin_user.Id }; } if (this.form_mode == FORM_MODE.EDIT) { this.Text = "แก้ไขตารางราคา"; this.txtPriceCode.Enabled = false; this.stpri = this.stpri_dialog.LoadSingleStpriFromServer(this.stpri.Id); if (this.stpri == null) { this.DialogResult = DialogResult.Cancel; this.Close(); } else { this.stpri.ChgBy = this.main_form.logedin_user.Id; } } this.txtPriceCode.Text = this.stpri.PriceCode; this.txtDescription.Text = this.stpri.Description; this.txtDisc1.Text = this.stpri.Disc1.HasValue ? String.Format("{0:#,#0.00}", this.stpri.Disc1.Value) : "0.00"; this.txtDisc2.Text = this.stpri.Disc2.HasValue ? String.Format("{0:#,#0.00}", this.stpri.Disc2.Value) : "0.00"; this.cbTabPr.SelectedIndex = this.cbTabPr.Properties.Items.IndexOf(this.cbTabPr.Properties.Items.Cast <TabPrObj>().Where(t => t.Value == this.stpri.TabPr).FirstOrDefault()); this.cbDisc1Perc.SelectedIndex = this.cbDisc1Perc.Properties.Items.IndexOf(this.cbDisc1Perc.Properties.Items.Cast <IsPercentObj>().Where(d => d.Value == this.stpri.DiscPerc1).FirstOrDefault()); this.cbDisc2Perc.SelectedIndex = this.cbDisc2Perc.Properties.Items.IndexOf(this.cbDisc2Perc.Properties.Items.Cast <IsPercentObj>().Where(d => d.Value == this.stpri.DiscPerc2).FirstOrDefault()); this.splashScreenManager1.CloseWaitForm(); }
/** Add mode no need stpri to passing; * Edit mode stpri is needed **/ public StpriAddEditDialog(StpriDialog stpri_dialog, StpriVM stpri = null) { InitializeComponent(); this.stpri_dialog = stpri_dialog; this.main_form = stpri_dialog.main_form; this.stpri = stpri; this.form_mode = stpri == null ? FORM_MODE.ADD : FORM_MODE.EDIT; }
private void btnEdit_Click(object sender, EventArgs e) { if (this.gridViewStpri.GetRow(this.gridViewStpri.FocusedRowHandle) == null) { return; } StpriVM stpri = this.stpri.Where(s => s.Id == (int)this.gridViewStpri.GetRowCellValue(this.gridViewStpri.FocusedRowHandle, this.colId)).FirstOrDefault(); StpriAddEditDialog st = new StpriAddEditDialog(this, stpri); if (st.ShowDialog() == DialogResult.OK) { this.stpri = this.LoadStpriFromServer(); this.bs.ResetBindings(true); this.bs.DataSource = this.stpri; } }
public StpriVM LoadSingleStpriFromServer(int id) { APIResult get = APIClient.GET(this.main_form.config.ApiUrl + "Stpri/GetStpriAt", this.main_form.config.ApiKey, "&id=" + id); if (get.Success) { StpriVM stpri = JsonConvert.DeserializeObject <StpriVM>(get.ReturnValue); return(stpri); } else { if (MessageBox.Show(get.ErrorMessage.RemoveBeginAndEndQuote(), "Error", MessageBoxButtons.RetryCancel, MessageBoxIcon.Error) == DialogResult.Retry) { return(LoadSingleStpriFromServer(id)); } return(null); } }
private void btnDelete_Click(object sender, EventArgs e) { if (this.gridViewStpri.GetRow(this.gridViewStpri.FocusedRowHandle) == null) { return; } StpriVM stpri = this.stpri.Where(s => s.Id == (int)this.gridViewStpri.GetRowCellValue(this.gridViewStpri.FocusedRowHandle, this.colId)).FirstOrDefault(); if (MessageBox.Show("ลบรหัส \"" + stpri.PriceCode + "\" ทำต่อหรือไม่?", "", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.Cancel) { return; } this.splashScreenManager1.ShowWaitForm(); ApiAccessibilities acc = new ApiAccessibilities { API_KEY = this.main_form.config.ApiKey, stpri = stpri }; APIResult delete = APIClient.DELETE(this.main_form.config.ApiUrl + "Stpri/DeleteStpri", acc); if (delete.Success) { this.stpri = this.LoadStpriFromServer(); this.bs.ResetBindings(true); this.bs.DataSource = this.stpri; this.splashScreenManager1.CloseWaitForm(); } else { this.splashScreenManager1.CloseWaitForm(); if (MessageBox.Show(delete.ErrorMessage.RemoveBeginAndEndQuote(), "Error", MessageBoxButtons.RetryCancel, MessageBoxIcon.Error) == DialogResult.Retry) { this.btnDelete.PerformClick(); } } }