Ejemplo n.º 1
0
        public void CleanTest()
        {
            DateField target   = new DateField();
            var       expected = new DateTime(2006, 10, 25);

            // Required
            AssertExtras.Raises <ValidationException>(delegate
            {
                target.Clean(null);
            }).WithMessage("This field is required.");

            target.Required = false;

            Assert.IsNull(target.Clean(null));

            Assert.AreEqual(expected, target.Clean(new DateTime?(expected)));
            Assert.AreEqual(expected, target.Clean("2006-10-25"));
            Assert.AreEqual(expected, target.Clean("06-10-25"));
            Assert.AreEqual(expected, target.Clean("10/25/2006"));
            Assert.AreEqual(expected, target.Clean("10/25/06"));
            Assert.AreEqual(expected, target.Clean("Oct 25 2006"));
            Assert.AreEqual(expected, target.Clean("Oct 25, 2006"));
            Assert.AreEqual(expected, target.Clean("25 Oct 2006"));
            Assert.AreEqual(expected, target.Clean("25 Oct, 2006"));
            Assert.AreEqual(expected, target.Clean("October 25 2006"));
            Assert.AreEqual(expected, target.Clean("October 25, 2006"));
            Assert.AreEqual(expected, target.Clean("25 October 2006"));
            Assert.AreEqual(expected, target.Clean("25 October, 2006"));

            AssertExtras.Raises <ValidationException>(delegate
            {
                target.Clean("25 Octc, 2006");
            }).WithMessage("Enter a valid date.");
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Raises the <see cref="E:System.Web.UI.Control.Init" /> event.
        /// </summary>
        /// <param name="e">An <see cref="T:System.EventArgs" /> object that contains the event data.</param>
        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);

            gReport.DataKeyNames = new string[] { "Id" };
            gReport.GridRebind  += gReport_GridRebind;

            int tagId = int.MinValue;

            if (int.TryParse(PageParameter("tagId"), out tagId) && tagId > 0)
            {
                Tag _tag = new TagService(new RockContext()).Get(tagId);

                if (_tag != null)
                {
                    TagId         = tagId;
                    TagEntityType = EntityTypeCache.Read(_tag.EntityTypeId);

                    if (TagEntityType != null)
                    {
                        Type modelType = TagEntityType.GetEntityType();

                        gReport.RowItemText = modelType.Name + " Tag";
                        lTaggedTitle.Text   = "Tagged " + modelType.Name.Pluralize();

                        if (modelType != null)
                        {
                            // If displaying people, set the person id fiels so that merge and communication icons are displayed
                            if (TagEntityType.Name == "Rock.Model.Person")
                            {
                                gReport.PersonIdField = "Id";
                            }

                            foreach (var column in gReport.GetPreviewColumns(modelType))
                            {
                                gReport.Columns.Add(column);
                            }

                            // Add a CreatedDateTime if one does not exist
                            var gridBoundColumns = gReport.Columns.OfType <BoundField>();
                            if (gridBoundColumns.Any(c => c.DataField.Equals("CreatedDateTime")) == false)
                            {
                                BoundField addedDateTime = new DateField();
                                addedDateTime.DataField      = "CreatedDateTime";
                                addedDateTime.SortExpression = "CreatedDateTime";
                                addedDateTime.HeaderText     = "Date Tagged";
                                gReport.Columns.Add(addedDateTime);
                            }

                            // Add delete column
                            var deleteField = new DeleteField();
                            gReport.Columns.Add(deleteField);
                            deleteField.Click += gReport_Delete;

                            BindGrid();
                        }
                    }
                }
            }
        }
Ejemplo n.º 3
0
        private bool ParseDate(Element el)
        {
            DateTime dt         = DateTime.MinValue;
            bool     hasDefault = DateTime.TryParse(el.defaultValue.Trim(), out dt);

            DateField field = new DateField
            {
                Label                 = el.label,
                RestrictedYear        = el.restrictedYear,
                DefaultTodayEnabled   = el.enableDefaultDate,
                DefaultValue          = dt,
                DefaultValueSpecified = hasDefault,
                ReadOnly              = el.readOnly,
                Required              = el.required,
                ModifyEnabled         = el.modifyEnable,
                HiddenField           = el.hiddenField,
                Searchable            = el.searchable,
                ClientId              = el.clientId,
                ColumnName            = Utils.SafeSQLName(el.label),
                ResultVisibility      = el.resultVisibility,
                ResultPosition        = el.resultPosition,
                Layout                = new LayoutPosition
                {
                    PanelId   = el.columns.ToString(),
                    ColNumber = el.columns,
                    RowNumber = el.rows
                }
            };

            sections.AddCtrl(field);
            return(true);
        }
        public void GetEventList(EventModel eventModel)
        {
            string dataSource = RenderingContext.Current.Rendering.DataSource;

            if (!string.IsNullOrEmpty(dataSource))
            {
                Item           userGroupItem      = Sitecore.Context.Database.GetItem(dataSource);
                MultilistField selectedEventField = userGroupItem.Fields[EventConstant.GroupEvent];

                if (selectedEventField != null)
                {
                    Item[] eventItems = selectedEventField.GetItems();
                    if (eventItems != null && eventItems.Length > 0)
                    {
                        foreach (var item in eventItems)
                        {
                            GroupEvent eventItem = new GroupEvent();
                            eventItem.Name  = item[EventConstant.EventName];
                            eventItem.Venue = item[EventConstant.EventVenue];
                            DateField dateTimeField = item.Fields[EventConstant.EventDate];
                            eventItem.EventDate = Sitecore.DateUtil.IsoDateToDateTime(dateTimeField.Value);
                            MultilistField photoslist = item.Fields[EventConstant.EventPhotos];
                            Item[]         photos     = null;
                            if (photoslist != null)
                            {
                                photos = photoslist.GetItems();
                            }
                            eventItem.Photos = GetUrlOfPhotos(photos);
                        }
                    }
                }
            }
        }
        public ActionResult Index()
        {
            var sourceItem = RenderingContext.Current.Rendering.Item;

            #region Mapping Fields
            var pageModel = new PageModel();

            pageModel.Header = sourceItem["Header"];
            pageModel.Body   = sourceItem["Body"];

            DateField dateField = sourceItem.Fields["Date"];
            if (dateField != null)
            {
                pageModel.Date = dateField.DateTime;
            }

            ImageField imgField = sourceItem.Fields["Image"];
            if (imgField != null)
            {
                pageModel.Image = new Glass.Mapper.Sc.Fields.Image()
                {
                    Src = Sitecore.Resources.Media.MediaManager.GetMediaUrl(imgField.MediaItem)
                };
            }
            #endregion

            return(View("~/Areas/basic/Views/Home/Index.cshtml", pageModel));
        }
