Example #1
0
 public All_orders()
 {
     InitializeComponent();
     this.db = new CarRentEntities();
     fillDgv(db.Orders.ToList());
     orders = db.Orders.ToList();
 }
Example #2
0
        public List <CarStatus> GetAllCars()
        {
            using (CarRentEntities db = new CarRentEntities())
            {
                return(db.cars_tbl.Select(c => new CarStatus
                {
                    CarTypeId = new CarType
                    {
                        CarTypeId = c.carsType_tbl.CarTypeId,
                        ModelMake = c.carsType_tbl.ModelMake,
                        Model = c.carsType_tbl.Model,
                        ModelName = c.carsType_tbl.ModelName,
                        ModelYear = c.carsType_tbl.ModelYear,
                        ModelBody = c.carsType_tbl.ModelBody,
                        ModelWeightKg = c.carsType_tbl.ModelWeightKg,
                        ModelDoors = c.carsType_tbl.ModelDoors,
                        Gear = c.carsType_tbl.Gear
                    },
                    ActuallyKm = c.ActuallyKm,
                    Picture = c.Picture,
                    AvaibleToBeRent = c.AvaibleToBeRent,
                    ProperToBeRent = c.ProperToBeRent,
                    DayPrice = c.DayPrice,
                    DayDelayPrice = c.DayDelayPrice,
                    PlateNumber = c.PlateNumber,

                    BranchId = new Branch
                    {
                        Adress = c.branchs_tbl.Adress,
                        BranchName = c.branchs_tbl.BranchName
                    },
                }
                                          ).ToList());
            }
        }
        public bool AddCar(CarType c)
        {
            try
            {
                using (CarRentEntities db = new CarRentEntities())
                {
                    db.carsType_tbl.Add(
                        new carsType_tbl
                    {
                        ModelMake     = c.ModelMake,
                        Model         = c.Model,
                        ModelName     = c.ModelName,
                        ModelYear     = c.ModelYear,
                        ModelBody     = c.ModelBody,
                        ModelWeightKg = c.ModelWeightKg,
                        ModelDoors    = c.ModelDoors,
                        Gear          = c.Gear
                    });

                    db.SaveChanges();
                    return(true);
                }
            }
            catch (Exception)
            {
                return(false);
            }
        }
Example #4
0
        /// <summary>
        /// 批量删除消息记录
        /// </summary>
        /// <param name="arg"></param>
        /// <returns></returns>
        public Task <IApiResult> DelsMessages(P_Message.P_DelsMessages arg)
        {
            return(Task.Run(() =>
            {
                IApiResult ar = new IApiResult();
                try
                {
                    ExceptionMessage em = new ExceptionMessage();

                    using (DAL.CarRentEntities db = new CarRentEntities())
                    {
                        int count = db.Database.ExecuteSqlCommand("update ExceptionMessage set Deleted=1 where ExceptionID in(" + arg.id + ")");

                        ar.message = $"delete {count} data success!";
                        ar.result = new { url = "reload" };
                    }
                }
                catch (Exception ex)
                {
                    Log.Error(this, ex);
                    ar.code = StatusCode.error;
                    ar.message = ex.Message;
                }
                return ar;
            }));
        }
Example #5
0
 public DeliveryDate(int SelectedId, int UserId)
 {
     InitializeComponent();
     this.db         = new CarRentEntities();
     this.selectedId = SelectedId;
     this.userId     = UserId;
 }
 public static List <Branch> getBranches()
 {
     using (CarRentEntities db = new CarRentEntities())
     {
         return(db.Branches.ToList());
     }
 }
Example #7
0
        public bool AddUser(User user)
        {
            try
            {
                using (CarRentEntities db = new CarRentEntities())
                {
                    db.users_tbl.Add(
                        new users_tbl
                    {
                        FullName  = user.FullName,
                        Identity  = user.Identity,
                        UserName  = user.UserName,
                        BirthDay  = user.BirthDay,
                        Gender    = user.Gender,
                        Email     = user.Email,
                        Rank      = user.Rank,
                        Passwords = user.Passwords,
                        Picture   = user.Picture
                    }
                        );

                    db.SaveChanges();
                    return(true);
                }
            }
            catch (Exception)
            {
                return(false);
            }
        }
Example #8
0
 public bool EditCar(CarStatus changedCar)
 {
     try
     {
         using (CarRentEntities db = new CarRentEntities())
         {
             cars_tbl car = db.cars_tbl.FirstOrDefault(c => c.PlateNumber == changedCar.PlateNumber);
             if (car != null)
             {
                 car.ActuallyKm      = changedCar.ActuallyKm;
                 car.AvaibleToBeRent = changedCar.AvaibleToBeRent;
                 car.ProperToBeRent  = changedCar.ProperToBeRent;
                 car.Picture         = changedCar.Picture;
                 car.DayPrice        = changedCar.DayPrice;
                 car.DayDelayPrice   = changedCar.DayDelayPrice;
                 car.PlateNumber     = changedCar.PlateNumber;
                 db.SaveChanges();
                 return(true);
             }
             return(false);
         }
     }
     catch (Exception)
     {
         return(false);
     }
 }
Example #9
0
        /// <summary>
        /// 修改设备信息
        /// </summary>
        /// <param name="arg"></param>
        /// <returns></returns>
        public Task <IApiResult> UpdateDeviceInfo(P_Devices.P_UpdateDeviceInfo arg)
        {
            return(Task.Run(() =>
            {
                IApiResult ar = new IApiResult();
                try
                {
                    DAL.Devices d = new DAL.Devices();

                    d.DeviceID = arg.deviceid;
                    using (DAL.CarRentEntities db = new CarRentEntities())
                    {
                        var device = db.Devices.Find(arg.deviceid);
                        device.DeviceName = arg.devicename;
                        device.Description = arg.description;
                        device.GroupID = arg.groupid;
                        db.SaveChanges();//保存至数据库中
                        ar.message = "Device information is modified successfully";
                        ar.result = new { url = "reload" };
                    }
                }
                catch (Exception ex)
                {
                    Log.Error(this, ex);
                    ar.code = Interface.StatusCode.error;
                    ar.message = ex.Message;
                }
                return ar;
            }));
        }
 public bool EditCar(CarType changedCar)
 {
     try
     {
         using (CarRentEntities db = new CarRentEntities())
         {
             carsType_tbl car = db.carsType_tbl.FirstOrDefault(c => c.CarTypeId == changedCar.CarTypeId);
             if (car != null)
             {
                 car.ModelMake     = changedCar.ModelMake;
                 car.Model         = changedCar.Model;
                 car.ModelName     = changedCar.ModelName;
                 car.ModelYear     = changedCar.ModelYear;
                 car.ModelBody     = changedCar.ModelBody;
                 car.ModelWeightKg = changedCar.ModelWeightKg;
                 car.ModelDoors    = changedCar.ModelDoors;
                 car.Gear          = changedCar.Gear;
                 db.SaveChanges();
                 return(true);
             }
             return(false);
         }
     }
     catch (Exception)
     {
         return(false);
     }
 }
Example #11
0
 /// <summary>
 /// 删除一条设备记录
 /// </summary>
 /// <param name="arg"></param>
 /// <returns></returns>
 public Task <IApiResult> DelDevice(P_Devices.P_DelDevice arg)
 {
     return(Task.Run(() =>
     {
         IApiResult ar = new IApiResult();
         try
         {
             using (DAL.CarRentEntities db = new CarRentEntities())
             {
                 var de = db.Devices.First(d => d.DeviceID == arg.id);
                 de.Deleted = true;
                 int count = db.SaveChanges();
                 ar.message = $"delete{count} data success!";
                 ar.result = new { url = "" };
             }
         }
         catch (Exception ex)
         {
             Log.Error(this, ex);
             ar.code = Interface.StatusCode.error;
             ar.message = ex.Message;
         }
         return ar;
     }));
 }
Example #12
0
 public static List <User> getUsersByRole(char roleType)
 {
     using (CarRentEntities db = new CarRentEntities())
     {
         return(db.Users.Where(user => user.RoleType.ToString() == roleType.ToString()).ToList());
     }
 }
Example #13
0
        public static bool DeleteUser(string ID)
        {
            bool isDeleted;

            try
            {
                using (CarRentEntities db = new CarRentEntities())
                {
                    User user = db.Users.FirstOrDefault(u => u.ID == ID);
                    if (user != null)
                    {
                        db.Users.Remove(user);
                        db.SaveChanges();
                        isDeleted = true;
                    }
                    else
                    {
                        isDeleted = false;
                    }
                }
            }
            catch (Exception e)
            {
                isDeleted = false;
            }

            return(isDeleted);
        }
Example #14
0
 public static List <User> getAllUsers()
 {
     using (CarRentEntities db = new CarRentEntities())
     {
         return(db.Users.ToList());
     }
 }
