Navigacija
Lista poslednjih: 16, 32, 64, 128 poruka.

Administracija korisnika

[es] :: .NET :: WPF Programiranje :: Administracija korisnika

Strane: 1 2

[ Pregleda: 3376 | Odgovora: 25 ] > FB > Twit

Postavi temu Odgovori

Autor

Pretraga teme: Traži
Markiranje Štampanje RSS

Shadowed
Vojvodina

Član broj: 649
Poruke: 12611



+4573 Profil

icon Re: Administracija korisnika13.06.2018. u 21:51 - pre 20 meseci
Proveri SQL query.
 
Odgovor na temu

android27

Član broj: 338625
Poruke: 17
109.175.10.*



Profil

icon Re: Administracija korisnika19.06.2018. u 18:40 - pre 20 meseci
mozel mi neko dat primjer koda za edit dugme sto pravim ali da je malo lakse da kad pritisnem edit mogu izmjenit podatke u sql pokusavam pravit neke kodove ali nijedan nece ovo sam pravio i nije uspjelo

/code

private void Button_Click_1(object sender, RoutedEventArgs e)
{
SqlConnection conn = new SqlConnection();
conn.ConnectionString = ConfigurationManager.ConnectionStrings["ConnString"].ToString();

SqlConnection conn1 = new SqlConnection();
SqlDataAdapter ad = new SqlDataAdapter();
SqlCommand cmd = new SqlCommand();
String str = "UPDATE Username, Password, IsAdmin FROM ADMIN_1";
cmd.Parameters.AddWithValue("@Username", this.txtUsername.Text);
cmd.Parameters.AddWithValue("@IsAdmin", this.txtIsAdmin.Text);
cmd.Parameters.AddWithValue("@Password", this.txtPassword.Text);
//add whatever parameters you required to update here
int rows = cmd.ExecuteNonQuery();
conn.Close();
}
}
}
 
Odgovor na temu

Shadowed
Vojvodina

Član broj: 649
Poruke: 12611



+4573 Profil

icon Re: Administracija korisnika19.06.2018. u 21:51 - pre 20 meseci
Nije ti dobar SQL query.
Pogledaj ovde primere za select, insert, update i delete (u ovom konkretnom slucaju za update).
 
Odgovor na temu

android27

Član broj: 338625
Poruke: 17
109.175.10.*



Profil

icon Re: Administracija korisnika21.06.2018. u 22:11 - pre 20 meseci
hvala vam na pomoci evo kod za ovu zadacu nadam se da ce pomoci drugima...

1. ovo je za prozor mainwindow.xaml kod

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
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.Configuration;

namespace wpfloginscreen
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
SqlConnection con;
DataTable dt;

public MainWindow()
{
InitializeComponent();

//Connect your access database
con = new SqlConnection();
con.ConnectionString = ConfigurationManager.ConnectionStrings["ConnString"].ToString();
BindGrid();
}

//Display records in grid
private void BindGrid()
{
SqlCommand cmd = new SqlCommand();
if (con.State != ConnectionState.Open)
con.Open();
cmd.Connection = con;
cmd.CommandText = "select * from ADMIN_1";
SqlDataAdapter da = new SqlDataAdapter(cmd);
dt = new DataTable();
da.Fill(dt);
gvData.ItemsSource = dt.AsDataView();

if (dt.Rows.Count > 0)
{
lblCount.Visibility = System.Windows.Visibility.Hidden;
gvData.Visibility = System.Windows.Visibility.Visible;
}
else
{
lblCount.Visibility = System.Windows.Visibility.Visible;
gvData.Visibility = System.Windows.Visibility.Hidden;
}

}

//Add records in grid
private void btnAdd_Click(object sender, RoutedEventArgs e)
{
SqlCommand cmd = new SqlCommand();
if (con.State != ConnectionState.Open)
con.Open();
cmd.Connection = con;

if (txtId.Text != "")
{
if (txtId.IsEnabled == true)
{
cmd.CommandText = "insert into ADMIN_1(Id,Username,Password,IsAdmin) Values(" + txtId.Text + ",'" + txtUsername.Text + "','" + txtPassword.Text + "','" + txtIsAdmin.Text + "')";
cmd.ExecuteNonQuery();
BindGrid();
MessageBox.Show("korisnik je uspjesno dodat...");
ClearAll();
}
else
{
cmd.CommandText = "update ADMIN_1 set Username='" + txtUsername.Text + "',Password='" + txtPassword.Text + "',IsAdmin='" + txtIsAdmin.Text + "' where Id=" + txtId.Text;
cmd.ExecuteNonQuery();
BindGrid();
MessageBox.Show("korisnicki podaci su azurirani...");
ClearAll();
}
}
else
{
MessageBox.Show("molimo dodajte Id.......");
}
}

