Exemplo n.º 1
0
        public static NhanVienADO Tim(int ma)
        {
            string sql = @"EXEC SP_TIMNHANVIEN '" + ma + "' ";
            var    t   = XuLyDuLieu.DocDuLieu(sql);

            if (t.Rows.Count == 0)
            {
                return(null);                  //k tim thay
            }
            else
            {
                return(new NhanVienADO(
                           int.Parse(t.Rows[0]["IDNV"].ToString()),
                           t.Rows[0]["TENNV"].ToString(),
                           DateTime.Parse(t.Rows[0]["NgaySinh"].ToString()),
                           //bool.Parse( t.Rows[0]["GioiTinh"].ToString()),
                           t.Rows[0]["NoiTamTru"].ToString(),
                           t.Rows[0]["SDT"].ToString(),
                           t.Rows[0]["QueQuan"].ToString(),
                           t.Rows[0]["TenDN"].ToString(),
                           t.Rows[0]["MatKhau"].ToString(),
                           t.Rows[0]["IDChucVu"].ToString()
                           ));
            }
        }
 private void btnDeMo_Click(object sender, EventArgs e)
 {
     if (mtrTH1_LOI.Checked)
     {
         var data = XuLyDuLieu.DocDuLieu("EXEC SP_DSLOAI_TH1");
         grvDSLoaiDU.DataSource = data;
     }
     // grvDSLoaiDU.DataSource = XuLyDuLieu.DocDuLieu("EXEC SP_DSLOAI_TH1");
     if (mtrTH1_SuaLoi.Checked)
     {
         grvDSLoaiDU.DataSource = XuLyDuLieu.DocDuLieu("EXEC SP_DSLOAI_XULY_TH1");
     }
     if (mtrTH2_LOI.Checked)
     {
         var data = XuLyDuLieu.DocDuLieu("EXEC SP_READLOAI_TH2");
         grvDSLoaiDU.DataSource = data;
     }
     if (mtrTH2_SuaLoi.Checked)
     {
         var data = XuLyDuLieu.DocDuLieu("EXEC SP_XULY_TH2");
         grvDSLoaiDU.DataSource = data;
     }
     if (mtrTH3_LOI.Checked)
     {
         var data = XuLyDuLieu.DocDuLieu("EXEC SP_READLOAI_TH3");
         grvDSLoaiDU.DataSource = data;
     }
     if (mtrTH3_SuaLoi.Checked)
     {
         var data = XuLyDuLieu.DocDuLieu("EXEC SP_XULY_TH3");
         grvDSLoaiDU.DataSource = data;
     }
 }
Exemplo n.º 3
0
        //Them nhan vien
        public static bool Them(NhanVienADO o)
        {
            #region cau truy van
            string sql = @"P_INSERTNHANVIEN";
            #endregion
            var kq = XuLyDuLieu.ThucThiThemXoaSua(sql
                                                  , "@TenNV", o.TenNV
                                                  , "@NgaySinh", o.NgaySinh
                                                  , "@NoiTamTru", o.NoiTamTru
                                                  , "@SDT", o.SDT
                                                  , "@QueQuan", o.QueQuan
                                                  , "@TenDN", o.TenDN
                                                  , "@MatKhau", o.MatKhau
                                                  , "@TenDN", o.TenDN
                                                  , "IDChucVu", o.IDChucVu

                                                  );
            if (kq == null)
            {
                return(false);
            }
            else
            {
                return(true);
            }
        }
Exemplo n.º 4
0
        public static bool Xoa(int id)
        {
            #region cau truy van
            var kq = Tim(id);

            if (kq == null)
            {
                return(false);           //ko co gi de xoa.
            }
            int gt = XuLyDuLieu.ThucThiThemXoaSua("SP_DELETENHANVIEN'" + id + "'");
            return(gt > 0);

            #endregion
        }
