public Worker(string name, string lastName, string position, int salary, int workingHoursPerWeek, List <ILogger> logs) { Name = name; LastName = lastName; WorkingHoursPerWeek = workingHoursPerWeek; Salary = salary; Position = position; RegisterDate = DateTime.Now; List <Worker> list = DatabaseMethods.SelectWorkers(); if (list.Count() > 0) { WorkerNumber = (from w in list select w.WorkerNumber).Max() + 1; } else { WorkerNumber = 1; } foreach (ILogger log in logs) { if (log != null) { log.WriteToLog(this, RegisterDate, "Created worker"); } } }
private void Change_Click(object sender, EventArgs e) { if (establishmentComboBox.Items.Count > 4) { if (establishmentComboBox.SelectedIndex == -1) { establishmentComboBox.BackColor = Color.Salmon; } else { establishmentComboBox.BackColor = Color.LightGreen; } if (workersBox.SelectedIndex == -1) { workersBox.BackColor = Color.Salmon; } else { workersBox.BackColor = Color.LightGreen; } if (establishmentComboBox.SelectedIndex != -1 && workersBox.SelectedIndex != 1) { Worker worker = null; int workerNumber = Convert.ToInt32(workersBox.SelectedItem.ToString().Split('.').First()); worker = DatabaseMethods.SelectWorkers().Where(x => x.WorkerNumber == workerNumber).First(); string oldPosition = worker.Position; worker.Position = establishmentComboBox.SelectedItem.ToString(); DatabaseMethods.UpdateWorker(worker); MessageBox.Show("Old position: " + oldPosition + Environment.NewLine + "New position: " + worker.Position, "Success", MessageBoxButtons.OK, MessageBoxIcon.Information); Dispose(); } } }
private void ChangeWorkerPositionButton_Click(object sender, EventArgs e) { List <Worker> workerList = DatabaseMethods.SelectWorkers(); if (workerList.Count() > 0) { List <string> list = workerList.Select(i => i.WorkerNumber + ". " + i.Name + " " + i.LastName + ", " + i.Position).ToList(); ChangeShiftForm changeShiftForm = new ChangeShiftForm(new BindingSource(list, null)); changeShiftForm.establishmentComboBox.Items.AddRange(new object[] { "Operations manager", "Quality control, safety, environmental manager", "Accountant, bookkeeper, controller", "Office manager", "Receptionist", "Foreperson, supervisor, lead person", "Marketing manager", "Purchasing manager", "Shipping and receiving person or manager", "Professional staff" }); changeShiftForm.establishmentLabel.Text = "Position: "; changeShiftForm.ShowDialog(); } else { MessageBox.Show("No workers!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
public static void PayOutSalaryHandler(ShowObject sender, EventArgs e) { List <Worker> workerList = DatabaseMethods.SelectWorkers(); if (workerList.Count() > 0) { Worker worker = null; int number = Convert.ToInt32(sender.objectBox.SelectedItem.ToString().Split('.').First()); worker = workerList.Where(x => x.WorkerNumber == number).First(); if (Budget.Balance - worker.Salary > Convert.ToDouble(Program.ReadSetting("Limit of bankrupt", "App.config"))) { MessageBox.Show("Paid out €" + worker.Salary + " to " + worker.Name + " " + worker.LastName, "Success", MessageBoxButtons.OK, MessageBoxIcon.Information); worker.PaySalary(); sender.Dispose(); } else { worker.PaySalary(); sender.Dispose(); } } else { MessageBox.Show("No workers!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void WorkerComboBox_DropDown(object sender, EventArgs e) { List <string> list = DatabaseMethods.SelectWorkers().Select(i => i.WorkerNumber + ". " + i.Name + " " + i.LastName + ", " + i.Position).ToList(); list.Insert(0, "Add new worker..."); workerComboBox.DataSource = new BindingSource(list, null); }
private void RaiseButton_Click(object sender, EventArgs e) { if (workersBox.SelectedIndex != -1) { workersBox.BackColor = Color.LightGreen; } else { workersBox.BackColor = Color.Salmon; } if (moneyTrackBar.Value > 0) { moneyTrackBar.BackColor = Color.LightGreen; } else { moneyTrackBar.BackColor = Color.Salmon; } if (workersBox.BackColor == Color.LightGreen && moneyTrackBar.BackColor == Color.LightGreen) { Worker worker = null; int number = Convert.ToInt32(workersBox.SelectedItem.ToString().Split('.').First()); worker = DatabaseMethods.SelectWorkers().Where(x => x.WorkerNumber == number).First(); double oldSalary = worker.Salary; worker.RaiseSalary(moneyTrackBar.Value); DatabaseMethods.UpdateWorker(worker); MessageBox.Show("Old salary: €" + oldSalary + "\nNew salary: €" + worker.Salary, "Success", MessageBoxButtons.OK, MessageBoxIcon.Information); 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 RaiseCutSalaryButton_Click(object sender, EventArgs e) { List <Worker> workerList = DatabaseMethods.SelectWorkers(); if (workerList.Count() > 0) { List <string> list = workerList.Select(i => i.WorkerNumber + ". " + i.Name + " " + i.LastName + ", " + i.Position).ToList(); RaiseCutSalaryForm raiseCutSalaryForm = new RaiseCutSalaryForm(new BindingSource(list, null)); raiseCutSalaryForm.ShowDialog(); } else { MessageBox.Show("No workers!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void ShowWorkersButton_Click(object sender, EventArgs e) { List <Worker> workerList = DatabaseMethods.SelectWorkers(); if (workerList.Count() > 0) { List <string> list = workerList.Select(i => i.WorkerNumber + ". " + i.Name + " " + i.LastName + ", " + i.Position).ToList(); ShowObject showObject = new ShowObject(new BindingSource(list, null), typeof(Worker), this); showObject.Text = "Show workers"; showObject.ShowDialog(); } else { MessageBox.Show("No workers!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void tabControl_Selected(object sender, TabControlEventArgs e) { 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); StartThreadQuantityUpdate(); }
private void PayOutSalaryButton_Click(object sender, EventArgs e) { List <Worker> workerList = DatabaseMethods.SelectWorkers(); if (workerList.Count() > 0) { List <string> list = workerList.Select(i => i.WorkerNumber + ". " + i.Name + " " + i.LastName + ", " + i.Position).ToList(); ShowObject showObject = new ShowObject(new BindingSource(list, null), typeof(Worker), this); showObject.Text = "Pay out salary"; showObject.showButton.Text = "Pay out salary"; showObject.showButton.Size = new Size(564, 51); showObject.deleteButton.Visible = false; showObject.ShowDialog(); } else { MessageBox.Show("No workers!", "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 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(); } } } } }