0% found this document useful (0 votes)
16 views4 pages

dataentryform

dataentry

Uploaded by

missyveloria
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views4 pages

dataentryform

dataentry

Uploaded by

missyveloria
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 4

using MySqlX.XDevAPI.

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;

lblSearch.Enabled = status.Substring(7, 1).Equals("T") ? true : false;


txtSearch.Enabled = status.Substring(7, 1).Equals("T") ? true : false;
}

private void txtClear()


{
txtID.Clear();
txtLname.Clear();
txtFname.Clear();
txtMname.Clear();
txtAddress.Clear();
cmbCourse.SelectedIndex = -1;
cmbYear.SelectedIndex = -1;
}

private void loadRecords()


{
searchFilter = "Student_LName LIKE '" + txtSearch.Text.Replace("'",
"\\'") + "%'";
gridView.DataSource = db.ViewRecords("*", "student", searchFilter ,"
Order By Student_LName,Student_FName,Student_MName ASC");

if (gridView.RowCount > 0)
{
buttons("TTTFFF_T");
}
else
{
if(txtSearch.TextLength>0) buttons("TFFFFF_T");
else buttons("TFFFFF_F");
}
}

private String isEntryError()


{
string errorMsg="";

if (txtID.Text.Trim().Length == 0) errorMsg = errorMsg + "ID is


required.\n";
if (txtLname.Text.Trim().Length == 0) errorMsg = errorMsg + "Lastname
is required.\n";
if (txtFname.Text.Trim().Length == 0) errorMsg = errorMsg + "Firstname
is required.\n";
if (txtMname.Text.Trim().Length == 0) errorMsg = errorMsg + "Middlename
is required.\n";
if (cmbCourse.Text.Trim().Length == 0) errorMsg = errorMsg + "Course is
required.\n";
if (cmbYear.Text.Trim().Length == 0) errorMsg = errorMsg + "Year is
required.\n";
if (db.RecExist("student","Student_ID='"+txtID.Text + "'")) errorMsg =
errorMsg + "ID number already exist.\n";
if (db.RecExist("student", "Student_LName='" +
txtLname.Text.Replace("'", "\\'") + "' and Student_FName='" +txtFname.Text + "' and
Student_MName='"+ txtMname.Text.Replace("'", "\\'") + "'")) errorMsg = errorMsg +
"Student name already exist.\n";

return errorMsg;
}
//===========================================================

private void FrmStudent1_Load(object sender, EventArgs e)


{
loadRecords();
}

private void btnAdd_Click(object sender, EventArgs e)


{
tabControl1.SelectedIndex = 1;
gridView.Enabled = false;
panelEntry.Enabled = true;
buttons("FFFTFT_F");
txtClear();
}

private void btnEdit_Click(object sender, EventArgs e)


{
tabControl1.SelectedIndex = 1;
gridView.Enabled = false;
panelEntry.Enabled = true;
buttons("FFFFTT_F");
txtClear();

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();
}

private void btnDelete_Click(object sender, EventArgs e)


{
if (MessageBox.Show("Are you sure to delete the selected record?",
"Delete",
MessageBoxButtons.YesNo,
MessageBoxIcon.Warning) == DialogResult.Yes)
{
int deleteResult = db.DeleteRecord("student", "Student_ID='" +
gridView[0, gridView.CurrentRow.Index].Value.ToString() + "'");
loadRecords();
}
}

private void btnSave_Click(object sender, EventArgs e)


{
if(isEntryError().Length > 0)
{
MessageBox.Show("The following error occured:\n\n" +
isEntryError(),
"Data Entry",
MessageBoxButtons.OK,
MessageBoxIcon.Stop
);
return;
}

int addResult = db.AddRecord("student",

"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();
}

private void btnCancel_Click(object sender, EventArgs e)


{
tabControl1.SelectedIndex = 0;
gridView.Enabled = true;
panelEntry.Enabled = false;
txtClear();
loadRecords();
}

private void txtSearch_TextChanged(object sender, EventArgs e)


{
loadRecords();
}
}
}

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy