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

📄 form5.cs

📁 vs2008 组织部信息系统
💻 CS
字号:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace 团委组织部信息系统
{
    public partial class Form5 : Form
    {
        SqlDataAdapter da;
        DataSet ds;
        public Form5()
        {
            InitializeComponent();
        }

        private void bumenshezhi_infBindingNavigatorSaveItem_Click(object sender, EventArgs e)
        {
            this.Validate();
            this.bumenshezhi_infBindingSource.EndEdit();
            this.tableAdapterManager.UpdateAll(this.tuanweizuzhibu_infDataSet);

        }

        private void bumenshezhi_infBindingNavigatorSaveItem_Click_1(object sender, EventArgs e)
        {
            this.Validate();
            this.bumenshezhi_infBindingSource.EndEdit();
            this.tableAdapterManager.UpdateAll(this.tuanweizuzhibu_infDataSet);

        }

        private void Form5_Load(object sender, EventArgs e)
        {

        }

        private void buMenIdLabel_Click(object sender, EventArgs e)
        {

        }

        private void buMenIdTextBox_TextChanged(object sender, EventArgs e)
        {

        }

        private void bumenshezhi_infDataGridView_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            buMenIdTextBox.Text = bumenshezhi_infDataGridView.Rows[e.RowIndex].Cells[0].Value.ToString();
            buMenNameTextBox.Text = bumenshezhi_infDataGridView.Rows[e.RowIndex].Cells[1].Value.ToString();
            buZhangNameTextBox.Text = bumenshezhi_infDataGridView.Rows[e.RowIndex].Cells[2].Value.ToString();
        }

        private void fillByToolStripButton_Click(object sender, EventArgs e)
        {
            try
            {
                this.bumenshezhi_infTableAdapter.FillBy(this.tuanweizuzhibu_infDataSet.bumenshezhi_inf);
            }
            catch (System.Exception ex)
            {
                System.Windows.Forms.MessageBox.Show(ex.Message);
            }

        }

        private void fillBy1ToolStripButton_Click(object sender, EventArgs e)
        {
            try
            {
                this.bumenshezhi_infTableAdapter.FillBy1(this.tuanweizuzhibu_infDataSet.bumenshezhi_inf);
            }
            catch (System.Exception ex)
            {
                System.Windows.Forms.MessageBox.Show(ex.Message);
            }

        }

        private void button6_Click(object sender, EventArgs e)
        {
            string connectionstring = @"data source=localhost;Initial catalog=tuanweizuzhibu_inf;integrated security=SSPI;";
            string commandstring = @"select * from bumenshezhi_inf where buMenId like'%" + textBox1.Text + "%'or buMenName like'%" + textBox1.Text + "%' or buZhangName like'%" + textBox1.Text + "%'";
            da = new SqlDataAdapter(commandstring, connectionstring);
            ds = new DataSet();
            da.Fill(ds, "bumenshezhi_inf");
            bumenshezhi_infDataGridView.DataSource = ds.Tables["bumenshezhi_inf"];

        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {

        }

        private void label1_Click(object sender, EventArgs e)
        {

        }

        private void button5_Click(object sender, EventArgs e)
        {
            buMenIdTextBox.Text = "";
            buMenNameTextBox.Text = "";
            buZhangNameTextBox.Text = "";
        }

        private void button1_Click(object sender, EventArgs e)
        {
            string connectionstring = @"data source=localhost;Initial catalog=tuanweizuzhibu_inf;integrated security=SSPI;";
            string commandstring = @"select * from bumenshezhi_inf where buMenId like'%" + buMenIdTextBox.Text + "%'or buMenName like'%" + buMenNameTextBox.Text + "%' or buZhangName like'%" + buZhangNameTextBox.Text + "%'";
            if (buMenIdTextBox.Text == "")
            { MessageBox.Show(" 不能为空!"); }
            else
            {

                SqlConnection conn = new SqlConnection(connectionstring);
                SqlCommand cmd = new SqlCommand(commandstring, conn);
                SqlDataReader dr;
                int prime = 0;
                conn.Open();
                dr = cmd.ExecuteReader();
                while (dr.Read())
                {
                    if (dr.GetString(0) == buMenIdTextBox.Text)
                    {
                        MessageBox.Show("不能添加相同信息!");
                        prime = 1;
                        break;
                    }
                }
                if (prime == 0)
                    try
                    {
                        da = new SqlDataAdapter(commandstring, connectionstring);
                        SqlCommandBuilder scb = new SqlCommandBuilder(da);
                        ds = new DataSet();
                        da.Fill(ds, "bumenshezhi_inf");
                        DataTable mytable = ds.Tables["bumenshezhi_inf"];
                        DataRow myrow = ds.Tables["bumenshezhi_inf"].NewRow();
                        myrow[0] = buMenIdTextBox.Text.ToString();
                        myrow[1] = buMenNameTextBox.Text.ToString();
                        myrow[2] = buZhangNameTextBox.Text.ToString();


                        mytable.Rows.Add(myrow);
                        da.Update(ds, "bumenshezhi_inf");
                        ds.AcceptChanges();
                        MessageBox.Show("添加成功!");
                        bumenshezhi_infDataGridView.DataSource = ds.Tables["bumenshezhi_inf"];
                    }
                    catch (SqlException ex)
                    {
                        MessageBox.Show("添加失败:" + ex.Message, "出现错误",
                            MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                    finally
                    {
                        dr.Close();
                        conn.Close();
                    }
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            string connectionstring = @"data source=localhost;Initial catalog=tuanweizuzhibu_inf;integrated security=SSPI;";
            string commandstring = @"select * from bumenshezhi_inf where buMenId like'%" + buMenIdTextBox.Text + "%'or buMenName like'%" + buMenNameTextBox.Text + "%' or buZhangName like'%" + buZhangNameTextBox.Text + "%'";
            if (buMenIdTextBox.Text == "" || buMenNameTextBox.Text == "" || buZhangNameTextBox.Text == "" )
            { MessageBox.Show("请选择要删除的对象!"); }
            else
            {
                da = new SqlDataAdapter(commandstring, connectionstring);
                SqlCommandBuilder scb = new SqlCommandBuilder(da);
                ds = new DataSet();
                da.Fill(ds, "bumenshezhi_inf");
                bumenshezhi_infDataGridView.DataSource = ds.Tables["bumenshezhi_inf"];
                DataTable mytable = ds.Tables["bumenshezhi_inf"];
                mytable.Rows[bumenshezhi_infDataGridView.CurrentRow.Index].Delete();
                da.Update(ds, "bumenshezhi_inf");
                ds.AcceptChanges();
                MessageBox.Show("信息删除成功!");
                bumenshezhi_infDataGridView.DataSource = ds.Tables["bumenshezhi_inf"];
                buMenIdTextBox.Text = "";
                buMenNameTextBox.Text = "";
                buZhangNameTextBox.Text = "";
            }
        }

        private void button3_Click(object sender, EventArgs e)
        {
            string connectionstring = @"data source=localhost;Initial catalog=tuanweizuzhibu_inf;integrated security=SSPI;";
            string commandstring = @"select * from bumenshezhi_inf where buMenId like'%" + buMenIdTextBox.Text + "%'or buMenName like'%" + buMenNameTextBox.Text + "%' or buZhangName like'%" + buZhangNameTextBox.Text + "%'";
            SqlConnection conn = new SqlConnection(connectionstring);
            string sqlStatement = "UPDATE work_inf SET " +
                    "buMenId='" + buMenIdTextBox.Text + "'," +
                    "buMenName='" + buMenNameTextBox.Text + "'," +
                    "buZhangName='" + buZhangNameTextBox.Text + "'" +
                    "WHERE buMenId = '" + buMenIdTextBox.Text + "'";
            SqlCommand cmd = new SqlCommand(sqlStatement, conn);
            try
            {
                conn.Open();
                int rowAffected = cmd.ExecuteNonQuery();
                if (rowAffected == 1)
                {
                    da = new SqlDataAdapter(commandstring, connectionstring);
                    ds = new DataSet();
                    da.Fill(ds, "bumenshezhi_inf");
                    MessageBox.Show("修改成功!");
                    bumenshezhi_infDataGridView.DataSource = ds.Tables["bumenshezhi_inf"];
                    buMenIdTextBox.Text = "";
                    buMenNameTextBox.Text = "";
                    buZhangNameTextBox.Text = "";
                }

            }

            catch (SqlException ex)
            {
                MessageBox.Show("修改失败:" + ex.Message, "出现错误",
                    MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {

                conn.Close();
            }
        }

        private void button4_Click(object sender, EventArgs e)
        {
            this.Hide();
        }
    }
}

⌨️ 快捷键说明

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