Пример #1
0
        private void btnLuuN_Click(object sender, EventArgs e)
        {
            id = 0; int dem = -1;

            NhapHangBLL bll = new NhapHangBLL();
            MatHangBLL  mhb = new MatHangBLL();

            for (int i = 0; i < lvMHN.Items.Count; i++)
            {
                NhapHang nh = new NhapHang();
                // nh.id = int.Parse(lvMHN.Items[i].SubItems[0].Text);
                nh.idMH      = int.Parse(lvMHN.Items[i].SubItems[0].Text);
                nh.idNCC     = int.Parse(lvMHN.Items[i].SubItems[1].Text);
                nh.idNV      = int.Parse(lvMHN.Items[i].SubItems[2].Text);
                nh.soluong   = int.Parse(lvMHN.Items[i].SubItems[3].Text);
                nh.thanhtien = float.Parse(lvMHN.Items[i].SubItems[4].Text);

                MatHang mh = mhb.getDetailsById(nh.idMH);
                mh.soluong  += nh.soluong;
                nh.thanhtien = nh.soluong * mhb.getGiaNhapById(nh.idMH);



                try
                {
                    if ((id = bll.getIdAndInsert(nh)) != 0)
                    {
                        dem++;
                        mhb.update(mh);
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }

            if (ckReportN.Checked == true)
            {
                id = id - dem;
                tcAdd.Controls.Clear();
                tcAdd.Controls.Add(HoaDonNhap);
                loadReport(1);
            }
            else
            {
                if (lvMHN.Items.Count != 0)
                {
                    MessageBox.Show("Lưu thành công");
                    Close();
                }

                else
                {
                    MessageBox.Show("Chưa có dữ liệu");
                }
            }
        }
Пример #2
0
        private void btnLuuX_Click(object sender, EventArgs e)
        {
            id = 0; int  dem = -1;
            XuatHangBLL  bll = new XuatHangBLL();
            MatHangBLL   mhb = new MatHangBLL();
            KhuyenMaiBLL kmb = new KhuyenMaiBLL();

            for (int i = 0; i < lvMHX.Items.Count; i++)
            {
                XuatHang xh = new XuatHang();
                xh.idMH      = int.Parse(lvMHX.Items[i].SubItems[0].Text);
                xh.idNV      = int.Parse(lvMHX.Items[i].SubItems[1].Text);
                xh.soluong   = int.Parse(lvMHX.Items[i].SubItems[2].Text);
                xh.thanhtien = float.Parse(lvMHX.Items[i].SubItems[3].Text);

                MatHang mh = mhb.getDetailsById(xh.idMH);

                KhuyenMai km = kmb.getDetailsByIdMH(xh.idMH);
                float     gia;
                if (km != null)
                {
                    if (km.typegia == 0)
                    {
                        gia = mh.giaban - mh.giaban / 100 * km.gia;
                    }

                    else
                    {
                        gia = mh.giaban - km.gia;
                    }
                }
                else
                {
                    gia = mh.giaban;
                }

                mh.soluong -= xh.soluong;

                xh.thanhtien = xh.soluong * gia;
                try
                {
                    if ((id = bll.getIdAndInsert(xh)) != 0)
                    {
                        mhb.update(mh);
                        dem++;
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }

            if (ckReportX.Checked == true)
            {
                id = id - dem;
                tcAdd.Controls.Clear();
                tcAdd.Controls.Add(HoaDonBan);
                loadReport(2);
            }
            else
            {
                if (lvMHX.Items.Count != 0)
                {
                    MessageBox.Show("Xuất Mặt Hàng thành công.");
                    Close();
                }

                else
                {
                    MessageBox.Show("Chưa có dữ liệu");
                }
            }
        }
Пример #3
0
        void Luu_Click(object sender, EventArgs e)
        {
            // Mặt hàng
            if (Fn == Function.MAT_HANG)
            {
                MatHangBLL bll = new MatHangBLL();
                MatHang    mh  = bll.getDetailsById(id);

                mh.name = txtNameM.Text;
                if (mh.name == "")
                {
                    MessageBox.Show("Tên mặt hàng không được bỏ trống");
                    txtNameM.Focus();
                    return;
                }

                float i;
                bool  isNum = float.TryParse(txtGiaBanM.Text, out i);
                if (isNum)
                {
                    mh.giaban = i;
                    if (mh.giaban < 0)
                    {
                        MessageBox.Show("Giá bán không được nhỏ hơn 0");
                        txtGiaBanM.Focus();
                        return;
                    }
                }
                else
                {
                    MessageBox.Show("Nhập sai giá bán");
                    txtGiaBanM.Focus();
                    return;
                }

                isNum = float.TryParse(txtGiaNhapM.Text, out i);
                if (isNum)
                {
                    mh.gianhap = i;
                    if (mh.gianhap < 0)
                    {
                        MessageBox.Show("Giá nhập không được nhỏ hơn 0");
                        txtGiaNhapM.Focus();
                        return;
                    }
                }
                else
                {
                    MessageBox.Show("Nhập sai giá nhập");
                    txtGiaNhapM.Focus();
                    return;
                }


                if (mh.giaban < mh.gianhap)
                {
                    MessageBox.Show("Giá bán phải lớn giá nhập.");
                    txtGiaBanM.Focus();
                    return;
                }

                try
                {
                    if (bll.update(mh))
                    {
                        MessageBox.Show("Cập nhật thành công.");
                        Close();
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
            // Danh mục
            else if (Fn == Function.DANH_MUC)
            {
                DanhMucBLL bll = new DanhMucBLL();
                DanhMuc    dm  = bll.getDetailsById(id);

                dm.name = txtNameDM.Text;
                if (dm.name == "")
                {
                    MessageBox.Show("Tên danh mục không được bỏ trống");
                    txtNameDM.Focus();
                    return;
                }

                dm.content = txtContentDM.Text;
                if (dm.content == "")
                {
                    MessageBox.Show("Mô tả không được bỏ trống");
                    txtContentDM.Focus();
                    return;
                }

                try
                {
                    if (bll.update(dm))
                    {
                        MessageBox.Show("Cập nhật thành công.");
                        Close();
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
            // Nhân viên
            else if (Fn == Function.NHAN_VIEN)
            {
                NhanVienBLL bll = new NhanVienBLL();
                NhanVien    nv  = bll.getDetailsById(id);

                nv.name = txtNameNV.Text;
                if (nv.name == "")
                {
                    MessageBox.Show("Tên nhân viên không được để trống");
                    txtNameNV.Focus();
                    return;
                }

                nv.diachi = txtDiaChiNV.Text;
                if (nv.diachi == "")
                {
                    MessageBox.Show("Địa chỉ không được để trống");
                    txtDiaChiNV.Focus();
                    return;
                }

                nv.chucvu = txtChucVuNV.Text;
                if (nv.chucvu == "")
                {
                    MessageBox.Show("Chức vụ không được để trống");
                    txtDiaChiNV.Focus();
                    return;
                }

                double i;
                bool   isNum = double.TryParse(txtSdtNV.Text, out i);
                if (isNum)
                {
                    nv.sdt = txtSdtNV.Text;
                }
                else
                {
                    MessageBox.Show("Nhập không đúng số điện thoại!");
                    txtSdtNV.Focus();
                    return;
                }

                try
                {
                    if (bll.update(nv))
                    {
                        MessageBox.Show("Cập nhật thành công.");
                        Close();
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }

            // Nhà cung cấp
            else if (Fn == Function.NHA_CUNG_CAP)
            {
                NhaCungCapBLL bll = new NhaCungCapBLL();
                NhaCungCap    ncc = bll.getDetailsById(id);

                ncc.name = txtNameNCC.Text;
                if (ncc.name == "")
                {
                    MessageBox.Show("Tên nhà cung cấp không được bỏ trống");
                    txtNameNCC.Focus();
                    return;
                }

                ncc.content = txtContentNCC.Text;
                if (ncc.content == "")
                {
                    MessageBox.Show("Mô tả không được bỏ trống");
                    txtContentNCC.Focus();
                    return;
                }

                ncc.diachi = txtDiaChiNCC.Text;
                if (ncc.diachi == "")
                {
                    MessageBox.Show("Địa chỉ không được bỏ trống");
                    txtDiaChiNCC.Focus();
                    return;
                }

                double i;

                bool isNum = double.TryParse(txtSdtNCC.Text, out i);
                if (isNum)
                {
                    ncc.sdt = txtSdtNCC.Text;
                }
                else
                {
                    MessageBox.Show("Nhập không đúng số điện thoại!");
                    txtSdtNCC.Focus();
                    return;
                }

                try
                {
                    if (bll.update(ncc))
                    {
                        MessageBox.Show("Cập nhật thành công.");
                        Close();
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
            //Khuyến mãi
            else if (Fn == Function.KHUYEN_MAI)
            {
                KhuyenMaiBLL bll = new KhuyenMaiBLL();
                KhuyenMai    km  = bll.getDetailsById(id);

                km.content = txtContentKM.Text;
                if (km.content == "")
                {
                    MessageBox.Show("Mô tả không được bỏ trống");
                    txtContentKM.Focus();
                    return;
                }



                km.starttime = txtBatDauKM.Text;
                km.endtime   = txtKetThucKM.Text;

                DateTime start = Convert.ToDateTime(txtBatDauKM.Text);
                DateTime end   = Convert.ToDateTime(txtKetThucKM.Text);

                //if (DateTime.Now > start)
                //{
                //    MessageBox.Show("Ngày bắt đầu nhỏ hơn ngày hiện tại?");
                //    txtBatDauKM.Focus();
                //    return;
                //}

                if (end < start)
                {
                    MessageBox.Show("Ngày bắt đầu lớn hơn ngày kết thúc?!");
                    txtKetThucKM.Focus();
                    return;
                }
                float i;
                bool  isNum = float.TryParse(txtGiaKM.Text, out i);
                if (isNum)
                {
                    km.gia = i;
                    if (km.typegia == 0)
                    {
                        if (km.gia < 0 || km.gia > 100)
                        {
                            MessageBox.Show("Giới hạn % từ 0 đến 100!");
                            txtGiaKM.Focus();
                            return;
                        }
                    }
                }
                else
                {
                    MessageBox.Show("Nhập không đúng định dạng số!");
                    txtGiaKM.Focus();
                    return;
                }

                try
                {
                    if (bll.update(km))
                    {
                        MessageBox.Show("Cập nhật thành công.");
                        Close();
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
            // Nhập hàng
            else if (Fn == Function.NHAP)
            {
                NhapHangBLL bll  = new NhapHangBLL();
                NhapHang    nh   = bll.getDetailsById(id);
                MatHangBLL  bll1 = new MatHangBLL();
                MatHang     mh   = bll1.getDetailsById(nh.idMH);

                int  i;
                bool isNum = int.TryParse(txtSoLuongNH.Text, out i);
                if (isNum)
                {
                    mh.soluong -= nh.soluong;
                    mh.soluong += i;
                    nh.soluong  = i;
                }
                else
                {
                    MessageBox.Show("Nhập không đúng định dạng số");
                    txtSoLuongNH.Focus();
                    return;
                }

                try
                {
                    if (bll.update(nh))
                    {
                        bll1.update(mh);
                        MessageBox.Show("Cập nhật thành công.");
                        Close();
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
            // Xuất hàng
            else if (Fn == Function.XUAT)
            {
                XuatHangBLL bll = new XuatHangBLL();
                XuatHang    xh  = bll.getDetailsById(id);

                MatHangBLL bll1 = new MatHangBLL();
                MatHang    mh   = bll1.getDetailsById(xh.idMH);

                int  i;
                bool isNum = int.TryParse(txtSoLuongXH.Text, out i);
                if (isNum)
                {
                    if (mh.soluong < i)
                    {
                        MessageBox.Show("Số lượng bán không được lớn hơn tồn kho {" + mh.soluong + "}");
                        return;
                    }

                    mh.soluong += xh.soluong;
                    mh.soluong -= i;
                    xh.soluong  = i;
                }
                else
                {
                    MessageBox.Show("Nhập không đúng định dạng số!");
                    txtSoLuongXH.Focus();
                    return;
                }

                try
                {
                    if (bll.update(xh))
                    {
                        bll1.update(mh);
                        MessageBox.Show("Cập nhật thành công.");
                        Close();
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
        }