//search by c# private void txtScore_TextChanged(object sender, EventArgs e) { if (this.txtScore.Text.Trim().Length == 0) { return; } if (DataValidation.IsInteger(this.txtScore.Text.Trim())) { this.ds.Tables[0].DefaultView.RowFilter = "CSharp>" + this.txtScore.Text.Trim(); new DataGridViewStyle().DgvStyle1(this.dgvScoreList); } }
//Login private void btnLogin_Click(object sender, EventArgs e) { // data validation if (this.txtLoginId.Text.Trim().Length == 0) { MessageBox.Show("Please fill in login Id", "Warning"); this.txtLoginId.Focus(); return; } if (this.txtLoginPwd.Text.Trim().Length == 0) { MessageBox.Show("Please fill in login password", "Warning"); this.txtLoginPwd.Focus(); return; } if (!DataValidation.IsInteger(this.txtLoginId.Text.Trim())) { MessageBox.Show("The login Id must be an integer", "Warning"); this.txtLoginId.Focus(); return; } // instance of SysAdmin SysAdmin objAdmin = new SysAdmin() { LoginId = Convert.ToInt32(this.txtLoginId.Text.Trim()), LoginPwd = this.txtLoginPwd.Text.Trim() }; // database connection Program.currentAdmin = objAdminService.AdminLogin(objAdmin); try { if (Program.currentAdmin != null) { this.DialogResult = DialogResult.OK; this.Close(); } else { MessageBox.Show("LoginId or Password is incorrect", "Warning"); } } catch (Exception ex) { MessageBox.Show(ex.Message, "Database connection error"); } }
//add student private void btnAdd_Click(object sender, EventArgs e) { #region Data validation if (this.txtStudentName.Text.Trim().Length == 0) { MessageBox.Show("The Student Name can not be null", "Warning"); this.txtStudentName.Focus(); return; } if (!this.rdoFemale.Checked && !this.rdoMale.Checked) { MessageBox.Show("Please select Gender", "Warning"); this.rdoMale.Focus(); return; } int age = DateTime.Now.Year - Convert.ToDateTime(this.dtpBirthday.Text).Year; if (age < 18 || age > 35) { MessageBox.Show("The age should be between 18 and 35", "Warning"); this.dtpBirthday.Focus(); return; } if (this.cboClassName.SelectedIndex == -1) { MessageBox.Show("Plesas select Class Name"); this.cboClassName.Focus(); return; } if (this.txtStudentIdNo.Text.Trim().Length == 0) { MessageBox.Show("Please fill in Student id no card", "Warning"); this.txtStudentIdNo.Focus(); return; } if (this.txtCardNo.Text.Trim().Length == 0) { MessageBox.Show("Please fill in Attendance Card No", "Warning"); this.txtCardNo.Focus(); return; } if (this.txtPhoneNumber.Text.Trim().Length == 0) { MessageBox.Show("Please fill in phone number", "Warning"); this.txtPhoneNumber.Focus(); return; } if (this.txtAddress.Text.Trim().Length == 0) { MessageBox.Show("Please fill in address", "Warning"); this.txtAddress.Focus(); return; } if (!DataValidation.IsIdentityCard(this.txtStudentIdNo.Text.Trim())) { MessageBox.Show("The Student Id No format is incorrect", "Warning"); this.txtStudentIdNo.Focus(); return; } string birthday = Convert.ToDateTime(this.dtpBirthday.Text.Trim()).ToString("yyyyMMdd"); if (!this.txtStudentIdNo.Text.Trim().Contains(birthday)) { MessageBox.Show("The Birthday is not sams as The Student Id no format "); this.txtStudentIdNo.Focus(); return; } // check Student Id no if (objStuService.IsIdNoExisted(this.txtStudentIdNo.Text.Trim())) { MessageBox.Show("The StudentIdNo is exist,please check the Student Id No", "Warning"); this.txtStudentIdNo.Focus(); return; } // check Card No if (objStuService.IsCardNoExist(this.txtCardNo.Text.Trim())) { MessageBox.Show("The attendance card no is eixsted,please check Attendance Card No", "Warning"); this.txtCardNo.Focus(); return; } #endregion #region instializing Student object Student objStu = new Student() { StudentName = this.txtStudentName.Text.Trim(), Gender = this.rdoMale.Checked?"M":"F", Birthday = Convert.ToDateTime(this.dtpBirthday.Text.Trim()), StudentIdNo = this.txtStudentIdNo.Text.Trim(), CardNo = this.txtCardNo.Text.Trim(), Age = DateTime.Now.Year - Convert.ToDateTime(this.dtpBirthday.Text).Year, PhoneNumber = this.txtPhoneNumber.Text.Trim(), StudentAddress = this.txtAddress.Text.Trim(), ClassId = Convert.ToInt32(this.cboClassName.SelectedValue), StuImage = this.pbStu.Image != null? new SerializeObjectToString().SerializeObject(this.pbStu.Image):"", ClassName = this.cboClassName.Text.Trim() }; #endregion #region connecting database try { int studentId = objStuService.AddStudent(objStu); if (studentId > 1) { objStu.StudentId = studentId; this.stuList.Add(objStu); this.dgvStudentList.DataSource = null; this.dgvStudentList.DataSource = this.stuList; } // add more student validation DialogResult result = MessageBox.Show("Do you want to add more student?", "Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (result == DialogResult.Yes) { foreach (Control item in this.gbstuinfo.Controls) { if (item is TextBox) { item.Text = ""; } else if (item is CheckBox) { ((RadioButton)item).Checked = false; } } this.cboClassName.SelectedIndex = -1; this.pbStu.Image = null; this.txtStudentName.Focus(); } else { this.Close(); } } catch (Exception ex) { throw new Exception("Add Student Exception:" + ex.Message); } #endregion }