//AT LEAST ONE USER EXIST OR NOT CHECK private void LoginUserAllAvailableCheck() { try { objUserLogic = new UserClassBLL(); DataSet ds = new DataSet(); ds = (DataSet)objUserLogic.CurrentUser(lblUserProfile.Text); string secQue = ds.Tables["Table_User"].Rows[0].Field <string>("sec_question"); string secAns = ds.Tables["Table_User"].Rows[0].Field <string>("sec_answer"); string mobile = ds.Tables["Table_User"].Rows[0].Field <string>("mobile"); string division = ds.Tables["Table_User"].Rows[0].Field <string>("division"); lblCommenDetails.Text = division;//CURRENT USER DIVISION if (string.IsNullOrEmpty(secQue) || string.IsNullOrEmpty(secAns) || string.IsNullOrEmpty(mobile) || string.IsNullOrEmpty(division)) { frmUser frmUs = new frmUser(); frmUs.ShowDialog(); MessageBox.Show("You must filling all of details.", "User Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } //SET CURRENT USERNAME AND DIVISION //objUcSurveyor = new ucSurveyor(); //objUcSurveyor.PassValue(lblUserProfile.Text, division); } catch (Exception ex) { MessageBox.Show(ex.Message, "User Login Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
//SAVE USER DATA private void UserDataSave() { try { if (//CHECK TEXBOXES NOT NULL OR EMPTY String.IsNullOrWhiteSpace(txtUsername.Text) || String.IsNullOrWhiteSpace(cbxType.Text) || String.IsNullOrWhiteSpace(txtPass.Text) || String.IsNullOrWhiteSpace(txtConfirmPass.Text) || String.IsNullOrWhiteSpace(cbxSecQue.Text) || String.IsNullOrWhiteSpace(txtSecAns.Text) || String.IsNullOrWhiteSpace(txtEmail.Text) || String.IsNullOrWhiteSpace(txtMobile.Text) || String.IsNullOrWhiteSpace(cbxDivision.Text) ) { MessageBox.Show("You must be filling all field!.", "User Registration", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { if (objUserLogic.NewUserCheck(txtUsername.Text, cbxDivision.Text) == false) { //PROPERTIES FOR DATA ADD objUserLogic = new UserClassBLL() { username = txtUsername.Text, userType = cbxType.Text.ToString(), password = txtPass.Text, secQue = cbxSecQue.Text.ToString(), secAns = txtSecAns.Text, mobile = txtMobile.Text, email = txtEmail.Text, division = cbxDivision.Text }; //INSERT DATA TO DATABASE objUserLogic.AddNewUser(); MessageBox.Show("User registration successfully!", "User Registration", MessageBoxButtons.OK, MessageBoxIcon.Information); //CLEAR ALL TEXBOX AND COMBOBOX ClearTextBoxces(); //LOAD USER DATA LoadDataDgv(); //SET TO BUTTON TEXT Add btnAdd.Text = "Add"; } else { MessageBox.Show("Already exist this user!", "User Registration", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } catch (Exception ex) { MessageBox.Show(ex.Message, "USER ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
//UPDATE USER DATA private void UserDataUpadate() { try { if (//CHECK TEXBOXES NOT NULL OR EMPTY String.IsNullOrWhiteSpace(txtUsername.Text) || String.IsNullOrWhiteSpace(cbxType.Text) || String.IsNullOrWhiteSpace(txtPass.Text) || String.IsNullOrWhiteSpace(txtConfirmPass.Text) || String.IsNullOrWhiteSpace(cbxSecQue.Text) || String.IsNullOrWhiteSpace(txtSecAns.Text) || String.IsNullOrWhiteSpace(txtEmail.Text) || String.IsNullOrWhiteSpace(txtMobile.Text) || String.IsNullOrWhiteSpace(cbxDivision.Text) ) { MessageBox.Show("You must be filling all field!.", "User Registration", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { objUserLogic = new UserClassBLL() { username = txtUsername.Text, userType = cbxType.Text, password = txtPass.Text, secQue = cbxSecQue.Text, secAns = txtSecAns.Text, mobile = txtMobile.Text, email = txtEmail.Text, division = cbxDivision.Text }; //UPDATE USER DATA objUserLogic.UpdateUser(); MessageBox.Show("User Update successfully!", "User Update", MessageBoxButtons.OK, MessageBoxIcon.Information); //CLEAR ALL TEXBOX AND COMBOBOX ClearTextBoxces(); //LOAD USER DATA LoadDataDgv(); //SET TO BUTTON TEXT Add btnAdd.Text = "Add"; //TEXTBOX ENABLE txtUsername.Enabled = true; cbxDivision.Enabled = true; } } catch (Exception ex) { MessageBox.Show(ex.Message, "USER ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void frmUser_Load(object sender, EventArgs e) { txtUsername.Enabled = true; //ENABLE TEXTBOX AFTER DATAGRIDVIEW ROW DOUBLE CLICK cbxDivision.Enabled = true; btnAdd.Text = "Add"; //TEXTBOX DEFAULT TEXT SET AFTER DATAGRIDVIEW ROW DOUBLE CLICK LoadDataDgv(); //LOAD USER DATA DataGrdViewDesign(); //DATAGRIDVIEW DESIGN //LOAD DIVISION DATA TO COMBO BOX objUserLogic = new UserClassBLL(); cbxDivision.DataSource = objUserLogic.LoadDivisioToCbx(); }
//IF NOT USER OPEN USER REGISTERATION WINDOW private void UserNotExist() { try { objUserLogic = new UserClassBLL(); DataSet ds = new DataSet(); ds = (DataSet)objUserLogic.LoadUserData(); DataTable dt = ds.Tables["Table_User"]; if (dt.Rows.Count == 0) { frmUser frmObjUser = new frmUser(); frmObjUser.ShowDialog(); } } catch (Exception ex) { MessageBox.Show(ex.Message, "User Login Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
//LOGIN USER PROFILE DETAILS public void UserProfileDetails() { try { objUserLogic = new UserClassBLL(); DataSet ds = new DataSet(); ds = (DataSet)objUserLogic.CurrentUser(loginUser); lblUsernameTop.Text = lblUsername.Text = loginUser; lblType.Text = ds.Tables["Table_User"].Rows[0].Field <string>("user_type"); lblDivision.Text = lblDivisionTop.Text = ds.Tables["Table_User"].Rows[0].Field <string>("division"); lblMobile.Text = ds.Tables["Table_User"].Rows[0].Field <string>("mobile"); lblEmail.Text = ds.Tables["Table_User"].Rows[0].Field <string>("email"); } catch (Exception ex) { MessageBox.Show(ex.Message, "USER ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void btnLogIn_Click(object sender, EventArgs e) { try { objUserLogic = new UserClassBLL(); DataSet ds = new DataSet(); ds = (DataSet)objUserLogic.CurrentUser(txtUsename.Text); //CHECK USER EXIST OR NOT (USING LINQ) DataTable dt = ds.Tables["Table_User"]; DataColumn[] usernameCol = dt.Columns.Cast <DataColumn>().ToArray(); bool checkUserExist = dt.AsEnumerable().Any(row => usernameCol.Any(col => row[col].ToString() == txtUsename.Text)); //CHECK USER EXIST OR NOT if (checkUserExist) { //AVAILABLE USERNAME & PASSWORD GET string username = ds.Tables["Table_User"].Rows[0].Field <string>("username"); string password = ds.Tables["Table_User"].Rows[0].Field <string>("password"); //CHECK USERNAME & PASSWORD ARE EQUAL if (username.Equals(txtUsename.Text) && password.Equals(txtPassword.Text)) { //RUNNING BACKGROUNDWORKER AND STARTING PROCESS COUNTING PRECENTAGE backgroundWorker1.RunWorkerAsync(); btnLogIn.Enabled = false; llblFogotPass.Enabled = false; } else { MessageBox.Show("Login Fail, Please check again password!", "User Login Error", MessageBoxButtons.OK, MessageBoxIcon.Error); PlaceHolderUser(); } } else { MessageBox.Show("User not exist, Please check again username!", "User Login Error", MessageBoxButtons.OK, MessageBoxIcon.Error); PlaceHolderUser(); } } catch (Exception ex) { MessageBox.Show(ex.Message, "User Login Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
//RECOVERY USER PASSWORD private void Recovery() { try { objUserLogic = new UserClassBLL(); DataSet ds = new DataSet(); ds = (DataSet)objUserLogic.CurrentUser(txtUsername.Text); DataTable dt = ds.Tables["Table_User"]; DataColumn[] usernameCol = dt.Columns.Cast<DataColumn>().ToArray(); bool checkUserExist = dt.AsEnumerable().Any(row => usernameCol.Any(col => row[col].ToString() == txtUsername.Text)); //CHECK USER EXIST OR NOT if (checkUserExist) { string secQue = ds.Tables["Table_User"].Rows[0].Field<string>("sec_question"); string secAns = ds.Tables["Table_User"].Rows[0].Field<string>("sec_answer"); if (secQue.Equals(cbxSecQue.Text) && secAns.Equals(txtSecAns.Text)) { string password = ds.Tables["Table_User"].Rows[0].Field<string>("password"); MessageBox.Show("Your password is \"" + password + "\"", "Fogot Password", MessageBoxButtons.OK, MessageBoxIcon.Information); this.Close(); } else { MessageBox.Show("Wrong Answer or Security Question!", "Fogot Password", MessageBoxButtons.OK, MessageBoxIcon.Warning); Clear(); //CLEAR ALL TEXTBOX AND COMBO BOX } } else { MessageBox.Show("Wrong Username!", "Fogot Password", MessageBoxButtons.OK, MessageBoxIcon.Warning); Clear(); //CLEAR ALL TEXTBOX AND COMBO BOX } } catch (Exception ex) { MessageBox.Show(ex.Message, "Fogot Password", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
//LOAD USER DATA private void LoadDataDgv() { objUserLogic = new UserClassBLL(); dgvUser.DataSource = objUserLogic.LoadUserData(); dgvUser.DataMember = "Table_User"; }