private void fillDGV() { List <Orders> orders = db.Orders.Where(o => o.Status != "Completed").ToList(); foreach (Orders i in orders) { int PriceFromCar = db.Cars.FirstOrDefault(c => c.Make == i.CarMake).Id; Cars abc = db.Cars.Find(PriceFromCar); TimeSpan tspanNormal = (i.FinishDate.Value - i.PickedDate.Value); int rentday = System.Math.Abs(tspanNormal.Days); if (i.FinishDate > DateTime.Now) { decimal NormalPrice = Convert.ToDecimal(String.Format("{0:0.00}", (abc.Price * rentday))); i.Price = NormalPrice; i.Status = "Ongoing"; } else { i.Status = "expired"; TimeSpan tspan = (DateTime.Now - i.FinishDate.Value); int Expire = tspan.Days; decimal sum = Convert.ToDecimal(String.Format("{0:0.00}", ((rentday * abc.Price) + (Expire * (abc.Price / 100 * 20))))); String.Format("{0:0.00}", sum); i.Price = sum; } db.SaveChanges(); dgvComplete.Rows.Add(i.Id, i.ConsumerID, i.Consumers.FullName, i.CarMadeID, i.Mades.Made, i.CarMake, i.PickedDate, i.FinishDate, i.Price, i.Status); } }
private void createCars() { if (!string.IsNullOrWhiteSpace(comboBox1.Text) && !string.IsNullOrWhiteSpace(txtMake.Text) && !string.IsNullOrWhiteSpace(txtPrice.Text) && !string.IsNullOrWhiteSpace(txtFuelC.Text) && !string.IsNullOrWhiteSpace(txtEngine.Text) && !string.IsNullOrWhiteSpace(txtYear.Text)) { int a; decimal b; if (decimal.TryParse(txtEngine.Text, out b) && int.TryParse(txtFuelC.Text, out a) && decimal.TryParse(txtPrice.Text, out b) && int.TryParse(txtYear.Text, out a)) { int GetIdMades = db.Mades.FirstOrDefault(m => m.Made == comboBox1.Text).Id; Cars cars = new Cars(); cars.Made = GetIdMades; cars.Make = txtMake.Text; cars.Year = Convert.ToInt32(txtYear.Text); cars.Engine = Convert.ToDecimal(txtEngine.Text); cars.FuelCons = Convert.ToInt32(txtFuelC.Text); cars.Price = Convert.ToDecimal(txtPrice.Text); db.Cars.Add(cars); db.SaveChanges(); MessageBox.Show("Car Succesfully Created!"); txtMake.Clear(); txtYear.Clear(); txtEngine.Clear(); txtFuelC.Clear(); txtPrice.Clear(); } else { lblFillFields.Visible = false; lblRight.Visible = true; } } else { lblFillFields.Visible = true; } }
private void CreateDetails() { Employees employees = new Employees(); employees.FullName = txtName.Text; employees.IdentityNumber = Convert.ToInt32(txtIdentity.Text); employees.Position = txtPosition.Text; employees.Age = Convert.ToInt32(txtAge.Text); db.Employees.Add(employees); db.SaveChanges(); MessageBox.Show("Succesfully Created!"); txtName.Clear(); txtIdentity.Clear(); txtPosition.Clear(); txtAge.Clear(); lblFillFields.Visible = false; lblAge.Visible = false; }
private void createConsumer() { Consumers consumers = new Consumers(); if (!string.IsNullOrWhiteSpace(txtName.Text) && !string.IsNullOrWhiteSpace(txtAge.Text) && !string.IsNullOrWhiteSpace(txtDrivingLicence.Text) && !string.IsNullOrWhiteSpace(txtIdentity.Text)) { int a; if (int.TryParse(txtAge.Text, out a) && int.TryParse(txtDrivingLicence.Text, out a) && int.TryParse(txtIdentity.Text, out a)) { consumers.IdentityNumber = Convert.ToInt32(txtIdentity.Text); consumers.DrivingLicence = Convert.ToInt32(txtDrivingLicence.Text); consumers.FullName = txtName.Text; consumers.Age = Convert.ToInt32(txtAge.Text); lblFillFields.Visible = false; lblRight.Visible = false; db.Consumers.Add(consumers); db.SaveChanges(); MessageBox.Show("Succesfully Created!"); txtIdentity.Clear(); txtDrivingLicence.Clear(); txtName.Clear(); txtAge.Clear(); } else { lblFillFields.Visible = false; lblRight.Visible = true; } } else { lblFillFields.Visible = true; } }
private void createRegister() { Admins admins = new Admins(); admins.FullName = txtFullname.Text; admins.Username = txtUsername.Text; admins.Email = txtEmail.Text; admins.Password = txtPassword.Text; db.Admins.Add(admins); db.SaveChanges(); }
private void qqq() { if (!string.IsNullOrWhiteSpace(cbConsumerName.Text) && !string.IsNullOrWhiteSpace(cbCarMade.Text) && !string.IsNullOrWhiteSpace(cbCarMake.Text) && cbConsumerName.Text != "Choose..." && cbCarMake.Text != "Choose..." && cbCarMade.Text != "Choose..." ) { AllOrders allOrders = new AllOrders(); Orders orders = new Orders(); int getCarConsumerID = db.Consumers.FirstOrDefault(m => m.FullName == cbConsumerName.Text).Id; int getCarMadeID = db.Mades.FirstOrDefault(m => m.Made == cbCarMade.Text).Id; int getCarPrice = db.Cars.FirstOrDefault(m => m.Make == cbCarMake.Text).Id; Cars inttt = db.Cars.Find(getCarPrice); orders.ConsumerID = Convert.ToInt32(getCarConsumerID); orders.CarMadeID = Convert.ToInt32(getCarMadeID); orders.CarId = Convert.ToInt32(getCarPrice); orders.CarMake = cbCarMake.Text; orders.PickedDate = dtFrom.Value; orders.FinishDate = dtTill.Value; orders.Price = inttt.Price; db.Orders.Add(orders); db.SaveChanges(); MessageBox.Show("Order Succesfully Created!"); } else { MessageBox.Show("Please Fill All Fields! By the way 'Choose' is not an option"); } }