public ClsUserManageData getSingleUserData(int userId) { ClsUserManageData userData = new ClsUserManageData(); try { string querry = "SELECT * FROM tbl_userdetail u LEFT JOIN tbl_userrole r ON u.roleId = r.userRoleId WHERE userId = '" + userId + "'; "; DataTable dt = new DataTable(); dt = CONN.getDataTable(querry); if (dt.Rows.Count > 0) { userData._userId = Convert.ToInt16(dt.Rows[0]["userId"].ToString()); userData._userName = dt.Rows[0]["userName"].ToString(); userData._firstName = dt.Rows[0]["firstName"].ToString(); userData._lastName = dt.Rows[0]["lastName"].ToString(); userData._dob = Convert.ToDateTime(dt.Rows[0]["dob"].ToString()); userData._idNumber = dt.Rows[0]["NIC"].ToString(); userData._address = dt.Rows[0]["address"].ToString(); userData._email = dt.Rows[0]["email"].ToString(); userData._roleId = Convert.ToInt16(dt.Rows[0]["roleId"].ToString()); userData._phoneNo = dt.Rows[0]["phoneNo"].ToString(); userData._userRole = dt.Rows[0]["userRoleName"].ToString(); } } catch (Exception ex) { throw ex; } return(userData); }
public bool updateData_userDetail(ClsUserManageData UserData) { bool ret = false; try { string updateUserDetail = string.Empty; updateUserDetail = "UPDATE tbl_userdetail SET "; updateUserDetail += "firstName = '" + UserData._firstName + "',"; updateUserDetail += "lastName = '" + UserData._lastName + "',"; updateUserDetail += "dob = '" + UserData._dob + "',"; updateUserDetail += "NIC = '" + UserData._idNumber + "',"; updateUserDetail += "address ='" + UserData._address + "',"; updateUserDetail += "email = '" + UserData._email + "',"; updateUserDetail += "roleId = '" + UserData._roleId + "',"; updateUserDetail += "phoneNo = '" + UserData._phoneNo + "'"; updateUserDetail += "WHERE userId = '" + UserData._userId + "';"; ret = CONN.update(updateUserDetail); } catch (Exception ex) { throw ex; } return(ret); }
/// <summary> /// load when create user /// </summary> public FrmCreateUser(string userName) { COM_MESSAGE = new CommonControls.Classes.ClsMessages(); VALIDATION = new CommonControls.Classes.ClsValidation(); COMM_METHODS = new CommonControls.Classes.ClsCommonMethods(); CREATEUSER = new BLL.ClsUserManageData(); MANAGEDB = new BLL.ClsUserManageDbChanges(); InitializeComponent(); txt_userID.Text = MANAGEDB.getMaxUserID().ToString(); //fill data of user role from db dropDown_userRole.DataSource = MANAGEDB.getUserRoleList(); dropDown_userRole.DisplayMember = "userRoleName"; dropDown_userRole.ValueMember = "userRoleId"; dropDown_userRole.BindingContext = this.BindingContext; dropDown_userRole.SelectedIndex = -1; btn_create.Visible = true; btn_update.Visible = false; btn_delete.Visible = false; btn_resetPass.Visible = false; USERNAME = userName; this.ActiveControl = txt_userName; }
public bool InsertData_userDetail(ClsUserManageData UserData) { bool ret = false; string insertToUserDetail = string.Empty; string insertToLogin = string.Empty; try { //create querry for tbl_userdetail insertToUserDetail = "INSERT INTO tbl_userdetail ( userId, userName, firstName, lastName, dob, NIC, address, email, roleId, phoneNo ) VALUES ( "; insertToUserDetail += "'" + UserData._userId + "',"; insertToUserDetail += "'" + UserData._userName + "',"; insertToUserDetail += "'" + UserData._firstName + "',"; insertToUserDetail += "'" + UserData._lastName + "',"; insertToUserDetail += "'" + UserData._dob + "',"; insertToUserDetail += "'" + UserData._idNumber + "',"; insertToUserDetail += "'" + UserData._address + "',"; insertToUserDetail += "'" + UserData._email + "',"; insertToUserDetail += "'" + UserData._roleId + "',"; insertToUserDetail += "'" + UserData._phoneNo; insertToUserDetail += "');"; //create querry for tbl_login insertToLogin = "******"; insertToLogin += "'" + UserData._userName + "',"; insertToLogin += "'" + COMMON.EncodePassword(UserData._userName) + "',"; insertToLogin += "'" + UserData._userId + "',"; insertToLogin += "'" + UserData._roleId; insertToLogin += "');"; if (CONN.update(insertToUserDetail)) { if (CONN.update(insertToLogin)) { ret = true; } } } catch (Exception e) { ret = false; throw e; } return(ret); }
/// <summary> /// load when edit user /// </summary> /// <param name="singleUserDetails"></param> public FrmCreateUser(BLL.ClsUserManageData singleUserDetails, string userName) { COM_MESSAGE = new CommonControls.Classes.ClsMessages(); VALIDATION = new CommonControls.Classes.ClsValidation(); COMM_METHODS = new CommonControls.Classes.ClsCommonMethods(); CREATEUSER = new BLL.ClsUserManageData(); MANAGEDB = new BLL.ClsUserManageDbChanges(); InitializeComponent(); txt_userID.Text = singleUserDetails._userId.ToString(); txt_userName.Text = singleUserDetails._userName; txt_firstName.Text = singleUserDetails._firstName; txt_lastName.Text = singleUserDetails._lastName; txt_dob.Text = singleUserDetails._dob.ToString("yyyy/MM/dd"); txt_email.Text = singleUserDetails._email; txt_address.Text = singleUserDetails._address; txt_nic.Text = singleUserDetails._idNumber; txt_phoneNumber.Text = singleUserDetails._phoneNo.ToString(); txt_userName.Enabled = false; dropDown_userRole.DataSource = MANAGEDB.getUserRoleList(); dropDown_userRole.DisplayMember = "userRoleName"; dropDown_userRole.ValueMember = "userRoleId"; dropDown_userRole.BindingContext = this.BindingContext; dropDown_userRole.SelectedIndex = dropDown_userRole.FindString(singleUserDetails._userRole); //singleUserDetails._roleId; btn_create.Visible = false; btn_update.Visible = true; btn_delete.Visible = true; btn_resetPass.Visible = true; IS_UPDATING = true; USERNAME = userName; this.ActiveControl = txt_firstName; }