Example #1
0
        public tblCar GetCar(int id)
        {
            string connStr = ConfigurationManager.ConnectionStrings["AdoConnStr"].ConnectionString;

            using (SqlConnection connection = new SqlConnection(connStr))
            {
                connection.Open();

                SqlCommand command = new SqlCommand();
                command.Connection  = connection;
                command.CommandText = $"select * from tblCar where Car_ID = {id}";

                var reader = command.ExecuteReader();

                tblCar car;
                while (reader.Read())
                {
                    car = new tblCar
                    {
                        Car_ID       = Convert.ToInt32(reader["Car_ID"].ToString()),
                        SerialNumber = reader["SerialNumber"].ToString(),
                        Make         = reader["Make"].ToString(),
                        Model        = reader["Model"].ToString(),
                        Color        = reader["Color"].ToString(),
                        Year         = Convert.ToInt16(reader["Year"]),
                        CarForSale   = Convert.ToBoolean(reader["CarForSale"])
                    };
                    return(car);
                }
                return(null);
            }
        }
Example #2
0
        public ActionResult GeneralReport(string from, string to)
        {
            try
            {
                string path = Path.Combine(Server.MapPath("~/Reports"), "car.rdlc");
                if (!System.IO.File.Exists(path) || string.IsNullOrEmpty(from) || string.IsNullOrEmpty(to))
                {
                    return View("rptCar");
                }
                tblCar carRpt = new tblCar();
                carRpt.fromDate = Convert.ToDateTime(from);
                carRpt.toDate = Convert.ToDateTime(to);
                List<object> objLst = carRepository.GetCarRpt(carRpt);
                var reportViewModel = carRepository.CarViewModel(objLst, from, to);
                reportViewModel.FileName = path;
                var renderedBytes = reportViewModel.RenderReport();
                if (reportViewModel.ViewAsAttachment)
                {
                    Response.AddHeader("content-disposition", reportViewModel.ReporExportFileName);

                }
                return File(renderedBytes, reportViewModel.LastmimeType);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Example #3
0
        public void AddNewCar(tblCar car)
        {
            DataClasses1DataContext db = new DataClasses1DataContext();

            db.tblCars.InsertOnSubmit(car);
            db.SubmitChanges();
            db.Dispose();
        }
        public bool SaveCar(tblCar objcar)
        {
            int maxId = context.tblCars.Select(p => p.ID).DefaultIfEmpty(0).Max();

            objcar.ID = ++maxId;
            context.tblCars.Add(objcar);
            return(context.SaveChanges() > 0);
        }
Example #5
0
 public bool Add(tblCar car)
 {
     using (var dbContext = new CarDealerDBEntities())
     {
         dbContext.tblCars.Add(car);
         dbContext.SaveChanges();
         return(true);
     }
 }
Example #6
0
        public void UnDeleteCar(string id)
        {
            DataClasses1DataContext db = new DataClasses1DataContext();
            tblCar oldcar = (from table in db.tblCars where table.carID == int.Parse(id) select table).Single();

            oldcar.status = "available";
            db.SubmitChanges();
            db.Dispose();
        }
Example #7
0
 public bool Update(tblCar car)
 {
     return(ExecuteNonQueryCommand($"update tblCar set " +
                                   $"SerialNumber = {car.SerialNumber}, " +
                                   $"Make = '{car.Make}', " +
                                   $"Model = '{car.Model}', " +
                                   $"Color = '{car.Color}', " +
                                   $"Year = '{car.Year}', " +
                                   $"CarForSale = '{car.CarForSale}' " +
                                   $"where Car_ID = {car.Car_ID}"));
 }
        public tblCar getCarByName(string name)
        {
            tblCar result = null;
            DataClasses1DataContext db = new DataClasses1DataContext();
            var com = from table in db.tblCars where table.carName == name select table;

            foreach (var item in com)
            {
                result = item;
            }
            return(result);
        }
Example #9
0
        public void UpdateCar(tblCar carUpdate)
        {
            DataClasses1DataContext db = new DataClasses1DataContext();
            tblCar oldCar = (from table in db.tblCars where table.carID == carUpdate.carID select table).Single();

            oldCar.carName      = carUpdate.carName;
            oldCar.licensePlate = carUpdate.licensePlate;
            oldCar.status       = carUpdate.status;
            oldCar.nearestPhoto = carUpdate.nearestPhoto;
            db.SubmitChanges();
            db.Dispose();
        }
Example #10
0
 public bool Add(tblCar car)
 {
     return(ExecuteNonQueryCommand($"insert into tblCar " +
                                   $"(SerialNumber, Make, Model, Color, Year, CarForSale) " +
                                   $"values ( " +
                                   $"'{car.SerialNumber}', " +
                                   $"'{car.Make}', " +
                                   $"'{car.Model}', " +
                                   $"'{car.Color}', " +
                                   $"'{car.Year}', " +
                                   $"'{car.CarForSale}'" +
                                   $")"));
 }
Example #11
0
 public bool Delete(tblCar car)
 {
     using (var dbContext = new CarDealerDBEntities())
     {
         var dbCar = dbContext.tblCars.FirstOrDefault(x => x.Car_ID == car.Car_ID);
         if (dbCar != null)
         {
             dbContext.tblCars.Remove(dbCar);
             dbContext.SaveChanges();
             return(true);
         }
         return(false);
     }
 }
Example #12
0
        public static CarIF GetCarfullInfor(string carID)
        {
            CarIF result = new CarIF();
            DataClasses1DataContext db = new DataClasses1DataContext();
            tblCar car = db.tblCars.Where(s => s.carID == int.Parse(carID)).Single();

            result.CarId        = car.carID;
            result.CarName      = car.carName;
            result.licensePlate = car.licensePlate;
            result.Status       = car.status;
            result.SetImage(car.nearestPhoto.ToArray());
            db.Dispose();
            return(result);
        }
Example #13
0
 public bool Update(tblCar car)
 {
     using (var dbContext = new CarDealerDBEntities())
     {
         var old = dbContext.tblCars.FirstOrDefault(x => x.Car_ID == car.Car_ID);
         old.SerialNumber = car.SerialNumber;
         old.Make         = car.Make;
         old.Model        = car.Model;
         old.Color        = car.Color;
         old.Year         = car.Year;
         old.CarForSale   = car.CarForSale;
         dbContext.SaveChanges();
         return(true);
     }
 }
Example #14
0
        public bool Delete()
        {
            Console.Write("enter car id to delete: ");
            int id  = Convert.ToInt32(Console.ReadLine());
            var car = new tblCar
            {
                Car_ID = id
            };
            var carSold = new tblCarsSold
            {
                Car_ID = id
            };

            //CarSoldRepository.Delete(carSold);
            Console.WriteLine("Car deleted successfully!");
            return(Repositories.CarRepository.Delete(car));
        }
Example #15
0
        public void CreateHistory(string carname)
        {
            tblCarDAO dao = new tblCarDAO();
            tblCar    car = dao.getCarByName(carname);

            if (dao.Getposition(car.carID) != null)
            {
                DataClasses1DataContext db = new DataClasses1DataContext();

                var carpark = (from table in db.tblCarParks where table.position == dao.Getposition(car.carID) select table).SingleOrDefault();
                if (carpark.timeIn == null)
                {
                    carpark.timeIn = DateTime.Now;
                }
                db.SubmitChanges();

                tblHistory his = new tblHistory();
                his.carID    = car.carID;
                his.position = dao.Getposition(car.carID);
                his.timeIn   = DateTime.Now;
                his.userID   = car.userID;
                Random rd = new Random();
                his.keyCode = rd.Next(1000, 9999).ToString();

                db.tblHistories.InsertOnSubmit(his);
                db.SubmitChanges();
                var caru = (from table in db.tblCars where table.carName == carname select table).Single();
                caru.status = "activated";
                db.SubmitChanges();

                string phone = (from table in db.tblUsers
                                where table.userID
                                == car.userID
                                select table.phoneNumber).Single();
                SMSSender sms         = new SMSSender();
                bool      checksended = sms.sendSMS(phone, his.keyCode);
                if (checksended == true)
                {
                    System.Windows.Forms.MessageBox.Show("your keycode is already sended!!!");
                }
            }
            else
            {
                System.Windows.Forms.MessageBox.Show("you have no place in plan");
            }
        }
Example #16
0
        public void GetCar()
        {
            Console.Write("enter car id: ");
            Int32.TryParse(Console.ReadLine(), out int id);
            tblCar car = Repositories.CarRepository.GetCar(id);

            if (car != null)
            {
                Console.WriteLine($"" +
                                  $"Car ID: {car.Car_ID}\n" +
                                  $"Serial number: {car.SerialNumber}\n" +
                                  $"Make: {car.Make}\n" +
                                  $"Model: {car.Model}\n" +
                                  $"Color: {car.Color}\n" +
                                  $"Year: {car.Year}\n" +
                                  $"Car for sale?: {car.CarForSale}\n");
            }
        }
Example #17
0
 public JsonResult EditCar(tblCar objCar)
 {
     if (Session["role"] == null)
     {
         Session["userId"] = null;
         Session["role"] = null;
         return Json(null, JsonRequestBehavior.AllowGet);
     }
     else if (Session["role"].ToString() == "Super Admin")
     {
         return Json(carRepository.EditCar(objCar), JsonRequestBehavior.AllowGet);
     }
     else
     {
         Session["userId"] = null;
         Session["role"] = null;
         return Json(null, JsonRequestBehavior.AllowGet);
     }
 }
        private void btnSave_Click(object sender, EventArgs e)
        {
            bool check = ValidationFeild();

            if (check == true)
            {
                tblCar car  = new tblCar();
                CarIF  data = new CarIF();
                car.carName = txtCarName.Text;
                if (txtLicensePlate.Text == null || txtLicensePlate.Text == "")
                {
                    if (readLicense(PicBoxCarLicence.Image) == null)
                    {
                        MessageBox.Show("Can't read license.Please give another picture");
                    }
                    else
                    {
                        car.licensePlate = readLicense(PicBoxCarLicence.Image);
                    }
                }
                else
                {
                    car.licensePlate = txtLicensePlate.Text;
                }
                MemoryStream ms = new MemoryStream();
                PicBoxCarLicence.Image.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
                car.nearestPhoto = ms.ToArray();
                car.status       = "activated";
                car.userID       = cbUser.SelectedItem.ToString();
                CarDAO dao = new CarDAO();
                dao.AddNewCar(car);
                data = CarDAO.GetCarfullInforByName(car.carName);
                parent.Getdata(data);
                MessageBox.Show("Add car success!");
                this.Close();
            }
        }
        public void CreateHistory(string carname)
        {
            cameraCheck camc = new cameraCheck();
            tblCar      car  = camc.getCarByName(carname);

            if (camc.Getposition(car.carID) != 0)
            {
                DataClasses1DataContext db = new DataClasses1DataContext();

                tblHistory his = new tblHistory();
                his.carID    = car.carID;
                his.position = camc.Getposition(car.carID).ToString();
                his.timeIn   = DateTime.Now;
                his.userID   = car.userID;
                Random rd = new Random();
                his.keyCode = rd.Next(1000, 9999).ToString();

                db.tblHistories.InsertOnSubmit(his);
                db.SubmitChanges();

                string phone = (from table in db.tblUsers
                                where table.userID
                                == car.userID
                                select table.phoneNumber).Single();
                SMSSender sms         = new SMSSender();
                bool      checksended = sms.sendSMS(phone, his.keyCode);
                if (checksended == true)
                {
                    System.Windows.Forms.MessageBox.Show("your keycode is already sended!!!");
                }
            }
            else
            {
                System.Windows.Forms.MessageBox.Show("you have no place in plan");
            }
        }
        public bool EditCar(tblCar car)
        {
            context.Entry(car).State = EntityState.Modified;

            return(context.SaveChanges() > 0);
        }
        public List <object> GetCarRpt(tblCar carRpt)
        {
            var carLst = context.tblCars.Where(pp => pp.carWeightDate >= carRpt.fromDate && pp.carWeightDate <= carRpt.toDate).ToList();

            return(carLst.ToList <object>());
        }
Example #22
0
 public bool Delete(tblCar car)
 {
     return(ExecuteNonQueryCommand($"delete from tblCar where Car_ID = {car.Car_ID}"));
 }