private void FormChiTietThanhVien_Load(object sender, EventArgs e)
        {
            ThanhVienDTO thanhVienDTO = ThanhVienBUS.SelectThanhVienById(maThanhVien);

            labelMaThanhVien.Text  = "Mã thành viên: " + maThanhVien;
            labelTenThanhVien.Text = "Tên thành viên: " + thanhVienDTO.TenThanhVien;
            labelDiaChi.Text       = "Địa chỉ: " + thanhVienDTO.DiaChi;
            labelTongCV.Text       = "Tổng CV: " + thanhVienDTO.CV.ToString();

            List <PhieuXuatDTO> listPhieuXuatDTO = PhieuXuatBUS.SelectPhieuXuatByMaThanhVien(maThanhVien);

            if (listPhieuXuatDTO != null)
            {
                dataGridViewChiTiet.Rows.Clear();
                List <ChiTietPhieuXuatDTO> listChiTietPhieuXuatDTO = new List <ChiTietPhieuXuatDTO>();
                foreach (PhieuXuatDTO itemPhieuXuat in listPhieuXuatDTO)
                {
                    listChiTietPhieuXuatDTO = ChiTietPhieuXuatBUS.SelectChiTietPhieuXuatByMaPhieuXuat(itemPhieuXuat.MaPhieuXuat);
                    if (listChiTietPhieuXuatDTO != null)
                    {
                        foreach (ChiTietPhieuXuatDTO itemCTPX in listChiTietPhieuXuatDTO)
                        {
                            dataGridViewChiTiet.Rows.Add(
                                itemPhieuXuat.MaPhieuXuat,
                                itemPhieuXuat.NgayBan.ToString("dd/MM/yyyy"),
                                NhanVienBUS.SelectNhanVienById(itemPhieuXuat.MaNhanVien).TenNhanVien,
                                SanPhamBUS.SelectSanPhamById(itemCTPX.MaSanPham).TenSanPham,
                                itemCTPX.SoLuong.ToString(),
                                string.Format("{0:#,0.##}", itemCTPX.ThanhTien)
                                );
                        }
                    }
                }
            }
        }
Example #2
0
        //Cập nhật lại phiếu xuất
        private void btnYes_Click(object sender, EventArgs e)
        {
            if (CheckOut_clSoLuong(dataGridView_XuatHang))
            {
                List <ChiTietPhieuXuatDTO> listChiTietPhieuXuatDTO = new List <ChiTietPhieuXuatDTO>();
                listChiTietPhieuXuatDTO = ChiTietPhieuXuatBUS.SelectChiTietPhieuXuatByMaPhieuXuat(MaPhieuXuat);

                int        cv         = 0;
                int        cv2        = 0;
                int        SoLuongTon = 0;
                SanPhamDTO sanPhamDTO = new SanPhamDTO();
                for (int i = 0; i < listChiTietPhieuXuatDTO.Count; i++)
                {
                    //Tính lại SoLuongTon của sản phẩm
                    SoLuongTon             = listChiTietPhieuXuatDTO[i].SoLuong - int.Parse(dataGridView_XuatHang.Rows[i].Cells["clSoLuong"].Value.ToString());
                    sanPhamDTO             = SanPhamBUS.SelectSanPhamById(listChiTietPhieuXuatDTO[i].MaSanPham);
                    sanPhamDTO.SoLuongTon += SoLuongTon;
                    SanPhamBUS.UpdateSanPhamById(sanPhamDTO);

                    //cv
                    cv2 += int.Parse(dataGridView_XuatHang.Rows[i].Cells["clSoLuong"].Value.ToString()) * int.Parse(dataGridView_XuatHang.Rows[i].Cells[clCV.Index].Value.ToString());
                    cv  += listChiTietPhieuXuatDTO[i].CV * listChiTietPhieuXuatDTO[i].SoLuong;

                    listChiTietPhieuXuatDTO[i].SoLuong   = int.Parse(dataGridView_XuatHang.Rows[i].Cells["clSoLuong"].Value.ToString());
                    listChiTietPhieuXuatDTO[i].ThanhTien = float.Parse(dataGridView_XuatHang.Rows[i].Cells["clThanhTien"].Value.ToString());
                    ChiTietPhieuXuatBUS.UpdateChiTietPhieuXuatById(listChiTietPhieuXuatDTO[i]);
                }

                //Tinh lai TongCV
                if (IsThanhVien == true)
                {
                    this.thanhVienDTO.CV = this.thanhVienDTO.CV - cv + cv2;
                    ThanhVienBUS.UpdateThanhVienById(this.thanhVienDTO);
                }
                MessageBox.Show("Cập nhật thành công", "Cập nhật đơn hàng");
                this.Dispose();
            }
            else
            {
                MessageBox.Show("Phiếu xuất không hợp lệ, tất cả số lượng sản phẩm đều bằng không", "Phiếu xuất");
                dataGridView_XuatHang.CurrentCell          = dataGridView_XuatHang.Rows[0].Cells[clSoLuong.Index];
                dataGridView_XuatHang.CurrentCell.Selected = true;
                dataGridView_XuatHang.BeginEdit(true);
            }
        }
Example #3
0
        private void buttonXoa_Click(object sender, EventArgs e)
        {
            DialogResult res = MessageBox.Show("Xóa thành viên", "Thành viên", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1);

            //Lấy vị trí cần xóa
            if (res == DialogResult.Yes)
            {
                Index = dataGridView_QuanLyThanhVien.CurrentRow.Index;
                string id  = dataGridView_QuanLyThanhVien.CurrentRow.Cells["ColMaThanhVien"].Value.ToString().Trim();
                int    stt = int.Parse(dataGridView_QuanLyThanhVien.CurrentRow.Cells["ColSTT"].Value.ToString());
                if (ThanhVienBUS.DeleteThanhVienById(id))
                {
                    dataGridView_QuanLyThanhVien.Rows.RemoveAt(Index);
                    if (dataGridView_QuanLyThanhVien.Rows.Count > 0)
                    {
                        bool flag = false;
                        for (int i = 0; i < Index; i++)
                        {
                            if (dataGridView_QuanLyThanhVien.Rows[i].Visible == true)
                            {
                                flag = true;
                            }
                        }
                        for (int i = Index; i < dataGridView_QuanLyThanhVien.RowCount; i++)
                        {
                            if (dataGridView_QuanLyThanhVien.Rows[i].Visible == true)
                            {
                                dataGridView_QuanLyThanhVien.Rows[i].Cells["ColSTT"].Value = stt.ToString();
                                stt++;
                                flag = true;
                            }
                        }
                        if (flag == false)
                        {
                            buttonDisabled();
                        }
                    }
                    else
                    {
                        buttonDisabled();
                    }
                }
            }
        }
Example #4
0
 private void txtMaThanhVien_TextChanged(object sender, EventArgs e)
 {
     thanhVienDTO = new ThanhVienDTO();
     if (ThanhVienBUS.SelectThanhVienById(txtMaThanhVien.Text) != null)
     {
         thanhVienDTO             = ThanhVienBUS.SelectThanhVienById(txtMaThanhVien.Text);
         txtTenKhachHang.Text     = thanhVienDTO.TenThanhVien;
         txtDiaChi.Text           = thanhVienDTO.DiaChi;
         txtTenKhachHang.ReadOnly = true;
         txtDiaChi.ReadOnly       = true;
         IsThanhVien = true;
     }
     else
     {
         txtTenKhachHang.Text     = "";
         txtDiaChi.Text           = "";
         txtTenKhachHang.ReadOnly = false;
         txtDiaChi.ReadOnly       = false;
         IsThanhVien = false;
     }
 }
Example #5
0
        /*
         * Hàm KhoiTao
         * Tải toàn bộ danh sách tham số
         */
        private void KhoiTao()
        {
            //panelTimKiem.Visible = true;
            List <ThanhVienDTO> lsttsDTO = ThanhVienBUS.SelectThanhVienAll();

            if (lsttsDTO != null)
            {
                ThanhVienDTO item = new ThanhVienDTO();
                dataGridView_QuanLyThanhVien.Rows.Clear();
                for (int i = 0; i < lsttsDTO.Count; i++)
                {
                    item = lsttsDTO[i];
                    dataGridView_QuanLyThanhVien.Rows.Add((i + 1).ToString(), item.MaThanhVien, item.TenThanhVien, item.DiaChi, item.CV, item.TienNo);
                    dataGridView_QuanLyThanhVien.Rows[i].ReadOnly = true;
                }
                buttonLamLai.Enabled = true;
                buttonEnabled();
            }
            else
            {
                buttonLamLai.Enabled = false;
                buttonDisabled();
            }
        }
        private void btnXoa_Click(object sender, EventArgs e)
        {
            DialogResult result = MessageBox.Show("Xóa phiếu xuất", "Phiếu xuất", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1);

            //Lấy vị trí cần xóa
            if (result == DialogResult.Yes)
            {
                int    Index = dataGridView_TraCuuXuatHang.CurrentRow.Index;
                int    stt   = int.Parse(dataGridView_TraCuuXuatHang.CurrentRow.Cells[clSTT.Index].Value.ToString());
                string id    = dataGridView_TraCuuXuatHang.CurrentRow.Cells["clMaPhieuXuat"].Value.ToString();
                List <ChiTietPhieuXuatDTO> listChiTietPhieuXuatDTO = ChiTietPhieuXuatBUS.SelectChiTietPhieuXuatByMaPhieuXuat(id);
                PhieuXuatDTO phieuXuatDTO = PhieuXuatBUS.SelectPhieuXuatById(id);
                if (PhieuXuatBUS.DeletePhieuXuatById(id))
                {
                    dataGridView_TraCuuXuatHang.Rows.RemoveAt(Index);
                    if (dataGridView_TraCuuXuatHang.RowCount > 0)
                    {
                        bool f = false;
                        for (int i = 0; i < Index; i++)
                        {
                            if (dataGridView_TraCuuXuatHang.Rows[i].Visible == true)
                            {
                                f = true;
                                break;
                            }
                        }

                        for (int i = Index; i < dataGridView_TraCuuXuatHang.RowCount; i++)
                        {
                            if (dataGridView_TraCuuXuatHang.Rows[i].Visible == true)
                            {
                                dataGridView_TraCuuXuatHang.Rows[i].Cells["clSTT"].Value = stt.ToString();
                                stt++;
                                f = true;
                            }
                        }

                        if (f == false)
                        {
                            buttonDisabled();
                        }
                        else
                        {
                            buttonEnabled();
                        }
                    }
                    else
                    {
                        buttonDisabled();
                    }


                    int        cv         = 0;
                    SanPhamDTO sanPhamDTO = new SanPhamDTO();
                    for (int i = 0; i < listChiTietPhieuXuatDTO.Count; i++)
                    {
                        //Tính lại SoLuongTon của sản phẩm
                        sanPhamDTO            = SanPhamBUS.SelectSanPhamById(listChiTietPhieuXuatDTO[i].MaSanPham);
                        sanPhamDTO.SoLuongTon = sanPhamDTO.SoLuongTon + listChiTietPhieuXuatDTO[i].SoLuong;
                        SanPhamBUS.UpdateSanPhamById(sanPhamDTO);

                        //cv
                        cv += listChiTietPhieuXuatDTO[i].CV * listChiTietPhieuXuatDTO[i].SoLuong;
                    }

                    //Tinh lai TongCV
                    if (phieuXuatDTO.MaThanhVien != "")
                    {
                        ThanhVienDTO thanhVien = ThanhVienBUS.SelectThanhVienById(phieuXuatDTO.MaThanhVien);
                        thanhVien.CV = thanhVien.CV - cv;
                        ThanhVienBUS.UpdateThanhVienById(thanhVien);
                    }

                    MessageBox.Show("Xóa thành công");
                }
            }
        }
Example #7
0
        private void buttonYes_Click(object sender, EventArgs e)
        {
            bool flag = true;

            if (dataGridView_QuanLyThanhVien.Rows[Index].Cells["ColTenThanhVien"].Value == null)
            {
                MessageBox.Show("Tên thành viên không được để trống");
                dataGridView_QuanLyThanhVien.CurrentCell = dataGridView_QuanLyThanhVien.Rows[Index].Cells["ColTenThanhVien"];
                dataGridView_QuanLyThanhVien.BeginEdit(true);
                flag = false;
            }
            else if (dataGridView_QuanLyThanhVien.Rows[Index].Cells["ColDiaChi"].Value == null)
            {
                MessageBox.Show("Địa chỉ không được để trống");
                dataGridView_QuanLyThanhVien.CurrentCell = dataGridView_QuanLyThanhVien.Rows[Index].Cells["ColDiaChi"];
                dataGridView_QuanLyThanhVien.BeginEdit(true);
                flag = false;
            }



            if (flag)
            {
                //ThanhVienDTO tvDTO = new ThanhVienDTO();
                //tvDTO.TenThanhVien = dataGridView_QuanLyThanhVien.Rows[Index].Cells["ColTenThanhVien"].Value.ToString();
                //tvDTO.DiaChi = dataGridView_QuanLyThanhVien.Rows[Index].Cells["ColDiaChi"].Value.ToString();
                //tvDTO.CV = 0;//int.Parse(dataGridView_QuanLyThanhVien.Rows[Index].Cells["ColCV"].Value.ToString());
                //tvDTO.TienNo = 0;//float.Parse(dataGridView_QuanLyThanhVien.Rows[Index].Cells["ColTienNo"].Value.ToString());
                if (Status == 1)//Them tham so
                {
                    ThanhVienDTO tvDTO = new ThanhVienDTO();
                    tvDTO.TenThanhVien = dataGridView_QuanLyThanhVien.Rows[Index].Cells["ColTenThanhVien"].Value.ToString().Trim();
                    tvDTO.DiaChi       = dataGridView_QuanLyThanhVien.Rows[Index].Cells["ColDiaChi"].Value.ToString().Trim();
                    tvDTO.CV           = 0;
                    tvDTO.TienNo       = 0;
                    tvDTO.MaThanhVien  = ThanhVienBUS.CreateThanhVienId().Trim();
                    dataGridView_QuanLyThanhVien.Rows[Index].Cells["ColMaThanhVIen"].Value = tvDTO.MaThanhVien;
                    dataGridView_QuanLyThanhVien.Rows[Index].Cells["ColSTT"].Value         = (Index + 1).ToString();
                    if (ThanhVienBUS.InsertThanhVien(tvDTO))
                    {
                        dataGridView_QuanLyThanhVien.Rows[Index].ReadOnly = true;
                        MessageBox.Show("Thêm thành công");
                        dataGridView_QuanLyThanhVien.Rows[dataGridView_QuanLyThanhVien.Rows.Count - 1].Cells["ColCV"].Value     = tvDTO.CV;
                        dataGridView_QuanLyThanhVien.Rows[dataGridView_QuanLyThanhVien.Rows.Count - 1].Cells["ColTienNo"].Value = tvDTO.TienNo;
                    }
                    else
                    {
                        dataGridView_QuanLyThanhVien.Rows.RemoveAt(Index);
                        MessageBox.Show("Thêm thất bại");
                    }
                }
                else if (Status == 2)
                {
                    ThanhVienDTO tvDTO = new ThanhVienDTO();
                    tvDTO.TenThanhVien = dataGridView_QuanLyThanhVien.Rows[Index].Cells["ColTenThanhVien"].Value.ToString().Trim();
                    tvDTO.DiaChi       = dataGridView_QuanLyThanhVien.Rows[Index].Cells["ColDiaChi"].Value.ToString().Trim();
                    tvDTO.CV           = int.Parse(dataGridView_QuanLyThanhVien.Rows[Index].Cells["ColCV"].Value.ToString().Trim());
                    tvDTO.TienNo       = float.Parse(dataGridView_QuanLyThanhVien.Rows[Index].Cells["ColTienNo"].Value.ToString().Trim());
                    tvDTO.MaThanhVien  = dataGridView_QuanLyThanhVien.Rows[Index].Cells["ColMaThanhVien"].Value.ToString().Trim();
                    if (ThanhVienBUS.UpdateThanhVienById(tvDTO))
                    {
                        dataGridView_QuanLyThanhVien.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_QuanLyThanhVien.Rows[Index].Cells["ColTenThanhVien"].Value = BackupThanhVienDTO.TenThanhVien;
                        dataGridView_QuanLyThanhVien.Rows[Index].Cells["ColDiaChi"].Value       = BackupThanhVienDTO.DiaChi;
                        dataGridView_QuanLyThanhVien.Rows[Index].Cells["ColCV"].Value           = BackupThanhVienDTO.CV;
                        dataGridView_QuanLyThanhVien.Rows[Index].Cells["ColTienNo"].Value       = BackupThanhVienDTO.TienNo;
                        dataGridView_QuanLyThanhVien.Rows[Index].ReadOnly = true;
                    }
                }

                Reset();
            }
        }
Example #8
0
        private bool Process_Button()
        {
            //Lấy các trường để insert vào bảng PhieuXuat
            PhieuXuatDTO phieuXuatDTO = new PhieuXuatDTO();

            phieuXuatDTO.MaPhieuXuat = txtMaPhieuXuat.Text;
            phieuXuatDTO.NgayBan     = DateTimeSystem;
            phieuXuatDTO.MaNhanVien  = ThongTin.NhanVienDTO.MaNhanVien;

            if (txtMaThanhVien.Text == "")
            {
                //MaThanhVien Thamchieu bang ThanhVien => notnull=>sua storeproc
                phieuXuatDTO.MaThanhVien = null;

                if (txtTenKhachHang.Text == "")
                {
                    MessageBox.Show("Tên khách hàng không hợp lệ");
                    return(false);
                }
                else
                {
                    phieuXuatDTO.TenKhachHang = txtTenKhachHang.Text;
                }

                if (txtDiaChi.Text == "")
                {
                    MessageBox.Show("Địa chỉ không hợp lệ");
                    return(false);
                }
                else
                {
                    phieuXuatDTO.DiaChi = txtDiaChi.Text;
                }
                phieuXuatDTO.MaLoaiPhieuXuat = "LPX02";
            }
            else
            {
                phieuXuatDTO.MaThanhVien     = txtMaThanhVien.Text;
                phieuXuatDTO.TenKhachHang    = txtTenKhachHang.Text;
                phieuXuatDTO.DiaChi          = txtDiaChi.Text;
                phieuXuatDTO.MaLoaiPhieuXuat = "LPX01";
            }

            //Lấy các trường để insert vào bảng ChiTietPhieuXuat
            List <ChiTietPhieuXuatDTO> listChiTietPhieuXuatDTO = new List <ChiTietPhieuXuatDTO>();
            SanPhamDTO sanPhamDTO = new SanPhamDTO();

            for (int i = 0; i < dataGridView_XuatHang.Rows.Count; i++)
            {
                ChiTietPhieuXuatDTO chiTietPhieuXuatDTO = new ChiTietPhieuXuatDTO();
                DataGridViewRow     Row = dataGridView_XuatHang.Rows[i];
                int check;
                int.TryParse(Row.Cells["clSoLuong"].Value.ToString(), out check);
                if (check > 0)
                {
                    chiTietPhieuXuatDTO.MaChiTietPhieuXuat = txtMaPhieuXuat.Text;
                    if (i > 100)
                    {
                        chiTietPhieuXuatDTO.MaChiTietPhieuXuat += (i + 1).ToString();
                    }
                    else if (i > 100)
                    {
                        chiTietPhieuXuatDTO.MaChiTietPhieuXuat += "0" + (i + 1).ToString();
                    }
                    else
                    {
                        chiTietPhieuXuatDTO.MaChiTietPhieuXuat += "00" + (i + 1).ToString();
                    }

                    chiTietPhieuXuatDTO.MaPhieuXuat = txtMaPhieuXuat.Text;
                    chiTietPhieuXuatDTO.MaSanPham   = Row.Cells["clMaSanPham"].Value.ToString();
                    chiTietPhieuXuatDTO.CV          = int.Parse(Row.Cells["clCV"].Value.ToString());
                    chiTietPhieuXuatDTO.SoLuong     = int.Parse(Row.Cells["clSoLuong"].Value.ToString());
                    chiTietPhieuXuatDTO.DonGia      = float.Parse(Row.Cells["clDonGia"].Value.ToString());
                    chiTietPhieuXuatDTO.ThanhTien   = float.Parse(Row.Cells["clThanhTien"].Value.ToString());
                    listChiTietPhieuXuatDTO.Add(chiTietPhieuXuatDTO);

                    //Tinh SoLuongTon của sản phẩm
                    int SoLuongTon = int.Parse(Row.Cells["clSoLuongTon"].Value.ToString()) - int.Parse(Row.Cells["clSoLuong"].Value.ToString());
                    sanPhamDTO            = SanPhamBUS.SelectSanPhamById(chiTietPhieuXuatDTO.MaSanPham);
                    sanPhamDTO.SoLuongTon = SoLuongTon;
                    SanPhamBUS.UpdateSanPhamById(sanPhamDTO);

                    //Tinh TongCV
                    TongCV += int.Parse(Row.Cells["clCV"].Value.ToString()) * int.Parse(Row.Cells["clSoLuong"].Value.ToString());
                }
            }

            //insert dữ liệu
            if (PhieuXuatBUS.InsertPhieuXuat(phieuXuatDTO))
            {
                foreach (ChiTietPhieuXuatDTO chiTietPhieuXuatDTO in listChiTietPhieuXuatDTO)
                {
                    ChiTietPhieuXuatBUS.InsertChiTietPhieuXuat(chiTietPhieuXuatDTO);
                }
                if (IsThanhVien == true)
                {
                    thanhVienDTO.CV += TongCV;
                    ThanhVienBUS.UpdateThanhVienById(thanhVienDTO);
                }

                MessageBox.Show("Nhập dữ liệu thành công");
                return(true);
            }
            else
            {
                MessageBox.Show("Nhập dữ liệu thất bại");
            }
            return(false);
        }