private void btnAggiuntiFase_Click(object sender, EventArgs e) { txtMessaggio.Text = string.Empty; try { if (string.IsNullOrEmpty(txtNoCiclo.Text)) { txtMessaggio.Text = "Inserire un codice ciclo"; return; } if (ddlAreaProduzione.SelectedIndex == -1) { txtMessaggio.Text = "Selezionare un area produzione"; return; } if (ddlTask.SelectedIndex == -1) { txtMessaggio.Text = "Selezionare un task"; return; } BCServices bc = new BCServices(); bc.CreaConnessione(); bc.CambiaStatoCiclo(txtNoCiclo.Text, Stato.InSviluppo); int operazione = (int)nOperazioneFase.Value; AreaProduzione area = (AreaProduzione)ddlAreaProduzione.SelectedItem; TaskArea task = (TaskArea)ddlTask.SelectedItem; bc.AggiungiFase(txtNoCiclo.Text, txtVersioneCiclo.Text, operazione.ToString(), txtTipoFase.Text, area.Codice, task.Task, nSetupFase.Value, txtUMSetupFase.Text, txtCodiceScheda.Text, nLavorazioneFase.Value, txtUMLavorazioneFase.Text, nAttesaFase.Value, txtUMAttesaFase.Text, nSpostamentoFase.Value, txtUMSpostamentoFase.Text, nDimensioneLottoFase.Value, txtCollegmentoFase.Text, txtCodiceCondizioneFase.Text, txtCodiceLogicheFase.Text, txtCodiceCaratteristicaFase.Text, string.Empty); bc.CambiaStatoCiclo(txtNoCiclo.Text, Stato.Certificato); txtMessaggio.Text = "Fase aggiunta"; } 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; } } }