public Order(int offerNumber, int clientNumber, Worker worker, int orderClientsAmount, DateTime travelStartDate, List <ILogger> logs) { TravelOfferNumber = offerNumber; ServiceWorker = worker; OrderClientNumber = clientNumber; OrderRegisterDate = DateTime.Now; TravelStartDate = travelStartDate; List <Order> list = DatabaseMethods.SelectOrders(); if (list.Count > 0) { OrderNumber = list.Select(x => x.OrderNumber).Max() + 1; } else { OrderNumber = 1; } OrderClientsAmount = orderClientsAmount; OrderPrice = DatabaseMethods.SelectOffers().Where(x => x.OfferNumber == TravelOfferNumber).First().Price *orderClientsAmount; AddOrderPriceToBudget(OrderPrice); string email = DatabaseMethods.SelectClients().Where(x => x.ClientNumber == OrderClientNumber).First().Email; foreach (ILogger log in logs) { if (log != null) { log.WriteToLog(this, OrderRegisterDate, "Created order", email); } } }
private void OfferBox_DropDown(object sender, EventArgs e) { List <string> list = DatabaseMethods.SelectOffers().Select(i => i.OfferNumber + ". " + i.TravelDestination + ", " + i.HotelRanking + ", " + i.Feeding + ", €" + i.Price).ToList(); list.Insert(0, "Add new offer..."); offerBox.DataSource = new BindingSource(list, null); }
public Offer(string travelDestination, string feeding, int price, int travelTime, string hotelRanking, List <ILogger> logs) { TravelDestination = travelDestination; Feeding = feeding; Price = price; TravelTime = travelTime; HotelRanking = hotelRanking; List <Offer> list = DatabaseMethods.SelectOffers(); if (list.Count() > 0) { OfferNumber = (from o in list select o.OfferNumber).Max() + 1; } else { OfferNumber = 1; } foreach (ILogger log in logs) { if (log != null) { log.WriteToLog(this, DateTime.Now, "Created offer"); } } }
public override string ToString() { return("Order number: " + OrderNumber.ToString() + Environment.NewLine + "" + DatabaseMethods.SelectOffers().Where(x => x.OfferNumber == TravelOfferNumber).First().ToString() + Environment.NewLine + "Client: " + DatabaseMethods.SelectClients().Where(x => x.ClientNumber == OrderClientNumber).First().Name + " " + DatabaseMethods.SelectClients().Where(x => x.ClientNumber == OrderClientNumber).First().LastName + Environment.NewLine + "Worker: " + ServiceWorker.Name + " " + ServiceWorker.LastName + Environment.NewLine + "Order price: €" + OrderPrice.ToString() + Environment.NewLine + "Travelers amount: " + OrderClientsAmount.ToString() + Environment.NewLine + "Travel start date: " + TravelStartDate.ToShortDateString() + Environment.NewLine + "Order registered on: " + OrderRegisterDate.ToShortDateString()); }
private async Task SetLabelsAwait() { clientsQuantity.Text = (await GetLabelTextAsync(DatabaseMethods.SelectClients().Count, "Number of clients: ")); offersQuantity.Text = (await GetLabelTextAsync(DatabaseMethods.SelectOffers().Count(), "Number of offers: ")); workersQuantity.Text = (await GetLabelTextAsync(DatabaseMethods.SelectWorkers().Count(), "Number of workers: ")); ordersQuantity.Text = (await GetLabelTextAsync(DatabaseMethods.SelectOrders().Count(), "Number of orders: ")); activeOrders.Text = (await GetLabelTextAsync(CheckActiveOrders(), "Active orders: ")); if (!Budget.IsBankrupt()) { budgetBalance.BackColor = DefaultBackColor; budgetBalance.Text = (await GetLabelTextAsync((int)Budget.Balance, "Budget balance: €")); } }
private void ShowOffersButton_Click(object sender, EventArgs e) { List <Offer> offerList = DatabaseMethods.SelectOffers(); if (offerList.Count() > 0) { List <string> list = offerList.Select(i => i.OfferNumber + ". " + i.TravelDestination + ", " + i.HotelRanking + ", " + i.Feeding + ", €" + i.Price).ToList(); ShowObject showObject = new ShowObject(new BindingSource(list, null), typeof(Offer), this); showObject.Text = "Show offers"; showObject.ShowDialog(); } else { MessageBox.Show("No offers!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void NearestDeparturesForm_Load(object sender, EventArgs e) { nearestDeparturesListView.View = View.Details; nearestDeparturesListView.GridLines = true; nearestDeparturesListView.FullRowSelect = true; nearestDeparturesListView.Columns.Add("No.", 50); nearestDeparturesListView.Columns.Add("Travel destination", 360); nearestDeparturesListView.Columns.Add("Worker", 240); nearestDeparturesListView.Columns.Add("Client", 240); nearestDeparturesListView.Columns.Add("Price", 120); nearestDeparturesListView.Columns.Add("Order created", 170); nearestDeparturesListView.Columns.Add("Travel start date", 200); nearestDeparturesListView.Columns.Add("Travelers", 150); if (_isWorkerOrders == false) { List <Order> list = DatabaseMethods.SelectOrders(); Order[] orders = new Order[list.Count()]; int i = 0; foreach (Order order in list) { orders[i] = order; i++; } Array.Sort(orders); nearestDeparturesListView.Columns.RemoveAt(7); foreach (Order order in orders) { if (order.IsActive()) { string[] arr = new string[7]; arr[0] = order.OrderNumber.ToString(); arr[1] = DatabaseMethods.SelectOffers().Where(x => x.OfferNumber == order.TravelOfferNumber).First().TravelDestination; arr[2] = DatabaseMethods.SelectClients().Where(x => x.ClientNumber == order.OrderClientNumber).First().Name + " " + DatabaseMethods.SelectClients().Where(x => x.ClientNumber == order.OrderClientNumber).First().LastName; arr[3] = DatabaseMethods.SelectWorkers().Where(x => x.WorkerNumber == order.ServiceWorker.WorkerNumber).First().Name + " " + DatabaseMethods.SelectWorkers().Where(x => x.WorkerNumber == order.ServiceWorker.WorkerNumber).First().LastName; arr[4] = "€" + string.Format("{0:F2}", order.OrderPrice); arr[5] = order.OrderRegisterDate.ToShortDateString(); arr[6] = order.TravelStartDate.ToShortDateString(); ListViewItem itm = new ListViewItem(arr); nearestDeparturesListView.Items.Add(itm); } } } }
public void ShowButton_Click(object sender, EventArgs e) { if (type.Equals(typeof(Order)) && !deleteButton.Visible && showButton.Text != "Send information to E-mail") { if (objectBox.SelectedIndex == -1) { objectBox.BackColor = Color.Salmon; } else { NearestDeparturesForm ordersView = new NearestDeparturesForm(true); List <Worker> workers = DatabaseMethods.SelectWorkers(); List <Order> orders = DatabaseMethods.SelectOrders(); Worker worker = null; int number = Convert.ToInt32(objectBox.SelectedItem.ToString().Split('.').First()); worker = workers.Where(x => x.WorkerNumber == number).First(); List <Order> list = orders.Where(x => x.ServiceWorker.WorkerNumber == worker.WorkerNumber).ToList(); if (list.Count > 0) { foreach (Order order in list) { if (order.IsActive()) { string[] arr = new string[8]; arr[0] = order.OrderNumber.ToString(); arr[1] = DatabaseMethods.SelectOffers().Where(x => x.OfferNumber == order.TravelOfferNumber).First().TravelDestination; arr[2] = DatabaseMethods.SelectWorkers().Where(x => x.WorkerNumber == order.ServiceWorker.WorkerNumber).First().Name + " " + DatabaseMethods.SelectWorkers().Where(x => x.WorkerNumber == order.ServiceWorker.WorkerNumber).First().LastName; arr[3] = DatabaseMethods.SelectClients().Where(x => x.ClientNumber == order.OrderClientNumber).First().Name + " " + DatabaseMethods.SelectClients().Where(x => x.ClientNumber == order.OrderClientNumber).First().LastName; arr[4] = "€" + string.Format("{0:F2}", order.OrderPrice); arr[5] = order.OrderRegisterDate.ToShortDateString(); arr[6] = order.TravelStartDate.ToShortDateString(); arr[7] = order.OrderClientsAmount.ToString(); ListViewItem itm = new ListViewItem(arr); ordersView.nearestDeparturesListView.Items.Add(itm); } } ordersView.Text = worker.Name + " " + worker.LastName + " orders"; ordersView.ShowDialog(); } else { MessageBox.Show("No orders!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } Dispose(); } } else if (objectBox.SelectedIndex != -1) { if (!deleteButton.Visible && type.Equals(typeof(Order))) { MainForm.SendEmailOrderHandler(this, null); } else if (!deleteButton.Visible && type.Equals(typeof(Client))) { MainForm.SendEmailClientHandler(this, null); } else if (!deleteButton.Visible && type.Equals(typeof(Worker))) { MainForm.PayOutSalaryHandler(this, null); } else { if (type.Equals(typeof(Offer))) { List <Offer> offers = DatabaseMethods.SelectOffers(); Offer offer = null; int number = Convert.ToInt32(objectBox.SelectedItem.ToString().Split('.').First()); offer = offers.Where(x => x.OfferNumber == number).First(); MessageBox.Show(offer.ToString(), "Information", MessageBoxButtons.OK, MessageBoxIcon.Information); } if (type.Equals(typeof(Order))) { List <Order> orders = DatabaseMethods.SelectOrders(); Order order = null; int number = Convert.ToInt32(objectBox.SelectedItem.ToString().Split('.').First()); order = orders.Where(x => x.OrderNumber == number).First(); MessageBox.Show(order.ToString(), "Information", MessageBoxButtons.OK, MessageBoxIcon.Information); } if (type.Equals(typeof(Client))) { List <Client> clients = DatabaseMethods.SelectClients(); Client client = null; int number = Convert.ToInt32(objectBox.SelectedItem.ToString().Split(' ').Last().Remove(objectBox.SelectedItem.ToString().Split(' ').Last().Length - 1)); client = clients.Where(x => x.ClientNumber == number).First(); MessageBox.Show(client.ToString(), "Information", MessageBoxButtons.OK, MessageBoxIcon.Information); } if (type.Equals(typeof(Worker))) { List <Worker> workers = DatabaseMethods.SelectWorkers(); Worker worker = null; int number = Convert.ToInt32(objectBox.SelectedItem.ToString().Split('.').First()); worker = workers.Where(x => x.WorkerNumber == number).First(); MessageBox.Show(worker.ToString(), "Information", MessageBoxButtons.OK, MessageBoxIcon.Information); } } } else { MessageBox.Show("Not selected!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void chartsTab_Selected(object sender, TabControlEventArgs e) { switch (e.TabPageIndex) { case 0: List <string> positions = new List <string>(); List <int> positionCount = new List <int>(); var empl = DatabaseMethods.SelectWorkers().GroupBy(emp => emp.Position); foreach (var worker in empl) { positions.Add(worker.Key); positionCount.Add(worker.Count()); } chart1.Series[0].LegendText = "Number of workers"; RemoveGrid(chart1); chart1.Series["Series1"].IsValueShownAsLabel = true; chart1.Series["Series1"].Points.DataBindXY(positions, positionCount); break; case 1: List <string> workers = new List <string>(); List <double> salaries = new List <double>(); foreach (Worker worker in DatabaseMethods.SelectWorkers().OrderByDescending(x => x.Salary).Take(5).ToList()) { workers.Add(worker.Name + " " + worker.LastName); salaries.Add(DatabaseMethods.SelectWorkers().Where(x => x.Name + " " + x.LastName == worker.Name + " " + worker.LastName).First().Salary); } chart2.Series[0].LegendText = "Salary per month in €"; RemoveGrid(chart2); chart2.Series["Series1"].IsValueShownAsLabel = true; chart2.Series["Series1"].Points.DataBindXY(workers, salaries); break; case 2: workers = new List <string>(); salaries = new List <double>(); foreach (Worker worker in DatabaseMethods.SelectWorkers().OrderByDescending(x => x.Salary).Skip(DatabaseMethods.SelectWorkers().Count - 5).ToList()) { workers.Add(worker.Name + " " + worker.LastName); salaries.Add(DatabaseMethods.SelectWorkers().Where(x => x.Name + " " + x.LastName == worker.Name + " " + worker.LastName).First().Salary); } chart3.Series[0].LegendText = "Salary per month in €"; RemoveGrid(chart3); chart3.Series["Series1"].IsValueShownAsLabel = true; chart3.Series["Series1"].Points.DataBindXY(workers, salaries); break; case 3: List <Order> orders = DatabaseMethods.SelectOrders(); List <Offer> offers = DatabaseMethods.SelectOffers(); var join = orders.OrderByDescending(order => order.TravelStartDate).Reverse().Join(offers, ord => ord.TravelOfferNumber, off => off.OfferNumber, (ord, off) => new { ord.TravelStartDate, off.Price, ord.OrderClientsAmount }).GroupBy(grp => grp.TravelStartDate); List <string> dates = new List <string>(); List <double> prices = new List <double>(); foreach (var item in join) { dates.Add(item.Key.ToShortDateString()); prices.Add(item.Select(price => price.Price * price.OrderClientsAmount).Sum()); } chart4.Series[0].LegendText = "Total income for day in €"; RemoveGrid(chart4); chart4.Series["Series1"].IsValueShownAsLabel = true; chart4.Series["Series1"].Points.DataBindXY(dates, prices); break; } }
private void AboutOrderButton_Click(object sender, EventArgs e) { List <Order> orderList = DatabaseMethods.SelectOrders(); if (orderList.Count > 0) { List <string> list = orderList.Select(i => i.OrderNumber + ". " + DatabaseMethods.SelectClients().Where(x => x.ClientNumber == i.OrderClientNumber).First().Name + " " + DatabaseMethods.SelectClients().Where(x => x.ClientNumber == i.OrderClientNumber).First().LastName + " " + DatabaseMethods.SelectOffers().Where(x => x.OfferNumber == i.TravelOfferNumber).First().TravelDestination).ToList(); ShowObject showObject = new ShowObject(new BindingSource(list, null), typeof(Order)); showObject.Text = "Show orders"; showObject.showButton.Text = "Send information to E-mail"; showObject.showButton.Size = new Size(564, 51); showObject.deleteButton.Visible = false; showObject.ShowDialog(); } else { MessageBox.Show("No orders!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void Create_Click(object sender, EventArgs e) { if (clientsBox.SelectedIndex == 0) { AddClientForm addClientForm = new AddClientForm(_mainForm); addClientForm.ShowDialog(); } else { if (offerBox.SelectedIndex == 0) { AddOfferForm addOfferForm = new AddOfferForm(_mainForm); addOfferForm.ShowDialog(); } else { if (workerComboBox.SelectedIndex == 0) { AddWorkerForm addWorkerForm = new AddWorkerForm(_mainForm); addWorkerForm.ShowDialog(); } else { if (clientsBox.SelectedIndex != -1) { clientsBox.BackColor = Color.LightGreen; } else { clientsBox.BackColor = Color.Salmon; } if (offerBox.SelectedIndex != -1) { offerBox.BackColor = Color.LightGreen; } else { offerBox.BackColor = Color.Salmon; } if (workerComboBox.SelectedIndex != -1) { workerComboBox.BackColor = Color.LightGreen; } else { workerComboBox.BackColor = Color.Salmon; } if (travellersAmountTrackBar.Value >= 1) { travellersAmountTrackBar.BackColor = Color.LightGreen; } else { travellersAmountTrackBar.BackColor = Color.Salmon; } if (clientsBox.BackColor == Color.LightGreen && offerBox.BackColor == Color.LightGreen && workerComboBox.BackColor == Color.LightGreen && travellersAmountTrackBar.BackColor == Color.LightGreen) { Worker worker = null; int workerNumber = Convert.ToInt32(workerComboBox.SelectedItem.ToString().Split('.').First()); worker = DatabaseMethods.SelectWorkers().Where(x => x.WorkerNumber == workerNumber).First(); Offer offer = null; int offerNumber = Convert.ToInt32(offerBox.SelectedItem.ToString().Split('.').First()); offer = DatabaseMethods.SelectOffers().Where(x => x.OfferNumber == offerNumber).First(); Client client = null; int clientNumber = Convert.ToInt32(clientsBox.SelectedItem.ToString().Split(' ').Last().Remove(clientsBox.SelectedItem.ToString().Split(' ').Last().Length - 1)); client = DatabaseMethods.SelectClients().Where(x => x.ClientNumber == clientNumber).First(); Order order = new Order(offer.OfferNumber, client.ClientNumber, worker, travellersAmountTrackBar.Value, monthCalendar.SelectionStart, new List <ILogger> { new LogFileWritter(), new ScreenObjectInfoWritter(), emailConfirmationCheckBox.Checked ? new EmailInvoiceSender() : null }); DatabaseMethods.UpdateWorker(worker); if (DatabaseMethods.InsertOrder(order)) { _mainForm.StartThreadQuantityUpdate(); } else { MessageBox.Show("Cannot add order!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } Dispose(); } } } } }