public Menu(int UserID) { Size MinButtonSize = new System.Drawing.Size(290, 30); InitializeComponent(); if (UserID <= 0) { Login l = new Login(); l.Show(); this.Hide(); } else { _userID = UserID; DB db = new DB(); db.AddParam("@UserID", UserID); DataTable dtMenu = db.SQLResults("usp_MenuGet"); foreach (DataRow dr in dtMenu.Rows) { Button btn = new Button(); btn.AutoSize = true; btn.BackColor = Color.Azure; btn.MinimumSize = MinButtonSize; btn.Text = dr["DisplayName"].ToString(); btn.Name = dr["MenuID"].ToString(); btn.Margin = new Padding(3,0,0,0); btn.Click += new EventHandler(btnMenu_Click); flpMenu.Controls.Add(btn); } } }
private void btnLogin_Click(object sender, EventArgs e) { if (txtUsername.Text.Trim().Length <= 0) { MessageBox.Show("Please enter a valid username."); txtUsername.Focus(); return; } else if (txtPassword.Text.Trim().Length <= 0) { MessageBox.Show("Please enter a valid password."); txtPassword.Focus(); return; } else { int UserID = 0; DB db = new DB(); try { db.AddParam("@Username", txtUsername.Text.Trim()); db.AddParam("@Password", BMan_Encryption.EncryptPassword(txtPassword.Text.Trim(), ConfigurationManager.AppSettings["EncKey"])); DataTable dtUser = db.SQLResults("usp_Login"); if (dtUser.Rows.Count > 0) { UserID = Convert.ToInt32(dtUser.Rows[0]["UserID"]); } } catch (Exception ex) { Common.LogError(ex, "Login.btnLogin_Click"); } finally { db.CleanUp(); } if (UserID > 0) { Menu m = new Menu(UserID); m.Show(); this.Hide(); } else { MessageBox.Show("Login or Password invalid. Please try again."); txtPassword.Text = ""; txtPassword.Focus(); return; } } }
protected void btnMenu_Click(object sender, EventArgs e) { DB db = new DB(); db.AddParam("@MenuID", ((Button)sender).Name); DataTable dt = db.SQLResults("usp_MenuGetByID"); Assembly assembly = Assembly.Load("IndianaWhiskey"); Type t = assembly.GetType("IndianaWhiskey." + dt.Rows[0]["FormName"].ToString()); Form frmNext = (Form)Activator.CreateInstance(t, _userID); frmNext.Show(this); this.Hide(); }
private string GetUserName(int userID) { string strUserName = ""; DB db = new DB(); db.AddParam("@UserID", userID); DataTable dt = db.SQLResults("usp_UserNameGet"); if (dt.Rows.Count >= 1 && dt.Rows[0]["UserName"] != null && dt.Rows[0]["UserName"] != DBNull.Value) strUserName = dt.Rows[0]["UserName"].ToString(); db.CleanUp(); return strUserName; }
public static void PopulateComboBox(string storedProc, ComboBox cbo, string colName, string colValue, List<SqlParameter> lstParams, BindingContext bindingContext) { if (cbo != null) { DB db = new DB(); if (lstParams != null) { foreach (SqlParameter p in lstParams) { db.AddParam(p.ParameterName, p.Value); } } DataTable dt = db.SQLResults(storedProc); cbo.DataSource = dt; cbo.DisplayMember = colName; cbo.ValueMember = colValue; cbo.BindingContext = bindingContext; } }
private void btnSave_Click(object sender, EventArgs e) { if (txtFirstName.Text.Trim().Length <= 0) { MessageBox.Show("Please enter a first name."); txtFirstName.Focus(); return; } else if (txtLastName.Text.Trim().Length <= 0) { MessageBox.Show("Please enter a last name."); txtLastName.Focus(); return; } else if (txtUsername.Text.Trim().Length <= 0) { MessageBox.Show("Please enter a username."); txtUsername.Focus(); return; } else if (txtPassword.Text.Trim().Length <= 0) { MessageBox.Show("Please enter a password."); txtPassword.Focus(); return; } else if (txtPasswordConfirm.Text.Trim().Length <= 0) { MessageBox.Show("Please confirm your password."); txtPasswordConfirm.Focus(); return; } else if (txtPassword.Text.Trim() != txtPasswordConfirm.Text.Trim()) { MessageBox.Show("Passwords do not match. Please try again."); txtPassword.Text = ""; txtPasswordConfirm.Text = ""; txtPassword.Focus(); return; } else if (cboUserType.SelectedIndex < 0) { MessageBox.Show("Please select a user type."); cboUserType.Focus(); return; } else { UserID = 0; DB db = new DB(); try { db.AddParam("@FirstName", txtFirstName.Text.Trim()); db.AddParam("@LastName", txtLastName.Text.Trim()); db.AddParam("@Username", txtUsername.Text.Trim()); db.AddParam("@Password", BMan_Encryption.EncryptPassword(txtPassword.Text.Trim(), ConfigurationManager.AppSettings["EncKey"])); db.AddParam("@UserTypeID", cboUserType.SelectedValue); DataTable dtUser = db.SQLResults("usp_UserAdd"); if (dtUser.Rows.Count > 0) { UserID = Convert.ToInt32(dtUser.Rows[0]["UserID"]); } } catch (Exception ex) { Common.LogError(ex, "UserMaintenance.btnSave_Click"); UserID = 0; } finally { db.CleanUp(); } if (UserID > 0) { Menu m = new Menu(UserID); m.Show(); this.Hide(); } else if (UserID == -1) { MessageBox.Show("Username already exists. Please enter a different one."); txtUsername.Focus(); return; } else { MessageBox.Show("Error adding user. Please try again."); return; } } }
private void UserMaintenance_Load(object sender, EventArgs e) { DB db = new DB(); DataTable dtUT = db.SQLResults("usp_UserTypeList"); cboUserType.DataSource = dtUT; cboUserType.DisplayMember = "Description"; cboUserType.ValueMember = "UserTypeID"; db.CleanUp(); }