You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
168 lines
11 KiB
168 lines
11 KiB
using System;
|
|
using GalaSoft.MvvmLight;
|
|
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.Windows.Forms;
|
|
using System.Drawing;
|
|
using System.Text.RegularExpressions;
|
|
using Models;
|
|
using Audit.ViewModel;
|
|
|
|
namespace Audit.View
|
|
{
|
|
/// <summary>
|
|
/// StuffView.xaml 的交互逻辑
|
|
/// </summary>
|
|
public partial class StuffView : System.Windows.Controls.UserControl
|
|
{
|
|
/// <summary>
|
|
/// StuffView
|
|
/// </summary>
|
|
public StuffView()
|
|
{
|
|
InitializeComponent();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 输入限制
|
|
/// 仅允许数字及小数点
|
|
/// </summary>
|
|
public void Limitnumber(object sender, TextCompositionEventArgs e)
|
|
{
|
|
Regex re = new Regex("[^0-9]+.");//实例化输入信息白名单
|
|
e.Handled = re.IsMatch(e.Text);//检查输入信息并匹配白名单
|
|
|
|
}
|
|
|
|
private Product product = new Product();
|
|
private void Button_Preservation(object sender, RoutedEventArgs e)//保存按钮事件
|
|
{
|
|
int int_stuff_ProductType = 0;
|
|
if (this.stuff_ProductType.Text == "染料") int_stuff_ProductType = 0;//原料类型0。染料,1助剂,2粉体
|
|
if (this.stuff_ProductType.Text == "助剂") int_stuff_ProductType = 1;
|
|
if (this.stuff_ProductType.Text == "粉体助剂") int_stuff_ProductType = 2;
|
|
if (string.IsNullOrEmpty(this.stuff_ProductCode.Text)) System.Windows.MessageBox.Show("ERR.C0101:无效的原料信息", "错误");//检查原料代码
|
|
else
|
|
if (string.IsNullOrEmpty(this.stuff_ProductName.Text)) System.Windows.MessageBox.Show("ERR.C0101-2:无效的原料信息", "错误");//检查原料名称
|
|
else
|
|
if (string.IsNullOrEmpty(this.stuff_ProductType.Text)) System.Windows.MessageBox.Show("ERR.C0101-3:无效的原料信息", "错误");//检查原料类型
|
|
else
|
|
if (string.IsNullOrEmpty(this.stuff_GRAVITY.Text)) System.Windows.MessageBox.Show("ERR.C0101-1:无效的原料信息", "错误");//检查原料比重
|
|
else
|
|
if (float.Parse(this.stuff_GRAVITY.Text) < 0 || float.Parse(this.stuff_GRAVITY.Text) > 5) System.Windows.MessageBox.Show("ERR.C0102-1:原料信息错误", "错误");//检查比重输入数值
|
|
else
|
|
if(float.Parse(this.stuff_Concentration.Text) < 0 || float.Parse(this.stuff_Concentration.Text) > 100) System.Windows.MessageBox.Show("ERR.C0102-2:原料信息错误", "错误");//检查浓度输入数值
|
|
else
|
|
{
|
|
if (int_stuff_ProductType == 0)//判断是否为染料,非染料写空
|
|
{
|
|
if (ColorCode_SQL >= 0) product.Color = ColorCode_SQL;//判断色彩数据是否有效,有效写入
|
|
}
|
|
else
|
|
{
|
|
product.Color = null;//色彩栏写空
|
|
}
|
|
if (string.IsNullOrEmpty(this.stuff_Price.Text) == false) product.Price = Double.Parse(this.stuff_Price.Text);//判断价格数据是否有效,有效写入
|
|
if (string.IsNullOrEmpty(this.stuff_ProductUnit.Text) == false) product.ProductUnit = int.Parse(this.stuff_ProductUnit.Text);//判断供应商数据是否有效,有效写入
|
|
product.ProductCode = this.stuff_ProductCode.Text;//写入原料代码
|
|
product.ProductName = this.stuff_ProductName.Text;//写入原料名称
|
|
product.GRAVITY = Double.Parse(this.stuff_GRAVITY.Text);//写入原料比重
|
|
product.Concentration = Double.Parse(this.stuff_Concentration.Text);//写入原料浓度
|
|
product.ProductType = int_stuff_ProductType;//写入原料类型
|
|
new ProductProvider().Delete(product);//删除数据库原目标信息。
|
|
var count = new ProductProvider().Insert(product);//添加数据库信息。
|
|
if (count == 0)//判断执行是否成功
|
|
{
|
|
System.Windows.MessageBox.Show("ERR.C0110-1:添加失败","错误");
|
|
}
|
|
else
|
|
{
|
|
System.Windows.MessageBox.Show("添加完成");
|
|
}
|
|
}
|
|
}
|
|
|
|
private void Button_Delete(object sender, RoutedEventArgs e)//删除按钮事件
|
|
{
|
|
product.ProductCode = this.stuff_ProductCode.Text;//原料代码
|
|
string ShowProductName = "是否删除" + this.stuff_ProductName.Text;//获取原料名并拼接提示字符串
|
|
MessageBoxResult showProductName = System.Windows.MessageBox.Show(ShowProductName, "提示", MessageBoxButton.YesNo, MessageBoxImage.Warning, MessageBoxResult.Yes);//弹窗提示是否删除目标原料
|
|
if (showProductName == MessageBoxResult.Yes)//判断是否删除原料
|
|
{
|
|
var count = new ProductProvider().Delete(product);//删除数据库目标信息。
|
|
if (count == 0) System.Windows.MessageBox.Show("ERR.C0110-2:删除失败", "错误");//判断执行是否成功
|
|
}
|
|
}
|
|
|
|
private void DataGridStuff_MouseDoubleClick(object sender, MouseButtonEventArgs e)//数据表双击事件
|
|
{
|
|
int rownum = DataGridStuff.SelectedIndex;//获取鼠标选中行并定义变量
|
|
if (rownum != -1)//判断鼠标定位是否有效
|
|
{
|
|
string DataGridStuff_ProductCode = (DataGridStuff.Columns[1].GetCellContent(DataGridStuff.Items[rownum]) as TextBlock).Text;//定位第0列选中行单元格,原料代码
|
|
string DataGridStuff_ProductName = (DataGridStuff.Columns[2].GetCellContent(DataGridStuff.Items[rownum]) as TextBlock).Text;//定位第1列选中行单元格,原料名称
|
|
string DataGridStuff_Price = (DataGridStuff.Columns[3].GetCellContent(DataGridStuff.Items[rownum]) as TextBlock).Text;//定位第2列选中行单元格,价格
|
|
string DataGridStuff_ProductUnit = (DataGridStuff.Columns[4].GetCellContent(DataGridStuff.Items[rownum]) as TextBlock).Text;//定位第3列选中行单元格,供应商
|
|
string DataGridStuff_ProductType = (DataGridStuff.Columns[5].GetCellContent(DataGridStuff.Items[rownum]) as TextBlock).Text;//定位第4列选中行单元格,类型
|
|
/*string DataGridStuff_Color = (DataGridStuff.Columns[6].GetCellContent(DataGridStuff.Items[rownum])as TextBlock).Text;//定位第5列选中行单元格,色彩*/
|
|
string DataGridStuff_Concentration = (DataGridStuff.Columns[7].GetCellContent(DataGridStuff.Items[rownum]) as TextBlock).Text;//定位第6列选中行单元格,浓度
|
|
string DataGridStuff_GRAVITY = (DataGridStuff.Columns[8].GetCellContent(DataGridStuff.Items[rownum]) as TextBlock).Text;//定位第7列选中行单元格,比重
|
|
/*stuff_Color.Background = (DataGridStuff.Columns[6].GetCellContent(DataGridStuff.Items[rownum]) as TextBlock).Background;//定位第5列选中行单元格,色彩,背景色传递至色彩框背景色*/
|
|
stuff_ProductCode.Text = DataGridStuff_ProductCode.ToString();//填入原料代码
|
|
stuff_ProductName.Text = DataGridStuff_ProductName.ToString();//填入原料名称
|
|
stuff_Price.Text = DataGridStuff_Price.ToString();//填入价格
|
|
stuff_ProductType.Text = DataGridStuff_ProductType.ToString();//填入类型
|
|
stuff_ProductUnit.Text = DataGridStuff_ProductUnit.ToString();//填入供应商
|
|
/*stuff_Color.Text = DataGridStuff_Color.ToString();//填入色彩数据*/
|
|
stuff_Concentration.Text = DataGridStuff_Concentration.ToString();//填入浓度
|
|
stuff_GRAVITY.Text = DataGridStuff_GRAVITY.ToString();//填入比重
|
|
/*if (DataGridStuff_ProductType.ToString() == "0") stuff_ProductType.Text = "染料";//判断类型1-染料。2-助剂。3-粉体助剂。
|
|
if (DataGridStuff_ProductType.ToString() == "1") stuff_ProductType.Text = "助剂";
|
|
if (DataGridStuff_ProductType.ToString() == "2") stuff_ProductType.Text = "粉体助剂";*/
|
|
if ((DataGridStuff.Columns[6].GetCellContent(DataGridStuff.Items[rownum]) as TextBlock).Background != null) //定位第5列选中行单元格,色彩,判断参数是否有效
|
|
{
|
|
stuff_Color.Background = (DataGridStuff.Columns[6].GetCellContent(DataGridStuff.Items[rownum]) as TextBlock).Background; //定位第5列选中行单元格,色彩,有效背景色传递至色彩框背景色
|
|
}
|
|
else
|
|
{
|
|
stuff_Color.Background = new SolidColorBrush(System.Windows.Media.Color.FromArgb(255, 255, 255, 255));//白色传递至色彩框背景色
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
///存储色彩变量
|
|
/// </summary>
|
|
public static int ColorCode_SQL;
|
|
private List<Product> Product;
|
|
|
|
private void Stuff_Color_MouseDoubleClick(object sender, MouseButtonEventArgs e)//色彩框双击事件
|
|
{
|
|
|
|
System.Windows.Forms.ColorDialog colorDialog = new System.Windows.Forms.ColorDialog();//使用调色盘控件ColorDialog
|
|
if (colorDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)//打开调色盘
|
|
{
|
|
System.Drawing.Color DColor = colorDialog.Color;////获取选中色彩信息
|
|
//System.Windows.Media.Color MColor = new System.Windows.Media.Color();//转换
|
|
System.Windows.Media.Color MColor = System.Windows.Media.Color.FromArgb(DColor.A, DColor.R, DColor.G, DColor.B);//转换并配置ARGB参数
|
|
stuff_Color.Background = new SolidColorBrush(MColor);//ARGB参数输出至stuff_Color的背景色
|
|
stuff_Color.Foreground = new SolidColorBrush(MColor);//ARGB参数输出至stuff_Color的前景色
|
|
string colorCode = Convert.ToString(DColor.B,16) + Convert.ToString(DColor.G,16) + Convert.ToString(DColor.R,16);//反向十六进制RGB
|
|
//string colorCode = Convert.ToString(DColor.R,16) + Convert.ToString(DColor.G,16) + Convert.ToString(DColor.B,16);//正向十六进制RGB
|
|
ColorCode_SQL = Convert.ToInt32(colorCode, 16);//十六进制RGB转存储数值
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|