public DataTable GetDriverTable(string driverFullName) { DataTable newTable = GenerateEmptyDriverTable(); using (var connection = new FridgeBussinessEntities2()) { var driverTable = from dd in connection.Driver join ff in connection.Fridge on dd.PersonalCode equals ff.DeliveringDriverPersonalCode select new { driver = dd.FirstName + " " + dd.LastName, FridgeId = ff.FridgeID, cust = ff.Customer, until = ff.DeliverUntil, delivered = ff.DeliveredAt }; foreach (var car in driverTable) { if (car.driver.Equals(driverFullName) && car.delivered == null) { DataRow newRow = newTable.NewRow(); newRow["FridgeId"] = car.FridgeId; newRow["Client"] = car.cust; newRow["Address"] = connection.Customer.Single(c => c.CustomerName == car.cust).Address; newRow["DeliverUntil"] = car.until; newTable.Rows.Add(newRow); } } } return(newTable); }
private void DriverForm_FormClosing(object sender, FormClosingEventArgs e) { if (deliveredFridgesTodayIdList.Count > 0) { string line = ""; using (var connection = new FridgeBussinessEntities2()) { foreach (int id in deliveredFridgesTodayIdList) { Fridge temp = new Fridge(); temp = connection.Fridge.Single(f => f.FridgeID == id); line += "Klientas: " + temp.Customer + " | Saldytuvo nr: " + temp.FridgeID + "\n"; } } DialogResult result = MessageBox.Show("Pakeitimai:\n" + line + "Issaugoti?", "Warning", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Warning); if (result == DialogResult.Yes) { using (var connection = new FridgeBussinessEntities2()) { foreach (var fr in deliveredFridgesTodayIdList) { connection.Fridge.Single(f => f.FridgeID == fr).DeliveredAt = DateTime.Today; } connection.SaveChanges(); } } else if (result == DialogResult.Cancel) { e.Cancel = true; } } }
private void StartupForm_Load(object sender, EventArgs e) { using (var connection = new FridgeBussinessEntities2()) { ChooseDriverBox.DataSource = connection.Driver.Select(d => d.FirstName + " " + d.LastName).ToList(); ChooseClientBox.DataSource = connection.Customer.Select(d => d.CustomerName).ToList(); } }
private void DeleteFridgeButton_Click(object sender, EventArgs e) { int fridgeid = (int)FridgeGridView.CurrentRow.Cells[0].Value; using (var con = new FridgeBussinessEntities2()) { con.Fridge.Remove(con.Fridge.FirstOrDefault(f => f.FridgeID == fridgeid)); con.SaveChanges(); } Form1_Load(this, e); }
private int AverageDeliveriesPerDay() { int days; int fridges; using (var connection = new FridgeBussinessEntities2()) { days = connection.Fridge.Select(f => f.DeliveredAt).Distinct().Count(); fridges = connection.Fridge.Count(); } return(fridges / days); }
private void tesstt(DataTable table) { using (var sms = new FridgeBussinessEntities2()) { var fridges = sms.Fridge.AsQueryable().Where(c => c.Customer == currentClient); fridges = fridges.OrderBy(f => f.DeliveringDriverPersonalCode).ThenBy(f => f.DeliverUntil); foreach (var fr in fridges) { label1.Text += "\n" + sms.Driver.First(d => d.PersonalCode == fr.DeliveringDriverPersonalCode).FirstName + " " + fr.DeliverUntil; } //var collection = sms.Fridge.AsQueryable().Where(c => c.Customer == currentClient).GroupBy(c=>c.DeliveringDriverPersonalCode); } }
private TimeSpan AverageOrderToDeliveryTime() { TimeSpan total = new TimeSpan(0); int counter; using (var connection = new FridgeBussinessEntities2()) { Fridge[] fridges = connection.Fridge.ToArray(); foreach (var fr in fridges.Where(f => f.DeliveredAt != null)) { TimeSpan span = fr.DeliverUntil.Value - fr.DeliveredAt.Value; total += span + new TimeSpan(ClientForm.OrderToDeliverDayCount); } counter = connection.Fridge.Count(c => c.DeliveredAt != null); } return(new TimeSpan(total.Ticks / counter)); }
private void AddFridgeForm_Load(object sender, EventArgs e) { ManufactureDateYYBox.DataSource = Enumerable.Range(2006, DateTime.Now.Year - 2005).Reverse().ToList(); ManufactureDateMMBox.DataSource = Enumerable.Range(1, 12).ToList(); ManufactureDateDDBox.DataSource = Enumerable.Range(1, 31).ToList(); DeliverYYBox.DataSource = Enumerable.Range(DateTime.Now.Year, 4).ToList(); DeliverMMBox.DataSource = Enumerable.Range(1, 12).ToList(); DeliverDDBox.DataSource = Enumerable.Range(1, 31).ToList(); using (var temp = new FridgeBussinessEntities2()) { CustomerBox.DataSource = temp.Customer.Select(c => c.CustomerName).ToList(); DriverBox.DataSource = temp.Driver.Select(d => d.FirstName + " " + d.LastName).ToList(); } if (fridgeID == -1) { CustomerBox.SelectedIndex = -1; DriverBox.SelectedIndex = -1; DeliverYYBox.SelectedIndex = -1; DeliverMMBox.SelectedIndex = -1; DeliverDDBox.SelectedIndex = -1; } else { Text = "Edit Fridge"; button1.Text = "Save edit"; using (var conn = new FridgeBussinessEntities2()) { Fridge current = conn.Fridge.FirstOrDefault(c => c.FridgeID == fridgeID); MassBox.Text = current.Mass.ToString(); VolumeBox.Text = current.Volume.ToString(); ManufactureDateYYBox.SelectedItem = current.ManufacturedOn.Year; ManufactureDateMMBox.SelectedItem = current.ManufacturedOn.Month; ManufactureDateDDBox.SelectedItem = current.ManufacturedOn.Day; CustomerBox.SelectedItem = current.Customer; DriverBox.SelectedItem = (current.Driver != null) ? current.Driver.FirstName + " " + current.Driver.LastName : null; DeliverYYBox.SelectedItem = current.DeliverUntil.Value.Year; DeliverMMBox.SelectedItem = current.DeliverUntil.Value.Month; DeliverDDBox.SelectedItem = current.DeliverUntil.Value.Day; } } }
private void SaveFridge(Fridge newFridge) { using (var conn = new FridgeBussinessEntities2()) { if (fridgeID == -1) { conn.Fridge.Add(newFridge); conn.SaveChanges(); } else { Fridge temp = conn.Fridge.FirstOrDefault(f => f.FridgeID == newFridge.FridgeID); conn.Fridge.Remove(temp); conn.Fridge.Add(newFridge); conn.SaveChanges(); } } }
private void transferBetweenTables(DataGridView tableView, DataTable test, DataTable table) { string currentFridgeId = tableView.CurrentRow.Cells["FridgeId"].Value.ToString(); var row = test.AsEnumerable().Single(r => r["FridgeId"].ToString() == currentFridgeId); test.Rows.Remove(row); DataRow newRow = table.NewRow(); using (var connenction = new FridgeBussinessEntities2()) { Fridge current = connenction.Fridge.Single(f => f.FridgeID.ToString() == currentFridgeId); newRow["Volume"] = current.Volume; newRow["Mass"] = current.Mass; newRow["ManufacturedOn"] = current.ManufacturedOn; newRow["FridgeId"] = currentFridgeId; table.Rows.Add(newRow); } }
private Fridge CreateFridge(decimal volume, int mass) { using (var conn = new FridgeBussinessEntities2()) { DateOperations dop = new DateOperations(); return(new Fridge { FridgeID = fridgeID != -1 ? fridgeID : -1, Mass = mass, Volume = volume, ManufacturedOn = dop.DateParsing(ManufactureDateYYBox.Text, ManufactureDateMMBox.Text, ManufactureDateDDBox.Text), Customer = conn.Customer.FirstOrDefault(c => c.CustomerName == CustomerBox.Text).CustomerName, DeliverUntil = dop.DateParsing(DeliverYYBox.Text, DeliverMMBox.Text, DeliverDDBox.Text), DeliveringDriverPersonalCode = conn.Driver.First(d => d.FirstName + " " + d.LastName == DriverBox.Text).PersonalCode, Driver = conn.Driver.First(d => d.FirstName + " " + d.LastName == DriverBox.Text) }); } }
private void PlaceOrderButton_Click(object sender, EventArgs e) { if (CartGridView.Rows.Count > 0) { using (var connection = new FridgeBussinessEntities2()) { foreach (DataRow row in shoppingCartTable.Rows) { if (!string.IsNullOrEmpty(row["FridgeId"].ToString())) { int frid = (int)row["FridgeId"]; Fridge toReplace = connection.Fridge.First(f => f.FridgeID == frid); connection.Fridge.Remove(toReplace); connection.SaveChanges(); toReplace.Customer = currentClient; toReplace.DeliverUntil = DateTime.Today.AddDays(OrderToDeliverDayCount); connection.Fridge.Add(toReplace); } else { connection.Fridge.Add(new Fridge { Volume = (decimal)row["Volume"], Customer = currentClient }); } connection.SaveChanges(); } } MessageBox.Show("Order successful"); Close(); } else { MessageBox.Show("The cart is empty"); } }