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

.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.                 DListType.Items.FindByValue(DLValue).Selected = true;
  90.                 TxtEmail.Text = dv.Table.Rows[0][4].ToString();
  91.                 TxtPNum.Text = dv.Table.Rows[0][5].ToString();
  92.                 if (dv.Table.Rows[0][7].ToString().Trim() == "1")
  93.                 {
  94.                     CheckEmp.Checked = true;
  95.                 }
  96.                 else
  97.                 {
  98.                     CheckEmp.Checked = false;
  99.                 }
  100.                 DLstParent.Items.FindByValue(DLstParent.SelectedValue).Selected=false;
  101.                 try
  102.                 {
  103.                     DLstParent.Items.FindByValue(dv.Table.Rows[0]["ParentEmp"].ToString()).Selected = true;
  104.                 }
  105.                 catch
  106.                 {
  107.                 }
  108.                 EFlyPrj.EmpID = iEmpID;
  109.                 try
  110.                 {
  111.                     dv = EFlyPrj.GetAssignOpRole();
  112.                     for (int i = 0; i < dv.Table.Rows.Count; i++)
  113.                     {
  114.                         for (int j = 0; j < ChList.Items.Count; j++)
  115.                         {
  116.                             if (ChList.Items[j].Value.ToString().Trim() == dv.Table.Rows[i]["OpID"].ToString().Trim())
  117.                             {
  118.                                 ChList.Items[j].Selected = true;
  119.                                 break;
  120.                             }
  121.                         }
  122.                     }
  123.                 }
  124.                 catch (Exception ex)
  125.                 {
  126.                     this.ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('" + ex.Message.Replace("'", "").Replace("rn", "").Replace("n", "") + "');</script>");
  127.                     return;
  128.                 }
  129.             }
  130.             //bool bFlag = true;
  131.             //bFlag = EFly.HomonymyCheck(TxtName.Text);
  132.             //if (bFlag == false)
  133.             //{
  134.             //    ImageButton1.Attributes.Add("onclick", "javascript:return confirm('确定要删除此记录吗?');");
  135.             //}
  136.         }
  137.     }
  138.     protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
  139.     {
  140.         string StrName, StrEmail, StrOrgID, PhoneNum;
  141.         int iTmpFlag =0,iType=4;
  142.         //bool bFlag= true;
  143.         EtongFlyChou EFly = new EtongFlyChou();
  144.         StrOrgID = Request.QueryString["StrValue"];
  145.         sModify = Request.QueryString["StrM"].ToString();
  146.         sEmpID = Request.QueryString["StrValue"].ToString();
  147.         iEmpID = Convert.ToInt32(sEmpID);
  148.         StrName = TxtName.Text;
  149.         StrEmail = TxtEmail.Text;
  150.         PhoneNum = TxtPNum.Text;
  151.         try
  152.         {
  153.             iType = Convert.ToInt32(DListType.SelectedValue.ToString());
  154.         }
  155.         catch
  156.         {
  157.             iType = 4;
  158.         }
  159.         //bFlag = EFly.HomonymyCheck(StrName);
  160.         //if (bFlag == false)
  161.         //{
  162.         ////    ImageButton1.Attributes.Add("onclick","javascript:return confirm('确定要删除此记录吗?');");
  163.         ////    //string strjavascript = "function ShowMessage() { if(confirm('您确定删除吗?')) return false;}";
  164.         ////    ////Page.ClientScript.RegisterStartupScript(this.GetType(), "onclick", strjavascript);
  165.         ////    //ClientScript.RegisterStartupScript(this.GetType(), "onclick", strjavascript, true);
  166.         ////    //if(confirm('您确定删除吗?')){}else {return false;}
  167.         ////    //javascript:return confirm('确定要删除此记录吗?');
  168.         //}
  169.         
  170.         if (CheckEmp.Checked)
  171.         {
  172.             iTmpFlag = 1;
  173.         }
  174.         else
  175.         {
  176.             iTmpFlag = 0;
  177.         }
  178.         int iPEmpID = -1;
  179.         try
  180.         {
  181.             iPEmpID = Convert.ToInt32(DLstParent.SelectedValue);
  182.         }
  183.         catch
  184.         {
  185.             iPEmpID = -1;
  186.         }
  187.         ArrayList al = new ArrayList();
  188.         foreach (ListItem Lst in this.ChList.Items)
  189.         {
  190.             if (Lst.Selected == true) al.Add(Lst.Value);
  191.         }
  192.         if (sModify == "M")
  193.         {
  194.             if (EFly.UpEmp(iEmpID, StrName, PhoneNum, StrEmail, iTmpFlag,iType,al,iPEmpID) == true)
  195.             {
  196.                 ClientScript.RegisterStartupScript(this.GetType(), "", "alert('系统提示:保存成功!');", true);
  197.             }
  198.             else
  199.             {
  200.                 ClientScript.RegisterStartupScript(this.GetType(), "", "alert('系统提示:保存失败!');", true);
  201.             }
  202.             
  203.         }
  204.         else
  205.         {
  206.             if (EFly.AddEmpData(StrName, sEmpID, StrEmail, PhoneNum, iTmpFlag,iType,al,iPEmpID) == true)
  207.             {
  208.                 ClientScript.RegisterStartupScript(this.GetType(), "", "alert('系统提示:保存成功!');", true);
  209.             }
  210.             else
  211.             {
  212.                 ClientScript.RegisterStartupScript(this.GetType(), "", "alert('系统提示:保存失败!');", true);
  213.             }
  214.             
  215.         }
  216.     }
  217. }