//Clear all records from controls
private void btnCancel_Click(object sender, RoutedEventArgs e)
{
ClearAll();
}

private void ClearAll()
{
txtId.Text = "";
txtUsername.Text = "";
txtPassword.Text = "";
txtIsAdmin.Text = "";
btnAdd.Content = "Add";
txtId.IsEnabled = true;
}

//Edit records
private void btnEdit_Click(object sender, RoutedEventArgs e)
{
if (gvData.SelectedItems.Count > 0)
{
DataRowView row = (DataRowView)gvData.SelectedItems[0];
txtId.Text = row["Id"].ToString();
txtUsername.Text = row["Username"].ToString();
txtPassword.Text = row["Password"].ToString();
txtIsAdmin.Text = row["IsAdmin"].ToString();
txtId.IsEnabled = false;
btnAdd.Content = "Update";
}
else
{
MessageBox.Show("molimo izaberite korisnika iz liste...");
}
}

//Delete records from grid
private void btnDelete_Click(object sender, RoutedEventArgs e)
{
if (gvData.SelectedItems.Count > 0)
{
DataRowView row = (DataRowView)gvData.SelectedItems[0];

SqlCommand cmd = new SqlCommand();
if (con.State != ConnectionState.Open)
con.Open();
cmd.Connection = con;
cmd.CommandText = "delete from ADMIN_1 where Id=" + row["Id"].ToString();
cmd.ExecuteNonQuery();
BindGrid();
MessageBox.Show("korisnik uspjesno izbrisan...");
ClearAll();
}
else
{
MessageBox.Show("molimo izaberite korisnika iz liste...");
}
}

//Exit
private void btnExit_Click(object sender, RoutedEventArgs e)
{
Application.Current.Shutdown();
}
}
}

dole je xaml izgled aplikacije..

<Window x:Class="wpfloginscreen.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Code Scratcher WPF with access Add, Edit and Delete operations" Height="700" Width="900" Background="DarkOrange" WindowStartupLocation="CenterScreen" ResizeMode="NoResize" >
<Window.Resources>
<Style TargetType="TextBlock">
<Setter Property="FontSize" Value="20"/>
<Setter Property="Width" Value="160"/>
<Setter Property="Margin" Value="10"/>
</Style>
<Style TargetType="TextBox">
<Setter Property="FontSize" Value="20"/>
<Setter Property="Width" Value="250"/>
<Setter Property="Margin" Value="10"/>
</Style>
</Window.Resources>
<DockPanel Name="dockMain" VerticalAlignment="top" HorizontalAlignment="Center" LastChildFill="False">
<StackPanel>
<Label Content="Main Window" HorizontalAlignment="Center" FontSize="36" FontWeight="Bold"></Label>
<WrapPanel>
<TextBlock Text="ID : "/>
<TextBox Name="txtId" />
</WrapPanel>
<WrapPanel>
<TextBlock Text="User Name : "/>
<TextBox Name="txtUsername" />
</WrapPanel>
<WrapPanel>
<TextBlock Text="Password : "/>
<TextBox Name="txtPassword" />
</WrapPanel>
<WrapPanel>
<TextBlock Text="IsAdmin : "/>
<TextBox Name="txtIsAdmin" TextWrapping="Wrap" AcceptsReturn="True"/>
</WrapPanel>
<WrapPanel Margin="0" HorizontalAlignment="Center" Height="59">
<Button Name="btnAdd" Content="Add" FontSize="25" Width="120" Margin="5" Click="btnAdd_Click" />
<Button Name="btnEdit" Content="Edit" FontSize="25" Width="120" Margin="5" Click="btnEdit_Click" />
<Button Name="btnDelete" Content="Delete" FontSize="25" Width="120" Margin="5" Click="btnDelete_Click" />
<Button Name="btnCancel" Content="Cancel" FontSize="25" Width="120" Margin="5" Click="btnCancel_Click" />
<Button Name="btnExit" Content="Exit" FontSize="25" Width="120" Margin="5" Background="#400000" Foreground="Bisque" Click="btnExit_Click" />
</WrapPanel>
<Label Content="Nema Podataka." Name="lblCount" HorizontalAlignment="Center" FontSize="16" FontWeight="Bold" Foreground="#FFE10000"></Label>
<WrapPanel Margin="20" HorizontalAlignment="Center">
<DataGrid AutoGenerateColumns="True" Name="gvData" SelectionMode="Single" FontSize="15" Padding="5" Background="Black" />
</WrapPanel>
</StackPanel>
</DockPanel>
</Window>

za login screen napravite novi xaml i kod evo dole ispod je kod

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.Windows.Media.Animation;

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

private void btnSubmit_Click(object sender, RoutedEventArgs e)
{
SqlConnection sqlCon = new SqlConnection(@"Data Source=DESKTOP-AL48L30\SIDIKSQL; Initial Catalog=ADMIN_1; Integrated Security=True;");
try
{
if (sqlCon.State == ConnectionState.Closed)
sqlCon.Open();
String query = "SELECT COUNT(1) FROM ADMIN_1 WHERE [email protected] AND [email protected]";
SqlCommand sqlCmd = new SqlCommand(query, sqlCon);
sqlCmd.CommandType = CommandType.Text;
sqlCmd.Parameters.AddWithValue("@Username",txtUsername.Text);
sqlCmd.Parameters.AddWithValue("@Password", txtPassword.Password);
int count = Convert.ToInt32(sqlCmd.ExecuteScalar());
if (count == 1)
{
MainWindow dashboard = new MainWindow();
dashboard.Show();
this.Close();
}
else
{
MessageBox.Show("Username or password is incorrect.");
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
sqlCon.Close();
}
}

private void Image_MouseLeave(object sender, MouseEventArgs e)
{
Image img = (Image)sender;
DoubleAnimation animation = new DoubleAnimation(0,TimeSpan.FromSeconds(1));
img.BeginAnimation(Image.OpacityProperty, animation);
}

private void Image_MouseEnter(object sender, MouseEventArgs e)
{
Image img = (Image)sender;
DoubleAnimation animation = new DoubleAnimation(1, TimeSpan.FromSeconds(1));
img.BeginAnimation(Image.OpacityProperty, animation);
}
}
}

dole ispod xaml izgled aplikacije

<Window x:Class="wpfloginscreen.LoginScreen"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Login" Height="404.151" Width="303.813" FontSize="14" Background="Black">
<Border Background="#2e3137" CornerRadius="20" Margin="20,20,20,5">
<StackPanel Margin="20">
<Image Height="100" Margin="0,0,0,0" Source="3.png" Stretch="Fill" MouseLeave="Image_MouseLeave" MouseEnter="Image_MouseEnter"/>
<Button x:Name="btnSubmit" Click="btnSubmit_Click" Content="PRIJAVA" Margin="60 10" Background="#545d6a" Foreground="White" FontSize="18" RenderTransformOrigin="0.611,0.737"/>
<Separator/>
<Label Content="Username" Foreground="White"/>
<TextBox x:Name="txtUsername" Background="#545d6a" Foreground="White" FontSize="18"/>
<Label Content="Password" Foreground="White"/>
<PasswordBox x:Name="txtPassword" Background="#545d6a" Foreground="White" FontSize="18"/>
</StackPanel>
</Border>
</Window>


 
Odgovor na temu

android27

Član broj: 338625
Poruke: 17
109.175.10.*



Profil

icon Re: Administracija korisnika21.06.2018. u 22:12 - pre 20 meseci
trebace mi sad pomoc oko zadace aukcijska prodaja ko zna nek mi ode na novu temu sto cu otvorit
 
Odgovor na temu

computerinspector
Vlasnik i radnik firme
Computer Service Igor

Član broj: 339938
Poruke: 1
*.dynamic.isp.telekom.rs.



Profil

icon Re: Administracija korisnika12.03.2019. u 17:36 - pre 11 meseci
Pozdrav, ima li resenja aukcijske prodaje?
 
Odgovor na temu

[es] :: .NET :: WPF Programiranje :: Administracija korisnika

Strane: 1 2

[ Pregleda: 3376 | Odgovora: 25 ] > FB > Twit

Postavi temu Odgovori

Navigacija
Lista poslednjih: 16, 32, 64, 128 poruka.