小编Nil*_*rai的帖子

将数据表拆分为多个固定大小的表

我有一个有1123条记录的数据表.我想将此表拆分为5个固定大小的单独数据表.每张表的大小限制为225.

因此产生的数据表的大小将是:

DT1 : 225 rows
DT2 : 225 rows
DT3 : 225 rows
DT4 : 225 rows
DT5 : 223 rows (remaining rows)
Run Code Online (Sandbox Code Playgroud)

我能找到如何基于使用LINQ列值拆分数据表在这里.

我还发现了一种分裂的数据表到多个表在这里.想知道是否有更好的方法来做到这一点.从链接发布代码:

private static List<DataTable> SplitTable(DataTable originalTable, int batchSize)
{
     List<DataTable> tables = new List<DataTable>();
     int i = 0;
     int j = 1;
    DataTable newDt = originalTable.Clone();
   newDt.TableName = "Table_" + j;
   newDt.Clear();
    foreach (DataRow row in originalTable.Rows)
    {
         DataRow newRow = newDt.NewRow();
         newRow.ItemArray = row.ItemArray;
         newDt.Rows.Add(newRow);
         i++;
         if (i == batchSize) …
Run Code Online (Sandbox Code Playgroud)

c# linq datatable

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

C#WPF实时图表-一般创建图表

我正在使用WPF Live Charts库。我正在尝试一般地创建条形图。

以下是我的代码。由于它不支持泛型,因此无法在XAML中完成。

public abstract class AbstractGenericBarChart<T> : UserControl, INotifyPropertyChanged
{
    SeriesCollection _SeriesCollection;
    public SeriesCollection SeriesCollection { get { return _SeriesCollection; } set { _SeriesCollection = value; notifyPropertyChanged("SeriesCollection"); } }
    string[] _Labels;
    public string[] Labels { get { return _Labels; } set { _Labels = value; notifyPropertyChanged("Labels"); } }
    Func<int, string> _Formatter;
    public Func<int, string> Formatter { get { return _Formatter; } set { _Formatter = value; notifyPropertyChanged("Formatter"); } }

    public abstract void constructChart(List<T> chartItems);

    public void init(string xLabel, …
Run Code Online (Sandbox Code Playgroud)

c# wpf

7
推荐指数
1
解决办法
162
查看次数

按索引获取DataGrid

我试图DataGridRow从我DataGrid的索引中获取.我使用以下代码:

public DataGridRow GetGridRow(int index)
{
    DataGridRow row = (DataGridRow)DG_Statement.ItemContainerGenerator.ContainerFromIndex(index);
    if (row == null)
    {
        // May be virtualized, bring into view and try again.
        DG_Statement.UpdateLayout();
        DG_Statement.ScrollIntoView(DG_Statement.Items[index]);
        row = (DataGridRow)DG_Statement.ItemContainerGenerator.ContainerFromIndex(index);
    }
    return row;
}
Run Code Online (Sandbox Code Playgroud)

参考链接 - 获取数据网格中的行

但不幸的是它返回了一个null对象DataGridRow.如果我检查Items[]我的网格的属性,我可以看到13项.

需要建议如何获取网格行,因为我想要更改数据网格的前2行和后2行的颜色.

任何帮助表示赞赏.谢谢!!

添加DataGrid项的屏幕截图

在此输入图像描述

重要更新

如果我从Grid的SelectedIndexChanged事件中调用GetGridRow(),它可以完美地工作.

另一方面,如果我在构造显示网格的页面的对象之后调用它,则将行对象返回为NULL.

.net c# wpf xaml

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

在C#中使用PrintSpoolerAPI函数SetForm()

我正在开发一个Windows窗体应用程序,我想在其中打印自定义文档.此自定义文档具有自定义大小,我必须使用C#代码设置默认的打印页面大小.

我做了一些谷歌搜索并遇到了PrintSpoolerAPI.我找到的代码将使用AddForm()方法将自定义表单/页面添加到可用页面列表以进行打印.我还想将这个新添加的页面设置为默认打印页面.

我试着在代码中写这一行

bool x = SetForm(hPrinter, paperName, 1, ref formInfo);
Run Code Online (Sandbox Code Playgroud)

它返回一个true值但不设置默认打印页面.

dmPaperSize在这方面有任何作用吗?

这是完整的代码:

using System;
using System.Text;
using System.Runtime.InteropServices;
using System.Security;
using System.ComponentModel;
using System.Drawing.Printing;

namespace WindowsFormsApplication1
{
    public class CustomPrintForm
    {
        [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
        internal struct structPrinterDefaults
        {
            [MarshalAs(UnmanagedType.LPTStr)]
            public String pDatatype;
            public IntPtr pDevMode;
            [MarshalAs(UnmanagedType.I4)]
            public int DesiredAccess;
        };

    [DllImport("winspool.Drv", EntryPoint = "OpenPrinter", SetLastError = true,
         CharSet = CharSet.Unicode, ExactSpelling = false, CallingConvention = CallingConvention.StdCall),
    SuppressUnmanagedCodeSecurityAttribute()]
    internal static …
Run Code Online (Sandbox Code Playgroud)

c# printing print-spooler-api

6
推荐指数
1
解决办法
1809
查看次数

在 WPF ComboBox 中设置默认值

我正在使用 ComboBox ItemsSource 属性绑定来显示从列表到组合框的项目。

以下是代码:

<ComboBox x:Name="Cmb_Tax" ItemsSource="{Binding TaxList}" 
            DisplayMemberPath="ChargeName" SelectedItem="{Binding 
            SelectedTax,UpdateSourceTrigger=PropertyChanged}" IsEditable="True" 
            IsTextSearchEnabled="True" SelectionChanged="Cmb_Tax_SelectionChanged"/>

Classes.Charges _selected_tax = new Classes.Charges();
public Classes.Charges SelectedTax
{
    get
    {
        return _selected_tax;
    }
    set
    {
        _selected_tax = value;
    }
}

List<Classes.Charges> _taxlist = new List<Classes.Charges>();
public List<Classes.Charges> TaxList
{
    get
    {
        return _taxlist;
    }
    set
    {
        _taxlist = value;
        OnPropertyChanged("TaxList");
    }
}
Run Code Online (Sandbox Code Playgroud)

它正确显示组合框中的项目。

TaxList 中有一个特定项目"No Tax",我希望在组合框中默认选择它。该项目可以出现在列表中的任何索引处(不需要列表的第一项或最后一项)。

我正在尝试使用以下代码来设置组合框的选定索引属性,但遗憾的是它不起作用。

TaxList = Classes.Charges.GetChargeList("Tax");
Cmb_Tax.DataContext = this;            
int i = TaxList.FindIndex(x => x.ChargeName == tax_name);
Cmb_Tax.SelectedIndex …
Run Code Online (Sandbox Code Playgroud)

.net c# wpf

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

Mockito如何验证Lamba功能

我正在尝试测试以下方法:

public void execute(Publisher<T> publisher) throws Exception {
    PublishStrategy<T> publishStrategy = publisher.getPublishStrategy();
    publishStrategy.execute(publisher::executionHandler);
}
Run Code Online (Sandbox Code Playgroud)

以下是Junit代码:

@Test
public void testExecute() throws Exception {
    PublishStrategy<Event> publishStrategy = Mockito.mock(PublishStrategy.class);
    Publisher<Event> publisher = Mockito.mock(Publisher.class);
    Mockito.when(publisher.getPublishStrategy()).thenReturn(publishStrategy);
    Mockito.doNothing().when(publishStrategy).execute(publisher::executionHandler);
    PublishJob job = new PublishJob(publisher);
    job.execute(publisher);
    Mockito.verify(publishStrategy, Mockito.times(1)).execute(publisher::executionHandler);
}
Run Code Online (Sandbox Code Playgroud)

在verify方法调用上,我得到以下模仿异常:

Argument(s) are different! Wanted:
publishStrategy.execute(
    com.test.producer.jobs.PublishJobTest$$Lambda$3/1146825051@6f45df59
);
-> at com.test.producer.jobs.PublishJobTest.testExecute(PublishJobTest.java:23)
Actual invocation has different arguments:
publishStrategy.execute(
    com.producer.jobs.PublishJob$$Lambda$2/1525409936@38e79ae3
);
-> at com.producer.jobs.PublishJob.execute(PublishJob.java:30)
Run Code Online (Sandbox Code Playgroud)

我不明白为什么Mockito认为两个Lambda都不同?

更新 我不使用解决了它Mockito

这是另一种方法。Omitted empty overridden methods

@Test
public void testExecute() throws Exception …
Run Code Online (Sandbox Code Playgroud)

java junit mockito

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

向datatemplate添加按钮并调用其click事件

我正在尝试构建一个WPF应用程序(使用C#.net),其中我想在ListBox中添加按钮.

这是我放在资源字典中的数据模板

<DataTemplate x:Key="MYTemplate">
    <StackPanel Margin="4">
        <DockPanel>
            <TextBlock Text="ISBN No:" DockPanel.Dock="Left" Margin="5,0,10,0" Foreground="AliceBlue" />
            <TextBlock Text="            " />
            <TextBlock Text="{Binding ISBN}" Foreground="LimeGreen" FontWeight="Bold" />
        </DockPanel>
        <DockPanel>
            <TextBlock Text="Book Name:" DockPanel.Dock="Left" Margin="5,0,10,0" Foreground="AliceBlue"/>
            <TextBlock Text="       " />
            <TextBlock Text="{Binding BookName}" Foreground="LimeGreen"  FontWeight="Bold" />
        </DockPanel >
        <DockPanel >
            <TextBlock Text="Publisher Name:" DockPanel.Dock="Left" Margin="5,0,10,0" Foreground="AliceBlue" />
            <TextBlock Text=" " />
            <TextBlock Text="{Binding PublisherName}" Foreground="LimeGreen" FontWeight="Bold"  />
        </DockPanel>
        <DockPanel>
            <Button Name="MyButton" Content="Click Me">

            </Button>
        </DockPanel>
    </StackPanel>
</DataTemplate>
Run Code Online (Sandbox Code Playgroud)

如何将click事件添加到上述模板中的button标签?另外,我应该在何处放置单击按钮时将调用的方法.

.net c# wpf xaml visual-studio-2010

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

SQL Server CE - 无法在BIT列中插入值

我在SQL Server CE 3.5中创建了一个小表

以下是表格说明:

ROW_ID NVARCHAR(30),
NAME NVARCHAR(30),
TEST BIT
Run Code Online (Sandbox Code Playgroud)

我使用以下查询在表中插入记录:

insert into EMP(ROW_ID, NAME, TEST)
values('123', 'XYZ', TRUE);
Run Code Online (Sandbox Code Playgroud)

但我收到一个奇怪的错误:

错误消息:列名无效.[节点名称(如果有)=,列名= TRUE]

请帮我解决一下这个.

提前致谢.

sql sql-server sql-server-ce-3.5

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

如何在C#中使图表图例项交互

我在运行时使用win表单(C#.Net Framework 3.5)创建了一个图表.

在此输入图像描述

我想让这个图表的图例项目互动.

我的要求是,当用户点击图例中的颜色项目时 - 应打开颜色托盘,当用户从托盘中选择颜色时,所选颜色应应用于外部系列数据项.

我该如何实现这一目标?简而言之,如何为图例项添加单击事件处理程序?

任何帮助表示赞赏.NB

c# charts mschart winforms

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

直接打印 RDLC 报告而不显示报告查看器

我正在 WPF C# 4.0 项目中工作,在该项目中我试图打印 RDLC 报告,该报告基本上是直接发票而不显示 ReportViewer。我参考了以下MSDN 链接中的代码并根据我的目的对其进行了修改。

以下是我正在使用的修改后的代码。

using System;
using System.IO;
using System.Data;
using System.Text;
using System.Drawing.Imaging;
using System.Drawing.Printing;
using System.Collections.Generic;
using System.Windows.Forms;
using Microsoft.Reporting.WinForms;
using System.Xml;
using System.Resources;
using System.Drawing;
using System.Reflection;

namespace POS.Classes
{
    public class DirectReportPrint : IDisposable
    {
        private double[] PageBounds = { 0,0,0,0,0,0};
        private int m_currentPageIndex;
        private IList<Stream> m_streams;

        private DataTable _table = new DataTable();
        /// <summary>
        /// Must set this to get the report data
        /// </summary>
        public DataTable …
Run Code Online (Sandbox Code Playgroud)

.net c# wpf reportviewer rdlc

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