Exemple #1
0
        public frmThemTuyenXe(tblTuyenXe tuyenXe)
        {
            InitializeComponent();
            editMode = true;
            cbbBenXeDen.Enabled = false;
            cbbBenXeDi.Enabled = false;


            foreach (var item in new QUANLYXEKHACHEntities().tblBenXes.ToList())
            {
                cbbBenXeDen.Items.Add(item.TenBenXe);
                cbbBenXeDi.Items.Add(item.TenBenXe);
            }
            // Edit mode
            cbbBenXeDi.SelectedItem = tuyenXe.tblBenXe.TenBenXe;
            cbbBenXeDen.SelectedItem = tuyenXe.tblBenXe1.TenBenXe;
            txtMaTuyen.Text = tuyenXe.MaTuyen;

            dtgChiTietTuyen.Rows.Clear();
            QUANLYXEKHACHEntities db = new QUANLYXEKHACHEntities();
            List<tblChiTietTuyen> listChiTietTuyen = tuyenXe.tblChiTietTuyens.ToList();
            for (int i = 0; i < listChiTietTuyen.Count; i++)
            {
                DataGridViewComboBoxCell cell = (DataGridViewComboBoxCell)dtgChiTietTuyen.Rows[i].Cells["BenXeTrungGian"];
                foreach (var row in db.tblBenXes.Select(t => t.TenBenXe).ToList())
                    cell.Items.Add(row);

                cell.Value = listChiTietTuyen[i].tblBenXe.TenBenXe;
                dtgChiTietTuyen.Rows[i].Cells["ThoiGianDung"].Value = listChiTietTuyen[i].ThoiGianDung;
                dtgChiTietTuyen.Rows[i].Cells["GhiChu"].Value = listChiTietTuyen[i].GhiChu;
            } 
        }
