예제 #1
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");
            }
 
        }
        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 { }
        }
예제 #3
0
        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");
            }         
        }
        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);
            }
        }
        private void btXoa_Click(object sender, EventArgs e)
        {
            QUANLYXEKHACHEntities db = new QUANLYXEKHACHEntities();
            BLL.BLL_BenXe temp = new BLL.BLL_BenXe();

            tblBenXe benXe = db.tblBenXes.Where(t => t.TenBenXe == cbTenBenXe.SelectedItem.ToString()).SingleOrDefault();
            if(benXe != null)
            {
                if (temp.canDelete(benXe.MaBenXe))
                {
                    db.tblBenXes.Remove(benXe);
                    db.SaveChanges();

                    frmXoaBenXe_Load(sender, e);
                    MessageBox.Show("Xóa thành công");
                }
            }
        }
 private void btluu_Click(object sender, EventArgs e)
 {
     try
     {
         QUANLYXEKHACHEntities db = new QUANLYXEKHACHEntities();
         int id = ma;
         tblTaiKhoan tk = db.tblTaiKhoans.Where(t => t.MaNhanVien == id).SingleOrDefault();
         string MatKhauMoi = txtMatKhauMoi.Text;
         tk.MatKhau = MatKhauMoi;
         db.Entry(tk).State = System.Data.Entity.EntityState.Modified;
         db.SaveChanges();
         MessageBox.Show("Thay đổi mật khẩu thành công");
         this.DialogResult = DialogResult.Cancel;
     }
     catch (Exception ex)
     {
         MessageBox.Show("Lỗi: " + ex.Message);
     }
 }
        private void btXoa_Click(object sender, EventArgs e)
        {
            if(cbMaTuyen.Text.Equals(""))
            {
                MessageBox.Show("Vui lòng chọn tuyến bay muốn xóa", "Lỗi");
                return;
            }

            QUANLYXEKHACHEntities db = new QUANLYXEKHACHEntities();
            BLL_TuyenXe temp = new BLL_TuyenXe();
            if(temp.canDelete(cbMaTuyen.SelectedItem.ToString()))
            {
                tblTuyenXe tuyenXe = db.tblTuyenXes.Where(t => t.MaTuyen == cbMaTuyen.SelectedItem.ToString()).Single();
                db.tblTuyenXes.Remove(tuyenXe);
                db.SaveChanges();
                MessageBox.Show("Xóa thành công", "Thông báo");
            }
            else
                MessageBox.Show("Tuyến không tồn tại", "Thông báo");
        }
예제 #8
0
        public static void updateBaoCaoDoanhThuThang(int maChuyenDi)
        {
            QUANLYXEKHACHEntities db = new QUANLYXEKHACHEntities();

            //int maChuyen = int.Parse(txtMaChuyenDi.Text.ToString());
            int maChuyen = maChuyenDi;
            tblChuyenDi chuyenDi = db.tblChuyenDis.Where(t => t.MaChuyenDi == maChuyen).SingleOrDefault();

            tblBaoCaoDoanhThuThang bc = db.tblBaoCaoDoanhThuThangs.Where(t => t.Thang == chuyenDi.KhoiHanh.Value.Month && t.Nam == chuyenDi.KhoiHanh.Value.Year).SingleOrDefault();
            if (bc == null)
            {
                bc = new tblBaoCaoDoanhThuThang();
                bc.Thang = chuyenDi.KhoiHanh.Value.Month;
                bc.Nam = chuyenDi.KhoiHanh.Value.Year;
                db.tblBaoCaoDoanhThuThangs.Add(bc);
                db.SaveChanges();
            }

            bc.SoChuyenDi = db.tblBaoCaoDoanhThuChuyenDis.Count(t => t.KhoiHanh.Value.Month == bc.Thang && t.KhoiHanh.Value.Year == bc.Nam);
            bc.DoanhThu = db.tblBaoCaoDoanhThuChuyenDis.Where(t => t.KhoiHanh.Value.Month == bc.Thang && t.KhoiHanh.Value.Year == bc.Nam).Sum(t => t.DoanhThu);

            db.SaveChanges();
        }
        private void btnThêm_Click(object sender, EventArgs e)
        {
            QUANLYXEKHACHEntities db = new QUANLYXEKHACHEntities();

            tblBenXe benXeDi = db.tblBenXes.Where(t => t.TenBenXe == cbTenBenDi.SelectedItem.ToString()).Single();
            tblBenXe benXeDen = db.tblBenXes.Where(t => t.TenBenXe == cbTenBenDen.SelectedItem.ToString()).Single();

            BLL_TuyenXe temp = new BLL_TuyenXe();
            if(temp.canInsert(benXeDi.MaBenXe, benXeDen.MaBenXe))
            {
                tblTuyenXe tuyenXe = new tblTuyenXe();
                tuyenXe.MaBenXeDi = benXeDi.MaBenXe;
                tuyenXe.MaBenXeDen = benXeDen.MaBenXe;
                tuyenXe.MaTuyen = txtMaTuyen.Text.ToString();

                db.tblTuyenXes.Add(tuyenXe);
                db.SaveChanges();

                MessageBox.Show("Thêm thành công");
            }
            else
                MessageBox.Show("Thêm thất bại");
        }
        private void btSua_Click(object sender, EventArgs e)
        {
            string maBen = cbMaBenXe.SelectedItem.ToString();
            string tenBen = txtTenBenXe.Text.ToString();

            BLL_BenXe temp = new BLL_BenXe();
            if(temp.canUpdate(maBen, tenBen))
            {
                QUANLYXEKHACHEntities db = new QUANLYXEKHACHEntities();
                tblBenXe benXe = db.tblBenXes.Where(t => t.MaBenXe == maBen).SingleOrDefault();
                if(benXe != null)
                {
                    benXe.TenBenXe = tenBen;
                    db.SaveChanges();

                    MessageBox.Show("Cập nhật thành công");
                }
            }
            else 
            {
                MessageBox.Show("Cập nhật thất bại");
            }
        }
예제 #11
0
        private void btnCapNhat_Click(object sender, EventArgs e)
        {
            List<tblChiTietPhieuDatCho> listCTPhieu = new List<tblChiTietPhieuDatCho>();
            QUANLYXEKHACHEntities db = new QUANLYXEKHACHEntities();
            // tìm các vé đặt chỗ - LayVe == false => if LayVe == true -> đã cập nhật
            for(int i = 0; i < dtgDanhSachVe.RowCount; i++)
            {
                if(bool.Parse(dtgDanhSachVe.Rows[i].Cells["LayVe"].Value.ToString()) != timDatVe)
                {
                    int maCTPhieu = int.Parse(dtgDanhSachVe.Rows[i].Cells["MaCTPhieu"].Value.ToString());
                    tblChiTietPhieuDatCho phieu = db.tblChiTietPhieuDatChoes.Where(t => t.MaCTPhieu == maCTPhieu).SingleOrDefault();
                    if (phieu != null)
                    {
                        phieu.LayVe = !timDatVe;
                        listCTPhieu.Add(phieu);
                    }     
                }
            }

            if(listCTPhieu.Count != 0)
            {
                DialogResult result = MessageBox.Show("Dữ liệu có sự thay đổi, bản muốn cập nhật?", "Thông báo", MessageBoxButtons.YesNo);
                if(result == System.Windows.Forms.DialogResult.Yes)
                {
                    int maChuyenDi = listCTPhieu[0].MaChuyenDi.Value;
                    db.SaveChanges();
                    MessageBox.Show("Thành công");

                    capNhatBaoCaoDoanhThu(maChuyenDi);
                }
            }
        }
        void    updateRecord()
        {
            QUANLYXEKHACHEntities db = new QUANLYXEKHACHEntities();
            BLL_ChuyenDi temp = new BLL_ChuyenDi();
            int maChuyen = int.Parse(txtMaChuyenDi.Text.ToString());

            tblChuyenDi chuyenDi = db.tblChuyenDis.Where(t=>t.MaChuyenDi == maChuyen).SingleOrDefault();
            chuyenDi.DonGia = decimal.Parse(txtGiaVe.Text.ToString());
            chuyenDi.MaXe = int.Parse(cbbMaXe.SelectedItem.ToString());
            chuyenDi.KhoiHanh = dtpKhoiHanh.Value;
            chuyenDi.KetThuc = dtpKetThuc.Value;
            chuyenDi.SoGheTrong = chuyenDi.SoGheDat = 0;

            // xóa bến xe trung gian cũ
            chuyenDi.tblChiTietChuyenDis.Clear();

            string message = temp.validateInput(chuyenDi.MaChuyenDi, chuyenDi.MaXe, chuyenDi.DonGia, dtpKhoiHanh.Value, dtpKetThuc.Value);
            if (string.IsNullOrEmpty(message))
            {
                if (temp.canUpdate(chuyenDi.MaChuyenDi, chuyenDi.MaXe))
                {
                    BLL_ChiTietChuyenDi CTChuyenDi = new BLL_ChiTietChuyenDi();
                    List<tblChiTietChuyenDi> listCTChuyenDi = solveDataInputCT_ChuyenDi();
                    foreach (var item in listCTChuyenDi)
                    {
                        string mes = CTChuyenDi.validateInput(item.MaChuyenDi, item.ThoiGianDung);
                        if (!string.IsNullOrEmpty(mes))
                        {
                            MessageBox.Show(mes);
                            return;
                        }
                    }

                    foreach (var item in listCTChuyenDi)
                        chuyenDi.tblChiTietChuyenDis.Add(item);

                    db.SaveChanges();
                    MessageBox.Show("Cập nhật thành công");
                }
            }
            else
                MessageBox.Show(message, "Thông báo");
        }
예제 #13
0
        private void btnXoa_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("Ban có muốn xóa?", "Thông báo", MessageBoxButtons.YesNo) == System.Windows.Forms.DialogResult.Yes)
            {
                int maCTPhieu = int.Parse(dtgDanhSachVe.CurrentRow.Cells["MaCTPhieu"].Value.ToString());
                QUANLYXEKHACHEntities db = new QUANLYXEKHACHEntities();
                tblChiTietPhieuDatCho ctPhieu = db.tblChiTietPhieuDatChoes.Where(t => t.MaCTPhieu == maCTPhieu).SingleOrDefault();

                int maChuyenDi = int.Parse(ctPhieu.MaChuyenDi.Value.ToString());
                if (ctPhieu != null)
                    db.tblChiTietPhieuDatChoes.Remove(ctPhieu);
                db.SaveChanges();
                MessageBox.Show("Thành công");

                capNhatBaoCaoDoanhThu(maChuyenDi);
            }
        }
예제 #14
0
        private void btnThem_Click(object sender, EventArgs e)
        {
            try
            {
                QUANLYXEKHACHEntities db = new QUANLYXEKHACHEntities();

                tblBenXe benXeDi = db.tblBenXes.Where(t => t.TenBenXe == cbbBenXeDi.SelectedItem.ToString()).Single();
                tblBenXe benXeDen = db.tblBenXes.Where(t => t.TenBenXe == cbbBenXeDen.SelectedItem.ToString()).Single();

                tblTuyenXe tuyenXe = null;
                if (editMode)
                {
                    tuyenXe = db.tblTuyenXes.Where(t => t.MaTuyen == txtMaTuyen.Text.ToString()).SingleOrDefault();
                    if (tuyenXe == null)
                    {
                        MessageBox.Show("Dữ liệu không tồn tại.");
                        return;
                    }
                }
                else
                    tuyenXe = new tblTuyenXe();

                tuyenXe.MaBenXeDi = benXeDi.MaBenXe;
                tuyenXe.MaBenXeDen = benXeDen.MaBenXe;
                tuyenXe.MaTuyen = txtMaTuyen.Text.ToString();

                BLL_ChiTietTuyenXe CtTuyen = new BLL_ChiTietTuyenXe();
                List<tblChiTietTuyen> listCTtuyen = solveDataInputChiTietTuyen();
                foreach (var item in listCTtuyen)
                {
                    string mes = CtTuyen.validateInput(item.MaTuyen, item.ThoiGianDung);
                    if (!string.IsNullOrEmpty(mes))
                    {
                        MessageBox.Show(mes);
                        return;
                    }
                }

                // Xóa record
                tuyenXe.tblChiTietTuyens.Clear();
                foreach (var item in listCTtuyen)
                    tuyenXe.tblChiTietTuyens.Add(item);

                if (!editMode)
                {
                    if (new BLL_TuyenXe().canInsert(benXeDi.MaBenXe, benXeDen.MaBenXe))
                        db.tblTuyenXes.Add(tuyenXe);
                    else
                        MessageBox.Show("Lưu thất bại");
                }
                db.SaveChanges();

                MessageBox.Show("Lưu thành công");
            }
            catch(FormatException)
            {
                MessageBox.Show("Thời gian dừng nhập sai! Phải là số nguyên");
            }
            catch (ArgumentNullException)
            {
                MessageBox.Show("Thời gian dừng nhập sai! Phải là số nguyên");
            }
            catch(Exception)
            { }
        }
        private void btnThem_Click(object sender, EventArgs e)
        {
            QUANLYXEKHACHEntities db = new QUANLYXEKHACHEntities();

            // check tab selected
            if(tabControl.SelectedTab.Name == "tabXeKhach")
            {
                tblXeKhach xeKhach = new tblXeKhach();
                xeKhach.MaXe = int.Parse(txtMaXeKhach.Text.ToString());
                xeKhach.SoGhe = int.Parse(txtSoGhe.Text.ToString());
                xeKhach.MaLoaiXe = db.tblLoaiXes.Where(t => t.TenLoaiXe == cbbLoaiXe.SelectedItem.ToString()).SingleOrDefault().MaLoaiXe;
                xeKhach.MaTuyen = cbbTuyenXe.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.canInsert(xeKhach.MaXe, xeKhach.BienSoXe))
                    {
                        db.tblXeKhaches.Add(xeKhach);
                        db.SaveChanges();
                        MessageBox.Show("Thêm thành công");
                    }
                    else
                        MessageBox.Show("Thêm không thành công");
                }
                else
                    MessageBox.Show(message);
               
            }
            else 
            {
                tblXeTrungChuyen xe = new tblXeTrungChuyen();
                xe.MaXe = int.Parse(txtMaXeTrungChuyen.Text.ToString());
                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.canInsert(xe.MaXe, xe.BienSoXe))
                    {
                        db.tblXeTrungChuyens.Add(xe);
                        db.SaveChanges();
                        MessageBox.Show("Thêm thành công");
                    }
                    else
                        MessageBox.Show("Thêm không thành công");
                }
                else
                    MessageBox.Show(message);
            }

            btnTaoMoi_Click(sender, e);
        }
예제 #16
0
        void    updateRecord()
        {
            QUANLYXEKHACHEntities db = new QUANLYXEKHACHEntities();
            BLL_ChuyenDi temp = new BLL_ChuyenDi();
            int maChuyen = int.Parse(txtMaChuyenDi.Text.ToString());

            tblChuyenDi chuyenDi = db.tblChuyenDis.Where(t=>t.MaChuyenDi == maChuyen).SingleOrDefault();
            chuyenDi.DonGia = decimal.Parse(txtGiaVe.Text.ToString());
            chuyenDi.MaXe = int.Parse(cbbMaXe.SelectedItem.ToString());
            chuyenDi.KhoiHanh = dtpKhoiHanh.Value;
            chuyenDi.SoGheTrong = chuyenDi.SoGheDat = 0;


            string message = temp.validateInput(chuyenDi.MaChuyenDi, chuyenDi.MaXe, chuyenDi.DonGia, dtpKhoiHanh.Value, dtpKetThuc.Value);
            if (string.IsNullOrEmpty(message))
            {
                if (temp.canUpdate(chuyenDi.MaChuyenDi, chuyenDi.MaXe))
                {
                    BLL_ChiTietTuyenXe CTChuyenDi = new BLL_ChiTietTuyenXe();

                    db.SaveChanges();
                    MessageBox.Show("Cập nhật thành công");
                }
            }
            else
                MessageBox.Show(message, "Thông báo");
        }
        private void btnLuu_Click(object sender, EventArgs e)
        {
            phieuDatCho.HoTen = txtHoTen.Text;
            phieuDatCho.TrungChuyen = txtTrungChuyen.Text;
            phieuDatCho.DienThoai = int.Parse(txtDienThoai.Text);

            List<tblChiTietPhieuDatCho> listCTPhieu = new List<tblChiTietPhieuDatCho>();
            BLL.BLL_ChiTietPhieuDatCho temp = new BLL.BLL_ChiTietPhieuDatCho();
            foreach (DataGridViewRow row in dtgGhe.Rows)
            {
                if (string.IsNullOrEmpty(row.Cells["ViTriGhe"].Value + ""))
                    continue;


                tblChiTietPhieuDatCho ctPhieu = new tblChiTietPhieuDatCho();
                ctPhieu.MaPhieu = phieuDatCho.MaPhieu;
                ctPhieu.ViTriGhe = int.Parse(row.Cells["ViTriGhe"].Value.ToString());
                ctPhieu.LayVe = rdBanVe.Checked;
                ctPhieu.MaCTPhieu = temp.getLastestIndex();
                ctPhieu.MaChuyenDi = chuyenDi.MaChuyenDi;

                string message = temp.validateInput(phieuDatCho.MaPhieu, chuyenDi.MaChuyenDi, ctPhieu.ViTriGhe);
                if (!string.IsNullOrEmpty(message))
                {
                    MessageBox.Show(message);
                    return;
                }
                else
                    listCTPhieu.Add(ctPhieu);
            }


            if (phieuDatCho.tblChiTietPhieuDatChoes != null)
                phieuDatCho.tblChiTietPhieuDatChoes.Clear();
            if(listCTPhieu.ToArray().Length == 0)
            {
                MessageBox.Show("Vui lòng nhập vị trí ghế");
                return;
            }

            foreach (var item in listCTPhieu)
                phieuDatCho.tblChiTietPhieuDatChoes.Add(item);


            QUANLYXEKHACHEntities db = new QUANLYXEKHACHEntities();
            string mes = new BLL.BLL_PhieuDatCho().validateInput(phieuDatCho.MaPhieu, chuyenDi.MaChuyenDi, phieuDatCho.HoTen);
            if (string.IsNullOrEmpty(mes))
            {
                if (db.tblPhieuDatChoes.Where(t => t.MaPhieu == phieuDatCho.MaPhieu).Count() == 0) // insert
                {
                    phieuDatCho.MaPhieu = new BLL.BLL_PhieuDatCho().getLastestIndex();
                    db.tblPhieuDatChoes.Add(phieuDatCho);
                }
                   
                db.SaveChanges();

                MessageBox.Show("Thành công");
            }
            else
                MessageBox.Show(mes);
        }
예제 #18
0
        private void btnLuu_Click(object sender, EventArgs e)
        {
            try
            {
                QUANLYXEKHACHEntities db = new QUANLYXEKHACHEntities();
                // Kiểm tra phiếu đã tồn tại chưa
                if (!editMode)
                    phieuDatCho.MaPhieu = new BLL.BLL_PhieuDatCho().getLastestIndex();
                else
                    phieuDatCho = db.tblPhieuDatChoes.Where(t => t.MaPhieu == phieuDatCho.MaPhieu).SingleOrDefault();

                phieuDatCho.HoTen = txtHoTen.Text;
                phieuDatCho.TrungChuyen = txtTrungChuyen.Text;
                phieuDatCho.DienThoai = int.Parse(txtDienThoai.Text);


                // Chi tiết vé
                List<tblChiTietPhieuDatCho> listCTPhieu = new List<tblChiTietPhieuDatCho>();
                BLL.BLL_ChiTietPhieuDatCho temp = new BLL.BLL_ChiTietPhieuDatCho();
                foreach (DataGridViewRow row in dtgGhe.Rows)
                {
                    if (string.IsNullOrEmpty(row.Cells["ViTriGhe"].Value + ""))
                        continue;


                    tblChiTietPhieuDatCho ctPhieu = new tblChiTietPhieuDatCho();
                    ctPhieu.ViTriGhe = int.Parse(row.Cells["ViTriGhe"].Value.ToString());
                    ctPhieu.LayVe = rdBanVe.Checked;
                    ctPhieu.MaChuyenDi = chuyenDi.MaChuyenDi;
                    ctPhieu.MaPhieu = phieuDatCho.MaPhieu;

                    string message = temp.validateInput(phieuDatCho.MaPhieu, chuyenDi.MaChuyenDi, ctPhieu.ViTriGhe);
                    if (!string.IsNullOrEmpty(message))
                    {
                        MessageBox.Show(message);
                        return;
                    }
                    else
                        listCTPhieu.Add(ctPhieu);
                }
                if (listCTPhieu.ToArray().Length == 0)
                {
                    MessageBox.Show("Vui lòng nhập vị trí ghế");
                    return;
                }

                if (phieuDatCho.tblChiTietPhieuDatChoes != null)
                    phieuDatCho.tblChiTietPhieuDatChoes.Clear();
                
                    
                // Thêm chi tiết vé
                int lastCTPhieu = temp.getLastestIndex();
                foreach (var item in listCTPhieu)
                {
                    item.MaCTPhieu = lastCTPhieu++;
                    phieuDatCho.tblChiTietPhieuDatChoes.Add(item);
                }


                // Thông tin phiếu
                string mes = new BLL.BLL_PhieuDatCho().validateInput(phieuDatCho.MaPhieu, phieuDatCho.HoTen, phieuDatCho.DienThoai);
                if (string.IsNullOrEmpty(mes)) // Insert
                {
                    if (!editMode)
                        db.tblPhieuDatChoes.Add(phieuDatCho);
                }
                db.SaveChanges();
                MessageBox.Show("Thành công");
            }
            catch(FormatException)
            {
                MessageBox.Show("Ghế nhập sai. Phải là số nguyên");
            }catch(Exception)
            {
                MessageBox.Show("Lỗi");
            }



            // Đa luồng
            Thread thread = new Thread((ThreadStart)=>
            {
                int maChuyen = int.Parse(txtMaChuyenDi.Text.ToString());
                updateBaoCaoDoanhThuChuyenDi(maChuyen);
                updateBaoCaoDoanhThuThang(maChuyen);
                updateBaoCaoDoanhThuNam(maChuyen);
            });

            thread.Start();
        }
