private static Componente CreaComponente(ArticoliDS.COMPONENTIRow riga, ArticoliDS ds) { if (riga == null) { return(null); } Componente componente = new Componente(); componente.IdDiba = riga.IDDIBA; componente.IdComponente = riga.IDCOMPONENTE; componente.IdPadre = riga.IsIDPADRENull() ? 0 : riga.IDPADRE; componente.Anagrafica = riga.IsANAGRAFICANull() ? string.Empty : riga.ANAGRAFICA; componente.Descrizione = riga.DESCRIZIONE; componente.CollegamentoDiBa = riga.IsCOLLEGAMENTODIBANull() ? string.Empty : riga.COLLEGAMENTODIBA; componente.UMQuantita = riga.IsUMQUANTITANull() ? string.Empty : riga.UMQUANTITA; componente.Quantita = riga.IsUMQUANTITANull() ? 0 : riga.QUANTITA; componente.Errore = string.Empty; componente.FasiCiclo = new List <FaseCiclo>(); componente.Cancellato = riga.CANCELLATO; componente.DataModifica = riga.DATAMODIFICA; componente.UtenteModifica = riga.UTENTEMODIFICA; componente.FasiCiclo = FaseCiclo.EstraiListaFaseCiclo(componente, ds); return(componente); }
private void UpdateComponentiHander(object sender, RowUpdatedEventArgs e) { if ((e.Status == UpdateStatus.Continue) && (e.StatementType == StatementType.Insert)) { ArticoliDS.COMPONENTIRow row = (ArticoliDS.COMPONENTIRow)e.Row; ArticoliDS.COMPONENTIDataTable dt = row.Table as ArticoliDS.COMPONENTIDataTable; bool isIdentityReadOnly = dt.IDCOMPONENTEColumn.ReadOnly; dt.IDCOMPONENTEColumn.ReadOnly = false; try { row.IDCOMPONENTE = (int)RetrievePostUpdateID <decimal>(e.Command, row); } catch (Exception ex) { throw ex; } finally { dt.IDCOMPONENTEColumn.ReadOnly = isIdentityReadOnly; } } }
public static void SalvaListaComponenti(List <Componente> componenti, string utente) { if (componenti.Count() == 0) { return; } int idDiba = componenti[0].IdDiba; ArticoliDS ds = new ArticoliDS(); using (ArticoliBusiness bArticolo = new ArticoliBusiness()) { bArticolo.GetCOMPONENTI(ds, idDiba, true); bArticolo.GetFASICICLO(ds, idDiba, true); List <int> idComponentiAttivi = componenti.Select(x => x.IdComponente).ToList(); List <int> idComponentiDaCancellare = ds.COMPONENTI.Where(x => !idComponentiAttivi.Contains(x.IDCOMPONENTE)).Select(x => x.IDCOMPONENTE).ToList(); foreach (int idComponenteDaCancellare in idComponentiDaCancellare) { ArticoliDS.COMPONENTIRow componenteDaCancellare = ds.COMPONENTI.Where(x => x.RowState != System.Data.DataRowState.Deleted && x.IDCOMPONENTE == idComponenteDaCancellare).FirstOrDefault(); componenteDaCancellare.CANCELLATO = true; componenteDaCancellare.UTENTEMODIFICA = utente; componenteDaCancellare.DATAMODIFICA = DateTime.Now; } //Componente radice = componenti.Where(x => x.IdPadre == 0).FirstOrDefault(); //if (radice == null) return; //salvaComponentiRicorsivo(radice, ds, componenti, utente); foreach (Componente componente in componenti.OrderByDescending(x => x.IdPadre)) { // preparaSalvataggio(componente, ds, utente); ArticoliDS.COMPONENTIRow rigaComponente = ds.COMPONENTI.Where(x => x.RowState != System.Data.DataRowState.Deleted && x.IDCOMPONENTE == componente.IdComponente).FirstOrDefault(); if (rigaComponente == null || componente.IdComponente < 0) { rigaComponente = ds.COMPONENTI.NewCOMPONENTIRow(); rigaComponente.IDCOMPONENTE = componente.IdComponente; if (componente.IdPadre != 0) { rigaComponente.IDPADRE = componente.IdPadre; } rigaComponente.IDDIBA = componente.IdDiba; rigaComponente.DESCRIZIONE = componente.Descrizione.ToUpper(); rigaComponente.ANAGRAFICA = (string.IsNullOrEmpty(componente.Anagrafica)) ? string.Empty : componente.Anagrafica.ToUpper(); rigaComponente.COLLEGAMENTODIBA = (string.IsNullOrEmpty(componente.CollegamentoDiBa)) ? string.Empty : componente.CollegamentoDiBa.ToUpper(); rigaComponente.QUANTITA = componente.Quantita; rigaComponente.UMQUANTITA = (string.IsNullOrEmpty(componente.UMQuantita)) ? string.Empty : componente.UMQuantita.ToUpper(); rigaComponente.CANCELLATO = false; rigaComponente.DATAMODIFICA = DateTime.Now; rigaComponente.UTENTEMODIFICA = utente; ds.COMPONENTI.AddCOMPONENTIRow(rigaComponente); } else { if (componente.IdPadre != 0) { rigaComponente.IDPADRE = componente.IdPadre; } rigaComponente.DESCRIZIONE = componente.Descrizione.ToUpper(); rigaComponente.ANAGRAFICA = (string.IsNullOrEmpty(componente.Anagrafica)) ? string.Empty : componente.Anagrafica.ToUpper(); rigaComponente.COLLEGAMENTODIBA = (string.IsNullOrEmpty(componente.CollegamentoDiBa)) ? string.Empty : componente.CollegamentoDiBa.ToUpper(); rigaComponente.QUANTITA = componente.Quantita; rigaComponente.UMQUANTITA = (string.IsNullOrEmpty(componente.UMQuantita)) ? string.Empty : componente.UMQuantita.ToUpper(); rigaComponente.CANCELLATO = false; rigaComponente.DATAMODIFICA = DateTime.Now; rigaComponente.UTENTEMODIFICA = utente; } FaseCiclo.SalvaListaFaseCiclo(componente.FasiCiclo, utente, componente.IdDiba, componente.IdComponente, ds); } DataRow[] root = ds.COMPONENTI.Where(x => x.IsIDPADRENull()).ToArray(); // DataRow[] altriNodi = ds.COMPONENTI.Where(x => !x.IsIDPADRENull()).OrderByDescending(x => x.IDPADRE).ToArray(); salvaComponentiRicorsivo(root, ds, bArticolo); //bArticolo.UpdateComponentiTable(ds.COMPONENTI.TableName, root); //bArticolo.UpdateComponentiTable(ds.COMPONENTI.TableName, altriNodi); bArticolo.UpdateTable(ds.FASICICLO.TableName, ds); } }