infshow.cs
上传用户:zhongfine
上传日期:2022-08-01
资源大小:2860k
文件大小:4k
源码类别:

企业管理

开发平台:

C#

  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9. using System.Data.SqlClient;
  10. using System.IO;
  11. namespace 人事管理系统
  12. {
  13.     public partial class infshow : Form
  14.     {
  15.         SqlCommand cmd = new SqlCommand();
  16.         Datacon mydatacon = new Datacon();
  17.         SqlConnection sqlcn = new SqlConnection();
  18.         OpenFileDialog mydlg = new OpenFileDialog();
  19.         public infshow()
  20.         {
  21.             InitializeComponent();
  22.         }
  23.         private void label11_Click(object sender, EventArgs e)
  24.         {
  25.         }
  26.         private void infshow_Load(object sender, EventArgs e)
  27.         {
  28.         }
  29.         int i =1;
  30.         private void button1_Click(object sender, EventArgs e)
  31.         {
  32.             if (label13.Text == label19.Text||label24.Text=="管理员")
  33.             {
  34.                 sqlcn = mydatacon.getcon();
  35.                 sqlcn.Open();
  36.                 cmd.CommandText = "update PERSON set BIRTHDAY='" + dateTimePicker1.Text + "',ADDRESS='" + textBox1.Text + "',TEL='" + textBox2.Text + "',REMARK='" + textBox3.Text + "' where ID='" + label13.Text + "'";
  37.                 cmd.Connection = sqlcn;
  38.                 cmd.ExecuteNonQuery();
  39.                 Stream ms;
  40.                 byte[] picbyte;
  41.                 if (pictureBox1.Image != null)
  42.                 {
  43.                     //cmd.CommandText = "update PERSON set PHOTO=null where ID='"+label13.Text+"'";
  44.                     //cmd.ExecuteNonQuery();
  45.                     if (i != 1)
  46.                     {
  47.                         if ((ms = mydlg.OpenFile()) != null)
  48.                         {
  49.                             picbyte = new byte[ms.Length];
  50.                             ms.Position = 0;
  51.                             ms.Read(picbyte, 0, Convert.ToInt32(ms.Length));
  52.                           
  53.                             SqlCommand csd = new SqlCommand("update PERSON set PHOTO=@zhaopian where ID='" + label13.Text + "'", sqlcn);
  54.                             csd.Parameters.Add("@zhaopian", SqlDbType.Image);
  55.                             csd.Parameters["@zhaopian"].Value = picbyte;
  56.                             csd.ExecuteNonQuery();
  57.                             ms.Close();
  58.                         }
  59.                     }
  60.                 }
  61.                 MessageBox.Show("当前修改保存成功!");
  62.                 sqlcn.Close();
  63.             }
  64.             else
  65.             {
  66.                 MessageBox.Show("您不是当前页面员工或管理员,无法修改信息!");
  67.                 return;
  68.             }
  69.         }
  70.         private void button2_Click(object sender, EventArgs e)
  71.         {
  72.             this.Close();
  73.         }
  74.         private void button3_Click(object sender, EventArgs e)
  75.         {
  76.             mydlg.Title = "选择照片";
  77.             mydlg.Filter = "JPEG图像文件(*JPG)|*jpg|所有图像文件(*GIF,*BMP,*JPEG,etc)|*gif;*bmp;*jpeg;*jpeg;*tif;*tiff;*png|所有文件(*.*)|*.*";
  78.             if (mydlg.ShowDialog() == DialogResult.OK)
  79.             {
  80.                 Image image = Image.FromFile(mydlg.FileName);
  81.                 pictureBox1.Image = image;
  82.                 i = 0;
  83.                 return;
  84.             }
  85.             i = 1;
  86.         }
  87.         private void button4_Click(object sender, EventArgs e)
  88.         {
  89.             if (label13.Text == label19.Text || label24.Text == "管理员")
  90.             {
  91.                 pictureBox1.Image = null;
  92.                 sqlcn = mydatacon.getcon();
  93.                 sqlcn.Open();
  94.                 cmd.Connection = sqlcn;
  95.                 cmd.CommandText = "update PERSON set PHOTO=null where ID='" + label13.Text + "'";
  96.                 cmd.ExecuteNonQuery();
  97.             }
  98.             else
  99.             {
  100.                 MessageBox.Show("您不是当前页面员工或管理员,无法修改信息!");
  101.                 return;
  102.             }
  103.         }
  104.     }
  105. }