Sei sulla pagina 1di 4

using System;

using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.OleDb;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApplication3
{
public partial class Form1 : Form
{
OleDbDataReader rdr = null;

OleDbConnection con = null;


OleDbCommand cmd = null;

List<int> id_rubro = new List<int>();

String cs = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|


DataDirectory|\\1.accdb;";

public Form1()
{
InitializeComponent();
}

private void Form1_Load_1(object sender, EventArgs e)


{
Mostrarmanual();
}
private void btnguardar_Click(object sender, EventArgs e)
{
//en orden como la bd
try
{
con = new OleDbConnection(cs);
con.Open();

string cb = ("insert into


manual(material,cedula,nombredematerial,fechadenacimiento) VALUES ('" +
txtmaterial.Text + "','" + txtcedula.Text + "','" + txtnombredem.Text + "','" +
dtpfecha.Value.Date + "')");

cmd = new OleDbCommand(cb);

cmd.Connection = con;

cmd.ExecuteReader();
MessageBox.Show("Guardado Correctamente", "manual",
MessageBoxButtons.OK, MessageBoxIcon.Information);
Mostrarmanual();
if (con.State == ConnectionState.Open)
{
con.Close();
}

con.Close();

}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK,
MessageBoxIcon.Error);
}

}
public void Mostrarmanual()
{
//en orden
try
{
con = new OleDbConnection(cs);
con.Open();
cmd = new OleDbCommand("SELECT (material)as [material],(cedula)as
[cedula],(nombredematerial) as [nombredematerial],(fechadenacimiento) as
[fechadenacimiento] from manual order by material", con);

OleDbDataAdapter myDA = new OleDbDataAdapter(cmd);


DataSet myDataSet = new DataSet();
myDA.Fill(myDataSet, "manual");
dtgmanual.DataSource = myDataSet.Tables["manual"].DefaultView;
//dataGridView1.DataSource =
myDataSet.Tables["Socios"].DefaultView;
con.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK,
MessageBoxIcon.Error);
}
}

private void btnmodificar_Click_1(object sender, EventArgs e)


{
try
{
con = new OleDbConnection(cs);
con.Open();

string otro = ("UPDATE manual SET manual.material = '" +


txtmaterial.Text + "', manual.cedula = '" + txtcedula.Text + "',
manual.nombredematerial = '" + txtnombredem.Text + "', manual.fechadenacimiento =
'" + dtpfecha.Value.Date + "' where cedula='" + txtcedula.Text + "'");
cmd = new OleDbCommand(otro);
cmd.Connection = con;
cmd.ExecuteReader();
MessageBox.Show("Actualizado Correctamente", "manual",
MessageBoxButtons.OK, MessageBoxIcon.Information);
if (con.State == ConnectionState.Open)
{
con.Close();
}

con.Close();

}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK,
MessageBoxIcon.Error);
}
Mostrarmanual();

}
}

//
salir

//
volver

Form fMenu = new Form1();


fMenu.Show();
Visible = false;
}

//
//solo letra codigo por asscii Y letra
if ((e.KeyChar >= 32 && e.KeyChar <= 64) || (e.KeyChar >= 91 &&
e.KeyChar <= 255))
{
MessageBox.Show("SOLO LETRAS MAYUSCULAS...", "ERROR",
MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
e.Handled = true;
return;

////solo numero codigo por asscii


//// solo letra codigo por asscii Y NUMERO
//if ((e.KeyChar >= 32 && e.KeyChar <= 47) || (e.KeyChar >= 58 &&
e.KeyChar <= 64) || (e.KeyChar >= 91 && e.KeyChar <= 255))

//{
// MessageBox.Show("SOLO NUMEROS DE 0 AL 9 Y LETRAS MAYUSCULAS",
"ERROR", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
// e.Handled = true;
// // return;
solo numero

//if ((e.KeyChar >= 32 && e.KeyChar <= 47) || (e.KeyChar >= 58 &&
e.KeyChar <= 255))

//{
// MessageBox.Show("SOLO NUMEROS DE 0 AL 9 ", "ERROR",
MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
// e.Handled = true;
// // return;
//}