Login

using System;
using System.Windows.Forms;
using ProductManager.Model;
using Microsoft.Win32;

namespace ProductManager
{
    public partial class FormLogin : Form
    {
        #region 自定义对象
        private UserDAO userDAO;
        private UserDTO userDTO;
        string title = "欢迎登录企业销售管理系统!";
        #endregion

        public FormLogin()
        {
            #region
            InitializeComponent();
            userDAO = new UserDAO();
            userDTO = new UserDTO();
            this.AutoSizeMode = AutoSizeMode.GrowAndShrink;
            this.SizeGripStyle = SizeGripStyle.Hide;
            this.FormBorderStyle = FormBorderStyle.Sizable;
            this.StartPosition = FormStartPosition.CenterScreen;
            this.AcceptButton = btnOK;
            btnOK.DialogResult = DialogResult.OK; // 自定义有模式对话框确定按钮。
            this.CancelButton = btnCancel;       // 自定义有模式对话框取消按钮。
            #endregion
        }

        #region FormLoad
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);
            txtID.Clear();
            txtPwd.Clear();
        }
        #endregion

        #region AcceptButton
        private void btnOK_Click(object sender, EventArgs e)
        {
            userDTO.UserName = txtID.Text.Trim();
            userDTO.UserPassword = txtPwd.Text.Trim();
            userDAO.SetUserItem = userDTO;
            if (userDAO.ValidateUser())
            {
                txtID.Focus();
                this.Hide();
                if (this.Owner == null)
                {
                    //using (RegistryKey subKey = Application.UserAppDataRegistry)
                    //{
                    //    int time = Convert.ToInt32(subKey.GetValue("UseTime", 30));
                    //    if (time > 0)
                    //    {
                    //        subKey.SetValue("UseTime", time - 1);
                    //        string message = string.Format("您可以免费使用本软件 :{0}次!", time);
                    //        MessageBox.Show(this, message, "系统提示!", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    using (RegistryKey subKey = Application.UserAppDataRegistry)
                    {
                        FormMain main = new FormMain();
                        subKey.SetValue("Handle", main.Handle);
                        main.Tag = userDTO.UserAccess;
                        main.Show();
                    }
                    //    }
                    //    else
                    //    {
                    //        MessageBox.Show(this, "若继续使用,请购买本软件!", "系统提示!", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    //        Application.Exit();
                    //    }
                    //}
                }
                else
                    this.Owner.Tag = userDTO.UserAccess;
            }
            else
            {
                MessageBox.Show(this, "您输入的用户名或密码有误, 请重新键入用户名和密码!", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                txtPwd.Clear();
                txtID.Focus();
                txtID.SelectAll();
                this.DialogResult = DialogResult.None; // 自定义有模式对话框继续运行
            }
        }

        private void txtUser_KeyPress(object sender, KeyPressEventArgs e)
        {
            e.IsPassword();
        }
        #endregion

        #region CancelButton
        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }
        #endregion

        #region timer_Tick
        private void timer_Tick(object sender, EventArgs e)
        {
            if (this.Text.Length < title.Length)
                this.Text = title.Substring(0, this.Text.Length + 1);
            else
            {
                string str = this.Text.Trim();
                this.Text = (str.Length > 0) ? this.Text.Replace(str[0], ' ') : null;
            }
        }
        #endregion

        #region FormClosing
        protected override void OnFormClosing(FormClosingEventArgs e)
        {
            base.OnFormClosing(e);
            if (e.CloseReason != CloseReason.ApplicationExitCall)
            {
                if (this.Owner == null)
                    Application.Exit();
                else
                    this.txtID.Focus();
            }
        }
        #endregion
    }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值