private void btnEliminar_Click(object sender, EventArgs e)
 {
     if (status == "True")
     {
         descripcion = "Baja";
     }
     else
     {
         descripcion = "Alta";
     }
     if (Funciones.StatusUpdate("alumnos", btnEliminar.Text, id))
     {
         movimiento.Clear();
         movimiento.Add("0");
         movimiento.Add(FrmMenu.usuarioID.ToString());
         movimiento.Add(id.ToString());
         movimiento.Add("'Alumnos'");
         movimiento.Add("'status'");
         movimiento.Add("NULL");
         movimiento.Add("NULL");
         movimiento.Add("'" + descripcion + "'");
         movimiento.Add("NOW()");
         movimiento.Add("NOW()");
         movimiento.Add("1");
         Funciones.Insert("movimientos", movimiento);
         this.Close();
     }
 }
Example #2
0
        private void btnReparar_Click(object sender, EventArgs e)
        {
            if (btnReparar.BackColor == Color.Crimson)
            {
                var respuesta = MessageBox.Show("¿Está seguro de mandar a reparación este artículo?", "Información", MessageBoxButtons.YesNo, MessageBoxIcon.Information);
                if (respuesta == DialogResult.Yes)
                {
                    ds = Conexion.MySQL("SELECT * FROM articulos WHERE id = " + id + ";");

                    if (ds.Tables["tabla"].Rows[0]["disponible"].ToString() == "False")
                    {
                        MessageBox.Show("El artículo se encuentra en un préstamo activo.\nPara ser marcado como mandado a reparación debe no estar en un préstamo activo.");
                        return;
                    }

                    Conexion.MySQL("UPDATE articulos SET disponible = 0, status = 0 WHERE id = " + id + ";");
                    btnEliminar.Visible  = false;
                    btnReparar.BackColor = Color.SeaGreen;

                    movimiento.Clear();
                    movimiento.Add("0");
                    movimiento.Add(FrmMenu.usuarioID.ToString());
                    movimiento.Add(id.ToString());
                    movimiento.Add("'Articulos'");
                    movimiento.Add("'Reparación'");
                    movimiento.Add("NULL");
                    movimiento.Add("NULL");
                    movimiento.Add("'Enviado'");
                    movimiento.Add("NOW()");
                    movimiento.Add("NOW()");
                    movimiento.Add("1");
                    Funciones.Insert("movimientos", movimiento);
                }
            }
            else
            {
                var respuesta = MessageBox.Show("¿Está seguro de marcar como reparado este artículo?", "Información", MessageBoxButtons.YesNo, MessageBoxIcon.Information);
                if (respuesta == DialogResult.Yes)
                {
                    Conexion.MySQL("UPDATE articulos SET disponible = 1, status = 1 WHERE id = " + id + ";");
                    btnEliminar.Visible  = true;
                    btnReparar.BackColor = Color.Crimson;

                    movimiento.Clear();
                    movimiento.Add("0");
                    movimiento.Add(FrmMenu.usuarioID.ToString());
                    movimiento.Add(id.ToString());
                    movimiento.Add("'Articulos'");
                    movimiento.Add("'Reparación'");
                    movimiento.Add("NULL");
                    movimiento.Add("NULL");
                    movimiento.Add("'Recibido'");
                    movimiento.Add("NOW()");
                    movimiento.Add("NOW()");
                    movimiento.Add("1");
                    Funciones.Insert("movimientos", movimiento);
                }
            }
        }
