Hi people! I am pretty new in all this. And I don't have so much time because of my little baby. I appreciate any help I can get.
Here is the code.
XAML:
<window x:class="Aukcija1.MainWindow" xmlns:x="#unknown">
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Auctions" Height="350" Width="525">
xmlns:wf="clr-namespace:System.Windows.Forms;assembly=System.Windows.Forms">
<grid>
DataContext="{Binding}">
<datagrid> AutoGeneratedColumns="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=auction_ID}" header="Auction ID" width="SizeToHeader" />
<datagridtextcolumn x:name="artikalNameColumn" binding="{Binding Path=item_name}" header="Item Name" width="SizeToHeader" />
<datagridtextcolumn x:name="pocetnacijenaColumn" binding="{Binding Path=start_price}" header="Start Price" width="SizeToHeader" />
<datagridtextcolumn x:name="trenutnacijenaColumn" binding="{Binding Path=current_price}" 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>
</window>
C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Data.SqlClient;
using System.Data;
using System.Windows.Threading;
using System.Windows.Forms;
using System.Timers;
namespace Aukcija1
{
public partial class MainWindow : Window
{
DispatcherTimer timer;
int interval;
int step;
public MainWindow()
{
interval = 1001;
step = 20;
timer = new DispatcherTimer();
timer.Interval = TimeSpan.FromMilliseconds(interval);
timer.Start();
timer.Tick += new EventHandler(timer_Tick);
DataTable AuctionsTable = new DataTable();
SqlConnection conn = new SqlConnection(@"datasource=(local);database=Aukcija;integrated security=true;");
SqlDataAdapter aukcDa = new SqlDataAdapter("select * from auctions", conn);
aukcDa.Fill(AuctionsTable);
aukcija_bazeDataGrid.DataContext = AuctionsTable;
}
private void InitializeComponent()
{
throw new NotImplementedException();
}
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, SelectedCellsChangedEventArgs e)
{
using (SqlConnection conn = new SqlConnection())
{
conn.ConnectionString = (@"datasource=(local);database=Aukcija;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)
{
Form1 popup = new Form1();
popup.ShowDialog();
popup.Dispose();
}
private void button3_Click(object sender, RoutedEventArgs e)
{
Form2 popup = new Form2();
popup.ShowDialog();
popup.Dispose();
}
private void button2_Click(object sender, RoutedEventArgs e)
{
using (SqlConnection conn = new SqlConnection())
{
conn.ConnectionString = (@"datasource=(local);database=Aukcija;integrated secutiry=true;");
SqlCommand command = conn.CreateCommand();
command.CommandType = CommandType.StoredProcedure;
command.CommandText = "uspPovecajCenuArtiklaZaJedan";
command.Parameters.AddWithValue("@auction_ID", 1);
conn.Open();
command.ExecuteNonQuery();
}
}
private void loadGrid()
{
SqlConnection con = new SqlConnection(@"datasource=(local);database=Aukcija;integrated secutiry=true;");
SqlDataAdapter ad = new SqlDataAdapter();
SqlCommand cmd = new SqlCommand();
con.Open();
string strQuery = "select * from Auctions";
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, SelectedCellsChangedEventArgs e)
{
}
public UIElement button1 { get; set; }
}
}
SQL table:
Auctions (auction_ID, item_name, start_price, current_price).
I got these errors:
The name 'aukcija_bazeDataGrid' does not exist in the current context
The object 'Window' already has a child and cannot add ''. 'Window' can accept only one child. The property 'Content' is set more than once.