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
}
}