Example #1
0
        private void btnBack_Click(object sender, EventArgs e)
        {
            this.Close();
            FmProduct fmProduct = new FmProduct();

            fmProduct.Show();
        }
Example #2
0
        private async void btnAdd_Click(object sender, EventArgs e)
        {
            try
            {
                if (checkExistId(tbId.Text))
                {
                    MessageBox.Show(DefineMessage.ID_INVALID, CommonDefines.MESSAGEBOX_CAPTION, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
                if (!validateInputEntered())
                {
                    MessageBox.Show(DefineMessage.INVALID_DATA, CommonDefines.MESSAGEBOX_CAPTION, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
                // Tạo product mới
                PRODUCT product = new PRODUCT();
                product.ID = tbId.Text;
                if (pbAvatar.Image != null)
                {
                    product.IMAGES = product.ID + avatarExtention;
                }
                product.MNAME        = tbName.Text;
                product.CATEGORY     = cbbCategory.SelectedItem.ToString();
                product.MANUFACTURER = tbManufactor.Text;
                product.NUMBER       = int.Parse(tbNumber.Text);
                product.PRICE        = int.Parse(tbPrice.Text);
                product.DESCRIPTIONS = tbDescription.Text;
                product.STATUSS      = 1;

                // Upload file ảnh avatar vào hệ thống
                if (avatarPath != "")
                {
                    File.Copy(avatarPath, CommonFunction.getProductImagePath() + product.IMAGES, true);
                }


                // Insert vào database
                db.PRODUCTs.Add(product);
                await db.SaveChangesAsync();

                // Thông báo thành công
                MessageBox.Show(DefineMessage.ADD_RECORD_SUCCESSFUL, CommonDefines.MESSAGEBOX_CAPTION, MessageBoxButtons.OK, MessageBoxIcon.Information);
                this.Close();
                FmProduct fmProduct = new FmProduct();
                fmProduct.Show();
            }
            catch (Exception ex)
            {
                MessageBox.Show(DefineMessage.ERROR_OCCURED, CommonDefines.MESSAGEBOX_CAPTION, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
        }
Example #3
0
        private async void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                var result = MessageBox.Show(DefineMessage.CONFIRM_EDIT, CommonDefines.MESSAGEBOX_CAPTION, MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                if (result == DialogResult.Yes)
                {
                    // Tạo product mới
                    PRODUCT product = db.PRODUCTs.Where(p => p.ID.Equals(this.product.ID)).FirstOrDefault();

                    product.MNAME        = tbName.Text;
                    product.CATEGORY     = cbbCategory.SelectedItem.ToString();
                    product.MANUFACTURER = tbManufactor.Text;
                    product.NUMBER       = int.Parse(tbNumber.Text);
                    product.PRICE        = int.Parse(tbPrice.Text);
                    product.DESCRIPTIONS = tbDescription.Text;
                    product.STATUSS      = 1;
                    if (!lbPhotoName.Text.Equals(this.product.ID))
                    {
                        product.IMAGES = product.ID + avatarExtention;
                    }

                    // Upload file ảnh avatar vào hệ thống
                    if (avatarPath != "")
                    {
                        File.Copy(avatarPath, CommonFunction.getProductImagePath() + product.IMAGES, true);
                    }

                    // Insert vào database
                    db.Entry(product).State = System.Data.Entity.EntityState.Modified;
                    await db.SaveChangesAsync();

                    // Thông báo thành công
                    MessageBox.Show(DefineMessage.MODIFY_SUCCESSFUL, CommonDefines.MESSAGEBOX_CAPTION, MessageBoxButtons.OK, MessageBoxIcon.Information);
                    this.Close();
                    FmProduct fmProduct = new FmProduct();
                    fmProduct.Show();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(DefineMessage.ERROR_OCCURED, CommonDefines.MESSAGEBOX_CAPTION, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
        }
Example #4
0
        private async void btnDelete_Click(object sender, EventArgs e)
        {
            try
            {
                var result = MessageBox.Show(DefineMessage.CONFIRM_DELETE_RECORD, CommonDefines.MESSAGEBOX_CAPTION, MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
                if (result == DialogResult.Yes)
                {
                    db.PRODUCTs.Remove(product);
                    await db.SaveChangesAsync();

                    MessageBox.Show(DefineMessage.DELETE_RECORD_SUCCESSFUL, CommonDefines.MESSAGEBOX_CAPTION, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    this.Close();
                    FmProduct fmProduct = new FmProduct();
                    fmProduct.Show();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(DefineMessage.ERROR_OCCURED, CommonDefines.MESSAGEBOX_CAPTION, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
        }