Button Save
Assign values to the attributes of the _user class, then create a variable msg and this variable receives the value of the result of the process _metod.insertUpdate,
- private void btnSave_Click(object sender, System.EventArgs e)
- {
- _user.id = textBox1.Text;
- _user.name = textBox2.Text;
- _user.address = textBox3.Text;
- _user.status = textBox4.Text;
- string msg = _metod.insertUpdate(_user);
- if (msg == "0")
- {
- MessageBox.Show("Record added");
- cleanform();
- }
- else
- {
- MessageBox.Show(msg);
- }
-
- }
Button clean: we will only clean the textboxs form,
- private void btnClear_Click(object sender, System.EventArgs e)
- {
- cleanform();
- }
Delete button
This code deletes the record whose Id matches the value of the TextBox1 control,
- private void btnDelete_Click(object sender, System.EventArgs e)
- {
- _user.id = textBox1.Text;
- string msg = _metod.delete(_user);
- if (msg == "0")
- {
- MessageBox.Show("record deleted");
- cleanform();
- }
- else
- {
- MessageBox.Show(msg);
- }
- }
Search button
This button executes a record search based on the ID field written to the TextBox1 control
- private void btnFind_Click(object sender, System.EventArgs e)
- {
- if (textBox1.Text != "")
- {
-
- var items = _metod.findById (textBox1.Text);
- if (items != null)
- {
- textBox2.Text = items.name;
- textBox3.Text = items.address;
- textBox4.Text = items.status;
- }
- else
- {
- MessageBox.Show("Record not found");
- }
-
- }
- }
Populate Button
This button returns a list of class _user, and fills the grid. For this exercise columns were created in the grid, then the properties of the _user class are traversed and the Name value is assigned to the property of the dataGridView2.Columns [n] .DataPropertyName,
- private void btnPopulate_Click(object sender, System.EventArgs e)
- {
- List<ClassObjects.users> lista = _metod.allRecords(_user);
- dataGridView1.DataSource = lista;
- int i = 0;
- string xx = "";
- dataGridView2.AutoGenerateColumns = false;
- foreach (var prop in _user.GetType().GetProperties())
- {
- dataGridView2.Columns[i].DataPropertyName = prop.Name;
- i = i + 1;
- }
- dataGridView2.DataSource = lista;
- }
Populate Dynamics button
This button returns a dynamic list, so that you can fill the grid with the FG.ConvertToDataTable ()
- private void btnPopulateDyn_Click(object sender, System.EventArgs e)
- {
- Utilities.Funciones FG = new Utilities.Funciones();
- var items = _metod.dynamicsList();
- DataTable dt = new DataTable();
- dt = FG.ConvertToDataTable(items);
- dataGridView1.DataSource = dt;
-
-
- dataGridView2.AutoGenerateColumns = false;
- for (int i = 0; i < dt.Columns.Count - 1; i++)
- {
- dataGridView2.Columns[i].DataPropertyName = dt.Columns[i].ColumnName;
- }
- dataGridView2.DataSource = dt;
-
-
- }
I hope this small example will help your projects. I'm always attentive to your comments.