Пример #1
0
        public List <city> Get_All()
        {
            List <city> cities_list = new List <city>();

            try
            {
                string query = "SELECT id_city, capital ,date, mayor, hospital_quantity, population FROM cities_by_id;";
                conect();
                var    data = _session.Execute(query);
                int    id;
                string capital;
                foreach (var row in data)
                {
                    city tempCity = new city();
                    tempCity.id                 = row.GetValue <int>("id_city");
                    tempCity.capital            = row.GetValue <string>("capital");
                    tempCity.mayor              = row.GetValue <string>("mayor");
                    tempCity.hostpital_quantity = row.GetValue <int>("hospital_quantity");
                    tempCity.population         = row.GetValue <int>("population");
                    tempCity.dateTime           = row.GetValue <DateTime>("date");
                    cities_list.Add(tempCity);
                }
                disconect();
                return(cities_list);
            }
            catch (Exception e)
            {
                throw e;
            }
            finally
            {
                disconect();
            }
        }
Пример #2
0
        public void Edit_characteristics(city data)
        {
            try
            {
                conect();
                string query           = "UPDATE cities_by_id SET characteristics = ";
                string characteristics = "['";
                int    i = 0;
                while ((data.characteritics.Count - 1) > i)
                {
                    characteristics += data.characteritics[i] + "','";
                    i++;
                }

                characteristics += data.characteritics[i] + "'] + characteristics  ";
                query           += characteristics + "WHERE id_city = ";
                query           += data.id.ToString() + " AND capital = '";
                query           += data.capital + "';";
                _session.Execute(query);
                disconect();
            }
            catch (Exception e)
            {
                throw e;
            }
            finally
            {
                disconect();
            }
        }
Пример #3
0
        public void insertData(city data)
        {
            try
            {
                conect();

                string characteristics;

                int index = 0;

                if (data.characteritics.Count > 0 && data.capital != "")
                {
                    characteristics = "[";
                    while ((data.characteritics.Count - 1) > index)
                    {
                        characteristics += "'" + data.characteritics[index] + "',";
                        index++;
                    }
                    characteristics += "'" + data.characteritics[index] + "']";
                }
                else
                {
                    characteristics = "['NO-DATA']";
                }



                string query = "INSERT INTO cities_by_id (" +
                               "id_city," +
                               "capital," +
                               "characteristics," +
                               "date," +
                               "hospital_quantity," +
                               "mayor," +
                               "population) VALUES(";

                query += data.id.ToString() + ",'";
                query += data.capital + "',";
                query += characteristics + ",";
                query += "toTimeStamp(toDate(now())),";
                query += data.hostpital_quantity.ToString() + ",'";
                query += data.mayor + "',";
                query += data.population.ToString() + ");";

                _session.Execute(query);
                MessageBox.Show("Informacion agregada");
                return;
            }
            catch (Exception e)
            {
                throw e;
            }
            finally
            {
                disconect();
            }
        }
Пример #4
0
        public void delte_row(city row)
        {
            conect();
            string query = "DELETE FROM cities_by_id WHERE id_city =";

            query += row.id.ToString() + ";";
            _session.Execute(query);
            disconect();
        }
Пример #5
0
        private void agregar_registro_Click(object sender, EventArgs e)
        {
            city data = new city();

            if (ciudad.Text == "" && data.capital == null)
            {
                MessageBox.Show("FALTA No.Ciudad o Centro", "INCORRECTO");
                return;
            }

            data.id      = Int32.Parse(ciudad.Text);
            data.capital = capital.Text.ToString();
            if (textBox2.Text != "")
            {
                data.hostpital_quantity = Int32.Parse(textBox2.Text);
            }
            data.mayor = alcalde.Text;
            if (textBox2.Text != "")
            {
                data.population = Int32.Parse(poblacion.Text);
            }

            int index = 0;

            data.characteritics = new List <string>();
            while (index < caracteristicas.Items.Count)
            {
                caracteristicas.SelectedItem = index;
                data.characteritics.Add(caracteristicas.Items[index].ToString());
                index++;
            }


            EnlaceCassandra node = new EnlaceCassandra();

            node.insertData(data);
            index = caracteristicas.Items.Count;
            while (index >= 0)
            {
                caracteristicas.Items.Remove(index);
                index--;
            }

            cities_list = node.Get_Cities_by_id();

            for (int i = 0; cities_list.Count > i; i++)
            {
                elegir_ciudad.Items.Add(cities_list[i].id.ToString());
            }

            ciudad.Text    = "";
            alcalde.Text   = "";
            capital.Text   = "";
            textBox2.Text  = "";
            poblacion.Text = "";
        }