예제 #19
0
        void   insertRecord()
        {
            BLL_ChuyenDi temp = new BLL_ChuyenDi();

            tblChuyenDi chuyenDi = new tblChuyenDi();
            chuyenDi.MaChuyenDi = int.Parse(txtMaChuyenDi.Text.ToString());
            chuyenDi.DonGia = int.Parse(txtGiaVe.Text.ToString());
            chuyenDi.MaXe = int.Parse(cbbMaXe.SelectedItem.ToString());
            chuyenDi.KhoiHanh = dtpKhoiHanh.Value;
            chuyenDi.SoGheTrong = chuyenDi.SoGheDat = 0;

            string message = temp.validateInput(chuyenDi.MaChuyenDi, chuyenDi.MaXe, int.Parse(chuyenDi.DonGia.ToString()), dtpKhoiHanh.Value, dtpKetThuc.Value);
            if (string.IsNullOrEmpty(message))
            {
                if (temp.canInsert(chuyenDi.MaChuyenDi, chuyenDi.MaXe))
                {
                    BLL_ChiTietTuyenXe CTChuyenDi = new BLL_ChiTietTuyenXe();
                    QUANLYXEKHACHEntities db = new QUANLYXEKHACHEntities();
                    db.tblChuyenDis.Add(chuyenDi);
                    db.SaveChanges();
                    MessageBox.Show("Thêm thành công");
                }
            }
            else
                MessageBox.Show(message, "Thông báo");
        }
        private void btCapNhat_Click(object sender, EventArgs e)
        {
            try
            {
                BLL_NhanVien temp = new BLL_NhanVien();
                if (temp.canUpdate(int.Parse(txtMaNhanVien.Text.ToString()), int.Parse(txtCMND.Text.ToString())))
                {
                    QUANLYXEKHACHEntities db = new QUANLYXEKHACHEntities();

                    tblNhanVien t = new tblNhanVien();
                    tblTaiKhoan v = new tblTaiKhoan();
                    t.MaNhanVien = int.Parse(txtMaNhanVien.Text.ToString());
                    t.TenNhanVien = txtTenNhanVien.Text.ToString();
                    t.MaLoaiNhanVien = ConvertLoaiNhanVien();
                    t.NgaySinh = dtNgaySinh.Value;
                    t.CMND = int.Parse(txtCMND.Text.ToString());
                    t.DiaChi = txtDiaChi.Text.ToString();
                    v = db.tblTaiKhoans.Where(s => s.MaNhanVien == t.MaNhanVien).SingleOrDefault();
                    //v.MaNhanVien = int.Parse(txtMaNhanVien.Text.ToString());
                    if (ConvertLoaiNhanVien() == 2)
                    {
                        if (v == null)
                        {
                            v = new tblTaiKhoan();
                            v.MaNhanVien = t.MaNhanVien;
                            v.TenTaiKhoan = txtTaiKhoan.Text.ToString();
                            v.MatKhau = txtMatKhau.Text.ToString();
                            v.MaQuyen = ConvertQuyenHan();
                            db.tblTaiKhoans.Add(v);
                        }
                        else {
                            v.MaNhanVien = t.MaNhanVien;
                            v.TenTaiKhoan = txtTaiKhoan.Text.ToString();
                            v.MatKhau = txtMatKhau.Text.ToString();
                            v.MaQuyen = ConvertQuyenHan();
                            db.Entry(v).State = System.Data.Entity.EntityState.Modified;
                        }                       
                        db.Entry(t).State = System.Data.Entity.EntityState.Modified;
                        db.SaveChanges();
                    }
                    else
                    {
                        if(v.MaNhanVien == t.MaNhanVien)
                            db.tblTaiKhoans.Remove(v);
                        db.Entry(t).State = System.Data.Entity.EntityState.Modified;
                        db.SaveChanges();
                    }

                    MessageBox.Show("Cập nhật thành công");
                    LoadDataGridView();
                    reset();
                }
                else
                {
                    MessageBox.Show("Cập nhật thất bại!");
                }
            }
            catch
            {
                MessageBox.Show("Vui lòng nhập đầy đủ thông tin!");
            }
        }
예제 #21
0
        private void btCapNhat_Click(object sender, EventArgs e)
        {
            QUANLYXEKHACHEntities db = new QUANLYXEKHACHEntities();
            List<tblChiTietTrungChuyen> list = new List<tblChiTietTrungChuyen>();
            foreach(DataGridViewRow row in dtgDanhSachTC.Rows)
            {
                if(bool.Parse(row.Cells["DaRuoc"].Value.ToString()))
                {
                    int maPhieu = int.Parse(row.Cells["MaPhieu"].Value.ToString());
                    tblChiTietTrungChuyen tc = db.tblChiTietTrungChuyens.Where(t => t.MaPhieu == maPhieu).SingleOrDefault();
                    if(tc != null)
                    {
                        tc.DaRuoc = true;
                        list.Add(tc);
                    }
                }
            }

            if (list.Count != 0 && MessageBox.Show("Dữ liệu có sự thay đổi, bạn muốn cập nhật?", "Thông báo", MessageBoxButtons.YesNo) == System.Windows.Forms.DialogResult.Yes)
            {
                db.SaveChanges();
                MessageBox.Show("Thành công");

                cbbXeTrungChuyen_SelectedIndexChanged(sender, e);
            }
        }