Ejemplo n.º 6
0
        public void Can_create_various_date_ranges(string date)
        {
            // Arrange

            var     anchor = DateTime.Parse(date);
            dynamic result = new System.Dynamic.ExpandoObject();

            string format(DateField d) => $"{d.Min.ToString(FORMAT)} => {d.Max.ToString(FORMAT)}";

            // Act
            result.Input = date;

            var today = DateField.ForToday("today", anchor);

            result.Today = format(today);

            var week = DateField.ForThisWeek("week", anchor);

            result.ThisWeek = format(week);

            var month = DateField.ForThisMonth("month", anchor);

            result.ThisMonth = format(month);

            var year = DateField.ForThisYear("year", anchor);

            result.ThisYear = format(year);

            var json = JsonConvert.SerializeObject(result, Formatting.Indented);

            // Assert
            Diff.Approve(json, ".json", date);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Computed field for month
        /// </summary>
        /// <param name="indexable">IIndexable</param>
        /// <returns>object.</returns>
        public object ComputeFieldValue(IIndexable indexable)
        {
            Item item = null;

            try
            {
                item = indexable as SitecoreIndexableItem;
                if (item == null)
                {
                    return(null);
                }

                string formattedTemplateId = SearchHelper.FormatGuid(item.TemplateID.ToString());

                if (formattedTemplateId.Equals(SearchHelper.FormatGuid(CommonConstants.EventsTemplateID)) &&
                    item.Fields["Date"] != null && !string.IsNullOrEmpty(item.Fields["Date"].Value))
                {
                    DateField dt = item.Fields["Date"];
                    return(Sitecore.DateUtil.FormatDateTime(dt.DateTime, "MMM", item.Language.CultureInfo));
                }
            }

            catch (Exception ex)
            {
                string itemId = string.Empty;
                if (item != null)
                {
                    itemId = item.ID.ToString();
                }
                Sitecore.Diagnostics.Log.Error(this.GetType().Name + " - Item ID: " + itemId, ex, this);
            }

            return(null);
        }
        private DateField GetDateFiledItem(FilterHtmlGenerator.Filter filterData, bool isRangeControl)
        {
            var config  = StandartConfigDateField(isRangeControl);
            var maxDate = (DateTime?)filterData.MaxValue;

            if (maxDate != null)
            {
                config.MaxDate = maxDate.Value;
            }

            var dateField = new DateField(config)
            {
                ID = RegistrationControlToRepository(isRangeControl
                                                 ? UniquePrefixes.EndDateField
                                                 : UniquePrefixes.BeginDateField,
                                                     filterData,
                                                     isRangeControl),
                ClientIDMode = ClientIDMode.Static,
            };

            dateField.CustomConfig.Add(new ConfigItem("rememberMaxValue", maxDate?.ToShortDateString() ?? "", ParameterMode.Value));
            dateField.CustomConfig.Add(new ConfigItem("maxText", Resources.SMaxDateText, ParameterMode.Value));
            dateField.CustomConfig.Add(new ConfigItem("minText", Resources.SMinDateText, ParameterMode.Value));

            return(dateField);
        }
Ejemplo n.º 9
0
    /// <summary>
    /// 日期地区格式化 默认为dd/M/Y
    /// </summary>
    /// <param name="dateField">日期控件</param>
    public static void DateFormat(DateField dateField)
    {
        string Format     = "dd/m/Y";
        string AltFormats = string.Empty;

        switch (Format)
        {
        case "dd/m/Y":
            AltFormats = "d/M/Y|d/M|d/M/y|ddmY|ddm|ddmy";
            break;

        case "m/dd/Y":
            AltFormats = "M/d/Y|M/d|M/d/y|mddY|mdd|mddy";
            break;

        case "Y/m/dd":
            AltFormats = "Y/M/d|M/d|y/M/d|Ymdd|mdd";
            break;

        default:
            Format     = "m/dd/Y";
            AltFormats = "M/d/Y|M/d|M/d/y|mddY|mdd|mddy";
            break;
        }
        dateField.Format     = Format;
        dateField.AltFormats = AltFormats;
    }
 private void SetListeners(FilterHtmlGenerator.Filter filterData, DateField dateField, bool isRangeControl)
 {
     if (!isRangeControl && !string.IsNullOrEmpty(filterData.OnChangedValue))
     {
         dateField.Listeners.Change.Handler += filterData.OnChangedValue;
     }
 }
Ejemplo n.º 11
0
        /// <summary>
        /// Adds the grid columns.
        /// </summary>
        /// <param name="dataTable">The data table.</param>
        private void AddGridColumns(DataTable dataTable)
        {
            bool showColumns = bool.Parse(GetAttributeValue("ShowColumns"));
            var  columnList  = GetAttributeValue("Columns").SplitDelimitedValues().ToList();

            int rowsToEval = 10;

            if (dataTable.Rows.Count < 10)
            {
                rowsToEval = dataTable.Rows.Count;
            }

            gReport.Columns.Clear();

            if (!string.IsNullOrWhiteSpace(gReport.PersonIdField))
            {
                gReport.Columns.Add(new SelectField());
            }

            foreach (DataColumn dataTableColumn in dataTable.Columns)
            {
                if (columnList.Count > 0 &&
                    ((showColumns && !columnList.Contains(dataTableColumn.ColumnName, StringComparer.OrdinalIgnoreCase)) ||
                     (!showColumns && columnList.Contains(dataTableColumn.ColumnName, StringComparer.OrdinalIgnoreCase))))
                {
                    continue;
                }

                BoundField bf = new BoundField();

                if (dataTableColumn.DataType == typeof(bool))
                {
                    bf = new BoolField();
                }

                if (dataTableColumn.DataType == typeof(DateTime))
                {
                    bf = new DateField();

                    for (int i = 0; i < rowsToEval; i++)
                    {
                        object dateObj = dataTable.Rows[i][dataTableColumn];
                        if (dateObj is DateTime)
                        {
                            DateTime dateTime = (DateTime)dateObj;
                            if (dateTime.TimeOfDay.Seconds != 0)
                            {
                                bf = new DateTimeField();
                                break;
                            }
                        }
                    }
                }

                bf.DataField      = dataTableColumn.ColumnName;
                bf.SortExpression = dataTableColumn.ColumnName;
                bf.HeaderText     = dataTableColumn.ColumnName.SplitCase();
                gReport.Columns.Add(bf);
            }
        }
Ejemplo n.º 12
0
        public void Constructors_Defaults()
        {
            var df = new DateField();

            Assert.False(df.IsShortFormat);
            Assert.Equal(DateTime.MinValue, df.Date);
            Assert.Equal(1, df.CursorPosition);
            Assert.Equal(new Rect(0, 0, 12, 1), df.Frame);

            var date = DateTime.Now;

            df = new DateField(date);
            Assert.False(df.IsShortFormat);
            Assert.Equal(date, df.Date);
            Assert.Equal(1, df.CursorPosition);
            Assert.Equal(new Rect(0, 0, 12, 1), df.Frame);

            df = new DateField(1, 2, date);
            Assert.False(df.IsShortFormat);
            Assert.Equal(date, df.Date);
            Assert.Equal(1, df.CursorPosition);
            Assert.Equal(new Rect(1, 2, 12, 1), df.Frame);

            df = new DateField(3, 4, date, true);
            Assert.True(df.IsShortFormat);
            Assert.Equal(date, df.Date);
            Assert.Equal(1, df.CursorPosition);
            Assert.Equal(new Rect(3, 4, 10, 1), df.Frame);

            df.IsShortFormat = false;
            Assert.Equal(new Rect(3, 4, 12, 1), df.Frame);
            Assert.Equal(12, df.Width);
        }
Ejemplo n.º 13
0
 protected void rptStoryIntro_ItemDataBound(object sender, System.Web.UI.WebControls.RepeaterItemEventArgs e)
 {
     if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
     {
         try
         {
             Item nodeItm = (Item)e.Item.DataItem;
             //Text fldDate = (Text)e.Item.FindControl("fldDate");
             Literal litDate = (Literal)e.Item.FindControl("litDate");
             litDate.Text = "Hello World";
             //Literal eventDateFld = (Literal)e.Item.FindControl("eventDateFld");
             //eventDateFld.Text = scDateField.DateTime.ToString("MMM dd");
             Item      storyItem     = nodeItm.Parent;
             DateField nodeDateField = storyItem.Fields["Date"];
             litDate.Text = nodeDateField.DateTime.ToString("MMMM yyyy");
             Text fldDescription = (Text)e.Item.FindControl("fldDescription");
             //fldDate.Item = nodeItm;
             fldDescription.Item = nodeItm;
         }
         catch (Exception ex)
         {
             bool exHandled = handleException(ex);
         }
     }
 }
Ejemplo n.º 14
0
        protected virtual string formatDateField(Item item, ID fieldID)
        {
            DateField field = item.Fields[fieldID];

            if (field == null && String.IsNullOrEmpty(field.Value))
            {
                return(string.Empty);
            }

            var    formattingstring = "|{0}|{1}";
            string formattedvalue;
            var    dateTimeFormatInfo = CultureInfo.CurrentUICulture.DateTimeFormat;

            var format = GetDateFormat(dateTimeFormatInfo.ShortDatePattern);

            if (field.InnerField.TypeKey == "datetime")
            {
                formattedvalue =
                    field.DateTime.ToString(string.Concat(format, " ", dateTimeFormatInfo.ShortTimePattern));
            }
            else
            {
                formattedvalue = field.DateTime.ToString(format);
            }

            return(string.Format(formattingstring, formattedvalue, item[fieldID]));
        }
Ejemplo n.º 15
0
        public void SimpleDateFieldTest()
        {
            // Create a new text document
            TextDocument td = new TextDocument();

            td.New();
            // Create a new paragraph
            Paragraph p  = new Paragraph(td);
            DateField df = new DateField(td);

            // Set fixed to false whch means that the current date is displayed
            df.Fixed = false;
            // add the date field to content
            p.Content.Add(df);
            td.Content.Add(p);

            // test import/export
            using (IPackageWriter writer = new OnDiskPackageWriter())
            {
                td.Save(AARunMeFirstAndOnce.outPutFolder + "field_date.odt", new OpenDocumentTextExporter(writer));
            }
            //td.Load(AARunMeFirstAndOnce.outPutFolder + "field_date.odt");
            //td.Fields.RemoveAt(0);
            // this document should be empty now!!!
            //td.Save(AARunMeFirstAndOnce.outPutFolder + "field_date2.odt");
        }
Ejemplo n.º 16
0
        /// <summary>
        /// Adds a new DateField.
        /// </summary>
        ///
        public DateField AddDateField()
        {
            DateField fieldDate = new DateField();

            Add(fieldDate);
            return(fieldDate);
        }
Ejemplo n.º 17
0
        /// <summary>
        ///     Adds the search fields to the criteria panel
        /// </summary>
        private void InitialiseField(HtmlGenericControl row, Search.SearchParameter parameter, Int32 width)
        {
            BaseInputControl control = null;

            switch (parameter.FieldType)
            {
            case "textbox":
            case "jslookup": control = new TextField(); break;

            case "datepicker": control = new DateField(); break;

            case "checkbox": control = new CheckField(); break;

            case "select": control = this.InitialiseListField(parameter); break;
            }

            // Add the control to the parameter panel
            if (control != null)
            {
                control.ID             = parameter.FieldName;
                control.LabelText      = parameter.CustomLabel.TrimOrNullify() ?? parameter.DefaultLabel;
                control.DataBoundValue = parameter.FieldName;
                control.CssClass      += " col-md-" + width.ToString();
                if (parameter.FieldName == "PN_SURNAME")
                {
                    control.FieldValueRaw = (object)(string.IsNullOrEmpty(PersonSurname) ? "" : PersonSurname);
                }
                row.Controls.Add(control);
            }
        }
Ejemplo n.º 18
0
        public override IRenderingModelBase GetModel()
        {
            HistogramRenderingModel model = new HistogramRenderingModel();

            this.FillBaseProperties(model);
            if (model.DataSourceItem != null)
            {
                LookupField timePeriod = model.DataSourceItem.Fields[Templates.Histogram.Fields.TimePeriod];
                if (timePeriod.TargetItem != null)
                {
                    model.TimePeriod = (TimePeriods)Enum.Parse(typeof(TimePeriods), timePeriod.TargetItem.Fields["Value"].Value); //TODO Pull from Foundation.  And put this in a method.
                }
                model.SetDataUrl(model.DataSourceItem.Fields[Templates.DataVisualization.Fields.Data]);
                model.ShowLabels = !(string.IsNullOrWhiteSpace(this.Rendering.Parameters[Constants.ShowLabels]) ||
                                     this.Rendering.Parameters[Constants.ShowLabels] == "0"); //TODO Clean up
                DateField fromDate = model.DataSourceItem.Fields[Templates.Histogram.Fields.FromDate];
                if (fromDate.DateTime != DateTime.MinValue)
                {
                    model.FromDate = fromDate.DateTime;
                }
                DateField toDate = model.DataSourceItem.Fields[Templates.Histogram.Fields.ToDate];
                if (toDate.DateTime != DateTime.MinValue)
                {
                    model.ToDate = toDate.DateTime;
                }
                TextField dataColumnName = model.DataSourceItem.Fields[Templates.Histogram.Fields.DataColumnName];
                if (!string.IsNullOrWhiteSpace(dataColumnName.Value))
                {
                    model.DateColumnName = dataColumnName.Value;
                }
            }
            return(model);
        }
        public ActionResult DemoNoGlassArticle()
        {
            var dataSourceItem = RenderingContext.Current.Rendering.Item;

            var demoArticleNoGlass = new DemoArticleNoGlass();

            demoArticleNoGlass.Header = dataSourceItem["Header"];
            demoArticleNoGlass.Body   = dataSourceItem["Body"];
            ImageField imgField = dataSourceItem.Fields["Image"];

            if (imgField != null)
            {
                demoArticleNoGlass.Image = Sitecore.Resources.Media.MediaManager.GetMediaUrl(imgField.MediaItem);
            }
            DateField dateField = dataSourceItem.Fields["Date"];

            if (dateField != null)
            {
                demoArticleNoGlass.Date = dateField.DateTime.ToString();
            }

            //Alternatively, to make them EE editable:
            //Header = new HtmlString(FieldRenderer.Render(dataSourceItem, "Header"));
            //Body = new HtmlString(FieldRenderer.Render(dataSourceItem, "Body"));
            //Image = new HtmlString(FieldRenderer.Render(dataSourceItem, "Image", "mw=400"));
            //Date = new HtmlString(FieldRenderer.Render(dataSourceItem, "Date"));

            return(View(demoArticleNoGlass));
        }
Ejemplo n.º 20
0
        void Save()
        {
            foreach (var textBox in root.Children.OfType <TextBox>())
            {
                BindingExpression be = textBox.GetBindingExpression(TextBox.TextProperty);
                be?.UpdateSource();
            }
            DateField.GetBindingExpression(DatePicker.SelectedDateProperty).UpdateSource();
            AuthorField.GetBindingExpression(ComboBox.SelectedItemProperty).UpdateSource();
            PublisherField.GetBindingExpression(ComboBox.SelectedItemProperty).UpdateSource();

            var booksCollection = (Application.Current as App).LibraryData.Books;

            if (impactType == ImpactType.Save)
            {
                if (!booksCollection.Contains <Book>(impact))
                {
                    (Application.Current as App).LibraryData.Books.Add(impact);
                }
                else
                {
                    MessageBox.Show("A book with the ISBN has already been added", "Error",
                                    MessageBoxButton.OK, MessageBoxImage.Error);
                }
            }
            Close();
        }
        public override object GetFieldValue(IIndexableDataField field)
        {
            Field field1 = (Field)(field as SitecoreItemDataField);

            if (field1 != null)
            {
                if (string.IsNullOrEmpty(field1.Value))
                {
                    return((object)null);
                }
                if (FieldTypeManager.GetField(field1) is DateField)
                {
                    DateField dateField = new DateField(field1);
                    if (dateField.DateTime > DateTime.MinValue)
                    {
                        return((object)dateField.DateTime);
                    }
                }
            }
            else if (field.Value is DateTime)
            {
                return((object)(DateTime)field.Value);
            }
            return((object)null);
        }
Ejemplo n.º 22
0
        public static DateTime?DateTimeValue(this TimeField field, DateField dateField)
        {
            if (dateField == null)
            {
                return(null);
            }
            var dateNull = dateField.DateTimeValue();

            if (dateNull == null)
            {
                return(null);
            }
            var date = (DateTime)dateNull;
            var str  = field.Text;

            if (string.IsNullOrWhiteSpace(str))
            {
                return(date.Date);
            }
            var result = date;

            str = date.ToString("yyyy-MM-dd") + " " + str.Trim();
            if (DateTime.TryParse(str, out result))
            {
                return(result);
            }
            return(date.Date);
        }
Ejemplo n.º 23
0
        protected override void RenderContent(PrintContext printContext, XElement output)
        {
            XElement baseXml = new XElement("base");

            base.RenderContent(printContext, baseXml);

            XElement textFrame = baseXml.Element("TextFrame");
            Item     dataItem  = GetDataItem(printContext);

            XElement xElement = RenderItemHelper.CreateXElement("TextFrame", base.RenderingItem, printContext.Settings.IsClient, dataItem);

            this.SetAttributes(xElement);

            output.Add(xElement);

            XAttribute xAttribute = output.Attribute("ParagraphStyle");
            string     text       = (xAttribute != null && !string.IsNullOrEmpty(xAttribute.Value)) ? xAttribute.Value : "NormalParagraphStyle";

            Field     fieldname = dataItem.Fields[this.ContentFieldName];
            DateField dateField = fieldname;

            string dateoutput = dateField.DateTime.ToString(Format);

            IEnumerable <XElement> result = this.FormatText(text, dateoutput);

            xElement.Add(result);

            this.RenderChildren(printContext, xElement);
        }
        /// <summary>
        /// Updates an Article item.
        /// </summary>
        private static void UpdateArticleItem(Item articleItem, BlogFeedItem feedItem)
        {
            // Set the item fields
            articleItem.Editing.BeginEdit();
            try
            {
                articleItem["Title"]        = feedItem.Title;
                articleItem["Description"]  = feedItem.Description;
                articleItem["Article Type"] = Constants.ArticleType_BlogPost;

                // Display Date
                DateField displayDate = articleItem.Fields["Display Date"];
                displayDate.Value = DateUtil.ToIsoDate(feedItem.Updated.Date);

                // Link
                LinkField link = articleItem.Fields["Link"];
                link.Url      = feedItem.Link;
                link.Target   = "_blank";
                link.LinkType = "external";
            }
            finally
            {
                articleItem.Editing.EndEdit();
            }
        }
        public void Process(WorkflowPipelineArgs args)
        {
            Item      workflowItem = args.DataItem;
            IWorkflow itemwf       = this.master.WorkflowProvider.GetWorkflow(workflowItem);

            // Only run on project workflow
            if (itemwf.WorkflowID != Data.ProjectWorkflow.ToString())
            {
                return;
            }

            // Find other items that are in the same project
            var items = master.SelectItems("fast:/sitecore/content//*[@Project = '" + workflowItem.Fields[Data.ProjectFieldId].Value + "']");

            // Get the project defintion
            var       projectDefinition  = master.GetItem(workflowItem.Fields[Data.ProjectFieldId].Value);
            DateField projectReleaseDate = projectDefinition.Fields[Data.ProjectDetailsReleaseDate];

            // If there are no other items in the project, and it's after the project release date, continue the workflow.
            if (items == null && projectReleaseDate.DateTime < DateTime.Now)
            {
                // no other items using this so, send back
                RevertItemsWorkflowToOrigional(workflowItem);
                AutoPublish(args);
            }
            else
            {
                foreach (var item in items)
                {
                    // is the item in the same project
                    if (item.Fields[Data.ProjectFieldId].Value == workflowItem.Fields[Data.ProjectFieldId].Value)
                    {
                        // is it not in the waiting state
                        if (item.Fields["__Workflow state"].Value != Data.ProjectWorkflowReadytoGoLiveState.ToString())
                        {
                            if (item.ID != workflowItem.ID) // ignore if same item
                            {
                                AllItemsReady = false;
                                break;
                            }
                        }
                    }
                }

                if (AllItemsReady && projectReleaseDate.DateTime < DateTime.Now)
                {
                    foreach (var item in items)
                    {
                        // is the item in the same project
                        if (item.Fields[Data.ProjectFieldId].Value == workflowItem.Fields[Data.ProjectFieldId].Value)
                        {
                            RevertItemsWorkflowToOrigional(item);
                        }
                    }

                    AutoPublish(args);
                }
            }
        }
 public ViewBlogPostPageObject CreateNewPost(string title, DateTime blogPostDate, string bodyText)
 {
     TitleField.SendKeys(title);
     DateField.SendKeys(blogPostDate.ToShortDateString());
     BodyTextField.SendKeys(bodyText);
     SaveButton.Click();
     return(new ViewBlogPostPageObject(driver));
 }
        public void BeAbleToTellItIsNotEqualToAnotherTypeOfField()
        {
            NumberField aNumberField = new NumberField("Monto");

            DateField aDateField = new DateField("Fecha");

            Assert.IsFalse(aNumberField.Equals(aDateField));
        }
Ejemplo n.º 28
0
        /// <summary>
        /// Converts a Date to a string suitable for indexing.
        /// </summary>
        /// <throws>  RuntimeException if the date specified in the
        /// method argument is before 1970</throws>
        /// <remarks>Check, if we really have to subtract the TimeZone.UtcOffset,
        /// because the date is already UTC!</remarks>
        public static System.String DateToString(System.DateTime date)
        {
            TimeSpan ts = date.Subtract(new DateTime(1970, 1, 1));

            //TODO: Check, if this have to be removed:
            ts = ts.Subtract(TimeZone.CurrentTimeZone.GetUtcOffset(date));
            return(DateField.TimeToString(ts.Ticks / TimeSpan.TicksPerMillisecond));
        }
Ejemplo n.º 29
0
        public void BeAbleToTellItIsNotEqualToAnotherTypeOfField()
        {
            TextField aTextField = new TextField("Nombre");

            DateField aDateField = new DateField("Fecha");

            Assert.IsFalse(aTextField.Equals(aDateField));
        }
Ejemplo n.º 30
0
        /// <summary>
        /// Adds a new DateField with the given format.
        /// </summary>
        public DateField AddDateField(string format)
        {
            DateField fieldDate = new DateField();

            fieldDate.Format = format;
            Add(fieldDate);
            return(fieldDate);
        }
      /// <summary>
      /// Returns date/datetime field value in yyyyMMddHHmmss format.
      /// </summary>
      /// <returns></returns>
      public override string GetValue()
      {
         if(String.IsNullOrEmpty(_field.Value))
         {
            return String.Empty;
         }

         var dateField = new DateField(_field);
         return dateField.DateTime.ToString(IndexConstants.DateTimeFormat);
      }
        protected void btnRefresh_Click(object sender, EventArgs e)
        {
            try
            {
                SqlConnection sqlConnection = new SqlConnection(getConnnectionStr("analytics"));
                SqlCommand command = new SqlCommand("sp_sc_Refresh_Analytics", sqlConnection);
                command.CommandType = System.Data.CommandType.StoredProcedure;
                command.Parameters.Add(new SqlParameter("@lastUpdate", SqlDbType.DateTime));
                command.Parameters["@lastUpdate"].Direction = ParameterDirection.Output;
                sqlConnection.Open();
                command.ExecuteNonQuery();
                var lastUpdate = (DateTime)command.Parameters["@lastUpdate"].Value;
                sqlConnection.Close();
                btnRefresh.Enabled = false;

                // update campaign startdate and enddate
                using (new SecurityDisabler())
                {
                    var masterDb = Sitecore.Configuration.Factory.GetDatabase("master");
                    var campaignsRoot = masterDb.GetItem("/sitecore/system/Marketing Center/Campaigns");
                    var campaigns = campaignsRoot.Axes.GetDescendants()
                        .Where(x => x.TemplateID == new ID("{94FD1606-139E-46EE-86FF-BC5BF3C79804}")); // Campaign template ID
                    foreach (var campaign in campaigns)
                    {
                        var startDateField = new DateField(campaign.Fields["StartDate"]);
                        var endDateField = new DateField(campaign.Fields["EndDate"]);
                        var daySpan = DateTime.UtcNow - lastUpdate;

                        // update item field
                        using (new EditContext(campaign))
                        {
                            campaign.Editing.BeginEdit();
                            if (!string.IsNullOrEmpty(startDateField.Value))
                            {
                                startDateField.Value = DateUtil.ToIsoDate(startDateField.DateTime.AddDays(daySpan.Days));
                            }

                            if (!string.IsNullOrEmpty(endDateField.Value))
                            {
                                endDateField.Value = DateUtil.ToIsoDate(endDateField.DateTime.AddDays(daySpan.Days));
                            }

                            campaign.Editing.EndEdit();
                        }
                    }
                }

                ClassName = "msgShow";
            }
            catch (SqlException ex)
            {
                Console.WriteLine("SQL Error" + ex.Message.ToString());
            }
        }
 public override object GetFieldValue(IIndexableDataField field)
 {
     Field field1 = (Field)(field as SitecoreItemDataField);
     if (field1 != null)
     {
         if (string.IsNullOrEmpty(field1.Value))
             return (object)null;
         if (FieldTypeManager.GetField(field1) is DateField)
         {
             DateField dateField = new DateField(field1);
             if (dateField.DateTime > DateTime.MinValue)
                 return (object)dateField.DateTime;
         }
     }
     else if (field.Value is DateTime)
         return (object)(DateTime)field.Value;
     return (object)null;
 }
Ejemplo n.º 34
0
        /// <summary>
        /// Selects the previous field (from the current field) in the control.
        /// </summary>
        private void SelectPreviousField()
        {
            if (!this.Enabled || this.invalidFormat || (this.editingDateType != DateType.Exact &&
               this.editingDateType != DateType.Approximate))
            {
                return;
            }

            if (this.currentField == DateField.DayName || this.currentField == DateField.Day)
            {
                this.currentField = DateField.Year;
            }
            else
            {
                this.currentField = (DateField)((int)this.currentField - 1);
            }

            this.SelectCurrentField();
        }
 public void TypeTravelDepartureDateField(DateField dateField, string value)
 {
     UIUtil.DefaultProvider.Type("TrvDptDate_" + dateField.ToString(), value, LocateBy.Id);
 }
        /// <summary>
        /// Updates the last use.
        /// </summary>
        public void UpdateLastUseWithCurrentDate()
        {
            if (this.LastUse != null && this.LastUse.DateTime.Date == DateTime.Now.Date)
              {
            return;
              }

              using (new SecurityDisabler())
              {
            this.BeginEdit();
            this["Last Use"] = DateUtil.IsoNowDate;
            this.lastUse = this.InnerItem.Fields["Last Use"];
            this.EndEdit();
              }
        }
		/// <summary>
		/// Initializes a new instance of the <see cref="DateProperty"/> class.
		/// </summary>
		/// <param name="field">The Field to wrap.</param>
		public DateProperty(Field field)
			: base(field)
		{
			this.dateField = field;
		}
Ejemplo n.º 38
0
            public Transaction()
            {
                date = new DateField();
                date.Text = "Date";
                date.AllowNull = false;

                time = new TimeField();
                time.Text = "Time";
                time.AllowNull = true;

                total = new MoneyField();
                total.Text = "Total";
                total.AllowNull = false;
            }
Ejemplo n.º 39
0
 /// <summary>
 /// Sets the value of current field to its default value.
 /// </summary>
 /// <returns>
 /// default field
 /// </returns>
 private DateField SetDefaultField()
 {          
    this.currentField = DateField.Day;          
     return this.currentField;
 }
Ejemplo n.º 40
0
        /// <summary>
        /// Increments the specified field.
        /// </summary>        
        private void IncrementField()
        {                        
            NhsDate tmp;
            DateField fld = this.currentField;
            if (!NhsDate.TryParseExact(this.txtInput.Text, out tmp, CultureInfo.CurrentCulture))
            {
                this.invalidFormat = true;
                return;
            }

            int mon = tmp.DateValue.Month;

            int newDayValue;
            int daysInMonth;

            switch (this.currentField)
            {
                case DateField.DayName:
                case DateField.Day:
                    tmp.DateValue = tmp.DateValue.AddDays(1);

                    if (tmp.DateValue.Month != mon)
                    {
                        tmp.DateValue = tmp.DateValue.AddMonths(-1);
                    }

                    break;
                case DateField.Month:
                    int newMonthValue = tmp.DateValue.Month;
                    newMonthValue = newMonthValue == 12 ? 1 : ++newMonthValue;
                    daysInMonth = DateTime.DaysInMonth(tmp.DateValue.Year, newMonthValue);
                    newDayValue = daysInMonth < tmp.DateValue.Day ? daysInMonth : tmp.DateValue.Day;
                    tmp.DateValue = new DateTime(tmp.DateValue.Year, newMonthValue, newDayValue, tmp.DateValue.Hour, tmp.DateValue.Minute, tmp.DateValue.Second, tmp.DateValue.Millisecond, tmp.DateValue.Kind);

                    break;
                case DateField.Year:
                    int newYearValue = tmp.DateValue.Year;
                    newYearValue = newYearValue == 9999 ? 1 : ++newYearValue;
                    daysInMonth = DateTime.DaysInMonth(newYearValue, tmp.DateValue.Month);
                    newDayValue = daysInMonth < tmp.DateValue.Day ? daysInMonth : tmp.DateValue.Day;
                    tmp.DateValue = new DateTime(newYearValue, tmp.DateValue.Month, newDayValue, tmp.DateValue.Hour, tmp.DateValue.Minute, tmp.DateValue.Second, tmp.DateValue.Millisecond, tmp.DateValue.Kind);

                    break;
            }

            this.Value = tmp;
            this.FormatOnFocusValue();
            this.currentField = fld;
            this.SelectCurrentField();
        }
Ejemplo n.º 41
0
 /// <summary>
 /// updates the value of current field.
 /// </summary>
 /// <remarks>when the control gets focus, current field is updated.</remarks>
 private void SetCurrentField()
 {           
     if (this.txtInput.SelectionStart < this.GetFieldStart(DateField.Month))
     {
         this.currentField = DateField.Day;
     }
     else if (this.txtInput.SelectionStart < this.GetFieldStart(DateField.Year))
     {
         this.currentField = DateField.Month;
     }
     else
     {
         this.currentField = DateField.Year;
     }
 }
Ejemplo n.º 42
0
 /// <summary>
 /// Retrieves the start index of the specified field.
 /// </summary>
 /// <param name="field">Field to search.</param>
 /// <returns>The end of the specified field</returns>
 private int GetFieldEnd(DateField field)
 {           
    return (this.fieldEnd[(int)field] - this.fieldStart[1]);           
 }
 public void TypeTravelArrivalDateField(DateField dateField, string value)
 {
     UIUtil.DefaultProvider.Type("TrvArrDate_" + dateField.ToString(), value, LocateBy.Id);
 }
Ejemplo n.º 44
0
        /// <summary>
        /// Selects the next field (from the current field) in the control.
        /// </summary>
        private void SelectNextField()
        {
            if (!this.Enabled || this.invalidFormat || (this.editingDateType != DateType.Exact &&
                this.editingDateType != DateType.Approximate))
            {
                return;
            }

            this.currentField = (DateField)(((int)this.currentField + 1) % 4);
            if (this.currentField == DateField.DayName)
            {
                this.currentField = DateField.Day;
            }

            this.SelectCurrentField();
        }
Ejemplo n.º 45
0
        /// <summary>
        /// Selects the specified filed
        /// </summary>
        /// <param name="field">Field to be selected.</param>
        private void SelectField(DateField field)
        {
            if (field == DateField.Null)
            {
                field = this.SetDefaultField();
            }

            this.txtInput.SelectionStart = this.GetFieldStart(field);
            this.txtInput.SelectionLength = this.GetFieldEnd(field) - this.txtInput.SelectionStart;
        }
Ejemplo n.º 46
0
 private void OutputDateValues(DateField field, StringBuilder sb)
 {
     if (field.Values.Count() == 0)
     {
         sb.Append("<empty/>\n");
         return;
     }
     foreach (DateTime dateValue in field.Values)
     {
         sb.Append("<date>");
         sb.Append(dateValue.ToUniversalTime().ToString("yyyy-MM-ddTHH:mm:ssZ"));
         sb.Append("</date>\n");
     }
 }
Ejemplo n.º 47
0
		protected IStorageDateField CreateEmptyDateFieldObject(DateField field)
		{
			var storageService = service.StorageService;
			return (IStorageDateField)storageService.GetObjectFactory().CreateEmptyFieldObject(field.GetType());
		}
 public void TypeCFDateField(int cfId, DateField dateField, string value)
 {
     UIUtil.DefaultProvider.Type(
         string.Format(CFDateFieldFormat, cfId.ToString(), dateField.ToString()),
         value,
         LocateBy.Id);
 }
 public void TypeCFDateField(string cfName, DateField dateField, string value)
 {
     this.TypeCFDateField(this.GetCFItemID(cfName).ToString(), dateField, value);
 }
Ejemplo n.º 50
0
        private void BuildFormPanel()
        {
            this.cbxReminder = new Checkbox  {
                Ref = "../../../hasReminder",
                BoxLabel = "Reminder:",
                DataIndex = "HasReminder",
                Checked = false
            };

            this.dfReminder = new DateField
            {
                Ref = "../../../reminder",
                Disabled = true,
                DataIndex = "Reminder",
                Width = 135
            };

            this.taskSubject = new TextField
            {
                AllowBlank = false,
                FieldLabel = "Task&nbsp;Subject",
                DataIndex = "Title",
                Anchor = "100%"
            };

            this.dueDate = new DateField
            {
                AllowBlank = false,
                FieldLabel = "Due Date",
                DataIndex = "DueDate",
                Width = 135
            };

            this.taskCategory = new DropDownField
              {
                  AllowBlank = false,
                  LazyInit = false,
                  FieldLabel = "Task List",
                  DataIndex = "Name",
                  Editable = false,
                  Mode = DropDownMode.ValueText,
                  Ref = "../../../taskCategory",
                  Component =
                  {
                      new TreePanel
                      {
                          Height = 150,
                          Shadow = ShadowMode.None,
                          UseArrows = true,
                          AutoScroll = true,
                          Animate = true,
                          RootVisible = false,
                          Cls = "tasks-tree",
                          Root =
                          {
                              new TreeNode("root")
                          },
                          SelectionModel =
                          {
                              new DefaultSelectionModel()
                          }
                      }
                  }
              };

            this.description = new HtmlEditor
            {
                HideLabel = true,
                DataIndex = "Description",
                Anchor = "100% -150",
                EnableSourceEdit = false,
                EnableFont = false
            };

            this.formPanel = new FormPanel
             {
                 Region = Ext.Net.Region.Center,
                 LabelWidth = 75,
                 ButtonAlign = Alignment.Right,
                 MinButtonWidth = 80,
                 BaseCls = "x-plain",
                 Ref = "taskForm",
                 Cls = "task-window", RenderFormElement = false,

                 CustomConfig =
                 {
                     new ConfigItem("margins", "10 10 5 10", ParameterMode.Value)
                 },

                 Items =
                 {
                     new BoxComponent
                     {
                         Hidden = true,
                         Ref = "../taskMessage",
                         AutoEl =
                         {
                             Cls = "taskMessage"
                         }
                     },
                     taskSubject,
                     new Container
                     {
                         Cls = "x-plain",
                         Layout = "Hbox",
                         Anchor = "100%",
                         Height = 30,
                         Items =
                         {
                             new Container
                             {
                                 Width = 250,
                                 Layout = "Form",
                                 Cls = "x-pain",
                                 Items =
                                 {
                                     dueDate
                                 }
                             },
                             new Container
                             {
                                 Flex = 1,
                                 Layout = "Form",
                                 Cls = "x-plain",
                                 LabelWidth = 55,
                                 Items =
                                 {
                                     taskCategory
                                 }
                             }
                         }
                     },
                     new BoxComponent
                     {
                         AutoEl =
                         {
                             Cls = "divider"
                         }
                     },
                     new Container
                     {
                         Layout = "HBox",
                         Anchor = "100%",
                         Cls = "x-plain",
                         Height = 30,
                         Items =
                         {
                             new Container
                             {
                                 Width = 80,
                                 Layout = "Form",
                                 Cls = "x-plain",
                                 HideLabels = true,
                                 Items =
                                 {
                                     cbxReminder
                                 }
                             },
                             new Container
                             {
                                 Flex = 1,
                                 Layout = "Form",
                                 Cls = "x-plain",
                                 HideLabels = true,
                                 Items =
                                 {
                                     dfReminder
                                 }
                             }
                         }
                     },
                     description
                 }
             };

            this.Buttons.Add(new Button ("OK"));
            this.Buttons.Add(new Button ("Cancel"));

            this.Items.Add(this.formPanel);
        }
        public void SelectTravelCCExpirationDate(DateField dateField, string value)
        {
            switch (dateField)
            {
                case DateField.Year:
                    UIUtil.DefaultProvider.SelectWithText("TrvccExpYear", value, LocateBy.Name);
                    break;

                case DateField.Month:
                    UIUtil.DefaultProvider.SelectWithText("TrvccExpMonth", value, LocateBy.Name);
                    break;

                case DateField.Day:
                    UIUtil.DefaultProvider.FailTest("There is NO 'Day' field for CC expiration date!");
                    break;

                default:
                    break;
            }
        }