employee_form.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_curricula_vitae_employee_form : 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 (Session["p_department_id"] != null)
  20.             {
  21.                 SqlConnection conn = dbConnection.getConnection();
  22.                 conn.Open();
  23.                 SqlCommand cmd = new SqlCommand("select id, name from OA_DEPARTMENT where id=" + Session["p_department_id"].ToString(), conn);
  24.                 SqlDataReader dr = cmd.ExecuteReader();
  25.                 if (dr.Read())
  26.                 {
  27.                     DepartmentId.Value = dr["id"].ToString();
  28.                     TxtDepartment.Text = dr["name"].ToString();
  29.                 }
  30.                 dr.Close();
  31.                 conn.Close();
  32.             }
  33.             TxtNo.Attributes.Add("onchange", "changeEmpNo()");
  34.         }
  35.     }
  36.     protected bool CheckValidate()
  37.     {
  38.         int flag = 0;
  39.         if (DepartmentId.Value.Equals(""))
  40.         {
  41.             flag = 1;
  42.             Response.Write("<script language='javascript'>alert('部門不能為空!')</script>");
  43.             TxtDepartment.Focus();
  44.         }
  45.         if (TxtName.Text.Trim().Equals(""))
  46.         {
  47.             flag = 1;
  48.             Response.Write("<script language='javascript'>alert('姓名不能為空!')</script>");
  49.             TxtName.Focus();
  50.         }
  51.         if (TxtNo.Text.Trim().Equals(""))
  52.         {
  53.             flag = 1;
  54.             Response.Write("<script language='javascript'>alert('工號不能為空!')</script>");
  55.             TxtNo.Focus();
  56.         }
  57.         if (TxtLoginName.Text.Trim().Equals(""))
  58.         {
  59.             flag = 1;
  60.             Response.Write("<script language='javascript'>alert('登錄名不能為空!')</script>");
  61.             TxtLoginName.Focus();
  62.         }
  63.         if (TxtPwd.Text.Trim().Equals(""))
  64.         {
  65.             flag = 1;
  66.             Response.Write("<script language='javascript'>alert('密碼不能為空!')</script>");
  67.             TxtPwd.Focus();
  68.         }
  69.         if (TxtMailWork.Text.Trim().Equals(""))
  70.         {
  71.             flag = 1;
  72.             Response.Write("<script language='javascript'>alert('工作郵箱不能為空!')</script>");
  73.             TxtMailWork.Focus();
  74.         }
  75.         if (flag == 0)
  76.         {
  77.             return true;
  78.         }
  79.         else
  80.         {
  81.             return false;
  82.         }
  83.     }
  84.     protected void BtnOk_Click(object sender, EventArgs e)
  85.     {
  86.         if (this.CheckValidate())
  87.         {
  88.             int flag = 0;
  89.             SqlConnection conn = dbConnection.getConnection();
  90.             conn.Open();
  91.             SqlCommand cmd = new SqlCommand("select count(id) from OA_EMPLOYEE where login_name='" +
  92.                 TxtLoginName.Text.Trim() + "'", conn);
  93.             int count = Convert.ToInt32(cmd.ExecuteScalar());
  94.             if (count == 1)
  95.             {
  96.                 flag = 1;
  97.             }
  98.             if (flag == 0)
  99.             {
  100.                 //添加员工基本资料
  101.                 int emp_id = 1;
  102.                 cmd = new SqlCommand("select max(id) from OA_EMPLOYEE", conn);
  103.                 try
  104.                 {
  105.                     emp_id = Convert.ToInt32(cmd.ExecuteScalar().ToString()) + 1;
  106.                 }
  107.                 catch { }
  108.                 cmd = new SqlCommand("insert into OA_EMPLOYEE(id, department_id, emp_no, emp_name, login_name, " +
  109.                     "pwd, user_group, position, dimission_date, active_date, sex, birth_date, nation, " +
  110.                     "marriage, id_card, native, stature, address, linkman, tel, registered_address,"+
  111.                     "smart_phone, tel_extension, id_card_expire, email_work, email_personal,work_card_no1, "+
  112.                     "work_card_no2, link_man_tel, work_place,is_del) values (" +
  113.                     emp_id + ", '" + DepartmentId.Value + "','" + TxtNo.Text + "','" + TxtName.Text + "','" + TxtLoginName.Text +
  114.                     "','" + TxtPwd.Text + "','" + DdlGroup.SelectedValue + "','" + DdlPosition.SelectedValue + "','" +
  115.                     TxtDimissionDate.Text + "','" + TxtActiveDate.Text + "','" + DdlSex.SelectedValue + "','" +
  116.                     TxtBirthDate.Text + "','" + TxtNation.Text + "','" + DdlMarriage.SelectedValue + "','" +
  117.                     TxtIdCard.Text + "','" + TxtNative.Text + "','" + TxtStature.Text + "','" + TxtAddress.Text + "','" +
  118.                     TxtLinkman.Text + "','" + TxtTel.Text + "','" + TxtRegisteredAdress.Text + "','"+
  119.                     TxtSmartPhone.Text+"','"+TxtTelExtension.Text+"','"+TxtIdCardExpire.Text+"','"+
  120.                     TxtMailWork.Text+"','"+TxtMailPersonal.Text+"','"+TxtWorkCardNo1.Text+"','"+
  121.                     TxtWorkCardNo2.Text+"','"+TxtLinkmanTel.Text+"','"+TxtWorkPlace.Text+"','N')", conn);
  122.                 cmd.ExecuteNonQuery();
  123.                 //添加家庭情况
  124.                 #region
  125.                 if (!TxtFamilyName1.Text.Trim().Equals(""))
  126.                 {
  127.                     cmd = new SqlCommand("insert into OA_EMPLOYEE_FAMILY (emp_id, family_name, [relative], age, " +
  128.                         "tel, company) values (" + emp_id + ", '" + TxtFamilyName1.Text + "', '" + TxtRelative1.Text + "','" +
  129.                         TxtAge1.Text + "','" + TxtTel1.Text + "','" + TxtCompany1.Text + "')", conn);
  130.                     cmd.ExecuteNonQuery();
  131.                 }
  132.                 if (!TxtFamilyName2.Text.Trim().Equals(""))
  133.                 {
  134.                     cmd = new SqlCommand("insert into OA_EMPLOYEE_FAMILY (emp_id, family_name, [relative], age, " +
  135.                         "tel, company) values (" + emp_id + ", '" + TxtFamilyName2.Text + "', '" + TxtRelative2.Text + "','" +
  136.                         TxtAge2.Text + "','" + TxtTel2.Text + "','" + TxtCompany2.Text + "')", conn);
  137.                     cmd.ExecuteNonQuery();
  138.                 }
  139.                 if (!TxtFamilyName3.Text.Trim().Equals(""))
  140.                 {
  141.                     cmd = new SqlCommand("insert into OA_EMPLOYEE_FAMILY (emp_id, family_name, [relative], age, " +
  142.                         "tel, company) values (" + emp_id + ", '" + TxtFamilyName3.Text + "', '" + TxtRelative3.Text + "','" +
  143.                         TxtAge3.Text + "','" + TxtTel3.Text + "','" + TxtCompany3.Text + "')", conn);
  144.                     cmd.ExecuteNonQuery();
  145.                 }
  146.                 if (!TxtFamilyName4.Text.Trim().Equals(""))
  147.                 {
  148.                     cmd = new SqlCommand("insert into OA_EMPLOYEE_FAMILY (emp_id, family_name, [relative], age, " +
  149.                         "tel, company) values (" + emp_id + ", '" + TxtFamilyName4.Text + "', '" + TxtRelative4.Text + "','" +
  150.                         TxtAge4.Text + "','" + TxtTel4.Text + "','" + TxtCompany4.Text + "')", conn);
  151.                     cmd.ExecuteNonQuery();
  152.                 }
  153.                 #endregion
  154.                 //添加背景
  155.                 #region
  156.                 if (!TxtBackName1.Text.Trim().Equals(""))
  157.                 {
  158.                     cmd = new SqlCommand("insert into OA_EMPLOYEE_BACKGROUND(emp_id, back_name, [relative], job, " +
  159.                         "tel, company)values(" + emp_id + ",'" + TxtBackName1.Text + "','" + TxtBackRelative1.Text + "','" +
  160.                         TxtBackJob1.Text + "','" + TxtBackTel1.Text + "','" + TxtBackCompany1.Text + "')", conn);
  161.                     cmd.ExecuteNonQuery();
  162.                 }
  163.                 if (!TxtBackName2.Text.Trim().Equals(""))
  164.                 {
  165.                     cmd = new SqlCommand("insert into OA_EMPLOYEE_BACKGROUND(emp_id, back_name, [relative], job, " +
  166.                         "tel, company)values(" + emp_id + ",'" + TxtBackName2.Text + "','" + TxtBackRelative2.Text + "','" +
  167.                         TxtBackJob2.Text + "','" + TxtBackTel2.Text + "','" + TxtBackCompany2.Text + "')", conn);
  168.                     cmd.ExecuteNonQuery();
  169.                 }
  170. #endregion
  171.                 //添加教育經歷
  172.                 #region
  173.                 if (!TxtSchoolName1.Text.Trim().Equals(""))
  174.                 {
  175.                     cmd = new SqlCommand("insert into OA_EMPLOYEE_EDUCATION(emp_id, begin_year, begin_month, " +
  176.                         "end_year, end_month, school, subject, grade)values(" + emp_id + ",'" + TxtEdBeginYear1.Text +
  177.                         "','" + TxtEdBeginMonth1.Text + "','" + TxtEdEndYear1.Text + "','" + TxtEdEndMonth1.Text + "','" +
  178.                         TxtSchoolName1.Text + "','" + TxtSubject1.Text + "','" + TxtGrade1.Text + "')", conn);
  179.                     cmd.ExecuteNonQuery();
  180.                 }
  181.                 if (!TxtSchoolName2.Text.Trim().Equals(""))
  182.                 {
  183.                     cmd = new SqlCommand("insert into OA_EMPLOYEE_EDUCATION(emp_id, begin_year, begin_month, " +
  184.                         "end_year, end_month, school, subject, grade)values(" + emp_id + ",'" + TxtEdBeginYear2.Text +
  185.                         "','" + TxtEdBeginMonth2.Text + "','" + TxtEdEndYear2.Text + "','" + TxtEdEndMonth2.Text + "','" +
  186.                         TxtSchoolName2.Text + "','" + TxtSubject2.Text + "','" + TxtGrade2.Text + "')", conn);
  187.                     cmd.ExecuteNonQuery();
  188.                 }
  189.                 if (!TxtSchoolName3.Text.Trim().Equals(""))
  190.                 {
  191.                     cmd = new SqlCommand("insert into OA_EMPLOYEE_EDUCATION(emp_id, begin_year, begin_month, " +
  192.                         "end_year, end_month, school, subject, grade)values(" + emp_id + ",'" + TxtEdBeginYear3.Text +
  193.                         "','" + TxtEdBeginMonth3.Text + "','" + TxtEdEndYear3.Text + "','" + TxtEdEndMonth3.Text + "','" +
  194.                         TxtSchoolName3.Text + "','" + TxtSubject3.Text + "','" + TxtGrade3.Text + "')", conn);
  195.                     cmd.ExecuteNonQuery();
  196.                 }
  197.                 if (!TxtSchoolName4.Text.Trim().Equals(""))
  198.                 {
  199.                     cmd = new SqlCommand("insert into OA_EMPLOYEE_EDUCATION(emp_id, begin_year, begin_month, " +
  200.                         "end_year, end_month, school, subject, grade)values(" + emp_id + ",'" + TxtEdBeginYear4.Text +
  201.                         "','" + TxtEdBeginMonth4.Text + "','" + TxtEdEndYear4.Text + "','" + TxtEdEndMonth4.Text + "','" +
  202.                         TxtSchoolName4.Text + "','" + TxtSubject4.Text + "','" + TxtGrade4.Text + "')", conn);
  203.                     cmd.ExecuteNonQuery();
  204.                 }
  205.                 #endregion
  206.                 //添加工作經歷
  207.                 #region
  208.                 if (!TxtWorkCompany1.Text.Trim().Equals(""))
  209.                 {
  210.                     cmd = new SqlCommand("insert into OA_EMPLOYEE_JOB(emp_id, begin_year, begin_month, end_year, " +
  211.                         "end_month, company, tel, salary, dimission_reason)values(" + emp_id + ",'" + TxtWorkBeginYear1.Text +
  212.                         "','" + TxtWorkBeginMonth1.Text + "','" + TxtWorkEndYear1.Text + "','" + TxtWorkEndMonth1.Text + "','" +
  213.                         TxtWorkCompany1.Text + "','" + TxtWorkTel1.Text + "','" + TxtWorkSalary1.Text + "','" +
  214.                         TxtDimissionReason1.Text + "')", conn);
  215.                     cmd.ExecuteNonQuery();
  216.                 }
  217.                 if (!TxtWorkCompany2.Text.Trim().Equals(""))
  218.                 {
  219.                     cmd = new SqlCommand("insert into OA_EMPLOYEE_JOB(emp_id, begin_year, begin_month, end_year, " +
  220.                         "end_month, company, tel, salary, dimission_reason)values(" + emp_id + ",'" + TxtWorkBeginYear2.Text +
  221.                         "','" + TxtWorkBeginMonth2.Text + "','" + TxtWorkEndYear2.Text + "','" + TxtWorkEndMonth2.Text + "','" +
  222.                         TxtWorkCompany2.Text + "','" + TxtWorkTel2.Text + "','" + TxtWorkSalary2.Text + "','" +
  223.                         TxtDimissionReason2.Text + "')", conn);
  224.                     cmd.ExecuteNonQuery();
  225.                 }
  226.                 if (!TxtWorkCompany3.Text.Trim().Equals(""))
  227.                 {
  228.                     cmd = new SqlCommand("insert into OA_EMPLOYEE_JOB(emp_id, begin_year, begin_month, end_year, " +
  229.                         "end_month, company, tel, salary, dimission_reason)values(" + emp_id + ",'" + TxtWorkBeginYear3.Text +
  230.                         "','" + TxtWorkBeginMonth3.Text + "','" + TxtWorkEndYear3.Text + "','" + TxtWorkEndMonth3.Text + "','" +
  231.                         TxtWorkCompany3.Text + "','" + TxtWorkTel3.Text + "','" + TxtWorkSalary3.Text + "','" +
  232.                         TxtDimissionReason3.Text + "')", conn);
  233.                     cmd.ExecuteNonQuery();
  234.                 }
  235.                 if (!TxtWorkCompany4.Text.Trim().Equals(""))
  236.                 {
  237.                     cmd = new SqlCommand("insert into OA_EMPLOYEE_JOB(emp_id, begin_year, begin_month, end_year, " +
  238.                         "end_month, company, tel, salary, dimission_reason)values(" + emp_id + ",'" + TxtWorkBeginYear4.Text +
  239.                         "','" + TxtWorkBeginMonth4.Text + "','" + TxtWorkEndYear4.Text + "','" + TxtWorkEndMonth4.Text + "','" +
  240.                         TxtWorkCompany4.Text + "','" + TxtWorkTel4.Text + "','" + TxtWorkSalary4.Text + "','" +
  241.                         TxtDimissionReason4.Text + "')", conn);
  242.                     cmd.ExecuteNonQuery();
  243.                 }
  244.                 #endregion
  245.                 //添加專業技能
  246.                 #region
  247.                 if (!TxtLanguage.Text.Trim().Equals("") || !TxtComputerGrade.Text.Trim().Equals("")
  248.                     || !TxtCertificate.Text.Trim().Equals("") || !TxtOther.Text.Trim().Equals(""))
  249.                 {
  250.                     int skill_id = 1;
  251.                     cmd = new SqlCommand("select max(id) from OA_EMPLOYEE_SKILL", conn);
  252.                     try
  253.                     {
  254.                         skill_id = Convert.ToInt32(cmd.ExecuteScalar().ToString()) + 1;
  255.                     }
  256.                     catch { }
  257.                     cmd = new SqlCommand("insert into OA_EMPLOYEE_SKILL(id, emp_id, language, computer_grade, " +
  258.                         "certificate, other) values(" + skill_id + "," + emp_id + ",'" + TxtLanguage.Text + "','" +
  259.                         TxtComputerGrade.Text + "','" + TxtCertificate.Text + "','" + TxtOther.Text + "')", conn);
  260.                     cmd.ExecuteNonQuery();
  261.                 }
  262.                 #endregion
  263.                 Session["p_department_id"] = DepartmentId.Value;
  264.                // Response.Redirect("employee_list_index.aspx");
  265.                 Response.Redirect("upload_photo.aspx?e_id="+emp_id);
  266.             }
  267.             else
  268.             {
  269.                 Response.Write("<script language='javascript'>alert('已存在相同登錄名的員工');</script>");
  270.                 TxtLoginName.Focus();
  271.             }
  272.             conn.Close();
  273.         }
  274.     }
  275.     protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
  276.     {
  277.         if (Calendar1.Visible == true)
  278.         {
  279.             Calendar1.Visible = false;
  280.         }
  281.         else
  282.         {
  283.             Calendar1.Visible = true;
  284.         }
  285.     }
  286.     protected void Calendar1_SelectionChanged(object sender, EventArgs e)
  287.     {
  288.         string year = Calendar1.SelectedDate.Year.ToString();
  289.         string month = Calendar1.SelectedDate.Month.ToString();
  290.         if (month.Length == 1)
  291.         {
  292.             month = "0" + month;
  293.         }
  294.         string day = Calendar1.SelectedDate.Day.ToString();
  295.         if (day.Length == 1)
  296.         {
  297.             day = "0" + day;
  298.         }
  299.         TxtActiveDate.Text = year + "-" + month + "-" + day; 
  300.         Calendar1.Visible = false;
  301.     }
  302.     protected void ImageButton2_Click(object sender, ImageClickEventArgs e)
  303.     {
  304.         if (Calendar2.Visible == true)
  305.         {
  306.             Calendar2.Visible = false;
  307.         }
  308.         else
  309.         {
  310.             Calendar2.Visible = true;
  311.         }
  312.     }
  313.     protected void Calendar2_SelectionChanged(object sender, EventArgs e)
  314.     {
  315.         string year = Calendar2.SelectedDate.Year.ToString();
  316.         string month = Calendar2.SelectedDate.Month.ToString();
  317.         if (month.Length == 1)
  318.         {
  319.             month = "0" + month;
  320.         }
  321.         string day = Calendar2.SelectedDate.Day.ToString();
  322.         if (day.Length == 1)
  323.         {
  324.             day = "0" + day;
  325.         }
  326.         TxtDimissionDate.Text = year + "-" + month + "-" + day; ;
  327.         Calendar2.Visible = false;
  328.     }
  329. }