小编Vla*_*den的帖子

如何通过jQuery在datetime-local上设置datetime

我的表单上有datetime-local html控件,我需要通过JS或jQuery动态设置日期和时间.我该怎么做?

<input type="datetime-local" id="publishDate" required/>
Run Code Online (Sandbox Code Playgroud)

我试过了

$("#publishDate").val("2013-3-18 13:00");
$("#publishDate").val("2013-3-18T13:00");
$("#publishDate").val(new Date().toLocalString());
Run Code Online (Sandbox Code Playgroud)

但没有任何效果.

提前致谢.

html javascript jquery html5

17
推荐指数
5
解决办法
4万
查看次数

如何计算C#中两年间的闰年数

有没有更好的方法来计算两年之间的闰年数.假设我有开始日期和结束日期.

我有我的代码,但我认为应该有更优雅的方式.

调用代码:

var numberOfLeapYears = NumberOfLeapYears(startDate.Year + 1, endDate.Year - 1);
Run Code Online (Sandbox Code Playgroud)

功能本身:

    private static int NumberOfLeapYears(int startYear, int endYear)
    {
        var counter = 0;

        for (var year = startYear; year <= endYear; year++)
            counter += DateTime.IsLeapYear(year) ? 1 : 0;

        return counter;
    }
Run Code Online (Sandbox Code Playgroud)

所以,如果我有startDate = "10/16/2006",endDate = "4/18/2004"我的结果应该只有1个闰年(2000).另外一个词startDate的年份和endDate的年份不应该计算,只有几年之间.

在此先感谢您的帮助.

c# linq datetime date

13
推荐指数
2
解决办法
2万
查看次数

是ConcurrentBag中的Parallel.ForEach <T>线程安全

MSDN上ConcurrentBag的描述不清楚:

当订购无关紧要时,袋子可用于存放物品,与套装不同,袋子支持重复.ConcurrentBag是一个线程安全的包实现,针对同一个线程将生成和消耗存储在包中的数据的情况进行了优化.

我的问题是它是线程安全的,如果在Parallel.ForEach中使用ConcurrentBag这是一个很好的做法.

