Пример #1
0
        private void btnGrabar_Click_1(object sender, EventArgs e)
        {
            if (validar())
            {
                string sql;

                if (miAccion == acciones.Nuevo)
                {
                    Noche noche = new Noche();
                    noche.Nro_luna           = Convert.ToInt32(txtNroLuna.Text);
                    noche.Fecha_horaComienzo = dtpFechaCom.Value;
                    noche.Fecha_horaCierre   = dtpHoraCierre.Value;


                    sql = "INSERT INTO NOCHE VALUES ('"
                          + noche.Nro_luna + "','"
                          + noche.Fecha_horaComienzo + "','"
                          + noche.Fecha_horaCierre + "')";
                    oDatos.actualizarBD(sql);
                    cargarLista("NOCHE");
                }

                if (miAccion == acciones.Modificar)
                {
                    int i = listBoxNoches.SelectedIndex;

                    if (MessageBox.Show("¿Seguro que desea modificar los datos de la noche " + ArregloNoches[i].Nro_luna + " ?"
                                        , "Modificar"
                                        , MessageBoxButtons.YesNo
                                        , MessageBoxIcon.Warning
                                        , MessageBoxDefaultButton.Button2)
                        == DialogResult.Yes)
                    {
                        ArregloNoches[i].Nro_luna           = Convert.ToInt32(txtNroLuna.Text);
                        ArregloNoches[i].Fecha_horaComienzo = dtpFechaCom.Value;
                        ArregloNoches[i].Fecha_horaCierre   = dtpHoraCierre.Value;


                        sql = "UPDATE NOCHE set nro_luna ='" + ArregloNoches[i].Nro_luna
                              + "', fecha_horaComienzo ='" + ArregloNoches[i].Fecha_horaComienzo
                              + "', fecha_horaCierre ='" + ArregloNoches[i].Fecha_horaCierre
                              + "' Where id_noche=" + ArregloNoches[i].Id_noche;

                        oDatos.actualizarBD(sql);
                        cargarLista("NOCHE");
                    }
                }
                habilitar(false);
                miAccion = acciones.Ninguna;
            }
        }
Пример #2
0
        private void cargarLista(string nombreTabla)
        {
            oDatos.leerTabla(nombreTabla);
            int n = 0;

            while (oDatos.pLector.Read())
            {
                Noche noche = new Noche();
                if (!oDatos.pLector.IsDBNull(0))
                {
                    noche.Id_noche = oDatos.pLector.GetInt32(0);
                }
                if (!oDatos.pLector.IsDBNull(1))
                {
                    noche.Nro_luna = oDatos.pLector.GetInt32(1);
                }
                if (!oDatos.pLector.IsDBNull(2))
                {
                    noche.Fecha_horaComienzo = oDatos.pLector.GetDateTime(2);
                }
                if (!oDatos.pLector.IsDBNull(3))
                {
                    noche.Fecha_horaCierre = oDatos.pLector.GetDateTime(3);
                }


                ArregloNoches[n] = noche;
                n++;
            }
            oDatos.pLector.Close();
            oDatos.desconectar();
            listBoxNoches.Items.Clear();
            for (int i = 0; i < n; i++)
            {
                listBoxNoches.Items.Add(ArregloNoches[i].ToString());
            }
            listBoxNoches.SelectedIndex = -1;
        }