Пример #6
0
        private void remplazar_Click(object sender, EventArgs e)
        {
            string id   = elegir_ciudad.Text;
            city   data = new city();

            if (ciudad.Text == "" && data.capital == null)
            {
                MessageBox.Show("FALTA No.Ciudad o Centro", "INCORRECTO");
                return;
            }

            data.id      = Int32.Parse(ciudad.Text);
            data.capital = capital.Text.ToString();
            if (textBox2.Text != "")
            {
                data.hostpital_quantity = Int32.Parse(textBox2.Text);
            }
            data.mayor = alcalde.Text;
            if (textBox2.Text != "")
            {
                data.population = Int32.Parse(poblacion.Text);
            }

            int index = 0;

            data.characteritics = new List <string>();
            while (index < caracteristicas.Items.Count)
            {
                caracteristicas.SelectedItem = index;
                data.characteritics.Add(caracteristicas.Items[index].ToString());
                index++;
            }

            EnlaceCassandra node = new EnlaceCassandra();

            node.replace(data, id);

            InitializeComponent();
            EnlaceCassandra addCities = new EnlaceCassandra();

            cities_list = addCities.Get_Cities_by_id();

            for (int i = 0; cities_list.Count > i; i++)
            {
                elegir_ciudad.Items.Add(cities_list[i].id.ToString());
            }

            dato_especifico.Items.Add("Alcalde");
            dato_especifico.Items.Add("Poblacion");
            dato_especifico.Items.Add("Numero Hospitales");

            MessageBox.Show("EL  BATCH SE APLICO, REINICIE LA APLICACION", "BATCH STATUS");
        }
Пример #7
0
        public void replace(city newData, string id)
        {
            conect();
            int    index = 0;
            string characteristics;

            if (newData.characteritics.Count > 0 && newData.capital != "")
            {
                characteristics = "[";
                while ((newData.characteritics.Count - 1) > index)
                {
                    characteristics += "'" + newData.characteritics[index] + "',";
                    index++;
                }
                characteristics += "'" + newData.characteritics[index] + "']";
            }
            else
            {
                characteristics = "['NO-DATA']";
            }

            string query = "BEGIN BATCH DELETE FROM cities_by_id WHERE id_city = ";

            query += id;
            query += " INSERT INTO cities_by_id (" +
                     "id_city," +
                     "capital," +
                     "characteristics," +
                     "date," +
                     "hospital_quantity," +
                     "mayor," +
                     "population) VALUES(";

            index = 0;

            query += newData.id.ToString() + ",'";
            query += newData.capital + "',";
            query += characteristics + ",";
            query += "toTimeStamp(toDate(now())),";
            query += newData.hostpital_quantity.ToString() + ",'";
            query += newData.mayor + "',";
            query += newData.population.ToString() + ") ";

            query += "APPLY BATCH;";

            _session.Execute(query);
            disconect();
        }
Пример #8
0
        private void Eliminar_renglon_Click(object sender, EventArgs e)
        {
            city delete = new city();

            delete.id      = Int32.Parse(ciudad.Text.ToString());
            delete.capital = capital.Text;

            EnlaceCassandra row = new EnlaceCassandra();

            row.delte_row(delete);

            cities_list = row.Get_Cities_by_id();

            for (int i = 0; cities_list.Count > i; i++)
            {
                elegir_ciudad.Items.Add(cities_list[i].id.ToString());
            }

            MessageBox.Show("Renglon eliminado\nPuede dar en mostrar informacion", "actualizacion");
        }
Пример #9
0
        private void modificar_caracteristicas_Click(object sender, EventArgs e)
        {
            city modCaracteristcas = new city();
            int  index             = 0;

            modCaracteristcas.characteritics = new List <string>();
            while (index < caracteristicas.Items.Count)
            {
                caracteristicas.SelectedItem = index;
                modCaracteristcas.characteritics.Add(caracteristicas.Items[index].ToString());
                index++;
            }

            modCaracteristcas.id      = Int32.Parse(ciudad.Text.ToString());
            modCaracteristcas.capital = capital.Text;

            EnlaceCassandra characteristics = new EnlaceCassandra();

            characteristics.Edit_characteristics(modCaracteristcas);
        }