Exemplo n.º 1
0
        private void btnXacNhan_Click(object sender, EventArgs e)
        {
            string tenDN   = txtTenDangNhap.Text.Trim();
            string matkhau = txtMatKhau.Text.Trim();

            try
            {
                if (tenDN == "")
                {
                    MessageBox.Show("Thiếu tên đăng nhập!", "Chú ý!");
                    txtTenDangNhap.Select();
                    return;
                }
                if (matkhau == "")
                {
                    MessageBox.Show("Hãy nhập mật khẩu!", "Chú ý!");
                    txtMatKhau.Select();
                    return;
                }
                string        select = "SELECT * FROM tblDangNhap";
                SqlDataReader dr     = DataConn.ThucHienReader(select);
                Boolean       kt     = false;
                if (dr != null)
                {
                    while (dr.Read())
                    {
                        if (dr.GetString(0) == tenDN && dr.GetString(1) == matkhau)
                        {
                            kt = true;
                            mainForm.DisplayAll();
                            MessageBox.Show("Đăng nhập thành công!");
                            this.Close();
                        }
                    }
                }
                dr.Close();
                dr.Dispose();

                if (kt == false)
                {
                    MessageBox.Show("Bạn nhập sai tên đăng nhập hoặc mật khẩu!");
                }
            }
            catch (NotEnoughInfoException)
            {
                MessageBox.Show("Bạn hãy nhập tên đăng nhập và mật khẩu!");
            }
        }
        private void btnThem_Click(object sender, EventArgs e)
        {
            string select = "";

            try
            {
                if (txtMaNV.Text == "" || txtTenNV.Text == "" || txtDiaChi.Text == "")
                {
                    throw new NotEnoughInfoException();
                }

                string        select1 = "select MaNhanVien from tblNhanVien";
                SqlDataReader dr      = DataConn.ThucHienReader(select1);
                if (dr != null)
                {
                    while (dr.Read())
                    {
                        if (dr.GetString(0) == txtMaNV.Text)
                        {
                            dr.Close();
                            dr.Dispose();
                            throw new SameKeyException();
                        }
                    }
                }
                dr.Close();
                dr.Dispose();

                select = "insert into tblNhanVien values(N'" + txtMaNV.Text + "',N'" + txtTenNV.Text + "',N'" + txtDiaChi.Text + "',N'" + txtDienThoai.Text + "')";
                DataConn.ThucHienCmd(select);
                MessageBox.Show("Đã thêm nhân viên " + txtTenNV.Text + " vào danh sách nhân viên!");
            }
            catch (FormatException)
            {
                MessageBox.Show("Không đúng định dạng dữ liệu cần thiết! Bạn hãy xem lại hoặc nhấn F1 để vào trợ giúp!");
            }
            catch (NotEnoughInfoException)
            {
                MessageBox.Show("Bạn hãy nhập đủ các trường có dấu (*)");
            }
            catch (SameKeyException)
            {
                MessageBox.Show("Đã có mã nhân viên này! Bạn hãy chọn một mã khác!");
            }
        }
Exemplo n.º 3
0
        private void btnThem_Click(object sender, EventArgs e)
        {
            try
            {
                //Exception khi không đủ dữ liệu
                if (txtMaMatH.Text == "" || txtTenMatH.Text == "" || txtSoLuong.Text == "" || txtDonGia.Text == "")
                {
                    throw new NotEnoughInfoException();
                }

                //Exception khi trùng Mã mặt hàng (trùng khóa chính)
                string        select1 = "select MaMatH from tblMatHang";
                SqlDataReader dr      = DataConn.ThucHienReader(select1);
                if (dr != null)
                {
                    while (dr.Read())
                    {
                        if (dr.GetString(0) == txtMaMatH.Text)
                        {
                            dr.Close();
                            dr.Dispose();
                            throw new SameKeyException();
                        }
                    }
                }
                dr.Close();
                dr.Dispose();

                string select = "insert into tblMatHang values(N'" + txtMaMatH.Text + "',N'" + txtTenMatH.Text + "'," + txtSoLuong.Text + "," + txtDonGia.Text + "," + (float.Parse(txtDonGia.Text) + 20000) + ")";
                DataConn.ThucHienCmd(select);
                MessageBox.Show("Đã nhập thêm mặt hàng mới!");
            }
            catch (FormatException)
            {
                MessageBox.Show("Không đúng định dạng cần thiết! Hãy xem trợ giúp!");
            }
            catch (SameKeyException)
            {
                MessageBox.Show("Đã có mặt hàng với mã này! Hãy đổi mã mặt hàng khác!");
            }
            catch (NotEnoughInfoException)
            {
                MessageBox.Show("Bạn hãy nhập đủ các trường có dấu (*)");
            }
        }
        private void btnThem_Click(object sender, EventArgs e)
        {
            try
            {
                //Exception khi không đủ dữ liệu để nhập
                if (txtMaNCC.Text == "" || txtMaMatH.Text == "" || txtTenNCC.Text == "" || txtDienThoai.Text == "")
                {
                    throw new NotEnoughInfoException();
                }
                //Exception khi trùng mã nhà cung cấp
                string        select1 = "select MaNCC from tblNhaCungCap";
                SqlDataReader dr      = DataConn.ThucHienReader(select1);
                if (dr != null)
                {
                    while (dr.Read())
                    {
                        if (dr.GetString(0) == txtMaNCC.Text)
                        {
                            dr.Close();
                            dr.Dispose();
                            throw new SameKeyException();
                        }
                    }
                }
                dr.Close();
                dr.Dispose();

                string select = "insert into tblNhaCungCap(MaNCC,MaMatH,TenNCC,DienThoai) values('" + txtMaNCC.Text + "','" + txtMaMatH.Text + "','" + txtTenNCC.Text + "','" + txtDienThoai.Text + "')";
                DataConn.ThucHienCmd(select);
                MessageBox.Show("Đã thêm nhà cung cấp mới!");
            }
            catch (FormatException)
            {
                MessageBox.Show("Không đúng định dạng cần thiết! Hãy xem trợ giúp");
            }
            catch (SameKeyException)
            {
                MessageBox.Show("Đã có nhà cung cấp với mã này! Hãy nhập mã khác!");
            }
            catch (NotEnoughInfoException)
            {
                MessageBox.Show("Bạn hãy nhập đủ các trường có dấu (*)");
            }
        }
 private void btnXoa_Click(object sender, EventArgs e)
 {
     try
     {
         //Nếu ko có đủ dữ liệu->thông báo thiếu dữ liệu
         if (txtMaNV.Text == "" && txtTenNV.Text == "" && txtDienThoai.Text == "" && txtDiaChi.Text == "")
         {
             throw new NotEnoughInfoException();
         }
         //Nếu trong hóa đơn xuất có nhân viên này lập -> thông báo phải xóa hóa đơn trước khi xóa nhân viên
         string        select1 = "select MaNhanVien from tblHoaDonXuat";
         SqlDataReader dr      = DataConn.ThucHienReader(select1);
         if (dr != null)
         {
             while (dr.Read())
             {
                 if (dr.GetString(0) == txtMaNV.Text)
                 {
                     dr.Close();
                     dr.Dispose();
                     throw new SameKeyException();
                 }
             }
         }
         dr.Close();
         dr.Dispose();
         //Thực hiện xóa nhân viên
         string delete = "DELETE tblNhanVien WHERE MaNhanVien=N'" + txtMaNV.Text + "'";
         DataConn.ThucHienCmd(delete);
         HienThi();
     }
     catch (NotEnoughInfoException)
     {
         MessageBox.Show("Hãy nhập đủ dữ liệu trước khi nhấn nút xóa!");
     }
     catch (SameKeyException)
     {
         MessageBox.Show("Đang có hóa đơn xuất nhân viên này lập! Hãy xóa hóa đơn trước khi xóa nhân viên!", "Chú ý!");
     }
 }
