Example #1
0
        private void iconButtonOrder_Click(object sender, EventArgs e)
        {
            EntitiesAutomobiles automobiles = new EntitiesAutomobiles();
            Orders      order = new Orders();
            Users       users = automobiles.Users.Where(x => x.idUser == idUser).FirstOrDefault();
            Automobiles auto  = automobiles.Automobiles.Where(x => x.idAuto == idAuto).FirstOrDefault();

            order.idAuto     = idAuto;
            order.idUser     = idUser;
            order.dateOrder  = DateTime.Now;
            order.dateStart  = dateTimeStart.Value;
            order.dateFinish = dateTimeFinish.Value;
            int n = 0;

            n          = (dateTimeFinish.Value - dateTimeStart.Value).Days + 1;
            order.cost = automobiles.Automobiles.Where(z => z.idAuto == idAuto).Select(x => x.price).FirstOrDefault() * n;

            bool     add = false;
            DateTime start = DateTime.Now, finish = DateTime.Now;

            if (automobiles.Orders.Where(x => x.idAuto == idAuto).Count() == 0)
            {
                add = true;
            }

            foreach (Orders ord in automobiles.Orders.Where(x => x.idAuto == idAuto))
            {
                if ((order.dateStart.Value.Date >= ord.dateStart.Value.Date && order.dateStart.Value.Date <= ord.dateFinish.Value.Date) ||
                    (order.dateFinish.Value.Date >= ord.dateStart.Value.Date && order.dateFinish.Value.Date <= ord.dateFinish.Value.Date) ||
                    (ord.dateStart.Value.Date >= order.dateStart.Value.Date && ord.dateStart.Value.Date <= order.dateFinish.Value.Date) ||
                    (ord.dateFinish.Value.Date >= order.dateStart.Value.Date && ord.dateFinish.Value.Date <= order.dateFinish.Value.Date))
                {
                    start  = ord.dateStart.Value.Date;
                    finish = ord.dateFinish.Value.Date;
                    add    = false;
                    break;
                }
                else
                {
                    add = true;
                }
            }
            if (add)
            {
                labelMessage.ForeColor = Color.GreenYellow;
                labelMessage.Text      = "Авто забронированно";
                automobiles.Orders.Add(order);
            }
            else
            {
                labelMessage.ForeColor = Color.Red;
                labelMessage.Text      = "Автомобиль уже забронирован с " + start.Date.ToString() + " до " + finish.Date.ToString();
            }
            automobiles.SaveChanges();
        }
Example #2
0
        /// <summary>
        /// Takes a vehicle and adds it correctly to the database
        /// </summary>
        /// <typeparam name="T">Any class model that inherits the vehicle model</typeparam>
        /// <param name="vehicle">The input vehicle</param>
        public void AddVehicle <T>(T vehicle) where T : Vehicle
        {
            Automobiles automobile = null;
            string      type       = "";

            if (typeof(T) == typeof(Truck))
            {
                Truck truck = (Truck)(object)vehicle;
                automobile = new Automobiles
                {
                    Colour      = vehicle.colour,
                    DateAdded   = DateTime.Now,
                    Price       = vehicle.price,
                    Name        = vehicle.name,
                    JsonDetails = JsonConvert.SerializeObject(new { truck.boxSize, truck.fourByFour })
                };
                type = "Truck";
            }
            else if (typeof(T) == typeof(Car))
            {
                Car car = (Car)(object)vehicle;
                automobile = new Automobiles
                {
                    Colour      = vehicle.colour,
                    DateAdded   = DateTime.Now,
                    Price       = vehicle.price,
                    Name        = vehicle.name,
                    JsonDetails = JsonConvert.SerializeObject(new { car.doors })
                };
                type = "Car";
            }
            else if (typeof(T) == typeof(Motorbike))
            {
                Motorbike motorbike = (Motorbike)(object)vehicle;
                automobile = new Automobiles
                {
                    Colour      = vehicle.colour,
                    DateAdded   = DateTime.Now,
                    Price       = vehicle.price,
                    Name        = vehicle.name,
                    JsonDetails = JsonConvert.SerializeObject(new { motorbike.passengerSeat })
                };
                type = "Motorbike";
            }
            else
            {
                throw new Exception("Model not yet implemented");
            }

            _automobileRepository.AddAutomobile(automobile, type);
        }
Example #3
0
        public FormOrders()
        {
            InitializeComponent();

            dataGridView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
            dataGridView1.DataSource    = automobiles.Orders.ToList();

            dataGridView1.Columns[0].HeaderText = "ID";
            dataGridView1.Columns[1].HeaderText = "Id Auto";
            dataGridView1.Columns[2].HeaderText = "ID User";
            dataGridView1.Columns[3].HeaderText = "Дата заказа";
            dataGridView1.Columns[4].HeaderText = "Начало аренды";
            dataGridView1.Columns[5].HeaderText = "Конец аренды";
            dataGridView1.Columns[6].HeaderText = "Стоимость";

            //DataGridViewTextBoxColumn column = new DataGridViewTextBoxColumn();

            //dataGridView1.Columns.Add(column);
            //dataGridView1.Columns[9].HeaderText = "Авто";
            //dataGridView1.Columns[9].Name = "Авто";

            int n = dataGridView1.Columns.Count;

            for (int i = 0; i < n; i++)
            {
                dataGridView1.Columns[i].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
            }


            //n = dataGridView1.Rows.Count;
            //for (int i = 0; i < n; i++)
            //{
            //    auto= automobiles.Automobiles.Where(x => x.idAuto ==
            //       Int32.Parse(dataGridView1.Rows[i].Cells[9].Value.ToString())).FirstOrDefault();
            //    dataGridView1[9, i].Value = auto.Brands.nameBrand + " " + auto.Models.nameModel;
            //}

            Automobiles auto = new Automobiles();

            //foreach (DataGridViewRow row in dataGridView1.Rows)
            //{
            //    int idauto = Int32.Parse(row.Cells[1].Value.ToString());
            //    auto = automobiles.Automobiles.Where(x => x.idAuto == idauto).FirstOrDefault();
            //    row.Cells[9].Value = (auto.Brands.nameBrand + "  11 " + auto.Models.nameModel).ToString();
            //}
            //dataGridView1[9, 1].Value = "dsdsds";
            dataGridView1.Columns[7].Visible = false;
            dataGridView1.Columns[8].Visible = false;
        }
Example #4
0
        public async Task <IActionResult> OnGetAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            Automobiles = await _context.Automobiles
                          .Include(a => a.ManId).FirstOrDefaultAsync(m => m.AID == id);

            if (Automobiles == null)
            {
                return(NotFound());
            }
            return(Page());
        }
Example #5
0
        public async Task <IActionResult> OnPostAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            Automobiles = await _context.Automobiles.FindAsync(id);

            if (Automobiles != null)
            {
                _context.Automobiles.Remove(Automobiles);
                await _context.SaveChangesAsync();
            }

            return(RedirectToPage("./Index"));
        }
Example #6
0
        public async Task <IActionResult> OnGetAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            Automobiles = await _context.Automobiles
                          .Include(a => a.ManId).FirstOrDefaultAsync(m => m.AID == id);

            if (Automobiles == null)
            {
                return(NotFound());
            }
            ViewData["MID"] = new SelectList(_context.Set <Manufacturers>(), "MID", "MID");
            return(Page());
        }
Example #7
0
 public void AddAuto(Automobile a)
 {
     Automobiles.Add(a);
 }
Example #8
0
        public FormInfoAuto(int idauto, int iduser)
        {
            InitializeComponent();
            automobiles = new EntitiesAutomobiles();

            InfoUser info = new InfoUser();

            idUser = info.getidUser();
            Users user = automobiles.Users.Where(x => x.idUser == idUser).FirstOrDefault();

            idAuto = idauto;

            if (user.admin.Value)
            {
                iconButtonOrder.Visible = false;
                btnIzm.Visible          = true;
                labelBrand.ReadOnly     = false;
                labelModel.ReadOnly     = false;
                labelYear.ReadOnly      = false;
                labelPrice.ReadOnly     = false;
            }
            else
            {
                iconButton1.Visible = false;
                iconButton2.Visible = false;
                btnIzm.Visible      = false;
                labelBrand.ReadOnly = true;
                labelModel.ReadOnly = true;
                labelYear.ReadOnly  = true;
                labelPrice.ReadOnly = true;
            }

            auto = automobiles.Automobiles.Where(x => x.idAuto == idAuto).FirstOrDefault();

            listView1.LargeImageList = imageList1;
            imageList1.ImageSize     = new Size(100, 100);

            List <string> images = auto.Images.
                                   Where(x => x.idAuto == auto.idAuto)
                                   .Select(x => x.image).ToList();
            int j = 0;

            foreach (string el in images)
            {
                try
                {
                    imageList1.Images.Add(Image.FromFile(el));
                    i++;
                }
                catch
                {
                    MessageBox.Show(
                        "Файл не открывается",
                        "Сообщение",
                        MessageBoxButtons.OK,
                        MessageBoxIcon.Error,
                        MessageBoxDefaultButton.Button1);
                }

                // установка названия файла
                ListViewItem lvi = new ListViewItem();
                //lvi.Text = file.Remove(0, file.LastIndexOf('\\') + 1);

                lvi.Tag        = el;
                lvi.ImageIndex = j; // установка картинки для файла

                listView1.Items.Add(lvi);
                j++;
            }
            labelBrand.Text = auto.Brands.nameBrand;
            labelModel.Text = auto.Models.nameModel;
            labelPrice.Text = auto.price.ToString();
            labelYear.Text  = auto.yearModel.ToString();
            pictureBox1.Load(listView1.Items[0].Tag.ToString());
        }
Example #9
0
 static void Main(string[] args)
 {
     Automobiles objAutomobiles = new Automobiles("Chassies");
 }
Example #10
0
        public Auto automobileSearch(String searchString)
        {
            var findautomobile = Automobiles.Where(automobile => automobile.ID.Equals(searchString)).SingleOrDefault();

            return(findautomobile);
        }
Example #11
0
 public void automobileRegistration(Auto autoautomobile)
 {
     Automobiles.Add(autoautomobile);
 }
Example #12
0
        public static void Main()
        {
            Automobiles auto = new Automobiles("Mercedes");

            Console.ReadKey();
        }
Example #13
0
        private void addBtn_Click(object sender, EventArgs e)
        {
            EntitiesAutomobiles automobiles = new EntitiesAutomobiles();
            string brandN = textBrand.Text;
            string modelN = textModel.Text;
            string classN = textClass.Text;
            string kppN   = textKPP.Text;


            Automobiles auto = new Automobiles();

            auto.price     = decimal.Parse(textPrice.Text);
            auto.yearModel = Int32.Parse(textYear.Text);

            if (brandN != "")
            {
                Brands brand = automobiles.Brands.Where(x => x.nameBrand == brandN).FirstOrDefault();
                if (brand == null)
                {
                    Brands newBrand = new Brands
                    {
                        nameBrand = brandN
                    };
                    automobiles.Brands.Add(newBrand);
                    automobiles.SaveChanges();
                    brand        = automobiles.Brands.Where(x => x.nameBrand == brandN).FirstOrDefault();
                    auto.idBrand = brand.idBrand;
                }
                else
                {
                    auto.idBrand = brand.idBrand;
                }
            }

            if (modelN != "" && classN != "")
            {
                Models model = automobiles.Models.Where(x => x.nameModel == modelN && x.classModel == classN).FirstOrDefault();
                if (model == null)
                {
                    Models newModel = new Models
                    {
                        nameModel  = modelN,
                        classModel = classN
                    };
                    automobiles.Models.Add(newModel);
                    automobiles.SaveChanges();
                    model        = automobiles.Models.Where(x => x.nameModel == modelN && x.classModel == classN).FirstOrDefault();
                    auto.idModel = model.idModel;
                }
                else
                {
                    auto.idModel = model.idModel;
                }
            }

            if (kppN != "")
            {
                KPP kpp = automobiles.KPP.Where(x => x.nameKPP == kppN).FirstOrDefault();
                if (kpp == null)
                {
                    KPP newKpp = new KPP
                    {
                        nameKPP = kppN
                    };
                    automobiles.KPP.Add(newKpp);
                    automobiles.SaveChanges();
                    kpp        = automobiles.KPP.Where(x => x.nameKPP == kppN).FirstOrDefault();
                    auto.idKPP = kpp.idKPP;
                }
                else
                {
                    auto.idKPP = kpp.idKPP;
                }
            }

            automobiles.Automobiles.Add(auto);
            automobiles.SaveChanges();
            SaveFoto();
            auto = automobiles.Automobiles
                   .Where(x => x.Brands.nameBrand == brandN &&
                          x.Models.nameModel == modelN &&
                          x.Models.classModel == classN).FirstOrDefault();
            foreach (ListViewItem lvi in listView1.Items)
            {
                string path = "packages\\Foto\\";
                path += lvi.Text + ".jpg";
                Images image = new Images();
                image.idAuto = auto.idAuto;
                image.image  = path;
                automobiles.Images.Add(image);
            }
            automobiles.SaveChanges();
        }