例如:

    private List<XYZ> MyMethod(List<MyData> myData)
    {
        var data = new ConcurrentBag<XYZ>();

        Parallel.ForEach(myData, item =>
                        {
                            // Some data manipulation

                            data.Add(new XYZ(/* constructor parameters */);
                        });

        return data.ToList();
    }
Run Code Online (Sandbox Code Playgroud)

这样我就不必使用常规List在Parallel.ForEach中使用同步锁定.

非常感谢.

concurrency multithreading .net-4.0 thread-safety c#-4.0

10
推荐指数
1
解决办法
7681
查看次数

如何在CSOM请求中包含Project的FieldValues

我正在尝试使用客户端对象模型(CSOM)从SharePoint中提取所有项目信息.以下是我获取项目信息的方式:

projectContext.Load(projectContext.Projects,
    c =>
        c.Where(p => p.Id == new Guid(id))
            .IncludeWithDefaultProperties(f => f.Name, f => f.Owner.Id, f => f.CreatedDate,
                f => f.StartDate, f => f.FinishDate, f => f.PercentComplete, f => f.Description));

projectContext.Load(projectContext.LookupTables, c => c.Include(f => f.Id, f => f.Entries));
projectContext.Load(projectContext.Web.SiteUsers);
projectContext.ExecuteQuery();
Run Code Online (Sandbox Code Playgroud)

但是,我还需要从这些项目中检索FieldValues属性,我无法弄清楚如何将它包含在同一个查询中.我从上面的代码中检索项目后,发现如何在项目级别上执行此操作,如下所示:

var pubProject = project.IncludeCustomFields;
projectContext.Load(pubProject);
projectContext.Load(pubProject.CustomFields);

projectContext.ExecuteQuery();

var fieldValues = pubProject.FieldValues;
Run Code Online (Sandbox Code Playgroud)

现在pubProject将包含FieldValues信息,但是对所有项目使用该方法变得太慢(调用SharePoint需要1到4秒),因为我需要为每个项目提出额外请求,CSOM的最佳实践是尽量少打电话.

如果我在include字段中包含FieldValues ,如下所示:

projectContext.Load(projectContext.Projects,
    c =>
        c.Where(p => p.Id == new Guid(id))
            .IncludeWithDefaultProperties(f => f.Name, f => f.Owner.Id, f => f.CreatedDate,
                f => f.StartDate, …
Run Code Online (Sandbox Code Playgroud)

sharepoint sharepoint-2013 csom

10
推荐指数
1
解决办法
1878
查看次数

如何将Resharper(R#)中的默认访问修饰符更改为内部

默认情况下,Resharper将所有方法,属性和类创建为公共.有人知道如何将其改为内部吗?

非常感谢.

resharper

9
推荐指数
1
解决办法
1358
查看次数

如何在Kendo UI网格中创建自定义删除/销毁按钮/命令?

我正在使用Kendo UI网格,GridEditMode.InCell我需要在网格列中添加删除/销毁命令的超链接,而不是默认的"删除"按钮.

我目前的代码如下:

c.Command(command => command.Destroy()).Width(90);
Run Code Online (Sandbox Code Playgroud)

telerik telerik-mvc telerik-grid kendo-ui

9
推荐指数
2
解决办法
2万
查看次数

如何使用复选框控件设置Kendo UI mvc网格

我正在使用Kendo UI MVC网格.该模型的一个属性是bool,所以我需要将它作为复选框呈现在网格中.默认情况下,Kendo UI会在列中将其显示为"true"和"false"值.所以你需要第一次点击获取复选框,然后第二次点击更改组合框的值.我没有设置网格的默认值,而是设置ClientTemplate,所以我得到了复选框而不是"true"和"false"值.

              c.Bound(p => p.GiveUp)
                  .Title("Giveup")
                  .ClientTemplate("<input type='checkbox' id='GiveUp' name='GiveUp' #if(GiveUp){#checked#}# value='#=GiveUp#' />")
                  .Width(50);
Run Code Online (Sandbox Code Playgroud)

此网格使用批量编辑和网格编辑(GridEditMode.InCell)

      .Editable(x => x.Mode(GridEditMode.InCell))
      .DataSource(ds => ds.Ajax()
                            .ServerOperation(false)
                            .Events(events => events.Error("error"))
                            .Batch(true)
                            .Model(model => model.Id(p => p.Id))
                            .Read(read => read.Action("Orders", "Order").Data("formattedParameters"))))
Run Code Online (Sandbox Code Playgroud)

所以我希望能够让用户点击复选框并更改我的模型的值,但不幸的是,这不起作用.我可以看到视觉复选框的值被更改但我没有看到红色三角形标记单元格已更改,当我点击添加新项目按钮时,复选框中的值消失.

请告诉我我做错了什么.

提前致谢.

telerik telerik-mvc telerik-grid kendo-ui

6
推荐指数
2
解决办法
3万
查看次数

xaml嵌套类路径设计器问题

我有嵌套类

public class Enums
{
  public enum WindowModeEnum { Edit, New }
}
Run Code Online (Sandbox Code Playgroud)

在我的xaml中我参考代码:

<Style.Triggers>
    <DataTrigger Binding="{Binding WindowMode}"
        Value="{x:Static Types1:Enums+WindowModeEnum.Edit}">
             <Setter Property="Visibility"
                     Value="Collapsed" />
    </DataTrigger>
</Style.Triggers>
Run Code Online (Sandbox Code Playgroud)

代码编译并正常运行,但我无法在设计窗口中打开xaml代码.我收到以下错误:

Type 'Types1:Enums+WindowModeEnum' was not found.
   at MS.Internal.Metadata.ExposedTypes.ValueSerializers.StaticMemberDocumentValueSerializer.ConvertToDocumentValue(ITypeMetadata type, String value, IServiceProvider documentServices)
   at MS.Internal.Design.DocumentModel.DocumentTrees.Markup.XamlMarkupExtensionPropertyBase.get_Value()
   at MS.Internal.Design.DocumentModel.DocumentTrees.DocumentPropertyWrapper.get_Value()
   at MS.Internal.Design.DocumentModel.DocumentTrees.InMemory.InMemoryDocumentProperty..ctor(DocumentProperty property, InMemoryDocumentItem item)
   at MS.Internal.Design.DocumentModel.DocumentTrees.InMemory.InMemoryDocumentItem.SetUpItem(DocumentItem item)
Run Code Online (Sandbox Code Playgroud)

VS2008,VS2010中存在相同的错误.

有没有人有任何想法,如何处理它所以我可以在设计模式下打开窗口.

非常感谢.

弗拉德.

wpf xaml designer visual-studio-2010

5
推荐指数
1
解决办法
727
查看次数

实体框架(EF)OutOfMemoryException

我有来自其他来源的> 67000条记录来到我的系统.将业务规则应用于这些记录后,我必须将它们存储到数据库中.我使用以下代码执行此操作:

        using (var context = new MyEntities())
        {
            var importDataInfo = context.ImportDataInfoes.First(x => x.ID == importId);

            importedRecords.ForEach(importDataInfo.ValuationEventFulls.Add);

            context.SaveChanges();
        }
Run Code Online (Sandbox Code Playgroud)

执行代码后,我收到以下错误(OutOfMemoryException)

    Error in executing code|Exception of type 'System.OutOfMemoryException' was thrown.*   at System.Data.Mapping.Update.Internal.KeyManager.<WalkGraph>d__5.MoveNext()
   at System.Data.Mapping.Update.Internal.KeyManager.GetPrincipalValue(PropagatorResult result)
   at System.Data.Mapping.Update.Internal.UpdateCompiler.GenerateValueExpression(EdmProperty property, PropagatorResult value)
   at System.Data.Mapping.Update.Internal.UpdateCompiler.BuildSetClauses(DbExpressionBinding target, PropagatorResult row, PropagatorResult originalRow, TableChangeProcessor processor, Boolean insertMode, Dictionary`2& outputIdentifiers, DbExpression& returning, Boolean& rowMustBeTouched)
   at System.Data.Mapping.Update.Internal.UpdateCompiler.BuildInsertCommand(PropagatorResult newRow, TableChangeProcessor processor)
   at System.Data.Mapping.Update.Internal.TableChangeProcessor.CompileCommands(ChangeNode changeNode, UpdateCompiler compiler)
   at System.Data.Mapping.Update.Internal.UpdateTranslator.<ProduceDynamicCommands>d__0.MoveNext()
   at System.Linq.Enumerable.<ConcatIterator>d__71`1.MoveNext()
   at System.Data.Mapping.Update.Internal.UpdateCommandOrderer..ctor(IEnumerable`1 commands, UpdateTranslator translator)
   at System.Data.Mapping.Update.Internal.UpdateTranslator.ProduceCommands()
   at System.Data.Mapping.Update.Internal.UpdateTranslator.Update(IEntityStateManager …
Run Code Online (Sandbox Code Playgroud)

.net c# entity-framework out-of-memory entity-framework-4

5
推荐指数
1
解决办法
7194
查看次数

如何按需使用Kendo Grid Ajax Read事件

我有带有 DropDownList 和 Telerik 的 Kendo UI 网格控件的页面。第一次打开页面时,DropDownList 中没有选择任何项目。当用户在 DropDownList 中选择值时,Grid 才应该对服务器进行 Ajax 调用并加载相应的数据。

当用户在 DropDownList 中选择项目时,我的代码工作正常,但问题是第一次打开页面时,我的 DropDownList 中没有值,Grid 不应调用服务器。

我的问题是,如果 DropDowList 中没有选择任何项目,如何防止网格不调用服务器?

    <div>
@Html.Kendo().DropDownList().Name("broker").DataTextField("GrandParentName").DataValueField("Id").BindTo(Model).SelectedIndex(@selectedIndex).Events(e => e.Change("brokerChanged"))
    </div>

    @(Html.Kendo().Grid<OrderViewModel>()
          .Name("Orders")
          .HtmlAttributes(new {style = "height: 500"})
          .Columns(c =>
              {
                  c.Bound(p => p.Id)
                      .Width(50)
                      .Title("")
                      .Sortable(false)
                      .IncludeInMenu(false)
                      .ClientTemplate((@Html.ActionLink("Edit", "Index", "Splits", new {Id = "OrderId"}, null).ToHtmlString().Replace("OrderId", "#=Id#")));
                  c.Bound(p => p.TradeDate)
                      .Title("Trd Dt")
                      .Format("{0:d}")
                      .Width(90)
                      .HtmlAttributes(new {style = "text-align: right"});
                  c.Bound(p => p.Price)
                      .Title("Price")
                      .Format("{0:n}")
                      .Width(100)
                      .HtmlAttributes(new {style = "text-align: right"});
                  c.Bound(p => p.Status) …
Run Code Online (Sandbox Code Playgroud)

telerik telerik-mvc telerik-grid kendo-ui

5
推荐指数
1
解决办法
6881
查看次数