public void insert(StudentDTO value) { string cmd = "SP_INS_SINHVIEN"; SqlCmd = new SqlCommand(cmd, SqlCon); SqlCmd.CommandType = CommandType.StoredProcedure; SqlParameter StudentID = new SqlParameter("@MASV", SqlDbType.NVarChar, 20, "MASV"); StudentID.IsNullable = false; StudentID.Direction = ParameterDirection.Input; StudentID.Value = value.StudentID; SqlCmd.Parameters.Add(StudentID); SqlParameter StudentName = new SqlParameter("@HOTEN", SqlDbType.NVarChar, 100, "HOTEN"); StudentName.IsNullable = false; StudentName.Direction = ParameterDirection.Input; StudentName.Value = value.StudentName; SqlCmd.Parameters.Add(StudentName); SqlParameter Birthday = new SqlParameter("@NGAYSINH", SqlDbType.Date, 3, "NGAYSINH"); Birthday.IsNullable = false; Birthday.Direction = ParameterDirection.Input; Birthday.Value = value.Birthday; SqlCmd.Parameters.Add(Birthday); SqlParameter Address = new SqlParameter("@DIACHI", SqlDbType.NVarChar, 200, "DIACHI"); Address.IsNullable = false; Address.Direction = ParameterDirection.Input; Address.Value = value.Address; SqlCmd.Parameters.Add(Address); SqlParameter ClassID = new SqlParameter("@MALOP", SqlDbType.VarChar, 20, "MALOP"); ClassID.IsNullable = false; ClassID.Direction = ParameterDirection.Input; ClassID.Value = value.ClassID; SqlCmd.Parameters.Add(ClassID); SqlParameter Username = new SqlParameter("@TENDN", SqlDbType.NVarChar, 100, "TENDN"); Username.IsNullable = false; Username.Direction = ParameterDirection.Input; Username.Value = value.Username; SqlCmd.Parameters.Add(Username); SqlParameter Password = new SqlParameter("@MATKHAU", SqlDbType.VarChar, 100, "MATKHAU"); Password.IsNullable = false; Password.Direction = ParameterDirection.Input; Password.Value = value.Password; SqlCmd.Parameters.Add(Password); this.executeNonQuery(); }
public override object convertOneRowIntoADTO(DataTable dt, int i, int type = 0) { StudentDTO obj = new StudentDTO(); if (type == 0) { obj.StudentID = dt.Rows[i]["MASV"].ToString(); obj.StudentName = dt.Rows[i]["HOTEN"].ToString(); obj.Birthday = DateTime.Parse(dt.Rows[i]["NGAYSINH"].ToString()); obj.Address = dt.Rows[i]["DIACHI"].ToString(); obj.ClassID = dt.Rows[i]["MALOP"].ToString(); obj.Username = dt.Rows[i]["TENDN"].ToString(); } else if (type == 1) { obj.StudentID = dt.Rows[i]["MASV"].ToString(); obj.Username = dt.Rows[i]["TENDN"].ToString(); obj.Password = Encoding.ASCII.GetString((byte[])dt.Rows[i]["MATKHAU"]); } return obj; }
public StudentDTO[] selectAll() { string cmd = "SELECT * FROM SINHVIEN"; SqlCmd = new SqlCommand(cmd, SqlCon); ArrayList list = this.executeQueryArrayList(0); int n = list.Count; StudentDTO[] result = new StudentDTO[n]; for (int i = 0; i < n; i++) result[i] = (StudentDTO)list[i]; return result; }
public StudentDTO login(string id, string pw) { StudentDTO student = new StudentDTO(); string cmd = "SP_CHK_LOGIN_SINHVIEN"; SqlCmd = new SqlCommand(cmd, SqlCon); SqlCmd.CommandType = CommandType.StoredProcedure; SqlParameter username = new SqlParameter("@TENDN", SqlDbType.NVarChar, 100, "TENDN"); username.IsNullable = false; username.Direction = ParameterDirection.Input; username.Value = id; SqlCmd.Parameters.Add(username); SqlParameter password = new SqlParameter("@MATKHAU", SqlDbType.NVarChar, 100, "MATKHAU"); password.IsNullable = false; password.Direction = ParameterDirection.Input; password.Value = pw; SqlCmd.Parameters.Add(password); ArrayList list = executeQueryArrayList(1); int n = list.Count; if (n == 0) return null; return (StudentDTO)list[0]; }
public void updateStudent(StudentDTO value) { studentdao.update(value); }
public void insertStudent(StudentDTO value) { studentdao.insert(value); }
private void button_Commit2_Click(object sender, EventArgs e) { StudentDTO studentdto = new StudentDTO(); studentdto.StudentID = textBox_StudentID2.Text; studentdto.StudentName = textBox_StudentName2.Text; studentdto.Birthday = DateTime.Parse(dateTimePicker_Birthday2.Value.ToShortDateString()); studentdto.Address = textBox_Address2.Text; studentdto.ClassID = textBox_ClassID2.Text; studentdto.Username = textBox_Username2.Text; studentdto.Password = textBox_Password2.Text; try { ClassDTO[] classlist = classbll.getClassByStaff(_staffdto.StaffID); int classsize = classlist.Length; string classid = studentdto.ClassID; int j; for (j = 0; j < classsize; j++) { if (classid == classlist[j].ClassID) { if (flag_student == 1) { _studentbll.insertStudent(studentdto); } else if (flag_student == 2) { _studentbll.updateStudent(studentdto); } break; } } if (j == classsize) MessageBox.Show("Bạn không có quyền thêm hoặc thay đổi thông tin sinh viên có mã số " + studentdto.StudentID, "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error); loadStudent(); flag_student = 0; textBox_StudentID2.Enabled = false; textBox_StudentName2.Enabled = false; dateTimePicker_Birthday2.Enabled = false; textBox_Address2.Enabled = false; textBox_ClassID2.Enabled = false; textBox_Username2.Enabled = false; textBox_Password2.Enabled = false; textBox_StudentID2.Text = ""; textBox_StudentName2.Text = ""; textBox_Address2.Text = ""; textBox_ClassID2.Text = ""; textBox_Username2.Text = ""; textBox_Password2.Text = ""; } catch (System.Exception ex) { MessageBox.Show(ex.Message, "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error); } }