Example #1
0
        private void FillForm(StmasVM stmas)
        {
            if (stmas == null)
            {
                return;
            }

            this.txtStkcod.Text         = stmas.Stkcod;
            this.txtStkdesTh.Text       = stmas.StkDesTh;
            this.txtStkdesEn.Text       = stmas.StkDesEn;
            this.cbStkGrp.SelectedIndex = this.cbStkGrp.Properties.Items.Cast <IstabVM>().Where(i => i.Id == stmas.StkGrp).Count() > 0 ? this.cbStkGrp.Properties.Items.IndexOf(this.cbStkGrp.Properties.Items.Cast <IstabVM>().Where(i => i.Id == stmas.StkGrp).FirstOrDefault()) : -1;
            this.cbQucod.SelectedIndex  = this.cbQucod.Properties.Items.Cast <IstabVM>().Where(i => i.Id == stmas.Qucod).Count() > 0 ? this.cbQucod.Properties.Items.IndexOf(this.cbQucod.Properties.Items.Cast <IstabVM>().Where(i => i.Id == stmas.Qucod).FirstOrDefault()) : -1;
            this.txtSellpr1.EditValue   = stmas.Sellpr1;
            this.txtSellpr2.EditValue   = stmas.Sellpr2;
            this.txtSellpr3.EditValue   = stmas.Sellpr3;
            this.txtSellpr4.EditValue   = stmas.Sellpr4;
            this.txtSellpr5.EditValue   = stmas.Sellpr5;
            this.img_file_path          = stmas.ProductImg == null || stmas.ProductImg.Trim().Length == 0 ? "" : this.main_form.config.ApiUrl.ToLower().Replace("/api/", "") + "/Images/Product/" + stmas.ProductImg;

            this.picProductImg.Image = null;
            if (this.img_file_path.Length > 0)
            {
                this.picProductImg.LoadAsync(this.img_file_path);
            }
        }
Example #2
0
 public StmasListDialog(StmasDialog stmas_dialog, StmasVM stmas = null)
 {
     InitializeComponent();
     this.stmas_dialog   = stmas_dialog;
     this.main_form      = stmas_dialog.main_form;
     this.selected_stmas = stmas;
 }
Example #3
0
        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();
                    }
                }
            }
        }
Example #4
0
 private void btnEdit_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
 {
     this.backup_stmas = this.current_stmas.Clone();
     this.form_mode    = FORM_MODE.EDIT;
     this.SetFormControlState();
     this.txtStkdesTh.Focus();
 }
Example #5
0
 private void btnAdd_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
 {
     this.backup_stmas  = this.current_stmas.Clone();
     this.current_stmas = new StmasVM
     {
         Id         = -1,
         Stkcod     = string.Empty,
         StkDesTh   = string.Empty,
         StkDesEn   = string.Empty,
         Barcod     = string.Empty,
         StkTyp     = "0",
         StkGrp     = -1,
         Qucod      = -1,
         Sellpr1    = 0,
         Sellpr2    = 0,
         Sellpr3    = 0,
         Sellpr4    = 0,
         Sellpr5    = 0,
         ProductImg = string.Empty,
         CreBy      = this.main_form.logedin_user.Id,
         CreDate    = DateTime.Now
     };
     this.FillForm(this.current_stmas);
     this.form_mode = FORM_MODE.ADD;
     this.SetFormControlState();
     this.txtStkcod.Focus();
 }
Example #6
0
        private void btnList_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            StmasListDialog st_list = new StmasListDialog(this, this.current_stmas);

            if (st_list.ShowDialog() == DialogResult.OK)
            {
                this.current_stmas = st_list.selected_stmas;
                this.FillForm(this.current_stmas);
            }
        }
Example #7
0
 private void btnStop_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
 {
     if (MessageBox.Show("ยกเลิกการเพิ่ม/แก้ไข, ใช่หรือไม่?", "", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
     {
         this.form_mode = FORM_MODE.READ;
         this.SetFormControlState();
         this.current_stmas = this.backup_stmas.Clone();
         this.FillForm(this.current_stmas);
     }
 }
Example #8
0
        private void btnNext_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            var stmas = this.LoadSingleStmasFromServer(RECORD_NAVIGATION.NEXT, this.current_stmas.Id);

            if (stmas == null)
            {
                return;
            }

            this.current_stmas = stmas;
            this.FillForm(this.current_stmas);
        }
Example #9
0
        private void btnOK_Click(object sender, EventArgs e)
        {
            if (this.gridViewStmas.GetRow(this.gridViewStmas.FocusedRowHandle) == null)
            {
                return;
            }

            this.selected_stmas = this.stmas_list.Where(s => s.Id == (int)this.gridViewStmas.GetRowCellValue(this.gridViewStmas.FocusedRowHandle, this.colId)).FirstOrDefault();

            if (this.selected_stmas == null)
            {
                return;
            }

            this.DialogResult = DialogResult.OK;
            this.Close();
        }
Example #10
0
        private StmasVM FindByStkcod(string key_word)
        {
            APIResult find = APIClient.GET(this.main_form.config.ApiUrl + "Stmas/FindByStkcod", this.main_form.config.ApiKey, "&stkcod=" + key_word);

            if (find.Success)
            {
                StmasVM stmas = JsonConvert.DeserializeObject <StmasVM>(find.ReturnValue);
                return(stmas);
            }
            else
            {
                if (MessageBox.Show(find.ErrorMessage, "Error", MessageBoxButtons.RetryCancel, MessageBoxIcon.Error) == DialogResult.Retry)
                {
                    return(this.FindByStkcod(key_word));
                }
            }

            return(null);
        }
Example #11
0
        private void StmasDialog_Load(object sender, EventArgs e)
        {
            if (!this.splashScreenManager1.IsSplashFormVisible)
            {
                this.splashScreenManager1.ShowWaitForm();
            }

            this.LoadComboboxItem();

            this.current_stmas = this.LoadSingleStmasFromServer(RECORD_NAVIGATION.LAST);
            this.FillForm(this.current_stmas);

            if (this.splashScreenManager1.IsSplashFormVisible)
            {
                this.splashScreenManager1.CloseWaitForm();
            }

            this.form_mode = FORM_MODE.READ;
            this.SetFormControlState();
        }
Example #12
0
        private void btnFind_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            FindDialog fd = new FindDialog("รหัสสินค้า", this.find_keyword);

            if (fd.ShowDialog() == DialogResult.OK)
            {
                this.find_keyword = fd.key_word;

                StmasVM find_result = this.FindByStkcod(this.find_keyword);
                if (find_result != null)
                {
                    this.current_stmas = find_result;
                    this.FillForm(this.current_stmas);
                }
                else
                {
                    MessageBox.Show("ค้นหารหัส '" + this.find_keyword + "' ไม่พบ", "", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
        }
Example #13
0
 private void btnLast_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
 {
     this.current_stmas = this.LoadSingleStmasFromServer(RECORD_NAVIGATION.LAST);
     this.FillForm(this.current_stmas);
 }
Example #14
0
        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();
            }
        }