⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 updateoperator.cs

📁 这是一个图书馆管理用的简化系统
💻 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 UpdateOperator : Form
    {
        public UpdateOperator()
        {
            InitializeComponent();
        }
        #region 验证输入数据
        public bool yanzhen()
        {
            if (oname.Text == "")
            {
                MessageBox.Show("请填写姓名");
                oname.Focus();
                return false;
            }
            if (oid.Text == "")
            {
                MessageBox.Show("请填写操作员编号");
                oid.Focus();
                return false;
            }
            if (Identify.IdentifyCard(odegree.Text) == false)
            {
                MessageBox.Show("身份证号码应为15位或18位");
                odegree.Text = "";
                odegree.Focus();
                return false;
            }
            if (Identify.Pwd(opwd.Text)==false)
            {
                MessageBox.Show("请输入六位密码");
                opwd.Text = "";
                opwd.Focus();
                return false;
            }
            else
            {
                try
                {
                    int id1 = Int32.Parse(oid.Text);

                }
                catch (System.FormatException)
                {
                    MessageBox.Show("操作员编号应由数字组成");
                    return false;

                }
                return true;
            }
        }
        #endregion 
        #region 验证操作员编号是否存在
        public bool oidNull()
        {
            string opeid = "select * from Operate where id='" + oid.Text + "'";
            if (Operator.select(opeid) > 0)
            {
                MessageBox.Show("操作员编号已存在。");
                oid.Text = "";
                return false;
            }
            else
                return true;
        }
         #endregion 
        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                string sqlup = "update Operate set id=@opid1,password=@opassword1,sex=@opsex1,name=@opname1,age=@opage1,school=@opschool1,degreenum=@opdegreen1,address=@opaddress1,phone=@ophone1,addpeople=@opaddpeople1,addate=@opaddate1 where id ='"+oid.Text+"'";
                string connstr = Properties.Settings.Default.Book_manageConnectionString;
                SqlConnection con1 = new SqlConnection(connstr);
                SqlCommand com1 = new SqlCommand(sqlup, con1);
                com1.Parameters.Add("@opid1", SqlDbType.Char).Value =oid.Text;
                com1.Parameters.Add("@opassword1", SqlDbType.Char).Value = opwd.Text;
                com1.Parameters.Add("@opsex1", SqlDbType.Char).Value = sexcomb.Text;
                com1.Parameters.Add("@opname1", SqlDbType.Char).Value = oname.Text;
                com1.Parameters.Add("@opage1", SqlDbType.Char).Value = oage.Text;
                com1.Parameters.Add("@opschool1", SqlDbType.Char).Value = scomb.Text;
                com1.Parameters.Add("@opdegreen1", SqlDbType.Char).Value = odegree.Text;
                com1.Parameters.Add("@opaddress1", SqlDbType.Char).Value = oaddre.Text;
                com1.Parameters.Add("@ophone1", SqlDbType.Char).Value = ophon.Text;
                com1.Parameters.Add("@opaddpeople1", SqlDbType.Char).Value = oaddpe.Text;
                com1.Parameters.Add("@opaddate1", SqlDbType.DateTime).Value = DateTime.Today;

                con1.Open();
                com1.ExecuteNonQuery();
                con1.Close();
                MessageBox.Show("修改成功!");
                string sele = "select * from Operate";
                dataGridView1.DataSource = Operator.Datafill(sele);
            }
            catch(Exception err)
            {
                MessageBox.Show("不能打开数据库。");
                MessageBox.Show(err.ToString());
            }
        }
        private void dataGridView1_MouseClick(object sender, MouseEventArgs e)
        {
            oid.Text = dataGridView1.CurrentRow.Cells[0].Value.ToString();
            oname.Text = dataGridView1.CurrentRow.Cells[1].Value.ToString();
            opwd.Text = dataGridView1.CurrentRow.Cells[2].Value.ToString();
            sexcomb.Text = dataGridView1.CurrentRow.Cells[3].Value.ToString();
            oage.Text = dataGridView1.CurrentRow.Cells[4].Value.ToString();
            scomb.Text = dataGridView1.CurrentRow.Cells[5].Value.ToString();
            odegree.Text = dataGridView1.CurrentRow.Cells[6].Value.ToString();
            oaddre.Text = dataGridView1.CurrentRow.Cells[7].Value.ToString();
            ophon.Text = dataGridView1.CurrentRow.Cells[8].Value.ToString();
            oaddpe.Text = dataGridView1.CurrentRow.Cells[9].Value.ToString();
            oadda.Text = dataGridView1.CurrentRow.Cells[10].Value.ToString();

        }
        private void UpdateOperator_Load(object sender, EventArgs e)
        {
            // TODO: 这行代码将数据加载到表“book_manageDataSet.Operate”中。您可以根据需要移动或移除它。
            this.operateTableAdapter.Fill(this.book_manageDataSet.Operate);

        }

        private void ophon_KeyPress(object sender, KeyPressEventArgs e)
        {
            e.Handled = !Check.Integer(e);
        }

        private void odegree_KeyPress(object sender, KeyPressEventArgs e)
        {
            e.Handled = !Check.Integer(e);
        }


       
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -