public bool InsertChuyenXe(ChuyenXe tx)
        {
            string query  = string.Format("EXEC sp_ThemChuyenXe @idtuyen , @idchuyen , @giokh , @idtaixe , @idxe , @ghichu");
            int    result = DataProvider.ExecuteNonQuery(query, new object[] { tx.IDTuyen, tx.IDChuyen, tx.GioKhoiHanh, tx.IDTaiXe, tx.IDXe, tx.GhiChu });

            return(result > 0);
        }
Ejemplo n.º 2
0
 public IHttpActionResult Delete(string _machuyenxe)
 {
     try
     {
         using (var db = new DB())
         {
             using (var transaction = db.Database.BeginTransaction())
             {
                 ChuyenXe chuyenXe = db.ChuyenXes.FirstOrDefault(x => x.machuyenxe == _machuyenxe);
                 if (chuyenXe == null)
                 {
                     return(BadRequest("Chuyến xe không tồn tại"));
                 }
                 db.ChuyenXes.Remove(chuyenXe);
                 db.SaveChanges();
                 transaction.Commit();
                 return(Ok(_machuyenxe));
             }
         }
     }
     catch (Exception ex)
     {
         return(BadRequest("Chuyến xe đã được sử dụng nên không thể xóa. " + ex.Message));
     }
 }
        private void btnThemChuyen_Click(object sender, EventArgs e)
        {
            BUS_ChuyenXe bus_ChuyenXe = new BUS_ChuyenXe();
            ChuyenXe     tx           = new ChuyenXe();

            tx.GhiChu      = txtGhiChu.Text.ToString();
            tx.IDTaiXe     = (cbbTaiXe.SelectedItem as TaiXe).ID;
            tx.IDTuyen     = (cbbTenTuyen.SelectedItem as TuyenXe).ID;
            tx.IDXe        = (cbbxe.SelectedItem as Xe).ID;
            tx.GioKhoiHanh = DateTime.Parse(dtpGioKhoiHanh.Text);


            if (bus_ChuyenXe.InsertChuyenXe(tx))
            {
                MessageBox.Show("Thêm ChuyenXe thành công");
                LoadDSChuyenXe();
                if (insertChuyenXe != null)
                {
                    insertChuyenXe(this, new EventArgs());
                }
            }
            else
            {
                MessageBox.Show("Có lỗi khi thêm ChuyenXe");
            }
        }
Ejemplo n.º 4
0
 public IHttpActionResult Detail(string _machuyenxe)
 {
     try
     {
         using (var db = new DB())
         {
             ChuyenXe chuyenXe = db.ChuyenXes.FirstOrDefault(x => x.machuyenxe == _machuyenxe);
             if (chuyenXe == null)
             {
                 return(BadRequest("Chuyến xe không tồn tại"));
             }
             return(Ok(new
             {
                 chuyenXe.machuyenxe,
                 chuyenXe.malotrinh,
                 chuyenXe.makip,
                 chuyenXe.maxe,
                 chuyenXe.mataixe,
                 chuyenXe.maphuxe,
                 chuyenXe.ngayhoatdong,
                 chuyenXe.thoigiandungxe
             }));
         }
     }
     catch (Exception ex)
     {
         return(BadRequest(ex.Message));
     }
 }
        public bool UpdateChuyenXe(ChuyenXe tx)
        {
            string query  = string.Format("UPDATE Chuyen SET Tuyen_ID_Tuyen = {0}, Gio_khoi_hanh = {1}, Ghi_chu = N'{2}' ,Tai_xe_ID_Taixe = {3} , Xe_XeID = {4} WHERE ID_Chuyen = {5}", tx.IDTuyen, tx.GioKhoiHanh, tx.GhiChu, tx.IDTaiXe, tx.IDXe, tx.IDChuyen);
            int    result = DataProvider.ExecuteNonQuery(query);

            return(result > 0);
        }
Ejemplo n.º 6
0
    protected void Page_Load(object sender, EventArgs e)
    {
        string mod      = String.IsNullOrEmpty(Request["url"]) ? "Home" : Request["url"].ToString();
        string chuyenxe = String.IsNullOrEmpty(Request["url"]) ? "Home" : Request["nurl"].ToString();

        modId = ModControl.GetP_From_Code(mod);
        var res = new ChuyenXeRepository().SearchFor(o => o.url == chuyenxe).SingleOrDefault();

        if (res != null)
        {
            res.Xe        = new XeRepository().Find(res.MaXe.Value);
            res.Xe.NhaXe1 = new NhaxeRepository().Find(res.Xe.Nhaxe.Value);
            cx            = res;
        }
        else
        {
            Response.Redirect("/404.htm");
        }
        CMSfunc.checkURL();
        if (Session["UserID"] != null)
        {
            //var user = UserControls.GetUserByID(int.Parse(Session["UserID"].ToString()));
            //txtAddress.Text = user.User_Address;
            //txtName.Text = user.User_Name;
            //txtTel.Text = user.User_Tel;
            //email.Text = user.User_Email;
        }
    }
Ejemplo n.º 7
0
 public ChuyenXeViewModel(ChuyenXe cx)
 {
     this.Giotoi         = (cx.Giokhoihanh + cx.Thoigiandukien).Value.ToString("HH:mm");
     this.Xe             = new XeRepository().Find(cx.MaXe.Value);
     this.NhaXe          = new NhaxeRepository().Find(this.Xe.Nhaxe.Value);
     this.NhaXe.Xes      = new List <Xe>();
     this.Xe.ChuyenXes   = new List <ChuyenXe>();
     this.Thoigiandukien = cx.Thoigiandukien.Value.Hours.ToString() + " giờ " + cx.Thoigiandukien.Value.Minutes.ToString() + " phút";
     this.Ngaydi         = cx.Ngaydi.Value.ToString("dd/MM/yyyy");
     this.Mota           = cx.Mota;
     this.Chitiet        = cx.Chitiet;
     this.Diemden        = cx.Diemden;
     this.Diemdi         = cx.Diemdi;
     this.Giokhoihanh    = cx.Giokhoihanh.Value.ToString("HH:mm");
     this.MaChuyenXe     = cx.MaChuyenXe;
     this.TongVe         = cx.TongVe;
     this.TrangThai      = cx.TrangThai;
     this.TuyenDuong     = cx.TuyenDuong;
     this.url            = cx.url;
     this.VeThuongConLai = cx.VeThuongConLai;
     this.VeVipConLai    = cx.VeVipConLai;
     this.GiaThuong      = cx.GiaThuong;
     this.GiaVIP         = cx.GiaVIP;
     this.KhuyenMai      = cx.KhuyenMai;
     this.TongSoVeThuong = cx.TongSoVeThuong;
     this.TongSoVeVIP    = cx.TongSoVeVIP;
     this.SDT            = cx.SDT;
     this.LoTrinh        = cx.LoTrinh;
 }
Ejemplo n.º 8
0
        public int SuaChuyenXe(ChuyenXe a)
        {
            int          kq = 0;
            DAO_ChuyenXe CX = new DAO_ChuyenXe();

            kq = CX.SuaChuyenXe(a);
            return(kq);
        }
Ejemplo n.º 9
0
    public static string DELCHUYENXE(string machuyenxe)
    {
        ChuyenXeRepository cxRepo = new ChuyenXeRepository();
        ChuyenXe           cx     = cxRepo.Find(int.Parse(machuyenxe));
        var res = cxRepo.Remove(cx);

        cxRepo.Save();
        return(JsonConvert.SerializeObject(res));
    }
        public ActionResult Edit([Bind(Include = "MaChuyenXe,MaTuyenXe,TenChuyenXe,NgayGioChay,TaiXe")] ChuyenXe chuyenXe)
        {
            if (ModelState.IsValid)
            {
                chuyenXeService.CapNhatChuyenXe(chuyenXe);

                return(RedirectToAction("Index"));
            }
            ViewBag.MaTuyenXe = new SelectList(tuyenXeService.XemTuyenXe(), "MaTuyenXe", "TenTuyenXe", chuyenXe.MaTuyenXe);
            return(View(chuyenXe));
        }
Ejemplo n.º 11
0
        public int ThemChuyen(ChuyenXe cx)
        {
            provider.Connect();
            int idTuyen = Convert.ToInt32(cx.Tuyen);
            int idXe    = Convert.ToInt32(cx.Xe);
            int idTaiXe = Convert.ToInt32(cx.TaiXe);
            int nRow    = provider.ExecuteNonQuery(CommandType.Text, "insert into Chuyen values (" + cx.ChuyenID + "," + idTuyen + ",'" + cx.GioKhoiHanh + "','" + cx.GhiChu + "'," + idXe + "," + idTaiXe + ")");

            provider.DisConnect();
            return(nRow);
        }
