Exemple #1
0
 private void DgCliente_CellClick(object sender, DataGridViewCellEventArgs e)
 {
     try
     {
         if (this.dgCliente.Columns[e.ColumnIndex].Name == "Guardar")
         {
             if (MessageBox.Show("¿Seguro que desea Guardar?", "Alerta", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation) == DialogResult.Yes)
             {
                 {
                     foreach (DataRow fila in clientes.Rows)
                     {
                         if (dgCliente.CurrentRow.Cells[0].Value.ToString() == fila[0].ToString())
                         {
                             modificar = true;
                             bool           existir = false;
                             Cls_E_Clientes objE    = new Cls_E_Clientes();
                             objE.Dni     = dgCliente.CurrentRow.Cells[0].Value.ToString();
                             objE.Nombres = dgCliente.CurrentRow.Cells[1].Value.ToString();
                             objE.Estado  = dgCliente.CurrentRow.Cells[2].Value.ToString();
                             Cls_N_Clientes objN = new Cls_N_Clientes();
                             existir = objN.MtdActualizarCliente(objE);
                             if (existir == true)
                             {
                                 MessageBox.Show("Modificado exitosamente");
                                 btnRefrescar.PerformClick();
                                 dgCliente.Columns[0].ReadOnly = true;
                             }
                             break;
                         }
                         else
                         {
                             bool           existir;
                             Cls_E_Clientes objE = new Cls_E_Clientes();
                             objE.Dni     = dgCliente.CurrentRow.Cells[0].Value.ToString();
                             objE.Nombres = dgCliente.CurrentRow.Cells[1].Value.ToString();
                             objE.Estado  = dgCliente.CurrentRow.Cells[2].Value.ToString();
                             Cls_N_Clientes objN = new Cls_N_Clientes();
                             existir = objN.MtdAgregarCliente(objE);
                             if (existir == true)
                             {
                                 MessageBox.Show("Guardado exitosamente");
                                 btnRefrescar.PerformClick();
                                 dgCliente.Columns[0].ReadOnly = true;
                             }
                         }
                     }
                 }
             }
         }
         else if (this.dgCliente.Columns[e.ColumnIndex].Name == "Deshabilitar")
         {
             dgCliente.CurrentRow.Cells[2].Value = "0";
             mtdPintar();
         }
     }
     catch
     {
         //nada
     }
 }
Exemple #2
0
        internal bool MtdAgregarCliente(Cls_E_Clientes objE)
        {
            try
            {
                ClsConexionSQL objConexion = new ClsConexionSQL();
                SqlCommand     objComando  = new SqlCommand();
                objComando.Connection  = objConexion.conectar();
                objComando.CommandText = "USP_I_AgregarClientes";
                objComando.CommandType = CommandType.StoredProcedure;
                objComando.Parameters.Add(new SqlParameter("d", SqlDbType.VarChar));
                objComando.Parameters.Add(new SqlParameter("nom", SqlDbType.VarChar));
                objComando.Parameters.Add(new SqlParameter("est", SqlDbType.VarChar));
                objComando.Parameters["d"].Value   = objE.Dni;
                objComando.Parameters["nom"].Value = objE.Nombres.ToUpper();
                objComando.Parameters["est"].Value = objE.Estado;
                objComando.Connection = objConexion.conectar();
                objComando.ExecuteNonQuery();
                return(true);
            }
            catch (Exception ex)
            {
                return(false);

                throw ex;
            }
        }