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 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_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_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_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(); }