Пример #1
0
        private void dtgvDanhSachSanPham_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            //lbSoLuong.Text = e.ColumnIndex.ToString();
            if (e.ColumnIndex == 2 && e.RowIndex >= 0)
            {
                try
                {
                    ChiTietDonHangBUS ctdhBus = new ChiTietDonHangBUS();
                    ChiTietDonHangDTO ctdhDto = ctdhBus.KiemTraTonTai(_maDH, dtgvDanhSachSanPham_ChiTiet.Rows[e.RowIndex].Cells["MaSanPham"].Value.ToString());
                    if (ctdhDto.MaChiTietDonHang != 0)
                    {
                        DialogResult result = MessageBox.Show("Bạn có chắc muốn xóa sản phẩm này khỏi đơn hàng hay ko",
                                                              "Question",
                                                              MessageBoxButtons.YesNo,
                                                              MessageBoxIcon.Question,
                                                              MessageBoxDefaultButton.Button1);
                        if (result == DialogResult.Yes)
                        {
                            dt.Rows.Remove(dt.Rows[e.RowIndex]);
                            ctdhBus.Delete(ctdhDto.MaChiTietDonHang);
                        }
                    }
                    else
                    {
                        dt.Rows.Remove(dt.Rows[e.RowIndex]);
                    }
                    dtgvDanhSachSanPham_ChiTiet.DataSource = dt;
                    dtgvDanhSachSanPham_DataSourceChanged(sender, e);
                }
                catch (System.Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }

            if (e.ColumnIndex == dtgvDanhSachSanPham_ChiTiet.Columns["CmbSoLuong"].Index && e.RowIndex >= 0)
            {
                dtgvDanhSachSanPham_ChiTiet.BeginEdit(true);
                ComboBox comboBox = (ComboBox)dtgvDanhSachSanPham_ChiTiet.EditingControl;
                if (comboBox != null)
                {
                    comboBox.DroppedDown = true;
                }
            }
        }
Пример #2
0
        private void dtgvDanhSachSanPham_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            try
            {
                //lbSoLuong.Text = e.ColumnIndex.ToString();
                if (e.ColumnIndex == dtgvDanhSachSanPham.Columns["Xoa"].Index && e.RowIndex >= 0)
                {
                    ChiTietDonHangBUS ctdhBus = new ChiTietDonHangBUS();
                    ChiTietDonHangDTO ctdhDto = ctdhBus.KiemTraTonTai(_maDH, dtgvDanhSachSanPham.Rows[e.RowIndex].Cells["MaSanPham"].Value.ToString());
                    if (ctdhDto.MaChiTietDonHang != 0)
                    {
                        DialogResult result = MessageBox.Show("Bạn có chắc muốn xóa sản phẩm này khỏi đơn hàng hay ko",
                                                              "Question",
                                                              MessageBoxButtons.YesNo,
                                                              MessageBoxIcon.Question,
                                                              MessageBoxDefaultButton.Button1);
                        if (result == DialogResult.Yes)
                        {
                            dt.Rows.Remove(dt.Rows[e.RowIndex]);
                            if (dhDto.TrangThai == 2 || dhDto.TrangThai == 5)
                            {
                                string     maSp      = ctdhDto.MaSanPham;
                                int        sl        = ctdhDto.SoLuong;
                                SanPhamDTO spDto     = SanPhamBUS.LaySanPham(maSp);
                                int        trangThai = 0;
                                if ((sl + spDto.SoLuong) > 0)
                                {
                                    trangThai = 1;
                                }
                                SanPhamBUS spBus = new SanPhamBUS();
                                spBus.CapNhatKhoHang(maSp, sl + spDto.SoLuong, trangThai);
                            }

                            if (dhDto.MaDonHang != 0)
                            {
                                DonHangBUS dhBus = new DonHangBUS();

                                dhDto.NguoiCapNhat   = frmDangNhap.gUserName;
                                dhDto.PhiVanChuyen   = Int32.Parse(txtPhiVanChuyen_Them.Text);
                                dhDto.TongTien       = Int32.Parse(lbTongTien.Text.Replace(@",", "")) - ctdhDto.GiaBan;
                                dhDto.SoLuongSanPham = Int32.Parse(lbSoLuong.Text) - ctdhDto.SoLuong;
                                if (rdGiaSi.Checked == true)
                                {
                                    dhDto.HinhThucMua = 0; //Gia Si
                                }
                                else
                                {
                                    dhDto.HinhThucMua = 1; //Gia Le
                                }
                                dhBus.Update(dhDto);
                            }
                            ctdhBus.Delete(ctdhDto.MaChiTietDonHang);
                        }
                    }
                    else
                    {
                        dt.Rows.Remove(dt.Rows[e.RowIndex]);
                    }
                    dtgvDanhSachSanPham.DataSource = dt;
                    formatData();
                    _changed = true;
                }
                if (e.ColumnIndex == dtgvDanhSachSanPham.Columns["CmbSoLuong"].Index && e.RowIndex >= 0)
                {
                    dtgvDanhSachSanPham.BeginEdit(true);
                    ComboBox comboBox = (ComboBox)dtgvDanhSachSanPham.EditingControl;
                    if (comboBox != null)
                    {
                        comboBox.DroppedDown = true;
                    }
                }
            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }