/// <summary> /// Handles the Click event of the cmdSubmit control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param> protected void cmdSubmit_Click(object sender, EventArgs e) { string strAction = string.Empty; try { string strUserId = objUtility.GetUserName(); objUserPreferences = ((MOSSServiceManager)objMossController).GetUserPreferences(strUserId); if(objUserPreferences == null) { objUserPreferences = new UserPreferences(); strAction = CREATE; } else { strAction = UPDATE; } bool blnIsSaved = false; objUserPreferences.Display = cboDisplay.SelectedItem.Value; objUserPreferences.DepthUnits = cboDepthUnits.SelectedItem.Value; objUserPreferences.Country = cboCountry.SelectedItem.Value; objUserPreferences.Asset = cboAsset.SelectedItem.Value; objUserPreferences.RecordsPerPage = cboRecordsPerPage.SelectedItem.Value; objUserPreferences.Basin = cboBasin.SelectedItem.Value; //Dream 3.0 code //Start objUserPreferences.PressureUnits = cboPressureUnits.SelectedItem.Value; objUserPreferences.TemperatureUnits = cboTemperatureUnits.SelectedItem.Value; //End URL objURL = null; ArrayList arlURL = new ArrayList(); objURL = new URL(); objURL.URLTitle = txtLinkTitle1.Text.Trim(); objURL.URLValue = txtLinkUrl1.Text.Trim(); arlURL.Add(objURL); objURL = new URL(); objURL.URLTitle = txtLinkTitle2.Text.Trim(); objURL.URLValue = txtLinkUrl2.Text.Trim(); arlURL.Add(objURL); objURL = new URL(); objURL.URLTitle = txtLinkTitle3.Text.Trim(); objURL.URLValue = txtLinkUrl3.Text.Trim(); arlURL.Add(objURL); objURL = new URL(); objURL.URLTitle = txtLinkTitle4.Text.Trim(); objURL.URLValue = txtLinkUrl4.Text.Trim(); arlURL.Add(objURL); objUserPreferences.URL = arlURL; blnIsSaved = ((MOSSServiceManager)objMossController).UpdateUserPreferences(strUserId, objUserPreferences, strAction); if(blnIsSaved) { CommonUtility.SetSessionVariable(Page, enumSessionVariable.UserPreferences.ToString(), objUserPreferences); Page.Response.Redirect("/_layouts/Dream/ConfirmUserPreferences.aspx?saved=1", false); } else { Page.Response.Redirect("/_layouts/Dream/ConfirmUserPreferences.aspx?saved=0", false); } } catch(WebException webEx) { ShowLableMessage(webEx.Message); } catch(Exception ex) { CommonUtility.HandleException(strCurrSiteUrl, ex); } }
/// <summary> /// Gets the default user preferences stored in the Sharepoint List. /// if the user has not set any Preferences explicitly, the default preferences will be taken from the /// Sharepoint list with the default values /// </summary> /// <param name="userID">The user ID.</param> /// <returns>UserPerferences object</returns> internal UserPreferences GetDefaultUserPreferences(string userID) { SPListItemCollection prefListItemColl = null; SPListItemCollection userDefLinksColl = null; UserPreferences objPreferences = null; string strSiteLocation = string.Empty; try { strSiteLocation = SPContext.Current.Site.Url.ToString(); SPSecurity.RunWithElevatedPrivileges(delegate() { using (SPSite site = new SPSite(strSiteLocation)) { using (SPWeb web = site.OpenWeb()) { objSPQuery.Query = "<Where><Eq><FieldRef Name=\"UserID\" /><Value Type=\"Text\">" + userID + "</Value></Eq></Where>"; prefListItemColl = web.Lists[USERPREFERENCESLIST].GetItems(objSPQuery); if (prefListItemColl != null && prefListItemColl.Count != 0) { objPreferences = new UserPreferences(); if (prefListItemColl[0]["Default_x0020_Asset"] != null) objPreferences.Asset = prefListItemColl[0]["Default_x0020_Asset"].ToString(); if (prefListItemColl[0]["Default_x0020_Basin"] != null) objPreferences.Basin = prefListItemColl[0]["Default_x0020_Basin"].ToString(); if (prefListItemColl[0]["Default_x0020_Country"] != null) objPreferences.Country = prefListItemColl[0]["Default_x0020_Country"].ToString(); if (prefListItemColl[0]["Title"] != null) objPreferences.Display = prefListItemColl[0]["Title"].ToString(); //objPreferences.Field = prefListItemColl[0]["Default_x0020_Field"].ToString(); if (prefListItemColl[0]["Records_x0020_Per_x0020_Page"] != null) objPreferences.RecordsPerPage = prefListItemColl[0]["Records_x0020_Per_x0020_Page"].ToString(); if (prefListItemColl[0]["Depth_x0020_Units"] != null) objPreferences.DepthUnits = prefListItemColl[0]["Depth_x0020_Units"].ToString(); //Dream 3.0 code //Start if (prefListItemColl[0]["Pressure_x0020_Units"] != null) objPreferences.PressureUnits = prefListItemColl[0]["Pressure_x0020_Units"].ToString(); if (prefListItemColl[0]["Temperature_x0020_Units"] != null) objPreferences.TemperatureUnits = prefListItemColl[0]["Temperature_x0020_Units"].ToString(); //End objSPQuery.Query = "<Where><Eq><FieldRef Name=\"UserID\" /><Value Type=\"Text\">" + userID + "</Value></Eq></Where>"; userDefLinksColl = web.Lists[USERDEFINEDLINKSLIST].GetItems(objSPQuery); URL objURL = new URL(); ArrayList arlUserDefLinks = new ArrayList(); for (int index = 0; index < userDefLinksColl.Count; index++) { objURL.URLTitle = userDefLinksColl[0]["Title"].ToString(); objURL.URLValue = userDefLinksColl[0]["URL"].ToString(); //objURL.Tooltip = userDefLinksColl[0]["Tooltip"].ToString(); arlUserDefLinks.Add(objURL); } objPreferences.URL = arlUserDefLinks; } } } }); } catch (Exception) { throw; } return objPreferences; }
/// <summary> /// Read UserPreferences to set users saved default value /// </summary> /// private void SetDefaultPreferences() { if(objUserPreferences != null) { cboDisplay.SelectedValue = objUserPreferences.Display; cboDepthUnits.SelectedValue = objUserPreferences.DepthUnits; cboCountry.SelectedValue = objUserPreferences.Country; cboAsset.SelectedValue = objUserPreferences.Asset; cboRecordsPerPage.SelectedValue = objUserPreferences.RecordsPerPage; cboBasin.SelectedValue = objUserPreferences.Basin; //Dream 3.0 Code //Start cboPressureUnits.SelectedValue = objUserPreferences.PressureUnits; cboTemperatureUnits.SelectedValue = objUserPreferences.TemperatureUnits; //End //Read user defined links URL objURL = null; ArrayList arlUserDefLinks = new ArrayList(); arlUserDefLinks = objUserPreferences.URL; for(int index = 0; index < arlUserDefLinks.Count; index++) { objURL = new URL(); objURL = (URL)arlUserDefLinks[index]; switch(index) { case 0: txtLinkTitle1.Text = objURL.URLTitle; txtLinkUrl1.Text = objURL.URLValue; break; case 1: txtLinkTitle2.Text = objURL.URLTitle; txtLinkUrl2.Text = objURL.URLValue; break; case 2: txtLinkTitle3.Text = objURL.URLTitle; txtLinkUrl3.Text = objURL.URLValue; break; case 3: txtLinkTitle4.Text = objURL.URLTitle; txtLinkUrl4.Text = objURL.URLValue; break; } } } }
/// <summary> /// Adds the list items from specified ListCollection. /// </summary> /// <param name="alURL">The arraylist of URL object.</param> /// <param name="userDefLinksList">The SPList to add items.</param> /// <param name="strUserID">logged in userid.</param> private void AddUserDefinedLinks(ArrayList URL, SPList userDefLinksList, string userID) { SPListItem userDefLinksItem; try { URL objURL = new URL(); for (int intIndex = 0; intIndex < URL.Count; intIndex++) { objURL = (URL)URL[intIndex]; if (objURL.URLTitle.Length > 0 || objURL.URLValue.Length > 0) { userDefLinksItem = userDefLinksList.Items.Add(); userDefLinksItem["UserID"] = userID; userDefLinksItem["Title"] = objURL.URLTitle; userDefLinksItem["URL"] = objURL.URLValue; userDefLinksItem["Tooltip"] = objURL.URLValue; userDefLinksItem.Update(); } } } catch (Exception) { throw; } }