小编Cra*_*aig的帖子

计算年,月,周和日

在我的应用程序中,用户输入两个日期.计划的开始日期和计划的结束日期.我们必须采用这些日期,并根据差异填充4个字段.

所以,让我们说他选择2010年1月1日作为开始,2011年3月2日作为结束,我们需要最终:

年:1个月:2周:0天1

意思是总持续时间为1年,2个月和1天.

有这样做的标准方法吗?或者我是否需要编写一个具有很多非常棘手的逻辑的方法来解决它?我希望我很幸运,并且会有一个date-diff类型.Net类可用.

.net c# timespan date

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

在 ReportViewer 中刷新数据集中的字段

我有一个用 VS2012 编写的 WinForms 应用程序。它从我的 SQL Server 数据库上的视图获取数据。我在视图中添加了一个新列,但是找不到让 ReportViewer 数据集查看新列的方法。

在 ReportData 面板中,我尝试过:

右键单击数据源,然后单击刷新。右键单击数据集,然后单击刷新

两者都没有让新列显示在可用列的列表中。

如何在 VS2012 中的报表设计器中显示该列?

c# reportviewer winforms

4
推荐指数
1
解决办法
9460
查看次数

查询速度快,但在 VIEW 中时,速度很慢 - 由于 ROW_NUMBER

我有一个查询,运行时,结果是即时的。

However, I paste the exact same query into VIEW, and the results take 6 seconds to reply.

For example,

SELECT ... FROM MyTables WHERE PersonID = x
Run Code Online (Sandbox Code Playgroud)

runs fast.

But create a view with:

SELECT ... FROM MyTables 
Run Code Online (Sandbox Code Playgroud)

And then call the view:

SELECT * FROM MyView WHERE PersonID = x
Run Code Online (Sandbox Code Playgroud)

And it runs slow.

Actual Query:

select ROW_NUMBER() over(partition by h.Id order by h.[SysStartTime]) as VersionNUmber,
      h.Id,
      fac.HIC,
      ... plus 18 other columns from the joined tables.

from …
Run Code Online (Sandbox Code Playgroud)

sql sql-server sql-server-2016

4
推荐指数
1
解决办法
2990
查看次数

ImageSharp和字体高度

我的任务是创建要打印的图像。在图片上,我需要输入一个大写字母(大写[AZ])。

打印的图像尺寸可以在15厘米高和30厘米高之间变化(包括两者之间的任何尺寸)。

字母需要横跨打印图像的整个高度。

设置字体大小时,我看到您可以获取文本的大小。

