Esempio n. 1
0
        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();
                        }
                    }
                }
            }
        }
Esempio n. 2
0
 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 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);
             }
         }
     }
 }