employee_show.aspx.cs
上传用户:xrffrp
上传日期:2022-03-25
资源大小:22155k
文件大小:17k
源码类别:

OA系统

开发平台:

ASP/ASPX

  1. using System;
  2. using System.Data;
  3. using System.Configuration;
  4. using System.Collections;
  5. using System.Web;
  6. using System.Web.Security;
  7. using System.Web.UI;
  8. using System.Web.UI.WebControls;
  9. using System.Web.UI.WebControls.WebParts;
  10. using System.Web.UI.HtmlControls;
  11. using System.Data.SqlClient;
  12. public partial class web_personnel_employee_show : System.Web.UI.Page
  13. {
  14.     protected void Page_Load(object sender, EventArgs e)
  15.     {
  16.         LoginDAO.CheckLogin(Session, Response, "../../", 2);
  17.         if (!IsPostBack)
  18.         {
  19.             if (Request.QueryString["edit"]!=null)
  20.             {
  21.                 BtnOk.Enabled = false;
  22.                 BtnEdit.Enabled = false;
  23.             }
  24.             if (Request.QueryString["e_id"] != null)
  25.             {
  26.                 this.SetValue(Request.QueryString["e_id"]);
  27.             }
  28.         }
  29.     }
  30.     protected void SetValue(string id)
  31.     {
  32.         this.SetBasic(id);
  33.         this.SetFamily(id);
  34.         this.SetBackGround(id);
  35.         this.SetEducation(id);
  36.         this.SetWork(id);
  37.         this.SetSkill(id);
  38.     }
  39.     //員工基本信息
  40.     protected void SetBasic(string id)
  41.     {
  42.         SqlConnection conn = dbConnection.getConnection();
  43.         conn.Open();
  44.         SqlCommand cmd = new SqlCommand("select e.emp_no, e.emp_name, e.login_name, d.name department_name, "+
  45.             "g.name [group], p.name position, e.nation, e.marriage, e.id_card, e.native, e.stature, e.address, "+
  46.             "e.linkman, e.tel, e.registered_address, e.active_date, e.dimission_date, e.sex, e.birth_date, "+
  47.             "e.id_card_expire, e.email_work, e.email_personal, e.smart_phone, e.tel_extension, e.work_card_no1, "+
  48.             "e.link_man_tel, e.photo_save_name, e.work_place, e.work_card_no2 ,e.q_manger "+
  49.             "from OA_EMPLOYEE e inner join OA_DEPARTMENT d on e.department_id=d.id inner join OA_USER_GROUP_MAIN g "+
  50.             "on e.user_group=g.id inner join OA_EMPLOYEE_POSITION p on e.position=p.id where e.id="+id, conn);
  51.         SqlDataReader dr = cmd.ExecuteReader();
  52.         if (dr.Read())
  53.         {
  54.             LblNo.Text = dr["emp_no"].ToString();
  55.             LblName.Text = dr["emp_name"].ToString();
  56.             LblTitle.Text = LblName.Text + "員工履歷表";
  57.             LblLoginName.Text = dr["login_name"].ToString();
  58.             LblDepartment.Text = dr["department_name"].ToString();
  59.             LblGroup.Text = dr["group"].ToString();
  60.             LblPosition.Text = dr["position"].ToString();
  61.             LblNation.Text = dr["nation"].ToString();
  62.             string marriage = dr["marriage"].ToString();
  63.             if (marriage.Equals("1"))
  64.             {
  65.                 LblMarriage.Text = "未婚";
  66.             }
  67.             if (marriage.Equals("2"))
  68.             {
  69.                 LblMarriage.Text = "已婚";
  70.             }
  71.             if (marriage.Equals("3"))
  72.             {
  73.                 LblMarriage.Text = "離異";
  74.             }
  75.             LblIdCard.Text = dr["id_card"].ToString();
  76.             LblNative.Text = dr["native"].ToString();
  77.             LblStature.Text = dr["stature"].ToString();
  78.             LblAddress.Text = dr["address"].ToString();
  79.             LblLinkman.Text = dr["linkman"].ToString();
  80.             LblTel.Text = dr["tel"].ToString();
  81.             LblRegisteredAddress.Text = dr["registered_address"].ToString();
  82.             LblActiveDate.Text = dr["active_date"].ToString();
  83.             LblDimissionDate.Text = dr["dimission_date"].ToString();
  84.             if (dr["sex"].ToString().Equals("M"))
  85.             {
  86.                 LblSex.Text = "男";
  87.             }
  88.             else
  89.             {
  90.                 LblSex.Text = "女";
  91.             }
  92.             if (dr["q_manger"].ToString().Equals("1"))
  93.             {
  94.                 Lblmanger.Text = "主管";
  95.             }
  96.             else
  97.             {
  98.                 Lblmanger.Text = "非主管";
  99.             }
  100.             LblBirthDate.Text = dr["birth_date"].ToString();
  101.             LblIdCardExpire.Text = dr["id_card_expire"].ToString();
  102.             LblMailWork.Text = dr["email_work"].ToString();
  103.             LblMailPersonal.Text = dr["email_personal"].ToString();
  104.             LblSmartPhone.Text = dr["smart_phone"].ToString();
  105.             LblTelExtension.Text = dr["tel_extension"].ToString();
  106.             LblWorkCardNo1.Text = dr["work_card_no1"].ToString();
  107.             LblWorkCardNo2.Text = dr["work_card_no2"].ToString();
  108.             LblLinkmanTel.Text = dr["link_man_tel"].ToString();
  109.             LblWorkPlace.Text = dr["work_place"].ToString();
  110.             if (!dr["photo_save_name"].ToString().Equals(""))
  111.             {
  112.                 EmpPhoto.ImageUrl = "../employee_photo/" + dr["photo_save_name"].ToString();
  113.             }
  114.         }
  115.         dr.Close();
  116.         conn.Close();
  117.     }
  118.     //家庭情況
  119.     protected void SetFamily(string id)
  120.     {
  121.         SqlConnection conn = dbConnection.getConnection();
  122.         conn.Open();
  123.         SqlCommand cmd = new SqlCommand("select family_name, [relative], age, tel, company from OA_EMPLOYEE_FAMILY where emp_id="+id, conn);
  124.         SqlDataReader dr = cmd.ExecuteReader();
  125.         int index = 1;
  126.         while (dr.Read())
  127.         {
  128.             if (index == 1)
  129.             {
  130.                 LblFamilyName1.Text = dr["family_name"].ToString();
  131.                 LblRelative1.Text = dr["relative"].ToString();
  132.                 LblAge1.Text = dr["age"].ToString();
  133.                 LblTel1.Text = dr["tel"].ToString();
  134.                 LblCompany1.Text = dr["company"].ToString();
  135.             }
  136.             if (index == 2)
  137.             {
  138.                 LblFamilyName2.Text = dr["family_name"].ToString();
  139.                 LblRelative2.Text = dr["relative"].ToString();
  140.                 LblAge2.Text = dr["age"].ToString();
  141.                 LblTel2.Text = dr["tel"].ToString();
  142.                 LblCompany2.Text = dr["company"].ToString();
  143.             }
  144.             if (index == 3)
  145.             {
  146.                 LblFamilyName3.Text = dr["family_name"].ToString();
  147.                 LblRelative3.Text = dr["relative"].ToString();
  148.                 LblAge3.Text = dr["age"].ToString();
  149.                 LblTel3.Text = dr["tel"].ToString();
  150.                 LblCompany3.Text = dr["company"].ToString();
  151.             }
  152.             if (index == 4)
  153.             {
  154.                 LblFamilyName4.Text = dr["family_name"].ToString();
  155.                 LblRelative4.Text = dr["relative"].ToString();
  156.                 LblAge4.Text = dr["age"].ToString();
  157.                 LblTel4.Text = dr["tel"].ToString();
  158.                 LblCompany4.Text = dr["company"].ToString();
  159.             }
  160.             index = index + 1;
  161.         }
  162.         dr.Close();
  163.         conn.Close();
  164.     }
  165.     //背景
  166.     protected void SetBackGround(string id)
  167.     {
  168.         SqlConnection conn = dbConnection.getConnection();
  169.         conn.Open();
  170.         SqlCommand cmd = new SqlCommand("select back_name, [relative], job, tel, company from OA_EMPLOYEE_BACKGROUND where emp_id="+id, conn);
  171.         SqlDataReader dr = cmd.ExecuteReader();
  172.         int index = 1;
  173.         while (dr.Read())
  174.         {
  175.             if (index == 1)
  176.             {
  177.                 LblBackName1.Text = dr["back_name"].ToString();
  178.                 LblBackRelative1.Text = dr["relative"].ToString();
  179.                 LblBackJob1.Text = dr["job"].ToString();
  180.                 LblBackTel1.Text = dr["tel"].ToString();
  181.                 LblBackCompany1.Text = dr["company"].ToString();
  182.             }
  183.             if (index == 2)
  184.             {
  185.                 LblBackName2.Text = dr["back_name"].ToString();
  186.                 LblBackRelative2.Text = dr["relative"].ToString();
  187.                 LblBackJob2.Text = dr["job"].ToString();
  188.                 LblBackTel2.Text = dr["tel"].ToString();
  189.                 LblBackCompany2.Text = dr["company"].ToString();
  190.             }
  191.             index = index + 1;
  192.         }
  193.         dr.Close();
  194.         conn.Close();
  195.     }
  196.     //教育經歷
  197.     protected void SetEducation(string id)
  198.     {
  199.         SqlConnection conn = dbConnection.getConnection();
  200.         conn.Open();
  201.         SqlCommand cmd = new SqlCommand("select begin_year, begin_month, end_year, end_month, school, subject, "+
  202.             "grade from OA_EMPLOYEE_EDUCATION where emp_id=" + id, conn);
  203.         SqlDataReader dr = cmd.ExecuteReader();
  204.         int index = 1;
  205.         while (dr.Read())
  206.         {
  207.             if (index == 1)
  208.             {
  209.                 LblEdBeginYear1.Text = dr["begin_year"].ToString();
  210.                 LblEdBeginMonth1.Text = dr["begin_month"].ToString();
  211.                 LblEdEndYear1.Text = dr["end_year"].ToString();
  212.                 LblEdEndMonth1.Text = dr["end_month"].ToString();
  213.                 LblSchoolName1.Text = dr["school"].ToString();
  214.                 LblSubject1.Text = dr["subject"].ToString();
  215.                 LblGrade1.Text = dr["grade"].ToString();
  216.             }
  217.             if (index == 2)
  218.             {
  219.                 LblEdBeginYear2.Text = dr["begin_year"].ToString();
  220.                 LblEdBeginMonth2.Text = dr["begin_month"].ToString();
  221.                 LblEdEndYear2.Text = dr["end_year"].ToString();
  222.                 LblEdEndMonth2.Text = dr["end_month"].ToString();
  223.                 LblSchoolName2.Text = dr["school"].ToString();
  224.                 LblSubject2.Text = dr["subject"].ToString();
  225.                 LblGrade2.Text = dr["grade"].ToString();
  226.             }
  227.             if (index == 3)
  228.             {
  229.                 LblEdBeginYear3.Text = dr["begin_year"].ToString();
  230.                 LblEdBeginMonth3.Text = dr["begin_month"].ToString();
  231.                 LblEdEndYear3.Text = dr["end_year"].ToString();
  232.                 LblEdEndMonth3.Text = dr["end_month"].ToString();
  233.                 LblSchoolName3.Text = dr["school"].ToString();
  234.                 LblSubject3.Text = dr["subject"].ToString();
  235.                 LblGrade3.Text = dr["grade"].ToString();
  236.             }
  237.             if (index == 4)
  238.             {
  239.                 LblEdBeginYear4.Text = dr["begin_year"].ToString();
  240.                 LblEdBeginMonth4.Text = dr["begin_month"].ToString();
  241.                 LblEdEndYear4.Text = dr["end_year"].ToString();
  242.                 LblEdEndMonth4.Text = dr["end_month"].ToString();
  243.                 LblSchoolName4.Text = dr["school"].ToString();
  244.                 LblSubject4.Text = dr["subject"].ToString();
  245.                 LblGrade4.Text = dr["grade"].ToString();
  246.             }
  247.             index = index + 1;
  248.         }
  249.         dr.Close();
  250.         conn.Close();
  251.     }
  252.     //工作經歷
  253.     protected void SetWork(string id)
  254.     {
  255.         SqlConnection conn = dbConnection.getConnection();
  256.         conn.Open();
  257.         SqlCommand cmd = new SqlCommand("select begin_year, begin_month, end_year, end_month, company, tel, "+
  258.             "salary, dimission_reason from OA_EMPLOYEE_JOB where emp_id=" + id, conn);
  259.         SqlDataReader dr = cmd.ExecuteReader();
  260.         int index = 1;
  261.         while (dr.Read())
  262.         {
  263.             if (index == 1)
  264.             {
  265.                 LblWorkBeginYear1.Text = dr["begin_year"].ToString();
  266.                 LblWorkBeginMonth1.Text = dr["begin_month"].ToString();
  267.                 LblWorkEndYear1.Text = dr["end_year"].ToString();
  268.                 LblWorkEndMonth1.Text = dr["end_month"].ToString();
  269.                 LblWorkCompany1.Text = dr["company"].ToString();
  270.                 LblWorkTel1.Text = dr["tel"].ToString();
  271.                 LblWorkSalary1.Text = dr["salary"].ToString();
  272.                 LblDimissionReason1.Text = dr["dimission_reason"].ToString();
  273.             }
  274.             if (index == 2)
  275.             {
  276.                 LblWorkBeginYear2.Text = dr["begin_year"].ToString();
  277.                 LblWorkBeginMonth2.Text = dr["begin_month"].ToString();
  278.                 LblWorkEndYear2.Text = dr["end_year"].ToString();
  279.                 LblWorkEndMonth2.Text = dr["end_month"].ToString();
  280.                 LblWorkCompany2.Text = dr["company"].ToString();
  281.                 LblWorkTel2.Text = dr["tel"].ToString();
  282.                 LblWorkSalary2.Text = dr["salary"].ToString();
  283.                 LblDimissionReason2.Text = dr["dimission_reason"].ToString();
  284.             }
  285.             if (index == 3)
  286.             {
  287.                 LblWorkBeginYear3.Text = dr["begin_year"].ToString();
  288.                 LblWorkBeginMonth3.Text = dr["begin_month"].ToString();
  289.                 LblWorkEndYear3.Text = dr["end_year"].ToString();
  290.                 LblWorkEndMonth3.Text = dr["end_month"].ToString();
  291.                 LblWorkCompany3.Text = dr["company"].ToString();
  292.                 LblWorkTel3.Text = dr["tel"].ToString();
  293.                 LblWorkSalary3.Text = dr["salary"].ToString();
  294.                 LblDimissionReason3.Text = dr["dimission_reason"].ToString();
  295.             }
  296.             if (index == 4)
  297.             {
  298.                 LblWorkBeginYear4.Text = dr["begin_year"].ToString();
  299.                 LblWorkBeginMonth4.Text = dr["begin_month"].ToString();
  300.                 LblWorkEndYear4.Text = dr["end_year"].ToString();
  301.                 LblWorkEndMonth4.Text = dr["end_month"].ToString();
  302.                 LblWorkCompany4.Text = dr["company"].ToString();
  303.                 LblWorkTel4.Text = dr["tel"].ToString();
  304.                 LblWorkSalary4.Text = dr["salary"].ToString();
  305.                 LblDimissionReason4.Text = dr["dimission_reason"].ToString();
  306.             }
  307.             index = index + 1;
  308.         }
  309.         dr.Close();
  310.         conn.Close();
  311.     }
  312.     //專業技能
  313.     protected void SetSkill(string id)
  314.     {
  315.         SqlConnection conn = dbConnection.getConnection();
  316.         conn.Open();
  317.         SqlCommand cmd = new SqlCommand("select [language],computer_grade,certificate,other from OA_EMPLOYEE_SKILL where emp_id="+id, conn);
  318.         SqlDataReader dr = cmd.ExecuteReader();
  319.         if (dr.Read())
  320.         {
  321.             LblLanguage.Text = dr["language"].ToString();
  322.             LblComputerGrade.Text = dr["computer_grade"].ToString();
  323.             LblCertificate.Text = dr["certificate"].ToString();
  324.             LblOther.Text = dr["other"].ToString();
  325.         }
  326.         dr.Close();
  327.         conn.Close();
  328.     }
  329.     protected void BtnOk_Click(object sender, EventArgs e)
  330.     {
  331.         if (Request.QueryString["e_id"] != null)
  332.         {
  333.             Response.Redirect("employee_edit.aspx?e_id="+Request.QueryString["e_id"]);
  334.         }
  335.     }
  336.     protected void BtnEdit_Click(object sender, EventArgs e)
  337.     {
  338.         BtnEdit.Visible = false;
  339.         BtnUpload.Visible = true;
  340.         FileUpload1.Visible = true;
  341.     }
  342.     protected void BtnUpload_Click(object sender, EventArgs e)
  343.     { 
  344.         DateMgr mgr = new DateMgr();
  345.         string time = mgr.getTime();
  346.         if (this.uploadFile(time) && Request.QueryString["e_id"] != null)
  347.         {
  348.             string save_name = FileUpload1.FileName.Substring(0, FileUpload1.FileName.Length - 4) + time + System.IO.Path.GetExtension(FileUpload1.FileName).ToLower();
  349.             string name = FileUpload1.FileName;
  350.             SqlConnection conn = dbConnection.getConnection();
  351.             conn.Open();
  352.             SqlCommand cmd = new SqlCommand("update OA_EMPLOYEE set photo_name='" + name +
  353.                 "', photo_save_name='" + save_name + "' where id=" + Request.QueryString["e_id"], conn);
  354.             cmd.ExecuteNonQuery();
  355.             conn.Close();
  356.             Response.Write("<script language='javascript'>alert('上傳檔案成功');</script>");
  357.            // EmpPhoto.ImageUrl = Server.MapPath("~/web/employee_photo/") + save_name;
  358.             EmpPhoto.ImageUrl = "../employee_photo/" + save_name;
  359.             BtnEdit.Visible = true;
  360.             BtnUpload.Visible = false;
  361.             FileUpload1.Visible = false;
  362.         }
  363.     }
  364.     protected bool uploadFile(string time)
  365.     {
  366.         bool flag = false;
  367.         string directory = Server.MapPath("../employee_photo/");
  368.         if (FileUpload1.HasFile)
  369.         {
  370.             bool extenstion = false;
  371.             string fileExtension = System.IO.Path.GetExtension(FileUpload1.FileName).ToLower();
  372.             string[] allowedExtensions = 
  373.                 { ".gif", ".jpg" };
  374.             for (int i = 0; i < allowedExtensions.Length; i++)
  375.             {
  376.                 if (fileExtension == allowedExtensions[i])
  377.                 {
  378.                     extenstion = true;
  379.                     break;
  380.                 }
  381.             }
  382.             if (!extenstion)
  383.             {
  384.                 Response.Write("<script language='javascript'>alert('只允許上傳格式為gif, jpg的檔案!');</script>");
  385.                 return false;
  386.             }
  387.             else
  388.             {
  389.                 string name = FileUpload1.FileName.Substring(0, FileUpload1.FileName.Length - 4) + time + System.IO.Path.GetExtension(FileUpload1.FileName).ToLower();
  390.                 FileUpload1.PostedFile.SaveAs(directory + name);
  391.                 ContentLength.Value = FileUpload1.PostedFile.ContentLength.ToString();
  392.                 flag = true;
  393.             }
  394.         }
  395.         return flag;
  396.     }
  397.     protected void BtnShowWhere_Click(object sender, EventArgs e)
  398.     {
  399.         if (Request.QueryString["e_id"] != null)
  400.         {
  401.             Response.Redirect("employee_where.aspx?e_id="+Request.QueryString["e_id"]);
  402.         }
  403.     }
  404. }