private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            var senderGrid = (DataGridView)sender;

            if (senderGrid.Columns[e.ColumnIndex] is DataGridViewButtonColumn &&
                e.RowIndex >= 0)
            {
                senderGrid.Rows[e.RowIndex].ReadOnly = false;
                var btn = (DataGridViewButtonCell)senderGrid.CurrentCell;
                FormIncidenciaDetalle abrir = new FormIncidenciaDetalle();
                abrir.ShowDialog();
            }
        }
示例#2
0
        private void dgvIncidencias_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            incidenciaID = Convert.ToInt32(dgvIncidencias.CurrentRow.Cells[0].Value.ToString());

            if (e.ColumnIndex == dgvIncidencias.Columns["aceptar"].Index)
            {
                incidenciaID = Convert.ToInt32(dgvIncidencias.CurrentRow.Cells[0].Value.ToString());

                var connetionString = "Server=.\\SQLEXPRESS; Database= Sistema_Incidencias; Integrated Security=True";
                var sql             = "UPDATE incidencia SET estado = 2 where incidencia.id = @id";// repeat for all variables

                using (var connection = new SqlConnection(connetionString))
                {
                    using (var command = new SqlCommand(sql, connection))
                    {
                        command.Parameters.Add("@id", incidenciaID);

                        connection.Open();
                        int result = command.ExecuteNonQuery();

                        if (result < 0)
                        {
                            Console.WriteLine("Error inserting data into Database!");
                        }
                        else
                        {
                            MessageBox.Show("Incidencia aceptada.", "Mensaje", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        }
                    }
                }
            }
            else if (e.ColumnIndex == dgvIncidencias.Columns["rechazar"].Index)
            {
                incidenciaID = Convert.ToInt32(dgvIncidencias.CurrentRow.Cells[0].Value.ToString());

                var connetionString = "Server=.\\SQLEXPRESS; Database= Sistema_Incidencias; Integrated Security=True";
                var sql             = "UPDATE incidencia SET estado = 3 where incidencia.id = @id";// repeat for all variables

                using (var connection = new SqlConnection(connetionString))
                {
                    using (var command = new SqlCommand(sql, connection))
                    {
                        command.Parameters.Add("@id", incidenciaID);

                        connection.Open();
                        int result = command.ExecuteNonQuery();

                        if (result < 0)
                        {
                            Console.WriteLine("Error inserting data into Database!");
                        }
                        else
                        {
                            MessageBox.Show("Incidencia rechazada.", "Mensaje", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        }
                    }
                }
            }

            else if (e.ColumnIndex == dgvIncidencias.Columns["detalles"].Index)
            {
                //FormIncidenciaDetalle detalles = new FormIncidenciaDetalle();
                //detalles.Show();

                Form frm = Application.OpenForms.Cast <Form>().FirstOrDefault(x => x is FormIncidenciaDetalle);

                if (frm != null)
                {
                    //si la instancia existe la pongo en primer plano
                    frm.BringToFront();
                    return;
                }

                //sino existe la instancia se crea una nueva
                frm = new FormIncidenciaDetalle();
                frm.Show();
            }
        }