/// <summary> /// Updates an existing company plan /// </summary> /// <param name="company"></param> public static void UpdateCompanyPlan(BasePlanCompany company) { // Initialize SQL SqlConnection sql = new SqlConnection(ConfigurationManager.ConnectionStrings["DB"].ConnectionString); SqlCommand cmd = new SqlCommand(@"UPDATE Plans_Organization SET OrgPlanName=@OrgPlanName, MaxUsers=@MaxUsers, MaxDomains=@MaxDomains, MaxExchangeMailboxes=@MaxExchangeMailboxes, MaxExchangeContacts=@MaxExchangeContacts, MaxExchangeDistLists=@MaxExchangeDistLists, MaxExchangePublicFolders=@MaxExchangePublicFolders, MaxTerminalServerUsers=@MaxTerminalServerUsers, MaxExchangeMailPublicFolders=@MaxExchangeMailPublicFolders, MaxExchangeResourceMailboxes=@MaxExchangeResourceMailboxes WHERE OrgPlanID=@OrgPlanID", sql); try { // Add parameters cmd.Parameters.AddWithValue("@OrgPlanID", company.PlanID); cmd.Parameters.AddWithValue("@OrgPlanName", company.PlanName); cmd.Parameters.AddWithValue("@MaxUsers", company.MaxUsers); cmd.Parameters.AddWithValue("@MaxDomains", company.MaxDomains); cmd.Parameters.AddWithValue("@MaxExchangeMailboxes", company.MaxExchangeMailboxes); cmd.Parameters.AddWithValue("@MaxExchangeContacts", company.MaxExchangeContacts); cmd.Parameters.AddWithValue("@MaxExchangeDistLists", company.MaxExchangeDistLists); cmd.Parameters.AddWithValue("@MaxExchangePublicFolders", company.MaxExchangeMailPublicFolders); cmd.Parameters.AddWithValue("@MaxExchangeMailPublicFolders", company.MaxExchangeMailPublicFolders); cmd.Parameters.AddWithValue("@MaxExchangeResourceMailboxes", company.MaxExchangeResourceMailboxes); cmd.Parameters.AddWithValue("@MaxTerminalServerUsers", company.MaxCitrixUsers); // Open connection sql.Open(); // Insert cmd.ExecuteNonQuery(); // Close connection sql.Close(); } catch (Exception) { throw; } finally { cmd.Dispose(); sql.Dispose(); } }
/// <summary> /// Gets plan information for a specific company /// </summary> /// <param name="planId"></param> /// <returns></returns> public static BasePlanCompany GetCompanyPlan(int planId) { // Initialize new collection BasePlanCompany pc = new BasePlanCompany(); // Initialize SQL SqlConnection sql = new SqlConnection(ConfigurationManager.ConnectionStrings["DB"].ConnectionString); SqlCommand cmd = new SqlCommand("SELECT * FROM Plans_Organization WHERE OrgPlanID=@OrgPlanID", sql); cmd.Parameters.AddWithValue("@OrgPlanID", planId); try { // Open Connection sql.Open(); // Read data SqlDataReader r = cmd.ExecuteReader(); while (r.Read()) { pc.PlanID = int.Parse(r["OrgPlanID"].ToString()); pc.PlanName = r["OrgPlanName"].ToString(); pc.MaxUsers = int.Parse(r["MaxUsers"].ToString()); pc.MaxDomains = int.Parse(r["MaxDomains"].ToString()); pc.MaxExchangeMailboxes = int.Parse(r["MaxExchangeMailboxes"].ToString()); pc.MaxExchangeContacts = int.Parse(r["MaxExchangeContacts"].ToString()); pc.MaxExchangeDistLists = int.Parse(r["MaxExchangeDistLists"].ToString()); if (r["MaxExchangeMailPublicFolders"] != DBNull.Value) pc.MaxExchangeMailPublicFolders = int.Parse(r["MaxExchangeMailPublicFolders"].ToString()); if (r["MaxExchangeResourceMailboxes"] != DBNull.Value) pc.MaxExchangeResourceMailboxes = int.Parse(r["MaxExchangeResourceMailboxes"].ToString()); pc.MaxCitrixUsers = int.Parse(r["MaxTerminalServerUsers"].ToString()); } // Close and dispose r.Close(); r.Dispose(); } catch (Exception) { throw; } finally { cmd.Dispose(); sql.Dispose(); } // Return our object return pc; }
/// <summary> /// Adds a new company plan /// </summary> /// <param name="company"></param> public static void AddCompanyPlan(BasePlanCompany company) { // Initialize SQL SqlConnection sql = new SqlConnection(ConfigurationManager.ConnectionStrings["DB"].ConnectionString); SqlCommand cmd = new SqlCommand(@"INSERT INTO Plans_Organization (OrgPlanName, ProductID, MaxUsers, MaxDomains, MaxExchangeMailboxes, MaxExchangeContacts, MaxExchangeDistLists, MaxExchangePublicFolders, MaxExchangeMailPublicFolders, MaxExchangeKeepDeletedItems, MaxExchangeResourceMailboxes, MaxTerminalServerUsers) VALUES (@OrgPlanName, @ProductID, @MaxUsers, @MaxDomains, @MaxExchangeMailboxes, @MaxExchangeContacts, @MaxExchangeDistLists, @MaxExchangePublicFolders, @MaxExchangeMailPublicFolders, @MaxExchangeKeepDeletedItems, @MaxExchangeResourceMailboxes, @MaxTerminalServerUsers) ", sql); try { // Add parameters cmd.Parameters.AddWithValue("@OrgPlanName", company.PlanName); cmd.Parameters.AddWithValue("@ProductID", 0); cmd.Parameters.AddWithValue("@MaxUsers", company.MaxUsers); cmd.Parameters.AddWithValue("@MaxDomains", company.MaxDomains); cmd.Parameters.AddWithValue("@MaxExchangeMailboxes", company.MaxExchangeMailboxes); cmd.Parameters.AddWithValue("@MaxExchangeContacts", company.MaxExchangeContacts); cmd.Parameters.AddWithValue("@MaxExchangeDistLists", company.MaxExchangeDistLists); cmd.Parameters.AddWithValue("@MaxExchangePublicFolders", company.MaxExchangeMailPublicFolders); cmd.Parameters.AddWithValue("@MaxExchangeMailPublicFolders", company.MaxExchangeMailPublicFolders); cmd.Parameters.AddWithValue("@MaxExchangeKeepDeletedItems", 0); cmd.Parameters.AddWithValue("@MaxExchangeResourceMailboxes", company.MaxExchangeResourceMailboxes); cmd.Parameters.AddWithValue("@MaxTerminalServerUsers", company.MaxCitrixUsers); // Open connection sql.Open(); // Insert cmd.ExecuteNonQuery(); // Close connection sql.Close(); } catch (Exception) { throw; } finally { cmd.Dispose(); sql.Dispose(); } }
/// <summary> /// Gets a list of company plans /// </summary> /// <returns></returns> public static List<BasePlanCompany> GetCompanyPlans() { // Initialize new collection List<BasePlanCompany> plans = new List<BasePlanCompany>(); // Initialize SQL SqlConnection sql = new SqlConnection(ConfigurationManager.ConnectionStrings["DB"].ConnectionString); SqlCommand cmd = new SqlCommand("SELECT * FROM Plans_Organization ORDER BY OrgPlanName", sql); try { // Open Connection sql.Open(); // Read data SqlDataReader r = cmd.ExecuteReader(); while (r.Read()) { BasePlanCompany pc = new BasePlanCompany(); pc.PlanID = int.Parse(r["OrgPlanID"].ToString()); pc.PlanName = r["OrgPlanName"].ToString(); pc.MaxUsers = int.Parse(r["MaxUsers"].ToString()); pc.MaxDomains = int.Parse(r["MaxDomains"].ToString()); pc.MaxExchangeMailboxes = int.Parse(r["MaxExchangeMailboxes"].ToString()); pc.MaxExchangeContacts = int.Parse(r["MaxExchangeContacts"].ToString()); pc.MaxExchangeDistLists = int.Parse(r["MaxExchangeDistLists"].ToString()); pc.MaxExchangePublicFolders = int.Parse(r["MaxExchangePublicFolders"].ToString()); pc.MaxExchangeMailPublicFolders = int.Parse(r["MaxExchangeMailPublicFolders"].ToString()); pc.MaxExchangeKeepDeletedItems = int.Parse(r["MaxExchangeKeepDeletedItems"].ToString()); pc.MaxCitrixUsers = int.Parse(r["MaxTerminalServerUsers"].ToString()); // Add to our list plans.Add(pc); } // Close and dispose r.Close(); r.Dispose(); } catch (Exception) { throw; } finally { cmd.Dispose(); sql.Dispose(); } // Return our collection return plans; }