dataentryform
dataentryform
Common;
using MySqlX.XDevAPI.Relational;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace DataBaseApp
{
public partial class FrmStudent1 : Form
{
MyDBase db; //for database transaction
String searchFilter = "";
public FrmStudent1()
{
InitializeComponent();
db = new MyDBase();
}
//======================================================
private void buttons(string status)
{
btnAdd.Enabled = status.Substring(0, 1).Equals("T") ? true : false;
btnEdit.Enabled = status.Substring(1, 1).Equals("T") ? true : false;
btnDelete.Enabled = status.Substring(2, 1).Equals("T") ? true : false;
btnSave.Enabled = status.Substring(3, 1).Equals("T") ? true : false;
btnUpdate.Enabled = status.Substring(4, 1).Equals("T") ? true : false;
btnCancel.Enabled = status.Substring(5, 1).Equals("T") ? true : false;
if (gridView.RowCount > 0)
{
buttons("TTTFFF_T");
}
else
{
if(txtSearch.TextLength>0) buttons("TFFFFF_T");
else buttons("TFFFFF_F");
}
}
return errorMsg;
}
//===========================================================
int r = gridView.CurrentRow.Index;
txtID.Text = gridView[0, r].Value.ToString();
txtLname.Text = gridView[1, r].Value.ToString();
txtFname.Text = gridView[2, r].Value.ToString();
txtMname.Text = gridView[3, r].Value.ToString();
txtAddress.Text = gridView[4, r].Value.ToString();
cmbCourse.Text = gridView[5, r].Value.ToString();
cmbYear.Text = gridView[6, r].Value.ToString();
}
"Student_ID,Student_LName,Student_FName,Student_MName,Student_Address,Student_Cours
e,Student_Year",
"'" + txtID.Text + "'," +
"'" + txtLname.Text.Replace("'", "\\'") +
"'," +
"'" + txtFname.Text.Replace("'", "\\'") +
"'," +
"'" + txtMname.Text.Replace("'", "\\'") +
"'," +
"'" + txtAddress.Text.Replace("'", "\\'")
+ "'," +
"'" + cmbCourse.Text + "'," +
"'" + cmbYear.Text + "'");
tabControl1.SelectedIndex = 0;
gridView.Enabled = true;
panelEntry.Enabled = false;
txtClear();
loadRecords();
}
private void btnUpdate_Click(object sender, EventArgs e)
{
int addResult = db.EditRecord("student",
"Student_ID='" + txtID.Text + "'," +
"Student_LName='" +
txtLname.Text.Replace("'", "\\'") + "'," +
"Student_FName='" + txtFname.Text + "'," +
"Student_MName='" +
txtMname.Text.Replace("'", "\\'") + "'," +
"Student_Address='" +
txtAddress.Text.Replace("'", "\\'") + "'," +
"Student_Course='" + cmbCourse.Text + "',"
+
"Student_Year='" + cmbYear.Text + "'",
"Student_ID='" + gridView[0,
gridView.CurrentRow.Index].Value.ToString() + "'");
tabControl1.SelectedIndex = 0;
gridView.Enabled = true;
panelEntry.Enabled = false;
txtClear();
loadRecords();
}