Example #15
0
        public ActionResult getCarData()
        {
            CarRentEntities db   = new CarRentEntities();
            var             cars = db.Cars.ToList();

            return(Json(cars, JsonRequestBehavior.AllowGet));
        }
Example #16
0
 public bool Edituser(User changedUser)
 {
     try
     {
         using (CarRentEntities db = new CarRentEntities())
         {
             users_tbl user = db.users_tbl.FirstOrDefault(u => u.UserName == changedUser.UserName);
             if (user != null)
             {
                 user.FullName  = changedUser.FullName;
                 user.Identity  = changedUser.Identity;
                 user.UserName  = changedUser.UserName;
                 user.BirthDay  = changedUser.BirthDay;
                 user.Gender    = changedUser.Gender;
                 user.Email     = changedUser.Email;
                 user.Passwords = changedUser.Passwords;
                 user.Rank      = changedUser.Rank;
                 user.Picture   = changedUser.Picture;
                 db.SaveChanges();
                 return(true);
             }
             return(false);
         }
     }
     catch (Exception)
     {
         return(false);
     }
 }
Example #17
0
        /// <summary>
        /// 根据消息ID删除一条报警消息
        /// </summary>
        /// <param name="arg"></param>
        /// <returns></returns>
        public Task <IApiResult> DelMessage(P_Message.P_DelMessage arg)
        {
            return(Task.Run(() =>
            {
                IApiResult ar = new IApiResult();
                try
                {
                    //DAL.ExceptionMessage dal = new ExceptionMessage()
                    //{
                    //    ExceptionID = arg.exceptionid,

                    //};
                    using (DAL.CarRentEntities db = new CarRentEntities())
                    {
                        var em = db.ExceptionMessage.First(e => e.ExceptionID == arg.exceptionid);
                        em.Deleted = 1;
                        //db.ExceptionMessage.Delete(e => e.ExceptionID == arg.ExceptionID);

                        //var context= db.ExceptionMessage.Attach(dal);//将数据交给EF容器处理
                        // context.Deleted = 1;
                        // db.ExceptionMessage.Remove(dal);
                        int count = db.SaveChanges();
                        ar.message = $"delete{count}a data success!";
                        ar.result = new { url = "" };
                    }
                }
                catch (Exception ex)
                {
                    Log.Error(this, ex);
                    ar.code = StatusCode.error;
                    ar.message = ex.Message;
                }
                return ar;
            }));
        }
Example #18
0
 public static List <CarsForRent> getAllCars()
 {
     using (CarRentEntities db = new CarRentEntities())
     {
         List <CarsForRent> allCars = db.CarsForRents.ToList();
         return(allCars);
     }
 }
Example #19
0
 public static List <RentCar> getAllRentCars()
 {
     using (CarRentEntities db = new CarRentEntities())
     {
         List <RentCar> rents = db.RentCars.ToList();
         return(rents);
     }
 }
Example #20
0
 public static List <RentCar> getRentCarsByUserID(int userID)
 {
     using (CarRentEntities db = new CarRentEntities())
     {
         List <RentCar> rents = db.RentCars.Where(order => order.UserID == userID).ToList();
         return(rents);
     }
 }
Example #21
0
 public Reports(int adminId)
 {
     InitializeComponent();
     this.db        = new CarRentEntities();
     this.AdminId   = adminId;
     LblAdmin.Text += db.Administrators.Find(this.AdminId).Name + " " + db.Administrators.Find(this.AdminId).Surname;
     FillDGV(db.CarsOnRent.OrderByDescending(c => c.ReturnDate).ToList());
 }
Example #22
0
 public static List <CarType> getAllCarsType()
 {
     using (CarRentEntities db = new CarRentEntities())
     {
         List <CarType> allTypes = db.CarTypes.ToList();
         return(allTypes);
     }
 }
Example #23
0
 public RentedCars(int adminId)
 {
     InitializeComponent();
     this.db        = new CarRentEntities();
     this.AdminId   = adminId;
     LblAdmin.Text += db.Administrators.Find(this.AdminId).Name + " " + db.Administrators.Find(this.AdminId).Surname;
     FillDGV(db.CarsOnRent.Where(c => c.AcceptedDate == null).ToList());
 }
Example #24
0
 public Dashboard(int AdminId)
 {
     InitializeComponent();
     this.db        = new CarRentEntities();
     this.adminId   = AdminId;
     LblAdmin.Text += db.Administrators.Find(this.adminId).Name + " " + db.Administrators.Find(this.adminId).Surname;
     FillDGV();
 }
