コード例 #1
0
        private void btnAddCl_Click(object sender, EventArgs e)
        {
            if (!string.IsNullOrWhiteSpace(txtFname.Text) &&
                !string.IsNullOrWhiteSpace(txtLname.Text) &&
                !string.IsNullOrWhiteSpace(dtpBirthDate.Text) &&
                !string.IsNullOrWhiteSpace(txtCardId.Text) &&
                !string.IsNullOrWhiteSpace(txtPhoneNumber.Text))
            {
                Clients cl = new Clients();


                cl.FirstName   = txtFname.Text;
                cl.LastName    = txtLname.Text;
                cl.BirthDate   = dtpBirthDate.Value;
                cl.CardId      = txtCardId.Text;
                cl.PhoneNumber = txtPhoneNumber.Text;
                cl.AddedDate   = DateTime.Now;

                db.Clients.Add(cl);
                db.SaveChanges();
                Reset();

                MessageBox.Show("Client added succesfully!");
                FillDgv(db.Clients.ToList());
            }
        }
コード例 #2
0
        private void btnAddW_Click(object sender, EventArgs e)
        {
            if (!string.IsNullOrWhiteSpace(txtFwname.Text) &&
                !string.IsNullOrWhiteSpace(txtLwname.Text) &&
                !string.IsNullOrWhiteSpace(dtpwBirthDate.Text) &&
                !string.IsNullOrWhiteSpace(txtwCardId.Text) &&
                !string.IsNullOrWhiteSpace(txtwPhoneNumber.Text))
            {
                Workers wr = new Workers();


                wr.FirstName   = txtFwname.Text;
                wr.LastName    = txtLwname.Text;
                wr.BirthDate   = dtpwBirthDate.Value;
                wr.CardId      = txtwCardId.Text;
                wr.PhoneNumber = txtwPhoneNumber.Text;
                wr.Email       = txtEmail.Text;
                wr.AddedDate   = DateTime.Now;

                db.Workers.Add(wr);
                db.SaveChanges();
                Reset();

                MessageBox.Show("Client added succesfully!");
                FillDgv(db.Workers.ToList());
            }
        }
コード例 #3
0
        private void BtnSave_Click(object sender, EventArgs e)
        {
            int CarId = 0;

            if (!string.IsNullOrEmpty(TxtCarName.Text) &&
                !string.IsNullOrEmpty(TxtCarModel.Text) &&
                NumEngine.Value > 0 && !string.IsNullOrEmpty(TxtRegNum.Text) &&
                NumPrice.Value > 0 && NumYear.Value > 1900)
            {
                if (CbCarBrand.Text != "Choose" && TxtCarName.Text == CbCarBrand.Text)
                {
                    if (db.CarNames.FirstOrDefault(c => c.Name == CbCarBrand.Text) != null)
                    {
                        CarId = db.CarNames.FirstOrDefault(c => c.Name == CbCarBrand.Text).Id;
                    }
                    CarNames      carBrand = db.CarNames.Find(CarId);
                    AvailableCars car      = db.AvailableCars.Find(CarId);
                    carBrand.Id       = CarId;
                    car.Model         = TxtCarModel.Text;
                    car.Engine        = Convert.ToDecimal(NumEngine.Value);
                    car.Year          = Convert.ToInt32(NumYear.Value);
                    car.RegNumber     = TxtRegNum.Text;
                    car.Price         = Convert.ToDecimal(NumPrice.Value);
                    car.CarNameId     = CarId;
                    car.EditedAddedBy = this.AdminId;
                    db.AvailableCars.Add(car);
                }
                else
                {
                    if (db.CarNames.FirstOrDefault(c => c.Name == TxtCarName.Text) != null)
                    {
                        CarId = db.CarNames.FirstOrDefault(c => c.Name == TxtCarName.Text).Id;
                    }
                    AvailableCars car      = new AvailableCars();
                    CarNames      carBrand = new CarNames();
                    carBrand.Name     = TxtCarName.Text;
                    car.Model         = TxtCarModel.Text;
                    car.Engine        = Convert.ToDecimal(NumEngine.Value);
                    car.Year          = Convert.ToInt32(NumYear.Value);
                    car.RegNumber     = TxtRegNum.Text;
                    car.Price         = Convert.ToDecimal(NumPrice.Value);
                    car.CarNameId     = CarId;
                    car.EditedAddedBy = this.AdminId;
                    db.CarNames.Add(carBrand);
                    db.AvailableCars.Add(car);
                }

                db.SaveChanges();
                MessageBox.Show("You Have Added New Car!");
                FillDGV();
                FillCbCarBrand();
            }
            else
            {
                LblWarning.Text = "Please Enter all (*) details!";
            }
        }
