我有一个按钮,单击该按钮将在SQL Server上运行存储过程,并在同一窗口的网格中显示结果数据.
在Windows窗体世界中,我创建一个数据表,使用dataadapter填充它,然后将数据表分配给我的DataGridView的DataSource属性和poof ...这是我的数据.
我在WPF中使用带有Gridview的ListView尝试了类似的东西,我似乎无法使其工作.我的XAML中有以下内容:
<ListView Grid.Row="1" Name="Preview" ItemsSource="{Binding Path=Report}">
<GridView>
<GridViewColumn Header="Name" DisplayMemberBinding="{Binding Path=FormalName}" />
</GridView>
</ListView>
Run Code Online (Sandbox Code Playgroud)
在我的C#代码中
private void CreateReport(object sender, RoutedEventArgs e)
{
DataTable dt = new DataTable("Report");
SqlConnection cn = new SqlConnection("Data Source=DailyTimesheets;
Initial Catalog=DailyTimesheets;Integrated Security=SSPI");
SqlCommand cm = new SqlCommand("Reports.PayrollHoursInterface", cn);
cm.Parameters.AddWithValue("@PayBatchID", 722);
cm.CommandType = CommandType.StoredProcedure;
SqlDataAdapter da = new SqlDataAdapter(cm);
da.Fill(dt);
Preview.DataContext=dt;
}
Run Code Online (Sandbox Code Playgroud)
当我单击按钮(触发CreateReport方法)时,我的数据表被填充并分配给Datacontext,但没有显示任何内容.
Visual Studio 2008中的ASP.Net应用程序
我正在创建单元测试来测试(在)Web应用程序的有效登录.我有一个Authenticate(User,Pass)bool方法.null case和无效密码测试正常工作.
我的问题是如何测试有效的登录.我有对Web应用程序有效的帐户,但我觉得用户名和密码硬编码可能不是最好的解决方案.
我想我可能要:创建一个测试用户授予用户访问web应用程序运行我的测试删除testuser
有更好的方法吗?
asp.net unit-testing active-directory visual-studio-2008 visual-studio
有没有办法将类添加到类中,但允许它仍然由基类继承?
我有以下内容
public class ListWithRandomize<T> : List<T> {
public void Randomize() { // Randomize function}
}
Run Code Online (Sandbox Code Playgroud)
我将要有一堆需要随机化的List对象.是否可以将List对象设置为ListFithRandomize对象?我想我可以将randomize函数设置为static并让它以List <>作为参数,但我希望将它作为类的方法...如果可能的话.
谢谢.
在 WPF 应用程序中,我有一个 ViewModel,它公开了一组字符串,我使用 WrapPanel 通过 ItemsControl 容器将这些字符串显示为按钮。但是,我无法将 ViewModel 中的 RelayCommand 绑定到按钮。
视图模型(事件地址视图模型):
public IEnumerable<string> Addresses { get; set; }
public RelayCommand<string> ZoomToAddressCommand { get {
if (this.zoomToAddressCommand == null) this.zoomToAddressComamnd = new RelayCommand<string>(this.ZoomToAddress);
return this.zoomToAddressCommand;
}}
private void ZoomToAddress(string address) { MessageBox.Show (address); }
Run Code Online (Sandbox Code Playgroud)
XAML:
<TabItem x:Name="IncidentAddressesTab">
<ItemsControl ItemsSource="{Binding Addresses}">
<i:Interaction.Triggers>
<i:EventTrigger EventName="Command">
<cmd:EventToCommand
Command="{Binding ZoomToAddressCommand}"
CommandParameter="{Binding Text}"
PassEventArgsToCommand="True"
/>
</i:EventTrigger>
</i:Interaction.Triggers>
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel Orientation="Vertical"/>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<Button Content="{Binding}" />
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</TabItem>
Run Code Online (Sandbox Code Playgroud)
连接 DataContext …
我正在创建一个月的日期列表.我想知道什么会更有效率
List<DateTime> GetDates(DateTime StartDay) {
List<DateTime> dates = new List<DateTime>();
int TotalDays=StartDay.AddMonths(1).AddDays(-1).Day;
for (int i=1; i<TotalDays; i++) {
dates.Add(new DateTime(StartDay.Year, StartDay.Month, i));
}
return dates;
}
Run Code Online (Sandbox Code Playgroud)
要么
List<DateTime> GetDates(DateTime StartDay) {
List<DateTime> dates = new List<DateTime>();
DateTime NextMonth = StartDay.AddMonths(1);
for (DateTime curr=StartDay; !curr.Equals(NextMonth); curr=curr.AddDays(1)) {
dates.Add(curr);
}
return dates;
}
Run Code Online (Sandbox Code Playgroud)
基本上,新的DateTime()或DateTime.addDays更有效率.
更新:
static void Main(string[] args) {
System.Diagnostics.Stopwatch sw=new System.Diagnostics.Stopwatch();
long t1, t2, total;
List<DateTime> l;
DateTime begin = DateTime.Now;
total = 0L;
for (int i=0; i<10; i++) { …
Run Code Online (Sandbox Code Playgroud) c# ×3
.net ×2
wpf ×2
asp.net ×1
data-binding ×1
datetime ×1
inheritance ×1
mvvm ×1
oop ×1
performance ×1
stopwatch ×1
unit-testing ×1