Exemplo n.º 5
0
        public static bool Sua(NhanVienADO o)
        {
            #region cau truy van
            var kq = Tim(o.IDNV);

            if (kq == null)
            {
                return(false);           //ko co gi de xoa.
            }
            int gt = XuLyDuLieu.ThucThiThemXoaSua("P_UPDATENHANVIEN '" + o.IDNV + "', '"
                                                  + o.TenNV + "','" + o.NgaySinh + "','" + true + "','" + o.NoiTamTru + "','" + o.SDT + "','"
                                                  + o.QueQuan + "','" + o.TenDN + "','" + o.MatKhau + "', '" + o.IDChucVu + "' ");
            return(gt > 0);

            #endregion
        }
        private void btnThemNV_Click(object sender, EventArgs e)
        {
            try
            {
                //using (var k = new AppCode.QuanCafe())
                //{
                var o = new NhanVienADO()
                {
                    IDNV      = 0,
                    TenNV     = txtTenNV.Text,
                    NgaySinh  = dtPk.Value,
                    NoiTamTru = txtNoiTamTru.Text,
                    SDT       = txtSDT.Text,
                    QueQuan   = txtQueQuan.Text,
                    TenDN     = txtTenDNNV.Text,
                    MatKhau   = txtMatKhauNV.Text,
                    IDChucVu  = cbbChucVu.SelectedValue.ToString()
                };

                string sql = @"P_INSERTNHANVIEN '" + o.TenNV + "','" + o.NgaySinh + "',true,'" + o.NoiTamTru + "','" + o.SDT + "','" + o.QueQuan + "','" + o.TenDN + "','" + o.MatKhau + "','" + o.IDChucVu + "' ";
                #endregion
                var kq = XuLyDuLieu.ThucThiThemXoaSua(sql);
                //  var kq = NhanVienADO.Them(o);
                if (kq != 1)
                {
                    MessageBox.Show("Thêm thất bại", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    ;
                    return;
                }
                else
                {
                    LoadDanhSachNhanVien();
                    MessageBox.Show("Thêm thành công", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }
                // }
            }
            catch
            {
                return;
            }
        }
        private void btnHuyBan_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("Bạn muốn hủy bàn này?", "Thông báo", MessageBoxButtons.OKCancel, MessageBoxIcon.Asterisk) != System.Windows.Forms.DialogResult.Cancel)
            {
                var kqtimban = XuLyDuLieu.DocDuLieu("EXEC SP_TimBan '" + AppCode.STBan.idBan + "' ");
                var tenban   = kqtimban.Rows[0]["TenBan"].ToString();
                int idban    = AppCode.STBan.idBan;
                XuLyDuLieu.ThucThiThemXoaSua("SP_UPDATE_BAN '" + idban + "','" + tenban + "',Trống");

                try
                {
                    using (var k = new AppCode.QuanCafe())
                    {
                        var timhd = k.TimHoaDon(AppCode.STHoaDon.idHoaDon);

                        timhd.TrangThai = true;
                        timhd.GiamGia   = TinhTien.giamgia;
                        //MessageBox.Show(timhd.GiamGia.ToString());
                        k.SuaHD(timhd);
                        var timban = k.TimBan(AppCode.STBan.idBan);
                        //cap nhat
                        timban.TrangThai = "Trống";
                        k.CapNhatBan(timban);
                        txtGiamGia.Text  = "0";
                        txtTamTinh.Text  = "0";
                        txtTongTien.Text = "0";

                        lblTenBan.Text          = "";
                        grvCTBanTest.DataSource = null;
                    }
                }
                catch
                {
                }


                flpDSBan.Controls.Clear();
                LoadDSBan();
            }
        }
        private void btnLogin_Click(object sender, EventArgs e)
        {
            try
            {
                string sql = @"EXEC SP_TimTaiKkhoan '" + txtTenDN.Text + "' ";
                var    t   = XuLyDuLieu.DocDuLieu(sql);

                if (t.Rows.Count == 0)
                {
                    MessageBox.Show("Mật khẩu hoặc tên đăng nhập chưa đúng", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }

                else

                {
                    if (t.Rows.Count == 0 || t.Rows[0]["MatKhau"].ToString() != txtMatKhau.Text)
                    {
                        MessageBox.Show("Mật khẩu hoặc tên đăng nhập chưa đúng", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);

                        return;
                    }
                    else
                    {
                        AppCode.STNhanVien.idNhanVien  = int.Parse(t.Rows[0]["IDNV"].ToString());
                        AppCode.STNhanVien.IDChucVu    = (t.Rows[0]["IDChucVu"].ToString());
                        AppCode.STNhanVien.TenNhanVien = t.Rows[0]["TENNV"].ToString();

                        fManager f = new fManager();
                        this.Hide();
                        f.ShowDialog();
                        this.Show();
                    }
                }
            }
            catch
            {
            }
        }
        private void btnSuaNV_Click(object sender, EventArgs e)
        {
            try
            {
                var o = new NhanVienADO()
                {
                    IDNV      = int.Parse(txt2MaNV.Text),
                    TenNV     = txtTenNV.Text,
                    NgaySinh  = dtPk.Value,
                    NoiTamTru = txtNoiTamTru.Text,
                    SDT       = txtSDT.Text,
                    QueQuan   = txtQueQuan.Text,
                    TenDN     = txtTenDNNV.Text,
                    MatKhau   = txtMatKhauNV.Text,
                    IDChucVu  = cbbChucVu.SelectedValue.ToString()
                };

                int gt = XuLyDuLieu.ThucThiThemXoaSua("P_UPDATENHANVIEN '" + o.IDNV + "', '" + o.TenNV + "','" + o.NgaySinh + "','" + true + "','" + o.NoiTamTru + "','" + o.SDT + "','" + o.QueQuan + "','" + o.TenDN + "','" + o.MatKhau + "', '" + o.IDChucVu + "' ");

                var kq = NhanVienADO.Sua(o);
                if (kq == false)
                {
                    MessageBox.Show("Sủa  thất bại", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }
                else
                {
                    LoadDanhSachNhanVien();
                    MessageBox.Show("Sửa thành công", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }
            }
            catch
            {
            }
        }
        private void btnThemMon_Click_1(object sender, EventArgs e)
        {
            try
            {
                using (var k = new AppCode.QuanCafe())
                {
                    //Kiem tra trang thai ban
                    var kqtimban = k.TimBan(AppCode.STBan.idBan);
                    if (kqtimban.TrangThai == "Trống")
                    {
                        if (MessageBox.Show("Bạn muốn mỡ bàn này?", "Thông báo", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.OK)
                        {
                            var o = new Ban()
                            {
                                IDBan     = kqtimban.IDBan,
                                TenBan    = kqtimban.TenBan,
                                TrangThai = "Có người"
                            };
                            //cap nhat trang thai ban
                            k.CapNhatBan(o);
                            flpDSBan.Controls.Clear();
                            LoadDSBan();
                        }
                        else
                        {
                            return;
                        }
                    }



                    int rowSelected = grvDSDoUongF.CurrentRow.Index;
                    // dataGridView.Rows[rowSelected].Cells[i].Value;
                    var hd = k.TimHoaDonTheoIDBan(AppCode.STBan.idBan);
                    //Ban chua co hoa don
                    if (hd == null)
                    {
                        MessageBox.Show("dat tao hd");

                        hd = new HoaDon()
                        {
                            TrangThai     = false,
                            NgayLap       = DateTime.Now,
                            IDNhanVienLap = AppCode.STNhanVien.idNhanVien,
                            IDBan         = AppCode.STBan.idBan,
                        };


                        //var hd = new HoaDonADO(
                        //    0,
                        //    AppCode.STBan.idBan,
                        //    DateTime.Now,
                        //    AppCode.STNhanVien.idNhanVien,
                        //   false
                        //);

                        var kq1 = k.ThemHoaDon(hd);
                        AppCode.STHoaDon.idHoaDon = hd.IDHoaDon;
                    }


                    if (hd != null)
                    {
                        var cthd = new CTHoaDonADO()
                        {
                            IDHoaDon = hd.IDHoaDon,
                            IDDoUong = k.TimDoUongTheoTen(grvDSDoUongF.Rows[rowSelected].Cells[0].Value.ToString()).IDDoUong,
                            SoLuong  = int.Parse(nudSoLuong.Value.ToString()),
                            GiaGoc   = k.TimDoUongTheoTen(grvDSDoUongF.Rows[rowSelected].Cells[0].Value.ToString()).GiaGoc,
                            GiaBan   = double.Parse(grvDSDoUongF.Rows[rowSelected].Cells[3].Value.ToString())
                        };


                        string sql = @"SP_GOIMON '" + cthd.IDHoaDon + "', '" + cthd.IDDoUong + "','" + cthd.SoLuong + "','" + cthd.GiaGoc + "','" + cthd.GiaBan + "' ";
                        var    gt  = XuLyDuLieu.ThucThiThemXoaSua(sql);
                        MessageBox.Show(gt.ToString());
                        LoadDSCTHD(hd.IDHoaDon);
                        LoadTongTien();
                        LoadDSDoUong();
                    }
                }
            }
            catch
            {
                return;
            }
        }
        private void btnSuaLoai_Click(object sender, EventArgs e)
        {
            var o = new LoaiDoUong()
            {
                IDLoai  = Convert.ToInt32(txtMaLoai.Text),
                TenLoai = txtTenLoai.Text
            };

            try
            {
                if (mtrTH1_LOI.Checked)
                {
                    int kq = XuLyDuLieu.ThucThiThemXoaSua("SP_UPDAELOAI_TH1 '" + o.IDLoai + "', '" + o.TenLoai + "' ");
                    LoadDSLoai();

                    MessageBox.Show("cap nhat thất bại", "Thông báo", MessageBoxButtons.OKCancel, MessageBoxIcon.Information);
                }
                //DEMO TH1
                // int kq = XuLyDuLieu.ThucThiThemXoaSua("SP_UPDAELOAI_TH1 '" + o.IDLoai + "', '" + o.TenLoai + "' ");
                if (mtrTH1_SuaLoi.Checked)
                {
                    int kq = XuLyDuLieu.ThucThiThemXoaSua("SP_UPDAELOAI_TH1 '" + o.IDLoai + "', '" + o.TenLoai + "' ");
                    LoadDSLoai();

                    MessageBox.Show("cap nhat thất bại", "Thông báo", MessageBoxButtons.OKCancel, MessageBoxIcon.Information);
                }
                if (mtrTH2_LOI.Checked)
                {
                    int kq = XuLyDuLieu.ThucThiThemXoaSua("SP_WRITELOAI_TH2 '" + o.IDLoai + "', '" + o.TenLoai + "' ");
                    if (kq != 0)
                    {
                        LoadDSLoai();

                        MessageBox.Show("Update thanh cong", "Thông báo", MessageBoxButtons.OKCancel, MessageBoxIcon.Information);
                    }
                }
                if (mtrTH2_SuaLoi.Checked)
                {
                    int kq = XuLyDuLieu.ThucThiThemXoaSua("SP_WRITELOAI_TH2 '" + o.IDLoai + "', '" + o.TenLoai + "' ");
                    if (kq != 0)
                    {
                        LoadDSLoai();

                        MessageBox.Show("Update thanh cong", "Thông báo", MessageBoxButtons.OKCancel, MessageBoxIcon.Information);
                    }
                    //LoadDSLoai();
                }

                if (mtrTH4_Loi.Checked)
                {
                    XuLyDuLieu.ThucThiThemXoaSua("SP_TH4_XULY_T1 '" + int.Parse(txtMaLoai.Text) + "', '" + txtTenLoai.Text + "' ");
                    MessageBox.Show("Update thanh cong", "Thông báo", MessageBoxButtons.OKCancel, MessageBoxIcon.Information);
                    LoadDSLoai();
                }
                if (mtrTH4_Loi2_T2.Checked)
                {
                    var kq = XuLyDuLieu.ThucThiThemXoaSua("SP_TH4_XULY_T2 '" + int.Parse(txtMaLoai.Text) + "', '" + txtTenLoai.Text + "' ");
                    if (kq == 0)
                    {
                        MessageBox.Show("Update that bai", "Thông báo", MessageBoxButtons.OKCancel, MessageBoxIcon.Information);

                        return;
                    }
                    MessageBox.Show("Update thanh cong", "Thông báo", MessageBoxButtons.OKCancel, MessageBoxIcon.Information);
                    LoadDSLoai();
                }

                //DEMO TH2
                // int kq = XuLyDuLieu.ThucThiThemXoaSua("SP_WRITELOAI_TH2 '" + o.IDLoai + "', '" + o.TenLoai + "' ");
            }
            catch
            {
            }
        }
        private void btnThemLoai_Click(object sender, EventArgs e)
        {
            try
            {
                //demo loi bong ma
                if (mtrTH3_LOI.Checked)
                {
                    int kq = XuLyDuLieu.ThucThiThemXoaSua("SP_WRITELOAI_TH3 '" + txtTenLoai.Text + "'");
                    if (kq != 0)
                    {
                        MessageBox.Show("Thêm tành công", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        LoadDSDoUong();
                        return;
                    }
                    else
                    {
                        MessageBox.Show("Thêm that bai", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);

                        return;
                    }
                }

                if (mtrTH3_SuaLoi.Checked)
                {
                    int kq = XuLyDuLieu.ThucThiThemXoaSua("SP_WRITELOAI_TH3 '" + txtTenLoai.Text + "'");
                    if (kq != 0)
                    {
                        MessageBox.Show("Thêm tành công", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        LoadDSDoUong();
                        return;
                    }
                    else
                    {
                        MessageBox.Show("Thêm that bai", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);

                        return;
                    }
                }

                using (var k = new AppCode.QuanCafe())
                {
                    var o = new LoaiDoUong()
                    {
                        // IDLoai=int.Parse(txt1MaLoai.Text),
                        TenLoai = txtTenLoai.Text,
                    };

                    var kq = k.ThemLoaiDU(o);
                    if (kq == true)
                    {
                        LoadDSLoai();
                        MessageBox.Show("Thêm thành công", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        return;
                    }
                    else
                    {
                        MessageBox.Show("Thêm thất bại", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        return;
                    }
                }
            }
            catch
            {
                return;
            }
        }
 private void btnXemDSLoai_Click(object sender, EventArgs e)
 {
     grvDSLoaiDU.DataSource = XuLyDuLieu.DocDuLieu("EXEC SP_DSLOAI_VIEW");
 }