private void BackgroundWorker1_ProgressChanged(object sender, ProgressChangedEventArgs e) { // Refresh UI controls LoadedXmlStatus loadedXmlStatus = e.UserState as LoadedXmlStatus; SetXmlLoadingStatusMessage("Učitavanje podataka " + loadedXmlStatus.Naziv, true); DisplayXmlLoadingStatusMessageRow(loadedXmlStatus); // progress bar progressBgWorker1.Value = e.ProgressPercentage; progressLabel.Text = e.ProgressPercentage.ToString() + "%"; }
private LoadedXmlStatus SetXmlLoadingStatus(int redniBroj, bool isLoaded, int numberOfRecords, string statusDescription, KonfigDobavljaca konfigDobavljaca) { // status učitavanja LoadedXmlStatus status = new LoadedXmlStatus() { Number = redniBroj, Naziv = konfigDobavljaca.Naziv, URL = konfigDobavljaca.URL, NumberOfRecords = numberOfRecords, IsLoaded = isLoaded, StatusDescription = statusDescription, DataSource = konfigDobavljaca.WebProtokol, konfigDobavljaca = konfigDobavljaca }; return(status); }
private void DisplayXmlLoadingStatusMessageRow(LoadedXmlStatus status) { // prikaz statusa učitavanja DataGridViewRow row = new DataGridViewRow(); string isLoaded = status.IsLoaded ? "OK" : "Greška"; row.CreateCells(dgvStatus); // prkaz kolona u prikazu statusa učitavanja row.SetValues( status.Number, status.Naziv, isLoaded, status.NumberOfRecords, status.StatusDescription, status.DataSource, status.konfigDobavljaca.Id // nije vidljiva kolona, koristi se za selektovanje Id-a dobavljača (Name: 'IdDobavljaca') ); // markira kolonu u drugu boju ako deserijalizacija xml-a nije uspela if (!status.IsLoaded) { DataGridViewCellStyle style = new DataGridViewCellStyle(); style.BackColor = Color.Yellow; style.ForeColor = Color.DarkRed; row.DefaultCellStyle = style; } dgvStatus.Rows.Add(row); dgvStatus.ClearSelection(); dgvStatus.Refresh(); }
private void LoadXmlFilesForAllSuppliers(object sender, DoWorkEventArgs e) { // Xml rezultat za jednog dobavljača List <B2B_Results_RowItem> b2B_Results_RowItems; List <KonfigDobavljaca> suppliersConfigurations = DBHelper.Instance.GetAllSupplierConfigurations(); BackgroundWorker worker = sender as BackgroundWorker; int totalSuppliers = suppliersConfigurations.Count(); for (int currentSupplierIndex = 0; currentSupplierIndex < totalSuppliers; currentSupplierIndex++) { // progress bar percentage decimal progressBarPercentage = (currentSupplierIndex + 1) * (decimal)(100 / totalSuppliers); // kod poslednjeg dobavljača progress je 100% if (currentSupplierIndex + 1 == totalSuppliers) { progressBarPercentage = 100; } // cancelled backgroung worker if (worker.CancellationPending) { e.Cancel = true; return; } b2B_Results_RowItems = new List <B2B_Results_RowItem>(); // učitavanje podataka LoadedXmlStatus loadedXmlStatus = new LoadedXmlStatus(); bool isLoaded = true; int numberOfRecords = 0; try { b2B_Results_RowItems = XMLHelper.Instance.GetB2B_Results_RowItems_PerSupplier(suppliersConfigurations[currentSupplierIndex]); // set loading status numberOfRecords = b2B_Results_RowItems.Count; if (numberOfRecords == 0) { isLoaded = false; } // set loaded xmlStatuses loadedXmlStatus = SetXmlLoadingStatus(currentSupplierIndex + 1, isLoaded, numberOfRecords, XMLHelper.StatusDescription, suppliersConfigurations[currentSupplierIndex]); // background worker report status worker.ReportProgress((int)progressBarPercentage, loadedXmlStatus); } catch (Exception xcp) { //SetXmlLoadingStatusMessage("Greška " + suppliersConfigurations[currentSupplierIndex].Naziv, true); // set loaded xmlStatuses isLoaded = false; loadedXmlStatus = SetXmlLoadingStatus(currentSupplierIndex + 1, isLoaded, numberOfRecords, XMLHelper.StatusDescription, suppliersConfigurations[currentSupplierIndex]); // background worker report status worker.ReportProgress((int)progressBarPercentage, loadedXmlStatus); continue; } // dodavanje u listu rezultata učitavanja B2B_Results_Rows_AllSuppliers.AddRange(b2B_Results_RowItems); } }