private void btnSync_Click(object sender, EventArgs e)
        {
            db.insertPendingTeachers();
               String serieTemp="";
               int serieID=0;
               foreach(AsignacionClass a in asignaciones)
               {
               AsignacionClase asignacion = new AsignacionClase();
               Serie serie = new Serie();
               if (!serieTemp.Equals(a.Serie()))
               {
                   //insertar serie
                   serie.Descripcion = a.Serie();
                   db.insertSerie(ref serie);
                   serieID = Convert.ToInt32(db.LastUpdated);//obtener id serie insertada
                   serieTemp = a.Serie();
               }
               serie.ID = serieID;//asignar id seria al objeto serie
               asignacion.Serie = serie;//asignar objeto seria a la asignacion

               //Asignar id aula a la asignacion
               Aula au = new Aula();
               au.Id = a.AulaID;
               asignacion.Aula = au;

               //Asignar el codigo de grupo
               //buscar el id en la tabla grupo en base a la serie
               Grupo g = new Grupo();
               g.Id = db.getIdFromGrupo(a.Serie());
               asignacion.Grupo = g;
               //Asignar inicio y fin
               string hora24=DateTime.Parse(a.HoraInicio).ToString("HH:mm", CultureInfo.CurrentCulture);
               DateTime inicio = a.FechaInicio.Add(TimeSpan.Parse(hora24));

               switch (a.Dia)
               {
                   case "LUNES": inicio=inicio.AddDays(-(inicio.DayOfWeek - DayOfWeek.Monday)); break;
                    case "MARTES": inicio=inicio.AddDays(-(inicio.DayOfWeek - DayOfWeek.Tuesday)); break;
                    case "MIERCOLES": inicio=inicio.AddDays(-(inicio.DayOfWeek - DayOfWeek.Wednesday) ); break;
                    case "JUEVES": inicio=inicio.AddDays(-(inicio.DayOfWeek - DayOfWeek.Thursday)); break;
                    case "VIERNES": inicio=inicio.AddDays(-(inicio.DayOfWeek - DayOfWeek.Friday)); break;
                    case "SABADO": inicio=inicio.AddDays(-(inicio.DayOfWeek - DayOfWeek.Saturday)); break;
                    case "DOMINGO": inicio=inicio.AddDays(-(inicio.DayOfWeek - DayOfWeek.Sunday)); break;
               }
               asignacion.Inicio = inicio;
               string hora242 = DateTime.Parse(a.HoraFin).ToString("HH:mm", CultureInfo.CurrentCulture);
               asignacion.Fin = asignacion.Inicio.Add(-TimeSpan.Parse(hora24));
               asignacion.Fin = asignacion.Fin.Add(TimeSpan.Parse(hora242));

               //reprogramada
               asignacion.Reprogramada = false;
               Asignacion fin = asignacion;
               while (asignacion.Inicio <= a.FechaFin)
               {
                   db.insertAsignacion(ref fin);
                   asignacion.Inicio = asignacion.Inicio.AddDays(7);
                   asignacion.Fin = asignacion.Fin.AddDays(7);
               }

               }
        }
        private void btnAgregar_Click(object sender, EventArgs e)
        {
            try
            {
                Grupo grupo = new Grupo();
                Asignatura asignatura = new Asignatura();
                asignatura.Id = Convert.ToInt32(gruposForm.cbAsignatura.SelectedValue);
                grupo.Asignatura = asignatura;
                Docente docente = new Docente();
                docente.Id = Convert.ToInt32(gruposForm.cbDocente.SelectedValue);
                grupo.Docente = docente;
                if(gruposForm.txtInscritos.Text.Equals(""))
                {
                    grupo.CantidadEstudiantes=0;
                }
                else
                {
                    grupo.CantidadEstudiantes = Convert.ToInt32(gruposForm.txtInscritos.Text);
                }
                Periodo periodo = new Periodo();
                periodo.Id = Convert.ToInt32(gruposForm.cbPeriodo.SelectedValue);
                grupo.Periodo = periodo;
                db.insertGrupo(grupo);
                gruposForm.Hide();
                cargarDataGridGrupos();
            }
            catch (Exception ex)
            {

                MessageBox.Show(ex.Message);
            }
        }
示例#3
0
 public GruposForm(Grupo g)
 {
     InitializeComponent();
     grupo = g;
 }
示例#4
0
        public Boolean actualizarGrupo(Grupo Grupo)
        {
            this.connection.Open();
            this.command = this.connection.CreateCommand();
            this.transaction = this.connection.BeginTransaction();
            this.command.Connection = this.connection;
            this.command.Transaction = this.transaction;

            try
            {
                this.command.CommandText = "Update grupo set id_asignatura=@idAsignatura,id_docente=@idDocente,cant_estudiante=@inscritos,id_periodo=@idPeriodo where id_grupo=@id;";
                this.command.Parameters.Add(new SqlParameter("@idAsignatura", SqlDbType.Int));
                this.command.Parameters.Add(new SqlParameter("@idDocente", SqlDbType.Int));
                this.command.Parameters.Add(new SqlParameter("@inscritos", SqlDbType.Int));
                this.command.Parameters.Add(new SqlParameter("@idPeriodo", SqlDbType.Int));
                this.command.Parameters.Add(new SqlParameter("@id", SqlDbType.Int));
                this.command.Parameters["@idAsignatura"].Value = Grupo.Asignatura.Id;
                this.command.Parameters["@idDocente"].Value = Grupo.Docente.Id;
                this.command.Parameters["@inscritos"].Value = Grupo.CantidadEstudiantes;
                this.command.Parameters["@idPeriodo"].Value = Grupo.Periodo.Id;
                this.command.Parameters["@id"].Value = Grupo.Id;
                this.command.ExecuteNonQuery();
                this.transaction.Commit();
                return true;
            }
            catch (Exception e)
            {
                try
                {
                    this.transaction.Rollback();
                    throw new Exception("Error al Actualizar." + e.Message);
                    return false;
                }
                catch (Exception ex)
                {
                    throw new Exception("Error al rollback accion." + ex.Message);
                    return false;
                }
            }
            finally
            {
                this.connection.Close();
            }
        }