コード例 #4
0
 public ActionResult getUserData(User usr)
 {
     usr.active = true;
     db.Users.Add(usr);
     db.SaveChanges();
     return(new JsonResult {
         Data = usr, JsonRequestBehavior = JsonRequestBehavior.AllowGet
     });
 }
コード例 #5
0
ファイル: CarsController.cs プロジェクト: daw7/carRentProject
        public ActionResult Create([Bind(Include = "tp_carID,active,type,segment,priceGross,priceNet,deposit,brand,model")] Car car)
        {
            if (ModelState.IsValid)
            {
                db.Cars.Add(car);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(car));
        }
コード例 #6
0
ファイル: Customers.cs プロジェクト: Shabnam-13/CarRent
        private void btnUp_Click(object sender, EventArgs e)
        {
            Customer customer = db.Customers.Find(Id);

            customer.FirstName      = txtName.Text;
            customer.LastName       = txtSname.Text;
            customer.Phone          = txtPhone.Text;
            customer.Identification = txtIden.Text;
            customer.Email          = txtEmail.Text;
            customer.Address        = txtAddress.Text;

            db.SaveChanges();
            fillDgv(db.Customers.ToList());
            Reset();
        }
コード例 #7
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);
     }
 }
コード例 #8
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);
            }
        }
コード例 #9
0
        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);
            }
        }
コード例 #10
0
        private void btnConfirm_Click(object sender, EventArgs e)
        {
            Orders o = db.Orders.Find(selectedId);

            o.DeliveryDate = dtpDeliveryDate.Value;
            o.Id           = selectedId;

            if (o.DropOffDate.Value < o.DeliveryDate.Value)
            {
                int days       = Convert.ToInt32((o.DropOffDate - o.PickUpDate).Value.TotalDays);
                int penDays    = Convert.ToInt32((o.DeliveryDate.Value - o.DropOffDate).Value.TotalDays);
                int price      = Convert.ToInt32(o.Cars.Price.Value * days);
                int penPrice   = Convert.ToInt32((o.Cars.Price.Value * 120 / 100) * penDays);
                int totalPrice = penPrice + price;

                if (dtpDeliveryDate.Value != null)
                {
                    o.Cars.IsInGarage = true;
                }

                o.CarPrice     = price;
                o.PenaltyPrice = penPrice;
                o.TotalPrice   = totalPrice;
            }
            db.SaveChanges();
            this.Close();
            ExpiredOrders ex = new ExpiredOrders(userId);

            ex.Show();
            MessageBox.Show("Delivery Accepted!");
        }
コード例 #11
0
        private void BtnUpdate_Click(object sender, EventArgs e)
        {
            string    oldName  = TxtFirstName.Text;
            Customers customer = db.Customers.Find(this._selectedId);

            customer.Name           = TxtFirstName.Text;
            customer.Surname        = TxtLastName.Text;
            customer.Email          = TxtEmail.Text;
            customer.Address        = RtbAddress.Text;
            customer.Phone          = TxtPhone.Text;
            customer.Identification = TxtId.Text;
            customer.EditedAddedBy  = this.adminId;
            db.SaveChanges();
            MessageBox.Show("You Have Updated " + oldName + " to " + customer.Name);
            FillDGV();
        }
コード例 #12
0
ファイル: Device.cs プロジェクト: mgoogps/carrent
        /// <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;
            }));
        }
