Example #1
0
        private void cargarHorarios()
        {
            flowLayoutPanel1.Controls.Clear();
            string         connectionString = "Server=DESKTOP-MU4EH1E;Database=FicharApp;User Id=admin;Password=123;";
            string         sql         = "SELECT * FROM Horario, Tramos_Horarios WHERE Tramos_Horarios.ID = Horario.ID Order BY Tramos_Horarios.IDTramo";
            SqlConnection  connection  = new SqlConnection(connectionString);
            SqlDataAdapter dataadapter = new SqlDataAdapter(sql, connection);
            DataSet        ds          = new DataSet();

            connection.Open();
            dataadapter.Fill(ds, "Authors_table");
            connection.Close();
            string IDActual = "";

            controlHorario ch = new controlHorario();

            foreach (DataRow dr in ds.Tables[0].Rows)
            {
                if (IDActual == "")
                {
                    ch.label1.Text = dr.ItemArray[1].ToString();
                }
                else if (IDActual != dr.ItemArray[0].ToString())
                {
                    flowLayoutPanel1.Controls.Add(ch);
                    ch             = new controlHorario();
                    ch.label1.Text = dr.ItemArray[1].ToString();
                }

                Label l = new Label();
                l.Text = dr.ItemArray[3].ToString() + " - " + dr.ItemArray[4].ToString();
                ch.flowLayoutPanel1.Controls.Add(l);

                IDActual = dr.ItemArray[0].ToString();
            }

            if (ds.Tables[0].Rows.Count > 0)
            {
                flowLayoutPanel1.Controls.Add(ch);
            }
        }
Example #2
0
        private void lbHorarios_SelectedIndexChanged(object sender, EventArgs e)
        {
            lbTramos.Items.Clear();
            //Nos conectamos a bdd
            string         connectionString = "Server=DESKTOP-MU4EH1E;Database=FicharApp;User Id=admin;Password=123;";
            string         sql         = "select * from Tramos_Horarios where id=" + ((sender as ListBox).SelectedItem as Horario).id;
            SqlConnection  connection  = new SqlConnection(connectionString);
            SqlDataAdapter dataadapter = new SqlDataAdapter(sql, connection);
            DataSet        ds          = new DataSet();

            connection.Open();
            dataadapter.Fill(ds, "Authors_table");
            connection.Close();

            controlHorario ch = new controlHorario();

            foreach (DataRow dr in ds.Tables[0].Rows)
            {
                lbTramos.Items.Add(new Tramos(dr.ItemArray[0].ToString(), dr.ItemArray[1].ToString(), dr.ItemArray[2].ToString(), dr.ItemArray[3].ToString()));
            }
        }
