/// <summary> /// Setups grid query parameters. /// </summary> private void SetupGridQueryParameters() { // Create query parameters QueryDataParameters parameters = new QueryDataParameters(); parameters.Add("@Now", DateTime.Now); if (ListingType == ListingTypeEnum.OutdatedDocuments) { parameters.Add("@SiteID", SiteContext.CurrentSiteID); } // Initialize UserID query parameter int userID = currentUserInfo.UserID; if (ListingType == ListingTypeEnum.PendingDocuments) { parameters.Add("@SiteID", SiteInfoProvider.GetSiteID(SiteName)); if ((currentUserInfo.CheckPrivilegeLevel(UserPrivilegeLevelEnum.Admin)) || (currentUserInfo.IsAuthorizedPerResource("CMS.Content", "manageworkflow"))) { userID = -1; } } parameters.Add("@UserID", userID); // Document Age if (DocumentAge != String.Empty) { string[] ages = DocumentAge.Split(';'); if (ages.Length == 2) { // Add from a to values to temp parameters int from = ValidationHelper.GetInteger(ages[1], 0); int to = ValidationHelper.GetInteger(ages[0], 0); if (@from > 0) { gridElem.WhereCondition = SqlHelper.AddWhereCondition(gridElem.WhereCondition, SOURCE_MODIFIEDWHEN + " >= @FROM"); parameters.Add("@FROM", DateTime.Now.AddDays((-1) * @from)); } if (to > 0) { gridElem.WhereCondition = SqlHelper.AddWhereCondition(gridElem.WhereCondition, SOURCE_MODIFIEDWHEN + " <= @TO"); parameters.Add("@TO", DateTime.Now.AddDays((-1) * to)); } } } // Set parameters gridElem.QueryParameters = parameters; }
/// <summary> /// Sets age of documents in order to obtain correct data set. /// </summary> /// <param name="modifiedFrom">Document modified from</param> /// <param name="modifiedTo">Document modified to</param> private void SetDocumentAge(ref DateTime modifiedFrom, ref DateTime modifiedTo) { // Set age of documents if (!string.IsNullOrEmpty(DocumentAge)) { string[] ages = DocumentAge.Split(';'); if (ages.Length == 2) { // Compute 'from' and 'to' values int from = ValidationHelper.GetInteger(ages[1], 0); int to = ValidationHelper.GetInteger(ages[0], 0); if (from > 0) { modifiedFrom = DateTime.Now.AddDays((-1) * from); } if (to > 0) { modifiedTo = DateTime.Now.AddDays((-1) * to); } } } }
protected void Page_Load(object sender, EventArgs e) { if (StopProcessing) { // Do nothing return; } gridElem.IsLiveSite = IsLiveSite; gridElem.OnExternalDataBound += gridElem_OnExternalDataBound; gridElem.HideControlForZeroRows = false; currentUserInfo = CMSContext.CurrentUser; // Initialize strings string strDays = GetString("MyDesk.OutdatedDocuments.Days"); string strWeeks = GetString("MyDesk.OutdatedDocuments.Weeks"); string strMonths = GetString("MyDesk.OutdatedDocuments.Months"); string strYears = GetString("MyDesk.OutdatedDocuments.Years"); // Set proper XML for control type switch (ListingType) { case ListingTypeEnum.CheckedOut: gridElem.ZeroRowsText = GetString("mydesk.ui.nochecked"); gridElem.WhereCondition = "View_CMS_Tree_Joined.DocumentCheckedOutByUserID = @UserID"; break; case ListingTypeEnum.MyDocuments: gridElem.ZeroRowsText = GetString("general.nodatafound"); gridElem.WhereCondition = "View_CMS_Tree_Joined.NodeOwner = @UserID"; break; case ListingTypeEnum.RecentDocuments: gridElem.ZeroRowsText = GetString("general.nodatafound"); gridElem.WhereCondition = "((View_CMS_Tree_Joined.DocumentCreatedByUserID = @UserID OR View_CMS_Tree_Joined.DocumentModifiedByUserID = @UserID OR View_CMS_Tree_Joined.DocumentCheckedOutByUserID = @UserID))"; break; case ListingTypeEnum.PendingDocuments: gridElem.ZeroRowsText = GetString("mydesk.ui.nowaitingdocs"); gridElem.WhereCondition = WorkflowStepInfoProvider.GetWorkflowPendingStepsWhereCondition(currentUserInfo, SiteName); break; case ListingTypeEnum.OutdatedDocuments: // Initialize controls if (!RequestHelper.IsPostBack()) { // Fill the dropdown list drpFilter.Items.Add(strDays); drpFilter.Items.Add(strWeeks); drpFilter.Items.Add(strMonths); drpFilter.Items.Add(strYears); // Load default value txtFilter.Text = "1"; drpFilter.SelectedValue = strYears; // Bind dropdown lists BindDropDowns(); } gridElem.WhereCondition = "((DocumentCreatedByUserID = @UserID OR DocumentModifiedByUserID = @UserID OR DocumentCheckedOutByUserID = @UserID) AND " + SOURCE_MODIFIEDWHEN + "<=@OlderThan AND " + SOURCE_NODESITEID + "=@SiteID)"; // Add where condition if (!string.IsNullOrEmpty(txtDocumentName.Text)) { gridElem.WhereCondition = SqlHelperClass.AddWhereCondition(gridElem.WhereCondition, GetOutdatedWhereCondition(SOURCE_DOCUMENTNAME, drpDocumentName, txtDocumentName)); } if (!string.IsNullOrEmpty(txtDocumentType.Text)) { gridElem.WhereCondition = SqlHelperClass.AddWhereCondition(gridElem.WhereCondition, GetOutdatedWhereCondition(SOURCE_CLASSDISPLAYNAME, drpDocumentType, txtDocumentType)); } gridElem.ZeroRowsText = GetString("mydesk.ui.nooutdated"); // Show custom filter plcOutdatedFilter.Visible = true; break; case ListingTypeEnum.WorkflowDocuments: break; case ListingTypeEnum.PageTemplateDocuments: gridElem.ZeroRowsText = GetString("Administration-PageTemplate_Header.Documents.nodata"); break; case ListingTypeEnum.CategoryDocuments: gridElem.ZeroRowsText = GetString("Category_Edit.Documents.nodata"); break; case ListingTypeEnum.ProductDocuments: break; case ListingTypeEnum.TagDocuments: gridElem.ZeroRowsText = GetString("taggroup_edit.documents.nodata"); break; case ListingTypeEnum.DocTypeDocuments: gridElem.ZeroRowsText = GetString("DocumentType_Edit_General.Documents.nodata"); break; case ListingTypeEnum.All: gridElem.ZeroRowsText = GetString("mydesk.ui.nodata"); break; } // Page Size if (!RequestHelper.IsPostBack() && !String.IsNullOrEmpty(ItemsPerPage)) { gridElem.Pager.DefaultPageSize = ValidationHelper.GetInteger(ItemsPerPage, -1); } // Order switch (ListingType) { case ListingTypeEnum.WorkflowDocuments: case ListingTypeEnum.OutdatedDocuments: case ListingTypeEnum.PageTemplateDocuments: case ListingTypeEnum.CategoryDocuments: case ListingTypeEnum.TagDocuments: case ListingTypeEnum.ProductDocuments: case ListingTypeEnum.DocTypeDocuments: gridElem.OrderBy = SOURCE_DOCUMENTNAME; break; default: gridElem.OrderBy = OrderBy; break; } if (ListingType == ListingTypeEnum.All) { gridElem.WhereCondition = SqlHelperClass.AddWhereCondition(gridElem.WhereCondition, String.Format("(UserID1 = {0} OR UserID2 = {0} OR UserID3 = {0})", currentUserInfo.UserID)); } // Create query parameters QueryDataParameters parameters = new QueryDataParameters(); if (ListingType == ListingTypeEnum.OutdatedDocuments) { parameters.Add("@SiteID", CMSContext.CurrentSite.SiteID); DateTime olderThan = DateTime.Now; int dateTimeValue = ValidationHelper.GetInteger(txtFilter.Text, 0); if (drpFilter.SelectedValue == strDays) { olderThan = olderThan.AddDays(-dateTimeValue); } else if (drpFilter.SelectedValue == strWeeks) { olderThan = olderThan.AddDays(-dateTimeValue * 7); } else if (drpFilter.SelectedValue == strMonths) { olderThan = olderThan.AddMonths(-dateTimeValue); } else if (drpFilter.SelectedValue == strYears) { olderThan = olderThan.AddYears(-dateTimeValue); } parameters.Add("@OlderThan", olderThan); } // Initialize UserID query parameter int userID = currentUserInfo.UserID; if (ListingType == ListingTypeEnum.PendingDocuments) { parameters.Add("@SiteID", SiteInfoProvider.GetSiteID(SiteName)); if ((currentUserInfo.IsGlobalAdministrator) || (currentUserInfo.IsAuthorizedPerResource("CMS.Content", "manageworkflow"))) { userID = -1; } } parameters.Add("@UserID", userID); // Document Age if (DocumentAge != String.Empty) { string[] ages = DocumentAge.Split(';'); if (ages.Length == 2) { // Add from a to values to temp parameters int from = ValidationHelper.GetInteger(ages[1], 0); int to = ValidationHelper.GetInteger(ages[0], 0); if (from > 0) { gridElem.WhereCondition = SqlHelperClass.AddWhereCondition(gridElem.WhereCondition, SOURCE_MODIFIEDWHEN + " >= @FROM"); parameters.Add("@FROM", DateTime.Now.AddDays((-1) * from)); } if (to > 0) { gridElem.WhereCondition = SqlHelperClass.AddWhereCondition(gridElem.WhereCondition, SOURCE_MODIFIEDWHEN + " <= @TO"); parameters.Add("@TO", DateTime.Now.AddDays((-1) * to)); } } } // Site name if (!String.IsNullOrEmpty(SiteName) && (SiteName != UniGrid.ALL)) { SiteInfo site = SiteInfoProvider.GetSiteInfo(SiteName); if (site != null) { gridElem.WhereCondition = SqlHelperClass.AddWhereCondition(gridElem.WhereCondition, SOURCE_NODESITEID + " = " + site.SiteID); UniGrid.GridColumns.Columns.RemoveAll(c => (c.Source == SOURCE_SITENAME || c.Source == SOURCE_NODESITEID)); } } // Path filter if (Path != String.Empty) { if (ListingType == ListingTypeEnum.All) { gridElem.WhereCondition = SqlHelperClass.AddWhereCondition(gridElem.WhereCondition, SOURCE_DOCUMENTNAMEPATH + " LIKE N'" + CMSContext.ResolveCurrentPath(Path).Replace("'", "''") + "'"); } else { gridElem.WhereCondition = SqlHelperClass.AddWhereCondition(gridElem.WhereCondition, SOURCE_NODEALIASPATH + " LIKE N'" + CMSContext.ResolveCurrentPath(Path).Replace("'", "''") + "'"); } } // Document type filer if (!String.IsNullOrEmpty(DocumentType)) { string[] types = DocumentType.Split(';'); gridElem.WhereCondition = SqlHelperClass.AddWhereCondition(gridElem.WhereCondition, SqlHelperClass.GetWhereCondition <string>(SOURCE_CLASSNAME, types, true)); } // Document name filter if (DocumentName != String.Empty) { gridElem.WhereCondition = SqlHelperClass.AddWhereCondition(gridElem.WhereCondition, SOURCE_DOCUMENTNAME + " LIKE N'%" + SqlHelperClass.GetSafeQueryString(DocumentName, false) + "%'"); } // Site running filter if ((SiteName == UniGrid.ALL) && DisplayOnlyRunningSites) { gridElem.WhereCondition = SqlHelperClass.AddWhereCondition(gridElem.WhereCondition, "SiteName IN (SELECT SiteName FROM CMS_Site WHERE SiteStatus = 'RUNNING')"); } // Set parameters gridElem.QueryParameters = parameters; }