public void AgregarCategoria(DTOCategory category)
        {
            string sSel;
            string sSelCount;
            bool exist;
            sSelCount = "SELECT COUNT(*) FROM \"tbl_ProgramCategory\" WHERE \"idCategory\"=" + category.IdCategory + "";
            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)
            {
                if (category.IdFather != 0)
                    sSel = "INSERT INTO \"tbl_ProgramCategory\" VALUES(" + category.IdCategory + ",'" + category.MscName + "','" + category.CategoryName + "'," + category.IdFather + ");";
                else
                    sSel = "INSERT INTO \"tbl_ProgramCategory\" VALUES(" + category.IdCategory + ",'" + category.MscName + "','" + category.CategoryName + "',-1)";

                NpgsqlDataAdapter da;
                DataSet dt = new DataSet();

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

                }
            }
        }
Esempio n. 2
0
        static void InsertCategories(XmlDocument xmlDoc)
        {
            try
            {
                Console.WriteLine("Categoria de Programas");
                DTOCategory categoria = new DTOCategory();
                XmlNodeList categories = xmlDoc.GetElementsByTagName("glf")[0].ChildNodes[0].ChildNodes[5].ChildNodes;
                int i = categories.Count;
                int j = 0;
                foreach (XmlNode category in categories)
                {
                    categoria.IdCategory = Int64.Parse(category.Attributes["id"].Value);
                    categoria.MscName = category.Attributes["mscname"].Value;
                    categoria.CategoryName = category.Attributes["value"].Value;
                    categoria.IdFather = 0;
                    conexion.AgregarCategoria(categoria);
                    foreach (XmlNode subCategory in category.ChildNodes)
                    {
                        categoria.IdCategory = Int64.Parse(subCategory.Attributes["id"].Value);
                        categoria.MscName = subCategory.Attributes["mscname"].Value;
                        categoria.CategoryName = subCategory.Attributes["value"].Value;
                        categoria.IdFather = Int64.Parse(category.Attributes["id"].Value);
                        conexion.AgregarCategoria(categoria);
                    }

                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }