Exemplo n.º 1
0
        private void btnSearch_Click(object sender, EventArgs e)
        {
            try
            {
                Cursor.Current = Cursors.WaitCursor;
                Student s = new Student();
                if (!txtSN.Text.Trim().Equals(""))
                {
                    dgvStudent.DataSource = s.SearchStudentsById(txtSN.Text.Trim());
                }
                else if (!txtLastName.Text.Trim().Equals(""))
                {
                    dgvStudent.DataSource = s.SearchStudentsByLastName(txtLastName.Text.Trim());
                }

                dgvStudent.Columns[0].Width = 120;
                dgvStudent.Columns[1].Width = 120;
                dgvStudent.Columns[2].Width = 120;
                dgvStudent.Columns[3].Width = 120;
                dgvStudent.Columns[4].Width = 75;
                dgvStudent.Columns[5].Width = 50;

                Cursor.Current = Cursors.Default;

                if (dgvStudent.Rows.Count == 0)
                {
                    throw new Exception("Student not found.");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Exemplo n.º 2
0
        private void btnSearch_Click(object sender, EventArgs e)
        {
            try
            {
                Cursor.Current        = Cursors.WaitCursor;
                txtBal.Text           = 0.ToString("N2");
                dgvBalance.DataSource = null;
                dgvBalance.Rows.Clear();

                Student s = new Student();
                if (!txtSN.Text.Trim().Equals(""))
                {
                    dgvStudent.DataSource = s.SearchStudentsById(txtSN.Text.Trim());
                }
                else if (!txtName.Text.Trim().Equals(""))
                {
                    dgvStudent.DataSource = s.SearchStudentsByLastName(txtName.Text.Trim());
                }

                dgvStudent.Columns[0].Width = 100;
                dgvStudent.Columns[1].Width = 200;
                dgvStudent.Columns[2].Width = 200;
                dgvStudent.Columns[3].Width = 200;
                dgvStudent.Columns[4].Width = 110;
                Cursor.Current = Cursors.Default;

                if (dgvStudent.Rows.Count > 0)
                {
                    scMain.Panel1Collapsed = false;
                }
                else
                {
                    throw new Exception("No record(s) found");
                }
            }
            catch (MySqlException ex)
            {
                if (ex.Number == 1042)
                {
                    MessageBox.Show("Database server is offline. Contact administrator.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                else
                {
                    MessageBox.Show(ex.Number + ": " + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }