Professional Documents
Culture Documents
cs
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;
namespace CRUDWPF
{
/// <summary>
/// Logique d'interaction pour MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
LoadGrid();
}
}
private void ClearDataBtn_Click(object sender, RoutedEventArgs e)
{
clearData();
}
Fichier MainWindow.xaml
<Window x:Class="CRUDWPF.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
Title="MainWindow" Height="450" Width="900">
<Grid>
<Label Content="CRUD Operation in C#" HorizontalAlignment="Center" Margin="0,10,0,0"
VerticalAlignment="Top" RenderTransformOrigin="0.393,-0.05" Height="31" FontSize="16"/>
<Label Content="Name" HorizontalAlignment="Left" Margin="66,60,0,0" VerticalAlignment="Top"
RenderTransformOrigin="-0.16,-2.36" Height="36" FontSize="14"/>
<Label Content="Age" HorizontalAlignment="Left" Margin="66,101,0,0" VerticalAlignment="Top"
Height="36" FontSize="14"/>
<Label Content="Gender" HorizontalAlignment="Left" Margin="66,143,0,0" VerticalAlignment="Top"
Height="36" FontSize="14"/>
<Label Content="City" HorizontalAlignment="Left" Margin="66,184,0,0" VerticalAlignment="Top"
Height="36" FontSize="14"/>
<TextBox x:Name="name_txt" HorizontalAlignment="Left" Margin="130,60,0,0" TextWrapping="Wrap"
VerticalAlignment="Top" Width="154" Height="32" FontSize="14"/>
<TextBox x:Name="age_txt" HorizontalAlignment="Left" Margin="130,101,0,0" TextWrapping="Wrap"
VerticalAlignment="Top" Width="154" Height="32" FontSize="14"/>
<TextBox x:Name="gender_txt" HorizontalAlignment="Left" Margin="130,143,0,0" TextWrapping="Wrap"
VerticalAlignment="Top" Width="155" Height="32" FontSize="14"/>
<TextBox x:Name="city_txt" HorizontalAlignment="Left" Margin="130,184,0,0" TextWrapping="Wrap"
VerticalAlignment="Top" Width="155" Height="32" FontSize="14"/>
<DataGrid x:Name="datagrid" d:ItemsSource="{d:SampleData ItemCount=5}" Margin="313,60,29,217"/>
<Button x:Name="InsertBtn" Content="Insert Record" HorizontalAlignment="Left" Margin="82,339,0,0"
VerticalAlignment="Top" Height="47" Width="101" FontSize="14" FontWeight="Bold"
Background="#FFB96868" BorderBrush="Black" Foreground="#FFF8F7F7" OpacityMask="Black"
Click="InsertBtn_Click"/>
<Button x:Name="UpdateBtn" Content="Update Record" HorizontalAlignment="Left" Margin="267,339,0,0"
VerticalAlignment="Top" Height="47" Width="101" FontSize="14" FontWeight="Bold"
Background="#FFB96868" BorderBrush="Black" Foreground="#FFF8F7F7" OpacityMask="Black"
Click="UpdateBtn_Click"/>
<Button x:Name="DeleteBtn" Content="Delete Record" HorizontalAlignment="Left" Margin="457,339,0,0"
VerticalAlignment="Top" Height="47" Width="101" FontSize="14" FontWeight="Bold"
Background="#FFB96868" BorderBrush="Black" Foreground="#FFF8F7F7" OpacityMask="Black"
Click="DeleteBtn_Click"/>
<Button x:Name="ClearDataBtn" Content="Clear Data" HorizontalAlignment="Left" Margin="652,339,0,0"
VerticalAlignment="Top" Height="47" Width="101" FontSize="14" FontWeight="Bold"
Background="#FFB96868" BorderBrush="Black" Foreground="#FFF8F7F7" OpacityMask="Black"
Click="ClearDataBtn_Click"/>
<Label Content="ID" HorizontalAlignment="Left" Margin="231,251,0,0" VerticalAlignment="Top"
Height="36" FontSize="14"/>
<TextBox x:Name="search_txt" HorizontalAlignment="Left" Margin="289,251,0,0" TextWrapping="Wrap"
VerticalAlignment="Top" Width="155" Height="32" FontSize="14"/>
<Button Content="Button" HorizontalAlignment="Left" Margin="592,269,0,0" VerticalAlignment="Top"/>
</Grid>
</Window>