public static List <ReservationObj> getBySQL(String sql)
        {
            List <ReservationObj> list = new List <ReservationObj>();
            Connection            c    = new Connection();
            MySqlCommand          cmd  = c.con.CreateCommand();

            cmd.CommandText = sql;
            c.con.Open();
            MySqlDataReader r = cmd.ExecuteReader();

            while (r.Read())
            {
                ReservationObj product = new ReservationObj();
                product.id         = r.GetInt32("id");
                product.date_at    = r.GetString("date_at");
                product.time_at    = r.GetString("time_at");
                product.note       = r.GetString("note");
                product.title      = r.GetString("title");
                product.pacient_id = r.GetInt32("pacient_id");
                product.medic_id   = r.GetInt32("medic_id");

                list.Add(product);
            }
            return(list);
        }
        public ReservationForm()
        {
            InitializeComponent();
            pas = PacientObj.getAll();
            mes = MedicObj.getAll();
            foreach (MedicObj m in mes)
            {
                medic.Items.Add(m.name + " " + m.lastname);
            }
            foreach (PacientObj p in pas)
            {
                pacient.Items.Add(p.name + " " + p.lastname);
            }

            if (action == 1)
            {
                btn_del.Enabled = false;
            }
            else if (action == 2)
            {
                label_title.Text = "Editar Cita";
                Text             = "Editar Cita";
                btn_del.Enabled  = true;
                ReservationObj p = ReservationObj.getById(id);
                if (p.id > 0)
                {
                    title.Text   = p.title;
                    note.Text    = p.note;
                    date_at.Text = p.date_at;
                    time_at.Text = p.time_at;
                    int n = 0;
                    foreach (MedicObj m in mes)
                    {
                        if (m.id == p.medic_id)
                        {
                            medic.SelectedIndex = n; break;
                        }
                        n++;
                    }
                    n = 0;
                    foreach (PacientObj m in pas)
                    {
                        if (m.id == p.pacient_id)
                        {
                            pacient.SelectedIndex = n; break;
                        }
                        n++;
                    }
                }
                else
                {
                    MessageBox.Show("No se encontro el paciente.");
                }
            }
        }
        private void button1_Click(object sender, EventArgs e)
        {
            String sql = " select * from reservation ";

            if (q.Text != "")
            {
                sql += "where title like '%" + q.Text + "%' ";
            }
            if (pacient.SelectedIndex != -1)
            {
                if (q.Text == "")
                {
                    sql += " where ";
                }
                else
                {
                    sql += " and ";
                }
                sql += " pacient_id = " + pas[pacient.SelectedIndex].id;
            }
            if (medic.SelectedIndex != -1)
            {
                if (q.Text == "" && pacient.SelectedIndex == -1)
                {
                    sql += " where ";
                }
                else
                {
                    sql += " and ";
                }
                sql += " medic_id = " + mes[medic.SelectedIndex].id;
            }
            if (q.Text == "" && pacient.SelectedIndex == -1 && medic.SelectedIndex == -1)
            {
                sql += " where ";
            }
            else
            {
                sql += " and ";
            }
            sql += " date_at=\"" + date_at.Value.ToString("yyyy-MM-dd") + "\"";

            fill(ReservationObj.getBySQL(sql));
        }
        public static ReservationObj getById(int product_id)
        {
            Connection c = new Connection();
            MySqlCommand cmd = c.con.CreateCommand();
            cmd.CommandText = "select * from reservation where id=" + product_id;
            c.con.Open();
            MySqlDataReader r = cmd.ExecuteReader();
            ReservationObj product = new ReservationObj();
            while (r.Read())
            {

                product.id = r.GetInt32("id");
                product.date_at = r.GetString("date_at");
                product.time_at = r.GetString("time_at");
                product.note = r.GetString("note");
                product.title = r.GetString("title");
                product.pacient_id = r.GetInt32("pacient_id");
                product.medic_id = r.GetInt32("medic_id");
                break;
            }
            return product;
        }
        public static List<ReservationObj> getBySQL(String sql)
        {
            List<ReservationObj> list = new List<ReservationObj>();
            Connection c = new Connection();
            MySqlCommand cmd = c.con.CreateCommand();
            cmd.CommandText = sql;
            c.con.Open();
            MySqlDataReader r = cmd.ExecuteReader();
            while (r.Read())
            {
                ReservationObj product = new ReservationObj();
                product.id = r.GetInt32("id");
                product.date_at = r.GetString("date_at");
                product.time_at = r.GetString("time_at");
                product.note = r.GetString("note");
                product.title = r.GetString("title");
                product.pacient_id = r.GetInt32("pacient_id");
                product.medic_id = r.GetInt32("medic_id");

                list.Add(product);
            }
            return list;
        }
        public static ReservationObj getById(int product_id)
        {
            Connection   c   = new Connection();
            MySqlCommand cmd = c.con.CreateCommand();

            cmd.CommandText = "select * from reservation where id=" + product_id;
            c.con.Open();
            MySqlDataReader r       = cmd.ExecuteReader();
            ReservationObj  product = new ReservationObj();

            while (r.Read())
            {
                product.id         = r.GetInt32("id");
                product.date_at    = r.GetString("date_at");
                product.time_at    = r.GetString("time_at");
                product.note       = r.GetString("note");
                product.title      = r.GetString("title");
                product.pacient_id = r.GetInt32("pacient_id");
                product.medic_id   = r.GetInt32("medic_id");
                break;
            }
            return(product);
        }