예제 #22
0
        private void btXoa_Click(object sender, EventArgs e)
        {
            QUANLYXEKHACHEntities db = new QUANLYXEKHACHEntities();
            
            int maPhieu = int.Parse(dtgDanhSachTC.CurrentRow.Cells["MaPhieu"].Value.ToString());
            dynamic selectedItem = cbbXeTrungChuyen.SelectedItem;
            string bienSo = selectedItem.BienSo;
            tblXeTrungChuyen xeTC = db.tblXeTrungChuyens.Where(t => t.BienSoXe == bienSo).SingleOrDefault();
            if(xeTC != null)
            { 
                tblChiTietTrungChuyen temp = db.tblChiTietTrungChuyens.Where(t => t.MaXe == xeTC.MaXe && t.MaPhieu == maPhieu).SingleOrDefault();
                if (temp != null)
                    db.tblChiTietTrungChuyens.Remove(temp);
                db.SaveChanges();

                // thêm vào datagridview
                dtgKhachHang.Rows.Add(dtgDanhSachTC.CurrentRow.Cells["HoTen"].Value,
                                        dtgDanhSachTC.CurrentRow.Cells["MaPhieu"].Value,
                                        dtgDanhSachTC.CurrentRow.Cells["SDT"].Value,
                                        dtgDanhSachTC.CurrentRow.Cells["DiaDiem"].Value,
                                        dtgDanhSachTC.CurrentRow.Cells["SoVe"].Value);
                dtgDanhSachTC.Rows.RemoveAt(dtgDanhSachTC.CurrentRow.Index);
            }
        }
        void   insertRecord()
        {
            BLL_ChuyenDi temp = new BLL_ChuyenDi();

            tblChuyenDi chuyenDi = new tblChuyenDi();
            chuyenDi.MaChuyenDi = int.Parse(txtMaChuyenDi.Text.ToString());
            chuyenDi.DonGia = int.Parse(txtGiaVe.Text.ToString());
            chuyenDi.MaXe = int.Parse(cbbMaXe.SelectedItem.ToString());
            chuyenDi.KhoiHanh = dtpKhoiHanh.Value;
            chuyenDi.KetThuc = dtpKetThuc.Value;
            chuyenDi.SoGheTrong = chuyenDi.SoGheDat = 0;

            string message = temp.validateInput(chuyenDi.MaChuyenDi, chuyenDi.MaXe, int.Parse(chuyenDi.DonGia.ToString()), dtpKhoiHanh.Value, dtpKetThuc.Value);
            if (string.IsNullOrEmpty(message))
            {
                if (temp.canInsert(chuyenDi.MaChuyenDi, chuyenDi.MaXe))
                {
                    BLL_ChiTietChuyenDi CTChuyenDi = new BLL_ChiTietChuyenDi();
                    List<tblChiTietChuyenDi> listCTChuyenDi = solveDataInputCT_ChuyenDi();
                    foreach (var item in listCTChuyenDi)
                    {
                        string mes = CTChuyenDi.validateInput(item.MaChuyenDi, item.ThoiGianDung);
                        if (!string.IsNullOrEmpty(mes))
                        {
                            MessageBox.Show(mes);
                            return;
                        }
                    }

                    foreach (var item in listCTChuyenDi)
                        chuyenDi.tblChiTietChuyenDis.Add(item);

                    QUANLYXEKHACHEntities db = new QUANLYXEKHACHEntities();
                    db.tblChuyenDis.Add(chuyenDi);
                    db.SaveChanges();
                    MessageBox.Show("Thêm thành công");
                }
            }
            else
                MessageBox.Show(message, "Thông báo");
        }
        private void btthem_Click(object sender, EventArgs e)
        {
            try
            {
                BLL_TaiKhoan temp = new BLL_TaiKhoan();
                if (temp.canInsert(txtTenDangNhap.Text.ToString(), txtMatKhau.Text.ToString()))
                {
                    QUANLYXEKHACHEntities db = new QUANLYXEKHACHEntities();

                    tblTaiKhoan t = new tblTaiKhoan();
                    t.MaNhanVien = int.Parse(txtMaNhanVien.Text.ToString());
                    t.TenTaiKhoan = txtTenDangNhap.Text.ToString();
                    t.MatKhau = txtMatKhau.Text.ToString();
                    t.MaQuyen = ConvertQuyenHan();                  
                    db.tblTaiKhoans.Add(t);
                    db.SaveChanges();

                    MessageBox.Show("Thêm thành công");
                    LoadDataGridView();
                    reset();
                }
                else
                {
                    MessageBox.Show("Không thành công");
                }
            }
            catch
            {
                MessageBox.Show("Vui lòng nhập đầy đủ thông tin!");
            }
        }
        private void btthem_Click(object sender, EventArgs e)
        {
          try {
            BLL_NhanVien temp = new BLL_NhanVien();
            if (temp.canInsert(int.Parse(txtMaNhanVien.Text.ToString()),int.Parse(txtCMND.Text.ToString())))
            {
                QUANLYXEKHACHEntities db = new QUANLYXEKHACHEntities();

                tblNhanVien t = new tblNhanVien();
                tblTaiKhoan v = new tblTaiKhoan();
                t.MaNhanVien = int.Parse(txtMaNhanVien.Text.ToString());
                t.TenNhanVien = txtTenNhanVien.Text.ToString();
                t.MaLoaiNhanVien = ConvertLoaiNhanVien();
                t.NgaySinh = dtNgaySinh.Value;
                t.CMND = int.Parse(txtCMND.Text.ToString());
                t.DiaChi = txtDiaChi.Text.ToString();

                //v.MaNhanVien = int.Parse(txtMaNhanVien.Text.ToString());
                if(ConvertLoaiNhanVien() == 2)
                {
                    v.MaNhanVien = t.MaNhanVien;
                    v.TenTaiKhoan = txtTaiKhoan.Text.ToString();
                    v.MatKhau = txtMatKhau.Text.ToString();
                    v.MaQuyen = ConvertQuyenHan();
                    db.tblTaiKhoans.Add(v);
                    db.tblNhanViens.Add(t);
                    db.SaveChanges();
                }
                else {
                    db.tblNhanViens.Add(t);
                    db.SaveChanges();
                }
                      
                MessageBox.Show("Thêm thành công");
                LoadDataGridView();
                reset();
            }
            else
            {
                MessageBox.Show("Nhân viên đã tồn tại!");
            }
          }
          catch {
              MessageBox.Show("Vui lòng nhập đầy đủ thông tin!");
          }
        }