Ejemplo n.º 12
0
        public IHttpActionResult Put(ChuyenXe _chuyenXe)
        {
            try
            {
                using (var db = new DB())
                {
                    using (var transaction = db.Database.BeginTransaction())
                    {
                        ChuyenXe chuyenXe = db.ChuyenXes.FirstOrDefault(x => x.machuyenxe == _chuyenXe.machuyenxe);
                        if (chuyenXe == null)
                        {
                            return(BadRequest("Mã chuyến xe không tồn tại"));
                        }
                        chuyenXe.malotrinh    = _chuyenXe.malotrinh;
                        chuyenXe.makip        = _chuyenXe.makip;
                        chuyenXe.maxe         = _chuyenXe.maxe;
                        chuyenXe.mataixe      = _chuyenXe.mataixe;
                        chuyenXe.maphuxe      = _chuyenXe.maphuxe;
                        chuyenXe.ngayhoatdong = _chuyenXe.ngayhoatdong;

                        // khởi tạo danh sách ghế đặt có trạng thái mặc định trống toàn bộ trong chuyến
                        List <Ghe> ghes = db.Ghes.Where(x => x.maxe == _chuyenXe.maxe).ToList();
                        if (ghes == null)
                        {
                            ghes = new List <Ghe>();
                        }
                        ghes.ForEach(x =>
                        {
                            if (db.TrangThaiGhes.FirstOrDefault(y => y.maghe == x.maghe && x.ngaycapnhat == _chuyenXe.ngayhoatdong.Value) == null)
                            {
                                db.TrangThaiGhes.Add(new Database.TrangThaiGhe()
                                {
                                    maghe     = x.maghe,
                                    ngay      = _chuyenXe.ngayhoatdong,
                                    trangthai = Helper.TrangThaiGhe.GHETRONG
                                });
                            }
                        });
                        db.SaveChanges();
                        transaction.Commit();
                        return(Ok(new
                        {
                            _chuyenXe.machuyenxe
                        }));
                    }
                }
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }
        }
Ejemplo n.º 13
0
        private void btnThem_Click(object sender, EventArgs e)
        {
            ChuyenXe cx = new ChuyenXe();

            cx.ChuyenID    = txtMaChuyen.Text.ToString();
            cx.Tuyen       = cbTuyenXe.Text.ToString();
            cx.Xe          = cbMaXe.Text.ToString();
            cx.TaiXe       = cbTaiXe.Text.ToString();
            cx.GioKhoiHanh = dtpThoiGian.Text.ToString();
            cx.GhiChu      = txtGhiChu.Text.ToString();
            bus.themChuyen(cx);
            reLoad();
        }
Ejemplo n.º 14
0
        public int SuaChuyen(ChuyenXe cx)
        {
            int t  = Convert.ToInt32(cx.Tuyen);
            int tx = Convert.ToInt32(cx.TaiXe);
            int xe = Convert.ToInt32(cx.Xe);
            int id = Convert.ToInt32(cx.ChuyenID);

            provider.Connect();
            int nRow = provider.ExecuteNonQuery(CommandType.Text, "update Chuyen set Tuyen_ID_Tuyen = " + t + ", Gio_Khoi_Hanh = N'" + cx.GioKhoiHanh + "', Ghi_Chu = '" + cx.GhiChu + "' , Xe_XeID = " + xe + " , Tai_xe_ID_TaiXe = " + tx + " where ID_Chuyen = " + id + "");

            provider.DisConnect();
            return(nRow);
        }
        // GET: ChuyenXes/Details/5
        public ActionResult Details(int id)
        {
            //if (id == null)
            //{
            //    return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
            //}
            ChuyenXe chuyenXe = chuyenXeService.LayChuyenXe(id);

            if (chuyenXe == null)
            {
                return(HttpNotFound());
            }
            return(View(chuyenXe));
        }
        // GET: ChuyenXes/Edit/5
        public ActionResult Edit(int id)
        {
            //if (id == null)
            //{
            //    return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
            //}
            ChuyenXe chuyenXe = chuyenXeService.LayChuyenXe(id);

            if (chuyenXe == null)
            {
                return(HttpNotFound());
            }
            ViewBag.MaTuyenXe = new SelectList(tuyenXeService.XemTuyenXe(), "MaTuyenXe", "TenTuyenXe");
            return(View(chuyenXe));
        }
