public void AgregarProgramaActorRole(DTOProgramActorRole par) { string sSel; string sSelCount; bool exist; sSelCount = "SELECT COUNT(*) FROM \"tbl_ProgramActorRole\" WHERE \"idProgram\" = " + par.IdProgram + " AND \"idActor\"="+ par.IdActor +" AND \"idRole\" = "+ par.IdRole +";"; NpgsqlDataAdapter daCount; DataSet dtCount = new DataSet(); try { daCount = new NpgsqlDataAdapter(sSelCount, sConexion); daCount.Fill(dtCount); if (dtCount.Tables[0].Rows[0][0].ToString() == "0") exist = false; else exist = true; } catch (Exception) { exist = false; } if (!exist) { sSel = "INSERT INTO \"tbl_ProgramActorRole\" VALUES(" + par.IdProgram + "," + par.IdActor + "," + par.IdRole + ","+ par.Order +");"; NpgsqlDataAdapter da; DataSet dt = new DataSet(); try { da = new NpgsqlDataAdapter(sSel, sConexion); da.Fill(dt); } catch (Exception) { } } }
static void InsertPrograms(XmlDocument doc) { try { Console.WriteLine("Programas"); DTOProgram programa = new DTOProgram(); DTOProgramActorRole par = new DTOProgramActorRole(); XmlNodeList programs = doc.GetElementsByTagName("glf")[0].ChildNodes[0].ChildNodes[1].ChildNodes; int i = programs.Count; int j = 0; foreach (XmlNode program in programs) { programa.IdProgram = Int64.Parse(program.Attributes["id"].Value); if (program.Attributes["t"] != null) programa.Title = program.Attributes["t"].Value; else programa.Title = ""; if (program.Attributes["rt"] != null) programa.RTitle = program.Attributes["rt"].Value; else programa.RTitle = ""; if (program.Attributes["d"] != null) programa.Description = program.Attributes["d"].Value; else programa.Description = ""; if (program.Attributes["rd"] != null) programa.RDescription = program.Attributes["rd"].Value; else programa.RDescription = ""; if (program.Attributes["et"] != null) programa.EpisodeTitle = program.Attributes["et"].Value; else programa.EpisodeTitle = ""; XmlNode category = buscarCategoria(program); if (category != null) programa.IdCategory = Int64.Parse(category.Attributes["id"].Value); else programa.IdCategory = 0; conexion.AgregarPrograma(programa); ArrayList roles = buscarRole(program); foreach (XmlNode role in roles) { par.IdProgram = programa.IdProgram; par.IdActor = Int32.Parse(role.Attributes["n"].Value); par.IdRole = Int32.Parse(role.Attributes["r"].Value); par.Order = Int32.Parse(role.Attributes["o"].Value); conexion.AgregarProgramaActorRole(par); } } } catch (Exception ex) { Console.WriteLine(ex.Message); } }