public void SetPrivacyProperty(int MemberId, string Property, PrivacyOptions option) { DataView view = new DataView(Table, "Property='" + Property + "'", "", DataViewRowState.CurrentRows); if (view.Count == 0) { return; } int value = int.Parse(view[0]["Value"].ToString()); //Only me multiply by 2 int testOnlyMe = (int)Math.Pow(2, value * 2); int testFriends = (int)Math.Pow(2, value); int addedValue = 0; if (option == PrivacyOptions.Friends) { addedValue = testFriends; } else if (option == PrivacyOptions.OnlyMe) { addedValue = testOnlyMe; } //string sql = "Update Members set Privacy=(Privacy& ~{0})|(Privacy& ~{1})|{2} where MemberId={3}"; string sql = @" Update Members set Privacy = case When (Privacy&{0}) <> 0 then (Privacy& ~{0})|{2} when (Privacy&{1}) <> 0 then (Privacy& ~{1})|{2} else Privacy | {2} end where MemberId={3}"; sql = String.Format(sql, testOnlyMe, testFriends, addedValue, MemberId); DBUtils.ExecuteQuery(sql, cte.lib); }
bool IsSelected(PrivacyOptions option, int param, int privacy) { //0 = all settings are open for everyone // //if (option == PrivacyOptions.Everyone && privacy == 0) //return true; //for only me we multiply by 2 //initialized as only everyone int test = 0; if (option == PrivacyOptions.OnlyMe) { test = (int)Math.Pow(2, param * 2); } else if (option == PrivacyOptions.Friends) { test = (int)Math.Pow(2, param); } return((privacy & test) == test); }