コード例 #13
0
        private void btnReg_Click(object sender, EventArgs e)
        {
            if (!string.IsNullOrWhiteSpace(txtName.Text) && !string.IsNullOrWhiteSpace(txtSname.Text) &&
                !string.IsNullOrWhiteSpace(txtPhone.Text) && !string.IsNullOrWhiteSpace(txtIden.Text))
            {
                if (db.Customers.FirstOrDefault(id => id.Identification == txtIden.Text) == null)
                {
                    Customer customer = new Customer();
                    customer.FirstName      = txtName.Text;
                    customer.LastName       = txtSname.Text;
                    customer.Phone          = txtPhone.Text;
                    customer.Email          = txtEmail.Text;
                    customer.Identification = txtIden.Text;
                    customer.Address        = txtAddress.Text;
                    customer.AddedDate      = DateTime.Now;

                    CustomerId = customer.Id;

                    db.Customers.Add(customer);
                    db.SaveChanges();
                    MessageBox.Show("Customer added successfully!");
                    btnChooseCar.Visible = true;
                }
                else
                {
                    lblError.Text = "This customer already exists.";
                }
            }
            else
            {
                lblError.Text = "Please fill all required(*) data!";
            }
        }
コード例 #14
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;
            }));
        }
コード例 #15
0
 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);
     }
 }
コード例 #16
0
        private void btnAddOrder_Click(object sender, EventArgs e)
        {
            if (!string.IsNullOrWhiteSpace(txtFname.Text) &&
                !string.IsNullOrWhiteSpace(txtLname.Text) &&
                !string.IsNullOrWhiteSpace(cmbMake.Text) &&
                !string.IsNullOrWhiteSpace(cmbModel.Text) &&
                !string.IsNullOrWhiteSpace(cmbColor.Text) &&
                !string.IsNullOrWhiteSpace(cmbCity.Text) &&
                !string.IsNullOrWhiteSpace(txtEngine.Text) &&
                !string.IsNullOrWhiteSpace(numPrice.Value.ToString()))
            {
                Orders o = new Orders();

                this.selectedCarId    = Convert.ToInt32(dgvCars.CurrentRow.Cells[0].Value);
                this.selectedClientId = Convert.ToInt32(dgvClients.CurrentRow.Cells[0].Value);

                o.CarId       = this.selectedCarId;
                o.ClientId    = this.selectedClientId;
                o.PickUpDate  = dtpPickUp.Value;
                o.DropOffDate = dtpDropOff.Value;
                o.CarPrice    = Convert.ToInt32(numPrice.Value);

                db.Orders.Add(o);
                db.SaveChanges();
                Reset();
                MessageBox.Show("Car rented successfully!");
            }
            else
            {
                MessageBox.Show("Please fill out all fields");
            }
        }
コード例 #17
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);
        }
コード例 #18
0
ファイル: Device.cs プロジェクト: mgoogps/carrent
 /// <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;
     }));
 }
コード例 #19
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);
     }
 }
コード例 #20
0
        private void btnAddCar_Click(object sender, EventArgs e)
        {
            if (!string.IsNullOrWhiteSpace(cmbMake.Text) &&
                !string.IsNullOrWhiteSpace(cmbModel.Text) &&
                !string.IsNullOrWhiteSpace(cmbColor.Text) &&
                !string.IsNullOrWhiteSpace(cmbCity.Text) &&
                !string.IsNullOrWhiteSpace(txtEngine.Text) &&
                !string.IsNullOrWhiteSpace(numPrice.Value.ToString()))
            {
                Cars c = new Cars();
                if (db.Makes.FirstOrDefault(m => m.Name == cmbMake.Text) != null)
                {
                    c.MakeId = db.Makes.FirstOrDefault(m => m.Name == cmbMake.Text).Id;
                }

                if (db.CarModels.FirstOrDefault(cm => cm.Name == cmbModel.Text) != null)
                {
                    c.CarModelId = db.CarModels.FirstOrDefault(cm => cm.Name == cmbModel.Text).Id;
                }

                if (db.Colors.FirstOrDefault(cl => cl.Name == cmbColor.Text) != null)
                {
                    c.ColorId = db.Colors.FirstOrDefault(cl => cl.Name == cmbColor.Text).Id;
                }

                if (db.Cities.FirstOrDefault(ct => ct.Name == cmbCity.Text) != null)
                {
                    c.CityId = db.Cities.FirstOrDefault(ct => ct.Name == cmbCity.Text).Id;
                }

                c.EngineCapacity = Convert.ToDecimal(txtEngine.Text);
                c.Year           = Convert.ToInt32(numYear.Value);
                c.Price          = Convert.ToInt32(numPrice.Value);
                c.AddedDate      = DateTime.Now;

                db.Cars.Add(c);
                db.SaveChanges();
                Reset();

                MessageBox.Show("Car added succesfully!");
                FillDgv(db.Cars.ToList());
            }
        }
コード例 #21
0
 public static void addUser(User userInfo)
 {
     userInfo.Password = Encrypt(userInfo.Password, userInfo.Email);
     //string Decrypted = Decrypt(Encrypted, EncryptionKey);
     using (CarRentEntities db = new CarRentEntities())
     {
         db.Users.Add(userInfo);
         db.SaveChanges();
     }
 }
コード例 #22
0
 private void BtnSave_Click(object sender, EventArgs e)
 {
     if (!string.IsNullOrWhiteSpace(TxtFirstName.Text) &&
         !string.IsNullOrWhiteSpace(TxtLastName.Text) &&
         !string.IsNullOrWhiteSpace(TxtUserName.Text) &&
         !string.IsNullOrWhiteSpace(TxtPassword.Text) &&
         !string.IsNullOrWhiteSpace(TxtPhone.Text) &&
         !string.IsNullOrWhiteSpace(TxtEmail.Text) &&
         !string.IsNullOrWhiteSpace(RtbAddress.Text) &&
         !string.IsNullOrWhiteSpace(TxtId.Text))
     {
         if (db.Administrators.FirstOrDefault(a => a.Username == TxtUserName.Text) == null)
         {
             Administrators admin = new Administrators();
             admin.Name           = TxtFirstName.Text;
             admin.Surname        = TxtLastName.Text;
             admin.Username       = TxtUserName.Text;
             admin.Password       = TxtPassword.Text;
             admin.Email          = TxtEmail.Text;
             admin.Address        = RtbAddress.Text;
             admin.Phone          = TxtPhone.Text;
             admin.Identification = TxtId.Text;
             admin.AddedEditedBy  = this.adminId;
             db.Administrators.Add(admin);
             db.SaveChanges();
             LblWarning.Text = "";
             MessageBox.Show(" " + TxtFirstName.Text + " " + TxtLastName.Text + " As An Admin");
             FillDGV();
         }
         else
         {
             LblWarning.Text = "This Username exists,Please choose another one";
         }
     }
     else
     {
         LblWarning.Text = "Please Enter all (*) details!";
     }
 }
コード例 #23
0
ファイル: Employees.cs プロジェクト: Shabnam-13/CarRent
        private void btnAdd_Click(object sender, EventArgs e)
        {
            if (!string.IsNullOrWhiteSpace(txtName.Text) && !string.IsNullOrWhiteSpace(txtSname.Text) &&
                !string.IsNullOrWhiteSpace(txtPhone.Text) && numAge.Value != 0 && !string.IsNullOrWhiteSpace(txtPos.Text) &&
                !string.IsNullOrWhiteSpace(txtUname.Text) && !string.IsNullOrWhiteSpace(txtPass.Text))
            {
                if (db.Employees.FirstOrDefault(u => u.UserName == txtUname.Text) == null)
                {
                    Employee emp = new Employee();
                    emp.FirstName = txtName.Text;
                    emp.LastName  = txtSname.Text;
                    emp.UserName  = txtUname.Text;
                    emp.Age       = Convert.ToInt32(numAge.Value);
                    emp.Position  = txtPos.Text;
                    emp.Phone     = txtPhone.Text;
                    emp.Email     = txtEmail.Text;
                    emp.Address   = txtAddress.Text;
                    emp.AddedDate = DateTime.Now;
                    emp.Password  = txtPass.Text;

                    db.Employees.Add(emp);
                    db.SaveChanges();
                    MessageBox.Show("Employee added successfully!");
                    Reset();
                    fillDgv(db.Employees.ToList());
                }
                else
                {
                    lblError.Text = "This user name already exists";
                }
            }
            else
            {
                lblError.Text = "Please fill all required(*) data!";
            }
        }
コード例 #24
0
        private void BtnClose_Click(object sender, EventArgs e)
        {
            int carId = db.CarsOnRent.FirstOrDefault(c => c.AvailableCars.RegNumber == this.CarNumber).Id;

            if (db.CarsOnRent.Find(carId) != null)
            {
                CarsOnRent carAccept = db.CarsOnRent.Find(carId);
                carAccept.AcceptedDate = DtpAcceptedDate.Value;
                db.SaveChanges();
                MessageBox.Show("Deal Has Been Closed");
                this.Close();
                RentedCars rented = new RentedCars(this.AdminId);
                rented.Show();
            }
        }
コード例 #25
0
ファイル: Device.cs プロジェクト: mgoogps/carrent
        public Task <IApiResult> EndRental(P_Devices.PDevicesByDeviceID arg)
        {
            return(Task.Run(() =>
            {
                IApiResult hr = new IApiResult();
                using (CarRentEntities db = new CarRentEntities())
                {
                    try
                    {
                        var leaser = (from lr in db.LeaseRecord where lr.DeviceID == arg.deviceid && lr.Status == 2 select lr).SingleOrDefault();
                        if (leaser == null)
                        {
                            hr.message = "Can not find element.";//未找到状态为 2 的设备
                            hr.code = StatusCode.failure;
                            return hr;
                        }
                        var dev = (from d in db.Devices where d.DeviceID == leaser.DeviceID select d).Single();
                        var user = db.Users.Find(dev.UserID);
                        var endTime = DateTime.Now;
                        TimeSpan ts = (endTime - leaser.StartTime).Value;
                        if (ts.TotalMinutes <= 5)
                        {
                            hr.message = "Free for five minutes!";
                        }
                        else
                        {
                            ///结束租车后,扣除用户余额里面的 点数
                            var mi = Math.Ceiling((ts.TotalMinutes - 5) / 60);
                            var money = Convert.ToInt32(mi * user.ActivationCount);
                            leaser.Fee = money;
                            user.MoneyCount = user.MoneyCount - money;
                            hr.message = "Charges are successful!";
                        }

                        dev.Status = 0;                                                //Status (1:已租,0:未租)
                        leaser.Status = CarRent.Common.Lib.CarStatus.Complete.toInt(); //1 已申请,等待确认,2 正在出租,3出租完成,4已拒绝
                        leaser.EndTime = endTime;
                        db.SaveChanges();
                    }
                    catch (Exception ex)
                    {
                        hr.message = ex.Message;
                        hr.code = StatusCode.error;
                    }
                }
                return hr;
            }));
        }
コード例 #26
0
 public static bool addCarForRent(CarsForRent carForRent)
 {
     using (CarRentEntities db = new CarRentEntities())
     {
         try
         {
             db.CarsForRents.Add(carForRent);
             db.SaveChanges();
             return(true);
         }
         catch
         {
             return(false);
         }
     }
 }
コード例 #27
0
 public static bool addRent(RentCar rent)
 {
     using (CarRentEntities db = new CarRentEntities())
     {
         try
         {
             db.RentCars.Add(rent);
             db.SaveChanges();
             return(true);
         }
         catch
         {
             return(false);
         }
     }
 }