Ejemplo n.º 17
0
 private void btnLuuChuyenXe_Click(object sender, EventArgs e)
 {
     if (KTRONG() == false)
     {
         return;
     }
     else
     {
         ChuyenXe cx = new ChuyenXe();
         cx.id_chuyen       = txtIDChuyenXe.Text;
         cx.tuyen_id_tuyen  = cbIDTuyen.SelectedItem.ToString();
         cx.giokhoihanh     = DtpChuyenXe.Value;
         cx.ghichu          = txtGhiChu.Text;
         cx.xe_xeid         = cbIDXe.SelectedItem.ToString();
         cx.tai_xe_id_taixe = cbIDTaiXe.SelectedItem.ToString();
         BUS_ChuyenXe chuyenx = new BUS_ChuyenXe();
         if (txtIDChuyenXe.Enabled == true)
         {
             if (chuyenx.ThemChuyenXe(cx) == 1)
             {
                 this.Close();
             }
             else if (chuyenx.ThemChuyenXe(cx) == -1)
             {
                 MessageBox.Show("Không Được Trùng ID");
                 return;
             }
             else
             {
                 MessageBox.Show("Không Thêm Được");
                 return;
             }
         }
         else
         {
             if (chuyenx.SuaChuyenXe(cx) == 1)
             {
                 txtIDChuyenXe.Enabled = true;
                 this.Close();
             }
             else
             {
                 MessageBox.Show("Không Sửa Được");
                 return;
             }
         }
     }
 }
Ejemplo n.º 18
0
        public int ThemChuyenXe(ChuyenXe a)
        {
            int          kq = 0;
            DAO_ChuyenXe CX = new DAO_ChuyenXe();
            DataTable    dt = CX.LoadIDChuyenXe();

            foreach (DataRow row in dt.Rows)
            {
                if (a.id_chuyen == row[0].ToString())
                {
                    return(-1);
                }
            }
            kq = CX.ThemChuyenXe(a);
            return(kq);
        }
        public ChuyenXe GetChuyenXeByID(int id)
        {
            ChuyenXe ChuyenXe = null;

            string       query    = "select * from Chuyen where ID_Chuyen = " + id;
            DataProvider provider = new DataProvider();
            DataTable    data     = provider.ExecuteQuery(query);

            foreach (DataRow item in data.Rows)
            {
                ChuyenXe = new ChuyenXe(item);
                return(ChuyenXe);
            }

            return(ChuyenXe);
        }
Ejemplo n.º 20
0
 public int SuaChuyen(ChuyenXe cx)
 {
     foreach (DataRow row in dao.loadTenXe(cx.Xe).Rows)
     {
         cx.Xe = row["XeID"].ToString();
     }
     foreach (DataRow row2 in dao.loadTenTaiXe(cx.TaiXe).Rows)
     {
         cx.TaiXe = row2["ID_TaiXe"].ToString();
     }
     foreach (DataRow row3 in dao.loadTenTuyen(cx.Tuyen).Rows)
     {
         cx.Tuyen = row3["ID_Tuyen"].ToString();
     }
     return(dao.SuaChuyen(cx));
 }
        public ActionResult Create([Bind(Include = "MaChuyenXe,MaTuyenXe,TenChuyenXe,NgayGioChay,TaiXe")] ChuyenXe chuyenXe)
        {
            logger.Info("Start controller....");
            int status = chuyenXeService.ThemChuyenXe(chuyenXe);

            if (status == 0)
            {
                logger.Info("Status: Success");
                ViewBag.MaTuyenXe = new SelectList(tuyenXeService.XemTuyenXe(), "MaTuyenXe", "TenTuyenXe");
                return(View(chuyenXe));
            }
            else
            {
                logger.Info("Status: Fail");
                return(Content("Them that bai"));
            }
        }
