添加客户管理页面
This commit is contained in:
commit
f558f56d42
7 files changed
+678
-9
No files matched your search
+1
-2
@@ -37,8 +37,7 @@
|
||||
<MenuItem Header="_配送流程管理" FontSize="16" Name="_WORKFLOW" Click="WORKFLOW" IsEnabled="False"/>
|
||||
<Separator />
|
||||
<MenuItem Header="_布种" FontSize="16" Name="_fabric" Click="fabric" IsEnabled="False"/>
|
||||
<MenuItem Header="_品名" FontSize="16" Name="_variety" Click="variety" IsEnabled="False"/>
|
||||
<MenuItem Header="_色号" FontSize="16" Name="_color" Click="color" IsEnabled="False"/>
|
||||
<MenuItem Header="_色名" FontSize="16" Name="_color" Click="color" IsEnabled="False"/>
|
||||
<MenuItem Header="_客户" FontSize="16" Name="_client" Click="client" IsEnabled="False"/>
|
||||
</MenuItem>
|
||||
<MenuItem Header="_查询" FontSize="16" Focusable ="False">
|
||||
|
||||
+4
-7
@@ -98,7 +98,6 @@ namespace formula_manage
|
||||
_MAC_SET.IsEnabled = true;
|
||||
_STUFF.IsEnabled = true;
|
||||
_fabric.IsEnabled = true;
|
||||
_variety.IsEnabled = true;
|
||||
_client.IsEnabled = true;
|
||||
_color.IsEnabled = true;
|
||||
_statistics.IsEnabled = true;
|
||||
@@ -176,7 +175,6 @@ namespace formula_manage
|
||||
_MAC_SET.IsEnabled = true;
|
||||
_STUFF.IsEnabled = true;
|
||||
_fabric.IsEnabled = true;
|
||||
_variety.IsEnabled = true;
|
||||
_client.IsEnabled = true;
|
||||
_color.IsEnabled = true;
|
||||
_statistics.IsEnabled = true;
|
||||
@@ -193,7 +191,6 @@ namespace formula_manage
|
||||
_MAC_SET.IsEnabled = true;
|
||||
_STUFF.IsEnabled = true;
|
||||
_fabric.IsEnabled = true;
|
||||
_variety.IsEnabled = true;
|
||||
_client.IsEnabled = true;
|
||||
_color.IsEnabled = true;
|
||||
_statistics.IsEnabled = true;
|
||||
@@ -378,16 +375,16 @@ namespace formula_manage
|
||||
fabric_page.ShowDialog();//实例化并置顶打开信息窗口
|
||||
}
|
||||
|
||||
private void variety(object sender, RoutedEventArgs e)
|
||||
{
|
||||
}
|
||||
|
||||
private void color(object sender, RoutedEventArgs e)
|
||||
{
|
||||
color color_page = new color();
|
||||
color_page.ShowDialog();//实例化并置顶打开信息窗口
|
||||
}
|
||||
|
||||
private void client(object sender, RoutedEventArgs e)
|
||||
{
|
||||
client client_page = new client();
|
||||
client_page.ShowDialog();//实例化并置顶打开信息窗口
|
||||
}
|
||||
private void confirm(object sender, RoutedEventArgs e)
|
||||
{
|
||||
|
||||
@@ -0,0 +1,87 @@
|
||||
<Window x:Class="formula_manage.Windows.client"
|
||||
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"
|
||||
xmlns:local="clr-namespace:formula_manage.Windows"
|
||||
xmlns:ConvertMoels="clr-namespace:formula_manage.ConvertMoels"
|
||||
xmlns:viewmodel="clr-namespace:formula_manage.ViewModel"
|
||||
mc:Ignorable="d" Loaded="client_Loaded"
|
||||
Title="client" Height="720" Width="1100" MaxHeight="720" MaxWidth="1100" MinHeight="720" MinWidth="1100"
|
||||
BorderBrush="White" Background="#FFE0E0E0">
|
||||
<Grid>
|
||||
<!--原料表-->
|
||||
<DataGrid x:Name="DataGridclient" MouseDoubleClick="DataGridclient_MouseDoubleClick" SelectionMode="Single" AlternationCount="2" IsReadOnly="True" Margin="15,15,15,150" d:ItemsSource="{d:SampleData ItemCount=999}" AutoGenerateColumns="False" MinColumnWidth="30"
|
||||
HorizontalGridLinesBrush="#FFC9C9C9" VerticalGridLinesBrush="#FFC9C9C9" GridLinesVisibility="All" BorderBrush="#CCCCCC"
|
||||
BorderThickness="1,1,1,1" ColumnHeaderHeight="40" HorizontalContentAlignment="Right" Grid.ColumnSpan="2"
|
||||
CanUserResizeRows="False" CanUserAddRows="False" CanUserDeleteRows="False" CanUserReorderColumns="False"
|
||||
CanUserResizeColumns="False" CanUserSortColumns="False" HeadersVisibility ="Column">
|
||||
<DataGrid.RowStyle >
|
||||
<Style TargetType="{x:Type DataGridRow}">
|
||||
<Style.Triggers>
|
||||
<Trigger Property="ItemsControl.AlternationIndex" Value="0">
|
||||
<Setter Property="Background" Value="#FFFFFFFF" />
|
||||
</Trigger>
|
||||
<Trigger Property="ItemsControl.AlternationIndex" Value="1">
|
||||
<Setter Property="Background" Value="#FFF0F0F0" />
|
||||
</Trigger>
|
||||
<Trigger Property="IsMouseOver" Value="False">
|
||||
</Trigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
</DataGrid.RowStyle>
|
||||
<DataGrid.CellStyle>
|
||||
<Style TargetType="DataGridCell">
|
||||
<Setter Property="BorderThickness" Value="0"/>
|
||||
<Setter Property="MinWidth" Value="20"/>
|
||||
<Style.Triggers>
|
||||
<Trigger Property="IsSelected" Value="True">
|
||||
<Setter Property="Background" Value="#FFC0C0C0"/>
|
||||
<Setter Property="BorderBrush" Value="#FFC0C0C0"/>
|
||||
<Setter Property="Foreground" Value="#000000"/>
|
||||
</Trigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
</DataGrid.CellStyle>
|
||||
<DataGrid.Columns>
|
||||
<!--列信息绑定-->
|
||||
<DataGridTemplateColumn Header=" 序号" Width="50" MinWidth="10" IsReadOnly="True">
|
||||
<DataGridTemplateColumn.CellTemplate>
|
||||
<DataTemplate>
|
||||
<TextBlock FontSize="15" Text="{Binding RelativeSource={RelativeSource Mode=FindAncestor,AncestorType={x:Type DataGridRow}}, Path=Header}" HorizontalAlignment="Left" VerticalAlignment="Center" Margin="10,0,0,0"></TextBlock>
|
||||
</DataTemplate>
|
||||
</DataGridTemplateColumn.CellTemplate>
|
||||
</DataGridTemplateColumn>
|
||||
<DataGridTextColumn Header="客户代码" Binding="{Binding Code}" Width="250" FontSize="15" MaxWidth="500" MinWidth="100" CanUserReorder="False"/>
|
||||
<DataGridTextColumn Header="客户名称" Binding="{Binding Name}" Width="250" FontSize="15" MaxWidth="500" MinWidth="200" CanUserReorder="False"/>
|
||||
<DataGridTextColumn Header="备注" Binding="{Binding Remark}" Width="500" FontSize="15" MaxWidth="1500" MinWidth="150" CanUserReorder="False"/>
|
||||
</DataGrid.Columns>
|
||||
</DataGrid>
|
||||
<!--客户代码-->
|
||||
<TextBox x:Name="client_code" HorizontalAlignment="Left" Height="30" Margin="105,0,0,100" Text=""
|
||||
VerticalAlignment="Bottom" Width="250" FontSize="22" MaxLines="1" MaxLength="25"
|
||||
InputMethod.IsInputMethodEnabled="False"/>
|
||||
<TextBlock HorizontalAlignment="Left" Height="30" Margin="15,0,0,100" TextWrapping="Wrap" Text="客户代码"
|
||||
VerticalAlignment="Bottom" Width="100" FontSize="20"/>
|
||||
<!--客户名称-->
|
||||
<TextBox x:Name="client_name" HorizontalAlignment="Left" Height="30" Margin="465,0,0,100" Text=""
|
||||
VerticalAlignment="Bottom" Width="250" FontSize="22" MaxLines="1" MaxLength="50"/>
|
||||
<TextBlock HorizontalAlignment="Left" Height="30" Margin="375,0,0,100" TextWrapping="Wrap" Text="客户名称"
|
||||
VerticalAlignment="Bottom" Width="100" FontSize="20"/>
|
||||
<!--备注-->
|
||||
<TextBox x:Name="client_Remark" HorizontalAlignment="Left" Height="30" Margin="105,0,0,50" Text=""
|
||||
VerticalAlignment="Bottom" Width="610" FontSize="22" MaxLines="1" MaxLength="25"/>
|
||||
<TextBlock HorizontalAlignment="Left" Height="30" Margin="15,0,0,50" TextWrapping="Wrap" Text="备注"
|
||||
VerticalAlignment="Bottom" Width="120" FontSize="20"/>
|
||||
<!--存储按钮-->
|
||||
<Button Content="存储" HorizontalAlignment="Left" Height="50" Margin="795,0,0,60"
|
||||
VerticalAlignment="Bottom" Width="100" FontSize="30" Background="#FFEFEFEF" BorderBrush="White"
|
||||
Click="Button_Preservation">
|
||||
</Button>
|
||||
<!--删除按钮-->
|
||||
<Button Content="删除" HorizontalAlignment="Left" Height="50" Margin="935,0,0,60"
|
||||
VerticalAlignment="Bottom" Width="100" FontSize="30" Background="#FFEFEFEF" BorderBrush="White"
|
||||
Click="Button_Delete">
|
||||
</Button>
|
||||
</Grid>
|
||||
</Window>
|
||||
@@ -0,0 +1,237 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
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.Shapes;
|
||||
using GalaSoft.MvvmLight;
|
||||
using formula_manage.SQLModels;
|
||||
using System.Data.SqlClient;
|
||||
using System.Data;
|
||||
using System.Windows.Forms;
|
||||
using static System.Windows.Forms.VisualStyles.VisualStyleElement.Button;
|
||||
using Xceed.Wpf.AvalonDock.Themes;
|
||||
using static System.Net.Mime.MediaTypeNames;
|
||||
|
||||
namespace formula_manage.Windows
|
||||
{
|
||||
/// <summary>
|
||||
/// client.xaml 的交互逻辑
|
||||
/// </summary>
|
||||
public partial class client : Window
|
||||
{
|
||||
public string INIPath = Convert.ToString(System.AppDomain.CurrentDomain.BaseDirectory) + "formula.ini"; //配置文件路径
|
||||
|
||||
DataTable dataTable = new DataTable(); //建立缓存
|
||||
|
||||
int Button_ID = 0;
|
||||
string TEXT_SQLIP;
|
||||
string TEXT_SQLNAME;
|
||||
string TEXT_SQMOD;
|
||||
string TEXT_SQLUSER;
|
||||
string TEXT_SQLPASWOR;
|
||||
string Connstr_SC;
|
||||
|
||||
public client()
|
||||
{
|
||||
WindowStartupLocation = WindowStartupLocation.CenterScreen;
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
private async void client_Loaded(object sender, RoutedEventArgs e)//打开页面执行
|
||||
{
|
||||
UserClass.IniFile.IniFiles Configini = new UserClass.IniFile.IniFiles(INIPath);//生效配置读取
|
||||
this.DataGridclient.LoadingRow += new EventHandler<DataGridRowEventArgs>(this.DataGridEquipment_LoadingRow);//生成序列号
|
||||
|
||||
TEXT_SQLIP = Configini.IniReadvalue("SQL_SERVER", "SQL1"); //读配置文件
|
||||
TEXT_SQLNAME = Configini.IniReadvalue("SQL_SERVER", "SQL2");
|
||||
TEXT_SQMOD = Configini.IniReadvalue("SQL_SERVER", "SQL3");
|
||||
TEXT_SQLUSER = Configini.IniReadvalue("SQL_SERVER", "SQL4");
|
||||
TEXT_SQLPASWOR = Configini.IniReadvalue("SQL_SERVER", "SQL5");
|
||||
if (TEXT_SQMOD == "0") //判断连接方式
|
||||
{
|
||||
Connstr_SC = "server=" + TEXT_SQLIP + ";database=" + TEXT_SQLNAME + ";Trusted_Connection=SSPI";
|
||||
}
|
||||
else
|
||||
{
|
||||
Connstr_SC = "server=" + TEXT_SQLIP + ";database=" + TEXT_SQLNAME + ";User ID=" + TEXT_SQLUSER + ";Password=" + TEXT_SQLPASWOR;
|
||||
}
|
||||
|
||||
string client_sql = "SELECT Code ,Name , Remark FROM [dbo].[Client]";//查询语句
|
||||
|
||||
SqlConnection conn_SC = new SqlConnection(Connstr_SC); //实例化
|
||||
try
|
||||
{
|
||||
await conn_SC.OpenAsync(); //打开数据连接
|
||||
SqlDataAdapter client_data = new SqlDataAdapter(client_sql, Connstr_SC); //查询
|
||||
|
||||
client_data.Fill(dataTable); //查询结果存入缓存
|
||||
conn_SC.Close(); //关闭连接
|
||||
|
||||
DataGridclient.ItemsSource = dataTable.DefaultView; //数据加入表格
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
System.Windows.MessageBox.Show("请求信息失败,检查连接");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 生成序列号的方法
|
||||
/// </summary>
|
||||
private void DataGridEquipment_LoadingRow(object sender, DataGridRowEventArgs e)
|
||||
{
|
||||
e.Row.Header = e.Row.GetIndex() + 1;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 查询数据库的方法
|
||||
/// </summary>
|
||||
private async void GridSql()
|
||||
{
|
||||
string client_sql = "SELECT Code ,Name , Remark FROM [dbo].[Client]";//查询语句
|
||||
|
||||
SqlConnection conn_SC = new SqlConnection(Connstr_SC); //实例化
|
||||
|
||||
try
|
||||
{
|
||||
await conn_SC.OpenAsync(); //打开数据连接
|
||||
SqlDataAdapter client_data = new SqlDataAdapter(client_sql, Connstr_SC); //查询
|
||||
|
||||
dataTable.Clear();
|
||||
client_data.Fill(dataTable); //查询结果存入缓存
|
||||
conn_SC.Close(); //关闭连接
|
||||
|
||||
DataGridclient.ItemsSource = dataTable.DefaultView; //数据加入表格
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
System.Windows.MessageBox.Show("请求信息失败,检查连接");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
private async void Button_Preservation(object sender, RoutedEventArgs e)//保存按钮事件
|
||||
{
|
||||
Regex re_number = new Regex(@"^[0-9]+(.[0-9]{1,4})?$");//校验用正则表达式有1~2位小数的正实数
|
||||
string client_sql;
|
||||
|
||||
if (string.IsNullOrEmpty(this.client_code.Text))
|
||||
System.Windows.MessageBox.Show("ERR:无效的信息", "错误");//检查原料代码
|
||||
else
|
||||
if (string.IsNullOrEmpty(this.client_name.Text))
|
||||
System.Windows.MessageBox.Show("ERR:无效的名称", "错误");//检查原料名
|
||||
else
|
||||
{
|
||||
try
|
||||
{
|
||||
SqlConnection conn_SC = new SqlConnection(Connstr_SC); //实例化
|
||||
client_sql = "SELECT count(*) FROM [dbo].[Client] WHERE Code = '" + client_code.Text + " '";//查询语句
|
||||
await conn_SC.OpenAsync(); //打开数据连
|
||||
SqlCommand cmd = new SqlCommand(client_sql, conn_SC); //查询记录数
|
||||
int count = Convert.ToInt32(cmd.ExecuteScalar()); //显示记录数
|
||||
conn_SC.Close(); //关闭连接
|
||||
|
||||
if (count == 0)
|
||||
{
|
||||
client_sql = string.Format("INSERT INTO [dbo].[Client](Code ,Name , Remark) " +
|
||||
"VALUES ('" + client_code.Text + "','" + client_name.Text + "','" + client_Remark.Text + "')");
|
||||
await conn_SC.OpenAsync(); //打开数据连接
|
||||
SqlCommand INSERT_cmd = new SqlCommand(client_sql, conn_SC);
|
||||
int sql_in = INSERT_cmd.ExecuteNonQuery(); //执行语句
|
||||
|
||||
conn_SC.Close(); //关闭连接
|
||||
if (sql_in == 0)
|
||||
{
|
||||
System.Windows.MessageBox.Show("添加失败");
|
||||
}
|
||||
else
|
||||
{
|
||||
GridSql();
|
||||
System.Windows.MessageBox.Show("添加完成");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
client_sql = string.Format("UPDATE [dbo].[Client] SET Name='" + client_name.Text + "',Remark='" + client_Remark.Text + "' Where Code='"+ client_code.Text + "'");
|
||||
await conn_SC.OpenAsync(); //打开数据连接
|
||||
SqlCommand INSERT_cmd = new SqlCommand(client_sql, conn_SC);
|
||||
int sql_in = INSERT_cmd.ExecuteNonQuery(); //执行语句
|
||||
|
||||
conn_SC.Close(); //关闭连接
|
||||
if (sql_in == 0)
|
||||
{
|
||||
System.Windows.MessageBox.Show("C0110-1:修改失败");
|
||||
}
|
||||
else
|
||||
{
|
||||
GridSql();
|
||||
|
||||
System.Windows.MessageBox.Show("修改完成");
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
System.Windows.MessageBox.Show("请求失败,检查连接");
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private async void Button_Delete(object sender, RoutedEventArgs e)//删除按钮事件
|
||||
{
|
||||
string ShowProductName = "是否删除【" + this.client_name.Text + "】" + this.client_code.Text;//获取信息并拼接提示字符串
|
||||
MessageBoxResult showProductName = System.Windows.MessageBox.Show(ShowProductName, "提示", MessageBoxButton.YesNo, MessageBoxImage.Warning, MessageBoxResult.Yes);//弹窗提示是否删除目标原料
|
||||
if (showProductName == MessageBoxResult.Yes)//判断是否删除
|
||||
{
|
||||
|
||||
string Stuff_sql = string.Format("DELETE FROM [dbo].[Client] WHERE Code ='" + client_code.Text.ToString() + "'");
|
||||
|
||||
SqlConnection conn_SC = new SqlConnection(Connstr_SC); //实例化
|
||||
try
|
||||
{
|
||||
await conn_SC.OpenAsync(); //打开数据连接
|
||||
SqlCommand INSERT_cmd = new SqlCommand(Stuff_sql, conn_SC);
|
||||
int sql_in = INSERT_cmd.ExecuteNonQuery(); //执行语句
|
||||
conn_SC.Close(); //关闭连接
|
||||
if (sql_in == 0)
|
||||
{
|
||||
System.Windows.MessageBox.Show("C0110-2:删除失败", "错误");//判断执行是否成功
|
||||
}
|
||||
else
|
||||
{
|
||||
GridSql();
|
||||
}
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
System.Windows.MessageBox.Show("请求失败,检查连接");
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void DataGridclient_MouseDoubleClick(object sender, MouseButtonEventArgs e)//数据表双击事件
|
||||
{
|
||||
int rownum = DataGridclient.SelectedIndex;//获取鼠标选中行并定义变量
|
||||
if (rownum != -1)//判断鼠标定位是否有效
|
||||
{
|
||||
/*定位选中行及指定列单元格文本信息*/
|
||||
client_code.Text = (DataGridclient.Columns[1].GetCellContent(DataGridclient.Items[rownum]) as TextBlock).Text.TrimEnd();//定位第0列,代码
|
||||
client_name.Text = (DataGridclient.Columns[2].GetCellContent(DataGridclient.Items[rownum]) as TextBlock).Text.TrimEnd();//定位第1列,名称
|
||||
client_Remark.Text = (DataGridclient.Columns[3].GetCellContent(DataGridclient.Items[rownum]) as TextBlock).Text.TrimEnd();//定位,
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,94 @@
|
||||
<Window x:Class="formula_manage.Windows.color"
|
||||
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"
|
||||
xmlns:local="clr-namespace:formula_manage.Windows"
|
||||
xmlns:ConvertMoels="clr-namespace:formula_manage.ConvertMoels"
|
||||
xmlns:viewmodel="clr-namespace:formula_manage.ViewModel"
|
||||
mc:Ignorable="d" Loaded="color_Loaded"
|
||||
Title="color" Height="720" Width="1100" MaxHeight="720" MaxWidth="1100" MinHeight="720" MinWidth="1100"
|
||||
BorderBrush="White" Background="#FFE0E0E0">
|
||||
<Grid>
|
||||
<!--原料表-->
|
||||
<DataGrid x:Name="DataGridcolor" MouseDoubleClick="DataGridcolor_MouseDoubleClick" SelectionMode="Single" AlternationCount="2" IsReadOnly="True" Margin="15,15,15,150" d:ItemsSource="{d:SampleData ItemCount=999}" AutoGenerateColumns="False" MinColumnWidth="30"
|
||||
HorizontalGridLinesBrush="#FFC9C9C9" VerticalGridLinesBrush="#FFC9C9C9" GridLinesVisibility="All" BorderBrush="#CCCCCC"
|
||||
BorderThickness="1,1,1,1" ColumnHeaderHeight="40" HorizontalContentAlignment="Right" Grid.ColumnSpan="2"
|
||||
CanUserResizeRows="False" CanUserAddRows="False" CanUserDeleteRows="False" CanUserReorderColumns="False"
|
||||
CanUserResizeColumns="False" CanUserSortColumns="False" HeadersVisibility ="Column">
|
||||
<DataGrid.RowStyle >
|
||||
<Style TargetType="{x:Type DataGridRow}">
|
||||
<Style.Triggers>
|
||||
<Trigger Property="ItemsControl.AlternationIndex" Value="0">
|
||||
<Setter Property="Background" Value="#FFFFFFFF" />
|
||||
</Trigger>
|
||||
<Trigger Property="ItemsControl.AlternationIndex" Value="1">
|
||||
<Setter Property="Background" Value="#FFF0F0F0" />
|
||||
</Trigger>
|
||||
<Trigger Property="IsMouseOver" Value="False">
|
||||
</Trigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
</DataGrid.RowStyle>
|
||||
<DataGrid.CellStyle>
|
||||
<Style TargetType="DataGridCell">
|
||||
<Setter Property="BorderThickness" Value="0"/>
|
||||
<Setter Property="MinWidth" Value="20"/>
|
||||
<Style.Triggers>
|
||||
<Trigger Property="IsSelected" Value="True">
|
||||
<Setter Property="Background" Value="#FFC0C0C0"/>
|
||||
<Setter Property="BorderBrush" Value="#FFC0C0C0"/>
|
||||
<Setter Property="Foreground" Value="#000000"/>
|
||||
</Trigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
</DataGrid.CellStyle>
|
||||
<DataGrid.Columns>
|
||||
<!--列信息绑定-->
|
||||
<DataGridTemplateColumn Header=" 序号" Width="50" MinWidth="10" IsReadOnly="True">
|
||||
<DataGridTemplateColumn.CellTemplate>
|
||||
<DataTemplate>
|
||||
<TextBlock FontSize="15" Text="{Binding RelativeSource={RelativeSource Mode=FindAncestor,AncestorType={x:Type DataGridRow}}, Path=Header}" HorizontalAlignment="Left" VerticalAlignment="Center" Margin="10,0,0,0"></TextBlock>
|
||||
</DataTemplate>
|
||||
</DataGridTemplateColumn.CellTemplate>
|
||||
</DataGridTemplateColumn>
|
||||
<DataGridTextColumn Header="布种代码" Binding="{Binding Code}" Width="250" FontSize="15" MaxWidth="500" MinWidth="100" CanUserReorder="False"/>
|
||||
<DataGridTextColumn Header="布种名称" Binding="{Binding Name}" Width="250" FontSize="15" MaxWidth="500" MinWidth="200" CanUserReorder="False"/>
|
||||
<DataGridTextColumn Header="码重(g/Yard)" Binding="{Binding GYard}" Width="100" FontSize="15" MaxWidth="200" MinWidth="20" CanUserReorder="False"/>
|
||||
<DataGridTextColumn Header="备注" Binding="{Binding Remark}" Width="500" FontSize="15" MaxWidth="1500" MinWidth="150" CanUserReorder="False"/>
|
||||
</DataGrid.Columns>
|
||||
</DataGrid>
|
||||
<!--布种代码-->
|
||||
<TextBox x:Name="color_code" HorizontalAlignment="Left" Height="30" Margin="105,0,0,100" Text=""
|
||||
VerticalAlignment="Bottom" Width="250" FontSize="22" MaxLines="1" MaxLength="25"
|
||||
InputMethod.IsInputMethodEnabled="False"/>
|
||||
<TextBlock HorizontalAlignment="Left" Height="30" Margin="15,0,0,100" TextWrapping="Wrap" Text="布种代码"
|
||||
VerticalAlignment="Bottom" Width="100" FontSize="20"/>
|
||||
<!--布种名称-->
|
||||
<TextBox x:Name="color_name" HorizontalAlignment="Left" Height="30" Margin="465,0,0,100" Text=""
|
||||
VerticalAlignment="Bottom" Width="250" FontSize="22" MaxLines="1" MaxLength="50"/>
|
||||
<TextBlock HorizontalAlignment="Left" Height="30" Margin="375,0,0,100" TextWrapping="Wrap" Text="布种名称"
|
||||
VerticalAlignment="Bottom" Width="100" FontSize="20"/>
|
||||
<!--备注-->
|
||||
<TextBox x:Name="color_Remark" HorizontalAlignment="Left" Height="30" Margin="105,0,0,50" Text=""
|
||||
VerticalAlignment="Bottom" Width="340" FontSize="22" MaxLines="1" MaxLength="25"/>
|
||||
<TextBlock HorizontalAlignment="Left" Height="30" Margin="15,0,0,50" TextWrapping="Wrap" Text="备注"
|
||||
VerticalAlignment="Bottom" Width="120" FontSize="20"/>
|
||||
<!--码重-->
|
||||
<TextBox x:Name="color_GYard" HorizontalAlignment="Left" Height="30" Margin="585,0,0,50" Text="500"
|
||||
VerticalAlignment="Bottom" Width="130" FontSize="22" MaxLines="1" MaxLength="25"/>
|
||||
<TextBlock HorizontalAlignment="Left" Height="30" Margin="465,0,0,50" TextWrapping="Wrap" Text="码重(g/Yard)"
|
||||
VerticalAlignment="Bottom" Width="120" FontSize="20"/>
|
||||
|
||||
<!--存储按钮-->
|
||||
<Button Content="存储" HorizontalAlignment="Left" Height="50" Margin="795,0,0,60"
|
||||
VerticalAlignment="Bottom" Width="100" FontSize="30" Background="#FFEFEFEF" BorderBrush="White"
|
||||
Click="Button_Preservation">
|
||||
</Button>
|
||||
<!--删除按钮-->
|
||||
<Button Content="删除" HorizontalAlignment="Left" Height="50" Margin="935,0,0,60"
|
||||
VerticalAlignment="Bottom" Width="100" FontSize="30" Background="#FFEFEFEF" BorderBrush="White"
|
||||
Click="Button_Delete">
|
||||
</Button>
|
||||
</Grid>
|
||||
</Window>
|
||||
@@ -0,0 +1,241 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
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.Shapes;
|
||||
using GalaSoft.MvvmLight;
|
||||
using formula_manage.SQLModels;
|
||||
using System.Data.SqlClient;
|
||||
using System.Data;
|
||||
using System.Windows.Forms;
|
||||
using static System.Windows.Forms.VisualStyles.VisualStyleElement.Button;
|
||||
using Xceed.Wpf.AvalonDock.Themes;
|
||||
using static System.Net.Mime.MediaTypeNames;
|
||||
|
||||
namespace formula_manage.Windows
|
||||
{
|
||||
/// <summary>
|
||||
/// color.xaml 的交互逻辑
|
||||
/// </summary>
|
||||
public partial class color : Window
|
||||
{
|
||||
public string INIPath = Convert.ToString(System.AppDomain.CurrentDomain.BaseDirectory) + "formula.ini"; //配置文件路径
|
||||
|
||||
DataTable dataTable = new DataTable(); //建立缓存
|
||||
|
||||
int Button_ID = 0;
|
||||
string TEXT_SQLIP;
|
||||
string TEXT_SQLNAME;
|
||||
string TEXT_SQMOD;
|
||||
string TEXT_SQLUSER;
|
||||
string TEXT_SQLPASWOR;
|
||||
string Connstr_SC;
|
||||
|
||||
public color()
|
||||
{
|
||||
WindowStartupLocation = WindowStartupLocation.CenterScreen;
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
private async void color_Loaded(object sender, RoutedEventArgs e)//打开页面执行
|
||||
{
|
||||
UserClass.IniFile.IniFiles Configini = new UserClass.IniFile.IniFiles(INIPath);//生效配置读取
|
||||
this.DataGridcolor.LoadingRow += new EventHandler<DataGridRowEventArgs>(this.DataGridEquipment_LoadingRow);//生成序列号
|
||||
|
||||
TEXT_SQLIP = Configini.IniReadvalue("SQL_SERVER", "SQL1"); //读配置文件
|
||||
TEXT_SQLNAME = Configini.IniReadvalue("SQL_SERVER", "SQL2");
|
||||
TEXT_SQMOD = Configini.IniReadvalue("SQL_SERVER", "SQL3");
|
||||
TEXT_SQLUSER = Configini.IniReadvalue("SQL_SERVER", "SQL4");
|
||||
TEXT_SQLPASWOR = Configini.IniReadvalue("SQL_SERVER", "SQL5");
|
||||
if (TEXT_SQMOD == "0") //判断连接方式
|
||||
{
|
||||
Connstr_SC = "server=" + TEXT_SQLIP + ";database=" + TEXT_SQLNAME + ";Trusted_Connection=SSPI";
|
||||
}
|
||||
else
|
||||
{
|
||||
Connstr_SC = "server=" + TEXT_SQLIP + ";database=" + TEXT_SQLNAME + ";User ID=" + TEXT_SQLUSER + ";Password=" + TEXT_SQLPASWOR;
|
||||
}
|
||||
|
||||
string color_sql = "SELECT Code ,Name , GYard , Remark FROM [dbo].[PRODUCTION_Material]";//查询语句
|
||||
|
||||
SqlConnection conn_SC = new SqlConnection(Connstr_SC); //实例化
|
||||
try
|
||||
{
|
||||
await conn_SC.OpenAsync(); //打开数据连接
|
||||
SqlDataAdapter color_data = new SqlDataAdapter(color_sql, Connstr_SC); //查询
|
||||
|
||||
color_data.Fill(dataTable); //查询结果存入缓存
|
||||
conn_SC.Close(); //关闭连接
|
||||
|
||||
DataGridcolor.ItemsSource = dataTable.DefaultView; //数据加入表格
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
System.Windows.MessageBox.Show("请求信息失败,检查连接");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 生成序列号的方法
|
||||
/// </summary>
|
||||
private void DataGridEquipment_LoadingRow(object sender, DataGridRowEventArgs e)
|
||||
{
|
||||
e.Row.Header = e.Row.GetIndex() + 1;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 查询数据库的方法
|
||||
/// </summary>
|
||||
private async void GridSql()
|
||||
{
|
||||
string color_sql = "SELECT Code ,Name , GYard , Remark FROM [dbo].[PRODUCTION_Material]";//查询语句
|
||||
|
||||
SqlConnection conn_SC = new SqlConnection(Connstr_SC); //实例化
|
||||
|
||||
try
|
||||
{
|
||||
await conn_SC.OpenAsync(); //打开数据连接
|
||||
SqlDataAdapter color_data = new SqlDataAdapter(color_sql, Connstr_SC); //查询
|
||||
|
||||
dataTable.Clear();
|
||||
color_data.Fill(dataTable); //查询结果存入缓存
|
||||
conn_SC.Close(); //关闭连接
|
||||
|
||||
DataGridcolor.ItemsSource = dataTable.DefaultView; //数据加入表格
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
System.Windows.MessageBox.Show("请求信息失败,检查连接");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
private async void Button_Preservation(object sender, RoutedEventArgs e)//保存按钮事件
|
||||
{
|
||||
Regex re_number = new Regex(@"^[0-9]+(.[0-9]{1,4})?$");//校验用正则表达式有1~2位小数的正实数
|
||||
string color_sql;
|
||||
|
||||
if ((re_number.IsMatch(this.color_GYard.Text) == false) && (color_GYard.Text != ""))
|
||||
System.Windows.MessageBox.Show("ERR:单位码重错误", "错误");//检查价格输入信息
|
||||
else
|
||||
if (string.IsNullOrEmpty(this.color_code.Text))
|
||||
System.Windows.MessageBox.Show("ERR:无效的原料信息", "错误");//检查原料代码
|
||||
else
|
||||
if (string.IsNullOrEmpty(this.color_name.Text))
|
||||
System.Windows.MessageBox.Show("ERR:无效的原料名称", "错误");//检查原料名
|
||||
else
|
||||
{
|
||||
try
|
||||
{
|
||||
SqlConnection conn_SC = new SqlConnection(Connstr_SC); //实例化
|
||||
color_sql = "SELECT count(*) FROM [dbo].[PRODUCTION_Material] WHERE Code = '" + color_code.Text + " '";//查询语句
|
||||
await conn_SC.OpenAsync(); //打开数据连
|
||||
SqlCommand cmd = new SqlCommand(color_sql, conn_SC); //查询记录数
|
||||
int count = Convert.ToInt32(cmd.ExecuteScalar()); //显示记录数
|
||||
conn_SC.Close(); //关闭连接
|
||||
|
||||
if (count == 0)
|
||||
{
|
||||
color_sql = string.Format("INSERT INTO [dbo].[PRODUCTION_Material](Code ,Name , GYard , Remark) " +
|
||||
"VALUES ('" + color_code.Text + "','" + color_name.Text + "','" + color_GYard.Text + "','" + color_Remark.Text + "')");
|
||||
await conn_SC.OpenAsync(); //打开数据连接
|
||||
SqlCommand INSERT_cmd = new SqlCommand(color_sql, conn_SC);
|
||||
int sql_in = INSERT_cmd.ExecuteNonQuery(); //执行语句
|
||||
|
||||
conn_SC.Close(); //关闭连接
|
||||
if (sql_in == 0)
|
||||
{
|
||||
System.Windows.MessageBox.Show("添加失败");
|
||||
}
|
||||
else
|
||||
{
|
||||
GridSql();
|
||||
System.Windows.MessageBox.Show("添加完成");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
color_sql = string.Format("UPDATE [dbo].[PRODUCTION_Material] SET Name='" + color_name.Text + "',GYard='" + color_GYard.Text + "',Remark='" + color_Remark.Text + "' Where Code='"+ color_code.Text + "'");
|
||||
await conn_SC.OpenAsync(); //打开数据连接
|
||||
SqlCommand INSERT_cmd = new SqlCommand(color_sql, conn_SC);
|
||||
int sql_in = INSERT_cmd.ExecuteNonQuery(); //执行语句
|
||||
|
||||
conn_SC.Close(); //关闭连接
|
||||
if (sql_in == 0)
|
||||
{
|
||||
System.Windows.MessageBox.Show("C0110-1:修改失败");
|
||||
}
|
||||
else
|
||||
{
|
||||
GridSql();
|
||||
|
||||
System.Windows.MessageBox.Show("修改完成");
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
System.Windows.MessageBox.Show("请求失败,检查连接");
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private async void Button_Delete(object sender, RoutedEventArgs e)//删除按钮事件
|
||||
{
|
||||
string ShowProductName = "是否删除【" + this.color_name.Text + "】" + this.color_code.Text;//获取信息并拼接提示字符串
|
||||
MessageBoxResult showProductName = System.Windows.MessageBox.Show(ShowProductName, "提示", MessageBoxButton.YesNo, MessageBoxImage.Warning, MessageBoxResult.Yes);//弹窗提示是否删除目标原料
|
||||
if (showProductName == MessageBoxResult.Yes)//判断是否删除
|
||||
{
|
||||
|
||||
string Stuff_sql = string.Format("DELETE FROM [dbo].[PRODUCTION_Material] WHERE Code ='" + color_code.Text.ToString() + "'");
|
||||
|
||||
SqlConnection conn_SC = new SqlConnection(Connstr_SC); //实例化
|
||||
try
|
||||
{
|
||||
await conn_SC.OpenAsync(); //打开数据连接
|
||||
SqlCommand INSERT_cmd = new SqlCommand(Stuff_sql, conn_SC);
|
||||
int sql_in = INSERT_cmd.ExecuteNonQuery(); //执行语句
|
||||
conn_SC.Close(); //关闭连接
|
||||
if (sql_in == 0)
|
||||
{
|
||||
System.Windows.MessageBox.Show("C0110-2:删除失败", "错误");//判断执行是否成功
|
||||
}
|
||||
else
|
||||
{
|
||||
GridSql();
|
||||
}
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
System.Windows.MessageBox.Show("请求失败,检查连接");
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void DataGridcolor_MouseDoubleClick(object sender, MouseButtonEventArgs e)//数据表双击事件
|
||||
{
|
||||
int rownum = DataGridcolor.SelectedIndex;//获取鼠标选中行并定义变量
|
||||
if (rownum != -1)//判断鼠标定位是否有效
|
||||
{
|
||||
/*定位选中行及指定列单元格文本信息*/
|
||||
color_code.Text = (DataGridcolor.Columns[1].GetCellContent(DataGridcolor.Items[rownum]) as TextBlock).Text.TrimEnd();//定位第0列,代码
|
||||
color_name.Text = (DataGridcolor.Columns[2].GetCellContent(DataGridcolor.Items[rownum]) as TextBlock).Text.TrimEnd();//定位第1列,名称
|
||||
color_Remark.Text = (DataGridcolor.Columns[4].GetCellContent(DataGridcolor.Items[rownum]) as TextBlock).Text.TrimEnd();//定位,
|
||||
color_GYard.Text = (DataGridcolor.Columns[3].GetCellContent(DataGridcolor.Items[rownum]) as TextBlock).Text.TrimEnd();//定位,
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -236,6 +236,12 @@
|
||||
<Compile Include="Windows\APP_set.xaml.cs">
|
||||
<DependentUpon>APP_set.xaml</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Windows\client.xaml.cs">
|
||||
<DependentUpon>client.xaml</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Windows\color.xaml.cs">
|
||||
<DependentUpon>color.xaml</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Windows\RECIPE.xaml.cs">
|
||||
<DependentUpon>RECIPE.xaml</DependentUpon>
|
||||
</Compile>
|
||||
@@ -306,6 +312,14 @@
|
||||
<SubType>Designer</SubType>
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
</Page>
|
||||
<Page Include="Windows\client.xaml">
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
<SubType>Designer</SubType>
|
||||
</Page>
|
||||
<Page Include="Windows\color.xaml">
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
<SubType>Designer</SubType>
|
||||
</Page>
|
||||
<Page Include="Windows\RECIPE.xaml">
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
<SubType>Designer</SubType>
|
||||
|
||||
Reference in new issue
Block a user