private void button_LOGIN_Click(object sender, EventArgs e) { MY_DB db = new MY_DB(); STUDENT student = new STUDENT(); SqlDataAdapter da = new SqlDataAdapter(); DataTable dt = new DataTable(); SqlCommand cmd = new SqlCommand("select * from Login", db.getConnection); //cmd.Parameters.Add("@username", SqlDbType.VarChar).Value = txtUsername.Text; //cmd.Parameters.Add("@password", SqlDbType.VarChar).Value = txtPassword.Text; da.SelectCommand = cmd; da.Fill(dt); int count = dt.Rows.Count; if (count > 0) { for (int i = 0; i < count; i++) { if (txtUsername.Text == dt.Rows[i]["username"].ToString() && txtPassword.Text == dt.Rows[i]["password"].ToString()) { this.DialogResult = DialogResult.OK; } } if (this.DialogResult != DialogResult.OK) { MessageBox.Show("Invalid Username or Password", "Login error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
private void StaticForm_Load(object sender, EventArgs e) { panTotalColor = PanelTotal.BackColor; panMaleColor = PanelMale.BackColor; panFemaleColor = PanelFemale.BackColor; STUDENT student = new STUDENT(); double total = Convert.ToDouble(student.totalStudent()); double totalMale = Convert.ToDouble(student.totalMaleStudent()); double totalFemale = Convert.ToDouble(student.totalFemaleStudent()); double maleStudentsPercentage = (totalMale * (100 / total)); double femaleStudentsPercentage = (totalFemale * (100 / total)); LabelTotal.Text = ("Total Students: " + total.ToString()); LabelMale.Text = ("Male: " + maleStudentsPercentage.ToString("0.00") + "%"); LabelFemale.Text = ("Female: " + femaleStudentsPercentage.ToString("0.00") + "%"); }
private void ButtonAddStudent_Click(object sender, EventArgs e) { STUDENT student = new STUDENT(); int id = Convert.ToInt32(txtStudentID.Text); string fname = TextBoxFname.Text; string lname = TextBoxLname.Text; DateTime bday = DateTimePicker1.Value; string phone = TextBoxPhone.Text; string addr = TextBoxAddress.Text; string gender = "Male"; if (RadioButtonFemale.Checked) { gender = "Female"; } MemoryStream pic = new MemoryStream(); int bornyear = DateTimePicker1.Value.Year; int thisyear = DateTime.Now.Year; //sinh viên từ 10 - 100 có thể thay đổi if (((thisyear - bornyear) < 10) || ((thisyear - bornyear) > 100)) { MessageBox.Show("The student age must be between 10 and 100 year", "Invalid Birth Date", MessageBoxButtons.OK, MessageBoxIcon.Error); } else if (verif()) { PictureBoxStudentImage.Image.Save(pic, PictureBoxStudentImage.Image.RawFormat); if (student.insertStudent(id, fname, lname, bday, gender, phone, addr, pic)) { MessageBox.Show("New student added", "Add student", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show("Error", "Add student", MessageBoxButtons.OK, MessageBoxIcon.Error); } } else { MessageBox.Show("Empty fields", "Add student", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } }