private void btnthem_Click(object sender, EventArgs e) { if (txtmatkhau.Text != "" && txtmatkhau.Text != "" && (rdoadmin.Checked == true || rdonguoidung.Checked == true)) { Boolean r; if (rdoadmin.Checked) { r = true; } else { r = false; } DTO_Taikhoan ttk = new DTO_Taikhoan(tk.TaoMa(), txttaikhoan.Text, txtmatkhau.Text, r); if (tk.Them(ttk)) { MessageBox.Show("Thêm tài khoản thành công"); Fadmin_Load(sender, e); } else { MessageBox.Show("Không thành công"); } } else { MessageBox.Show("Nhập đủ thông tin"); } }
//lay 1 phan public DataTable GetTk(DTO_Taikhoan tk) { DataTable dt = new DataTable(); string gsome = "select * from TKDangnhap where [user]='" + tk.TK + "'and pass='******'"; dt = daotv.Query(gsome); return(dt); }
//sua public bool Sua(DTO_Taikhoan tk) { string ud = "update TKDangnhap set [user]='" + tk.TK + "',pass='******',quyen='" + tk.Quyen + "' where ID='" + tk.ID + "'"; if (daotv.NonQuery(ud)) { return(true); } return(false); }
//them public bool Them(DTO_Taikhoan tk) { string insert = string.Format("insert into TKDangnhap(ID,[user],pass,quyen) values('{0}','{1}','{2}','{3}')", tk.ID, tk.TK, tk.MK, tk.Quyen); if (daotv.NonQuery(insert)) { return(true); } return(false); }
private void btnxacnhan_Click(object sender, EventArgs e) { if (vitri >= 0 && vitri < dgvdktk.Rows.Count - 1) { string sdt = dgvdktk.Rows[vitri].Cells[1].Value.ToString(); string mk = dgvdktk.Rows[vitri].Cells[2].Value.ToString(); string ma = dgvdktk.Rows[vitri].Cells[0].Value.ToString(); bool q = false; DTO_Taikhoan tk = new DTO_Taikhoan(qltk.TaoMa(), sdt, mk, q); if (qldk.Xoa(ma) == true && qltk.Them(tk) == true) { MessageBox.Show("Xác nhận thành công."); Fqldangky_Load(sender, e); } else { MessageBox.Show("Không thành công."); } } }
public List <DTO_Taikhoan> GetData() { Connect(); List <DTO_Taikhoan> list = new List <DTO_Taikhoan>(); string sql = "SELECT Id, Username, Password, UserId FROM TaiKhoan"; try { SqlDataReader dr = ExecuteReader(sql); int id; string username; string password; int userid; while (dr.Read()) { id = dr.GetInt32(0); username = dr.GetString(1); password = dr.GetString(2); userid = dr.GetInt32(3); DTO_Taikhoan tk = new DTO_Taikhoan(id, username, password, userid); list.Add(tk); } dr.Close(); return(list); } catch (SqlException ex) { throw ex; } finally { Disconnect(); } }
private void btndangnhap_Click(object sender, EventArgs e) { if (txttk.Text != "" && txtmk.Text != "") { DTO_Taikhoan tk = new DTO_Taikhoan(txttk.Text, txtmk.Text); DataTable dt = new DataTable(); dt = dn.GetTk(tk); if (dt.Rows.Count > 0) { Boolean qq = Convert.ToBoolean(dt.Rows[0][3].ToString()); if (qq) { Fquantrivien fqtv = new Fquantrivien(); this.Hide(); fqtv.ShowDialog(); this.Show(); matk = dt.Rows[0][0].ToString(); } else { matk = dt.Rows[0][0].ToString(); Fabrv fab = new Fabrv(); this.Hide(); fab.ShowDialog(); this.Show(); } } else { MessageBox.Show("Sai tài khoản hoặc mật khẩu."); } } else { MessageBox.Show("Hãy nhập đủ thông tin."); } }
private void btnsua_Click(object sender, EventArgs e) { if (vitri >= 0 && vitri < dgvhienthitk.Rows.Count - 1) { if (txtmatkhau.Text != "" && txtmatkhau.Text != "" && (rdoadmin.Checked == true || rdonguoidung.Checked == true)) { Boolean r; if (rdoadmin.Checked) { r = true; } else { r = false; } DTO_Taikhoan ttk = new DTO_Taikhoan(txtid.Text, txttaikhoan.Text, txtmatkhau.Text, r); if (tk.Sua(ttk)) { MessageBox.Show("Sửa khoản thành công"); Fadmin_Load(sender, e); } else { MessageBox.Show("Không thành công"); } } else { MessageBox.Show("Nhập đủ thông tin"); } } else { MessageBox.Show("Chọn lại vị trí"); } }