예제 #26
0
        private void btXoa_Click(object sender, EventArgs e)
        {
            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();


                DialogResult result = MessageBox.Show(string.Format("Bạn muốn xóa thông tin xe khách\nMã xe: {0}\nTài xế: {1}\nBiển số: {2}", xe.MaXe, xe.tblNhanVien.TenNhanVien, xe.BienSoXe), "Thông báo", MessageBoxButtons.YesNo);
                if(result == System.Windows.Forms.DialogResult.Yes)
                {
                    BLL.BLL_XeKhach temp = new BLL.BLL_XeKhach();
                    if(temp.canDelete(xe.MaXe))
                    {
                        try
                        {
                            db.tblXeKhaches.Remove(xe);
                            db.SaveChanges();

                            MessageBox.Show("Thành công!");
                            frmQuanLyXe_Load(sender, e);
                        }catch
                        {
                            MessageBox.Show("Dữ liệu đang được sử dụng, không thể xóa!", "Lỗi");
                        }
                        
                    }
                    else
                        MessageBox.Show("Dữ liệu không tồn tại!", "Lỗi");
                }
            }
            else
            {
                int maXe = int.Parse(dtgDSXeTrungChuyen.CurrentRow.Cells["MaXeTC"].Value.ToString());
                tblXeTrungChuyen xe = db.tblXeTrungChuyens.Where(t => t.MaXe == maXe).SingleOrDefault();


                DialogResult result = MessageBox.Show(string.Format("Bạn muốn xóa thông tin xe trung chuyển\nMã xe: {0}\nTài xế: {1}\nBiển số: {2}", xe.MaXe, xe.tblNhanVien.TenNhanVien, xe.BienSoXe), "Thông báo", MessageBoxButtons.YesNo);
                if (result == System.Windows.Forms.DialogResult.Yes)
                {
                    BLL.BLL_XeTrungChuyen temp = new BLL.BLL_XeTrungChuyen();
                    if (temp.canDelete(xe.MaXe))
                    {
                        try
                        {
                            db.tblXeTrungChuyens.Remove(xe);
                            db.SaveChanges();

                            MessageBox.Show("Thành công!");
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show("Dữ liệu đang được sử dụng, không thể xóa!", "Lỗi");
                        }

                    }
                    else
                        MessageBox.Show("Dữ liệu không tồn tại!", "Lỗi");
                }
            }
        }
        private void btxoa_Click(object sender, EventArgs e)
        {
            QUANLYXEKHACHEntities db = new QUANLYXEKHACHEntities();
            try
            {
                if (string.IsNullOrEmpty(txtMaNhanVien.Text))
                {
                    MessageBox.Show("Tên nhân viên không tồn tại");
                }
                else
                {
                    int MaNV = int.Parse(txtMaNhanVien.Text.ToString());
                    tblNhanVien MaNhanVien = db.tblNhanViens.Where(t => t.MaNhanVien == MaNV).SingleOrDefault();
                    tblTaiKhoan ma = db.tblTaiKhoans.Where(t => t.MaNhanVien == MaNV).SingleOrDefault();

                    if (MessageBox.Show("Bạn có muốn xóa nhân viên'" + txtTenNhanVien.Text + "'không ??", "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                    {
                        if(ma != null)
                            db.tblTaiKhoans.Remove(ma);
                        db.tblNhanViens.Remove(MaNhanVien);
                        db.SaveChanges();
                        reset();
                        if (vitri > 0)
                        {
                            dgvNhanVien.CurrentCell = dgvNhanVien.Rows[vitri - 1].Cells[0];
                            dgvNhanVien.Rows[vitri - 1].Selected = true;
                            Gan_click();
                        }
                    }
                }

            }


            catch (Exception ex)
            {
                MessageBox.Show("Lỗi: " + ex.Message);
            }
        }
예제 #28
0
        public static void updateBaoCaoDoanhThuChuyenDi(int maChuyen)
        {
            QUANLYXEKHACHEntities db = new QUANLYXEKHACHEntities();
            //int maChuyen = int.Parse(txtMaChuyenDi.Text.ToString());

            tblBaoCaoDoanhThuChuyenDi bc = db.tblBaoCaoDoanhThuChuyenDis.Where(t => t.MaChuyenDi == maChuyen).SingleOrDefault();
            if (bc == null)
            {
                bc = new tblBaoCaoDoanhThuChuyenDi();
                bc.MaChuyenDi = maChuyen;
                db.tblBaoCaoDoanhThuChuyenDis.Add(bc);
                db.SaveChanges();
            }

            // set value
           
            tblChuyenDi chuyenDi = db.tblChuyenDis.Where(t => t.MaChuyenDi == maChuyen).SingleOrDefault();
            bc.KhoiHanh = chuyenDi.KhoiHanh.Value;
            bc.SoVe = db.tblChiTietPhieuDatChoes.Count(t => t.MaChuyenDi == maChuyen && t.LayVe.Value == true);
            bc.DoanhThu = bc.SoVe * chuyenDi.DonGia;

            db.SaveChanges();
        }