private void button2_Click(object sender, EventArgs e) { Int16 i = 0; ListViewItem[] temp = new ListViewItem[6]; ListViewItem tempItem = new ListViewItem(); Boolean UserNameExists = false; while (i < listView1.Items.Count) { if (textUserName.Text == listView1.Items[i].Text) UserNameExists = true; i++; } if (UserNameExists == false) { MessageBox.Show("Please select valid user name.", "Invalid User"); return; } string passwrr = "", divis = "", rights = ""; foreach (ListViewItem item in listView1.Items) { if (item.Text == textUserName.Text) { passwrr = item.SubItems[1].Text; divis = item.SubItems[2].Text; rights = item.SubItems[3].Text; } } if (textPassword.Text == passwrr) { GlobalProperties.LoggedOnUser = textUserName.Text; GlobalProperties.LoggedOnUserDivision = divis; GlobalProperties.LoggedOnUserRights = rights; GlobalProperties.loggedOnUserDivisionAbrev = divis; GlobalProperties.adminOverride = false; clsFunctions.WriteLog("User Log On - (" + GlobalProperties.loggedOnUser + " - " + GlobalProperties.loggedOnUserDivison + ")LADplus"); frmMainRibbon tmpMain = new frmMainRibbon(); tmpMain.Show(); Hide(); } else { MessageBox.Show("Invalid password. \nPlease enter correct password.\nContact your network administrator for more details.", "Invalid Password"); clsFunctions.WriteLog("Attempted User Logon (" + textUserName.Text + ")"); } }
private void simpleButton2_Click(object sender, EventArgs e) { ListViewItem[] temp = new ListViewItem[6]; var listViewItems = listView1.Items.OfType<ListViewItem>(); ListViewItem tempItem = new ListViewItem(); var listItem = listViewItems.FirstOrDefault(item => item.Text == textUserName.Text); var userNameExists = listItem != null; if (userNameExists == false) { MessageBox.Show("Please select valid user name.", "Invalid User"); return; } var passwrr = listItem.SubItems[1].Text; var divis = listItem.SubItems[2].Text; var rights = listItem.SubItems[3].Text; if (textPassword.Text == passwrr) { GlobalProperties.LoggedOnUser = textUserName.Text; GlobalProperties.LoggedOnUserDivision = divis; GlobalProperties.LoggedOnUserRights = rights; GlobalProperties.loggedOnUserDivisionAbrev = divis; GlobalProperties.adminOverride = false; var userDiv = GlobalProperties.LoggedOnUserDivision; clsFunctions.WriteLog("User Log On - (" + GlobalProperties.loggedOnUser + " - " + GlobalProperties.loggedOnUserDivison + ")"); frmMainRibbon tmpMain = new frmMainRibbon(); tmpMain.Show(); Hide(); } else { MessageBox.Show("Invalid password. \nPlease enter correct password.\nContact your network administrator for more details.", "Invalid Password"); clsFunctions.WriteLog("Attempted User Logon (" + textUserName.Text + ")"); } }