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

📄 formworkinfo.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 FormWorkInfo : Form
    {
        public FormWorkInfo()
        {
            InitializeComponent();
            workinfoform = this;

        }
        //初始化
        private void FormWorkInfo_Load(object sender, EventArgs e)
        {
            DBDataGrid();
            
        }
        //数据处理
        public void DBDataGrid()
        {
            string SqlText = "select WorkInfo.wwId,WorkInfo.wId as 员工编号,EmployInfo.eName as 员工姓名,WorkInfo.wName as 工作单位,WorkInfo.wJob as 工作职务,";
            SqlText += "WorkInfo.wFdate as 开始工作时间,WorkInfo.wLdate as 结束工作时间,WorkInfo.wRemarks as 备注 from WorkInfo,EmployInfo ";
            SqlText += "where WorkInfo.wId=EmployInfo.wId order by WorkInfo.wId 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 InsertWork(object sender, System.EventArgs e)
        {
            HRMan.HROper.FormWorkInfo.wID = "insert";  
            if (FormMain.FM.CheckForm("FormAddWork") == true)  
            {
                return;
            }
            else
            {
                HRMan.HROper.FormAddWork addwork = new HRMan.HROper.FormAddWork();  
                addwork.MdiParent = FormMain.FM;
                addwork.Show();
                addwork.Text = "添加工作关系";
            }
        }

        //修改
        private void UpdateWork(object sender, System.EventArgs e)
        {
            FormWorkInfo.wID = "update";
            this.sb.Remove(0, this.sb.ToString().Length);
            for (int i = 0; i < this.dt.Columns.Count; i++)
            {
                this.sb.Append(this.dataGrid1[i,this.dataGrid1.CurrentCellAddress.Y].Value.ToString() + "#");
            }
            if (FormMain.FM.CheckForm("FormAddWork") == true) 
            {
                return;
            }
            else
            {
                HRMan.HROper.FormAddWork addwork = new HRMan.HROper.FormAddWork();  
                addwork.MdiParent = FormMain.FM;
                addwork.Show();
                addwork.Text = "修改工作关系";
            }
        }       

        //删除
        private void DeleteWork(object sender, System.EventArgs e)
        {
            DialogResult result = MessageBox.Show("是否删除此记录?", "提示!", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
            if (result == DialogResult.Yes)
            {
                string SqlText = "delete from WorkInfo where wwID=" + 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 ExitWork(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, 152);
            this.dataGrid1.Height = 230;
        }
        //取消查询
        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 WorkInfo.wwId,WorkInfo.wId as 员工编号,EmployInfo.eName as 员工姓名,WorkInfo.wName as 工作单位,WorkInfo.wJob as 工作职务,";
            SqlText += "WorkInfo.wFdate as 开始工作时间,WorkInfo.wLdate as 结束工作时间,WorkInfo.wRemarks as 备注 from WorkInfo,EmployInfo ";
            SqlText += "where WorkInfo.wId=EmployInfo.wId";

            if (this.ID_txt.Text.Trim() != "")
            {
                SqlText += " and WorkInfo.wId=" + 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.textBox1.Text != "")
            {
                SqlText += " and WorkInfo.wName like '%[" + this.textBox1.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.Job_txt.Text != "")
            {
                SqlText += " and WorkInfo.wJob like '%[" + this.Job_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;
                    }
                }
            }

            
        }

        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.InsertWork(sender, e);
        }

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

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

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

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

       
       
    }
}

⌨️ 快捷键说明

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