Exemplo n.º 6
0
        private void btnXoa_Click(object sender, EventArgs e)
        {
            try
            {
                if (txtFax.Text == "" && txtEmail.Text == "" && txtDiaChi.Text == "" && txtDienThoai.Text == "")
                {
                    throw new NotEnoughInfoException();
                }
                string        select1 = "select MaNCC from tblHoaDonNhap";
                SqlDataReader dr      = DataConn.ThucHienReader(select1);
                if (dr != null)
                {
                    while (dr.Read())
                    {
                        if (dr.GetString(0) == txtMaNCC.Text)
                        {
                            dr.Close();
                            dr.Dispose();
                            throw new SameKeyException();
                        }
                    }
                }
                dr.Close();
                dr.Dispose();

                string delete = "DELETE tblNhaCungCap WHERE MaNCC=N'" + txtMaNCC.Text + "'";
                DataConn.ThucHienCmd(delete);
                HienThi();
            }
            catch (NotEnoughInfoException)
            {
                MessageBox.Show("Hãy nhập đủ dữ liệu trước khi nhấn nút xóa!");
            }
            catch (SameKeyException)
            {
                MessageBox.Show("Đang có hóa đơn nhập của nhà cung cấp này! Bạn hãy xóa hóa đơn trước khi xóa nhà cung cấp!", "Chú ý!");
            }
        }
        private void btnXuatHang_Click(object sender, EventArgs e)
        {
            //btnGhi.Enabled = true;
            //btnHoan.Enabled = true;
            //btnXuatHang.Enabled = false;
            //btnThoat.Enabled = true;
            //btnInHD.Enabled = false;

            //txtDonGia.ReadOnly = false;
            //txtDonViTinh.ReadOnly = false;
            //txtGhiChu.ReadOnly = false;
            //txtMaHD.ReadOnly = false;
            //txtThue.ReadOnly = false;
            //txtSoLuong.ReadOnly = false;
            //cboMaMatH.Enabled = true;
            //cboMaNhanVien.Enabled = true;
            //pckNgayXuat.Enabled = true;

            //txtSoLuong.Text = "";
            //txtMaHD.Text = "";
            //txtGhiChu.Text = "";
            //txtDonViTinh.Text = "";
            //txtDonGia.Text = "";
            //cboMaMatH.Text = "";
            //cboMaNhanVien.Text = "";
            //txtThue.Text = "0";

            //txtMaHD.Select();
            try
            {
                if (txtMaHD.Text == "")
                {
                    MessageBox.Show("Hãy nhập mã hóa đơn!", "Chú ý!");
                    txtMaHD.Select();
                    return;
                }
                if (cboMaNhanVien.Text == "")
                {
                    MessageBox.Show("Hãy chọn tên nhân viên xuất hàng!", "Chú ý!");
                    cboMaNhanVien.Select();
                    return;
                }
                if (pckNgayXuat.Text == "")
                {
                    MessageBox.Show("Hãy chọn ngày xuất!", "Chú ý!");
                    pckNgayXuat.Select();
                    return;
                }

                string        select1 = "select MaHD FROM tblHoaDonXuat";
                SqlDataReader dr      = DataConn.ThucHienReader(select1);


                if (dr != null)
                {
                    //MessageBox.Show("1");
                    while (dr.Read())
                    {
                        if (dr.GetString(0) == txtMaHD.Text)
                        {
                            //MessageBox.Show("2");
                            dr.Close();
                            dr.Dispose();
                            throw new SameKeyException();
                        }
                    }
                }
                dr.Close();
                dr.Dispose();

                string select = "insert into tblHoaDonXuat(MaHD,MaNhanVien,NgayXuat,GhiChu) values(N'" + txtMaHD.Text + "',N'" + values2 + "',N'" + pckNgayXuat.Text + "',N'" + txtGhiChu.Text + "')";
                DataConn.ThucHienCmd(select);

                HienThi();

                groupChiTietHDX.Enabled = true;
                //groupHoaDonXuat.Enabled = false;
                btnThem_Click(sender, e);
                cboMaMatH.Select();
            }
            catch (SameKeyException)
            {
                MessageBox.Show("Đã có hóa đơn với mã này!", "Chú ý!");
            }
            catch (FormatException)
            {
                MessageBox.Show("Không đúng định dạng dữ liệu!", "Thông báo!");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
        private void btnTinhTien_Click(object sender, EventArgs e)
        {
            try
            {
                if (txtMaHD.Text == "")
                {
                    throw new NotEnoughInfoException();
                }

                string        sql = "SELECT MaHD FROM tblChiTietHDX";
                SqlDataReader dr  = DataConn.ThucHienReader(sql);
                int           c   = 0;
                if (dr != null)
                {
                    while (dr.Read())
                    {
                        if (dr.GetString(0) == txtMaHD.Text)
                        {
                            c = 1;
                        }
                    }
                }

                if (c == 0)
                {
                    dr.Close();
                    dr.Dispose();
                    throw new NotEnoughInfoException();
                }
                else
                {
                    dr.Close();
                    dr.Dispose();

                    string select = "SELECT SoLuong,DonGia,Thue FROM tblChiTietHDX WHERE MaHD='" + txtMaHD.Text + "'";

                    SqlDataReader dr1     = DataConn.ThucHienReader(select);
                    double        gia     = 0;
                    double        soluong = 0;
                    double        thue    = 0;
                    double        tong    = 0;
                    if (dr1 != null)
                    {
                        while (dr1.Read())
                        {
                            soluong = dr1.GetDouble(0);
                            gia     = dr1.GetDouble(1);
                            thue    = dr1.GetDouble(2);
                            tong   += gia * soluong + thue * gia;
                        }
                    }
                    dr1.Close();
                    dr1.Dispose();
                    txtTongTien.Text = tong.ToString();
                    string update = "UPDATE tblHoaDonXuat SET TongTien=" + txtTongTien.Text + " WHERE MaHD='" + txtMaHD.Text + "'";
                    DataConn.ThucHienCmd(update);
                }
            }
            catch (NotEnoughInfoException)
            {
                MessageBox.Show("Bạn chưa nhập mã hóa đơn hoặc chưa có hóa đơn với mã này!", "Thông báo");
            }
            catch (Exception se)
            {
                MessageBox.Show("" + se.Message);
            }
        }
        private void btnGhi_Click(object sender, EventArgs e)
        {
            string select;

            if (kt == true)
            {
                try
                {
                    //Exception khi không đủ thông tin

                    if (cboMaMatH.Text == "")
                    {
                        MessageBox.Show("Hãy chọn mặt hàng xuất!", "Chú ý!");
                        cboMaMatH.Select();
                        return;
                    }
                    if (txtSoLuong.Text == "")
                    {
                        MessageBox.Show("Hãy nhập số lượng!", "Chú ý!");
                        txtSoLuong.Select();
                        return;
                    }
                    if (txtDonGia.Text == "")
                    {
                        MessageBox.Show("Hãy nhập đơn giá!", "Chú ý!");
                        txtDonGia.Select();
                        return;
                    }
                    if (txtDonViTinh.Text == "")
                    {
                        MessageBox.Show("Hãy nhập đơn vị tính!", "Chú ý!");
                        txtDonViTinh.Select();
                        return;
                    }
                    if (txtThue.Text == "")
                    {
                        MessageBox.Show("Hãy nhập thuế cho mặt hàng này!", "Chú ý!");
                        txtThue.Select();
                        return;
                    }
                    if (double.Parse(txtSoLuong.Text) <= 0)
                    {
                        MessageBox.Show("Số lượng không được nhỏ hơn 0!");
                        txtSoLuong.Select();
                        return;
                    }
                    if (double.Parse(txtDonGia.Text) <= 0)
                    {
                        MessageBox.Show("Đơn giá không được nhỏ hơn 0!");
                        txtSoLuong.Select();
                        return;
                    }
                    try
                    {
                        string        select3 = "SELECT SoLuong FROM tblMatHang WHERE MaMatH='" + values1 + "'";
                        SqlDataReader dr1     = DataConn.ThucHienReader(select3);
                        if (dr1 != null)
                        {
                            while (dr1.Read())
                            {
                                if (dr1.GetDouble(0) < double.Parse(txtSoLuong.Text))
                                {
                                    dr1.Close();
                                    dr1.Dispose();
                                    throw new OutOfQuantityException();
                                }
                            }
                        }
                        dr1.Close();
                        dr1.Dispose();
                    }
                    catch (OutOfQuantityException)
                    {
                        MessageBox.Show("Số lượng hàng trong kho không đủ để xuất!");
                        return;
                    }

                    string        select1 = "select MaMatH from tblChiTietHDX WHERE MaHD='" + txtMaHD.Text + "'";
                    SqlDataReader dr      = DataConn.ThucHienReader(select1);

                    if (dr != null)
                    {
                        while (dr.Read())
                        {
                            if (dr.GetString(0) == values1)
                            {
                                dr.Close();
                                dr.Dispose();
                                throw new SameKeyException();
                            }
                        }
                    }
                    dr.Close();
                    dr.Dispose();

                    //Thêm vào bảng tblChiTietHDX
                    select = "insert into tblChiTietHDX(MaMatH,MaHD,SoLuong,DonViTinh,DonGia,Thue) values(N'" + values1 + "',N'" + txtMaHD.Text + "'," + txtSoLuong.Text + ",N'" + txtDonViTinh.Text + "'," + txtDonGia.Text + "," + txtThue.Text + ")";
                    DataConn.ThucHienCmd(select);

                    //Cập nhật lại Số Lượng cho bảng tblMatHang (bớt số lượng mặt hàng)
                    select = "update tblMatHang set SoLuong=SoLuong-" + txtSoLuong.Text + " where MaMatH=N'" + values1 + "'";
                    DataConn.ThucHienCmd(select);
                    btnTinhTien_Click(sender, e);

                    HienThi();
                }
                catch (FormatException)
                {
                    MessageBox.Show("Không đúng định dạng dữ liệu cần thiết! Hãy xem trợ giúp!");
                }
                catch (NotEnoughInfoException)
                {
                    MessageBox.Show("Hãy nhập đủ các dữ liệu trước khi nhấn nút ghi!");
                }
                catch (SameKeyException)
                {
                    MessageBox.Show("Đã xuất mặt hàng này! ", "Thông báo!");
                }

                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
            else
            {
                string update = "";
                try
                {
                    if (cboMaMatH.Text == "" && txtSoLuong.Text == "" && txtDonGia.Text == "" && txtDonViTinh.Text == "")
                    {
                        throw new NotEnoughInfoException();
                    }
                    if (double.Parse(txtSoLuong.Text) <= 0)
                    {
                        MessageBox.Show("Số lượng không được nhỏ hơn 0!");
                        txtSoLuong.Select();
                        return;
                    }
                    if (double.Parse(txtDonGia.Text) <= 0)
                    {
                        MessageBox.Show("Đơn giá không được nhỏ hơn 0!");
                        txtSoLuong.Select();
                        return;
                    }
                    string        select1 = "select MaMatH from tblChiTietHDX WHERE MaHD='" + txtMaHD.Text + "'";
                    SqlDataReader dr      = DataConn.ThucHienReader(select1);

                    if (dr != null)
                    {
                        while (dr.Read())
                        {
                            if (dr.GetString(0) == values1)
                            {
                                dr.Close();
                                dr.Dispose();
                                throw new SameKeyException();
                            }
                        }
                    }
                    dr.Close();
                    dr.Dispose();

                    try
                    {
                        string        select3 = "SELECT SoLuong FROM tblMatHang WHERE MaMatH='" + values1 + "'";
                        SqlDataReader dr1     = DataConn.ThucHienReader(select3);
                        if (dr1 != null)
                        {
                            while (dr1.Read())
                            {
                                if (dr1.GetDouble(0) < double.Parse(txtSoLuong.Text))
                                {
                                    dr1.Close();
                                    dr1.Dispose();
                                    throw new OutOfQuantityException();
                                }
                            }
                        }
                        dr1.Close();
                        dr1.Dispose();
                    }
                    catch (OutOfQuantityException)
                    {
                        MessageBox.Show("Số lượng hàng trong kho không đủ để xuất!");
                        return;
                    }

                    update = "UPDATE tblChiTietHDX SET MaMatH='" + values1 + "' WHERE MaHD='" + txtMaHD.Text + "' AND MaMatH='" + txtMaH.Text + "'";
                    DataConn.ThucHienCmd(update);


                    HienThi();
                    btnTinhTien_Click(sender, e);
                }
                catch (FormatException)
                {
                    MessageBox.Show("Không đúng định dạng dữ liệu!", "Thông báo!");
                }
                catch (NotEnoughInfoException)
                {
                    MessageBox.Show("Hãy nhập dữ liệu để sửa!", "Thông báo!");
                }
                catch (SameKeyException)
                {
                    update = "UPDATE tblChiTietHDX SET SoLuong=" + txtSoLuong.Text + ",DonViTinh=N'" + txtDonViTinh.Text + "',DonGia=" + txtDonGia.Text + ",Thue=" + txtThue.Text + " WHERE MaHD='" + txtMaHD.Text + "' AND MaMatH='" + values1 + "'";
                    DataConn.ThucHienCmd(update);
                    HienThi();
                    //MessageBox.Show("Đã xuất mặt hàng này! ", "Thông báo!");
                    btnTinhTien_Click(sender, e);
                }
            }
        }
        private void btnNhap_Click(object sender, EventArgs e)
        {
            try
            {
                if (txtMaHoaDon.Text == "")
                {
                    MessageBox.Show("Hãy nhập mã hóa đơn!", "Chú ý!");
                    txtMaHoaDon.Select();
                    return;
                }
                if (cboMaNCC.Text == "")
                {
                    MessageBox.Show("Hãy chọn nhà cung cấp!", "Chú ý!");
                    cboMaNCC.Select();
                    return;
                }
                if (pckNgayNhap.Text == "")
                {
                    MessageBox.Show("Hãy chọn ngày nhập!", "Chú ý!");
                    pckNgayNhap.Select();
                    return;
                }

                string        select1 = "select tblHoaDonNhap.MaHD from tblHoaDonNhap";
                SqlDataReader dr      = DataConn.ThucHienReader(select1);

                if (dr != null)
                {
                    while (dr.Read())
                    {
                        if (dr.GetString(0) == txtMaHoaDon.Text)
                        {
                            dr.Close();
                            dr.Dispose();
                            throw new SameKeyException();
                        }
                    }
                }
                dr.Close();
                dr.Dispose();

                string select = "";
                select = "insert into tblHoaDonNhap(MaHD,MaNCC,NgayNhap,GhiChu) values(N'" + txtMaHoaDon.Text + "',N'" + values1 + "',N'" + pckNgayNhap.Text + "',N'" + txtGhiChu.Text + "')";
                DataConn.ThucHienCmd(select);
                HienThi();

                groupChiTietHDN.Enabled = true;
                btnThem_Click(sender, e);
                cboMaMatH.Select();
            }

            catch (SameKeyException)
            {
                MessageBox.Show("Đã có mã hóa đơn này!", "Thông báo!");
            }
            catch (FormatException)
            {
                MessageBox.Show("Định dạng dữ liệu không đúng!", "Thông báo!");
            }
            catch (Exception se)
            {
                MessageBox.Show(se.Message);
            }
            //kt = true;
            //cboMaMatH.Enabled = true;
            //cboMaNCC.Enabled = true;
            //txtDonGia.ReadOnly = false;
            //txtDonViTinh.ReadOnly = false;
            //txtGhiChu.ReadOnly = false;
            //txtMaHoaDon.ReadOnly = false;
            //txtSoLuong.ReadOnly = false;
            //pckNgayNhap.Enabled = true;
            //txtThue.ReadOnly = false;

            //btnGhi.Enabled = true;
            //btnHoan.Enabled = true;
            //btnNhap.Enabled = false;
            //btnThoat.Enabled = true;
            //btnInHD.Enabled = false;

            //cboMaMatH.Text = "";
            //cboMaNCC.Text = "";
            //txtDonGia.Text = "";
            //txtDonViTinh.Text = "";
            //txtGhiChu.Text = "";
            //txtMaHoaDon.Text = "";
            //txtSoLuong.Text = "";
            //pckNgayNhap.Text = DateTime.Today.TimeOfDay.ToString();
        }
Exemplo n.º 11
0
        private void btnGhi_Click(object sender, EventArgs e)
        {
            if (kt == true)//Thêm đơn đặt hàng chi tiết
            {
                string select = "";
                try
                {
                    //Exception khi không đủ dữ liệu

                    if (cboMatHang.Text == "")
                    {
                        MessageBox.Show("Hãy chọn mặt hàng!", "Chú ý!");
                        cboMatHang.Select();
                        return;
                    }
                    if (txtSoLuong.Text == "")
                    {
                        MessageBox.Show("Hãy nhập số lượng mặt hàng!", "Chú ý!");
                        txtSoLuong.Select();
                        return;
                    }
                    if (pckNgayDat.Text == "")
                    {
                        MessageBox.Show("Hãy nhập ngày đặt hàng!", "Chú ý!");
                        pckNgayDat.Select();
                        return;
                    }
                    if (pckNgayNhan.Text == "")
                    {
                        MessageBox.Show("Hãy nhập ngày nhận hàng!", "Chú ý!");
                        pckNgayNhan.Select();
                        return;
                    }

                    if (double.Parse(txtSoLuong.Text) <= 0)
                    {
                        MessageBox.Show("Số lượng không được nhỏ hơn 0!");
                        txtSoLuong.Select();
                        return;
                    }

                    //Exception khi năm nhận nhỏ hơn năm đặt
                    if (pckNgayNhan.Value.Year < pckNgayDat.Value.Year)
                    {
                        throw new TimeLogicException();
                    }

                    //Exception nếu năm nhận bằng nhau mà tháng nhận lại nhỏ hơn tháng đặt
                    else
                    if ((pckNgayNhan.Value.Year == pckNgayDat.Value.Year) && (pckNgayNhan.Value.Month < pckNgayDat.Value.Month))
                    {
                        throw new TimeLogicException();
                    }

                    //Exception nếu năm tháng nhận bằng nhau mà ngày nhận lại nhỏ hơn ngày đặt
                    else
                    if ((pckNgayDat.Value.Year == pckNgayNhan.Value.Year) && (pckNgayDat.Value.Month == pckNgayNhan.Value.Month) &&
                        (pckNgayDat.Value.Day > pckNgayNhan.Value.Day))
                    {
                        throw new TimeLogicException();
                    }

                    //Exception khi sai định dạng
                    if (float.Parse(txtSoLuong.Text) < 0)
                    {
                        throw new FormatException();
                    }

                    string        s  = "SELECT MaMatH FROM tblDatHangCT WHERE MaPhieu='" + txtMaPhieu.Text + "'";
                    SqlDataReader dr = DataConn.ThucHienReader(s);
                    if (dr != null)
                    {
                        while (dr.Read())
                        {
                            if (dr.GetString(0) == values)
                            {
                                dr.Close();
                                dr.Dispose();
                                throw new SameKeyException();
                            }
                        }
                    }
                    dr.Close();
                    dr.Dispose();


                    //Thêm vào bảng chi tiết đặt hàng
                    select = "INSERT INTO tblDatHangCT VALUES('" + txtMaPhieu.Text + "','" + values + "'," + txtSoLuong.Text + ",'" + pckNgayDat.Text + "','" + pckNgayNhan.Text + "')";
                    DataConn.ThucHienCmd(select);

                    HienThi();
                }
                catch (FormatException)
                {
                    MessageBox.Show("Bạn nhập chưa đúng định dạng của dữ liệu cần thiết! Hãy xem lại hoặc nhấn F1 để vào trợ giúp!");
                }
                catch (NotEnoughInfoException)
                {
                    MessageBox.Show("Hãy nhập các dữ liệu trước khi nhấn nút ghi!");
                }
                catch (TimeLogicException)
                {
                    MessageBox.Show("Chưa hợp lý về mặt thời gian!");
                }
                catch (SameKeyException)
                {
                    MessageBox.Show("Đã có mặt hàng này trong phiếu đặt hàng!", "Thông báo!");
                }
            }
            else
            {
                string update = "";
                try
                {
                    //Exception khi không đủ dữ liệu
                    if (cboMatHang.Text == "" && txtTenKhach.Text == "" && pckNgayDat.Text == "" && pckNgayNhan.Text == "" && txtDienThoai.Text == "" && txtMaPhieu.Text == "")
                    {
                        throw new NotEnoughInfoException();
                    }
                    if (double.Parse(txtSoLuong.Text) <= 0)
                    {
                        MessageBox.Show("Số lượng không được nhỏ hơn 0!");
                        txtSoLuong.Select();
                        return;
                    }

                    string        s  = "SELECT MaMatH FROM tblDatHangCT WHERE MaPhieu='" + txtMaPhieu.Text + "'";
                    SqlDataReader dr = DataConn.ThucHienReader(s);
                    if (dr != null)
                    {
                        while (dr.Read())
                        {
                            if (dr.GetString(0) == values)
                            {
                                dr.Close();
                                dr.Dispose();
                                throw new SameKeyException();
                            }
                        }
                    }
                    dr.Close();
                    dr.Dispose();
                    //Sửa

                    update = "UPDATE tblDatHangCT SET MaMatH='" + values + "' WHERE MaPhieu='" + txtMaPhieu.Text + "' AND MaMatH='" + txtMaH.Text + "'";
                    DataConn.ThucHienCmd(update);

                    //update = "UPDATE tblDatHangCT SET SoLuong="+txtSoLuong.Text+",NgayDat='"+pckNgayDat.Text+"',NgayNhan='"+pckNgayNhan.Text+"' WHERE MaPhieu='"+txtMaPhieu.Text+"'";
                    //DataConn.ThucHienCmd(update);

                    HienThi();
                }
                catch (NotEnoughInfoException)
                {
                    MessageBox.Show("Hãy nhập các dữ liệu trước khi nhấn nút ghi!");
                }
                catch (SameKeyException)
                {
                    update = "UPDATE tblDatHangCT SET SoLuong=" + txtSoLuong.Text + ",NgayDat='" + pckNgayDat.Text + "',NgayNhan='" + pckNgayNhan.Text + "' WHERE MaPhieu='" + txtMaPhieu.Text + "' AND MaMatH='" + values + "'";
                    DataConn.ThucHienCmd(update);

                    HienThi();
                    //MessageBox.Show("Đã có mặt hàng này trong phiếu đặt hàng!", "Thông báo!");
                }
            }
        }
        private void btnXoa_Click(object sender, EventArgs e)
        {
            try
            {
                string        select1 = "select MaMatH from tblChiTietHDN";
                SqlDataReader dr      = DataConn.ThucHienReader(select1);
                if (dr != null)
                {
                    while (dr.Read())
                    {
                        if (dr.GetString(0) == txtMaHang.Text)
                        {
                            dr.Close();
                            dr.Dispose();
                            throw new SameKeyException();
                        }
                    }
                }
                dr.Close();
                dr.Dispose();

                select1 = "select MaMatH from tblChiTietHDX";
                SqlDataReader dr1 = DataConn.ThucHienReader(select1);
                if (dr1 != null)
                {
                    while (dr1.Read())
                    {
                        if (dr1.GetString(0) == txtMaHang.Text)
                        {
                            dr1.Close();
                            dr1.Dispose();
                            throw new SameKeyException();
                        }
                    }
                }
                dr1.Close();
                dr1.Dispose();

                select1 = "select MaMatH from tblNhaCungCap";
                SqlDataReader dr2 = DataConn.ThucHienReader(select1);
                if (dr2 != null)
                {
                    while (dr2.Read())
                    {
                        if (dr2.GetString(0) == txtMaHang.Text)
                        {
                            dr2.Close();
                            dr2.Dispose();
                            throw new SameKeyException();
                        }
                    }
                }
                dr2.Close();
                dr2.Dispose();

                select1 = "select MaMatH from tblDatHangCT";
                SqlDataReader dr3 = DataConn.ThucHienReader(select1);
                if (dr3 != null)
                {
                    while (dr3.Read())
                    {
                        if (dr3.GetString(0) == txtMaHang.Text)
                        {
                            dr3.Close();
                            dr3.Dispose();
                            throw new SameKeyException();
                        }
                    }
                }
                dr3.Close();
                dr3.Dispose();

                string delete = "DELETE tblMatHang WHERE MaMatH=N'" + txtMaHang.Text + "'";
                DataConn.ThucHienCmd(delete);
                HienThi();
            }
            catch (SameKeyException)
            {
                MessageBox.Show("Có thể có hóa đơn, nhà cung cấp hoặc phiếu đặt hàng liên quan đến mặt hàng này! Bạn hãy xóa hóa đơn, nhà cung cấp hoặc phiếu đặt hàng liên quan!", "Chú ý!");
            }
        }
        private void btnGhi_Click(object sender, EventArgs e)
        {
            if (kt == true)
            {
                try
                {
                    //Exception khi không đủ dữ liệu
                    if (txtMaHang.Text == "")
                    {
                        MessageBox.Show("Hãy nhập mã hàng!", "Chú ý");
                        txtMaHang.Select();
                        return;
                    }
                    if (txtTenHang.Text == "")
                    {
                        MessageBox.Show("Hãy nhập tên hàng!", "Chú ý");
                        txtTenHang.Select();
                        return;
                    }
                    if (txtSoLuong.Text == "")
                    {
                        MessageBox.Show("Hãy nhập số lượng hàng!", "Chú ý");
                        txtSoLuong.Select();
                        return;
                    }
                    if (txtDonGia.Text == "")
                    {
                        MessageBox.Show("Hãy nhập đơn giá hàng!", "Chú ý");
                        txtDonGia.Select();
                        return;
                    }

                    if (double.Parse(txtSoLuong.Text) <= 0)
                    {
                        MessageBox.Show("Số lượng không được nhỏ hơn 0!");
                        txtSoLuong.Select();
                        return;
                    }
                    if (double.Parse(txtDonGia.Text) <= 0)
                    {
                        MessageBox.Show("Đơn giá không được nhỏ hơn 0!");
                        txtSoLuong.Select();
                        return;
                    }

                    //Exception khi trùng Mã mặt hàng (trùng khóa chính)
                    string        select1 = "select MaMatH from tblMatHang";
                    SqlDataReader dr      = DataConn.ThucHienReader(select1);
                    if (dr != null)
                    {
                        while (dr.Read())
                        {
                            //MessageBox.Show(dr.GetString(0));
                            //MessageBox.Show(txtMaHang.Text);

                            //MessageBox.Show(dr.GetString(1));
                            //MessageBox.Show(txtTenHang.Text);
                            if (dr.GetString(0) == txtMaHang.Text)
                            {
                                dr.Close();
                                dr.Dispose();
                                throw new SameKeyException();
                            }
                        }
                    }
                    dr.Close();
                    dr.Dispose();

                    select1 = "select TenMatH from tblMatHang";
                    SqlDataReader dr1 = DataConn.ThucHienReader(select1);
                    if (dr1 != null)
                    {
                        while (dr1.Read())
                        {
                            //MessageBox.Show(dr.GetString(0));
                            //MessageBox.Show(txtMaHang.Text);

                            //MessageBox.Show(dr.GetString(1));
                            //MessageBox.Show(txtTenHang.Text);
                            if (dr1.GetString(0) == txtTenHang.Text)
                            {
                                dr1.Close();
                                dr1.Dispose();
                                throw new SameKeyException();
                            }
                        }
                    }
                    dr1.Close();
                    dr1.Dispose();
                    string select = "insert into tblMatHang values(N'" + txtMaHang.Text + "',N'" + txtTenHang.Text + "'," + txtSoLuong.Text + "," + txtDonGia.Text + "," + (float.Parse(txtDonGia.Text) + 20000) + ")";
                    DataConn.ThucHienCmd(select);

                    HienThi();
                }
                catch (FormatException)
                {
                    MessageBox.Show("Không đúng định dạng cần thiết! Hãy xem trợ giúp!");
                }
                catch (SameKeyException)
                {
                    MessageBox.Show("Đã có mặt hàng với mã hoặc tên này! Hãy nhập mặt hàng khác!");
                }
                catch (NotEnoughInfoException)
                {
                    MessageBox.Show("Không có đủ dữ liệu để thêm!");
                }
            }
            else
            {
                try
                {
                    if (txtMaHang.Text == "" && txtSoLuong.Text == "" && txtDonGia.Text == "" && txtTenHang.Text == "")
                    {
                        throw new NotEnoughInfoException();
                    }
                    if (double.Parse(txtSoLuong.Text) <= 0)
                    {
                        MessageBox.Show("Số lượng không được nhỏ hơn 0!");
                        txtSoLuong.Select();
                        return;
                    }
                    if (double.Parse(txtDonGia.Text) <= 0)
                    {
                        MessageBox.Show("Đơn giá không được nhỏ hơn 0!");
                        txtSoLuong.Select();
                        return;
                    }
                    string update = "UPDATE tblMatHang SET TenMatH=N'" + txtTenHang.Text + "',SoLuong='" + txtSoLuong.Text + "',DonGia='" + txtDonGia.Text + "' WHERE MaMatH=N'" + txtMaHang.Text + "'";
                    DataConn.ThucHienCmd(update);

                    HienThi();
                }
                catch (NotEnoughInfoException)
                {
                    MessageBox.Show("Không có đủ dữ liệu để sửa!");
                }
            }
        }
Exemplo n.º 14
0
        private void btnThem_Click(object sender, EventArgs e)
        {
            try
            {
                //Thông báo khi thiếu dữ liệu
                if (txtTenDN.Text == "")
                {
                    MessageBox.Show("Nhập vào tên đăng nhập!", "Thông báo!");
                    txtTenDN.Select();
                    return;
                }
                if (txtMatKhau.Text == "")
                {
                    MessageBox.Show("Nhập vào mật khẩu!", "Thông báo!");
                    txtMatKhau.Select();
                    return;
                }
                if (txtNhacLai.Text == "")
                {
                    MessageBox.Show("Nhắc lại mật khẩu đăng nhập!", "Thông báo!");
                    txtNhacLai.Select();
                    return;
                }
                if (txtDiaChi.Text == "")
                {
                    MessageBox.Show("Nhập vào địa chỉ!", "Thông báo!");
                    txtDiaChi.Select();
                    return;
                }
                if (txtDienThoai.Text == "")
                {
                    MessageBox.Show("Nhập vào điện thoại!", "Thông báo!");
                    txtDienThoai.Select();
                    return;
                }
                if (txtMatKhau.Text != txtNhacLai.Text)
                {
                    MessageBox.Show("Mật khẩu và mật khẩu nhắc lại chưa khớp nhau!", "Chú ý!");
                    txtNhacLai.Select();
                    return;
                }
                //Exception khi trùng tên đăng nhập
                string        select = "SELECT TaiKhoan FROM tblDangNhap";
                SqlDataReader dr     = DataConn.ThucHienReader(select);
                if (dr != null)
                {
                    while (dr.Read())
                    {
                        if (dr.GetString(0) == txtTenDN.Text)
                        {
                            dr.Close();
                            dr.Dispose();
                            throw new SameKeyException();
                        }
                    }
                }
                dr.Close();
                dr.Dispose();

                string insert = "INSERT INTO tblDangNhap VALUES(N'" + txtTenDN.Text.Trim() + "',N'" + txtMatKhau.Text.Trim() + "',N'" + txtDiaChi.Text.Trim() + "',N'" + txtDienThoai.Text.Trim() + "')";
                DataConn.ThucHienCmd(insert);
                MessageBox.Show("Đã thêm " + txtTenDN.Text + " vào danh sách người dùng!");
                this.Close();
            }
            catch (SameKeyException)
            {
                MessageBox.Show("Đã có tài khoản đăng nhập với tên này!", "Thông báo!");
            }
        }
        private void btnGhi_Click(object sender, EventArgs e)
        {
            if (kt == true)//Thêm
            {
                string select = "";
                try
                {
                    //Thiếu thông tin - > báo lỗi
                    if (txtMaNV.Text == "")
                    {
                        MessageBox.Show("Hãy nhập mã nhân viên!", "Chú ý!");
                        txtMaNV.Select();
                        return;
                    }
                    if (txtTenNV.Text == "")
                    {
                        MessageBox.Show("Hãy nhập tên nhân viên!", "Chú ý!");
                        txtTenNV.Select();
                        return;
                    }
                    if (txtDiaChi.Text == "")
                    {
                        MessageBox.Show("Hãy nhập địa chỉ nhân viên!", "Chú ý!");
                        txtDiaChi.Select();
                        return;
                    }
                    //Bắt lỗi nếu trùng mã nhân viên
                    string        select1 = "select MaNhanVien from tblNhanVien";
                    SqlDataReader dr      = DataConn.ThucHienReader(select1);
                    if (dr != null)
                    {
                        while (dr.Read())
                        {
                            if (dr.GetString(0) == txtMaNV.Text)
                            {
                                dr.Close();
                                dr.Dispose();
                                throw new SameKeyException();
                            }
                        }
                    }
                    dr.Close();
                    dr.Dispose();

                    //select1 = "select TenNhanVien from tblNhanVien";
                    //SqlDataReader dr1 = DataConn.ThucHienReader(select1);
                    //if (dr1 != null)
                    //{
                    //    while (dr1.Read())
                    //    {
                    //        if (dr1.GetString(0) == txtTenNV.Text)
                    //        {
                    //            dr1.Close();
                    //            dr1.Dispose();
                    //            throw new SameKeyException();
                    //        }
                    //    }
                    //}
                    //dr1.Close();
                    //dr1.Dispose();

                    select = "insert into tblNhanVien values(N'" + txtMaNV.Text + "',N'" + txtTenNV.Text + "',N'" + txtDiaChi.Text + "',N'" + txtDienThoai.Text + "')";
                    DataConn.ThucHienCmd(select);
                    HienThi();
                }
                catch (FormatException)
                {
                    MessageBox.Show("Không đúng định dạng dữ liệu cần thiết! Bạn hãy xem lại hoặc nhấn F1 để vào trợ giúp!");
                }
                catch (NotEnoughInfoException)
                {
                    MessageBox.Show("Không có đủ dữ liệu để thêm!");
                }
                catch (SameKeyException)
                {
                    MessageBox.Show("Đã có nhân viên với mã này! Hãy nhập mã nhân viên khác!", "Thông báo!");
                }
            }
            else//Sửa
            {
                try
                {
                    if (txtMaNV.Text == "" && txtTenNV.Text == "" && txtDienThoai.Text == "" && txtDiaChi.Text == "")
                    {
                        throw new NotEnoughInfoException();
                    }
                    string update = "UPDATE tblNhanVien SET TenNhanVien=N'" + txtTenNV.Text + "',DiaChi=N'" + txtDiaChi.Text + "',DienThoai=N'" + txtDienThoai.Text + "' WHERE MaNhanVien=N'" + txtMaNV.Text + "'";
                    DataConn.ThucHienCmd(update);

                    HienThi();
                }
                catch (NotEnoughInfoException)
                {
                    MessageBox.Show("Không có đủ dữ liệu để sửa");
                }
            }
        }
Exemplo n.º 16
0
        private void btnGhi_Click(object sender, EventArgs e)
        {
            if (kt == true)
            {
                try
                {
                    //Exception khi không đủ dữ liệu để nhập
                    if (txtMaNCC.Text == "")
                    {
                        MessageBox.Show("Hãy nhập mã nhà cung cấp!", "Chú ý!");
                        txtMaNCC.Select();
                        return;
                    }
                    if (txtTenNCC.Text == "")
                    {
                        MessageBox.Show("Hãy nhập tên nhà cung cấp!", "Chú ý!");
                        txtTenNCC.Select();
                        return;
                    }
                    if (cboMatHang.Text == "")
                    {
                        MessageBox.Show("Hãy chọn mặt hàng được cung cấp!", "Chú ý!");
                        cboMatHang.Select();
                        return;
                    }

                    if (txtDienThoai.Text == "")
                    {
                        MessageBox.Show("Hãy nhập điện thoại của nhà cung cấp!", "Chú ý!");
                        txtDienThoai.Select();
                        return;
                    }
                    //Exception khi trùng mã nhà cung cấp
                    string        select1 = "select MaNCC from tblNhaCungCap";
                    SqlDataReader dr      = DataConn.ThucHienReader(select1);
                    if (dr != null)
                    {
                        while (dr.Read())
                        {
                            if (dr.GetString(0) == txtMaNCC.Text)
                            {
                                dr.Close();
                                dr.Dispose();
                                throw new SameKeyException();
                            }
                        }
                    }
                    dr.Close();
                    dr.Dispose();

                    select1 = "select TenNCC from tblNhaCungCap";
                    SqlDataReader dr1 = DataConn.ThucHienReader(select1);
                    if (dr1 != null)
                    {
                        while (dr1.Read())
                        {
                            if (dr1.GetString(0) == txtTenNCC.Text)
                            {
                                dr1.Close();
                                dr1.Dispose();
                                throw new SameKeyException();
                            }
                        }
                    }
                    dr1.Close();
                    dr1.Dispose();

                    string select = "insert into tblNhaCungCap(MaNCC,MaMatH,TenNCC,DienThoai) values('" + txtMaNCC.Text + "','" + values + "','" + txtTenNCC.Text + "','" + txtDienThoai.Text + "')";
                    DataConn.ThucHienCmd(select);
                    HienThi();
                }
                catch (FormatException)
                {
                    MessageBox.Show("Không đúng định dạng cần thiết! Hãy xem trợ giúp");
                }
                catch (SameKeyException)
                {
                    MessageBox.Show("Đã có nhà cung cấp với mã hoặc tên này! Hãy nhập mã và tên khác!");
                }
                catch (NotEnoughInfoException)
                {
                    MessageBox.Show("Hãy nhập đủ dữ liệu trước khi nhấn nút ghi!");
                }
            }
            else
            {
                try
                {
                    if (txtFax.Text == "" && txtEmail.Text == "" && txtDiaChi.Text == "" && txtDienThoai.Text == "" && cboMatHang.Text == "" && txtTenNCC.Text == "" && txtGhiChu.Text == "")
                    {
                        throw new NotEnoughInfoException();
                    }
                    string update = "UPDATE tblNhaCungCap SET TenNCC=N'" + txtTenNCC.Text + "',MaMatH=N'" + values + "',Fax=N'" + txtFax.Text + "',Email=N'" + txtEmail.Text + "',DiaChi=N'" + txtDiaChi.Text + "',DienThoai=N'" + txtDienThoai.Text + "',GhiChu=N'" + txtGhiChu.Text + "' WHERE MaNCC=N'" + txtMaNCC.Text + "'";
                    DataConn.ThucHienCmd(update);
                    HienThi();
                }
                catch (NotEnoughInfoException)
                {
                    MessageBox.Show("Không đủ dữ liệu để sửa!");
                }
            }
        }
Exemplo n.º 17
0
        private void btnDatHang_Click(object sender, EventArgs e)
        {
            try
            {
                if (txtMaPhieu.Text == "")
                {
                    MessageBox.Show("Hãy nhập mã phiếu đặt hàng!", "Chú ý!");
                    txtMaPhieu.Select();
                    return;
                }
                if (txtTenKhach.Text == "")
                {
                    MessageBox.Show("Hãy nhập tên khách hàng!", "Chú ý!");
                    txtTenKhach.Select();
                    return;
                }
                if (txtDienThoai.Text == "")
                {
                    MessageBox.Show("Hãy nhập điện thoại liên hệ của khách hàng!", "Chú ý!");
                    txtDienThoai.Select();
                    return;
                }
                string        s  = "SELECT MaPhieu FROM tblDatHang";
                SqlDataReader dr = DataConn.ThucHienReader(s);
                if (dr != null)
                {
                    while (dr.Read())
                    {
                        if (dr.GetString(0) == txtMaPhieu.Text)
                        {
                            dr.Close();
                            dr.Dispose();
                            throw new SameKeyException();
                        }
                    }
                }
                dr.Close();
                dr.Dispose();
                string select = "INSERT INTO tblDatHang(MaPhieu,TenKhachH,DienThoai,GhiChu) VALUES(N'" + txtMaPhieu.Text + "',N'" + txtTenKhach.Text + "','" + txtDienThoai.Text + "',N'" + txtGhiChu.Text + "')";
                DataConn.ThucHienCmd(select);
                groupDatHangCT.Enabled = true;
                btnThem_Click(sender, e);
                cboMatHang.Select();
            }
            catch (SameKeyException)
            {
                MessageBox.Show("Đã có mã phiếu này! Hãy nhập mã phiếu khác!");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }

            //kt = true;
            //btnDatHang.Enabled = false;
            //btnGhi.Enabled = true;
            //btnHoan.Enabled = true;
            //btnSua.Enabled = false;
            //btnThoat.Enabled = true;
            //btnXoa.Enabled = false;
            //btnInPhieu.Enabled = false;

            //txtMaPhieu.ReadOnly = false;
            //txtDienThoai.ReadOnly = false;
            //txtGhiChu.ReadOnly = false;
            //txtSoLuong.ReadOnly = false;
            //txtTenKhach.ReadOnly = false;
            //cboMatHang.Enabled = true;
            //pckNgayDat.Enabled = true;
            //pckNgayNhan.Enabled = true;

            //txtDienThoai.Text = "";
            //txtGhiChu.Text = "";
            //txtSoLuong.Text = "";
            //txtTenKhach.Text = "";
            //cboMatHang.Text = "";
            //txtMaPhieu.Text = "";
            //pckNgayDat.Text = DateTime.Today.TimeOfDay.ToString();
            //pckNgayNhan.Text = DateTime.Today.TimeOfDay.ToString();
            //txtMaPhieu.Select();
        }