wpf aplikacija,aukcija,c#

jackouu

Početnik
Poruka
2
Pozdrav ljudi,trebam pomoć pa ko je voljan hvala mu mnogo....radi se o wpf aplikaciji aukcijska prodaja,već sa pojavljivala tema po sloro svim forumima pa i ovom...

dole su kodovi a trenutno mi izbacuje sl error:
the name 'conn' does not exist in the current context

osim ove greške ne mogu da ubacim podatke u sql bazu sa dole postojećim kodom
takođe mi nije jasno kako da postavim timer metodu ili dispatcher da kad čovjek postavi ponudu za neki artikal
cijena tog artikla se poveća za 1 i počne timer da odbrojava unazad 2 minute,a onda isoči poruka aukcija je uspješno završena ???!!!


xaml.cs:
..................................................

<Window x:Class="WpfApplication4.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" Height="450" Width="550" xmlns:my="clr-namespace:WpfApplication4" Loaded="Window_Loaded">
<Window.Resources>
<my:AukcijaDataSet x:Key="aukcijaDataSet" />
<CollectionViewSource x:Key="aukcija_bazeViewSource" Source="{Binding Path=Aukcija_baze, Source={StaticResource aukcijaDataSet}}" />
</Window.Resources>
<Grid DataContext="{StaticResource aukcija_bazeViewSource}">
<DataGrid AutoGenerateColumns="False" EnableRowVirtualization="True" Height="136" HorizontalAlignment="Left" ItemsSource="{Binding}" Margin="78,22,0,0" Name="aukcija_bazeDataGrid" RowDetailsVisibilityMode="VisibleWhenSelected" VerticalAlignment="Top" Width="391">
<DataGrid.Columns>
<DataGridTextColumn x:Name="aukcijaIdColumn" Binding="{Binding Path=AukcijaId}" Header="Aukcija Id" Width="SizeToHeader" />
<DataGridTextColumn x:Name="artikalNameColumn" Binding="{Binding Path=ArtikalName}" Header="Artikal Name" Width="SizeToHeader" />
<DataGridTextColumn x:Name="cijenaColumn" Binding="{Binding Path=Cijena}" Header="Cijena" Width="SizeToHeader" />
</DataGrid.Columns>
</DataGrid>
<Label Content="AukcijaId" Height="23" HorizontalAlignment="Left" Margin="69,268,0,0" Name="label1" VerticalAlignment="Top" Width="83" />
<Label Content="ArtikalName" Height="24" HorizontalAlignment="Left" Margin="154,267,0,0" Name="label2" VerticalAlignment="Top" Width="68" />
<TextBox Height="23" HorizontalAlignment="Left" Margin="69,240,0,0" Name="AukcijaId" VerticalAlignment="Top" Width="63" DataContext="{Binding Path=aukcijaIdColumn}" />
<TextBox Height="23" HorizontalAlignment="Left" Margin="154,240,0,0" Name="ArtikalName" VerticalAlignment="Top" Width="68" DataContext="{Binding Path=artikalNameColumn}"/>
<Button Content="Ponuda" Height="26" HorizontalAlignment="Left" Margin="242,240,0,0" Name="button1" VerticalAlignment="Top" Width="68" Click="button1_Click" />
<Label Content="Vrijeme" HorizontalAlignment="Left" Margin="378,240,0,148" Name="label4" Width="81" />
<Label Content="Unesi ponudu" Height="28" HorizontalAlignment="Left" Margin="69,206,0,0" Name="label5" VerticalAlignment="Top" Width="83" />
<ListBox Height="38" HorizontalAlignment="Left" Margin="78,153,0,0" Name="listBox1" VerticalAlignment="Top" Width="391" />
</Grid>
</Window>


xaml.cs:
..................................................

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.Shapes;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Timers;
using System.Windows.Threading;

namespace WpfApplication4
{
/// <summary>
/// Interaction logic for Window1.xaml
/// </summary>
public partial class Window1 : Window
{
public Window1()
{
InitializeComponent();
}

private void Window_Loaded(object sender, RoutedEventArgs e)
{

WpfApplication4.AukcijaDataSet aukcijaDataSet = ((WpfApplication4.AukcijaDataSet)(this.FindResource("aukcijaDataSet")));
// Load data into the table Aukcija_baze. You can modify this code as needed.
WpfApplication4.AukcijaDataSetTableAdapters.Aukcija_bazeTableAdapter aukcijaDataSetAukcija_bazeTableAdapter = new WpfApplication4.AukcijaDataSetTableAdapters.Aukcija_bazeTableAdapter();
aukcijaDataSetAukcija_bazeTableAdapter.Fill(aukcijaDataSet.Aukcija_baze);
System.Windows.Data.CollectionViewSource aukcija_bazeViewSource = ((System.Windows.Data.CollectionViewSource)(this.FindResource("aukcija_bazeViewSource")));
aukcija_bazeViewSource.View.MoveCurrentToFirst();
}

public void BindMyData()
{
try
{
conn.Open();
SqlCommand comm = new SqlCommand("SELECT * FROM Aukcija_baze", conn);
DataSet ds = new DataSet();
SqlDataAdapter da = new SqlDataAdapter(comm);
da.Fill(ds);
aukcija_bazeDataGrid.ItemsSource = ds.Tables[0].DefaultView;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message.ToString());
}
finally
{
conn.Close();
}

BindMyData();
}

private void button1_Click(object sender, RoutedEventArgs e)
{
try
{
conn.Open();
SqlCommand comm = new SqlCommand("INSERT INTO Aukcija_baze VALUES(" + AukcijaId.Text + ",'" + ArtikalName.Text + "'," , conn);
comm.ExecuteNonQuery();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message.ToString());
}
finally
{
conn.Close();
BindMyData();
}

{
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)
{



}

}

}
 
Joj nepregledno je, stavi to u code tag...

Normalno da dobijas gresku kada nisi definisao SqlConnection

stavi gore
SqlConnection conn = new SqlConnection(conString);

za tajmer stavi negde probaj nesto ovako, ali nadam se da razumes da umesto ovog stringa gde sam ja stavio 30000 ti treba da se povezes na bazu, i namestis da pri svakoj promeni textbox-a "alterujes" tabelu, i refresujes textbox da izvuce novu vrednost...

Kod:
public Form1()
        {
            InitializeComponent();
            textBox1.Text = "30000"; //povezati sa bazom, bind textbox
            timer1.Interval = 120000; //2 min == 120 000 milisekundi
        }
        int i = 0;
        private void button1_Click(object sender, EventArgs e)
        {
            i++;
            int cena = Convert.ToInt32(textBox1.Text);
            cena += i;
            textBox1.Text = cena.ToString(); //poslati novu vrednost textboxa u bazu, "alter table"
            timer1.Start();
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            MessageBox.Show("Aukcija uspesno obavljena");
            timer1.Stop();
        }

Unapred da znas, na Krsti nemoj objavljivati nijedan problem vezan za programiranje, jer odgovor neces dobiti dugo vremena, Krsta jopsti forum i nije specijalizovan samo za PC, za to postoji elitesecurity, ili ako znas Engleski dreamincode, ili najbolji stackoverflow, odgovor dobijas za 10 min maksimalno. :)
 
Poslednja izmena:

Back
Top