2024-02-13 13:30:17 -05:00
|
|
|
|
using System;
|
|
|
|
|
using System.Data;
|
|
|
|
|
using System.Drawing;
|
|
|
|
|
using System.Windows.Forms;
|
2024-02-14 09:26:08 -05:00
|
|
|
|
|
2024-02-13 14:30:26 -05:00
|
|
|
|
|
2024-02-13 13:30:17 -05:00
|
|
|
|
|
|
|
|
|
namespace Database3
|
|
|
|
|
{
|
|
|
|
|
public partial class frmSearch : Form
|
|
|
|
|
{
|
2024-02-14 10:41:28 -05:00
|
|
|
|
|
|
|
|
|
public static string myID = "";
|
|
|
|
|
|
2024-02-13 13:30:17 -05:00
|
|
|
|
public frmSearch()
|
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
2024-02-14 10:41:28 -05:00
|
|
|
|
|
|
|
|
|
dgvStudents.DoubleClick += new EventHandler(dgvStudents_DoubleClick);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void dgvStudents_DoubleClick(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
string studentid = "";
|
|
|
|
|
|
|
|
|
|
if (dgvStudents.Rows.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
DataGridViewRow row = dgvStudents.SelectedRows[0];
|
|
|
|
|
frmEdit aform = new frmEdit();
|
|
|
|
|
|
|
|
|
|
studentid = row.Cells[0].Value.ToString().Trim();
|
|
|
|
|
myID = studentid;
|
|
|
|
|
aform.ShowDialog();
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2024-02-13 13:30:17 -05:00
|
|
|
|
}
|
2024-02-13 13:34:44 -05:00
|
|
|
|
|
|
|
|
|
private void btnSearch_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
2024-02-13 15:46:12 -05:00
|
|
|
|
string studentid = "9999999999";
|
|
|
|
|
string lname = "9999999999";
|
2024-02-14 09:26:08 -05:00
|
|
|
|
DateTime dob = new DateTime();
|
2024-02-13 16:59:13 -05:00
|
|
|
|
|
|
|
|
|
ErrorProvider ep1 = new ErrorProvider();
|
2024-02-13 15:46:12 -05:00
|
|
|
|
|
2024-02-13 14:30:26 -05:00
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
DataSet ds = new DataSet();
|
|
|
|
|
StudentDataTier stuDT = new StudentDataTier();
|
|
|
|
|
|
|
|
|
|
|
2024-02-13 15:46:12 -05:00
|
|
|
|
studentid = txtStuID.Text;
|
|
|
|
|
lname = txtlname.Text;
|
2024-02-13 16:59:13 -05:00
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
dob = DateTime.Parse(txtDOB.Text);
|
2024-02-13 14:30:26 -05:00
|
|
|
|
|
2024-02-13 15:46:12 -05:00
|
|
|
|
}
|
|
|
|
|
catch (Exception exception)
|
|
|
|
|
{
|
2024-02-13 16:59:13 -05:00
|
|
|
|
ep1.SetError(txtDOB, "Non valid value, but that's ok");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (string.IsNullOrWhiteSpace(txtStuID.Text) &&
|
|
|
|
|
string.IsNullOrWhiteSpace(txtlname.Text) &&
|
|
|
|
|
string.IsNullOrWhiteSpace(txtDOB.Text))
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("Must Enter at least one value");
|
2024-02-13 15:46:12 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Get the dataset using all three search parameters.
|
|
|
|
|
ds = stuDT.GetStudents(studentid, lname, dob);
|
|
|
|
|
|
|
|
|
|
// Check to see if any record is returned.
|
|
|
|
|
if (ds.Tables[0].Rows.Count > 0) // There is a record.
|
2024-02-13 14:30:26 -05:00
|
|
|
|
{
|
|
|
|
|
dgvStudents.Visible = true;
|
2024-02-13 15:46:12 -05:00
|
|
|
|
// Get data source.
|
2024-02-13 14:30:26 -05:00
|
|
|
|
dgvStudents.DataSource = ds.Tables[0];
|
|
|
|
|
dgvStudents.AlternatingRowsDefaultCellStyle.BackColor = Color.LightGreen;
|
|
|
|
|
|
|
|
|
|
// Set the row and column header styles.
|
|
|
|
|
dgvStudents.ColumnHeadersDefaultCellStyle.ForeColor = Color.White;
|
|
|
|
|
dgvStudents.ColumnHeadersDefaultCellStyle.BackColor = Color.Green;
|
|
|
|
|
}
|
2024-02-13 15:46:12 -05:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
dgvStudents.Visible = false; // Hide the DataGridView if no results are found.
|
|
|
|
|
MessageBox.Show("No records found.");
|
|
|
|
|
}
|
2024-02-13 14:30:26 -05:00
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
2024-02-13 15:46:12 -05:00
|
|
|
|
MessageBox.Show($"An error occurred: {ex.Message}");
|
2024-02-13 14:30:26 -05:00
|
|
|
|
}
|
2024-02-13 13:34:44 -05:00
|
|
|
|
}
|
2024-02-14 10:02:15 -05:00
|
|
|
|
|
|
|
|
|
private void frmSearch_Load(object sender, EventArgs e)
|
2024-02-14 10:41:28 -05:00
|
|
|
|
{
|
|
|
|
|
dgvStudents.Visible = false;
|
|
|
|
|
contextMenuStrip1.Items[1].Enabled = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void cmuSearch_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
btnSearch_Click(sender,e);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void txtStuID_TextChanged(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
cmuSearch.Enabled = txtStuID.Text.Length>0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void cmuEdit_Click(object sender, EventArgs e)
|
2024-02-14 10:02:15 -05:00
|
|
|
|
{
|
|
|
|
|
|
2024-02-13 15:46:12 -05:00
|
|
|
|
}
|
2024-02-14 10:02:15 -05:00
|
|
|
|
}
|
2024-02-13 14:30:26 -05:00
|
|
|
|
|
2024-02-13 13:30:17 -05:00
|
|
|
|
}
|