private void btnEstraiFasi_Click(object sender, EventArgs e) { txtMessaggio.Text = string.Empty; try { if (string.IsNullOrEmpty(txtNoCiclo.Text)) { txtMessaggio.Text = "Inserire un codice distinta"; return; } BCServices bc = new BCServices(); bc.CreaConnessione(); StringBuilder sb = new StringBuilder(); List <RigheCICLO> righe = bc.EstraiRigheCICLO(txtNoCiclo.Text); sb.AppendLine(string.Format("Trovate {0} righe", righe.Count)); foreach (RigheCICLO r in righe) { sb.AppendLine(string.Format("{0} {1} {2} {3} {4} {5}", r.Operation_No, r.Routing_No, r.No, r.Standard_Task_Code, r.Description, r.MTP_Card_Code)); } txtMessaggio.Text = sb.ToString(); } catch (Exception ex) { txtMessaggio.Text = estraiErrore(ex); } }
private void esportaCicli(List <string> cicli, BackgroundWorker worker, DoWorkEventArgs e, ref int contatore) { BCServices bc = new BCServices(); bc.CreaConnessione(); WorkerDTO dto = (WorkerDTO)e.Argument; foreach (string ciclo in cicli) { worker.ReportProgress(contatore, string.Format(string.Empty, ciclo)); worker.ReportProgress(contatore, string.Format("Ciclo {0}", ciclo)); contatore++; try { Cicli testata = bc.EstraiTestataCiclo(ciclo); if (testata != null) { bc.CambiaDescrizioneCiclo(ciclo, testata.Description); testata = bc.EstraiTestataCiclo(ciclo); if (testata.Status != Stato.InSviluppo) { string messaggio = string.Format("Ciclo {0} ignorato perchè in stato {1}", ciclo, testata.Status); worker.ReportProgress(contatore, messaggio); if (worker.CancellationPending) { e.Cancel = true; return; } continue; } List <RigheCICLO> righe = bc.EstraiRigheCICLO(ciclo); foreach (RigheCICLO riga in righe) { bc.RimuoviCommento(ciclo, string.Empty, riga.Operation_No, false); bc.RimuoviFase(ciclo, string.Empty, riga.Operation_No, false); } bc.Salva(); foreach (ExpFaseCicloBusinessCentral f in dto.FasiExport.Where(x => x.CodiceCiclo == ciclo).OrderBy(x => x.Operazione)) { try { f.Errore = string.Empty; bc.AggiungiFase(ciclo, string.Empty, f.Operazione.ToString(), f.Tipo, f.AreaProduzione, f.Task, (decimal)f.TempoSetup, f.UMSetup, f.SchedaProcesso, (decimal)f.TempoLavorazione, f.UMLavorazione, (decimal)f.TempoAttesa, f.UMAttesa, (decimal)f.TempoSpostamento, f.UMSpostamento, (decimal)f.DimensioneLotto, f.Collegamento, f.Condizione, f.LogicheLavorazione, f.Caratteristica, f.Descrizione); bc.AggiungiCommento(ciclo, string.Empty, f.Operazione.ToString(), f.CommentiConcatenati()); f.Esito = "OK"; } catch (Exception ex) { string messaggio = string.Format("Ciclo {0} operazione {1} non esportato per il seguente errore: {2}", ciclo, f.Operazione, ex.Message); { f.Errore = ex.Message; f.Esito = "KO"; } worker.ReportProgress(contatore, messaggio); } } worker.ReportProgress(contatore, string.Format("Ciclo {0} terminato", ciclo)); } else { string messaggio = string.Format("Il ciclo {0} non è stato trovato", ciclo); foreach (ExpFaseCicloBusinessCentral c in dto.FasiExport.Where(x => x.CodiceCiclo == ciclo)) { c.Errore = messaggio; c.Esito = "KO"; } worker.ReportProgress(contatore, messaggio); } } catch (Exception ex) { string messaggio = string.Format("Ciclo {0} non esportato per il seguente errore: {1}", ciclo, ex.Message); foreach (ExpFaseCicloBusinessCentral f in dto.FasiExport.Where(x => x.CodiceCiclo == ciclo).OrderBy(x => x.Operazione)) { f.Errore = "Eccezione"; f.Esito = "KO"; } worker.ReportProgress(contatore, messaggio); } finally { bc.CreaConnessione(); } if (worker.CancellationPending) { e.Cancel = true; return; } } }