AddEmployee.aspx.cs
上传用户:tiancihang
上传日期:2014-03-12
资源大小:21387k
文件大小:9k
源码类别:

.net编程

开发平台:

C#

  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 com.etong.DAL.FC;
  12. public partial class AddEmployee : System.Web.UI.Page
  13. {
  14.     protected int iEmpID;
  15.     protected string sEmpID,sModify;
  16.     protected void Page_Load(object sender, EventArgs e)
  17.     {   
  18.         if (!IsPostBack)
  19.         {
  20.             Response.Buffer = true;
  21.             Response.ExpiresAbsolute = System.DateTime.Now;
  22.             Response.Expires = 0;
  23.             Response.CacheControl = "no-cache";
  24.             ImageButton2.Attributes.Add("onclick", "javascript:if(confirm('确定要退出吗?')) {window.close();return;} else {return;}");
  25.             EtongFlyChou EFly = new EtongFlyChou();
  26.             sEmpID = Request.QueryString["StrValue"].ToString();
  27.             sModify = Request.QueryString["StrM"].ToString();
  28.             //sEmpID = sEmpID.Substring(2, sEmpID.Length - 2);
  29.             iEmpID = Convert.ToInt32(sEmpID);
  30.             string sParent="";
  31.             if (sModify == "M")
  32.             {
  33.                 sParent = EFly.GetEmpParentOrgID(sEmpID);
  34.             }
  35.             else
  36.             {
  37.                 sParent = sEmpID;
  38.             }
  39.             string StrOrgPath = "";
  40.             if (sParent.Trim() != "" && sParent != null)
  41.             {
  42.                 StrOrgPath = EFly.GetAddressName(sParent);
  43.             }
  44.             TxtOrgName.Text = StrOrgPath;
  45.             Page.Title = "新增职工信息";
  46.             LabTitle.Text = "新增职工信息";
  47.             EtongFlyChouWFPrj EFlyPrj = new EtongFlyChouWFPrj();
  48.             DataView dv1 = new DataView();
  49.             try
  50.             {
  51.                 dv1 = EFlyPrj.GetAllOpRole();
  52.                 ChList.DataTextField = "OpName";
  53.                 ChList.DataValueField = "OpID";
  54.                 ChList.DataSource = dv1;
  55.                 ChList.DataBind();
  56.                 dv1 = EFly.GetAllEmp();
  57.                 DLstParent.DataTextField = "EmpName";
  58.                 DLstParent.DataValueField = "EmpID";
  59.                 DLstParent.DataSource = dv1;
  60.                 DLstParent.DataBind();
  61.                 this.DLstParent.Items.Insert(0, new ListItem("----请选择----", "-1"));
  62.                 dv1 = EFly.GetEmpType();
  63.                 DListType.DataTextField = "name";
  64.                 DListType.DataValueField = "id";
  65.                 DListType.DataSource = dv1;
  66.                 DListType.DataBind();
  67.             }
  68.             catch (Exception ex)
  69.             {
  70.                 this.ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('" + ex.Message.Replace("'", "").Replace("rn", "").Replace("n", "") + "');</script>");
  71.                 return;
  72.             }
  73.                 
  74.             
  75.             //项目修改
  76.             if (sModify == "M")
  77.             {
  78.                 Page.Title = "职工信息修改";
  79.                 LabTitle.Text = "职工信息修改";
  80.                 DataView dv = new DataView();
  81.                 dv = EFly.GetEmp(sEmpID);
  82.                 TxtName.Text = dv.Table.Rows[0][1].ToString();
  83.                 DListType.Items.FindByValue(DListType.SelectedValue).Selected = false;
  84.                 string DLValue;
  85.                 //if (Convert.ToInt32(dv.Table.Rows[0][3].ToString()) > 4 || Convert.ToInt32(dv.Table.Rows[0][3].ToString()) < 1)
  86.                 //    DLValue = "4";
  87.                 //else 
  88.                 DLValue = dv.Table.Rows[0][3].ToString();
  89.                 try
  90.                 {
  91.                     DListType.Items.FindByValue(DLValue).Selected = true;
  92.                 }
  93.                 catch
  94.                 {
  95.                 }
  96.                 TxtEmail.Text = dv.Table.Rows[0][4].ToString();
  97.                 TxtPNum.Text = dv.Table.Rows[0][5].ToString();
  98.                 if (dv.Table.Rows[0][7].ToString().Trim() == "1")
  99.                 {
  100.                     CheckEmp.Checked = true;
  101.                 }
  102.                 else
  103.                 {
  104.                     CheckEmp.Checked = false;
  105.                 }
  106.                 DLstParent.Items.FindByValue(DLstParent.SelectedValue).Selected=false;
  107.                 try
  108.                 {
  109.                     DLstParent.Items.FindByValue(dv.Table.Rows[0]["ParentEmp"].ToString()).Selected = true;
  110.                 }
  111.                 catch
  112.                 {
  113.                 }
  114.                 EFlyPrj.EmpID = iEmpID;
  115.                 try
  116.                 {
  117.                     dv = EFlyPrj.GetAssignOpRole();
  118.                     for (int i = 0; i < dv.Table.Rows.Count; i++)
  119.                     {
  120.                         for (int j = 0; j < ChList.Items.Count; j++)
  121.                         {
  122.                             if (ChList.Items[j].Value.ToString().Trim() == dv.Table.Rows[i]["OpID"].ToString().Trim())
  123.                             {
  124.                                 ChList.Items[j].Selected = true;
  125.                                 break;
  126.                             }
  127.                         }
  128.                     }
  129.                 }
  130.                 catch (Exception ex)
  131.                 {
  132.                     this.ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('" + ex.Message.Replace("'", "").Replace("rn", "").Replace("n", "") + "');</script>");
  133.                     return;
  134.                 }
  135.             }
  136.             //bool bFlag = true;
  137.             //bFlag = EFly.HomonymyCheck(TxtName.Text);
  138.             //if (bFlag == false)
  139.             //{
  140.             //    ImageButton1.Attributes.Add("onclick", "javascript:return confirm('确定要删除此记录吗?');");
  141.             //}
  142.         }
  143.     }
  144.     protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
  145.     {
  146.         string StrName, StrEmail, StrOrgID, PhoneNum;
  147.         int iTmpFlag =0,iType=4;
  148.         //bool bFlag= true;
  149.         EtongFlyChou EFly = new EtongFlyChou();
  150.         StrOrgID = Request.QueryString["StrValue"];
  151.         sModify = Request.QueryString["StrM"].ToString();
  152.         sEmpID = Request.QueryString["StrValue"].ToString();
  153.         iEmpID = Convert.ToInt32(sEmpID);
  154.         StrName = TxtName.Text;
  155.         StrEmail = TxtEmail.Text;
  156.         PhoneNum = TxtPNum.Text;
  157.         try
  158.         {
  159.             iType = Convert.ToInt32(DListType.SelectedValue.ToString());
  160.         }
  161.         catch
  162.         {
  163.             iType = 4;
  164.         }
  165.         //bFlag = EFly.HomonymyCheck(StrName);
  166.         //if (bFlag == false)
  167.         //{
  168.         ////    ImageButton1.Attributes.Add("onclick","javascript:return confirm('确定要删除此记录吗?');");
  169.         ////    //string strjavascript = "function ShowMessage() { if(confirm('您确定删除吗?')) return false;}";
  170.         ////    ////Page.ClientScript.RegisterStartupScript(this.GetType(), "onclick", strjavascript);
  171.         ////    //ClientScript.RegisterStartupScript(this.GetType(), "onclick", strjavascript, true);
  172.         ////    //if(confirm('您确定删除吗?')){}else {return false;}
  173.         ////    //javascript:return confirm('确定要删除此记录吗?');
  174.         //}
  175.         
  176.         if (CheckEmp.Checked)
  177.         {
  178.             iTmpFlag = 1;
  179.         }
  180.         else
  181.         {
  182.             iTmpFlag = 0;
  183.         }
  184.         int iPEmpID = -1;
  185.         try
  186.         {
  187.             iPEmpID = Convert.ToInt32(DLstParent.SelectedValue);
  188.         }
  189.         catch
  190.         {
  191.             iPEmpID = -1;
  192.         }
  193.         ArrayList al = new ArrayList();
  194.         foreach (ListItem Lst in this.ChList.Items)
  195.         {
  196.             if (Lst.Selected == true) al.Add(Lst.Value);
  197.         }
  198.         if (sModify == "M")
  199.         {
  200.             if (EFly.UpEmp(iEmpID, StrName, PhoneNum, StrEmail, iTmpFlag,iType,al,iPEmpID) == true)
  201.             {
  202.                 ClientScript.RegisterStartupScript(this.GetType(), "", "alert('系统提示:保存成功!');", true);
  203.             }
  204.             else
  205.             {
  206.                 ClientScript.RegisterStartupScript(this.GetType(), "", "alert('系统提示:保存失败!');", true);
  207.             }
  208.             
  209.         }
  210.         else
  211.         {
  212.             if (EFly.AddEmpData(StrName, sEmpID, StrEmail, PhoneNum, iTmpFlag,iType,al,iPEmpID) == true)
  213.             {
  214.                 ClientScript.RegisterStartupScript(this.GetType(), "", "alert('系统提示:保存成功!');", true);
  215.             }
  216.             else
  217.             {
  218.                 ClientScript.RegisterStartupScript(this.GetType(), "", "alert('系统提示:保存失败!');", true);
  219.             }
  220.             
  221.         }
  222.     }
  223. }