Example #3
0
        private void btnEliminar_Click(object sender, EventArgs e)
        {
            ds = Conexion.MySQL("SELECT * FROM articulos WHERE id = " + id + ";");

            if (ds.Tables["tabla"].Rows[0]["disponible"].ToString() == "False" && status == "True")
            {
                MessageBox.Show("El artículo se encuentra en un préstamo activo.\nPara ser dado de baja debe no estar en un préstamo activo.");
                return;
            }

            if (status == "True")
            {
                descripcion = "Baja";
            }
            else
            {
                descripcion = "Alta";
            }
            if (Funciones.StatusUpdate("articulos", btnEliminar.Text, id))
            {
                movimiento.Clear();
                movimiento.Add("0");
                movimiento.Add(FrmMenu.usuarioID.ToString());
                movimiento.Add(id.ToString());
                movimiento.Add("'Articulos'");
                movimiento.Add("'status'");
                movimiento.Add("NULL");
                movimiento.Add("NULL");
                movimiento.Add("'" + descripcion + "'");
                movimiento.Add("NOW()");
                movimiento.Add("NOW()");
                movimiento.Add("1");
                Funciones.Insert("movimientos", movimiento);
                this.DialogResult = DialogResult.OK;
                this.Close();
            }
        }
        private void btnActualizar_Click(object sender, EventArgs e)
        {
            //if (txtMatricula.Text == "") { MessageBox.Show("Ingrese la matricula", "Advertencia", MessageBoxButtons.OK, MessageBoxIcon.Warning); txtMatricula.Focus(); return; }
            //if (txtNombre.Text == "") { MessageBox.Show("Ingrese el nombre", "Advertencia", MessageBoxButtons.OK, MessageBoxIcon.Warning); txtNombre.Focus(); return; }
            //if (txtPaterno.Text == "") { MessageBox.Show("Ingrese el apellido paterno", "Advertencia", MessageBoxButtons.OK, MessageBoxIcon.Warning); txtPaterno.Focus(); return; }
            //if (txtMaterno.Text == "") { MessageBox.Show("Ingrese el apellido materno", "Advertencia", MessageBoxButtons.OK, MessageBoxIcon.Warning); txtMaterno.Focus(); return; }
            if (cmbCarrera.Text == "")
            {
                MessageBox.Show("Seleccione una carrera", "Advertencia", MessageBoxButtons.OK, MessageBoxIcon.Warning); cmbCarrera.Focus(); return;
            }
            //if (txtCorreo.Text == "") { MessageBox.Show("Ingrese el correo", "Advertencia", MessageBoxButtons.OK, MessageBoxIcon.Warning); txtCorreo.Focus(); return; }
            //if (txtTelefono.Text == "") { MessageBox.Show("Ingrese el telefono", "Advertencia", MessageBoxButtons.OK, MessageBoxIcon.Warning); txtTelefono.Focus(); return; }

            if (!DatosCompletos())
            {
                MessageBox.Show("Debe de llenar los datos con el formato correcto.");
                return;
            }

            string status = "1";

            if (id != 0)
            {
                ds     = Conexion.MySQL("SELECT status FROM alumnos WHERE id = " + id + ";");
                status = ds.Tables["tabla"].Rows[0][0].ToString();
            }

            valores.Add(id.ToString());
            valores.Add("'" + txtMatricula.Text + "'");
            valores.Add("'" + txtNombre.Text + "'");
            valores.Add("'" + txtPaterno.Text + "'");
            valores.Add("'" + txtMaterno.Text + "'");
            valores.Add(llaves[cmbCarrera.SelectedIndex].ToString());
            valores.Add("'" + txtCorreo.Text + "'");
            valores.Add("'" + txtTelefono.Text + "'");
            valores.Add("NOW()");
            valores.Add("NOW()");
            valores.Add(status);

            nuevo.Add(txtMatricula.Text);
            nuevo.Add(txtNombre.Text);
            nuevo.Add(txtPaterno.Text);
            nuevo.Add(txtMaterno.Text);
            nuevo.Add(cmbCarrera.Text);
            nuevo.Add(txtCorreo.Text);
            nuevo.Add(txtTelefono.Text);

            if (id != 0)
            {
                var respuesta = MessageBox.Show("¿Esta seguro de actualizar este registro?", "Informacion", MessageBoxButtons.YesNo, MessageBoxIcon.Information);
                if (respuesta == DialogResult.Yes)
                {
                    if (Funciones.Insert("alumnos", valores))
                    {
                        for (int i = 0; i < original.Count; i++)
                        {
                            if (original[i] != nuevo[i])
                            {
                                movimiento.Clear();
                                movimiento.Add("0");
                                movimiento.Add(FrmMenu.usuarioID.ToString());
                                movimiento.Add(id.ToString());
                                movimiento.Add("'Alumnos'");
                                movimiento.Add("'" + columnas[i] + "'");
                                movimiento.Add("'" + nuevo[i] + "'");
                                movimiento.Add("'" + original[i] + "'");
                                movimiento.Add("'Modificó'");
                                movimiento.Add("NOW()");
                                movimiento.Add("NOW()");
                                movimiento.Add("1");
                                Funciones.Insert("movimientos", movimiento);
                            }
                        }
                    }
                    this.DialogResult = DialogResult.OK;
                    this.Close();
                }
            }
            else
            {
                if (Funciones.Insert("alumnos", valores))
                {
                    ds = Conexion.MySQL("SELECT Last_Insert_ID();");
                    movimiento.Clear();
                    movimiento.Add("0");
                    movimiento.Add(FrmMenu.usuarioID.ToString());
                    movimiento.Add(ds.Tables["tabla"].Rows[0][0].ToString());
                    movimiento.Add("'Alumnos'");
                    movimiento.Add("NULL");
                    movimiento.Add("NULL");
                    movimiento.Add("NULL");
                    movimiento.Add("'Agregó'");
                    movimiento.Add("NOW()");
                    movimiento.Add("NOW()");
                    movimiento.Add("1");
                    Funciones.Insert("movimientos", movimiento);
                }
                this.DialogResult = DialogResult.OK;
                this.Close();
            }
        }
        //Variables Publicas y Privadas
        //Formulario Carga o Cierra
        //Desarrollo
        private void btnActualizar_Click(object sender, EventArgs e)
        {
            List <string> valores = new List <string>();

            if (txtNombre.Text == "")
            {
                MessageBox.Show("Ingrese el nombre de la asignatura", "Advertencia", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); txtNombre.Focus(); return;
            }

            string status = "1";

            if (id != 0)
            {
                ds     = Conexion.MySQL("SELECT status FROM carreras WHERE id = " + id + ";");
                status = ds.Tables["tabla"].Rows[0][0].ToString();
            }

            valores.Add(id.ToString());
            valores.Add("'" + txtNombre.Text + "'");
            valores.Add("NOW()");
            valores.Add("NOW()");
            valores.Add(status);

            nuevo.Add(txtNombre.Text);

            if (id != 0)
            {
                var respuesta = MessageBox.Show("¿Esta seguro de actualizar este registro?", "Informacion", MessageBoxButtons.YesNo, MessageBoxIcon.Information);
                if (respuesta == DialogResult.Yes)
                {
                    if (Funciones.Insert("carreras", valores))
                    {
                        for (int i = 0; i < original.Count; i++)
                        {
                            if (original[i] != nuevo[i])
                            {
                                movimiento.Clear();
                                movimiento.Add("0");
                                movimiento.Add(FrmMenu.usuarioID.ToString());
                                movimiento.Add(id.ToString());
                                movimiento.Add("'Carreras'");
                                movimiento.Add("'" + columnas[i] + "'");
                                movimiento.Add("'" + nuevo[i] + "'");
                                movimiento.Add("'" + original[i] + "'");
                                movimiento.Add("'Modificó'");
                                movimiento.Add("NOW()");
                                movimiento.Add("NOW()");
                                movimiento.Add("1");
                                Funciones.Insert("movimientos", movimiento);
                            }
                        }
                    }
                    this.Close();
                }
            }
            else
            {
                if (Funciones.Insert("carreras", valores))
                {
                    ds = Conexion.MySQL("SELECT Last_Insert_ID();");
                    movimiento.Clear();
                    movimiento.Add("0");
                    movimiento.Add(FrmMenu.usuarioID.ToString());
                    movimiento.Add(ds.Tables["tabla"].Rows[0][0].ToString());
                    movimiento.Add("'Carreras'");
                    movimiento.Add("NULL");
                    movimiento.Add("NULL");
                    movimiento.Add("NULL");
                    movimiento.Add("'Agregó'");
                    movimiento.Add("NOW()");
                    movimiento.Add("NOW()");
                    movimiento.Add("1");
                    Funciones.Insert("movimientos", movimiento);
                }
                this.Close();
            }
        }
        private void btnActualizar_Click(object sender, EventArgs e)
        {
            var respuesta = MessageBox.Show("¿Desea actualizar el préstamo?", "Información", MessageBoxButtons.YesNo, MessageBoxIcon.Information);

            if (respuesta == DialogResult.Yes)
            {
                foreach (DataGridViewRow row in dataGridView1.Rows)
                {
                    if (row.DefaultCellStyle.ForeColor == Color.Red && !noEntregadoID.Contains(int.Parse(row.Cells[0].Value.ToString())))
                    {
                        ds = Conexion.MySQL("SELECT * FROM articulos WHERE id = " + row.Cells[0].Value.ToString() + " AND disponible = 1;");

                        if (ds.Tables["tabla"].Rows.Count == 0)
                        {
                            MessageBox.Show("El artículo con el ID " + row.Cells[0].Value.ToString() + " se encuentra en otro préstamo activo.");
                            return;
                        }
                    }
                }

                foreach (DataGridViewRow row in dataGridView1.Rows)
                {
                    if (row.DefaultCellStyle.ForeColor == Color.LimeGreen)
                    {
                        detalles.Clear();
                        detalles.Add("0");
                        detalles.Add(id.ToString());
                        detalles.Add(row.Cells[0].Value.ToString());
                        detalles.Add("NOW()");
                        detalles.Add("NOW()");
                        detalles.Add("1");

                        Funciones.Insert("detalles", detalles);

                        ds = Conexion.MySQL("SELECT LAST_INSERT_ID();");

                        movimiento.Clear();
                        movimiento.Add("0");
                        movimiento.Add(FrmMenu.usuarioID.ToString());
                        movimiento.Add(ds.Tables["tabla"].Rows[0][0].ToString());
                        movimiento.Add("'Detalles'");
                        movimiento.Add("'Artículo'");
                        movimiento.Add("'" + row.Cells[1].Value.ToString() + "'");
                        movimiento.Add("NULL");
                        movimiento.Add("'Prestó'");
                        movimiento.Add("NOW()");
                        movimiento.Add("NOW()");
                        movimiento.Add("1");
                        Funciones.Insert("movimientos", movimiento);
                    }

                    if (row.DefaultCellStyle.ForeColor == Color.Black && noEntregadoID.Contains(int.Parse(row.Cells[0].Value.ToString())))
                    {
                        Conexion.MySQL("UPDATE detalles SET status = 0, updated_at = NOW() WHERE articulo = " + row.Cells[0].Value.ToString() + " AND prestamo = " + id + ";");

                        ds = Conexion.MySQL("SELECT id FROM detalles WHERE articulo = " + row.Cells[0].Value.ToString() + " AND prestamo = " + id + ";");

                        movimiento.Clear();
                        movimiento.Add("0");
                        movimiento.Add(FrmMenu.usuarioID.ToString());
                        movimiento.Add(ds.Tables["tabla"].Rows[0][0].ToString());
                        movimiento.Add("'Detalles'");
                        movimiento.Add("'Artículo'");
                        movimiento.Add("'" + row.Cells[1].Value.ToString() + "'");
                        movimiento.Add("NULL");
                        movimiento.Add("'Devolvió'");
                        movimiento.Add("NOW()");
                        movimiento.Add("NOW()");
                        movimiento.Add("1");
                        Funciones.Insert("movimientos", movimiento);

                        Conexion.MySQL("UPDATE articulos SET disponible = 1, updated_at = NOW() WHERE id = " + row.Cells[0].Value.ToString() + ";");

                        movimiento.Clear();
                        movimiento.Add("0");
                        movimiento.Add(FrmMenu.usuarioID.ToString());
                        movimiento.Add(row.Cells[0].Value.ToString());
                        movimiento.Add("'Articulos'");
                        movimiento.Add("'Disponible'");
                        movimiento.Add("'1'");
                        movimiento.Add("'0'");
                        movimiento.Add("'Modificó'");
                        movimiento.Add("NOW()");
                        movimiento.Add("NOW()");
                        movimiento.Add("1");
                        Funciones.Insert("movimientos", movimiento);
                    }

                    if (row.DefaultCellStyle.ForeColor == Color.Red && !noEntregadoID.Contains(int.Parse(row.Cells[0].Value.ToString())))
                    {
                        Conexion.MySQL("UPDATE detalles SET status = 1, updated_at = NOW() WHERE articulo = " + row.Cells[0].Value.ToString() + " AND prestamo = " + id + ";");

                        ds = Conexion.MySQL("SELECT id FROM detalles WHERE articulo = " + row.Cells[0].Value.ToString() + " AND prestamo = " + id + ";");

                        movimiento.Clear();
                        movimiento.Add("0");
                        movimiento.Add(FrmMenu.usuarioID.ToString());
                        movimiento.Add(ds.Tables["tabla"].Rows[0][0].ToString());
                        movimiento.Add("'Detalles'");
                        movimiento.Add("'Artículo'");
                        movimiento.Add("'" + row.Cells[1].Value.ToString() + "'");
                        movimiento.Add("NULL");
                        movimiento.Add("'Prestó'");
                        movimiento.Add("NOW()");
                        movimiento.Add("NOW()");
                        movimiento.Add("1");
                        Funciones.Insert("movimientos", movimiento);

                        Conexion.MySQL("UPDATE articulos SET disponible = 0, updated_at = NOW() WHERE id = " + row.Cells[0].Value.ToString() + ";");

                        movimiento.Clear();
                        movimiento.Add("0");
                        movimiento.Add(FrmMenu.usuarioID.ToString());
                        movimiento.Add(row.Cells[0].Value.ToString());
                        movimiento.Add("'Articulos'");
                        movimiento.Add("'Disponible'");
                        movimiento.Add("'0'");
                        movimiento.Add("'1'");
                        movimiento.Add("'Modificó'");
                        movimiento.Add("NOW()");
                        movimiento.Add("NOW()");
                        movimiento.Add("1");
                        Funciones.Insert("movimientos", movimiento);
                    }
                }

                for (int i = 0; i < dataGridView1.Rows.Count; i++)
                {
                    if (dataGridView1.Rows[i].DefaultCellStyle.ForeColor == Color.LimeGreen)
                    {
                        dataGridView1.Rows[i].DefaultCellStyle.ForeColor          = Color.Red;
                        dataGridView1.Rows[i].DefaultCellStyle.SelectionForeColor = Color.Red;
                    }
                }

                noEntregadoID.Clear();
                foreach (DataGridViewRow row in dataGridView1.Rows)
                {
                    if (row.DefaultCellStyle.ForeColor == Color.Red)
                    {
                        noEntregadoID.Add(int.Parse(row.Cells[0].Value.ToString()));
                    }
                }

                if (noEntregadoID.Count == 0)
                {
                    Conexion.MySQL("UPDATE prestamos SET status = 0, updated_at = NOW() WHERE id = " + id + ";");

                    movimiento.Clear();
                    movimiento.Add("0");
                    movimiento.Add(FrmMenu.usuarioID.ToString());
                    movimiento.Add(id.ToString());
                    movimiento.Add("'Prestamos'");
                    movimiento.Add("NULL");
                    movimiento.Add("NULL");
                    movimiento.Add("NULL");
                    movimiento.Add("'Devolvió'");
                    movimiento.Add("NOW()");
                    movimiento.Add("NOW()");
                    movimiento.Add("1");
                    Funciones.Insert("movimientos", movimiento);

                    txtCodigo.Enabled     = false;
                    btnActualizar.Visible = false;
                }
            }
        }
        private void dataGridView1_CellMouseDoubleClick(object sender, DataGridViewCellMouseEventArgs e)
        {
            if (status == "False")
            {
                if (noEntregadoID.Contains(int.Parse(dataGridView1.Rows[e.RowIndex].Cells[0].Value.ToString())))
                {
                    var respuesta = MessageBox.Show("¿Desea marcar como devuelto este artículo?", "Información", MessageBoxButtons.YesNo, MessageBoxIcon.Information);
                    if (respuesta == DialogResult.Yes)
                    {
                        Conexion.MySQL("UPDATE detalles SET status = 0 WHERE articulo = " + int.Parse(dataGridView1.Rows[e.RowIndex].Cells[0].Value.ToString()) + " AND prestamo = " + id + ";");

                        ds = Conexion.MySQL("SELECT id FROM detalles WHERE articulo = " + int.Parse(dataGridView1.Rows[e.RowIndex].Cells[0].Value.ToString()) + " AND prestamo = " + id + ";");

                        movimiento.Clear();
                        movimiento.Add("0");
                        movimiento.Add(FrmMenu.usuarioID.ToString());
                        movimiento.Add(ds.Tables["tabla"].Rows[0][0].ToString());
                        movimiento.Add("'Detalles'");
                        movimiento.Add("'Artículo'");
                        movimiento.Add("'" + dataGridView1.Rows[e.RowIndex].Cells[1].Value.ToString() + "'");
                        movimiento.Add("NULL");
                        movimiento.Add("'Devolvió'");
                        movimiento.Add("NOW()");
                        movimiento.Add("NOW()");
                        movimiento.Add("1");
                        Funciones.Insert("movimientos", movimiento);

                        Conexion.MySQL("UPDATE articulos SET disponible = 1 WHERE id = " + int.Parse(dataGridView1.Rows[e.RowIndex].Cells[0].Value.ToString()) + ";");

                        movimiento.Clear();
                        movimiento.Add("0");
                        movimiento.Add(FrmMenu.usuarioID.ToString());
                        movimiento.Add(dataGridView1.Rows[e.RowIndex].Cells[0].Value.ToString());
                        movimiento.Add("'Articulos'");
                        movimiento.Add("'Disponible'");
                        movimiento.Add("'1'");
                        movimiento.Add("'0'");
                        movimiento.Add("'Modificó'");
                        movimiento.Add("NOW()");
                        movimiento.Add("NOW()");
                        movimiento.Add("1");
                        Funciones.Insert("movimientos", movimiento);

                        dataGridView1.Rows[e.RowIndex].DefaultCellStyle.ForeColor          = Color.Black;
                        dataGridView1.Rows[e.RowIndex].DefaultCellStyle.SelectionForeColor = Color.Black;
                    }
                }
                else
                {
                    MessageBox.Show("El artículo seleccionado ya ha sido devuelto.");
                }
            }
            else
            {
                if (dataGridView1.Rows[e.RowIndex].DefaultCellStyle.ForeColor == Color.Black)
                {
                    dataGridView1.Rows[e.RowIndex].DefaultCellStyle.ForeColor          = Color.Red;
                    dataGridView1.Rows[e.RowIndex].DefaultCellStyle.SelectionForeColor = Color.Red;
                }
                else if (dataGridView1.Rows[e.RowIndex].DefaultCellStyle.ForeColor == Color.Red)
                {
                    dataGridView1.Rows[e.RowIndex].DefaultCellStyle.ForeColor          = Color.Black;
                    dataGridView1.Rows[e.RowIndex].DefaultCellStyle.SelectionForeColor = Color.Black;
                }
                else if (dataGridView1.Rows[e.RowIndex].DefaultCellStyle.ForeColor == Color.LimeGreen)
                {
                    dataGridView1.Rows.RemoveAt(e.RowIndex);
                }
            }
        }
        //Desarrollo
        private void button1_Click(object sender, EventArgs e)
        {
            if (txtMatricula.Text == "")
            {
                MessageBox.Show("Ingrese la matricula", "Advertencia", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); txtMatricula.Focus(); return;
            }
            if (dataGridView1.Rows.Count == 0)
            {
                MessageBox.Show("Agregue artículos a la lista", "Advertencia", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); txtCodigo.Focus(); return;
            }
            if (cmbMaestro.Text == "")
            {
                MessageBox.Show("Seleccione el nombre del maestro", "Advertencia", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); cmbMaestro.Focus(); return;
            }
            if (cmbAsignatura.Text == "")
            {
                MessageBox.Show("Seleccione la asignatura", "Advertencia", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); cmbAsignatura.Focus(); return;
            }
            if (cmbLaboratorio.Text == "")
            {
                MessageBox.Show("Seleccione laboratorio", "Advertencia", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); cmbLaboratorio.Focus(); return;
            }

            if (!devolver)
            {
                List <string> valores  = new List <string>();
                List <string> detalles = new List <string>();
                List <string> articulo = new List <string>();

                ds = Conexion.MySQL("SELECT status FROM usuarios WHERE id = " + FrmMenu.usuarioID + ";");

                if (ds.Tables["tabla"].Rows[0][0].ToString() == "False")
                {
                    { MessageBox.Show("El usuario de la sesión se encuentra dado de baja en el sistema", "Advertencia", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; }
                }

                var respuesta = MessageBox.Show("¿Desea realizar el siguiente prestamo?", "Información", MessageBoxButtons.YesNo, MessageBoxIcon.Information);
                if (respuesta == DialogResult.Yes)
                {
                    if (DateTime.Now.ToString().Substring(0, 10) == dateTimePickerFin.Value.ToString().Substring(0, 10))
                    {
                        fecha = "NOW()";
                    }
                    else
                    {
                        fecha = "'" + dateTimePickerFin.Value.ToString().Substring(6, 4) + "-" + dateTimePickerFin.Value.ToString().Substring(3, 2) + "-" + dateTimePickerFin.Value.ToString().Substring(0, 2) + "'";
                    }

                    valores.Add("0");
                    valores.Add(alumnoID.ToString());
                    valores.Add(maestros[cmbMaestro.SelectedIndex].ToString());
                    valores.Add(laboratorios[cmbLaboratorio.SelectedIndex].ToString());
                    valores.Add(asignaturas[cmbAsignatura.SelectedIndex].ToString());
                    valores.Add(FrmMenu.usuarioID.ToString());
                    valores.Add(fecha);
                    valores.Add("NOW()");
                    valores.Add("NOW()");
                    valores.Add("1");

                    Funciones.Insert("prestamos", valores);

                    ds = Conexion.MySQL("SELECT LAST_INSERT_ID();");

                    prestamoID = int.Parse(ds.Tables["tabla"].Rows[0][0].ToString());

                    movimiento.Clear();
                    movimiento.Add("0");
                    movimiento.Add(FrmMenu.usuarioID.ToString());
                    movimiento.Add(prestamoID.ToString());
                    movimiento.Add("'Prestamos'");
                    movimiento.Add("NULL");
                    movimiento.Add("NULL");
                    movimiento.Add("NULL");
                    movimiento.Add("'Prestó'");
                    movimiento.Add("NOW()");
                    movimiento.Add("NOW()");
                    movimiento.Add("1");
                    Funciones.Insert("movimientos", movimiento);

                    foreach (DataGridViewRow row in dataGridView1.Rows)
                    {
                        detalles.Clear();
                        detalles.Add("0");
                        detalles.Add(prestamoID.ToString());
                        detalles.Add(row.Cells[0].Value.ToString());
                        detalles.Add("NOW()");
                        detalles.Add("NOW()");
                        detalles.Add("1");

                        Funciones.Insert("detalles", detalles);

                        articulo.Clear();
                        articulo.Add(row.Cells[0].Value.ToString());
                        articulo.Add("'" + row.Cells[1].Value.ToString() + "'");
                        articulo.Add("'" + row.Cells[2].Value.ToString() + "'");
                        articulo.Add("0");
                        articulo.Add("NOW()");
                        articulo.Add("NOW()");
                        articulo.Add("1");

                        Funciones.Insert("articulos", articulo);
                    }
                    borrarContenido();
                }
            }
            else
            {
                string texto;
                int    rowColorCount = 0;
                for (int i = 0; i < dataGridView1.Rows.Count; i++)
                {
                    if (dataGridView1.Rows[i].DefaultCellStyle.ForeColor == Color.Red)
                    {
                        rowColorCount++;
                    }
                }

                if (rowColorCount == dataGridView1.Rows.Count)
                {
                    MessageBox.Show("No se ha devuelto ningún artículo.\nFavor de devolver al menos uno a la lista");
                    return;
                }
                else if (rowColorCount != 0)
                {
                    texto = "Hay artículos faltantes\nLos artículos faltantes serán registrados como no entregados\n¿Desea realizar la siguiente devolución?";
                }
                else
                {
                    texto = "¿Desea realizar la siguiente devolución?";
                }

                var respuesta = MessageBox.Show(texto, "Información", MessageBoxButtons.YesNo, MessageBoxIcon.Information);
                if (respuesta == DialogResult.Yes)
                {
                    Conexion.MySQL("UPDATE prestamos SET status = '0' WHERE prestamos.id = " + prestamoID + ";");

                    foreach (DataGridViewRow row in dataGridView1.Rows)
                    {
                        if (row.DefaultCellStyle.ForeColor == Color.Black)
                        {
                            Conexion.MySQL("UPDATE detalles SET status = '0' WHERE detalles.prestamo = " + prestamoID + " AND detalles.articulo = " + row.Cells[0].Value.ToString() + ";");
                            Conexion.MySQL("UPDATE articulos SET disponible = '1' WHERE articulos.id = " + row.Cells[0].Value.ToString() + ";");
                        }
                    }

                    txtCodigo.Enabled    = false;
                    txtMatricula.Enabled = true;
                    txtMatricula.Focus();
                    MessageBox.Show("La devolución se ha realizado correctamente.");

                    movimiento.Clear();
                    movimiento.Add("0");
                    movimiento.Add(FrmMenu.usuarioID.ToString());
                    movimiento.Add(prestamoID.ToString());
                    movimiento.Add("'Prestamos'");
                    movimiento.Add("NULL");
                    movimiento.Add("NULL");
                    movimiento.Add("NULL");
                    movimiento.Add("'Devolvió'");
                    movimiento.Add("NOW()");
                    movimiento.Add("NOW()");
                    movimiento.Add("1");
                    Funciones.Insert("movimientos", movimiento);

                    borrarContenido();
                }
            }
            NotificationsUpdate();
        }
Example #9
0
        //Desarrollo
        private void btnRegistrar_Click(object sender, EventArgs e)
        {
            DataSet       ds;
            List <string> valores = new List <string>();

            if (txtUsuario.Text == "")
            {
                MessageBox.Show("Ingrese el usuario", "Advertencia", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); txtUsuario.Focus(); return;
            }
            if (txtContraseña.Text == "" && txtContraseñaC.Text != "")
            {
                MessageBox.Show("Ingrese la contraseña", "Advertencia", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); txtContraseña.Focus(); return;
            }
            if (txtContraseñaC.Text == "" && txtContraseña.Text != "")
            {
                MessageBox.Show("Ingrese la contraseña", "Advertencia", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); txtContraseñaC.Focus(); return;
            }
            if (!(txtContraseña.Text == txtContraseñaC.Text))
            {
                MessageBox.Show("Las contraseñas no coinciden", "Advertencia", MessageBoxButtons.OK, MessageBoxIcon.Warning); return;
            }
            if (cmbNivel.Text == "")
            {
                MessageBox.Show("Seleccione el Nivel", "Advertencia", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); cmbNivel.Focus(); return;
            }
            if (txtContraseña.Text != txtContraseñaC.Text)
            {
                MessageBox.Show("Las contraseñas no coinciden", "Advertencia", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); txtContraseña.Focus(); return;
            }

            string status = "1";

            if (id != 0)
            {
                ds     = Conexion.MySQL("SELECT status FROM usuarios WHERE id = " + id + ";");
                status = ds.Tables["tabla"].Rows[0][0].ToString();
            }

            valores.Add(id.ToString());
            valores.Add("'" + txtUsuario.Text + "'");
            valores.Add("md5('" + txtContraseña.Text + "')");
            valores.Add("'" + cmbNivel.Text + "'");
            valores.Add("NOW()");
            valores.Add("NOW()");
            valores.Add(status);

            nuevo.Add(txtUsuario.Text);
            nuevo.Add(cmbNivel.Text);

            if (id != 0)
            {
                var respuesta = MessageBox.Show("¿Esta seguro de actualizar este registro?", "Informacion", MessageBoxButtons.YesNo, MessageBoxIcon.Information);
                if (respuesta == DialogResult.Yes)
                {
                    if (Funciones.Insert("usuarios", valores))
                    {
                        for (int i = 0; i < original.Count; i++)
                        {
                            if (original[i] != nuevo[i])
                            {
                                movimiento.Clear();
                                movimiento.Add("0");
                                movimiento.Add(FrmMenu.usuarioID.ToString());
                                movimiento.Add(id.ToString());
                                movimiento.Add("'Usuarios'");
                                movimiento.Add("'" + columnas[i] + "'");
                                movimiento.Add("'" + nuevo[i] + "'");
                                movimiento.Add("'" + original[i] + "'");
                                movimiento.Add("'Modificó'");
                                movimiento.Add("NOW()");
                                movimiento.Add("NOW()");
                                movimiento.Add("1");
                                Funciones.Insert("movimientos", movimiento);
                            }
                        }

                        if (txtContraseña.Text == txtContraseñaC.Text)
                        {
                            movimiento.Clear();
                            movimiento.Add("0");
                            movimiento.Add(FrmMenu.usuarioID.ToString());
                            movimiento.Add(id.ToString());
                            movimiento.Add("'Usuarios'");
                            movimiento.Add("'Contraseña'");
                            movimiento.Add("NULL");
                            movimiento.Add("NULL");
                            movimiento.Add("'Modificó'");
                            movimiento.Add("NOW()");
                            movimiento.Add("NOW()");
                            movimiento.Add("1");
                            Funciones.Insert("movimientos", movimiento);
                        }
                    }
                    this.Close();
                }
            }
            else
            {
                if (Funciones.Insert("usuarios", valores))
                {
                    ds = Conexion.MySQL("SELECT Last_Insert_ID();");
                    movimiento.Clear();
                    movimiento.Add("0");
                    movimiento.Add(FrmMenu.usuarioID.ToString());
                    movimiento.Add(ds.Tables["tabla"].Rows[0][0].ToString());
                    movimiento.Add("'Usuarios'");
                    movimiento.Add("NULL");
                    movimiento.Add("NULL");
                    movimiento.Add("NULL");
                    movimiento.Add("'Agregó'");
                    movimiento.Add("NOW()");
                    movimiento.Add("NOW()");
                    movimiento.Add("1");
                    Funciones.Insert("movimientos", movimiento);
                }
                this.Close();
            }
        }