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); } } }
public Client(string name, string lastName, string email, string mobileNumber, List <ILogger> logs) { Name = name; LastName = lastName; Email = email; MobileNumber = mobileNumber; RegisterDate = DateTime.Now; List <Client> list = DatabaseMethods.SelectClients(); if (list.Count > 0) { ClientNumber = (from c in list select c.ClientNumber).Max() + 1; } else { ClientNumber = 1; } foreach (ILogger log in logs) { if (log != null) { log.WriteToLog(this, RegisterDate, "Created client", Email); } } }
private void ClientsBox_DropDown(object sender, EventArgs e) { List <string> list = DatabaseMethods.SelectClients().Select(i => i.Name + " " + i.LastName + " [Client number: " + i.ClientNumber + "]").ToList(); list.Insert(0, "Add new client..."); clientsBox.DataSource = new BindingSource(list, null); }
private void Create_Click(object sender, EventArgs e) { if (Regex.IsMatch(nameBox.Text, pattern: @"^[a-zA-ZąčęėįšųūžĄČĘĖĮŠŲŪŽ]+$")) { nameBox.BackColor = Color.LightGreen; } else { nameBox.BackColor = Color.Salmon; } if (Regex.IsMatch(lastNameBox.Text, pattern: @"^[a-zA-ZąčęėįšųūžĄČĘĖĮŠŲŪŽ]+$")) { lastNameBox.BackColor = Color.LightGreen; } else { lastNameBox.BackColor = Color.Salmon; } if (Regex.IsMatch(telNumberBox.Text, pattern: @"^(?!\s*$)[0-9]{8,14}$")) { telNumberBox.BackColor = Color.LightGreen; } else { telNumberBox.BackColor = Color.Salmon; } if (Regex.IsMatch(emailBox.Text, pattern: @"[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?")) { emailBox.BackColor = Color.LightGreen; } else { emailBox.BackColor = Color.Salmon; } if (nameBox.BackColor == Color.LightGreen && lastNameBox.BackColor == Color.LightGreen && telNumberBox.BackColor == Color.LightGreen && emailBox.BackColor == Color.LightGreen) { if (DatabaseMethods.SelectClients().Select(x => x.Email).ToList().Contains(emailBox.Text)) { MessageBox.Show("This email address exists!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { Client client = new Client(nameBox.Text, lastNameBox.Text, emailBox.Text, telNumberBox.Text, new List <ILogger> { new LogFileWritter(), new ScreenObjectInfoWritter(), emailConfirmationCheckBox.Checked ? new EmailInvoiceSender() : null }); DatabaseMethods.InsertClient(client); _mainForm.StartThreadQuantityUpdate(); Dispose(); } } }
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()); }
public static void SendEmailOrderHandler(ShowObject sender, EventArgs e) { Order order = null; int number = Convert.ToInt32(sender.objectBox.SelectedItem.ToString().Split('.').First()); order = DatabaseMethods.SelectOrderFromQuery("SELECT * FROM Orders WHERE OrderNumber = '" + number.ToString() + "'"); string email = DatabaseMethods.SelectClients().Where(x => x.ClientNumber == order.OrderClientNumber).First().Email; Task.Run(() => EmailSender.SendIt(order, email, order.OrderRegisterDate, "Order information")); MessageBox.Show("E-mail sent to " + email, "E-mail sent", MessageBoxButtons.OK, MessageBoxIcon.Information); sender.Dispose(); }
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 ShowClientsButton_Click(object sender, EventArgs e) { List <Client> clientList = DatabaseMethods.SelectClients(); if (clientList.Count() > 0) { List <string> list = clientList.Select(i => i.Name + " " + i.LastName + " [Client number: " + i.ClientNumber + "]").ToList(); ShowObject showObject = new ShowObject(new BindingSource(list, null), typeof(Client), this); showObject.Text = "Show clients"; showObject.ShowDialog(); } else { MessageBox.Show("No clients!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void AboutClientButton_Click(object sender, EventArgs e) { List <Client> clientList = DatabaseMethods.SelectClients(); if (clientList.Count() > 0) { List <string> list = clientList.Select(i => i.Name + " " + i.LastName + " [Client number: " + i.ClientNumber + "]").ToList(); ShowObject showObject = new ShowObject(new BindingSource(list, null), typeof(Client)); showObject.Text = "Show clients"; 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 clients!", "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 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(); } } } } }