public void AgregarHorario(DTOSchedule schedule)
        {
            string sSel;
            string sSelCount;
            bool exist;
            sSelCount = "SELECT COUNT(*) FROM \"tbl_Schedule\" WHERE \"startDate\" = '" + schedule.StartDate + "' AND \"endDate\"='"+ schedule.EndDate +"' AND \"idChannel\" = " + schedule.IdChannel;
            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_Schedule\"(\"startDate\",\"endDate\",\"idProgram\",\"idChannel\") VALUES('" + schedule.StartDate + "','" + schedule.EndDate + "'," + schedule.IdProgram + "," + schedule.IdChannel + ")";

                NpgsqlDataAdapter da;
                DataSet dt = new DataSet();

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

                }
            }
            else if (exist)
            {
                sSel = "UPDATE \"tbl_Schedule\" SET \"idProgram\" = " + schedule.IdProgram + " WHERE \"startDate\"='"+ schedule.StartDate +"' AND \"endDate\"='"+ schedule.EndDate +"' AND \"idChannel\"=" + schedule.IdChannel;

                NpgsqlDataAdapter da;
                DataSet dt = new DataSet();

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

                }
            }
        }
예제 #2
0
        static void InsertSchedule(XmlDocument doc)
        {
            try
            {
                Console.WriteLine("Limpiando Horario");
                //conexion.LimpiarHorario();
                Console.WriteLine("Horario");
                DTOSchedule schedule = new DTOSchedule();
                XmlNodeList schedules = doc.GetElementsByTagName("glf")[0].ChildNodes[0].ChildNodes[0].ChildNodes;

                foreach (XmlNode s in schedules)
                {
                    schedule.StartDate = DateTime.Parse(s.Attributes["s"].Value).ToLocalTime();
                    schedule.EndDate = endDateString(schedule.StartDate, Int32.Parse(s.Attributes["d"].Value));
                    schedule.IdProgram = Int64.Parse(s.Attributes["p"].Value);
                    schedule.IdChannel = Int64.Parse(s.Attributes["c"].Value);
                    conexion.AgregarHorario(schedule);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }