📄 updateadmin.cs
字号:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace BMS
{
public partial class UpdateAdmin : Form
{
public UpdateAdmin()
{
InitializeComponent();
}
#region 验证输入数据
public bool yanzhen()
{
if (aname.Text == "")
{
MessageBox.Show("请填写姓名");
aname.Focus();
return false;
}
if (aid.Text == "")
{
MessageBox.Show("请填写管理员编号");
aid.Focus();
return false;
}
if (Identify.IdentifyCard(a_degree.Text) == false)
{
MessageBox.Show("身份证号码应为15位或18位");
a_degree.Text = "";
a_degree.Focus();
return false;
}
if (Identify.Pwd(apwd.Text) == false)
{
MessageBox.Show("请输入六位密码");
apwd.Text = "";
apwd.Focus();
return false;
}
else
{
try
{
int id1 = Int32.Parse(aid.Text);
}
catch (System.FormatException)
{
MessageBox.Show("管理员编号应由数字组成");
return false;
}
return true;
}
}
#endregion
#region 验证管理员编号是否存在
public bool aidNull()
{
string a_id = "select * from Admin where Ad_id='"+aid.Text+"'";
if (Operator.select(a_id) > 0)
{
MessageBox.Show("管理员编号已存在。");
aid.Text = "";
return false;
}
else
return true;
}
#endregion
private void UpdateAdmin_Load(object sender, EventArgs e)
{
// TODO: 这行代码将数据加载到表“book_manageDataSet.Admin”中。您可以根据需要移动或移除它。
this.adminTableAdapter.Fill(this.book_manageDataSet.Admin);
}
private void button1_Click(object sender, EventArgs e)
{
try
{
string sqlup = "update Admin set Ad_id=@adid,Ad_pwd=@adpwd,Ad_sex=@adsex,Ad_name=@adname,Ad_degree=@addegree,Ad_address=@adaddress,Ad_phone=@adphone,Ad_people=@adpeople,Ad_date=@adaddate where Ad_id ='" + aid.Text + "'";
string connstr = Properties.Settings.Default.Book_manageConnectionString;
SqlConnection con = new SqlConnection(connstr);
SqlCommand com = new SqlCommand(sqlup, con);
com.Parameters.Add("@adid", SqlDbType.Char).Value = aid.Text;
com.Parameters.Add("@adpwd", SqlDbType.Char).Value =apwd.Text;
com.Parameters.Add("@adsex", SqlDbType.Char).Value =asexcom.Text;
com.Parameters.Add("@adname", SqlDbType.Char).Value = aname.Text;
com.Parameters.Add("@addegree", SqlDbType.Char).Value = a_degree.Text;
com.Parameters.Add("@adaddress", SqlDbType.Char).Value = a_adre.Text;
com.Parameters.Add("@adphone", SqlDbType.Char).Value = aphone.Text;
com.Parameters.Add("@adpeople", SqlDbType.Char).Value = apeople.Text;
com.Parameters.Add("@adaddate", SqlDbType.DateTime).Value = DateTime.Today;
con.Open();
com.ExecuteNonQuery();
con.Close();
MessageBox.Show("修改成功!");
string se = "select * from Admin";
dataGridView1.DataSource = Operator.Datafill(se);
}
catch (Exception err)
{
//MessageBox.Show("不能打开数据库。");
MessageBox.Show(err.ToString());
}
}
private void dataGridView1_MouseDown(object sender, MouseEventArgs e)
{
aid.Text = dataGridView1.CurrentRow.Cells[0].Value.ToString();
apwd.Text = dataGridView1.CurrentRow.Cells[1].Value.ToString();
aname.Text = dataGridView1.CurrentRow.Cells[2].Value.ToString();
asexcom.Text = dataGridView1.CurrentRow.Cells[3].Value.ToString();
a_degree.Text = dataGridView1.CurrentRow.Cells[4].Value.ToString();
a_adre.Text = dataGridView1.CurrentRow.Cells[5].Value.ToString();
aphone.Text= dataGridView1.CurrentRow.Cells[6].Value.ToString();
apeople.Text = dataGridView1.CurrentRow.Cells[7].Value.ToString();
a_date.Text = dataGridView1.CurrentRow.Cells[8].Value.ToString();
}
private void a_degree_KeyUp(object sender, KeyEventArgs e)
{
}
private void a_degree_KeyPress(object sender, KeyPressEventArgs e)
{
e.Handled = !Check.Integer(e);
}
private void aphone_KeyPress(object sender, KeyPressEventArgs e)
{
e.Handled = !Check.Integer(e);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -