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

📄 adddepartment.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 renshiguanli
{
    public partial class AddDepartment : Form
    {
        public AddDepartment()
        {
            InitializeComponent();
        }

        private void AddDepartment_Load(object sender, EventArgs e)
        {

        }

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

        public bool Compare_string(string a, string b)
        {//比较两个字符串是否相似匹配
            bool same;
            int i, j;
            for (i = 0, j = 0; i < a.Length && j < b.Length; i++, j++)
            {
                if (a[i] != b[j]) break;
            }
            if (i == a.Length && j == b.Length) 
            {
                same = true;
                return same;
            }
            else if (i == a.Length && j < b.Length)
            {
                for (; j < b.Length; j++)
                {
                    if (b[j].ToString() != " ") break;
                }
                if (j == b.Length)
                {
                    same = true;
                    return same;
                }
                else
                {
                    same = false;
                    return same;
                }
            }
            else if (i < a.Length && j == b.Length)
            {
                for (; i < a.Length; j++)
                {
                    if (a[i].ToString() != " ") break;
                }
                if (i == a.Length)
                {
                    same = true;
                    return same;
                }
                else
                {
                    same = false;
                    return same;
                }
            }
            else
            {
                same = false;
                return same;
            }
        }

        private void Sure_Click(object sender, EventArgs e)
        {
            if (textBox1.Text != null && textBox1.Text != ""
                && textBox2.Text != null && textBox2.Text != ""
                && textBox3.Text != null && textBox3.Text != "")
            {
                //首先连接数据库 察看新建部门名称是否重复
                //连接数据库(部门)
                SqlConnection Myconn = new SqlConnection("Data Source=NUAA\\SQLEXPRESS;Integrated Security=SSPI;Initial Catalog=aaa");
                SqlCommand selectCMD = new SqlCommand("SELECT DeptID,DeptName,Description,ManagerID FROM dbo.tblDepartment", Myconn);
                selectCMD.CommandTimeout = 30;
                SqlDataAdapter deptDA = new SqlDataAdapter();
                deptDA.SelectCommand = selectCMD;
                SqlCommandBuilder InsertCommand = new SqlCommandBuilder(deptDA);
                Myconn.Open();

                DataSet deptDS = new DataSet();
                deptDA.Fill(deptDS, "dbo.tblDepartment");
                Myconn.Close();

                int k;
                int x = 0;

                for (k = 0; k < deptDS.Tables["dbo.tblDepartment"].Rows.Count; k++)
                {
                    if (Compare_string(textBox1.Text, deptDS.Tables["dbo.tblDepartment"].Rows[k]["DeptName"].ToString()))
                    {
                        this.textBox1.Text = null;
                        x = 0;
                        MessageBox.Show("该部门已存在\n请重新输入部门名称");
                        break;
                    }
                    else x = 1;
                }

                if (x == 1)
                {
                    /*****************************************/
                    //send information to DepartmentManage 
                    //through the core
                    string info = this.textBox1.Text;
                    MainForm.core.SetText(info);
                    MainForm.core.SendText();

                    string info2 = this.textBox2.Text;
                    MainForm.core.SetText(info2);
                    MainForm.core.SendText();

                    string info3 = this.textBox3.Text;
                    MainForm.core.SetText(info3);
                    MainForm.core.SendText();
                    /*****************************************/
                    this.textBox1.Text = null;
                    this.textBox2.Text = null;
                    this.textBox3.Text = null;
                    this.Hide();
                }
            }
            else
            {
                MessageBox.Show("     Request Department's Name\n or Request Department's description\n or Request Department's Manager");
            }
        }

        private void Browse_Click(object sender, EventArgs e)
        {
            string name = Browse.Name;
            MainForm.core.OpenForm(name);
        }

        public void SetManager(string a)
        {
            textBox3.Text = a;
        }
    }
}

⌨️ 快捷键说明

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