事件 应用于授权子窗体传递验证数据给主窗体
标签:nlog 授权 oid result 密码 处理 inner partial img
一、事件定义类,即子窗体
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DataMaintenance.Services;
using DataMaintenance.Modle;
using Utility;
namespace DataMaintenance.UI
{
public partial class Frm_authorization : Form
{
public Frm_authorization()
{
InitializeComponent();
initializeDatasource();
}
///
/// 初始化控件数据源
///
private void initializeDatasource()
{
cmb_user.DataSource = new UserService().getUserList().Where(c => c.DateOfCancellation == null).Select((c) => new { c.userID, c.name,c.pwd,c.RegistrationDate }).ToList();
cmb_user.DisplayMember = "name";
cmb_user.ValueMember = "userID";
}
#region 事件
public event EventHandler authorizPass;
///
/// 事件处理方法,调用端实例化事件委托后就执行
///
///
protected virtual void onAuthorizPass(AuthorizationEventArgs authorizationEventArgs)
{
authorizPass?.Invoke(this, authorizationEventArgs);
}
#endregion
private void btn_certain_Click(object sender, EventArgs e)
{
//this.DialogResult = DialogResult.OK;
if (txt_pwd.Text!="")
{
string pwd = Encrypt.Encode(txt_pwd.Text);
if (new UserService().loginCheck(Convert.ToInt32(cmb_user.SelectedValue), pwd))
{
//引发验证通过事件
AuthorizationEventArgs authorizationEventArgs = new AuthorizationEventArgs();
authorizationEventArgs.userAndPwdRight = true;
onAuthorizPass(authorizationEventArgs);
this.Close();
}
else
{
lbl_information.Text = "";
lbl_information.Text = lbl_information.Text + "您输入受权密码不正确,请重新输入";
}
}
else
{
lbl_information.Text = "";
lbl_information.Text = "请输入受权密码";
}
}
private void btn_cancel_Click(object sender, EventArgs e)
{
this.DialogResult = DialogResult.Cancel;
}
}
public class AuthorizationEventArgs : EventArgs
{
public bool userAndPwdRight { get; set; }
}
}
View Code
二、事件订阅类,即主窗体
///
/// 更新ERP数据库中的模板参数
///
///
///
private void btn_mend_Click(object sender, EventArgs e)
{
Frm_authorization f = new Frm_authorization();
f.authorizPass += modifyTemple;
f.ShowDialog();
if (f.DialogResult == DialogResult.Cancel)
{
f.Close();
}
}
private void modifyTemple( object sender,AuthorizationEventArgs authorizationEventArgs)
{
int editAble;
List sqlParameterList = new List();
SqlParameter sqlParameter1 = new SqlParameter("@VT_ID", "8173");
SqlParameter sqlParameter2 = new SqlParameter("@FieldName", "itaxprice");
SqlParameter sqlParameter3 = new SqlParameter("@vt_cardnumber", "88");
SqlParameter sqlParameter4 = new SqlParameter("@VT_TemplateMode", "0");
string sql = "update voucheritems_base set CanModify = @editAble where VT_ID = @VT_ID and FieldName =@FieldName; ";
string sql2 = "update vouchertemplates_base set VT_TemplateMode=@VT_TemplateMode where vt_cardnumber =@vt_cardnumber and vt_id = @VT_ID ";
if (rb_noEedit.Checked)
{
editAble = 0;
SqlParameter sqlParameterEditAble = new SqlParameter("@editAble", editAble);
sqlParameterList.Add(sqlParameterEditAble);
};
if (rb_edit.Checked)
{
editAble = 1;
SqlParameter sqlParameterEditAble = new SqlParameter("@editAble", editAble);
sqlParameterList.Add(sqlParameterEditAble);
}
sqlParameterList.Add(sqlParameter1);
sqlParameterList.Add(sqlParameter2);
sqlParameterList.Add(sqlParameter3);
sqlParameterList.Add(sqlParameter4);
try
{
int influnceRows1 = Sqlhelper.UpdateWithparameters(sql + sql2, sqlParameterList.ToArray());
//int influnceRows2=Sqlhelper.UpdateWithparameters(sql2, sqlParameterList.ToArray());
//authorizationLog();
MessageBox.Show("更新" + influnceRows1 + "条记录,授权成功", "授权提示");
}
catch (Exception ex)
{
MessageBox.Show("授权出错:" + ex.Message + ex.InnerException, "授权提示");
}
}
View Code
事件 应用于授权子窗体传递验证数据给主窗体
标签:nlog 授权 oid result 密码 处理 inner partial img
原文地址:https://www.cnblogs.com/windy3417/p/13945912.html
评论