CNSA-212-Personal/Database3/frmSearch.cs

94 lines
2.8 KiB
C#
Raw Normal View History

2024-02-13 10:30:17 -08:00
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;
2024-02-13 11:30:26 -08:00
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.VisualBasic;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Data.SqlClient;
2024-02-13 12:46:12 -08:00
using Database3;
2024-02-13 11:30:26 -08:00
2024-02-13 10:30:17 -08:00
namespace Database3
{
public partial class frmSearch : Form
{
public frmSearch()
{
InitializeComponent();
}
2024-02-13 10:34:44 -08:00
private void btnSearch_Click(object sender, EventArgs e)
{
2024-02-13 12:46:12 -08:00
string studentid = "9999999999";
string lname = "9999999999";
2024-02-13 13:59:13 -08:00
DateTime dob = new DateTime(1/1/1111);
ErrorProvider ep1 = new ErrorProvider();
2024-02-13 12:46:12 -08:00
2024-02-13 11:30:26 -08:00
try
{
DataSet ds = new DataSet();
StudentDataTier stuDT = new StudentDataTier();
2024-02-13 12:46:12 -08:00
studentid = txtStuID.Text;
lname = txtlname.Text;
2024-02-13 13:59:13 -08:00
try
{
dob = DateTime.Parse(txtDOB.Text);
2024-02-13 11:30:26 -08:00
2024-02-13 12:46:12 -08:00
}
catch (Exception exception)
{
2024-02-13 13:59:13 -08: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 12:46:12 -08: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 11:30:26 -08:00
{
dgvStudents.Visible = true;
2024-02-13 12:46:12 -08:00
// Get data source.
2024-02-13 11:30:26 -08: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 12:46:12 -08:00
else
{
dgvStudents.Visible = false; // Hide the DataGridView if no results are found.
MessageBox.Show("No records found.");
}
2024-02-13 11:30:26 -08:00
}
catch (Exception ex)
{
2024-02-13 12:46:12 -08:00
MessageBox.Show($"An error occurred: {ex.Message}");
2024-02-13 11:30:26 -08:00
}
2024-02-13 10:34:44 -08:00
}
2024-02-13 12:46:12 -08:00
}
2024-02-13 11:30:26 -08:00
2024-02-13 10:30:17 -08:00
}