📄 frm会员管理.cs
字号:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data.SqlClient;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace 餐饮管理系统
{
public partial class Frm会员管理 : Form
{
public Frm会员管理()
{
InitializeComponent();
}
private void buttonAddOk_Click(object sender, EventArgs e)
{
//从界面上接收数据
string strMemID = textBox会员号.Text.Trim();
string strMemName = textBoxName.Text.Trim();
string strPwd = textBoxPwd.Text.Trim();
string strRePwd = textBoxRePwd.Text.Trim();
string strSex = comboBoxMemSex.Text.Trim();
string strBrith = dateTimePickerBrithday.Value.ToString();
string strMemClass = comboBoxMemClass.Text.Trim();
string str凭证类型 = comboBox凭证类型.Text.Trim();
string strMem证件号 = textBox证件号.Text.Trim();
string strMemAddress = textBoxAddress.Text.Trim();
//验证数据正确性, 不正确则抛出错误
if (strMemName == "")
{
Utility.SetErr(textBoxName, "用户名不能为空!");
return;
}
if (strPwd == "" || strRePwd == "")
{
Utility.SetErr(buttonAddOk, "密码不能为空!");
return;
}
if (strRePwd != strPwd)
{
Utility.SetErr(textBoxRePwd, "两次密码不一致!请重新输入!");
textBoxPwd.Text = "";
textBoxRePwd.Text = "";
textBoxPwd.Focus();
return;
}
//注册数据插入数据库
string strSql = string.Format("insert into dt_会员信息(会员号,密码,姓名,性别,生日,级别,凭证类型,证件号,详细地址)values('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}')",
strMemID, strPwd, strMemName, strSex, strBrith, strMemClass, str凭证类型,strMem证件号, strMemAddress);
if(DBserver.setCommNornQuey(strSql)>0)
MessageBox.Show("注册成功!");
}
private void Frm会员管理_Load(object sender, EventArgs e)
{
this.Cursor = Cursors.WaitCursor;
浏览会员信息ToolStripMenuItem_Click(null, null);
this.Cursor = Cursors.Default;
}
//private void tabControl1_Selecting(object sender, TabControlCancelEventArgs e)
//{
// 浏览会员信息ToolStripMenuItem_Click(null, null);
//}
private void 浏览会员信息ToolStripMenuItem_Click(object sender, EventArgs e)
{
try
{
//显示选中页面
tabControl1.SelectedTab = tabPageViewInfo;
//显示会员信息到界面上
string strSql = "select 会员号,姓名,性别,生日,级别,凭证类型,证件号,详细地址 from dt_会员信息";
DataTable dt = DBserver.setComGetTable(strSql);
dataGridView1.DataSource = dt;
}
catch (Exception ee)
{
MessageBox.Show(ee.Message);
}
}
private void 注册ToolStripMenuItem_Click(object sender, EventArgs e)
{
//产生自动编号
#region 产生工程编号
//产生工程编号
string strVipID = string.Format("{0}{1:D2}{2:D2}", DateTime.Today.Year, DateTime.Today.Month, DateTime.Today.Day);
string strSql = string.Format("select 会员号 from dt_会员信息 where 会员号 like '{0}%'", strVipID);
DataTable dt = DBserver.setComGetTable(strSql);
int nMax = 0;
foreach (DataRow drow in dt.Rows)
{
//获取数据的自增部分,并产生最大值。
string strCurr = drow[0].ToString().Substring(8);
int nIn = int.Parse(strCurr);
if (nIn >= nMax)
{
nMax = nIn;
}
}
//调用方法
strVipID = strVipID + GetAddPart(nMax + 1, 4);
textBox会员号.Text = strVipID;
#endregion
//注册时
tabControl1.SelectedTab = tabPageTakeIn;
}
#region 工程编号尾号
private string GetAddPart(int nIn, int nLength)
{
string strOut = "";
if (nIn == 1)
{
strOut = "0001";
}
else
{
string strIn = nIn.ToString();
strOut = strIn;
for (int i = 0; i < nLength - strIn.Length; i++)
{
strOut = "0" + strOut;
}
}
return strOut;
}
#endregion
string m_strCurrID="";
private void 编辑ToolStripMenuItem_Click(object sender, EventArgs e)
{
if (dataGridView1.SelectedRows.Count == 0)
{
MessageBox.Show("编辑前必须选中一行数据!");
return;
}
m_strCurrID = dataGridView1.CurrentRow.Cells["会员号"].Value.ToString();
string strCurIDsQl = string.Format("select *from dt_会员信息 where 会员号='{0}'", m_strCurrID);
DataTable dt = DBserver.setComGetTable(strCurIDsQl);
//将获取的数据赋值到界面上
DataRow dr = dt.Rows[0];
textBoxExitID.Text = dr["会员号"].ToString();
textBoxExitName.Text = dr["姓名"].ToString();
//textBoxExitPwd.Text = dr["密码"].ToString();
//textBoxExitRePwd.Text = dr["密码"].ToString();
textBoxExit证件号.Text = dr["证件号"].ToString();
comboBoxExitSex.Text = dr["性别"].ToString();
dateTimePickerExitBirthday.Value = Convert.ToDateTime(dr["生日"]);
comboBoxExitMemClass.Text = dr["级别"].ToString();
textBoxExit证件号.Text = dr["证件号"].ToString();
textBoxExitAddress.Text = dr["详细地址"].ToString();
comboBoxExit凭证类型.SelectedItem = dr["凭证类型"].ToString();
tabControl1.SelectedTab = tabPageExitParter;
}
//编辑确定时发生
private void buttonExitOK_Click(object sender, EventArgs e)
{
//从界面上接收数据
string strMemID = textBoxExitID.Text.Trim();
string strMemName = textBoxExitName.Text.Trim();
string strSQL = string.Format("select 密码 from dt_会员信息 where 会员号='{0}'", m_strCurrID);
string strOldpwd = DBserver.setCommGetScalar(strSQL).ToString();
string strPwd = "";
string strRePwd = "";
//判断旧密码是否正确
if (strOldpwd == textBoxOldPwd.Text.Trim())
{
strPwd = textBoxExitPwd.Text.Trim();
strRePwd = textBoxExitRePwd.Text.Trim();
}
else
{
Utility.SetErr(textBoxOldPwd, "原密码不正确!请重新填写!");
textBoxOldPwd.Text = "";
textBoxExitPwd.Text = "";
textBoxExitRePwd.Text = "";
textBoxOldPwd.Focus();
}
string strSex = comboBoxExitSex.Text.Trim();
string strBrith = dateTimePickerExitBirthday.Value.ToString();
string strMemClass = comboBoxExitMemClass.Text.Trim();
string str凭证类型 = comboBoxExit凭证类型.Text.Trim();
string strMem证件号 = textBoxExit证件号.Text.Trim();
string strMemAddress = textBoxExitAddress.Text.Trim();
//验证数据正确性, 不正确则抛出错误
if (strMemName == "")
{
Utility.SetErr(textBoxName, "用户名不能为空!");
return;
}
if (strPwd == "" || strRePwd == "")
{
Utility.SetErr(buttonAddOk, "密码不能为空!");
return;
}
if (strRePwd != strPwd)
{
Utility.SetErr(textBoxRePwd, "两次密码不一致!请重新输入!");
textBoxPwd.Text = "";
textBoxRePwd.Text = "";
textBoxPwd.Focus();
return;
}
//将修改后的数据在数据库中修改
string strSql = string.Format("update dt_会员信息 set 会员号='{0}',密码='{1}',姓名='{2}',性别='{3}',生日='{4}'" +
",级别='{5}',凭证类型='{6}',证件号='{7}',详细地址='{8}' where 会员号='{9}'",
strMemID, strPwd, strMemName, strSex, strBrith, strMemClass, str凭证类型, strMem证件号, strMemAddress, m_strCurrID);
if (DBserver.setCommNornQuey(strSql) > 0)
MessageBox.Show("编辑成功!");
}
private void 删除DToolStripMenuItem_Click(object sender, EventArgs e)
{
if (dataGridView1.SelectedRows.Count == 0)
{
MessageBox.Show("删除数据前必须选中一行!");
return;
}
if (MessageBox.Show("你将删除一个会员的信息,确认删除此会员吗?", "可可西里提示!", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning) == DialogResult.OK)
{
string strCurVIPID = dataGridView1.CurrentRow.Cells["会员号"].Value.ToString();
string strSql = string.Format("delete from dt_会员信息 where 会员号='{0}'", strCurVIPID);
if (DBserver.setCommNornQuey(strSql) > 0)
{
MessageBox.Show("删除成功!");
//调用一个方法刷新界面
浏览会员信息ToolStripMenuItem_Click(null, null);
}
}
else
return;
}
private void 退出XToolStripMenuItem_Click(object sender, EventArgs e)
{
//关闭当前窗体
this.Close();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -