public static List <Componente> EstraiListaComponenti(int idDiba) { ArticoliDS ds = new ArticoliDS(); using (ArticoliBusiness bArticolo = new ArticoliBusiness()) { bArticolo.GetCOMPONENTI(ds, idDiba, true); bArticolo.GetFASICICLO(ds, idDiba, true); } List <Componente> componenti = new List <Componente>(); foreach (ArticoliDS.COMPONENTIRow riga in ds.COMPONENTI) { Componente componente = CreaComponente(riga, ds); componenti.Add(componente); } return(componenti); }
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); } }