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

📄 formqueryemployee.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 HumanResourceManagement
{
    public partial class FormQueryEmployee : Form
    {
        SqlConnection cnn;
        DataSet dsCustomers;
        SqlDataAdapter daCustomers;
        public FormQueryEmployee()
        {
            InitializeComponent();
        }

        private const int CP_NOCLOSE_BUTTON = 0x200;
        protected override CreateParams CreateParams
        {
            get
            {
                CreateParams myCp = base.CreateParams;
                myCp.ClassStyle = myCp.ClassStyle | CP_NOCLOSE_BUTTON;
                return myCp;
            }
        } 

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.Close();
            FormListEmployee FE = new FormListEmployee();
            FE.Show();
        }

        private void FormQueryEmployee_Load(object sender, EventArgs e)
        {
            SqlConnection con = DB.connection();
            con.Open();
            cnn = new SqlConnection("data source=.;initial catalog=BlueHill_HRM;integrated security=true;");
            cnn.Open();
            SqlCommand cmd = new SqlCommand("select * from tblDepartment", cnn);
            SqlDataReader bm = cmd.ExecuteReader();
            while (bm.Read())
            {
                cbDepartment.Items.Add(bm["DeptName"].ToString());

            }
            cnn.Close();
        }

        private void btnQuery_Click(object sender, EventArgs e)
        {
            SqlConnection con = DB.connection();
            con.Open();
            if (txtName.Text.Trim() == "")
            {
                if (txtEmail.Text.Trim() == "")
                {
                    if (cbDepartment.Text.Trim() == "")
                    {
                        DialogResult = MessageBox.Show("三个条件,你总得填一个哇,不然我朗个给你查按!", "提示");
                    }
                    else
                    {
                        SqlCommand cmdc = new SqlCommand("select * from tblEmployee  where DeptID=(select DeptID from tblDepartment where DeptName='" + cbDepartment.Text.Trim() + "')", con);
                        SqlDataReader sdr = cmdc.ExecuteReader();
                        //DB.setA = sdr;
                    }
                }
                else
                {
                }
            }
            else
            {
                cnn = new SqlConnection("Data Source=.;Initial Catalog=BlueHill_HRM;integrated security=true;");
                dsCustomers = new DataSet();
                daCustomers = new SqlDataAdapter();
                SqlCommand cmSelect = new SqlCommand();
                cmSelect.Connection = cnn;
                cmSelect.CommandText = "select * from tblEmployee where Name= '" + txtName.Text.Trim() + "' or  Email='" + txtEmail.Text.Trim() + "' or DeptID='" + DptID.Text.ToString().Trim() + "'";
                daCustomers.SelectCommand = cmSelect;
                daCustomers.Fill(dsCustomers, "Customers");
                grdEmployee.DataSource = dsCustomers.Tables["Customers"];
            }
            con.Close();
        }

        private void cbDepartment_SelectedIndexChanged(object sender, EventArgs e)
        {
            cnn = new SqlConnection("data source=.;initial catalog=BlueHill_HRM;integrated security=true;");
            cnn.Open();
            SqlCommand cmd = new SqlCommand("select DeptID from tblDepartment where  DeptName =('" + cbDepartment.Text + "')", cnn);
            SqlDataReader bm = cmd.ExecuteReader();
            while (bm.Read())
            {
                DptID.Text = (bm["DeptID"].ToString());

            }
            cnn.Close();
        }
    }
}

⌨️ 快捷键说明

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