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

📄 formsociinfo.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 FormSociInfo : Form
    {
        //构造函数
        public FormSociInfo()
        {
            InitializeComponent();
            socialform = this;
        }
        //初始化
        private void FormSociInfo_Load(object sender, EventArgs e)
        {
            DBDataGrid();

        }
        //数据显示处理
        public void DBDataGrid()
        {
            string SqlText = "select SocietyInfo.sssId,SocietyInfo.seId as 员工编号,EmployInfo.eName as 员工姓名,SocietyInfo.sName as 姓名,SocietyInfo.sLaction as 关系,";
            SqlText += "SocietyInfo.sUinte as 工作单位和职务,SocietyInfo.sRemarks as 备注 from SocietyInfo,EmployInfo where SocietyInfo.seId=EmployInfo.seId order by SocietyInfo.seId 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 InsertSocial(object sender, System.EventArgs e)
        {
            FormSociInfo.sID = "insert";
            if (HRMan.FormMain.FM.CheckForm("FormSocialInfo") == true)
            {
                return;
            }
            else
            {
                FormAddSocia addsocia = new FormAddSocia();
                addsocia.MdiParent = FormMain.FM;
                addsocia.Show();
                addsocia.Text = "添加员工关系";
            }
        }

        //修改
        private void UpdateSocial(object sender, System.EventArgs e)
        {
            FormSociInfo.sID = "update";
            this.sb.Remove(0, this.sb.ToString().Length);
            for (int i = 0; i < this.dt.Columns.Count; i++)
            {
                sb.Append(this.dataGrid1[i, this.dataGrid1.CurrentCellAddress.Y].Value.ToString() + "#");
            }
            if (FormMain.FM.CheckForm("FormAddSocia") == true)
            {
                return;
            }
            else
            {
                FormAddSocia addsocia = new FormAddSocia();
                addsocia.MdiParent = FormMain.FM;
                addsocia.Show();
                addsocia.Text = "修改员工社会关系";
            }
        }

        //删除
        private void DeleteSocial(object sender, System.EventArgs e)
        {
            DialogResult result = MessageBox.Show("是否删除此记录?", "提示!", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
            if (result == DialogResult.Yes)
            {

                string SqlText = "delete from SocietyInfo where sssID=" + 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 Search(object sender, System.EventArgs e)
        {
            this.groupBox1.Visible = true;
            this.dataGrid1.Dock = DockStyle.None;
            this.dataGrid1.Location = new Point(0, 96);
            this.dataGrid1.Height = 352;
        }

        //退出
        private void ExitSocial(object sender, System.EventArgs e)
        {
            this.Close();
        }
        //处理查询
        private void button1_Click(object sender, EventArgs e)
        {
            string SqlText = "select SocietyInfo.sssId,SocietyInfo.seId as 员工编号,EmployInfo.eName as 员工姓名,SocietyInfo.sName as 姓名,SocietyInfo.sLaction as 关系,";
            SqlText += "SocietyInfo.sUinte as 工作单位和职务,SocietyInfo.sRemarks as 备注 from SocietyInfo,EmployInfo where SocietyInfo.seId=EmployInfo.seId";

            if (this.ID_txt.Text.Trim() != "")
            {
                SqlText += " and SocietyInfo.seId=" + 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 SocietyInfo.sName='" + this.name_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.comboBox1.Text != "")
            {
                SqlText += " and SocietyInfo.sLaction='" + 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;
                    }
                }
            }
        }
        //取消查询
        private void button2_Click(object sender, EventArgs e)
        {
            this.groupBox1.Visible = false;
            this.dataGrid1.Dock = DockStyle.Fill;
            this.DBDataGrid();
        }

        private void FormSociInfo_EnabledChanged(object sender, EventArgs e)
        {
            this.DBDataGrid();
        }

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

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

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

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

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

⌨️ 快捷键说明

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