183 lines
6.3 KiB
C#
183 lines
6.3 KiB
C#
using JY.DAL;
|
|||
|
|
using JY.Model;
|
||
|
|
using System;
|
||
|
|
using System.Collections.Generic;
|
||
|
|
using System.ComponentModel;
|
||
|
|
using System.Data;
|
||
|
|
using System.Drawing;
|
||
|
|
using System.Linq;
|
||
|
|
using System.Text;
|
||
|
|
using System.Threading.Tasks;
|
||
|
|
using System.Windows.Forms;
|
||
|
|
|
||
|
|
namespace JY.Inspection.Frm
|
||
|
|
{
|
||
|
|
public partial class FrmParaConfig : MetroFramework.Forms.MetroForm
|
||
|
|
{
|
||
|
|
public delegate void SendParamIN();
|
||
|
|
public SendParamIN sendParamIN;
|
||
|
|
|
||
|
|
/// <summary>
|
||
|
|
/// 数据库访问接口
|
||
|
|
/// </summary>
|
||
|
|
private IDbHelper dbHelper = new OpSqlDataBase();
|
||
|
|
/// <summary>
|
||
|
|
/// 定义DataGridView数据源
|
||
|
|
/// </summary>
|
||
|
|
private BindingList<ProductPara> blPLCConfigBaseList = new BindingList<ProductPara>();
|
||
|
|
|
||
|
|
|
||
|
|
public FrmParaConfig()
|
||
|
|
{
|
||
|
|
InitializeComponent();
|
||
|
|
}
|
||
|
|
|
||
|
|
private void FrmParaEdit_Load(object sender, EventArgs e)
|
||
|
|
{
|
||
|
|
this.dgvEdit.AutoGenerateColumns = false;
|
||
|
|
this.dgvEdit.DataSource = blPLCConfigBaseList;
|
||
|
|
setComb();
|
||
|
|
}
|
||
|
|
/// <summary>
|
||
|
|
/// 加载产品型号下拉
|
||
|
|
/// </summary>
|
||
|
|
private void setComb()
|
||
|
|
{
|
||
|
|
var list = dbHelper.GetProductModelList();
|
||
|
|
|
||
|
|
cmbProductModel.DataSource = list;
|
||
|
|
cmbProductModel.DisplayMember = "ModelName";
|
||
|
|
cmbProductModel.ValueMember = "ModelName";
|
||
|
|
}
|
||
|
|
|
||
|
|
/// <summary>
|
||
|
|
/// 保存数据
|
||
|
|
/// </summary>
|
||
|
|
/// <param name="sender"></param>
|
||
|
|
/// <param name="e"></param>
|
||
|
|
private void btnOK_Click(object sender, EventArgs e)
|
||
|
|
{
|
||
|
|
string strModelType = cmbProductModel.Text.Trim();
|
||
|
|
if (string.IsNullOrEmpty(strModelType) || blPLCConfigBaseList.Count <= 0)
|
||
|
|
{
|
||
|
|
MessageBox.Show("产品型号和参数列表不能为空!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
try
|
||
|
|
{
|
||
|
|
dbHelper.AddProductParaList(blPLCConfigBaseList.ToList());
|
||
|
|
MessageBox.Show("保存成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||
|
|
}
|
||
|
|
catch (Exception ex)
|
||
|
|
{
|
||
|
|
MessageBox.Show("保存失败:" + ex.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
/// <summary>
|
||
|
|
/// 添加型号
|
||
|
|
/// </summary>
|
||
|
|
/// <param name="sender"></param>
|
||
|
|
/// <param name="e"></param>
|
||
|
|
private void btnAddProductModel_Click(object sender, EventArgs e)
|
||
|
|
{
|
||
|
|
var productModel = new ProductModel();
|
||
|
|
productModel.ModelName = txtProductModel.Text;
|
||
|
|
productModel.Remark = txtProductModel.Text;
|
||
|
|
|
||
|
|
if (string.IsNullOrEmpty(productModel.ModelName))
|
||
|
|
{
|
||
|
|
MessageBox.Show("产品型号不能为空!", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
|
||
|
|
try
|
||
|
|
{
|
||
|
|
dbHelper.AddProductModel(productModel);
|
||
|
|
setComb();
|
||
|
|
MessageBox.Show("新增成功!", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||
|
|
}
|
||
|
|
catch (Exception ex)
|
||
|
|
{
|
||
|
|
MessageBox.Show("新增失败:" + ex.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||
|
|
}
|
||
|
|
|
||
|
|
//同步刷新主界面的类型选项
|
||
|
|
sendParamIN();
|
||
|
|
}
|
||
|
|
|
||
|
|
/// <summary>
|
||
|
|
/// 删除型号
|
||
|
|
/// </summary>
|
||
|
|
/// <param name="sender"></param>
|
||
|
|
/// <param name="e"></param>
|
||
|
|
private void btnDelProductModel_Click(object sender, EventArgs e)
|
||
|
|
{
|
||
|
|
if (string.IsNullOrEmpty(cmbProductModel.Text.Trim()))
|
||
|
|
{
|
||
|
|
MessageBox.Show("产品型号不能为空!", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
if (MessageBox.Show("删除该型号设置将无法恢复,确定要删除该产品型号?", "系统提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
|
||
|
|
{
|
||
|
|
try
|
||
|
|
{
|
||
|
|
dbHelper.DelProductModel(cmbProductModel.Text);
|
||
|
|
|
||
|
|
setComb();
|
||
|
|
MessageBox.Show("删除成功!", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||
|
|
}
|
||
|
|
catch (Exception ex)
|
||
|
|
{
|
||
|
|
MessageBox.Show("删除失败:" + ex.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
/// <summary>
|
||
|
|
/// 产品型号下拉框选择变更事件
|
||
|
|
/// </summary>
|
||
|
|
/// <param name="sender"></param>
|
||
|
|
/// <param name="e"></param>
|
||
|
|
private void cmbProductModel_SelectedIndexChanged(object sender, EventArgs e)
|
||
|
|
{
|
||
|
|
var list = dbHelper.GetProductParaByProdModel(cmbProductModel.Text);
|
||
|
|
blPLCConfigBaseList.Clear();
|
||
|
|
foreach (var item in list)
|
||
|
|
{
|
||
|
|
blPLCConfigBaseList.Add(item);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
/// <summary>
|
||
|
|
/// 关闭事件
|
||
|
|
/// </summary>
|
||
|
|
/// <param name="sender"></param>
|
||
|
|
/// <param name="e"></param>
|
||
|
|
private void FrmParaEdit_FormClosing(object sender, FormClosingEventArgs e)
|
||
|
|
{
|
||
|
|
this.DialogResult = DialogResult.OK;
|
||
|
|
}
|
||
|
|
|
||
|
|
/// <summary>
|
||
|
|
/// DataGrid自动添加行号
|
||
|
|
/// </summary>
|
||
|
|
/// <param name="sender"></param>
|
||
|
|
/// <param name="e"></param>
|
||
|
|
private void dgvEdit_RowPostPaint(object sender, DataGridViewRowPostPaintEventArgs e)
|
||
|
|
{
|
||
|
|
//自动编号,与数据无关
|
||
|
|
Rectangle rectangle = new Rectangle(e.RowBounds.Location.X,
|
||
|
|
e.RowBounds.Location.Y,
|
||
|
|
dgvEdit.RowHeadersWidth - 4,
|
||
|
|
e.RowBounds.Height);
|
||
|
|
TextRenderer.DrawText(e.Graphics,
|
||
|
|
(e.RowIndex + 1).ToString(),
|
||
|
|
dgvEdit.RowHeadersDefaultCellStyle.Font,
|
||
|
|
rectangle,
|
||
|
|
dgvEdit.RowHeadersDefaultCellStyle.ForeColor,
|
||
|
|
TextFormatFlags.VerticalCenter | TextFormatFlags.Right);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|