Esempio n. 1
0
        private void buttonYes_Click(object sender, EventArgs e)
        {
            bool flag = true;

            if (dataGridView_QuanLyLoaiSanPham.Rows[Index].Cells["ColTenLoaiSanPham"].Value == null)
            {
                MessageBox.Show("Tên loại sản phẩm không được để trống");
                dataGridView_QuanLyLoaiSanPham.CurrentCell = dataGridView_QuanLyLoaiSanPham.Rows[Index].Cells["ColTenLoaiSanPham"];
                dataGridView_QuanLyLoaiSanPham.BeginEdit(true);
                flag = false;
            }


            if (flag)
            {
                LoaiSanPhamDTO lspDTO = new LoaiSanPhamDTO();
                lspDTO.TenLoaiSanPham = dataGridView_QuanLyLoaiSanPham.Rows[Index].Cells["ColTenLoaiSanPham"].Value.ToString();

                if (Status == 1)//Them tham so
                {
                    lspDTO.MaLoaiSanPham = LoaiSanPhamBUS.CreateLoaiSanPhamId();
                    dataGridView_QuanLyLoaiSanPham.Rows[Index].Cells["ColMaLoaiSanPham"].Value = lspDTO.MaLoaiSanPham;
                    dataGridView_QuanLyLoaiSanPham.Rows[Index].Cells["ColSTT"].Value           = (Index + 1).ToString();
                    if (LoaiSanPhamBUS.InsertLoaiSanPham(lspDTO))
                    {
                        dataGridView_QuanLyLoaiSanPham.Rows[Index].ReadOnly = true;
                        MessageBox.Show("Thêm thành công");
                    }
                    else
                    {
                        dataGridView_QuanLyLoaiSanPham.Rows.RemoveAt(Index);
                        MessageBox.Show("Thêm thất bại");
                    }
                }
                else if (Status == 2)
                {
                    lspDTO.MaLoaiSanPham = dataGridView_QuanLyLoaiSanPham.Rows[Index].Cells["ColMaLoaiSanPham"].Value.ToString();
                    if (LoaiSanPhamBUS.UpdateLoaiSanPhamById(lspDTO))
                    {
                        dataGridView_QuanLyLoaiSanPham.Rows[Index].ReadOnly = true;
                        MessageBox.Show("Cập nhật thành công");
                    }
                    else
                    {
                        MessageBox.Show("Cập nhật thất bại");
                        dataGridView_QuanLyLoaiSanPham.Rows[Index].Cells["ColTenLoaiSanPham"].Value = BackupLoaiSanPhamDTO.TenLoaiSanPham;

                        dataGridView_QuanLyLoaiSanPham.Rows[Index].ReadOnly = true;
                    }
                }

                Reset();
            }
        }