Exemple #2
0
        public frmLichChuyenDi(tblChuyenDi chuyenDi)
        {
            InitializeComponent();
            editMode = true;
            try
            {
                QUANLYXEKHACHEntities db = new QUANLYXEKHACHEntities();
                txtMaChuyenDi.Text = chuyenDi.MaChuyenDi.ToString();
                txtGiaVe.Text = chuyenDi.DonGia.ToString();

                cbbMaTuyen.DataSource = db.tblTuyenXes.Select(t => t.MaTuyen).ToList();
                cbbMaTuyen.SelectedItem = chuyenDi.tblXeKhach.MaTuyen;
                txtTuyen.Text = chuyenDi.tblXeKhach.tblTuyenXe.tblBenXe.TenBenXe + "-" + chuyenDi.tblXeKhach.tblTuyenXe.tblBenXe1.TenBenXe;
                dtpKhoiHanh.Value = chuyenDi.KhoiHanh.Value;
                dtpKetThuc.Value = chuyenDi.KhoiHanh.Value.AddMinutes(chuyenDi.tblXeKhach.tblTuyenXe.ThoiGianDi);

                dtgBXTrungGian.Rows.Clear();
                foreach (var item in db.tblChiTietTuyens.Where(t => t.MaTuyen == chuyenDi.tblXeKhach.MaTuyen).ToList())
                {
                    dtgBXTrungGian.Rows.Add(item.tblBenXe.TenBenXe,
                                            item.ThoiGianDung,
                                            item.GhiChu);
                }

                cbbMaXe.DataSource = db.tblXeKhaches.Where(t => t.MaTuyen == chuyenDi.tblXeKhach.MaTuyen).Select(t => t.MaXe).ToList();
            }
            catch 
            { }
        }
        private void btnThem_Click(object sender, EventArgs e)
        {
            try 
            { 
                BLL_BenXe temp = new BLL_BenXe();
                if (temp.canInsert(txtMaBenXe.Text.ToString(), txtTenBenXe.Text.ToString()))
                {
                    QUANLYXEKHACHEntities db = new QUANLYXEKHACHEntities();

                    tblBenXe t = new tblBenXe();
                    t.MaBenXe = txtMaBenXe.Text.ToString();
                    t.TenBenXe = txtTenBenXe.Text.ToString();
                    db.tblBenXes.Add(t);
                    db.SaveChanges();

                    btnTaoMoi_Click(sender, e);
                    MessageBox.Show("Thêm thành công");
                }
                else 
                {
                    MessageBox.Show("Không thành công");
                }
            }
            catch { }
        }
        private void btThem_Click(object sender, EventArgs e)
        {
            tblChiTietTrungChuyen temp = new tblChiTietTrungChuyen();
            temp.MaPhieu = int.Parse(dtgKhachHang.CurrentRow.Cells["MaPhieu_KH"].Value.ToString());
            dynamic selectedItem = cbbXeTrungChuyen.SelectedItem;
            string bienSoXe = selectedItem.BienSo;
            temp.SoLuong = int.Parse(dtgKhachHang.CurrentRow.Cells["SoVe_KH"].Value.ToString());

            try
            {
                QUANLYXEKHACHEntities db = new QUANLYXEKHACHEntities();
                tblXeTrungChuyen xeTC = db.tblXeTrungChuyens.Where(t => t.BienSoXe == bienSoXe).SingleOrDefault();
                if(xeTC != null)
                {
                    temp.MaXe = xeTC.MaXe;
                    temp.DaRuoc = false;
                    db.tblChiTietTrungChuyens.Add(temp);
                    db.SaveChanges();

                    dtgDanhSachTC.Rows.Add(dtgKhachHang.CurrentRow.Cells["HoTen_KH"].Value,
                                       dtgKhachHang.CurrentRow.Cells["MaPhieu_KH"].Value,
                                       dtgKhachHang.CurrentRow.Cells["SDT_KH"].Value,
                                       dtgKhachHang.CurrentRow.Cells["DiaDiem_KH"].Value,
                                       dtgKhachHang.CurrentRow.Cells["SoVe_KH"].Value);
                    dtgKhachHang.Rows.RemoveAt(dtgKhachHang.CurrentRow.Index);    
                }    
            }
            catch
            {
                MessageBox.Show("Lỗi");
            }         
        }
Exemple #5
0
        private void cbMaChuyenDi_SelectedIndexChanged(object sender, EventArgs e)
        {
            khoiPhucTinhTrangGhe();

            QUANLYXEKHACHEntities db = new QUANLYXEKHACHEntities();
            int maChuyen = int.Parse(cbbMaChuyenDi.SelectedItem.ToString());
            tblChuyenDi chuyenDi = db.tblChuyenDis.Where(t => t.MaChuyenDi == maChuyen).SingleOrDefault();
            txtTuyen.Text = chuyenDi.tblXeKhach.tblTuyenXe.tblBenXe.TenBenXe.ToString() + "-" + chuyenDi.tblXeKhach.tblTuyenXe.tblBenXe1.TenBenXe.ToString();
            txtKhoiHanh.Text = chuyenDi.KhoiHanh.Value.ToString();
            txtGia.Text = chuyenDi.DonGia.ToString();
         
            foreach (var item in chuyenDi.tblChiTietPhieuDatChoes.ToList())
            {
                if(chuyenDi.tblXeKhach.MaLoaiXe == 1) // ghế ngồi
                {
                    if (item.LayVe.Value)
                        capNhatTinhTrangGhe(idGheThuong + item.ViTriGhe, Color.Red, pnlXeThuong);
                    else
                        capNhatTinhTrangGhe(idGheThuong + item.ViTriGhe, Color.Green, pnlXeThuong);
                }
                else
                {
                    if (item.LayVe.Value)
                        capNhatTinhTrangGhe(idGheNam + item.ViTriGhe, Color.Red, pnlGiuongNam);
                    else
                        capNhatTinhTrangGhe(idGheNam + item.ViTriGhe, Color.Green, pnlGiuongNam);
                }
            }

            tabXeThuong.Visible = tabXeGiuongNam.Visible = true;
            if (chuyenDi.tblXeKhach.MaLoaiXe == 1) // ghế ngồi
                tabXeGiuongNam.Visible = false;
            else
                tabXeThuong.Visible = false;
        }
Exemple #6
0
        private void btSua_Click(object sender, EventArgs e)
        {
            frmSuaXe form = null;
            QUANLYXEKHACHEntities db = new QUANLYXEKHACHEntities();
            if(dtgDanhSachXeKhachSelected)
            {
                int maXe = int.Parse(dtgDSXeKhach.CurrentRow.Cells["MaXe"].Value.ToString());
                tblXeKhach xe = db.tblXeKhaches.Where(t => t.MaXe == maXe).SingleOrDefault();
                if(xe != null)
                {
                    form = new frmSuaXe(xe);
                }
            }
            else
            {
                int maXe = int.Parse(dtgDSXeTrungChuyen.CurrentRow.Cells["MaXeTC"].Value.ToString());
                tblXeTrungChuyen xe = db.tblXeTrungChuyens.Where(t => t.MaXe == maXe).SingleOrDefault();
                if (xe != null)
                {
                    form = new frmSuaXe(xe);
                }
            }

            form.ShowDialog();
            frmQuanLyXe_Load(sender, e);
        }
        public frmTraCuuTrungChuyen()
        {
            InitializeComponent();

            QUANLYXEKHACHEntities db = new QUANLYXEKHACHEntities();
            cbbXeTrungChuyen.DataSource = db.tblXeTrungChuyens.Select(t => new { BienSo = t.BienSoXe, DiaDiem = t.DiaDiemTrungChuyen }).ToList();
        }
Exemple #8
0
        private void btnXoa_Click(object sender, EventArgs e)
        {
            int rowIndex = dtgChuyenDi.CurrentCell.RowIndex;
            DataGridViewRow row = dtgChuyenDi.Rows[rowIndex];

            int maChuyenDi = int.Parse(row.Cells["MaChuyenDi"].Value.ToString());
            string message = string.Format("Bạn muốn xóa chuyến đi\nBiển sô xe: {0}\nTuyến: {1}\nKhởi hành: {2}", row.Cells["BienSoXe"].Value, row.Cells["TuyenXe"].Value, row.Cells["KhoiHanh"].Value);
            DialogResult result = MessageBox.Show(message, "Thông báo", MessageBoxButtons.YesNo);
            if(result == System.Windows.Forms.DialogResult.Yes)
            {
                BLL.BLL_ChuyenDi temp = new BLL.BLL_ChuyenDi();
                if (temp.canDelete(maChuyenDi))
                {
                    QUANLYXEKHACHEntities db = new QUANLYXEKHACHEntities();

                    tblChuyenDi chuyenDi = db.tblChuyenDis.Where(t => t.MaChuyenDi == maChuyenDi).SingleOrDefault();
                    if (chuyenDi != null)
                    {
                        // Xóa báo cáo
                        tblBaoCaoDoanhThuChuyenDi bcChuyenDi = db.tblBaoCaoDoanhThuChuyenDis.Where(t => t.MaChuyenDi == chuyenDi.MaChuyenDi).SingleOrDefault();
                        if(bcChuyenDi != null)
                            db.tblBaoCaoDoanhThuChuyenDis.Remove(bcChuyenDi);

                        db.tblChuyenDis.Remove(chuyenDi);
                        db.SaveChanges();

                        MessageBox.Show("Xóa thành công");
                        frmQuanLyChuyenDi_Load(sender, e);
                    }
                }
                else
                    MessageBox.Show("Chuyến đi đã có khách hàng đặt vé hoặc mua, không thể xóa");
            }
 
        }
Exemple #9
0
        private List<tblChiTietTuyen> solveDataInputChiTietTuyen()
        {
            QUANLYXEKHACHEntities db = new QUANLYXEKHACHEntities();
            List<tblChiTietTuyen> list = new List<tblChiTietTuyen>();

            foreach (DataGridViewRow row in dtgChiTietTuyen.Rows)
            {
                if (string.IsNullOrEmpty(row.Cells[0].Value + "") && string.IsNullOrEmpty(row.Cells[1].Value + ""))
                    break;

                string MaBenXeTrungGian = "";
                string tenBenXe = row.Cells[0].Value.ToString();
                tblBenXe benXe = db.tblBenXes.Where(t => t.TenBenXe == tenBenXe).SingleOrDefault();
                if (benXe != null)
                    MaBenXeTrungGian = benXe.MaBenXe;

                tblChiTietTuyen temp = new tblChiTietTuyen();
                temp.MaBenXeTrungGiang = MaBenXeTrungGian;

                if (!string.IsNullOrEmpty(row.Cells[1].Value + ""))
                    temp.ThoiGianDung = int.Parse(row.Cells[1].Value.ToString());
                else
                    temp.ThoiGianDung = 0;
                temp.MaTuyen = txtMaTuyen.Text.ToString();
                if (row.Cells[2].Value != null)
                    temp.GhiChu = row.Cells[2].Value.ToString();
                else
                    temp.GhiChu = "";

                list.Add(temp);
            }

            return list;
        }
Exemple #10
0
        private void frmDanhSachDatVe_Load(object sender, EventArgs e)
        {
            QUANLYXEKHACHEntities db = new QUANLYXEKHACHEntities();

            cbbBenXeDen.DataSource = db.tblBenXes.Select(t => t.TenBenXe).ToList();
            cbbBenXeDi.DataSource = db.tblBenXes.Select(t => t.TenBenXe).ToList();
        }
        public bool canDelete(int maNV)
        {
            QUANLYXEKHACHEntities db = new QUANLYXEKHACHEntities();
            if (db.tblNhanViens.Where(t => t.MaNhanVien == maNV).ToArray().Length != 0)
                return true;

            return false;
        }
        public bool canUpdate(int maNV, int cmnd)
        {
            QUANLYXEKHACHEntities db = new QUANLYXEKHACHEntities();
            if (db.tblNhanViens.Where(t => t.MaNhanVien != maNV && t.CMND == cmnd).ToArray().Length != 0)
                return false;

            return true;
        }
Exemple #13
0
 private void btSua_Click(object sender, EventArgs e)
 {
     string maTuyen = dtgDanhSachTuyen.CurrentRow.Cells["MaTuyen"].Value.ToString();
     tblTuyenXe tuyenXe = new QUANLYXEKHACHEntities().tblTuyenXes.Where(t => t.MaTuyen == maTuyen).SingleOrDefault();
     frmThemTuyenXe form = new frmThemTuyenXe(tuyenXe);
     form.ShowDialog();
     frmQuanLyTuyenXe_Load(sender, e);
 }
        public bool canDelete(string maBen)
        {
            QUANLYXEKHACHEntities db = new QUANLYXEKHACHEntities();
            if (db.tblBenXes.Where(t => t.MaBenXe == maBen).ToArray().Length != 0)
                return true;

            return false;
        }
 public int getLastestIndex()
 {
     QUANLYXEKHACHEntities db = new QUANLYXEKHACHEntities();
     if (db.tblChiTietPhieuDatChoes.ToArray().Length == 0)
         return 1;
     else
         return db.tblChiTietPhieuDatChoes.Max(t => t.MaCTPhieu) + 1;
 }
Exemple #16
0
 public int getLastestIndex()
 {
     QUANLYXEKHACHEntities db = new QUANLYXEKHACHEntities();
     if (db.tblXeTrungChuyens.ToArray().Length == 0)
         return 1;
     else
         return db.tblXeTrungChuyens.Max(t => t.MaXe) + 1;
 }
        public bool canUpdate(string tenDN, string mk)
        {
            QUANLYXEKHACHEntities db = new QUANLYXEKHACHEntities();
            if (db.tblTaiKhoans.Where(t => t.TenTaiKhoan == tenDN && t.MatKhau == mk).ToArray().Length != 0)
                return false;

            return true;
        }
 private void frmDoiMatKhau_Load(object sender, EventArgs e)
 {
     int MaNV = ma;
     QUANLYXEKHACHEntities db = new QUANLYXEKHACHEntities();
     tblTaiKhoan tk = db.tblTaiKhoans.Where(t => t.MaNhanVien == MaNV).SingleOrDefault();
     txtTenNguoiDung.Text = tk.tblNhanVien.TenNhanVien.ToString();
     txtTenDangNhap.Text = tk.TenTaiKhoan.ToString();
 }
Exemple #19
0
        public bool canUpdate(int maChuyen, int? maXe)
        {
            QUANLYXEKHACHEntities db = new QUANLYXEKHACHEntities();
            if (db.tblChuyenDis.Where(t => t.MaChuyenDi == maChuyen).ToArray().Length != 0)
                return true;

            return false;
        }
Exemple #20
0
        public string validateInput(int maPhieu, string hoTen, int? dienThoai)
        {
            QUANLYXEKHACHEntities db = new QUANLYXEKHACHEntities();

            if (db.tblPhieuDatChoes.Where(t => t.DienThoai == dienThoai || t.MaPhieu == maPhieu).Count() != 0)
                return "Hành khách đã tồn tại";
            return null;
        }
Exemple #21
0
 public int  getLastestIndex()
 {
     QUANLYXEKHACHEntities db = new QUANLYXEKHACHEntities();
     if (db.tblChuyenDis.Count() == 0)
         return 1;
     else
         return db.tblChuyenDis.Max(t => t.MaChuyenDi) + 1;
 }
 private void cbMaSanBay_SelectedIndexChanged(object sender, EventArgs e)
 {
     tblBenXe benXe = new QUANLYXEKHACHEntities().tblBenXes.Where(t => t.MaBenXe == cbMaBenXe.SelectedItem.ToString()).SingleOrDefault();
     if(benXe != null)
     {
         txtTenBenXe.Text = benXe.TenBenXe;
     }
 }
        public bool canDelete(string maTuyen)
        {
            QUANLYXEKHACHEntities db = new QUANLYXEKHACHEntities();
            if (db.tblTuyenXes.Where(t => t.MaTuyen == maTuyen).SingleOrDefault() != null)
                return true;

            return false;
        }
Exemple #24
0
        public bool canDelete(int maXe)
        {
            QUANLYXEKHACHEntities db = new QUANLYXEKHACHEntities();
            tblXeTrungChuyen xeKhach = db.tblXeTrungChuyens.Where(t => t.MaXe == maXe).SingleOrDefault();
            if (xeKhach != null)
                return true;

            return false;
        }
Exemple #25
0
        public bool canUpdate(int maXe, string bienSoXe)
        {
            QUANLYXEKHACHEntities db = new QUANLYXEKHACHEntities();
            tblXeTrungChuyen xe = db.tblXeTrungChuyens.Where(t => t.MaXe != maXe && t.BienSoXe == bienSoXe).SingleOrDefault();
            if (xe != null)
                return false;

            return true;
        }
        private void btnSua_Click(object sender, EventArgs e)
        {
            QUANLYXEKHACHEntities db = new QUANLYXEKHACHEntities();

            if(tabXeKhach.Visible)
            {
                int maXe = int.Parse(txtMaXeKhach.Text.ToString());

                tblXeKhach xeKhach = db.tblXeKhaches.Where(t=>t.MaXe == maXe).SingleOrDefault();
                xeKhach.SoGhe = int.Parse(txtSoGhe.Text.ToString());
                xeKhach.MaLoaiXe = db.tblLoaiXes.Where(t => t.TenLoaiXe == cbbLoaiXe.SelectedItem.ToString()).SingleOrDefault().MaLoaiXe;
                xeKhach.MaTuyen = cbbMaTuyen.SelectedItem.ToString();
                xeKhach.MaTaiXe = db.tblNhanViens.Where(t => t.TenNhanVien == cbbTaiXeXK.SelectedItem.ToString()).SingleOrDefault().MaNhanVien;
                xeKhach.BienSoXe = txtBienSoXK.Text.ToString();


                BLL_XeKhach temp = new BLL_XeKhach();
                string message = temp.validateInput(xeKhach.MaXe, xeKhach.MaTaiXe, xeKhach.MaLoaiXe, xeKhach.BienSoXe, xeKhach.MaTuyen, xeKhach.SoGhe);
                if (string.IsNullOrEmpty(message))
                {
                    if (temp.canUpdate(xeKhach.MaXe, xeKhach.BienSoXe))
                    {
                        db.SaveChanges();
                        MessageBox.Show("Cập nhật thành công");
                    }
                    else
                        MessageBox.Show("Thất bại");
                }
                else
                    MessageBox.Show(message);
            }
            else
            {
                int maXe = int.Parse(txtMaXeTC.Text.ToString());
                
                tblXeTrungChuyen xe = db.tblXeTrungChuyens.Where(t=>t.MaXe == maXe).SingleOrDefault();
                xe.MaTaiXe = db.tblNhanViens.Where(t => t.TenNhanVien == cbbTaiXeXTC.SelectedItem.ToString()).SingleOrDefault().MaNhanVien;
                xe.BienSoXe = txtBienSoXTC.Text.ToString();
                xe.DiaDiemTrungChuyen = txtDiaDiem.Text.ToString();


                BLL_XeTrungChuyen temp = new BLL_XeTrungChuyen();
                string message = temp.validateInput(xe.MaXe, xe.MaTaiXe, xe.BienSoXe, xe.DiaDiemTrungChuyen);
                if (string.IsNullOrEmpty(message))
                {
                    if (temp.canUpdate(xe.MaXe, xe.BienSoXe))
                    {
                        db.SaveChanges();
                        MessageBox.Show("Cập nhật thành công");
                    }
                    else
                        MessageBox.Show("Thất bại");
                }
                else
                    MessageBox.Show(message);
            }
        }
        public bool canInsert(int maXe, string bienSoXe)
        {
            QUANLYXEKHACHEntities db = new QUANLYXEKHACHEntities();
            tblXeKhach xeKhach = db.tblXeKhaches.Where(t => t.MaXe == maXe || t.BienSoXe == bienSoXe).SingleOrDefault();
            if (xeKhach != null)
                return false;

            return true;
        }
 private void frmTraCuuChuyenDi_Load(object sender, EventArgs e)
 {
     try { 
     QUANLYXEKHACHEntities db = new QUANLYXEKHACHEntities();
     cbBenXeDi.DataSource = db.tblBenXes.Select(t => t.TenBenXe).ToList();        
     cbBenXeDen.DataSource = db.tblBenXes.Select(t => t.TenBenXe).ToList();
     }
     catch { }
 }
        public int  getLastestIndex()
        {
            QUANLYXEKHACHEntities db = new QUANLYXEKHACHEntities();

            if (db.tblNhanViens.ToArray().Length == 0)
                return 1;
            else
                return (db.tblNhanViens.Max(t => t.MaNhanVien) + 1);
        }
        private void btnLapVe_Click(object sender, EventArgs e)
        {
            QUANLYXEKHACHEntities db = new QUANLYXEKHACHEntities();

            int maChuyen = int.Parse(cbbMaChuyenDi.SelectedItem.ToString());
            tblChuyenDi chuyenDi = db.tblChuyenDis.Where(t => t.MaChuyenDi == maChuyen).SingleOrDefault();

            frmThongTinVe form = new frmThongTinVe(chuyenDi, new tblPhieuDatCho());
            form.Show();
        }