Example #3
0
        private void cargarHorarios()
        {
            lbHorarios.Items.Clear();
            string         connectionString = "Server=DESKTOP-MU4EH1E;Database=FicharApp;User Id=admin;Password=123;";
            string         sql         = "select * from horario";
            SqlConnection  connection  = new SqlConnection(connectionString);
            SqlDataAdapter dataadapter = new SqlDataAdapter(sql, connection);
            DataSet        ds          = new DataSet();

            connection.Open();
            dataadapter.Fill(ds, "Authors_table");
            connection.Close();

            controlHorario ch = new controlHorario();

            foreach (DataRow dr in ds.Tables[0].Rows)
            {
                lbHorarios.Items.Add(new Horario(dr.ItemArray[0].ToString(), dr.ItemArray[1].ToString()));
            }

            lbHorarios.SelectedIndex = 0;
        }
        private void CambiarHorarioACalendario_Load(object sender, EventArgs e)
        {
            string         connectionString = "Server=DESKTOP-MU4EH1E;Database=FicharApp;User Id=admin;Password=123;";
            string         sql         = "select * from horario";
            SqlConnection  connection  = new SqlConnection(connectionString);
            SqlDataAdapter dataadapter = new SqlDataAdapter(sql, connection);
            DataSet        ds          = new DataSet();

            connection.Open();
            dataadapter.Fill(ds, "Authors_table");
            connection.Close();

            controlHorario ch = new controlHorario();

            //Añadir Horario Vacío (Festivo)
            cbLunes.Items.Add(new Horario("-1", ""));
            cbMartes.Items.Add(new Horario("-1", ""));
            cbMiercoles.Items.Add(new Horario("-1", ""));
            cbJueves.Items.Add(new Horario("-1", ""));
            cbViernes.Items.Add(new Horario("-1", ""));
            cbSabado.Items.Add(new Horario("-1", ""));
            cbDomingo.Items.Add(new Horario("-1", ""));

            foreach (DataRow dr in ds.Tables[0].Rows)
            {
                //Añadir Horarios de DB
                cbLunes.Items.Add(new Horario(dr.ItemArray[0].ToString(), dr.ItemArray[1].ToString()));
                cbMartes.Items.Add(new Horario(dr.ItemArray[0].ToString(), dr.ItemArray[1].ToString()));
                cbMiercoles.Items.Add(new Horario(dr.ItemArray[0].ToString(), dr.ItemArray[1].ToString()));
                cbJueves.Items.Add(new Horario(dr.ItemArray[0].ToString(), dr.ItemArray[1].ToString()));
                cbViernes.Items.Add(new Horario(dr.ItemArray[0].ToString(), dr.ItemArray[1].ToString()));
                cbSabado.Items.Add(new Horario(dr.ItemArray[0].ToString(), dr.ItemArray[1].ToString()));
                cbDomingo.Items.Add(new Horario(dr.ItemArray[0].ToString(), dr.ItemArray[1].ToString()));
            }

            //Buscamos el horario de cada día y si no tiene, seleccionamos el 0 por defecto.
            int cuentaLunes = 0;

            cbLunes.SelectedIndex = 0;
            foreach (Horario item in cbLunes.Items)
            {
                if (item.id == Calendar.lun)
                {
                    cbLunes.SelectedIndex = cuentaLunes;
                }
                cuentaLunes++;
            }

            int cuentaMartes = 0;

            cbMartes.SelectedIndex = 0;
            foreach (Horario item in cbMartes.Items)
            {
                if (item.id == Calendar.mar)
                {
                    cbMartes.SelectedIndex = cuentaMartes;
                }
                cuentaMartes++;
            }

            int cuentaMiercoles = 0;

            cbMiercoles.SelectedIndex = 0;
            foreach (Horario item in cbMiercoles.Items)
            {
                if (item.id == Calendar.mie)
                {
                    cbMiercoles.SelectedIndex = cuentaMiercoles;
                }
                cuentaMiercoles++;
            }

            int cuentaJueves = 0;

            cbJueves.SelectedIndex = 0;
            foreach (Horario item in cbJueves.Items)
            {
                if (item.id == Calendar.jue)
                {
                    cbJueves.SelectedIndex = cuentaJueves;
                }
                cuentaJueves++;
            }

            int cuentaViernes = 0;

            cbViernes.SelectedIndex = 0;
            foreach (Horario item in cbViernes.Items)
            {
                if (item.id == Calendar.vie)
                {
                    cbViernes.SelectedIndex = cuentaViernes;
                }
                cuentaViernes++;
            }

            int cuentaSabado = 0;

            cbSabado.SelectedIndex = 0;
            foreach (Horario item in cbSabado.Items)
            {
                if (item.id == Calendar.sab)
                {
                    cbSabado.SelectedIndex = cuentaSabado;
                }
                cuentaSabado++;
            }

            int cuentaDomingo = 0;

            cbDomingo.SelectedIndex = 0;
            foreach (Horario item in cbDomingo.Items)
            {
                if (item.id == Calendar.dom)
                {
                    cbDomingo.SelectedIndex = cuentaDomingo;
                }
                cuentaDomingo++;
            }
        }
        private void cargarHorario()
        {
            if (trabajador.isAdmin)
            {
                horaEntrada.Text = "00:00";
                horaSalida.Text  = "00:00";
            }

            else
            {
                string connectionString = "Server=DESKTOP-MU4EH1E;Database=FicharApp;User Id=admin;Password=123;";
                switch (DateTime.Now.DayOfWeek)
                {
                case DayOfWeek.Monday:
                    string sql = "SELECT * FROM Horario, Tramos_Horarios, Calendario WHERE Tramos_Horarios.ID = Horario.ID AND " + trabajador.calendario +
                                 " = Calendario.id AND Calendario.Lunes = Horario.ID Order BY Tramos_Horarios.IDTramo";
                    SqlConnection  connection  = new SqlConnection(connectionString);
                    SqlDataAdapter dataadapter = new SqlDataAdapter(sql, connection);
                    DataSet        ds          = new DataSet();
                    connection.Open();
                    dataadapter.Fill(ds, "Authors_table");
                    connection.Close();
                    string IDActual = "";


                    foreach (DataRow dr in ds.Tables[0].Rows)
                    {
                        if (horario == 0)
                        {
                            horaEntrada.Text = dr.ItemArray[3].ToString();
                            horario++;
                        }
                        else
                        {
                            horaSalida.Text = dr.ItemArray[4].ToString();
                        }
                    }
                    break;

                case DayOfWeek.Tuesday:
                    string sqlMar = "SELECT * FROM Horario, Tramos_Horarios, Calendario WHERE Tramos_Horarios.ID = Horario.ID AND " + trabajador.calendario +
                                    " = Calendario.id AND Calendario.Martes = Horario.ID Order BY Tramos_Horarios.IDTramo";
                    SqlConnection  connectionMar  = new SqlConnection(connectionString);
                    SqlDataAdapter dataadapterMar = new SqlDataAdapter(sqlMar, connectionMar);
                    DataSet        dsMar          = new DataSet();
                    connectionMar.Open();
                    dataadapterMar.Fill(dsMar, "Authors_table");
                    connectionMar.Close();
                    string IDActualMar = "";

                    controlHorario chMar = new controlHorario();
                    foreach (DataRow dr in dsMar.Tables[0].Rows)
                    {
                        if (horario == 0)
                        {
                            horaEntrada.Text = dr.ItemArray[3].ToString();
                            horario++;
                        }
                        else
                        {
                            horaSalida.Text = dr.ItemArray[4].ToString();
                        }
                    }
                    break;

                case DayOfWeek.Wednesday:
                    string sqlMie = "SELECT * FROM Horario, Tramos_Horarios, Calendario WHERE Tramos_Horarios.ID = Horario.ID AND " + trabajador.calendario +
                                    " = Calendario.id AND Calendario.Miércoles = Horario.ID Order BY Tramos_Horarios.IDTramo";
                    SqlConnection  connectionMie  = new SqlConnection(connectionString);
                    SqlDataAdapter dataadapterMie = new SqlDataAdapter(sqlMie, connectionMie);
                    DataSet        dsMie          = new DataSet();
                    connectionMie.Open();
                    dataadapterMie.Fill(dsMie, "Authors_table");
                    connectionMie.Close();
                    string IDActualMie = "";

                    controlHorario chMie = new controlHorario();
                    foreach (DataRow dr in dsMie.Tables[0].Rows)
                    {
                        if (horario == 0)
                        {
                            horaEntrada.Text = dr.ItemArray[3].ToString();
                            horario++;
                        }
                        else
                        {
                            horaSalida.Text = dr.ItemArray[4].ToString();
                        }
                    }
                    break;

                case DayOfWeek.Thursday:
                    string sqlJue = "SELECT * FROM Horario, Tramos_Horarios, Calendario WHERE Tramos_Horarios.ID = Horario.ID AND " + trabajador.calendario +
                                    " = Calendario.id AND Calendario.Jueves = Horario.ID Order BY Tramos_Horarios.IDTramo";
                    SqlConnection  connectionJue  = new SqlConnection(connectionString);
                    SqlDataAdapter dataadapterJue = new SqlDataAdapter(sqlJue, connectionJue);
                    DataSet        dsJue          = new DataSet();
                    connectionJue.Open();
                    dataadapterJue.Fill(dsJue, "Authors_table");
                    connectionJue.Close();
                    string IDActualJue = "";

                    controlHorario chJue = new controlHorario();
                    foreach (DataRow dr in dsJue.Tables[0].Rows)
                    {
                        if (horario == 0)
                        {
                            horaEntrada.Text = dr.ItemArray[3].ToString();
                            horario++;
                        }
                        else
                        {
                            horaSalida.Text = dr.ItemArray[4].ToString();
                        }
                    }
                    break;


                case DayOfWeek.Friday:
                    string sqlVie = "SELECT * FROM Horario, Tramos_Horarios, Calendario WHERE Tramos_Horarios.ID = Horario.ID AND " + trabajador.calendario +
                                    " = Calendario.id AND Calendario.Viernes = Horario.ID Order BY Tramos_Horarios.IDTramo";
                    SqlConnection  connectionVie  = new SqlConnection(connectionString);
                    SqlDataAdapter dataadapterVie = new SqlDataAdapter(sqlVie, connectionVie);
                    DataSet        dsVie          = new DataSet();
                    connectionVie.Open();
                    dataadapterVie.Fill(dsVie, "Authors_table");
                    connectionVie.Close();
                    string IDActualVie = "";

                    controlHorario chVie = new controlHorario();
                    foreach (DataRow dr in dsVie.Tables[0].Rows)
                    {
                        if (horario == 0)
                        {
                            horaEntrada.Text = dr.ItemArray[3].ToString();
                            horario++;
                        }
                        else
                        {
                            horaSalida.Text = dr.ItemArray[4].ToString();
                        }
                    }
                    break;


                case DayOfWeek.Saturday:
                    string sqlSab = "SELECT * FROM Horario, Tramos_Horarios, Calendario WHERE Tramos_Horarios.ID = Horario.ID AND " + trabajador.calendario +
                                    " = Calendario.id AND Calendario.Sábado = Horario.ID Order BY Tramos_Horarios.IDTramo";
                    SqlConnection  connectionSab  = new SqlConnection(connectionString);
                    SqlDataAdapter dataadapterSab = new SqlDataAdapter(sqlSab, connectionSab);
                    DataSet        dsSab          = new DataSet();
                    connectionSab.Open();
                    dataadapterSab.Fill(dsSab, "Authors_table");
                    connectionSab.Close();
                    string IDActualSab = "";

                    controlHorario chSab = new controlHorario();
                    foreach (DataRow dr in dsSab.Tables[0].Rows)
                    {
                        if (horario == 0)
                        {
                            horaEntrada.Text = dr.ItemArray[3].ToString();
                            horario++;
                        }
                        else
                        {
                            horaSalida.Text = dr.ItemArray[4].ToString();
                        }
                    }
                    break;


                case DayOfWeek.Sunday:
                    string sqlDom = "SELECT * FROM Horario, Tramos_Horarios, Calendario WHERE Tramos_Horarios.ID = Horario.ID AND " + trabajador.calendario +
                                    " = Calendario.id AND Calendario.Domingo = Horario.ID Order BY Tramos_Horarios.IDTramo";
                    SqlConnection  connectionDom  = new SqlConnection(connectionString);
                    SqlDataAdapter dataadapterDom = new SqlDataAdapter(sqlDom, connectionDom);
                    DataSet        dsDom          = new DataSet();
                    connectionDom.Open();
                    dataadapterDom.Fill(dsDom, "Authors_table");
                    connectionDom.Close();
                    string IDActualDom = "";

                    controlHorario chDom = new controlHorario();
                    foreach (DataRow dr in dsDom.Tables[0].Rows)
                    {
                        if (horario == 0)
                        {
                            horaEntrada.Text = dr.ItemArray[3].ToString();
                            horario++;
                        }
                        else
                        {
                            horaSalida.Text = dr.ItemArray[4].ToString();
                        }
                    }
                    break;

                default:
                    Console.WriteLine("Default case");
                    break;
                }
            }
        }