public WorkerAssignmentWindow(OrderData data, ulong tag) { InitializeComponent(); this.data = data; _tag = tag; assignments = new List <WorkerAssignmentData>(); foreach (WorkerData worker in Database.worker.SelectAll()) { WorkerAssignmentData assignment = new WorkerAssignmentData() { worker = worker, orders = new List <ProductData>(), orderId = data.Number }; assignments.Add(assignment); } workersSource = Database.worker.SelectAll(); WorkerAssignment.ItemsSource = workersSource; itemsSource = new List <string>(); foreach (ProductData product in data.Products) { itemsSource.Add(actionRequiredString + product.Product); } listView.ItemsSource = itemsSource; }
private void WorkerAssignment_DropDownClosed(object sender, EventArgs e) { if (listView.SelectedItem == null || WorkerAssignment.SelectedIndex == -1) { WorkerAssignment.SelectedIndex = -1; return; } else { WorkerData worker = (WorkerData)WorkerAssignment.SelectedItem; WorkerAssignmentData assignment = assignments.Where(x => x.worker.Email == worker.Email).First(); foreach (WorkerAssignmentData existingAssingment in assignments) { existingAssingment.orders.RemoveAll(x => x.Product == ProductName.Text); } assignment.orders.Add(new ProductData() { Product = ProductName.Text, Quantity = int.Parse(ProductQty.Text) }); int index = itemsSource.IndexOf(ProductName.Text); if (index == -1) { index = itemsSource.IndexOf(actionRequiredString + ProductName.Text); } itemsSource[index] = itemsSource[index].Replace(actionRequiredString, string.Empty); listView.Items.Refresh(); } }
private void ListSelectedItemChanged(object sender, MouseButtonEventArgs e) { ListViewItem selected = sender as ListViewItem; string selection = selected.Content.ToString().Replace(actionRequiredString, string.Empty); ProductData product = data.Products.Where(x => x.Product == selection).First(); ProductName.Text = product.Product; ProductQty.Text = product.Quantity.ToString(); try { WorkerAssignmentData assignment = assignments.Where(x => x.orders.Exists(y => y.Product == selection)).First(); WorkerAssignment.SelectedItem = assignment.worker; } catch (Exception) { WorkerAssignment.SelectedIndex = -1; } }
private void SendAssignment(WorkerAssignmentData assignment) { string subject = "Proszę o realizację zamówienia."; StringBuilder builder = new StringBuilder(); foreach (ProductData product in assignment.orders) { builder.Append(product.Product); builder.Append(", ilość : "); builder.Append(product.Quantity); builder.Append("\n"); } MailSender esender = new MailSender(); esender.Send(assignment.worker.Email, builder.ToString(), subject, null); }
public static Workbook CreateWorkbookFromAssignment(WorkerAssignmentData assignment) { Workbook workbook = new Workbook(); Worksheet worksheet = new Worksheet("First Sheet"); worksheet.Cells[0, 0] = new Cell("id"); worksheet.Cells[0, 1] = new Cell("Product name"); worksheet.Cells[0, 2] = new Cell("Quantity"); worksheet.Cells[0, 3] = new Cell("Price"); for (int i = 0; i < assignment.orders.Count; i++) { worksheet.Cells[i + 1, 0] = new Cell(i); worksheet.Cells[i + 1, 1] = new Cell(assignment.orders[i].Product); worksheet.Cells[i + 1, 2] = new Cell(assignment.orders[i].Quantity); } workbook.Worksheets.Add(worksheet); return(workbook); }