上下文不存在
登录窗体using System;
using System.Collections.Generic;
using
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Microsoft.Win32;
using MrCy.BaseClass;
namespace MrCy
{
public partial class frmLogin : Form
{
public frmLogin()
{
InitializeComponent();
}
SoftReg softreg = new SoftReg();
private void Form1_Load(object sender, EventArgs e)
{
RegistryKey retkey = Microsoft.Win32.Registry.CurrentUser.OpenSubKey("software", true).CreateSubKey("wxk").CreateSubKey("wxk.INI");
foreach (string strRNum in retkey.GetSubKeyNames())//判断是否注册
{
if (strRNum == softreg.getRNum())
{
this.Text = "本软件(已注册)";
btnReg.Enabled = false;
main.Show();
return;
}
}
this.Text = "本软件(未注册)";
btnReg.Enabled = true;
btnSetMonitor.Enabled = btnAutoMonitor.Enabled = false;
startMonitor();
MessageBox.Show("您现在使用的是试用版,该软件可以免费试用30次!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
Int32 tLong;
try
{
tLong = (Int32)Registry.GetValue("HKEY_LOCAL_MACHINE\\SOFTWARE\\angel", "UseTimes", 0);
MessageBox.Show("感谢您已使用了" + tLong + "次", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
catch
{
Registry.SetValue("HKEY_LOCAL_MACHINE\\SOFTWARE\\angel", "UseTimes", 0, RegistryValueKind.DWord);
MessageBox.Show("欢迎新用户使用本软件", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
tLong = (Int32)Registry.GetValue("HKEY_LOCAL_MACHINE\\SOFTWARE\\angel", "UseTimes", 0);
if (tLong < 30)
{
int Times = tLong + 1;
Registry.SetValue("HKEY_LOCAL_MACHINE\\SOFTWARE\\angel", "UseTimes", Times);
}
else
{
MessageBox.Show("试用次数已到", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
Application.Exit();
}
////txtName.Focus();
//txtName.Focus();
}
private void txtPwd_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar == 13)
{
btnSubmit_Click(sender, e);
}
}
private void btnSubmit_Click(object sender, EventArgs e)
{
if (txtName.Text == "")
{
MessageBox.Show("请输入用户名", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
else
{
if (txtPwd.Text == "")
{
MessageBox.Show("请输入密码", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
else
{
SqlConnection conn = BaseClass.DBConn.CyCon();
conn.Open();
SqlCommand cmd = new SqlCommand("select count(*) from tb_User where UserName='" + txtName.Text + "' and UserPwd='" + txtPwd.Text + "'", conn);
int i = Convert.ToInt32(cmd.ExecuteScalar());
if (i > 0)
{
cmd = new SqlCommand("select * from tb_User where UserName='" + txtName.Text + "'", conn);
SqlDataReader sdr = cmd.ExecuteReader();
sdr.Read();
string UserPower = sdr["power"].ToString().Trim();
conn.Close();
frmMain main = new frmMain();
main.power = UserPower;
main.Names = txtName.Text;
main.Times = DateTime.Now.ToShortDateString();
main.Show();
this.Hide();
}
else
{
MessageBox.Show("用户名或密码错误");
}
}
}
}
private void btnConcel_Click(object sender, EventArgs e)
{
if (MessageBox.Show("确定退出系统吗?", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Asterisk) == DialogResult.OK)
{
Application.Exit();
}
}
}
}
frmRegister窗休的
using System;
using System.Collections.Generic;
using
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using MrCy.BaseClass;
using Microsoft.Win32;
namespace MrCy
{
public partial class frmRegister : Form
{
public frmRegister()
{
InitializeComponent();
}
SoftReg softreg = new SoftReg();
private void frmRegister_Load(object sender, EventArgs e)
{
txtMNum.Text = softreg.getMNum();
}
private void btnReg_Click(object sender, EventArgs e)
{
if (txtRNum.Text.Equals(softreg.getRNum()))
{
RegistryKey retkey = Microsoft.Win32.Registry.CurrentUser.OpenSubKey("software", true).CreateSubKey("wxk").CreateSubKey("wxk.INI").CreateSubKey(txtRNum.Text);
retkey.SetValue("UserName", "tsoft");
MessageBox.Show("注册成功!", "信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
showMain();
}
else
{
MessageBox.Show("注册码输入错误!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void btnClose_Click(object sender, EventArgs e)
{
showMain();
}
//隐藏注册窗体,显示主窗体
public void showMain()
{
this.Hide();
frmLogin frmLogin = new frmLogin();
frmLogin.Show();
}
}
}