private void zarzadzanieDodajButton_Click(object sender, EventArgs e) { var employeeForm = new EmployeeForm(); if (employeeForm.ShowDialog(this) == DialogResult.OK) { AsyncTaskRunner task = new AsyncTaskRunner( new Task( () => { Zarzadzanie_AddEmployee(employeeForm.Employee); }), () => { MessageBox.Show("Utworzono użytkownika: " + employeeForm.Employee.Login, "Sukces", MessageBoxButtons.OK, MessageBoxIcon.Information); Zarzadzanie_UpdatePracownicyListBox(); }); task.StartInTransaction(); } }
private void DoLogin(string id, string enteredLogin, string enteredPassword) { if (isLogging) return; int enteredPharmacyId; if (!Int32.TryParse(id, out enteredPharmacyId)) { MessageBox.Show("Nieprawidłowe Id apteki!", "Błąd", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } zalogujButton.Enabled = false; zalogujButton.Text = "Logowanie"; buttonTimer.Start(); bool loginSucceeded = true; isLogging = true; AsyncTaskRunner task = new AsyncTaskRunner(new Task( () => { loginSucceeded = Authorize(enteredPharmacyId, enteredLogin, enteredPassword); } ), () => { buttonTimer.Stop(); isLogging = false; if (!loginSucceeded) { MessageBox.Show("Użytkownik nie istnieje.", "Błąd", MessageBoxButtons.OK, MessageBoxIcon.Information); zalogujButton.Enabled = true; zalogujButton.Text = "Zaloguj"; } else { zalogujButton.Text = "Sukces!"; _context.Dispose(); this.DialogResult = DialogResult.Yes; } }); task.Start(); }
private void Obsluga_AcceptNewOrder() { var orderDetails = Obsluga_GenerateOrderDetailsFromGridView(obslugaDataGridView.Rows); Order newOrder = null; try { AsyncTaskRunner task = new AsyncTaskRunner( new Task( () => { foreach (var orderDetail in orderDetails) { orderDetail.Product.OnStock -= orderDetail.Quantity; } var employee = UnitOfWork.EmployeeRepository.GetEmployeeById(AptekaGlobals.ActiveEmployeeId); var pharmacy = employee.Pharmacy;// UnitOfWork.PharmacyRepository.GetPharmacyById(AptekaGlobals.ActivePharmacyId); newOrder = new Order(orderDetails) { Date = DateTime.Now, Employee = employee, Pharmacy = pharmacy }; UnitOfWork.OrderRepository.Create(newOrder); UnitOfWork.SaveChanges(); }), () => { MessageBox.Show("Zrealizowano zamówienie na kwotę: " + String.Format("{0:N2}", newOrder.CalculatePrice() + " zł"), "Sukces", MessageBoxButtons.OK, MessageBoxIcon.Information); OrderAcceptedEvent.Invoke(this, null); Obsluga_ResetOrder(); } ); task.StartInTransaction(); } catch (Exception) { MessageBox.Show("Błąd - nie udało się zrealizować zamówienia"); throw; } }
private void zarzadzaniePracownicyListBox_MouseDoubleClick(object sender, MouseEventArgs e) { ListViewHitTestInfo info = zarzadzaniePracownicyListBox.HitTest(e.X, e.Y); ListViewItem item = info.Item; if (item != null) { var employee = item.Tag as Employee; var employeeForm = new EmployeeForm(employee); if (employeeForm.ShowDialog(this) == DialogResult.OK) { AsyncTaskRunner task = new AsyncTaskRunner( new Task( () => { Zarzadzanie_UpdateEmployee(employee); }), () => { MessageBox.Show("Zaktualizowano dane pracownika: " + employee.Login, "Sukces", MessageBoxButtons.OK, MessageBoxIcon.Information); Zarzadzanie_UpdatePracownicyListBox(); }); task.StartInTransaction(); } } }
private void Zarzadzanie_StanMagazynu_AddNewProduct(Medicine medicine) { try { Product newProduct = null; AsyncTaskRunner task = new AsyncTaskRunner( new Task( () => { var activePharmacy = UnitOfWork.PharmacyRepository.GetPharmacyById(AptekaGlobals.ActivePharmacyId); newProduct = new Product() { Pharmacy = activePharmacy, Medicine = medicine, OnStock = 1, Price = 10.00 }; activePharmacy.Products.Add(newProduct); UnitOfWork.SaveChanges(); }), () => { Zarzadzanie_StanMagazynu_AddRow(newProduct); }); task.StartInTransaction(); } catch (Exception xcp) { MessageBox.Show(xcp.Message); } }
private void Zarzadzanie_RemoveSelectedProducts() { List<Product> productsToDelete = new List<Product>(); foreach (DataGridViewCell selectedCell in zarzadzanieStanMagazynuDataGridView.SelectedCells) { var row = zarzadzanieStanMagazynuDataGridView.Rows[selectedCell.RowIndex]; var product = row.Tag as Product; productsToDelete.Add(product); } try { AsyncTaskRunner task = new AsyncTaskRunner( new Task( () => { foreach (var product in productsToDelete) { UnitOfWork.ProductRepository.Delete(product); } UnitOfWork.SaveChanges(); }), () => { foreach (DataGridViewCell selectedCell in zarzadzanieStanMagazynuDataGridView.SelectedCells) { zarzadzanieStanMagazynuDataGridView.Rows.RemoveAt(selectedCell.RowIndex); } }); task.StartInTransaction(); } catch (Exception xcp) { Zarzadzanie_UpdateStanMagazynuGrid(); MessageBox.Show(xcp.Message); } }
private void zarzadzanieStanMagazynuDataGridView_CellEndEdit(object sender, DataGridViewCellEventArgs e) { var row = zarzadzanieStanMagazynuDataGridView.Rows[e.RowIndex]; var column = zarzadzanieStanMagazynuDataGridView.Columns[e.ColumnIndex]; var cell = row.Cells[e.ColumnIndex]; Product p = row.Tag as Product; try { AsyncTaskRunner task = new AsyncTaskRunner( new Task(() => { if (column.Name == "Zarzadzanie_ProductOnStockHeader") { var onStock = Zarzadzanie_StanMagazynu_CheckStringIsValidQuantity(cell.Value as string); p.OnStock = onStock; } else if (column.Name == "Zarzadzanie_ProductPriceHeader") { var price = Zarzadzanie_StanMagazynu_CheckStringIsValidPrice(cell.Value as string); p.Price = price; } UnitOfWork.ProductRepository.Update(p); UnitOfWork.SaveChanges(); }), null); task.StartInTransaction(); } catch (ArgumentException xcp) { cell.Value = "1"; MessageBox.Show(xcp.Message, "Błąd", MessageBoxButtons.OK, MessageBoxIcon.Warning); } catch (Exception xcp) { cell.Value = "1"; MessageBox.Show("Podana wartość nie jest poprawną liczbą", "Błąd", MessageBoxButtons.OK, MessageBoxIcon.Warning); } }
private void daneZapiszButton_Click(object sender, EventArgs e) { var transactionScope = new TransactionScope(); try { AsyncTaskRunner task = new AsyncTaskRunner( new Task(() => { Pharmacy currentPharmacy = UnitOfWork.PharmacyRepository.GetPharmacyById(AptekaGlobals.ActivePharmacyId); currentPharmacy.Name = daneNazwaTextBox.Text; currentPharmacy.Address.Street = daneUlicaTextBox.Text; currentPharmacy.Address.HouseNumber = daneNrTextBox.Text; currentPharmacy.Address.City = daneMiastoTextBox.Text; currentPharmacy.Address.PostalCode = daneKodTextBox.Text; currentPharmacy.Phone = daneTelefonTextBox.Text; UnitOfWork.SaveChanges(); transactionScope.Complete(); }), () => { MessageBox.Show("Zaktualizowano dane.", "Sukces", MessageBoxButtons.OK, MessageBoxIcon.Information); transactionScope.Dispose(); }); task.Start(); } catch (Exception) { MessageBox.Show("Błąd - nie udało się zmodyfikować danych"); throw; } }
private void Leksykon_ATCFindMatching(string searchText) { IEnumerable<ATCType> searchResults = null; AsyncTaskRunner task = new AsyncTaskRunner( new Task( () => { searchResults = (from atc in UnitOfWork.Context.ATCTypes.ToList() where atc.Code.StartsWith(searchText) select atc); }), () => { leksykonATCTreeView.Nodes.Clear(); var rootNode = leksykonATCTreeView.Nodes.Add("root", "Indeks ATC"); int minLength = searchResults.Min(atc => atc.Code.Length); searchResults = searchResults.Where(atc => atc.Code.Length == minLength); foreach (var atc in searchResults) { FillATCTree(atc, rootNode); } }); task.Start(); }
private void Leksykon_NMFindMatching(string searchText) { IEnumerable<string> searchResults = null; AsyncTaskRunner task = new AsyncTaskRunner( new Task( () => { searchResults = (from internationalName in UnitOfWork.MedicineRepository.GetAllInternationalNames() where internationalName.ToLower().Contains(searchText.ToLower()) select internationalName); }), () => { leksykonNMListView.Items.Clear(); foreach (var internationalName in searchResults) { ListViewItem item = new ListViewItem(internationalName); leksykonNMListView.Items.Add(item); } }); task.Start(); }
private void Leksykon_FFFindMatching(string searchText) { IEnumerable<string> searchResults = null; AsyncTaskRunner task = new AsyncTaskRunner( new Task( () => { searchResults = (from producer in UnitOfWork.MedicineRepository.GetAllProducerNames() where producer.ToLower().Contains(searchText.ToLower()) select producer); }), () => { leksykonFFListView.Items.Clear(); foreach (var producer in searchResults) { ListViewItem item = new ListViewItem(producer); leksykonFFListView.Items.Add(item); } }); task.Start(); }