示例#5
0
        /*
        public int cantGrupos()
        {
            int cantidad;
            try
            {
                string query = "Select count(*) from Vista_Grupos";
                command = new SqlCommand(query, connection);
                command.Connection.Open();
                cantidad = (Int32)command.ExecuteScalar();
                return cantidad;
            }
            catch (Exception e)
            {
                throw new Exception("Error al obtener datos de Grupo. " + e.Message.ToString());
            }
            finally
            {
                command.Connection.Close();
            }
        }
        */
        public Boolean insertGrupo(Grupo Grupo)
        {
            this.connection.Open();
            this.command = this.connection.CreateCommand();
            this.transaction = this.connection.BeginTransaction();
            this.command.Connection = this.connection;
            this.command.Transaction = this.transaction;

            try
            {
                this.command.CommandText = "insert into Grupo(id_asignatura,id_docente,id_periodo,cant_estudiante) values(@idAsignatura,@idDocente,@idPeriodo,@cantInscritos);" + "SELECT CAST(scope_identity() AS int)";
                this.command.Parameters.Add(new SqlParameter("@idAsignatura", SqlDbType.Int));
                this.command.Parameters.Add(new SqlParameter("@idDocente", SqlDbType.Int));
                this.command.Parameters.Add(new SqlParameter("@idPeriodo",SqlDbType.Int));
                this.command.Parameters.Add(new SqlParameter("@cantInscritos", SqlDbType.Int));
                this.command.Parameters["@idAsignatura"].Value = Grupo.Asignatura.Id;
                this.command.Parameters["@idDocente"].Value = Grupo.Docente.Id;
                this.command.Parameters["@idPeriodo"].Value = Grupo.Periodo.Id;
                this.command.Parameters["@cantInscritos"].Value = Grupo.CantidadEstudiantes;
                this.lastUpdated = this.command.ExecuteScalar().ToString();
                this.transaction.Commit();
                return true;
            }
            catch (Exception e)
            {
                try
                {
                    transaction.Rollback();
                    throw new Exception("Error al insertar registro. " + e.Message);
                    return false;
                }
                catch (Exception ex)
                {
                    throw new Exception("Error al rollback accion. " + ex.Message);
                }
            }
            finally
            {
                this.connection.Close();
            }
        }
示例#6
0
        /*--------------------FIN CATALOGO Asignaturas------------------------*/
        /*--------------------Catalogo de Grupos-------------------------*/
        public List<Grupo> getGrupos(Asignatura a)
        {
            SqlDataReader dataReader = null;
            List<Grupo> Grupos = new List<Grupo>();
            try
            {
                string query = "Select * from Vista_Grupos where idAsignatura=@idAsignatura";
                command = new SqlCommand(query, connection);
                command.Connection.Open();
                command.Parameters.Add(new SqlParameter("@idAsignatura", SqlDbType.Int));
                command.Parameters["@idAsignatura"].Value = a.Id;
                dataReader = command.ExecuteReader();
                while (dataReader.Read())
                {
                    Grupo Grupo = new Grupo();
                    Grupo.Id = Convert.ToInt32(dataReader["id"].ToString());
                    Grupo.CantidadEstudiantes = Convert.ToInt32(dataReader["cantEstudiantes"].ToString());

                    Asignatura asignatura = new Asignatura();
                    asignatura.Id = Convert.ToInt32(dataReader["idAsignatura"].ToString());
                    asignatura.Nombre = dataReader["nombreAsignatura"].ToString();
                    Grupo.Asignatura = asignatura;

                    Docente docente = new Docente();
                    docente.Id = Convert.ToInt32(dataReader["idDocente"].ToString());
                    docente.Nombre = dataReader["nombreDocente"].ToString();
                    Grupo.Docente = docente;

                    Periodo periodo = new Periodo();
                    periodo.Id = Convert.ToInt32(dataReader["idPeriodo"].ToString());
                    periodo.Descripcion = dataReader["descripcionPeriodo"].ToString();
                    Grupo.Periodo = periodo;

                    Grupo.NumeroGrupo = Convert.ToInt32(dataReader["Grupo"].ToString());

                    Grupos.Add(Grupo);
                }
                return Grupos;
            }
            catch (Exception e)
            {
                throw new Exception("Error al obtener datos de Grupo. " + e.Message.ToString());
            }
            finally
            {
                command.Connection.Close();
            }
        }
示例#7
0
        public Boolean borrarGrupo(Grupo Grupo)
        {
            this.connection.Open();
            this.command = this.connection.CreateCommand();
            this.transaction = this.connection.BeginTransaction();

            this.command.Connection = this.connection;
            this.command.Transaction = this.transaction;

            try
            {
                this.command.CommandText = "delete from Grupo where id_Grupo=@id;";
                this.command.Parameters.Add(new SqlParameter("@id", SqlDbType.Int));
                this.command.Parameters["@id"].Value = Grupo.Id;
                this.command.ExecuteNonQuery();
                this.transaction.Commit();
                return true;
            }
            catch (Exception e)
            {
                try
                {
                    this.transaction.Rollback();
                    throw new Exception("Error al borrar registro. " + e.Message);
                    return false;
                }
                catch (Exception ex)
                {
                    throw new Exception("Error al rollback acción. " + ex.Message);
                    return false;
                }
            }
            finally
            {
                this.connection.Close();
            }
        }