private void khDatCho_themYeuCauBtn_Click(object sender, EventArgs e)
        {
            LuaChon tangSelected     = (LuaChon)khDatChoTangcomboBox.SelectedValue;
            LuaChon hangSelected     = (LuaChon)khDatChoHangcomboBox.SelectedValue;
            LuaChon hinhThucSelected = (LuaChon)khDatChoHinhThuccomboBox.SelectedValue;

            int soPhong = Convert.ToInt32(khDatChoSoPhongNBR.Value);
            //string ngayBatDau = khDatCho_NBD.Value.ToString("yyyy/MM/dd HH:mm");
            //string ngayKetThuc = khDatCho_NKT.Value.ToString("yyyy/MM/dd HH:mm");
            DateTime ngayBatDau  = khDatCho_NBD.Value;
            DateTime ngayKetThuc = khDatCho_NKT.Value;

            if ((KhachHangForm.ngayBatDau - ngayBatDau).TotalMinutes > 0 || (ngayKetThuc - KhachHangForm.ngayKetThuc).TotalMinutes > 0)
            {
                MessageBox.Show("Vui lòng đặt chỗ trong quãng thời gian của giao dịch.");
                return;
            }
            if (soPhong == 0)
            {
                MessageBox.Show("Vui lòng nhập số phòng.");
                return;
            }

            yeuCauTraCuu.Rows.Add(tangSelected.giaTri, hangSelected.giaTri, hinhThucSelected.giaTri, soPhong, ngayBatDau, ngayKetThuc, hinhThucSelected.soNguoi);

            yeuCauDatChodataGridView.DataSource = yeuCauTraCuu;
            yeuCauDatChodataGridView.ReadOnly   = true;

            soNguoiThemMoi = soNguoiThemMoi + hinhThucSelected.soNguoi * soPhong;
            Console.WriteLine(soNguoiThemMoi);
        }
        public List <LuaChon> getListTuyChonTang()
        {
            List <LuaChon> rs = new List <LuaChon>();

            try
            {
                //Tuy Chon Tang
                // sp_MaxOfTang
                // @Max INT OUT
                SqlCommand cmd = new SqlCommand("sp_MaxOfTang", Program.conn);

                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.Add("@Max", SqlDbType.Int).Direction = ParameterDirection.Output;
                cmd.ExecuteNonQuery();

                int tang = Convert.ToInt32(cmd.Parameters["@Max"].Value);

                for (int i = 1; i <= tang; i++)
                {
                    LuaChon lc = new LuaChon(i, i.ToString());
                    rs.Add(lc);
                }
                cmd.Dispose();
                return(rs);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                return(rs);
            }
        }
        void loadCategoryBoiThuong()
        {
            List <LuaChon> rs = new List <LuaChon>();

            try
            {
                //Tuy Chon Tang
                // sp_CategoryBoiThuong
                DataTable  table = new DataTable();
                SqlCommand cmd   = new SqlCommand("sp_CategoryBoiThuong", Program.conn);

                cmd.CommandType = CommandType.StoredProcedure;
                table.Load(cmd.ExecuteReader());

                foreach (DataRow row in table.Rows)
                {
                    LuaChon lc = new LuaChon((int)row[0], row[1].ToString());
                    rs.Add(lc);
                }

                // Gan gia tri cho comboBox
                var bindingSource = new BindingSource();

                bindingSource.DataSource = rs;
                thanhtoanBoiThuongCategory.DataSource    = bindingSource.DataSource;
                thanhtoanBoiThuongCategory.DisplayMember = "moTa";
                cmd.Dispose();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
        public List <LuaChon> getListTuyChonHinhThuc()
        {
            List <LuaChon> rs = new List <LuaChon>();

            try
            {
                //Tuy Chon Tang
                // sp_CategoryHinhThuc
                DataTable  table = new DataTable();
                SqlCommand cmd   = new SqlCommand("sp_CategoryHinhThuc", Program.conn);

                cmd.CommandType = CommandType.StoredProcedure;

                table.Load(cmd.ExecuteReader());

                foreach (DataRow row in table.Rows)
                {
                    int     id   = Convert.ToInt32(row[0].ToString());
                    string  moTa = id.ToString() + " - " + row[1].ToString() + " - " + row[2].ToString() + " người/phòng";
                    LuaChon lc   = new LuaChon(id, moTa);
                    lc.soNguoi = Convert.ToInt32(row[2].ToString());
                    rs.Add(lc);
                }

                cmd.Dispose();
                return(rs);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                return(rs);
            }
        }
        private void thanhtoanBoiThuongPhongComboBox_SelectedIndexChanged(object sender, EventArgs e)
        {
            LuaChon selected = (LuaChon)thanhtoanBoiThuongPhongComboBox.SelectedItem;

            current = selected.giaTri;
            loadBoiThuongList();
        }
        void loadPhongComboBox()
        {
            List <LuaChon> rs = new List <LuaChon>();

            try
            {
                //Tuy Chon Tang
                // sp_ChiTietTheoGiaoDich
                // @Id INT
                DataTable  table = new DataTable();
                SqlCommand cmd   = new SqlCommand("sp_ChiTietTheoGiaoDich", Program.conn);

                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.Add("@IdGiaoDich", SqlDbType.Int).Value = gdThanhToanController.id;
                table.Load(cmd.ExecuteReader());

                foreach (DataRow row in table.Rows)
                {
                    LuaChon lc = new LuaChon((int)row[0], row[4].ToString());
                    rs.Add(lc);
                }

                // Gan gia tri cho comboBox
                var bindingSource = new BindingSource();

                bindingSource.DataSource = rs;
                thanhtoanBoiThuongPhongComboBox.DataSource    = bindingSource.DataSource;
                thanhtoanBoiThuongPhongComboBox.DisplayMember = "moTa";
                cmd.Dispose();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
Exemple #7
0
        private void khTraCuu_timkiem_Click(object sender, EventArgs e)
        {
            LuaChon tangSelected     = (LuaChon)khTangcomboBox.SelectedValue;
            LuaChon hangSelected     = (LuaChon)khHangcomboBox.SelectedValue;
            LuaChon hinhThucSelected = (LuaChon)khHinhThuccomboBox.SelectedValue;

            // Stored Procedure
            // sp_TimKiemGiaPhong
            // @Tang INT
            // @HangPhong INT
            // @HinhThuc INT
            try
            {
                DataTable  table = new DataTable();
                SqlCommand cmd   = new SqlCommand("sp_TimKiemGiaPhong", Program.conn);

                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.Add("@Tang", SqlDbType.Int).Value      = tangSelected.giaTri;
                cmd.Parameters.Add("@HangPhong", SqlDbType.Int).Value = hangSelected.giaTri;
                cmd.Parameters.Add("@HinhThuc", SqlDbType.Int).Value  = hinhThucSelected.giaTri;

                table.Load(cmd.ExecuteReader());

                tracuuphongGridView.DataSource = table;
                tracuuphongGridView.ReadOnly   = true;

                cmd.Dispose();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
        private void loadPhongCombox()
        {
            try
            {
                PhongList = new List <LuaChon>();

                foreach (DataRow row in kqTraCuu.Rows)
                {
                    LuaChon lc = new LuaChon((int)row[0], row[0].ToString());
                    lc.soNguoi = (int)row[6];
                    lc.current = 0;

                    PhongList.Add(lc);
                }

                // Gan gia tri cho comboBox
                var bindingSource = new BindingSource();

                bindingSource.DataSource    = PhongList;
                phongcomboBox.DataSource    = bindingSource.DataSource;
                phongcomboBox.DisplayMember = "moTa";
            } catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                // Stored Procedure
                // sp_ThemBoiThuong
                // @ID_CTGD INT
                // @ID_BoiThuong INT
                // @KetQua INT OUT
                DataTable  table = new DataTable();
                SqlCommand cmd   = new SqlCommand("sp_ThemBoiThuong", Program.conn);

                LuaChon boithuongSelected = (LuaChon)thanhtoanBoiThuongCategory.SelectedItem;
                Console.WriteLine(boithuongSelected.giaTri);
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.Add("@ID_CTGD", SqlDbType.Int).Value     = current;
                cmd.Parameters.Add("ID_BoiThuong", SqlDbType.Int).Value = boithuongSelected.giaTri;
                cmd.Parameters.Add("@KetQua", SqlDbType.Int).Direction  = ParameterDirection.Output;

                cmd.ExecuteNonQuery();

                int rs = (int)cmd.Parameters["@KetQua"].Value;
                //- 1 : Bồi thường không tồn tại

                //****THÊM BỒI THƯỜNG ****
                //--Input:	ID của chi tiết giao dịch cần thêm bồi thường,
                //--ID của bồi thường
                //0 : Chi tiết giao dịch không tồn tại
                //- 1 : Bồi thường không tồn tại
                //- 2 : Xảy ra lỗi khi thêm bồi thường
                //1 : Thêm bồi thường thành công

                if (rs == 0)
                {
                    MessageBox.Show("Chi tiết giao dịch không tồn tại");
                    loadPhongComboBox();
                }
                else if (rs == -1)
                {
                    MessageBox.Show("Bồi thường không tồn tại");
                    loadCategoryBoiThuong();
                }
                else if (rs == -2)
                {
                    MessageBox.Show("Xảy ra lỗi trong khi thêm bồi thường");
                }
                else
                {
                    loadBoiThuongList();
                }
                cmd.Dispose();
            } catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
        private void themKhachHangBtn_Click(object sender, EventArgs e)
        {
            try
            {
                LuaChon phongSelected = (LuaChon)phongcomboBox.SelectedItem;

                if (phongSelected.soNguoi == phongSelected.current)
                {
                    MessageBox.Show("Phòng đã đạt tối đa người.");
                    return;
                }
                string cmnd  = cmndTextBox.Text;
                string hoTen = hoTenKhachTextBox.Text;

                foreach (ChiTietGiaoDich ctgd in thongtin)
                {
                    if (ctgd.phong == phongSelected.giaTri)
                    {
                        foreach (string _cmnd in ctgd.cmnd)
                        {
                            if (_cmnd == cmnd)
                            {
                                MessageBox.Show("Khách hàng đã tồn tại.Kiểm tra lại thông tin CMND/Căn cước.");
                                return;
                            }
                        }
                        ctgd.hoTen.Add(hoTen);
                        ctgd.cmnd.Add(cmnd);
                        foreach (LuaChon lc in PhongList)
                        {
                            if (lc.giaTri == phongSelected.giaTri)
                            {
                                lc.current++;
                                reloadPhongComboBox();
                                break;
                            }
                        }
                        listThongTinKhach.Rows.Add(phongSelected.giaTri, hoTen, cmnd);
                        thongTinKhachdataGridView.DataSource = listThongTinKhach;
                        thongTinKhachdataGridView.ReadOnly   = true;
                        break;
                    }
                }
            } catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
        private void button2_Click(object sender, EventArgs e)
        {
            int id = (int)thanhtoanBoiThuongGridView.CurrentRow.Cells[0].Value;

            // sp_XoaBoiThuongChiTietGiaoDich
            // @Id INT
            // @Result INT OUT

            try
            {
                SqlCommand cmd = new SqlCommand("sp_XoaBoiThuongChiTietGiaoDich", Program.conn);

                LuaChon boithuongSelected = (LuaChon)thanhtoanBoiThuongPhongComboBox.SelectedItem;

                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.Add("@Id", SqlDbType.Int).Value         = id;
                cmd.Parameters.Add("@Result", SqlDbType.Int).Direction = ParameterDirection.Output;

                cmd.ExecuteNonQuery();

                int rs = (int)cmd.Parameters["@Result"].Value;
                if (rs == -1)
                {
                    MessageBox.Show("Xảy ra lỗi trong lúc xóa.");
                }
                else if (rs == 0)
                {
                    MessageBox.Show("Bồi thường không tồn tại.");
                    loadBoiThuongList();
                }
                else
                {
                    loadBoiThuongList();
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }