public void TestUserAccounts() { GreyFoxUserManager um = new GreyFoxUserManager(); um.CreateTable(); GreyFoxRoleManager rm = new GreyFoxRoleManager(); rm.CreateTable(); um.CreateReferences(); int userAID; int userBID; int userCID; bool adminRoleAdded; SecurityTestData.GetInstance().RoleAdmin.Save(); SecurityTestData.GetInstance().RoleUser.Save(); SecurityTestData.GetInstance().RoleGuest.Save(); userAID = SecurityTestData.GetInstance().UserA.Save(); userBID = SecurityTestData.GetInstance().UserB.Save(); userCID = SecurityTestData.GetInstance().UserC.Save(); GreyFoxUser user = new GreyFoxUser(userBID); user.Roles.Add(SecurityTestData.GetInstance().RoleAdmin); user.Save(); user = null; user = new GreyFoxUser(userBID); adminRoleAdded = false; foreach (GreyFoxRole role in user.Roles) { if (role.Name == SecurityTestData.GetInstance().RoleAdmin.Name) { adminRoleAdded = true; } } if (!adminRoleAdded) { throw new Exception("Admin role was not correctly added."); } // Delete Users - 'User Roles should be clear SecurityTestData.GetInstance().UserA.Delete(); SecurityTestData.GetInstance().UserB.Delete(); SecurityTestData.GetInstance().UserC.Delete(); // Delete Roles - 'User Roles should be clear SecurityTestData.GetInstance().RoleAdmin.Delete(); SecurityTestData.GetInstance().RoleUser.Delete(); SecurityTestData.GetInstance().RoleGuest.Delete(); }
private void bind() { GreyFoxRoleManager m = new GreyFoxRoleManager(); GreyFoxRoleCollection roles = m.GetCollection(string.Empty, "Name"); foreach (GreyFoxRole role in roles) { ComboBoxItem item = new ComboBoxItem(); item.Text = role.Name; item.Value = role.ID.ToString(); comboRoles.Items.Add(item); } }
public static GreyFoxRole GetRole(string rolename) { GreyFoxRoleManager roleManager; GreyFoxRoleCollection roles; roleManager = new GreyFoxRoleManager(); roles = roleManager.GetCollection( "Name='" + rolename.Replace("'", "''") + "'", string.Empty); if (roles.Count > 0) { return(roles[0]); } return(null); }
private void bindDropDownLists() { #region Bind General Child Data GreyFoxRoleManager requiredRoleManager = new GreyFoxRoleManager(); GreyFoxRoleCollection requiredRoleCollection = requiredRoleManager.GetCollection(string.Empty, string.Empty); foreach (GreyFoxRole requiredRole in requiredRoleCollection) { ListItem i = new ListItem(requiredRole.ToString(), requiredRole.ID.ToString()); msRequiredRole.Items.Add(i); } #endregion }
private void bindDropDownLists() { #region Bind General Child Data msModifyRole.Items.Add(new ListItem("Null", "Null")); GreyFoxRoleManager modifyRoleManager = new GreyFoxRoleManager(); GreyFoxRoleCollection modifyRoleCollection = modifyRoleManager.GetCollection(string.Empty, string.Empty); foreach (GreyFoxRole modifyRole in modifyRoleCollection) { ListItem i = new ListItem(modifyRole.ToString(), modifyRole.ID.ToString()); msModifyRole.Items.Add(i); } #endregion }
/// <summary> /// Render this control to the output parameter specified. /// </summary> /// <param name="output"> The HTML writer to write out to </param> protected override void RenderContent(HtmlTextWriter output) { GreyFoxRoleManager m = new GreyFoxRoleManager(); GreyFoxRoleCollection greyFoxRoleCollection = m.GetCollection(string.Empty, string.Empty); // Render Header Row this.headerLockEnabled = true; RenderRow(this.HeaderRowCssClass, ); bool rowflag = false; string rowCssClass; // // Render Records // foreach (GreyFoxRole greyFoxRole in greyFoxRoleCollection) { if (rowflag) { rowCssClass = defaultRowCssClass; } else { rowCssClass = alternateRowCssClass; } rowflag = !rowflag; output.WriteBeginTag("tr"); output.WriteAttribute("i", greyFoxRole.ID.ToString()); output.WriteLine(HtmlTextWriter.TagRightChar); output.Indent++; output.Indent--; output.WriteEndTag("tr"); output.WriteLine(); } }
private void bindDropDownLists() { #region Bind Default Child Data msContact.Items.Add(new ListItem("Null", "Null")); GreyFoxContactManager contactManager = new GreyFoxContactManager("sysGlobal_Contacts"); GreyFoxContactCollection contactCollection = contactManager.GetCollection(string.Empty, string.Empty); foreach (GreyFoxContact contact in contactCollection) { ListItem i = new ListItem(contact.ToString(), contact.ID.ToString()); msContact.Items.Add(i); } msRoles.Items.Add(new ListItem("Null", "Null")); GreyFoxRoleManager rolesManager = new GreyFoxRoleManager(); GreyFoxRoleCollection rolesCollection = rolesManager.GetCollection(string.Empty, string.Empty); foreach (GreyFoxRole roles in rolesCollection) { ListItem i = new ListItem(roles.ToString(), roles.ID.ToString()); msRoles.Items.Add(i); } #endregion }
public DbContentRatingCollection GetCollection(int topCount, string whereClause, string sortClause, params DbContentRatingFlags[] optionFlags) { StringBuilder query; Database database; DbCommand dbCommand; IDataReader r; DbContentRatingCollection dbContentRatingCollection; int innerJoinOffset; query = new StringBuilder("SELECT "); if (topCount > 0) { query.Append("TOP "); query.Append(topCount); query.Append(" "); } foreach (string columnName in InnerJoinFields) { query.Append("DbContentRating."); query.Append(columnName); query.Append(","); } innerJoinOffset = InnerJoinFields.GetUpperBound(0) + 1; int requiredRoleOffset = -1; // // Append Option Flag Fields // if (optionFlags != null) { for (int x = 0; x < optionFlags.Length; x++) { switch (optionFlags[x]) { case DbContentRatingFlags.RequiredRole: for (int i = 0; i <= GreyFoxRoleManager.InnerJoinFields.GetUpperBound(0); i++) { query.Append("RequiredRole."); query.Append(GreyFoxRoleManager.InnerJoinFields[i]); query.Append(","); } requiredRoleOffset = innerJoinOffset; innerJoinOffset = requiredRoleOffset + GreyFoxRoleManager.InnerJoinFields.GetUpperBound(0) + 1; break; } } } // // Remove trailing comma // query.Length--; if (optionFlags != null) { query.Append(" FROM "); // // Start INNER JOIN expressions // for (int x = 0; x < optionFlags.Length; x++) { query.Append("("); } query.Append("kitCms_Ratings AS DbContentRating"); } else { query.Append(" FROM kitCms_Ratings AS DbContentRating"); } // // Finish INNER JOIN expressions // if (optionFlags != null) { for (int x = 0; x < optionFlags.Length; x++) { switch (optionFlags[x]) { case DbContentRatingFlags.RequiredRole: query.Append(" LEFT JOIN sysGlobal_Roles AS RequiredRole ON DbContentRating.RequiredRoleID = RequiredRole.GreyFoxRoleID)"); break; } } } // // Render where clause // if (whereClause != string.Empty) { query.Append(" WHERE "); query.Append(whereClause); } // // Render sort clause // if (sortClause != string.Empty) { query.Append(" ORDER BY "); query.Append(sortClause); } // // Render final semicolon // query.Append(";"); database = DatabaseFactory.CreateDatabase(); dbCommand = database.GetSqlStringCommand(query.ToString()); #if DEBUG try { r = database.ExecuteReader(dbCommand); } catch (Exception e) { string msg = e.Message; throw(new Exception(msg + " --- Query: " + query.ToString())); } #else r = database.ExecuteReader(dbCommand); #endif dbContentRatingCollection = new DbContentRatingCollection(); while (r.Read()) { DbContentRating dbContentRating = ParseFromReader(r, 0, 1); // Fill RequiredRole if (requiredRoleOffset != -1 && !r.IsDBNull(requiredRoleOffset)) { GreyFoxRoleManager.FillFromReader(dbContentRating.requiredRole, r, requiredRoleOffset, requiredRoleOffset + 1); } dbContentRatingCollection.Add(dbContentRating); } return(dbContentRatingCollection); }
public GreyFoxSettingCollection GetCollection(int topCount, string whereClause, string sortClause, params GreyFoxSettingFlags[] optionFlags) { StringBuilder query = new StringBuilder("SELECT "); if (topCount > 0) { query.Append("TOP "); query.Append(topCount); query.Append(" "); } foreach (string columnName in InnerJoinFields) { query.Append("sysGlobal_Settings."); query.Append(columnName); query.Append(","); } int innerJoinOffset = InnerJoinFields.GetUpperBound(0) + 1; int modifyRoleOffset = -1; // // Append Option Flag Fields // if (optionFlags != null) { for (int x = 0; x < optionFlags.Length; x++) { switch (optionFlags[x]) { case GreyFoxSettingFlags.ModifyRole: for (int i = 0; i <= GreyFoxRoleManager.InnerJoinFields.GetUpperBound(0); i++) { query.Append("sysGlobal_Roles."); query.Append(GreyFoxRoleManager.InnerJoinFields[i]); query.Append(","); } modifyRoleOffset = innerJoinOffset; innerJoinOffset = modifyRoleOffset + GreyFoxRoleManager.InnerJoinFields.GetUpperBound(0) + 1; break; } } } // // Remove trailing comma // query.Length--; if (optionFlags != null) { query.Append(" FROM "); // // Start INNER JOIN expressions // for (int x = 0; x < optionFlags.Length; x++) { query.Append("("); } query.Append("sysGlobal_Settings"); } else { query.Append(" FROM sysGlobal_Settings "); } // // Finish INNER JOIN expressions // if (optionFlags != null) { for (int x = 0; x < optionFlags.Length; x++) { switch (optionFlags[x]) { case GreyFoxSettingFlags.ModifyRole: query.Append(" LEFT JOIN sysGlobal_Roles ON sysGlobal_Settings.ModifyRoleID = sysGlobal_Roles.GreyFoxRoleID)"); break; } } } // // Render where clause // if (whereClause != string.Empty) { query.Append(" WHERE "); query.Append(whereClause); } // // Render sort clause // if (sortClause != string.Empty) { query.Append(" ORDER BY "); query.Append(sortClause); } // // Render final semicolon // query.Append(";"); OleDbConnection dbConnection = new OleDbConnection(connectionString); OleDbCommand dbCommand = new OleDbCommand(query.ToString(), dbConnection); dbConnection.Open(); #if DEBUG OleDbDataReader r; try { r = dbCommand.ExecuteReader(); } catch (Exception e) { throw(new Exception(e.Message + " --- Query: " + query.ToString())); } #else OleDbDataReader r = dbCommand.ExecuteReader(); #endif GreyFoxSettingCollection greyFoxSettingCollection = new GreyFoxSettingCollection(); while (r.Read()) { GreyFoxSetting greyFoxSetting = ParseFromReader(r, 0, 1); // Fill ModifyRole if (modifyRoleOffset != -1 && !r.IsDBNull(modifyRoleOffset)) { GreyFoxRoleManager.FillFromReader(greyFoxSetting.modifyRole, r, modifyRoleOffset, modifyRoleOffset + 1); } greyFoxSettingCollection.Add(greyFoxSetting); } r.Close(); dbConnection.Close(); return(greyFoxSettingCollection); }
public GreyFoxSettingCollection GetCollection(int topCount, string whereClause, string sortClause, params GreyFoxSettingFlags[] optionFlags) { StringBuilder query; Database database; DbCommand dbCommand; IDataReader r; GreyFoxSettingCollection greyFoxSettingCollection; int innerJoinOffset; query = new StringBuilder("SELECT "); if (topCount > 0) { query.Append("TOP "); query.Append(topCount); query.Append(" "); } foreach (string columnName in InnerJoinFields) { query.Append("GreyFoxSetting."); query.Append(columnName); query.Append(","); } innerJoinOffset = InnerJoinFields.GetUpperBound(0) + 1; int parentOffset = -1; int parentParentOffset = -1; int parentModifyRoleOffset = -1; int modifyRoleOffset = -1; // // Append Option Flag Fields // if (optionFlags != null) { for (int x = 0; x < optionFlags.Length; x++) { switch (optionFlags[x]) { case GreyFoxSettingFlags.Parent: for (int i = 0; i <= GreyFoxSettingManager.InnerJoinFields.GetUpperBound(0); i++) { query.Append("Parent."); query.Append(GreyFoxSettingManager.InnerJoinFields[i]); query.Append(","); } parentOffset = innerJoinOffset; innerJoinOffset = parentOffset + GreyFoxSettingManager.InnerJoinFields.GetUpperBound(0) + 1; break; case GreyFoxSettingFlags.ParentParent: for (int i = 0; i <= GreyFoxSettingManager.InnerJoinFields.GetUpperBound(0); i++) { query.Append("Parent_Parent."); query.Append(GreyFoxSettingManager.InnerJoinFields[i]); query.Append(","); } parentParentOffset = innerJoinOffset; innerJoinOffset = parentParentOffset + GreyFoxSettingManager.InnerJoinFields.GetUpperBound(0) + 1; break; case GreyFoxSettingFlags.ParentModifyRole: for (int i = 0; i <= GreyFoxRoleManager.InnerJoinFields.GetUpperBound(0); i++) { query.Append("Parent_ModifyRole."); query.Append(GreyFoxRoleManager.InnerJoinFields[i]); query.Append(","); } parentModifyRoleOffset = innerJoinOffset; innerJoinOffset = parentModifyRoleOffset + GreyFoxRoleManager.InnerJoinFields.GetUpperBound(0) + 1; break; case GreyFoxSettingFlags.ModifyRole: for (int i = 0; i <= GreyFoxRoleManager.InnerJoinFields.GetUpperBound(0); i++) { query.Append("ModifyRole."); query.Append(GreyFoxRoleManager.InnerJoinFields[i]); query.Append(","); } modifyRoleOffset = innerJoinOffset; innerJoinOffset = modifyRoleOffset + GreyFoxRoleManager.InnerJoinFields.GetUpperBound(0) + 1; break; } } } // // Remove trailing comma // query.Length--; if (optionFlags != null) { query.Append(" FROM "); // // Start INNER JOIN expressions // for (int x = 0; x < optionFlags.Length; x++) { query.Append("("); } query.Append("sysGlobal_Settings AS GreyFoxSetting"); } else { query.Append(" FROM sysGlobal_Settings AS GreyFoxSetting"); } // // Finish INNER JOIN expressions // if (optionFlags != null) { for (int x = 0; x < optionFlags.Length; x++) { switch (optionFlags[x]) { case GreyFoxSettingFlags.Parent: query.Append(" LEFT JOIN sysGlobal_Settings AS Parent ON GreyFoxSetting.ParentID = Parent.GreyFoxSettingID)"); break; case GreyFoxSettingFlags.ParentParent: query.Append(" LEFT JOIN sysGlobal_Settings AS Parent_Parent ON Parent.ParentID = Parent_Parent.GreyFoxSettingID)"); break; case GreyFoxSettingFlags.ParentModifyRole: query.Append(" LEFT JOIN sysGlobal_Roles AS Parent_ModifyRole ON Parent.ModifyRoleID = Parent_ModifyRole.GreyFoxRoleID)"); break; case GreyFoxSettingFlags.ModifyRole: query.Append(" LEFT JOIN sysGlobal_Roles AS ModifyRole ON GreyFoxSetting.ModifyRoleID = ModifyRole.GreyFoxRoleID)"); break; } } } // // Render where clause // if (whereClause != string.Empty) { query.Append(" WHERE "); query.Append(whereClause); } // // Render sort clause // if (sortClause != string.Empty) { query.Append(" ORDER BY "); query.Append(sortClause); } // // Render final semicolon // query.Append(";"); database = DatabaseFactory.CreateDatabase(); dbCommand = database.GetSqlStringCommand(query.ToString()); #if DEBUG try { r = database.ExecuteReader(dbCommand); } catch (Exception e) { string msg = e.Message; throw(new Exception(msg + " --- Query: " + query.ToString())); } #else r = database.ExecuteReader(dbCommand); #endif greyFoxSettingCollection = new GreyFoxSettingCollection(); while (r.Read()) { GreyFoxSetting greyFoxSetting = ParseFromReader(r, 0, 1); // Fill Parent if (parentOffset != -1 && !r.IsDBNull(parentOffset)) { GreyFoxSettingManager.FillFromReader(greyFoxSetting.parent, r, parentOffset, parentOffset + 1); // Fill if (parentParentOffset != -1 && !r.IsDBNull(parentParentOffset)) { GreyFoxSettingManager.FillFromReader(greyFoxSetting.parent.Parent, r, parentParentOffset, parentParentOffset + 1); } // Fill if (parentModifyRoleOffset != -1 && !r.IsDBNull(parentModifyRoleOffset)) { GreyFoxRoleManager.FillFromReader(greyFoxSetting.parent.ModifyRole, r, parentModifyRoleOffset, parentModifyRoleOffset + 1); } } // Fill ModifyRole if (modifyRoleOffset != -1 && !r.IsDBNull(modifyRoleOffset)) { GreyFoxRoleManager.FillFromReader(greyFoxSetting.modifyRole, r, modifyRoleOffset, modifyRoleOffset + 1); } greyFoxSettingCollection.Add(greyFoxSetting); } // Microsoft DAAB still needs to close readers. r.Close(); return(greyFoxSettingCollection); }
/// <summary> /// Render this control to the output parameter specified. /// </summary> /// <param name="output"> The HTML writer to write out to </param> protected override void RenderContent(HtmlTextWriter output) { EnsureChildControls(); GreyFoxRoleManager m = new GreyFoxRoleManager(); GreyFoxRoleCollection roles = m.GetCollection(string.Empty, string.Empty); bool rowflag = false; string rowCssClass; // // Render Records // foreach (GreyFoxRole role in roles) { if (rowflag) { rowCssClass = this.defaultRowCssClass; } else { rowCssClass = this.alternateRowCssClass; } rowflag = !rowflag; output.WriteFullBeginTag("tr"); output.WriteLine(); output.Indent++; // // Render ID of Record // // output.WriteBeginTag("td"); // output.WriteAttribute("class", rowCssClass); // output.Write(HtmlTextWriter.TagRightChar); // output.Write(role.iD); // output.WriteEndTag("td"); // output.WriteLine(); // // Render Main Representation of Record // output.WriteBeginTag("td"); output.WriteAttribute("valign", "top"); output.WriteAttribute("class", rowCssClass); output.Write(HtmlTextWriter.TagRightChar); if (selectEnabled) { output.WriteBeginTag("a"); output.WriteAttribute("href", "javascript:" + Page.ClientScript.GetPostBackEventReference(this, "sel_" + role.iD)); output.Write(HtmlTextWriter.TagRightChar); output.Write(role.Name); output.WriteEndTag("a"); } else { output.WriteFullBeginTag("strong"); output.Write(role.name); output.WriteEndTag("strong"); } output.WriteEndTag("td"); output.WriteLine(); // // Render Disabled Status // output.WriteBeginTag("td"); output.WriteAttribute("class", rowCssClass); output.WriteAttribute("valign", "top"); output.Write(HtmlTextWriter.TagRightChar); if (role.isDisabled) { output.Write("Disabled"); } else { output.Write(" "); } output.WriteEndTag("td"); output.WriteLine(); output.Indent--; output.WriteEndTag("tr"); output.WriteLine(); } }
protected void ok_Click(object sender, EventArgs e) { bool reset = false; if (greyFoxUserID == 0) { editGreyFoxUser = new GreyFoxUser(); reset = resetOnAdd; } else { editGreyFoxUser = new GreyFoxUser(greyFoxUserID); } if (editGreyFoxUser.Contact == null) { editGreyFoxUser.Contact = new GreyFoxContact("sysGlobal_Contacts"); } editGreyFoxUser.Contact.ParseName(tbName.Text); editGreyFoxUser.Contact.Address1 = tbAddress1.Text; editGreyFoxUser.Contact.IsBadAddress = cbBadAddress.Checked; editGreyFoxUser.Contact.Address2 = tbAddress2.Text; editGreyFoxUser.Contact.City = tbCity.Text; editGreyFoxUser.Contact.StateProvince = tbStateProvince.Text; editGreyFoxUser.Contact.PostalCode = tbPostalCode.Text; editGreyFoxUser.Contact.Country = tbCountry.Text; editGreyFoxUser.Contact.HomePhone = tbHomePhone.Text; editGreyFoxUser.Contact.IsBadHomePhone = cbBadHomePhone.Checked; editGreyFoxUser.Contact.WorkPhone = tbWorkPhone.Text; editGreyFoxUser.Contact.IsBadWorkPhone = cbBadWorkPhone.Checked; editGreyFoxUser.Contact.MobilePhone = tbMobilePhone.Text; editGreyFoxUser.Contact.Pager = tbPager.Text; editGreyFoxUser.Contact.IsBadMobilePhone = cbBadMobilePhone.Checked; editGreyFoxUser.Contact.Email1 = tbEmail1.Text; editGreyFoxUser.Contact.IsBadEmail = cbBadEmail.Checked; editGreyFoxUser.Contact.Email2 = tbEmail2.Text; editGreyFoxUser.Contact.Url = tbUrl.Text; editGreyFoxUser.Contact.IsBadUrl = cbBadUrl.Checked; editGreyFoxUser.Contact.BirthDate = DateTime.Parse(tbBirthDate.Text); editGreyFoxUser.Contact.MemoText = tbMemoText.Text; editGreyFoxUser.UserName = tbUserName.Text; editGreyFoxUser.IsDisabled = cbIsDisabled.Checked; if (tbLoginPassword.Text != "") { editGreyFoxUser.LoginPassword = GreyFoxPassword.EncodePassword(tbLoginPassword.Text); } GreyFoxRoleManager roleManager = new GreyFoxRoleManager(); editGreyFoxUser.Roles = roleManager.DecodeString(tbRoles.Text, "\r\n"); if (editOnAdd) { greyFoxUserID = editGreyFoxUser.Save(); } else { editGreyFoxUser.Save(); } if (reset) { tbUserName.Text = string.Empty; cbIsDisabled.Checked = false; tbLoginPassword.Text = string.Empty; tbName.Text = string.Empty; tbAddress1.Text = string.Empty; tbAddress2.Text = string.Empty; tbCity.Text = string.Empty; tbStateProvince.Text = string.Empty; tbPostalCode.Text = string.Empty; tbCountry.Text = string.Empty; tbHomePhone.Text = string.Empty; tbWorkPhone.Text = string.Empty; tbMobilePhone.Text = string.Empty; tbPager.Text = string.Empty; tbEmail1.Text = string.Empty; tbEmail2.Text = string.Empty; tbUrl.Text = string.Empty; tbBirthDate.Text = string.Empty; tbMemoText.Text = string.Empty; } OnUpdated(EventArgs.Empty); }