123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160 |
- using System;
- using System.Collections.Generic;
- using ProjectBase.Controls;
- using SIMDP.BLL;
- using ProjectBase.Data.Pager;
- using SIMDP.Model;
- using ProjectBase.Util;
- using ProjectBase.Data.BaseDAL;
- using ProjectBase.Data.Logs;
- using ProjectBase.Data.Redis;
- using StackExchange.Redis;
- using System.Windows.Forms;
- using System.Drawing;
- using System.Data;
- using System.Data.Common;
- using System.Text.RegularExpressions;
- namespace SIMDP.Project
- {
- public partial class FormEditModel : DevExpress.XtraEditors.XtraForm
- {
- public delegate void delegateSaveFinished();
- public event delegateSaveFinished saveFinshed;
- private MoModelContrast mcmodel;
- public FormEditModel()
- {
- InitializeComponent();
- btn_Save.Enabled = false;
- btn_Add.Enabled = true;
- }
- /// <summary>
- /// 通过修改按钮进入的构造函数
- /// </summary>
- /// <param name="model"></param>
- public FormEditModel(MoModelContrast model)
- {
- InitializeComponent();
- txt_plccode.Text = model.PLC_Code.ToString();
- txt_model.Text = model.Model_Code.ToString();
- txt_engname.Text = model.English_Name;
- txt_chiname.Text = model.Chinese_Name;
- btn_Save.Enabled = true;
- btn_Add.Enabled = false;
- mcmodel = model;
- }
- private bool CheckCriticalField()
- {
- if (string.IsNullOrEmpty(txt_plccode.Text) || string.IsNullOrEmpty(txt_model.Text))
- return false;
- return true;
- }
- private void btn_Add_Click(object sender, EventArgs e)
- {
- if(!CheckCriticalField())
- {
- DevExpress.XtraEditors.XtraMessageBox.Show("请将关键字段填写完整。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
- return;
- }
- try
- {
- MoModelContrast model = new MoModelContrast()
- {
- PLC_Code = Convert.ToInt32(txt_plccode.Text),
- Model_Code = txt_model.Text,
- English_Name = txt_engname.Text,
- Chinese_Name = txt_chiname.Text,
- };
- bool bflag = BLLFactory<BlModelContrast>.Instance.Insert(model);
- if (bflag)
- {
- LogHelper.log.Info($"【车型解析界面--添加按钮】用户修改条目:{model.PLC_Code} {model.Model_Code}");
- DevExpress.XtraEditors.XtraMessageBox.Show("添加成功。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
- saveFinshed();
- this.Close();
- }
- }
- catch (Exception ex )
- {
- DevExpress.XtraEditors.XtraMessageBox.Show($"添加失败。\n{ex.Message}", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
- LogHelper.log.Error($"异常:{ex.Message}");
- }
- }
- private void btn_Save_Click(object sender, EventArgs e)
- {
- if (!CheckCriticalField())
- {
- DevExpress.XtraEditors.XtraMessageBox.Show("请将关键字段填写完整。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
- return;
- }
- try
- {
- mcmodel.PLC_Code = Convert.ToInt32(txt_plccode.Text);
- mcmodel.Model_Code = txt_model.Text;
- mcmodel.English_Name = txt_engname.Text;
- mcmodel.Chinese_Name = txt_chiname.Text;
- bool bflag = BLLFactory<BlModelContrast>.Instance.Update(mcmodel,mcmodel.Id);
- if (bflag)
- {
- LogHelper.log.Info($"【车型解析界面--修改按钮】用户修改条目:{mcmodel.PLC_Code} {mcmodel.Model_Code}");
- DevExpress.XtraEditors.XtraMessageBox.Show("修改成功。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
- saveFinshed();
- this.Close();
- }
- }
- catch (Exception ex )
- {
- DevExpress.XtraEditors.XtraMessageBox.Show($"修改失败。\n{ex.Message}", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
- LogHelper.log.Error($"异常:{ex.Message}");
- }
- }
- private void btn_Cancel_Click(object sender, EventArgs e)
- {
- this.Close();
- }
- protected override bool ProcessCmdKey(ref System.Windows.Forms.Message msg, System.Windows.Forms.Keys keyData)
- {
- int WM_KEYDOWN = 256;
- int WM_SYSKEYDOWN = 260;
- if (msg.Msg == WM_KEYDOWN | msg.Msg == WM_SYSKEYDOWN)
- {
- switch (keyData)
- {
- case Keys.Escape:
- //Application.Exit();
- this.Close();
- break;
- }
- }
- return false;
- }
- private void txt_plccode_KeyPress(object sender, KeyPressEventArgs e)
- {
- if (e.KeyChar != 8 && !Char.IsDigit(e.KeyChar))
- {
- e.Handled = true;
- }
- }
- }
- }
|