Example #25
0
        public Task <IApiResult> GetDevice(P_Devices.PDevicesByDeviceID arg)
        {
            return(Task.Run(() =>
            {
                IApiResult hr = new IApiResult();
                try
                {
                    using (CarRentEntities cre = new CarRentEntities())
                    {
                        Func <double, double, bool> inoutChina = (lat, lng) => Mgoo.CarRent.Position.ZCChinaLocation.InOutChina(Convert.ToDouble(lat), Convert.ToDouble(lng));

                        var devs = from d in cre.Devices
                                   join l in cre.LKLocation
                                   on d.DeviceID equals l.DeviceID
                                   into dl
                                   from dli in dl.DefaultIfEmpty()
                                   where d.DeviceID == arg.deviceid && d.Deleted == false
                                   // let po =   new Position.Point(Convert.ToDouble(dli.OLat ?? -1.00m), Convert.ToDouble(dli.OLng ?? -1.00m))
                                   //let isChina = inoutChina(po.Lat, po.Lng)
                                   //let point = isChina ? new Position.Point(po.Lat, po.Lng) : Position.PositionUtil.gps84_To_Gcj02(po.Lat, po.Lng)
                                   select new Models.Return.R_Devices.GetDevice_Result
                        {
                            DeviceID = d.DeviceID,
                            DeviceName = d.DeviceName,
                            SerialNumber = d.SerialNumber,
                            Status = d.Status,
                            DataContext = dli.DataContext ?? "",
                            Lat = dli.OLat ?? -1.00m,
                            Lng = dli.OLng ?? -1.00m,
                            Speed = dli.Speed ?? default(decimal),
                            LastCommunication = dli.LastCommunication == null ? default(DateTime) : dli.LastCommunication,
                            Course = dli.Course ?? default(decimal),
                            IsStop = dli.IsStop ?? default(int)
                        };
                        var list = devs.ToList();
                        list.ForEach((item) =>
                        {
                            //如果是在中国大陆则需要转换一下坐标
                            if (Position.ZCChinaLocation.InOutChina(Convert.ToDouble(item.Lat), Convert.ToDouble(item.Lng)))
                            {
                                Position.Point point = Position.PositionUtil.gps84_To_Gcj02(Convert.ToDouble(item.Lat), Convert.ToDouble(item.Lng));
                                item.Lng = Convert.ToDecimal(point.Lng);
                                item.Lat = Convert.ToDecimal(point.Lat);
                            }
                        });
                        hr.result = list;
                        hr.message = $"查询到{list.Count}条数据.";
                    }
                }
                catch (Exception ex)
                {
                    hr.message = ex.Message;
                    hr.code = StatusCode.error;
                    Log.Error(this, ex);
                }
                return hr;
            }));
        }
Example #26
0
 public Login()
 {
     InitializeComponent();
     this.CenterToScreen();
     this.db      = new CarRentEntities();
     pbx.Visible  = false;
     pbx2.Visible = false;
     txtPass.UseSystemPasswordChar = true;
 }
Example #27
0
        public ActionResult getLoginData(UserModel obj)
        {
            CarRentEntities db   = new CarRentEntities();
            var             user = db.Users.FirstOrDefault(x => x.login.Equals(obj.Login) && x.password.Equals(obj.Password));

            return(new JsonResult {
                Data = user, JsonRequestBehavior = JsonRequestBehavior.AllowGet
            });
        }
Example #28
0
 public CarsOptions(int adminId)
 {
     InitializeComponent();
     this.db        = new CarRentEntities();
     this.AdminId   = adminId;
     LblAdmin.Text += db.Administrators.Find(this.AdminId).Name + " " + db.Administrators.Find(this.AdminId).Surname;
     FillDGV();
     FillCbCarBrand();
 }
Example #29
0
 public NewRent(int AdminId)
 {
     InitializeComponent();
     this.db        = new CarRentEntities();
     this.adminId   = AdminId;
     LblAdmin.Text += db.Administrators.Find(this.adminId).Name + " " + db.Administrators.Find(this.adminId).Surname;
     FillCbName();
     FillCbCarBrand();
 }
Example #30
0
 public Reports(int UserId)
 {
     InitializeComponent();
     this.Size = new Size(1430, 650);
     this.CenterToScreen();
     this.db     = new CarRentEntities();
     this.userId = UserId;
     FillDgv(db.Orders.ToList());
 }