码迷,mamicode.com
首页 > Windows程序 > 详细

事件 应用于授权子窗体传递验证数据给主窗体

时间:2020-11-13 13:16:37      阅读:33      评论:0      收藏:0      [点我收藏+]

标签: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();
        }

     


        /// <summary>
        /// 初始化控件数据源
        /// </summary>
        private void initializeDatasource()
        {
            cmb_user.DataSource = new UserService().getUserList().Where<UserModle>(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<AuthorizationEventArgs> authorizPass;

        /// <summary>
        /// 事件处理方法,调用端实例化事件委托后就执行
        /// </summary>
        /// <param name="authorizationEventArgs"></param>
        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

 

二、事件订阅类,即主窗体

技术图片
   /// <summary>
        /// 更新ERP数据库中的模板参数
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        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<SqlParameter> sqlParameterList = new List<SqlParameter>();
            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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!