private void UpdateCustomerFields(Customer selectedCustomer) { //Clear products items so they don't overlap when selecting another customer productsBox.Items.Clear(); //Populate text fields bulstatText.Text = selectedCustomer.Bulstat.ToString(); molText.Text = selectedCustomer.MOL.ToString(); vatCheck.Checked = selectedCustomer.RegisteredOnVAT; nameText.Text = selectedCustomer.Name; addressText.Text = selectedCustomer.Address; }
private void insertBtn_Click(object sender, EventArgs e) { Random random = new Random(); List<Product> randomProducts = new List<Product>(); int numberOfRecords; bool isParseSucessfull = int.TryParse(numberOfRecordsField.Text, out numberOfRecords); if (isParseSucessfull) { //Create all users progressBar.Minimum = 1; progressBar.Maximum = numberOfRecords; var newUnit = new UnitOfWork(); // Task.Run(() => // { // Parallel.For(0, numberOfRecords, (i) => // { // //var newUnit = new UnitOfWork(); // // Console.WriteLine("N: " + i); // Customer randomCustomer = new Customer // { // Bulstat = random.Next(1000000), // MOL = "NEW " + random.Next(1000000).ToString(), // Name = "NEW NAME", // Address = "NEW ADDRESS", // Password = GeneratePassword(), // RegisteredOnVAT = true, // IsDeleted = false // }; // Order randomOrder = new Order // { // Date = DateTime.Now // }; // // for (int j = 0; j < 250; j++) // { // ProductOrder randomProductOrder = new ProductOrder // { // Quantity = 250 // }; // // randomProductOrder.ProductID = 5; // randomOrder.ProductOrders.Add(randomProductOrder); // } // randomCustomer.Orders.Add(randomOrder); // newUnit.CustomerRepository.Add(randomCustomer); // if (newUnit.TrySave() == false) // { // Console.WriteLine("ERROR SAVING"); // } // // }); // }); FDebug.Start(); for (int i = 0; i < numberOfRecords; i++) { Console.WriteLine("N: " + i); Customer randomCustomer = new Customer { Bulstat = random.Next(1000000), MOL = "NEW " + random.Next(1000000).ToString(), Name = "NEW NAME", Address = "NEW ADDRESS", Password = GeneratePassword(), RegisteredOnVAT = true, IsDeleted = false }; Order randomOrder = new Order { Date = DateTime.Now }; for (int j = 0; j < 250; j++) { ProductOrder randomProductOrder = new ProductOrder { Quantity = 250 }; randomProductOrder.ProductID = 5; randomOrder.ProductOrders.Add(randomProductOrder); } randomCustomer.Orders.Add(randomOrder); newUnit.CustomerRepository.Add(randomCustomer); if (newUnit.TrySave() == false) { } progressBar.PerformStep(); } FDebug.End(); timeLabel.Text = FDebug.TimeElapsed(); //IsAnythignInserted = true; } }
private void newCustomerBtn_Click(object sender, EventArgs e) { if (creatingCustomer == false) { ClearFields(); MessageBox.Show("Insert data into the fields \n and press 'Add Customer'."); newCustomerBtn.Text = "Add Customer"; creatingCustomer = true; //Return before the boolean flag reaches the next check return; } Customer insertCustomer = new Customer { Bulstat = int.Parse(bulstatText.Text), MOL = molText.Text, RegisteredOnVAT = vatCheck.Checked, Name = nameText.Text, Address = addressText.Text }; unitOfWork.CustomerRepository.Add(insertCustomer); newCustomerBtn.Text = "New customer"; }
private void customersBox_SelectedIndexChanged(object sender, EventArgs e) { selectedCustomer = unitOfWork.CustomerRepository .GetById(c => c.ID == currentUsableCustomers[customersBox.SelectedIndex].ID); selectedCustomerOrders = unitOfWork.OrdersRepository .GetOrdersByCustomerId(selectedCustomer.ID) .ToList(); UpdateCustomerFields(selectedCustomer); PopulateOrdersData(); }