小编Dbl*_*oom的帖子

在Powershell中,如何在函数中设置变量值并在父作用域中使用该值?

我试图使用函数设置一些变量的值.我的代码如下:

$BackupFile = $null
$TaskSequenceID = $null
$OSDComputerName = $null
$capturedWimPath = $null

Function Set-OsToBuild 
{
  switch ($OsToBuild)
  {
    "Win7x64"
        { 
            $BackupFile = "Win7x64-SP1.wim"
            $TaskSequenceID = "WIN7X64BC"
            $OSDComputerName = "Ref-Win7x64"
            $capturedWimPath = "$($PathToMdtShare)\Captures\$BackupFile"
        }
  }
}
Run Code Online (Sandbox Code Playgroud)

问题是$ BackupFile,$ TaskSequenceID,$ OSDComputerName和$ capturedWimPath的这些值在此函数之外是空白/ null.

这样做的正确方法是什么?我想在此函数中设置这些值,并在稍后的父作用域中的脚本中提供这些值.

variables powershell scope function

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

当我想加载另一个页面时,为什么会激活Page_Load事件?

对ASP来说很新,我觉得这是一个非常基本的问题.我在default.aspx.cs文件中有以下代码:

        protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            //Get one day ago
            DateTime oneDayAgo = DateTime.Now.ToLocalTime().AddDays(-1);
            String strOneDayAgo = oneDayAgo.ToString();

            //Declare the query string
            String queryString = "Select * from Computers Where whenCreated >= '" + strOneDayAgo + "' ORDER BY whenCreated DESC";

            //Show the query being used to the user
            lblQueryUsed.Text = queryString;

            // Run the query and bind the resulting DataSet to the GridView control.
            DataSet ds = GetData(queryString);
            if (ds.Tables.Count > 0)
            {
                GridView1.DataSource …
Run Code Online (Sandbox Code Playgroud)

c# asp.net events pageload

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

如何在If语句中评估Enum?

我想第一次将Enum实现到我的代码中.我有一个简单的自定义类,如下所示:

public class Application
{
    //Properties
    public string AppID { get; set; }
    public string AppName { get; set; }
    public string AppVer { get; set; }
    public enum AppInstallType { msi, exe }
    public string AppInstallArgs { get; set; }
    public string AppInstallerLocation { get; set; }
}
Run Code Online (Sandbox Code Playgroud)

我在该类中有一个名为Install()的方法,如下所示:

    public void Install()
    {
        if (AppInstallType.exe)
        {
            ProcessStartInfo procInfo = new ProcessStartInfo("cmd.exe");
            procInfo.Arguments = "/c msiexec.exe /i " + AppInstallerLocation + " " + AppInstallArgs; ;
            procInfo.WindowStyle = ProcessWindowStyle.Normal;

            Process …
Run Code Online (Sandbox Code Playgroud)

c# enums if-statement evaluate

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

在WPF中更改BitMapImage的尺寸,以及可以在<Image>元素中放置哪种对象?

我正在尝试使用TreeView元素创建一个资源管理器应用程序,并为树的每个级别提供不同的图标,并按照以下文章进行操作:http://www.codeproject.com/Articles/21248/A-Simple-WPF-Explorer -树

这一切都很好,除了我想要有不同大小的图标.

XAML的Image元素在这里:

<Image Name="img"
       Source="{Binding RelativeSource={RelativeSource Mode=FindAncestor,
       AncestorType={x:Type TreeViewItem}},
       Path=Header,
       Converter={x:Static local:HeaderToImageConverter.Instance}}"
/>
Run Code Online (Sandbox Code Playgroud)

决定返回哪个图标的代码片段在这里:

if ((value as string).Contains(@"\""))
{
    Uri uri = new Uri ("pack://application:,,,/Images/DeployWiz_Network.png");
    BitmapImage source = new BitmapImage(uri);

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

如何更改返回图像的尺寸?更改bitmapimage对象的尺寸似乎不起作用.我可以返回哪些其他图像对象作为源?

c# wpf treeview bitmapimage

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

在WPF数据网格中将Null或默认DateTime值显示为"空白"或NA

我有一个绑定到自定义对象的ObservableCollection的数据网格.其中一列绑定到DateTime属性,并且许多对象具有最小DateTime值.

在我的DataGrid中,这是我的DateTime列的代码

<DataGridTextColumn Binding="{Binding Path=StartTime, StringFormat={}{0:MM/dd/yyyy hh:mm:ss tt}}" Header="Start Time" Foreground="Black" Width="2*"/>
Run Code Online (Sandbox Code Playgroud)

如果日期为"1/1/1753 12:00:00 AM"或"1/1/0001 12:00,如何应用带有datatemplate的样式或可显示" - "或"NA"的东西:00:00"?

c# wpf datetime datagrid

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

Powershell变量被赋予函数的结果和传递给函数的参数I.

我在我的剧本中一遍又一遍地遇到这种情况.我有这行代码:

$Errors = Get-DeploymentErrors $uniqueID
Run Code Online (Sandbox Code Playgroud)

运行时,会为$ Errors分配Get-DeploymentErrors的结果和$ uniqueID的值.我只想为$ Errors分配Get-DeploymentErrors的结果.

以下是Get-DeploymentErrors函数:

Function Get-DeploymentErrors($uniqueID)
{
$Errors = @()

$conn = New-Object -TypeName System.Data.SqlClient.SqlConnection
$conn.ConnectionString = 'removed connection string'

$cmd = New-Object -TypeName System.Data.SqlClient.SqlCommand
$cmd.Connection = $conn
$cmd.CommandText = "removed sql statement"
$cmd.Parameters.AddWithValue("@uniqueID", $uniqueID)

$conn.Open()
$reader = $cmd.ExecuteReader()

if($reader.HasRows)
{
    While ($reader.Read())
    {
        $error = New-Object -TypeName PSObject

        $error | Add-Member -MemberType NoteProperty -Name StepID -Value $reader["StepID"]
        $error | Add-Member -MemberType NoteProperty -Name DeploymentID -Value $reader["DeploymentID"]
        $error | Add-Member -MemberType NoteProperty -Name MessageID …
Run Code Online (Sandbox Code Playgroud)

variables powershell pipeline function

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

WPF - DragOver 事件未在我的列表框上触发

我正在尝试在我的 WPF 应用程序中实现拖放功能。我有一个列表框,我希望能够从 Windows 资源管理器中删除文件。然后将这些文件添加到列表框中。我曾经按照本教程进行过这项工作:将文件拖放到 WPF 应用程序并异步上传到 ASP.NET Web API。减去上传到 web api 部分。我只想显示列表框中的文件。

问题是 DragOver 事件永远不会触发。我错过了什么?我早些时候有这个工作,但一些小的调整把它搞砸了。

这是我的 XAML(简化了父元素):

<Window>
  <Grid>
    <TabControl>
      <TabItem>
        <Grid>
          <GroupBox>
            <ListBox Name="lstTarget" AllowDrop="True"
                     Drop="lstTarget_Drop"
                     DragOver="lstTarget_DragOver"
                     DragLeave="lstTarget_DragLeave"
                     BorderThickness="3"
                     BorderBrush="Red"
                     >
            </ListBox>
Run Code Online (Sandbox Code Playgroud)

这是我的代码

private void lstTarget_Drop(object sender, DragEventArgs e)
{
    if (e.Data.GetDataPresent(DataFormats.FileDrop))
    {
        string[] files = (string[])e.Data.GetData(DataFormats.FileDrop);
        foreach (string filePath in files)
        {
            lstTarget.Items.Add(filePath);
        }
    }

    var listbox = sender as ListBox;
    listbox.Background = new SolidColorBrush(Color.FromRgb(226, 226, 226));
}
private void lstTarget_DragOver(object sender, DragEventArgs e)
{ …
Run Code Online (Sandbox Code Playgroud)

c# wpf xaml drag-and-drop listbox

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

使用MVC,如何基于<td>中包含的日期将某个类格式化为<tr>?

我有一个MVC应用程序,显示Windows部署的进度.在我看来,我有一个表格,显示每个部署的当前状态.其中一个属性是最后一次部署签入('CurrentTime').我想改变如果CurrentTime超过4小时前的风格.

在我的MVC视图中,我试图做这样的事情:

@foreach (var item in Model)
{
    if(item.CurrentTime < DateTime.Now.AddHours(-4))
    {
        @:<tr class="warning">
    }
    else
    {
        @:<tr>
    }
Run Code Online (Sandbox Code Playgroud)

这不起作用.我收到一个解析器错误:

遇到没有匹配开始标记的结束标记"tr".您的开始/结束标签是否正确平衡?

什么是简单的方法(我只是学习MVC /网络编程)来实现这一目标?

c# asp.net-mvc view razor

0
推荐指数
1
解决办法
1212
查看次数