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

📄 formtitle.cs

📁 数据库开发与实例(1+1混合数据库开发实例丛书)人事管理系统的源代码
💻 CS
字号:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace HRMan.HROper
{
    public partial class FormTitle : Form
    {
        public FormTitle()
        {
            InitializeComponent();
            titleform = this;
        }
        //初始化
        private void FormTitle_Load(object sender, EventArgs e)
        {
            DBDataGrid();
			TitleInit();
			
        }
        private void TitleInit()
        {
            string SqlText = "select * from Title";
            DataAccess DA = new DataAccess();  
            DataTable dt = DA.ExeSQLdt(SqlText);
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                this.comboBox1.Items.Add(dt.Rows[i]["tName"].ToString());
            }
        }

       //DataGrid数据绑定
        public void DBDataGrid()
        {
            string SqlText = "select TitleInfo.ttId,TitleInfo.tiId as 员工编号,EmployInfo.eName as 员工姓名,TitleInfo.tTitle as 评定的职称,TitleInfo.tType as 取得方式,";
            SqlText += "TitleInfo.tEmpdate as 取得时间,TitleInfo.tEmpTime as 截止时间,TitleInfo.tSection as 聘用单位,TitleInfo.tJob as 聘用职务,TitleInfo.tRemarks as [备注] ";
            SqlText += "from TitleInfo,EmployInfo where TitleInfo.tiId=EmployInfo.tiId order by TitleInfo.tiId asc";
            DataAccess DA = new DataAccess(); 
            this.dt = DA.ExeSQLdt(SqlText); 
            this.dataGrid1.DataSource = this.dt.DefaultView;
            this.cm = (CurrencyManager)BindingContext[this.dt];
            if (this.dataGrid1.Rows.Count != 0)
            {
                for (int i = 0; i < this.dataGrid1.Rows.Count; )
                {
                    this.dataGrid1.Rows[i].DefaultCellStyle.BackColor = System.Drawing.Color.Pink;
                    i += 2;
                }
            }
        }
       
        //处理工具栏事件
        //添加记录
        private void InsertTitle(object sender, System.EventArgs e)
        {
            HRMan.HROper.FormTitle.titleID ="insert";
            if (HRMan.FormMain.FM.CheckForm("FormAddTitle") == true)
            {
                return;
            }
            else
            {
                HRMan.HROper.FormAddTitle addtitle = new FormAddTitle();   
                addtitle.MdiParent = HRMan.FormMain.FM; 
                addtitle.Show();
                addtitle.Text = "添加职称";
            }
        }

        //修改记录
        private void UpdateTitle(object sender, System.EventArgs e)
        {
            HRMan.HROper.FormTitle.titleID = "update";
            this.sb.Remove(0, this.sb.ToString().Length);
            for (int i = 0; i < dt.Columns.Count; i++)
            {
                sb.Append(this.dataGrid1[i,this.dataGrid1.CurrentCellAddress.Y].Value.ToString() + "#");
            }
            if (HRMan.FormMain.FM.CheckForm("TitleRecord") == true)
            {
                return;
            }
            else
            {
                HRMan.HROper.FormAddTitle addtitle = new FormAddTitle(); 
                addtitle.MdiParent = HRMan.FormMain.FM;  
                addtitle.Show();
                addtitle.Text = "修改职称";
            }

        }

        //删除记录
        private void DeleteTitle(object sender, System.EventArgs e)
        {
            DialogResult result = MessageBox.Show("是否删除此记录?", "提示!", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
            if (result == DialogResult.Yes)
            {
                string SqlText = "delete TitleInfo where ttID=" + int.Parse(this.dataGrid1[0,this.dataGrid1.CurrentCellAddress.Y].Value.ToString());
                DataAccess DA = new DataAccess();  
                DA.ExeSQL(SqlText);
                this.DBDataGrid();
                MessageBox.Show("删除成功!");
            }
            if (result == DialogResult.No)
            {
                return;
            }

        }

        //退出
        private void ExitTitle(object sender, System.EventArgs e)
        {
            this.Close();
        }
        //查询
        private void Search(object sender, System.EventArgs e)
        {
            this.groupBox1.Visible = true;
            this.dataGrid1.Dock = DockStyle.None;
            this.dataGrid1.Location = new Point(0, 128);
            this.dataGrid1.Height = 320;
        }
        //刷新
        private void FormTitle_EnabledChanged(object sender, EventArgs e)
        {
            this.DBDataGrid();
        }
        //取消执行查询
        private void button2_Click(object sender, EventArgs e)
        {
            this.groupBox1.Visible = false;
            this.dataGrid1.Dock = DockStyle.Fill;
            this.DBDataGrid();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            string SqlText = "select TitleInfo.ttId,TitleInfo.tiId as 员工编号,EmployInfo.eName as 员工姓名,TitleInfo.tTitle as 评定的职称,TitleInfo.tType as 取得方式,";
            SqlText += "TitleInfo.tEmpdate as 取得时间,TitleInfo.tEmpTime as 截止时间,TitleInfo.tSection as 聘用单位,TitleInfo.tJob as 聘用职务,TitleInfo.tRemarks as [备注] ";
            SqlText += "from TitleInfo,EmployInfo where TitleInfo.tiId=EmployInfo.tiId";

            if (this.ID_txt.Text.Trim() != "")
            {
                SqlText += " and TitleInfo.tiId=" + int.Parse(this.ID_txt.Text.Trim());
                DataAccess DA = new DataAccess(); 
                this.dt = DA.ExeSQLdt(SqlText);
                this.dataGrid1.DataSource = this.dt.DefaultView;
                this.cm = (CurrencyManager)BindingContext[this.dt];
                if (this.dataGrid1.Rows.Count != 0)
                {
                    for (int i = 0; i < this.dataGrid1.Rows.Count; )
                    {
                        this.dataGrid1.Rows[i].DefaultCellStyle.BackColor = System.Drawing.Color.Pink;
                        i += 2;
                    }
                }
            }

            if (this.name_txt.Text.Trim() != "")
            {
                SqlText += " and EmployInfo.eName like '%[" + this.name_txt.Text + "]%'";
                DataAccess DA = new DataAccess(); 
                this.dt = DA.ExeSQLdt(SqlText);
                this.dataGrid1.DataSource = this.dt.DefaultView;
                this.cm = (CurrencyManager)BindingContext[this.dt];
                if (this.dataGrid1.Rows.Count != 0)
                {
                    for (int i = 0; i < this.dataGrid1.Rows.Count; )
                    {
                        this.dataGrid1.Rows[i].DefaultCellStyle.BackColor = System.Drawing.Color.Pink;
                        i += 2;
                    }
                }
            }

            if (this.comboBox1.Text != "")
            {
                SqlText += " and TitleInfo.tTitle like '%[" + this.comboBox1.SelectedItem.ToString() + "]%'";
                DataAccess DA = new DataAccess(); 
                this.dt = DA.ExeSQLdt(SqlText);
                this.dataGrid1.DataSource = this.dt.DefaultView;
                this.cm = (CurrencyManager)BindingContext[this.dt];
                if (this.dataGrid1.Rows.Count != 0)
                {
                    for (int i = 0; i < this.dataGrid1.Rows.Count; )
                    {
                        this.dataGrid1.Rows[i].DefaultCellStyle.BackColor = System.Drawing.Color.Pink;
                        i += 2;
                    }
                }
            }

            if (this.comboBox2.Text != "")
            {
                SqlText += " and TitleInfo.tType='" + this.comboBox2.SelectedItem.ToString() + "'";
                DataAccess DA = new DataAccess(); 
                this.dt = DA.ExeSQLdt(SqlText);
                this.dataGrid1.DataSource = this.dt.DefaultView;
                this.cm = (CurrencyManager)BindingContext[this.dt];
                if (this.dataGrid1.Rows.Count != 0)
                {
                    for (int i = 0; i < this.dataGrid1.Rows.Count; )
                    {
                        this.dataGrid1.Rows[i].DefaultCellStyle.BackColor = System.Drawing.Color.Pink;
                        i += 2;
                    }
                }
            }
           
        }

        private void toolStripButton1_Click(object sender, EventArgs e)
        {
            if (this.Position != 0)
            {
                foreach (DataGridViewRow dvrow in this.dataGrid1.Rows)
                {
                    dvrow.Selected = false;
                }
                this.dataGrid1.Rows[0].Selected = true;
                this.Position = 0;
            }
        }

        private void toolStripButton2_Click(object sender, EventArgs e)
        {
            if (this.Position > 0)
            {
                foreach (DataGridViewRow dvrow in this.dataGrid1.Rows)
                {
                    dvrow.Selected = false;
                }
                this.Position--;
                this.dataGrid1.Rows[this.Position].Selected = true;


            }
        }

        private void toolStripButton3_Click(object sender, EventArgs e)
        {
            if (this.Position < this.dataGrid1.Rows.Count - 1)
            {
                foreach (DataGridViewRow dvrow in this.dataGrid1.Rows)
                {
                    dvrow.Selected = false;
                }
                this.Position++;
                this.dataGrid1.Rows[this.Position].Selected = true;

            }
        }

        private void toolStripButton4_Click(object sender, EventArgs e)
        {
            if (this.Position != this.dataGrid1.Rows.Count - 1)
            {
                foreach (DataGridViewRow dvrow in this.dataGrid1.Rows)
                {
                    dvrow.Selected = false;
                }
                this.Position = this.dataGrid1.Rows.Count;
                this.dataGrid1.Rows[this.Position - 1].Selected = true;
            }
        }

        private void toolStripButton5_Click(object sender, EventArgs e)
        {
            this.InsertTitle(sender, e);
        }

        private void toolStripButton6_Click(object sender, EventArgs e)
        {
            this.UpdateTitle(sender, e);
        }

        private void toolStripButton7_Click(object sender, EventArgs e)
        {
            this.DeleteTitle(sender, e);
        }

        private void toolStripButton8_Click(object sender, EventArgs e)
        {
            this.Search(sender, e);
        }

        private void toolStripButton9_Click(object sender, EventArgs e)
        {
            this.ExitTitle(sender, e);
        }
    }
}

⌨️ 快捷键说明

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