Пример #1
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            if (isCheck == 0)
            {
                try
                {
                    lsp.TenLoai = txtTenLoaiSp.Text;
                    lsp.Dvt     = txtDvt.Text;

                    bool result = lspbll.InserLoaiSanPham(lsp);

                    if (result)
                    {
                        DialogResult dialogResultInsert = MessageBox.Show("Insert Successful!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        if (dialogResultInsert == DialogResult.OK)
                        {
                            HienThiLoaiSanPham();
                            EnableHome();
                        }
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Insert Fail!" + "\n\n\t" + ex.Message, "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            else if (isCheck == 1)
            {
                try
                {
                    lsp.TenLoai = txtTenLoaiSp.Text;
                    lsp.Dvt     = txtDvt.Text;
                    lsp.MaLoai  = int.Parse(txtMaLoaiSp.Text);

                    bool result = lspbll.EditLoaiSanPham(lsp);

                    if (result)
                    {
                        DialogResult dialogResultEdit = MessageBox.Show("Edit Successfull!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        if (dialogResultEdit == DialogResult.OK)
                        {
                            HienThiLoaiSanPham();
                        }
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Edit Fail!" + "\n\n\t" + ex.Message, "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            EnableHome();
        }
Пример #2
0
        private void btnEdit_Click(object sender, EventArgs e)
        {
            lsp.TenLoai = txtTenLoaiSp.Text;
            lsp.Dvt     = txtDvt.Text;
            lsp.MaLoai  = int.Parse(txtMaLoaiSp.Text);

            bool result = lspbll.EditLoaiSanPham(lsp);

            if (result)
            {
                HienThiLoaiSanPham();
            }
            else
            {
                MessageBox.Show("Inser Type Product Not Success !");
            }
        }
        private void btnSave_Click(object sender, EventArgs e)
        {
            bool check = false;

            if (isCheck == 0)
            {
                try
                {
                    int n = 0;

                    if (txtTenLoai.Text == "")
                    {
                        lbTenLoai.Visible = true;
                        check             = false;
                        lbTenLoai.Text    = "* Trường dữ liệu Tên Loại không được để trống! *";
                    }
                    else
                    {
                        if (int.TryParse(txtTenLoai.Text, out n))
                        {
                            lbTenLoai.Visible = true;
                            check             = false;
                            lbTenLoai.Text    = "* Trường dữ liệu Tên Loại không được chỉ là số! *";
                        }
                        else
                        {
                            lbTenLoai.Visible = false;
                            check             = true;
                            lsp.TenLoai       = txtTenLoai.Text;
                        }
                    }

                    if (txtDvt.Text == "")
                    {
                        lbDvt.Visible = true;
                        check         = false;
                        lbDvt.Text    = "* Trường dữ liệu DVT không được để trống! *";
                    }
                    else
                    {
                        if (int.TryParse(txtDvt.Text, out n))
                        {
                            lbDvt.Visible = true;
                            check         = false;
                            lbDvt.Text    = "* Trường dữ liệu DVT không được là số! *";
                        }
                        else
                        {
                            lbDvt.Visible = false;
                            check         = true;
                            lsp.Dvt       = txtDvt.Text;
                        }
                    }

                    if (check == true)
                    {
                        bool result = lspbll.InserLoaiSanPham(lsp);

                        if (result)
                        {
                            DialogResult dialogResultInsert = MessageBox.Show("Insert Successful!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            if (dialogResultInsert == DialogResult.OK)
                            {
                                HienThiLoaiSanPham();
                                EnableHome();
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Insert Fail!" + "\n\n\t" + ex.Message, "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            else if (isCheck == 1)
            {
                try
                {
                    int n = 0;

                    if (txtMaLoai.Text == "")
                    {
                        lbTenLoai.Visible = true;
                        check             = false;
                        lbTenLoai.Text    = "* Ban phải chọn loại sản phẩm cần sửa trước!*";
                        return;
                    }
                    else
                    {
                        lbTenLoai.Visible = false;
                        check             = true;
                        lsp.MaLoai        = int.Parse(txtMaLoai.Text);
                    }

                    if (txtTenLoai.Text == "")
                    {
                        lbTenLoai.Visible = true;
                        check             = false;
                        lbTenLoai.Text    = "* Trường dữ liệu Tên Loại không được để trống! *";
                        return;
                    }
                    else
                    {
                        if (int.TryParse(txtTenLoai.Text, out n))
                        {
                            lbTenLoai.Visible = true;
                            check             = false;
                            lbTenLoai.Text    = "* Trường dữ liệu Tên Loại không được chỉ là số! *";
                            return;
                        }
                        else
                        {
                            lbTenLoai.Visible = false;
                            check             = true;
                            lsp.TenLoai       = txtTenLoai.Text;
                        }
                    }

                    if (txtDvt.Text == "")
                    {
                        lbDvt.Visible = true;
                        check         = false;
                        lbDvt.Text    = "* Trường dữ liệu DVT không được để trống! *";
                        return;
                    }
                    else
                    {
                        if (int.TryParse(txtDvt.Text, out n))
                        {
                            lbDvt.Visible = true;
                            check         = false;
                            lbDvt.Text    = "* Trường dữ liệu DVT không được là số! *";
                            return;
                        }
                        else
                        {
                            lbDvt.Visible = false;
                            check         = true;
                            lsp.Dvt       = txtDvt.Text;
                        }
                    }

                    if (check == true)
                    {
                        bool result = lspbll.EditLoaiSanPham(lsp);

                        if (result)
                        {
                            DialogResult dialogResultEdit = MessageBox.Show("Edit Successfull!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            if (dialogResultEdit == DialogResult.OK)
                            {
                                HienThiLoaiSanPham();
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Edit Fail!" + "\n\n\t" + ex.Message, "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }