private void btnGuardar_Click(object sender, EventArgs e)
        {
            try
            {
                if (lblId.Text != "")
                {
                    Profesionales prof = new Profesionales(Convert.ToInt32(lblId.Text), "", "", null, "", "", "", 0,0,0);
                    string ingreso = txtIng.Text;
                    string egreso = txtEgr.Text;
                    DateTime t;
                    DateTime t1;
                    txtDesde.ValidatingType = typeof(System.DateTime);
                    txtDesde.TypeValidationCompleted += new TypeValidationEventHandler(txtDesde_TypeValidationCompleted);
                    txtHasta.ValidatingType = typeof(System.DateTime);
                    txtHasta.TypeValidationCompleted += new TypeValidationEventHandler(txtHasta_TypeValidationCompleted);
                    string lunes = "0";
                    string martes = "0";
                    string miercoles = "0";
                    string jueves = "0";
                    string viernes = "0";
                    string sabado = "0";
                    string domingo = "0";
                    int i;
                    for (i = 0; i <= (checkedListBox1.Items.Count - 1); i++)
                    {
                        if (checkedListBox1.GetItemChecked(i))
                        {
                            if (checkedListBox1.Items[i].ToString() == "Lunes")
                            {
                                lunes = "1";
                            }
                            else if (checkedListBox1.Items[i].ToString() == "Martes")
                            {
                                martes = "1";
                            }
                            else if (checkedListBox1.Items[i].ToString() == "Miercoles")
                            {
                                miercoles = "1";
                            }
                            else if (checkedListBox1.Items[i].ToString() == "Jueves")
                            {
                                jueves = "1";
                            }
                            else if (checkedListBox1.Items[i].ToString() == "Viernes")
                            {
                                viernes = "1";
                            }
                            else if (checkedListBox1.Items[i].ToString() == "Sabado")
                            {
                                sabado = "1";
                            }
                            else if (checkedListBox1.Items[i].ToString() == "Domingo")
                            {
                                domingo = "1";
                            }
                        }
                    }

                    if (DateTime.TryParse(ingreso, out t) && DateTime.TryParse(egreso, out t1) && txtHasta.Text == "  /  /")
                    {
                        ingreso = t.ToString("HH:mm");
                        egreso = t1.ToString("HH:mm");
                        string semana = "0";
                        if (!chkSemana.Checked)
                        {
                            semana = TSemana.Text;
                        }
                        HorariosProfesionales h = new HorariosProfesionales(0, prof, ingreso, egreso, Convert.ToDateTime(txtDesde.Text), lunes, martes, miercoles, jueves, viernes, sabado, domingo, semana);
                        if (idhorario == 0)
                        {
                            controlh.Agregar(h);
                        }
                        else
                        {
                            h.IdhorariosProfesionales = idhorario;
                            controlh.Modificar(h);
                            idhorario = 0;
                        }
                        frmHorariosProfesionales_Load(sender, e);
                    }
                    else if (DateTime.TryParse(ingreso, out t) && DateTime.TryParse(egreso, out t1) && txtHasta.Text != "  /  /")
                    {
                        ingreso = t.ToString("HH:mm");
                        egreso = t1.ToString("HH:mm");
                        string semana = "0";
                        if (!chkSemana.Checked)
                        {
                            semana = TSemana.Text;
                        }
                        HorariosProfesionales h = new HorariosProfesionales(0, prof, ingreso, egreso, Convert.ToDateTime(txtDesde.Text), Convert.ToDateTime(txtHasta.Text), lunes, martes, miercoles, jueves, viernes, sabado, domingo, semana);
                        if (idhorario == 0)
                        {
                            controlh.Agregar(h);
                        }
                        else
                        {
                            h.IdhorariosProfesionales = idhorario;
                            controlh.Modificar(h);
                            idhorario = 0;
                        }
                        frmHorariosProfesionales_Load(sender, e);
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                txtDesde.Text = "";
                txtHasta.Text = "";
                txtIng.Text = "";
                txtEgr.Text = "";
                TSemana.Text = "";
            }
        }
Beispiel #2
0
        public void cargagrilla()
        {
            try
            {
                laux = new List<grilla>();
                dataGridView1.ColumnHeadersVisible = true;
                DataGridViewCellStyle columnHeaderStyle = new DataGridViewCellStyle();
                columnHeaderStyle.BackColor = Color.Beige;
                columnHeaderStyle.Font = new Font("Verdana", 10, FontStyle.Bold);
                dataGridView1.GridColor = Color.Black;
                dataGridView1.ColumnHeadersDefaultCellStyle = columnHeaderStyle;
                dataGridView1.DefaultCellStyle.BackColor = Color.Gray;
                DataTable dt = oacceso.leerDatos("call sp_protrabaja('" + monthCalendar1.SelectionRange.Start.ToString("yyyy-MM-dd") + "')");
                dataGridView1.ColumnCount = dt.Rows.Count + 1;
                dataGridView1.Columns[0].Name = "Horario";
                dataGridView1.Columns[0].Frozen = true;
                DateTime start = DateTime.Parse("08:00");
                DateTime start1 = DateTime.Parse("08:00");
                DateTime end = DateTime.Parse("22:00");
                int row = 0;
                while (start <= end)
                {
                    dataGridView1.Rows.Add(start.TimeOfDay.ToString());
                    dataGridView1.Rows[row].Cells[0].Style.ForeColor = Color.White;
                    start1 = start.AddMinutes(60);
                    start = start1;
                    row++;
                }
                HorariosProfesionales h = null;
                int x = 1;
                foreach (DataRow dr in dt.Rows)
                {
                    Profesionales p = new Profesionales(Convert.ToInt32(dr["idprofesionales"]), Convert.ToString(dr["profesional"]), "", null, "", "", "", 1,0,0);
                    int cantidad = Convert.ToInt32(Convert.ToString(dr["horario"]).Substring(Convert.ToString(dr["horario"]).Length - 1, 1));
                    string query = Convert.ToString(dr["horario"]);
                    if (Convert.ToString(dr["horasmanuales"]) != "")
                    {
                        int canthorasmanuales = 0;
                        canthorasmanuales = Convert.ToInt32(Convert.ToString(dr["horasmanuales"]).Substring(Convert.ToString(dr["horasmanuales"]).LastIndexOf(';') + 1, Convert.ToString(dr["horasmanuales"]).Length - (Convert.ToString(dr["horasmanuales"]).LastIndexOf(';') + 1)));
                        cantidad = cantidad + canthorasmanuales;
                        query = query.Substring(0,query.Length - 1);
                        query = query + Convert.ToString(dr["horasmanuales"]);
                    }
                    int desde = 0;
                    int hasta = 5;
                    for (int z = 1; z <= cantidad; z++)
                    {
                        string ingreso = query.Substring(desde, 5);
                        string egreso = query.Substring(hasta, 5);
                        query = query.Substring(11, query.Length - 11);
                        h = new HorariosProfesionales(0, p, ingreso, egreso, DateTime.Now, "", "", "", "", "", "", "", "");
                        dataGridView1.Columns[x].Name = p.Profesional;
                        gri = new grilla(x, -1, p.Idprofesionales.ToString());
                        laux.Add(gri);
                        foreach (DataGridViewRow dg in dataGridView1.Rows)
                        {
                            if (h.Egreso != "10000" && h.Egreso != "00000")
                            {
                                if (Convert.ToDateTime(dg.Cells[0].Value) >= Convert.ToDateTime(h.Ingreso) && Convert.ToDateTime(dg.Cells[0].Value) <= Convert.ToDateTime(h.Egreso))
                                {
                                    int i = dataGridView1.Rows.IndexOf(dg);
                                    this.dataGridView1.Rows[i].Cells[x].Style.BackColor = Color.White;
                                }
                                else
                                {
                                    int i = dataGridView1.Rows.IndexOf(dg);
                                    if (this.dataGridView1.Rows[i].Cells[x].Style.BackColor != Color.White)
                                    {
                                        this.dataGridView1.Rows[i].Cells[x].Style.BackColor = Color.Gray;
                                    }
                                }
                            }
                            else
                            {
                                if (Convert.ToDateTime(dg.Cells[0].Value) == Convert.ToDateTime(h.Ingreso))
                                {

                                    int i = dataGridView1.Rows.IndexOf(dg);
                                    if (h.Egreso == "10000")
                                    {
                                        this.dataGridView1.Rows[i].Cells[x].Style.BackColor = Color.White;
                                    }
                                    else
                                    {
                                        this.dataGridView1.Rows[i].Cells[x].Style.BackColor = Color.Gray;
                                    }
                                }
                            }
                        }
                    }
                    x++;
                }

                int semana = 0;
                DateTime a = monthCalendar1.SelectionRange.Start;
                CultureInfo myCI = new CultureInfo("en-US");
                CalendarWeekRule myCWR = myCI.DateTimeFormat.CalendarWeekRule;
                DayOfWeek myFirstDOW = myCI.DateTimeFormat.FirstDayOfWeek;
                Calendar myCal = myCI.Calendar;
                if (myCal.GetWeekOfYear(a, myCWR, myFirstDOW) % 2 == 0)
                {
                    semana = 2;
                }
                else
                {
                    semana = 1;
                }
                dt = oacceso.leerDatos("call sp_turnos('" + monthCalendar1.SelectionRange.Start.ToString("yyyy-MM-dd") + "','" + Convert.ToInt32(monthCalendar1.SelectionRange.Start.DayOfWeek) + "','" + semana + "')");
                int col = 0;
                int idp = 0;
                foreach (DataRow dr in dt.Rows)
                {
                    Profesionales p = new Profesionales(Convert.ToInt32(dr["idprofesionales"]),"","",null,"","","",0,0,0);
                    if (idp != p.Idprofesionales)
                    {
                        foreach (grilla aux in laux)
                        {
                            if (-1 == aux.Fila && aux.Id == p.Idprofesionales.ToString())
                            {
                                col = aux.Columna;
                                idp = p.Idprofesionales;
                                break;
                            }
                        }
                    }
                    int fila = Convert.ToInt32(Convert.ToString(dr["hora"]).Substring(0, 2))-8;
                    string fijo = Convert.ToString(dr["fijo"]);
                    int asistencia = Convert.ToInt32(Convert.ToString(dr["asistencia"]));

                    if (col != 0)
                    {
                        if (asistencia == 1)
                        {
                            grilla gri = new grilla(col, fila, Convert.ToString(dr["idturnos"]));
                            laux.Add(gri);
                            this.dataGridView1.Rows[fila].Cells[col].Style.BackColor = Color.Orange;
                            this.dataGridView1.Rows[fila].Cells[col].Value = Convert.ToString(dr["detalle"]) + " " + Convert.ToString(dr["sesion"]);
                        }
                        else
                        {
                            if (fijo == "s")
                            {
                                if (Convert.ToDateTime(dr["fecha"]) == monthCalendar1.SelectionRange.Start)
                                {
                                    grilla gri = new grilla(col, fila, Convert.ToString(dr["idturnos"]));
                                    laux.Add(gri);
                                }
                                else
                                {
                                    grilla gri = new grilla(col, fila, Convert.ToString(dr["idturnos"]));
                                    laux.Add(gri);
                                }
                                if (Convert.ToString(dr["suspendido"]) == "0")
                                {
                                    this.dataGridView1.Rows[fila].Cells[col].Style.BackColor = Color.IndianRed;
                                    this.dataGridView1.Rows[fila].Cells[col].Value = Convert.ToString(dr["detalle"]) + " " + Convert.ToString(dr["sesion"]);
                                }
                                else if (this.dataGridView1.Rows[fila].Cells[col].Style.BackColor != Color.Gray)
                                {
                                    this.dataGridView1.Rows[fila].Cells[col].Style.BackColor = Color.LightBlue;
                                }
                            }
                            else if (fijo == "q")
                            {
                                if (Convert.ToDateTime(dr["fecha"]) == monthCalendar1.SelectionRange.Start)
                                {
                                    grilla gri = new grilla(col, fila, Convert.ToString(dr["idturnos"]));
                                    laux.Add(gri);
                                }
                                else
                                {
                                    grilla gri = new grilla(col, fila, Convert.ToString(dr["idturnos"]));
                                    laux.Add(gri);
                                }
                                if (Convert.ToString(dr["suspendido"]) == "0")
                                {
                                    this.dataGridView1.Rows[fila].Cells[col].Style.BackColor = Color.CornflowerBlue;
                                    this.dataGridView1.Rows[fila].Cells[col].Value = Convert.ToString(dr["detalle"]) + " " + Convert.ToString(dr["sesion"]);
                                }
                                else if (this.dataGridView1.Rows[fila].Cells[col].Style.BackColor != Color.Gray)
                                {
                                    this.dataGridView1.Rows[fila].Cells[col].Style.BackColor = Color.LightBlue;
                                }
                            }
                            else
                            {
                                grilla gri = new grilla(col, fila, Convert.ToString(dr["idturnos"]));
                                laux.Add(gri);
                                this.dataGridView1.Rows[fila].Cells[col].Style.BackColor = Color.Green;
                                this.dataGridView1.Rows[fila].Cells[col].Value = Convert.ToString(dr["detalle"]) + " " + Convert.ToString(dr["sesion"]);
                            }
                        }
                    }
                    else
                    {
                        MessageBox.Show("ERROR: existen turnos para profesionales sin grilla horaria");
                    }
                }

            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
 private void dataGridView1_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
 {
     try
     {
         int filaseleccionada = Convert.ToInt32(this.dataGridView1.CurrentRow.Index);
         int idhorarioprof = Convert.ToInt32(dataGridView1[0, filaseleccionada].Value);
         HorariosProfesionales h = new HorariosProfesionales(idhorarioprof, null, "", "", DateTime.Now, "", "", "", "", "", "", "","");
         DialogResult dialogResult = MessageBox.Show("Esta seguro de eliminar el Horario seleccionado ?", "Eliminar Configuracion Horarios", MessageBoxButtons.YesNo);
         if (dialogResult == DialogResult.Yes)
         {
             controlh.Borrar(h);
         }
         frmHorariosProfesionales_Load(sender, e);
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }