public void AgregarPrograma(DTOProgram program)
        {
            string sSel;
            string sSelCount;
            bool exist;
            sSelCount = "SELECT COUNT(*) FROM \"tbl_Program\" WHERE \"idProgram\"=" + program.IdProgram;
            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_Program\" VALUES("+ program.IdProgram;
                if (program.Title != "")
                    sSel = sSel + ",'" + program.Title.Replace("'","") + "'";
                else
                    sSel = sSel + ",NULL";

                if (program.RTitle != "")
                    sSel = sSel + ",'" + program.RTitle.Replace("'", "") + "'";
                else
                    sSel = sSel + ",NULL";

                if (program.Description != "")
                    sSel = sSel + ",'" + program.Description.Replace("'", "") + "'";
                else
                    sSel = sSel + ",NULL";

                if (program.RDescription != "")
                    sSel = sSel + ",'" + program.RDescription.Replace("'", "") + "'";
                else
                    sSel = sSel + ",NULL";

                if (program.EpisodeTitle != "")
                    sSel = sSel + ",'" + program.EpisodeTitle.Replace("'", "") + "'";
                else
                    sSel = sSel + ",NULL";

                if (program.IdCategory != 0)
                    sSel = sSel + "," + program.IdCategory+");";
                else
                    sSel = sSel + ",NULL);";

                NpgsqlDataAdapter da;
                DataSet dt = new DataSet();

                try
                {
                    da = new NpgsqlDataAdapter(sSel, sConexion);
                    da.Fill(dt);
                }
                catch (Exception)
                {

                }
            }
        }
Пример #2
0
        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);
            }
        }