在好例子网,分享、交流、成长!
您当前所在位置:首页C# 开发实例C#语言基础 → C# winfrom 公司员工信息管理系统

C# winfrom 公司员工信息管理系统

C#语言基础

下载此实例
  • 开发语言:C#
  • 实例大小:0.43M
  • 下载次数:283
  • 浏览次数:4597
  • 发布时间:2016-03-21
  • 实例类别:C#语言基础
  • 发 布 人:彬彬风华
  • 文件格式:.zip
  • 所需积分:4

实例介绍

【实例简介】VS2010 C#   SQLServer 开发的 简单的公司员工信息管理系统

【实例截图】

【核心代码】

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.IO;
//using 连接数据库;



namespace 连接数据库
{
    public partial class workerInfo : Form
    {
        public workerInfo()
        {
            InitializeComponent();
        }

        public static string workername=null;
        public static string workerID = null;
        public static string picfilename = null;

        private void btn_quanbiao_Click(object sender, EventArgs e)
        {
            WorkerList fr = new WorkerList();
            fr.Show();
        }

        #region 单击查询按钮
        private void btn_search_Click(object sender, EventArgs e)
        {
            string inputtxt = comboBox_input.Text;
            if (inputtxt == "请选择")
            {
                MessageBox.Show("请选择一个查询条件", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            else
            {
                int item = 0;
                if (inputtxt == "姓名") item = 1;
                if (inputtxt == "新编号") item = 2;
                if (inputtxt == "原编号") item = 3;

                switch (item)
                {
                    case 1:
                        inputtxt = "name";
                        break;
                    case 2:
                        inputtxt = "new_id";
                        break;
                    case 3:
                        inputtxt = "old_id";
                        break;
                }
                string inputval = cbb_input.Text;
                showMessage(inputtxt, inputval);
            }
        } 
        #endregion

        #region 读取单条记录
        public string ShowSign(string xiangmu, string txt, string val)
        {
            string sign = ""; //获取的记录
            SqlConnection mycon = DBLink.linkDB();
            try
            {
                mycon.Open();
            }
            catch (System.Exception ex)
            {
                MessageBox.Show("数据库连接失败" ex.Message, "提示");
                this.Close();
            }
            string sql = "select " xiangmu " from workerinfo where " txt " = '" val "'";
            try
            {
                // 查询
                SqlCommand command = new SqlCommand(sql, mycon);
                SqlDataReader dataReader = command.ExecuteReader();
                if (dataReader.Read())
                {
                    sign = Convert.ToString(dataReader[0]);
                }
                dataReader.Close();
            }
            catch (System.Exception ex)
            {
                MessageBox.Show("读取数据时出错/n" ex.Message, "提示");
                //this.Close();
                
            }
            return sign;
        } 
        #endregion

        #region 显示员工信息
        public void showMessage(string input, string inputvalue)
        {
            string inputtxt = input;
            string inputval = inputvalue;
            lab_age.Text = ShowSign("age", inputtxt, inputval);
            lab_college.Text = ShowSign("college", inputtxt, inputval);
            lab_infoname.Text = ShowSign("name", inputtxt, inputval);
            lab_jiguan.Text = ShowSign("jiguan", inputtxt, inputval);
            lab_nowID.Text = ShowSign("new_id", inputtxt, inputval);
            lab_oldID.Text = ShowSign("old_id", inputtxt, inputval);
            lab_job.Text = ShowSign("job", inputtxt, inputval);
            lab_sex.Text = ShowSign("sex", inputtxt, inputval);
            lab_job.Text = ShowSign("job", inputtxt, inputval);
            lab_people.Text = ShowSign("pep", inputtxt, inputval);
            textBox2.Text = ShowSign("licenseID", inputtxt, inputval);
            //获取标识符
            workerID = lab_nowID.Text;
            workername = lab_infoname.Text;
            //接下来显示从数据库中获取 的图片。。。。
            //////////////////////////////////////////////////////////////////////////
            byte[] mypic = GetArrayFromDB();
            if (mypic == null)
            {
                ruku.Enabled = false;
                pictureBox1.Image = null;
                return;
            }
            else
            {
                pictureBox1.SizeMode = PictureBoxSizeMode.Zoom;
                pictureBox1.Image = GetImagenFromArray(mypic);
                ruku.Enabled = false;
            }
        } 
        #endregion

        #region 从数据库中读取图片
        private byte[] GetArrayFromDB()
        {
            
            byte[] matriz = null;
           // string strcon = "Server=" strServerName ";Database=" strDatabase ";User id=" strUser ";Password=" strPsw;
            SqlConnection mycon = DBLink.linkDB();
            try
            {
                mycon.Open();
                SqlCommand cmd = new SqlCommand();
                cmd.Connection = mycon;
                cmd.CommandText = "select pic from workerinfo where name='" workername "'";
                string cmdresult = Convert.ToString(cmd.ExecuteScalar());
                if (cmdresult == "")
                {
                    return null;
                }
                else
                {
                    cmd.Parameters.Clear();
                    //cmd.Parameters.AddWithValue("Descripcion", NombreDeArchivo).SqlDbType = SqlDbType.VarChar;
                    matriz = (byte[])cmd.ExecuteScalar();
                }
            }
            catch
            {
                MessageBox.Show("数据库使用出错");
            }
            finally
            {
                mycon.Close();
                mycon.Dispose();
            }
            return matriz;
        }
        private Image GetImagenFromArray(byte[] matriz)
        {
            MemoryStream memoryStream = new MemoryStream();
            memoryStream.Write(matriz, 0, matriz.Length);
            Image imagen = Image.FromStream(memoryStream);
            return imagen;
        } 
        #endregion

        #region 载入图片、图片入库
        private void 载入照片_Click(object sender, EventArgs e)
        {
            //Stream myStream = null;
            //string fliename = null;
            //string filepath = null;
            string ImgPath = null;
            OpenFileDialog openFileDialog1 = new OpenFileDialog();
            openFileDialog1.InitialDirectory = "F:\\图片\\图片\\美女2";
            openFileDialog1.Filter = "jpge图像文件 (*.jpeg)|*.jpeg|JPG图像文件 (*.jpg)|*.jpg|BMP图像文件 (*.bmp)|(*.bmp)|All files (*.*)|*.*";
            openFileDialog1.FilterIndex = 2;
            openFileDialog1.Title = "打开图片";
            openFileDialog1.RestoreDirectory = true;

            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                try
                {
                    ImgPath = openFileDialog1.FileName;
                    picfilename = ImgPath;
                    Image img = Image.FromFile(ImgPath);//双引号里是图片的路径
                    pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage;
                    pictureBox1.Image = img;
                    // fliename = Path.GetFileName(openFileDialog1.FileName);
                    // filepath = Path.GetDirectoryName(openFileDialog1.FileName);
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Error: Could not read file from disk. Original error: " ex.Message);
                }
            }

            if (pictureBox1.Image != null)
            {
                ruku.Enabled = true;
            }
        }       
        private void ruku_Click(object sender, EventArgs e)
        {
            if (GetArrayFromDB()!=null)
            {   
                MessageBox.Show("该记录图片已存在,是否替换", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning);
            
            }
            Image myimage = pictureBox1.Image;
            byte[] imgbte = pictureIn.GetArrayFromImagen(myimage);
            pictureIn.GuardarImagen(imgbte);
            if (GetArrayFromDB()==null)
            {
                MessageBox.Show("图片没有入库成功", "提示");
            }
            else
            {
                MessageBox.Show("图片入库成功", "提示");
            }
        }
        #endregion

        #region 自动加载右键选项
        /// <summary>
        /// 加载右键选项
        /// </summary>
        public void loadItem()
        {
            SqlConnection newcon = DBLink.linkDB();
            string selitem = comboBox_input.Text;
            int item = 0;
            if (selitem == "姓名") item = 1;
            if (selitem == "新编号") item = 2;
            if (selitem == "原编号") item = 3;
            switch (item)
            {
                case 1:
                    selitem = "name";
                    break;
                case 2:
                    selitem = "new_id";
                    break;
                case 3:
                    selitem = "old_id";
                    break;
            }
            string selvalue = cbb_input.Text;
            string sql = string.Format("select {0} from workerinfo where {1} like '%{2}%' order by {3} ", selitem, selitem, selvalue, selitem);
            try
            {
                newcon.Open();
                SqlCommand cmd = new SqlCommand();
                cmd.CommandText = sql;
                cmd.Connection = newcon;
                SqlDataReader reader = cmd.ExecuteReader();
                // cbb_input.Items.Clear();
                while (reader.Read())
                {
                    cbb_input.Items.Add(reader[0]);
                }

                reader.Dispose();
                reader.Close();
                newcon.Dispose();
                newcon.Close();

            }
            catch
            {
                newcon.Close();
                MessageBox.Show("出错");
            }

        }
        /// <summary>
        /// 下拉响应事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void cbb_input_DropDown(object sender, EventArgs e)
        {
            comboBox_input.Items.Clear();
            loadItem();
        }
        #endregion

        #region 得到上个/下个员工的ID
        /// <summary>
        /// 获取后几位数  public string GetLastStr(string str,int num)
        /// </summary>
        /// <param name="str">要截取的字符串</param>
        /// <param name="num">返回的具体位数</param>
        /// <returns>返回结果的字符串</returns>
        public string GetLastStr(string str, int num)
        {
            int count = 0;
            if (str.Length > num)
            {
                count = str.Length - num;
                str = str.Substring(count, num);
            }
            return str;
        }

        public string nextID(string str)
        {
            string nextid = null;
            nextid = GetLastStr(str, 3);
            int tempID = Convert.ToInt16(nextid) 1;
            return "A" tempID.ToString().PadLeft(3, '0');
        }
        public string beforeID(string str)
        {
            string nextid = null;
            nextid = GetLastStr(str, 3);
            int tempID = Convert.ToInt16(nextid) - 1;
            return "A" tempID.ToString().PadLeft(3, '0');
        }
        #endregion

        #region 单击显示 上一个/下一个 员工信息
        private void btn_before_Click(object sender, EventArgs e)
        {
            string id = null;
            if (workerID == null)
            {
                MessageBox.Show("当前没有显示的员工,请先进行查询操作","提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
                return;
            }
            else
            {
                id = beforeID(workerID);
                if (id == "A000")
                {
                    MessageBox.Show("已经是第一个了");
                    return;
                }
                else
                {
                    showMessage("new_id", id);
                }
            }
        }

        private void btn_next_Click(object sender, EventArgs e)
        {
            string id = null;
            if (workerID == null)
            {
                MessageBox.Show("当前没有显示的员工,请先进行查询操作", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            else
            {
                id = nextID(workerID);

                if (id == "A026")
                {
                    MessageBox.Show("已经是最后一个了!!");
                    return;
                }
                else
                {
                    showMessage("new_id", id);
                }
            }
        } 
        #endregion

        private void comboBox_input_DropDown(object sender, EventArgs e)
        {
            //GridItem item = new GridItem();
            comboBox_input.Items.Clear();
            comboBox_input.Items.Add("姓名");
            comboBox_input.Items.Add("新编号");
            comboBox_input.Items.Add("原编号");
        }

    }
}


实例下载地址

网友评论

第 1 楼 zxd007 发表于: 2018-09-15 08:59 38
不能用 的

支持(0) 盖楼(回复)

第 2 楼 liuzhixiao666 发表于: 2020-12-07 18:21 21
没有数据库文件

支持(0) 盖楼(回复)

第 3 楼 liuzhixiao666 发表于: 2020-12-07 18:21 22
没有数据库文件

支持(0) 盖楼(回复)

第 4 楼 liuzhixiao666 发表于: 2020-12-07 18:21 22
没有数据库文件

支持(0) 盖楼(回复)

发表评论

(您的评论需要经过审核才能显示)

查看所有4条评论>>

小贴士

感谢您为本站写下的评论,您的评论对其它用户来说具有重要的参考价值,所以请认真填写。

  • 类似“顶”、“沙发”之类没有营养的文字,对勤劳贡献的楼主来说是令人沮丧的反馈信息。
  • 相信您也不想看到一排文字/表情墙,所以请不要反馈意义不大的重复字符,也请尽量不要纯表情的回复。
  • 提问之前请再仔细看一遍楼主的说明,或许是您遗漏了。
  • 请勿到处挖坑绊人、招贴广告。既占空间让人厌烦,又没人会搭理,于人于己都无利。

关于好例子网

本站旨在为广大IT学习爱好者提供一个非营利性互相学习交流分享平台。本站所有资源都可以被免费获取学习研究。本站资源来自网友分享,对搜索内容的合法性不具有预见性、识别性、控制性,仅供学习研究,请务必在下载后24小时内给予删除,不得用于其他任何用途,否则后果自负。基于互联网的特殊性,平台无法对用户传输的作品、信息、内容的权属或合法性、安全性、合规性、真实性、科学性、完整权、有效性等进行实质审查;无论平台是否已进行审查,用户均应自行承担因其传输的作品、信息、内容而可能或已经产生的侵权或权属纠纷等法律责任。本站所有资源不代表本站的观点或立场,基于网友分享,根据中国法律《信息网络传播权保护条例》第二十二与二十三条之规定,若资源存在侵权或相关问题请联系本站客服人员,点此联系我们。关于更多版权及免责申明参见 版权及免责申明

;
报警