Ejemplo n.º 22
0
 public IHttpActionResult Post(ChuyenXe _chuyenXe)
 {
     try
     {
         using (var db = new DB())
         {
             using (var transaction = db.Database.BeginTransaction())
             {
                 ChuyenXe chuyenXe = db.ChuyenXes.FirstOrDefault(x => x.machuyenxe == _chuyenXe.machuyenxe);
                 if (chuyenXe != null)
                 {
                     return(BadRequest("Mã chuyến xe đã tồn tại"));
                 }
                 db.ChuyenXes.Add(_chuyenXe);
                 db.SaveChanges();
                 // khởi tạo danh sách ghế đặt có trạng thái mặc định trống toàn bộ trong chuyến
                 List <Ghe> ghes = db.Ghes.Where(x => (x.maxe == _chuyenXe.maxe) && (x.active == true)).ToList();
                 if (ghes == null)
                 {
                     ghes = new List <Ghe>();
                 }
                 ghes.ForEach(x =>
                 {
                     db.TrangThaiGhes.Add(new Database.TrangThaiGhe()
                     {
                         maghe      = x.maghe,
                         ngay       = _chuyenXe.ngayhoatdong,
                         trangthai  = Helper.TrangThaiGhe.GHETRONG,
                         machuyenxe = _chuyenXe.machuyenxe
                     });
                 });
                 db.SaveChanges();
                 transaction.Commit();
                 return(Ok(new
                 {
                     _chuyenXe.machuyenxe
                 }));
             }
         }
     }
     catch (Exception ex)
     {
         return(BadRequest(ex.Message));
     }
 }
Ejemplo n.º 23
0
        public List <ChuyenXe> GetAll()
        {
            List <ChuyenXe> list = new List <ChuyenXe>();

            DataTable data = new DataTable();

            string query = "Select * from ChuyenXe";

            data = DataProvider.Instance.ExecuteQuery(query);

            foreach (DataRow row in data.Rows)
            {
                ChuyenXe cx = new ChuyenXe(row);
                list.Add(cx);
            }

            return(list);
        }
Ejemplo n.º 24
0
    protected void Page_Load(object sender, EventArgs e)
    {
        string mave = Request.QueryString["nurl"];

        if (string.IsNullOrEmpty(mave))
        {
            dvmain.Visible = false;
            Value.ShowMessage(ltrError, ErrorMessage.NoTransaction, AlertType.ERROR);
        }
        else
        {
            this.order = new OrderRepository().SearchFor(o => o.Order_Code == mave).SingleOrDefault();
            if (order != null)
            {
                this.chuyenxe = new ChuyenXeRepository().Find(order.MaChuyenXe.Value);
                if (chuyenxe != null)
                {
                    chuyenxe.Xe = new XeRepository().Find(chuyenxe.MaXe.Value);
                    if (chuyenxe.Xe != null)
                    {
                        chuyenxe.Xe.NhaXe1 = new NhaxeRepository().Find(chuyenxe.Xe.Nhaxe.Value);
                    }
                }
                if (order.Order_Account.HasValue)
                {
                    this.member = new MemberRepository().Find(order.Order_Account.Value);
                }
                this.method = new MethodRepository().Find(order.Order_CheckOutMethod.Value);
            }
            else
            {
                dvmain.Visible = false;
                Value.ShowMessage(ltrError, ErrorMessage.NoVertification, AlertType.ERROR);
            }
        }
    }
        private void btnCapNhatChuyen_Click(object sender, EventArgs e)
        {
            BUS_ChuyenXe bus_ChuyenXe = new BUS_ChuyenXe();
            ChuyenXe     tx           = new ChuyenXe();

            tx.IDChuyen    = (int)dgvChuyen.SelectedCells[0].OwningRow.Cells["ID_Chuyen"].Value;
            tx.GhiChu      = txtGhiChu.Text.ToString();
            tx.IDTaiXe     = (cbbTaiXe.SelectedItem as TaiXe).ID;
            tx.IDTuyen     = (cbbTenTuyen.SelectedItem as TuyenXe).ID;
            tx.GioKhoiHanh = DateTime.Parse(dtpGioKhoiHanh.Text);
            if (bus_ChuyenXe.UpdateChuyenXe(tx))
            {
                MessageBox.Show("Cập nhật ChuyenXe thành công");
                LoadDSChuyenXe();
                if (updateChuyenXe != null)
                {
                    updateChuyenXe(this, new EventArgs());
                }
            }
            else
            {
                MessageBox.Show("Có lỗi khi Cập nhật ChuyenXe");
            }
        }
        public bool InsertChuyenXe(ChuyenXe tx)
        {
            DAO_ChuyenXe daoChuyenXe = new DAO_ChuyenXe();

            return(daoChuyenXe.InsertChuyenXe(tx));
        }
        public bool UpdateChuyenXe(ChuyenXe tx)
        {
            DAO_ChuyenXe daoChuyenXe = new DAO_ChuyenXe();

            return(daoChuyenXe.UpdateChuyenXe(tx));
        }