using (Image<Rgba32> img = new Image<Rgba32>(imageWidth, imageHeight))
{
    img.Mutate(x => x.Fill(Rgba32.White));
    img.MetaData.HorizontalResolution = 96;
    img.MetaData.VerticalResolution = 96;
    var fo = SystemFonts.Find("Arial");
    var font = new Font(fo, 1350, FontStyle.Regular);
Run Code Online (Sandbox Code Playgroud)

我可以在这里获取文本的大小:

SizeF size = TextMeasurer.Measure(group.Text, new RendererOptions(font));
Run Code Online (Sandbox Code Playgroud)

但是,如您所见,我在这里将字体的大小硬编码。高度需要与图像的高度匹配。

有什么方法可以指定这一点,而又不会增加质量?有没有一种方法可以指定高度(以像素为单位)?也许我可以安全使用的字体大小有颜色?

当我将“字体大小”设置为“图像”的像素高度时,会看到以下信息: 在此处输入图片说明

我不确定为什么圆圈部分有间隙。我将左手文本的左上角位置设置为0,0 ....,将“ QWW”组的右上角点设置为图像的宽度,将0设置为Y。但是我希望它们要与尺寸和底部齐平。

c# .net-core imagesharp

4
推荐指数
2
解决办法
643
查看次数

JQuery UI和主题

我下载了JQuery UI并将脚本添加到我的解决方案中,并且使用少量代码,我有一个漂亮的日期选择器.

但是,我需要从我的css文件中使用自己的主题.我已根据示例代码创建了日期选择器,但它没有样式.也就是说,它出现在现有文本上.有没有办法从现有的css文件中分配css样式,使日历的背景不透明,并使用我的颜色?

jquery jquery-ui datepicker

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

ASP.Net MVC隐藏字段数组

我将List <>发送到View,然后将该列表转换为隐藏字段数组.这是使用局部视图完成的,以构建表.

<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<BudgieMoneySite.Models.TransactionSplitLine>" %>
<tr>
    <td>
        <%=Model.Category %>
        <%=Html.HiddenFor(x => x.CategoryId)%>
    </td>
    <td>
        <%=Model.SubCategory %>
        <%=Html.HiddenFor(x => x.SubCategoryId)%>
    </td>
    <td>
        <%=Model.Amount %>
        <%=Html.HiddenFor(x => x.AmountValue)%>
    </td>

</tr>
Run Code Online (Sandbox Code Playgroud)

我有x行....所以我希望我可以将隐藏字段中的值作为数组.我的模型中有一个字段,定义为public string [] CategoryIds {get; 组; }

(我认为这个问题可能是隐藏的领域被称为'CategoryId'和μ模型想要'CategoryIds').

渲染时,我看到我有一行看起来像这样:

<tr>
<td>
    Medical
    <input id="TransactionSplitLines_2__CategoryId" name="TransactionSplitLines[2].CategoryId" type="hidden" value="6" />

</td>
<td>
    Over the Counter Medicines
    <input id="TransactionSplitLines_2__SubCategoryId" name="TransactionSplitLines[2].SubCategoryId" type="hidden" value="22" />
</td>
<td>
    111
    <input id="TransactionSplitLines_2__AmountValue" name="TransactionSplitLines[2].AmountValue" type="hidden" value="0" />
</td>
Run Code Online (Sandbox Code Playgroud)

然后我试图将数据恢复到控制器中,如下所示:

[HttpPost]
public ActionResult AccountTransaction(AccountTransactionView model)
{
    var reply = …
Run Code Online (Sandbox Code Playgroud)

asp.net-mvc

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

背景工作者和跨线程问题

我有一个Winforms应用程序正常工作..使用BackgroundWorkerThread来管理串行数据到设备的GUI可用性.

它工作正常.

现在,我正在添加一个新方法,并复制我在其他形式中所做的事情.但我得到一个跨线程异常.

我宣布我的BWT是这样的:

BackgroundWorker bw = new BackgroundWorker();
            bw.WorkerSupportsCancellation = true;
            bw.DoWork += DownloadGpsDataFromDevice;
            bw.WorkerReportsProgress = true;
            bw.RunWorkerAsync();
Run Code Online (Sandbox Code Playgroud)

然后,我有一个这样的方法,这背景工作:

private void DownloadGpsDataFromDevice(object sender, DoWorkEventArgs e)
{
    _performScreenUpdate = true;
    tsStatus.Text = "Downloading GPS Data...";
    Invalidate();
    Refresh();


    Common.WriteLog("Extracting raw GPS data. Sending LL.");

    ReplyString raw = DeviceServices.ExecuteCommand("$LL");
Run Code Online (Sandbox Code Playgroud)

DeviceServices.ExecuteCommand("$ LL"); 是有效的工作,但我在上一行获得异常,我在那里登录到文本文件.现在,这让你担心 - 写入文件.但是,我在另一个BWT中做过数千次.

我使写作线程安全.这是我的Common.WriteLog方法:

public static void WriteLog(string input)
{
    lock (_lockObject)
    {
        WriteLogThreadSafe(input);
    }
}

private static void WriteLogThreadSafe(string input)
{
    Directory.CreateDirectory(LogFilePath);
    StreamWriter w = File.AppendText(LogFilePath + @"\" + LogFileName); …
Run Code Online (Sandbox Code Playgroud)

c# multithreading backgroundworker

3
推荐指数
1
解决办法
5496
查看次数

查询自联接表似乎很慢

我有一个表,其中包含一个分层的位置列表.位置具有父位置,并且位置具有多个兄弟位置.

CREATE TABLE [dbo].[Location]
(
    [ID] [int] IDENTITY(1,1) NOT NULL,
    [ParentID] [int] NULL,
    [LocationTypeID] [int] NOT NULL,
    [Description] [varchar](100) NOT NULL,
    [Deleted] [datetime] NULL,
    [CreatedDate] [datetime] NOT NULL,
    [CreatedUserID] [int] NOT NULL,
    [ModifiedDate] [datetime] NULL,
    [ModifiedUserID] [int] NULL,
    [Version] [timestamp] NOT NULL,

    CONSTRAINT [pk_location] 
    PRIMARY KEY CLUSTERED ([ID] ASC)
            WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF,  
                  IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, 
                  ALLOW_PAGE_LOCKS = ON) 
) 
GO

ALTER TABLE [dbo].[Location] WITH CHECK 
   ADD CONSTRAINT [fk_location_location] 
   FOREIGN KEY([ParentID]) REFERENCES [dbo].[Location] ([ID]) …
Run Code Online (Sandbox Code Playgroud)

sql sql-server

3
推荐指数
1
解决办法
48
查看次数

使用componentDidUpdate反应无限循环

我正在尝试创建一个基本的向导,有3个步骤.在我的根文件中,我在构造函数中设置了我的状态:

constructor(props) {
    super(props);
    this.state = {
      currentStep: 1,
      data: {
        firstname: 'James',
        surname: 'Smith',
        country: 'Australia',
      },
    };
Run Code Online (Sandbox Code Playgroud)

我的向导有3个"步骤",这是我如何渲染一个的例子:

<DataEntry currentStep={this.state.currentStep} data={this.state.data} afterValidate={this._nextStep} moveBack={this._prevStep} />
Run Code Online (Sandbox Code Playgroud)

然后在这一步中,我的构造函数是:

  constructor(props) {
    super(props);
    this.state = { data: this.props.data };
    this._validate = this._validate.bind(this);
    console.log(this.state);
  }
Run Code Online (Sandbox Code Playgroud)

所以我根据我传入的道具"数据"来设置步骤的状态.

我的onChange是通用的,所以每个'field'都有一个onchange,这样做:

  onChange(fieldName, fieldValue) {
    const thisData = { ...this.state.data, [fieldName]: fieldValue };
    this.setState({ data: thisData });
  }
Run Code Online (Sandbox Code Playgroud)

当我使用"下一步"按钮移动到下一步时,我在"步骤"组件中调用一个方法:

  _validate() {
    console.log('Validating...');
    this.props.afterValidate(this.state.data);
  }
Run Code Online (Sandbox Code Playgroud)

这会调用我父组件中的方法来更新数据:

  _nextStep(data) {
    console.log('Next');
    let currentStep = this.state.currentStep;
    console.log(currentStep);
    currentStep = currentStep >= 2 ? …
Run Code Online (Sandbox Code Playgroud)

javascript reactjs

3
推荐指数
1
解决办法
825
查看次数

如何在.net Core 2.2中实现JWT令牌

我已经为此奋斗了几个小时,似乎无法追踪为什么我对[Authorize]启用的端点的所有呼叫均因401而失败。

在我的.Net Core 2.2 Web API项目中,在Startup.cs中,我设置了身份验证:

public void ConfigureServices(IServiceCollection services)
        {
            var jwtSettings = new JwtSettings();
            Configuration.Bind(nameof(jwtSettings), jwtSettings);
            services.AddSingleton(jwtSettings);

            services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);

            // Add the JWT Bearer token configuration
            services.AddAuthentication(x =>
            {
                x.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
                x.DefaultScheme = JwtBearerDefaults.AuthenticationScheme;
                x.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme;
            })
            .AddJwtBearer(x =>
            {
                x.SaveToken = true;
                x.TokenValidationParameters = new TokenValidationParameters
                {
                    ValidateIssuerSigningKey = true,
                    IssuerSigningKey = new SymmetricSecurityKey(Encoding.ASCII.GetBytes("craigcraigcraigcraigcraigcraig")),//jwtSettings.Secret)),
                    ValidateIssuer = false,
                    ValidateAudience = false,
                    RequireExpirationTime = false,
                    ValidateLifetime = true
                };
            });

            services.AddSwaggerGen(x =>
            {
                x.SwaggerDoc("v1", new Info …
Run Code Online (Sandbox Code Playgroud)

c# jwt

3
推荐指数
1
解决办法
190
查看次数