コード例 #28
0
ファイル: NewRent.cs プロジェクト: IlkinOI/CarRentApplocation
 private void BtnRent_Click(object sender, EventArgs e)
 {
     if (CbName.Text != "Choose" &&
         CbSurname.Text != "Choose" &&
         CbBrand.Text != "Choose" &&
         CbModel.Text != "Choose" &&
         CbRegNum.Text != "Choose" &&
         DtpRentDate.Value.Date >= DateTime.Now.Date &&
         DtpReturnDate.Value.Date > DateTime.Now.Date &&
         DtpReturnDate.Value.Date > DtpRentDate.Value.Date)
     {
         int?CustomerId = null;
         int?carId      = null;
         if (db.Customers.FirstOrDefault(p => p.Name == CbName.Text && p.Surname == CbSurname.Text) != null)
         {
             CustomerId = db.Customers.FirstOrDefault(p => p.Name == CbName.Text && p.Surname == CbSurname.Text).Id;
         }
         if (db.AvailableCars.FirstOrDefault(c => c.RegNumber == CbRegNum.Text) != null)
         {
             carId = db.AvailableCars.FirstOrDefault(c => c.RegNumber == CbRegNum.Text).Id;
         }
         if (db.CarsOnRent.FirstOrDefault(c => (c.AvailableCars.RegNumber == CbRegNum.Text) &&
                                          (DtpRentDate.Value.Date >= c.RentalDate && DtpRentDate.Value.Date < c.ReturnDate) &&
                                          (DtpReturnDate.Value.Date >= c.RentalDate || DtpReturnDate.Value.Date < c.ReturnDate)) == null)
         {
             CarsOnRent car = new CarsOnRent();
             car.AvailableCarsId = carId;
             car.CustomerId      = CustomerId;
             car.RentalDate      = DtpRentDate.Value.Date;
             car.ReturnDate      = DtpReturnDate.Value.Date;
             car.Price           = db.AvailableCars.FirstOrDefault(c => c.Id == carId).Price.Value;
             car.EditedAddedBy   = this.adminId;
             db.CarsOnRent.Add(car);
             db.SaveChanges();
             MessageBox.Show(CbBrand.Text + " " + CbModel.Text + " " + "Has Been Rented To " + CbName.Text + " " + CbSurname.Text + " !");
             Reset();
         }
         else
         {
             MessageBox.Show("This Car Is Oqqupied On Selected Date!");
         }
     }
     else
     {
         LblWarning.Text = "Please choose all options and/or select proper date";
     }
 }
コード例 #29
0
ファイル: Device.cs プロジェクト: mgoogps/carrent
        public Task <IApiResult> StartRental(P_OnlyOneID arg)
        {
            return(Task.Run(() =>
            {
                IApiResult hr = new IApiResult();
                using (CarRentEntities db = new CarRentEntities())
                {
                    try
                    {
                        var leaser = (from l in db.LeaseRecord where l.LeaseID == arg.id && l.Status == 1 select l).SingleOrDefault();
                        if (leaser == null)
                        {
                            hr.code = StatusCode.failure;
                            hr.message = "Has been rented."; //已经租了
                            return hr;
                        }
                        var dev = (from d in db.Devices where d.DeviceID == leaser.DeviceID select d).SingleOrDefault();
                        var user = db.Users.Find(dev.UserID);
                        if (user.MoneyCount < user.ActivationCount)
                        {
                            hr.code = StatusCode.failure;
                            hr.message = "Insufficient balance."; //用户余额不足
                            return hr;
                        }
                        dev.Status = 1;  //Status (1:已租,0:未租)

                        //var leaser = (from lr in db.LeaseRecord where lr.LeaseID == arg.id select lr).Single();

                        leaser.Status = Mgoo.CarRent.Common.Lib.CarStatus.BeingRented.toInt();  //1 已申请,等待确认,2 正在出租,3出租完成,4已拒绝
                        leaser.StartTime = DateTime.Now;

                        //db.LeaseRecord.UpdateAsync(l => l.LeaseID==arg.id, l=> new LeaseRecord { Status = 2 });

                        db.Entry(leaser).State = System.Data.Entity.EntityState.Modified;
                        db.Entry(dev).State = System.Data.Entity.EntityState.Modified;
                        db.SaveChanges();
                        hr.message = "success!";
                    }
                    catch (Exception ex)
                    {
                        hr.message = ex.Message;
                        hr.code = StatusCode.error;
                    }
                }
                return hr;
            }));
        }
コード例 #30
0
 public static bool updateCarType(CarType carType)
 {
     using (CarRentEntities db = new CarRentEntities())
     {
         try
         {
             db.CarTypes.Add(carType);
             db.Entry(carType).State = System.Data.Entity.EntityState.Modified;
             db.SaveChanges();
             return(true);
         }
         catch (Exception e)
         {
             return(false);
         }
     }
 }