Dispatcher WPF应用程序,添加调度程序

Dispatcher WPF应用程序,添加调度程序,dispatcher,Dispatcher,我必须添加代码以每1秒刷新一次应用程序。我还需要设置按钮新拍卖只由管理员使用,按钮出价只由用户。我已经创建了usersuserID、userName、userPassword和userLevel表。 这就是我到目前为止所做的: <Window x:Class="WpfApplication1.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http:

我必须添加代码以每1秒刷新一次应用程序。我还需要设置按钮新拍卖只由管理员使用,按钮出价只由用户。我已经创建了usersuserID、userName、userPassword和userLevel表。 这就是我到目前为止所做的:

<Window x:Class="WpfApplication1.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="Auction" Height="350" Width="525"
    xmlns:wf="clr-namespace:System.Windows.Forms;assembly=System.Windows.Forms"
    >

<Grid DataContext="{Binding}">
    <DataGrid AutoGenerateColumns="False" EnableRowVirtualization="True" Height="264" HorizontalAlignment="Left" ItemsSource="{Binding}" Name="aukcija_bazeDataGrid" RowDetailsVisibilityMode="VisibleWhenSelected" VerticalAlignment="Top" Width="503" SelectionChanged="aukcija_bazeDataGrid_SelectionChanged">
        <DataGrid.Columns>
            <DataGridTextColumn x:Name="aukcijaIdColumn" Binding="{Binding Path=AukcijaID}" Header="Auction ID" Width="SizeToHeader" />
            <DataGridTextColumn x:Name="artikalNameColumn" Binding="{Binding Path=ProizvodIme}" Header="Item Name" Width="SizeToHeader" />
            <DataGridTextColumn x:Name="pocetnacenaColumn" Binding="{Binding Path=PocetnaCena}" Header="Start Price" Width="SizeToHeader" />
            <DataGridTextColumn x:Name="trenutnacenaColumn" Binding="{Binding Path=TrenutnaCena}" Header="Current Price" Width="SizeToHeader" />
        </DataGrid.Columns>
    </DataGrid>
    <Button Content="Login" Height="23" HorizontalAlignment="Left" Margin="331,276,0,0" Name="button1" VerticalAlignment="Top" Width="75" Click="button1_Click" />
    <Button Content="New Auction" Height="23" HorizontalAlignment="Left" Margin="416,276,0,0" Name="button3" VerticalAlignment="Top" Width="75" Click="button3_Click" />
    <Button Content="Bid price" Height="23" HorizontalAlignment="Left" Margin="12,276,0,0" Name="button2" VerticalAlignment="Top" Width="75" Click="button2_Click" />
</Grid>
} 问题是我不知道在Dispatchermer\u中写什么才能让它工作

namespace WpfApplication1
{

public partial class MainWindow : Window
{

    DispatcherTimer timer;
    int interval;
    int step;

    public MainWindow()
    {
        InitializeComponent();

        interval = 1001;
        step = 20;
        timer = new DispatcherTimer();
        timer.Interval = TimeSpan.FromMilliseconds(interval);
        timer.Start();
        timer.Tick += new EventHandler(timer_Tick);

        DataTable aukcijeTable = new DataTable();
        SqlConnection conn = new SqlConnection(@"data source=JOVAN\SQLEXPRESS1;database=AukcijskaProdaja;integrated security=true;");
        SqlDataAdapter aukcDa = new SqlDataAdapter("select * from Aukcija", conn);

        aukcDa.Fill(aukcijeTable);
        aukcija_bazeDataGrid.DataContext = aukcijeTable;


    }



    void timer_Tick(object sender, EventArgs e)
    {
        if (Canvas.GetLeft(button1) > 400)
            timer.Stop();
        step = (step > 1) ? (step -= 1) : 1;
        Canvas.SetLeft(button1, Canvas.GetLeft(button1) + step);
        if (interval > 1)
            timer.Interval = TimeSpan.FromMilliseconds(interval -= 100);
    }

    private void listBox1_SelectionChanged(object sender, SelectionChangedEventArgs e)
    {
        using (SqlConnection conn = new SqlConnection())
        {
            conn.ConnectionString = (@"data source=JOVAN\SQLEXPRESS1;database=AukcijskaProdaja;integrated security=true;");

            SqlCommand command = conn.CreateCommand();
            command.CommandType = CommandType.StoredProcedure;
            command.CommandText = "uspPovecajCenuArtiklaZaJedan";
            command.Parameters.AddWithValue("@auction_ID", aukcija_bazeDataGrid.SelectedValue);
            conn.Open();
            command.ExecuteNonQuery();
        }
    }

    private void button1_Click(object sender, RoutedEventArgs e)
    {
        Form popup = new Form();
        popup.ShowDialog();

        popup.Dispose();
    }

    private void button3_Click(object sender, RoutedEventArgs e)
    {
        Form popup = new Form();
        popup.ShowDialog();

        popup.Dispose();
    }

    private void button2_Click(object sender, RoutedEventArgs e)
    {
        using (SqlConnection conn = new SqlConnection())
        {
            conn.ConnectionString = (@"data source=JOVAN\SQLEXPRESS1;database=AukcijskaProdaja;integrated security=true;");

            SqlCommand command = conn.CreateCommand();
            command.CommandType = CommandType.StoredProcedure;
            command.CommandText = "uspPovecajCenuArtiklaZaJedan";
            command.Parameters.AddWithValue("@ArtikalID", 1);
            conn.Open();
            command.ExecuteNonQuery();
        }
    }

    private void loadGrid()
    {
        SqlConnection con = new SqlConnection(@"data source=JOVAN\SQLEXPRESS1;database=AukcijskaProdaja;integrated security=true;");
        SqlDataAdapter ad = new SqlDataAdapter();
        SqlCommand cmd = new SqlCommand();
        con.Open();
        string strQuery = "select * from Aukcija";
        cmd.CommandText = strQuery;
        ad.SelectCommand = cmd;
        cmd.Connection = con;
        DataSet ds = new DataSet();
        ad.Fill(ds);
        aukcija_bazeDataGrid.DataContext = ds.Tables[0].DefaultView;
        con.Close();
    }

    private void aukcija_bazeDataGrid_SelectionChanged(object sender, SelectionChangedEventArgs e)
    {


    }
    private void Window_Loaded(object sender, RoutedEventArgs e)
    {
        DispatcherTimer dispatcherTimer = new DispatcherTimer();
        dispatcherTimer.Tick += new EventHandler(dispatcherTimer_Tick);
        dispatcherTimer.Interval = new TimeSpan(0, 0, 1);
        dispatcherTimer.Start();
    }
    private void dispatcherTimer_Tick(object sender, EventArgs e)
    {

    }
}