protected void btnSave_Click(object sender, EventArgs e)
 {
     string alert = "";
     model = PageHelper.GetModel<TWCadreModel>(pnlContent.Controls);
     if (this.ProcessFlag.Value == "Add")
     {
         DataTable dt = tWCadreBll.GetTWCafreByKey(model);
         if (dt.Rows.Count > 0)
         {
             alert = "alert('" + Message.NotOnlyOne + "')";
         }
         logmodel.ProcessFlag = "insert";
         model.CreateUser = base.CurrentUserInfo.Personcode;
         model.CreateDate = System.DateTime.Now;
         bool flag = tWCadreBll.AddTWCdare(model, logmodel);
         if (flag == true)
         {
             alert = "alert('" + Message.AddSuccess + "')";
         }
         else
         {
             alert = "alert('" + Message.AddFailed + "')";
         }
         PageHelper.CleanControlsValue(pnlContent.Controls);
     }
     if (this.ProcessFlag.Value == "Modify")
     {
         logmodel.ProcessFlag = "update";
         model.UpdateDate = System.DateTime.Now;
         model.UpdateUser = base.CurrentUserInfo.Personcode;
         bool flag = tWCadreBll.UpdateTWCdareByKey(model, logmodel);
         if (flag == true)
         {
             alert = "alert('" + Message.UpdateSuccess + "')";
         }
         else
         {
             alert = "alert('" + Message.UpdateFailed + "')";
         }
     }
     ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "save", alert, true);
 }
        /// <summary>
        /// 輸出
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnExport_Click(object sender, EventArgs e)
        {
            if (this.ImportFlag.Value == "Import")
            {
                if (dt_global.Rows.Count == 0)
                {
                    ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "nodataexport", "alert('" + Message.NoDataExport + "');", true);
                }
                else
                {
                    List<TWCadreModel> list = tWCadreBll.GetList(dt_global);
                    string[] header = { ControlText.gvWorkNo, ControlText.gvHeadLocalName, ControlText.gvSex, ControlText.gvIdentityNo, ControlText.gvByName, ControlText.gvLevel, ControlText.gvManager, ControlText.gvHeadDepCode, ControlText.gvExtension, ControlText.gvHeadNotes, ControlText.gvJoinDate, ControlText.gvStatus, ControlText.gvLeaveDate, ControlText.gvCardNo, ControlText.gvIsKaoQin };
                    string[] properties = { "WorkNo", "LocalName", "Sex", "IdentityNo", "ByName", "LevelName", "ManagerName", "DepName", "Extension", "Notes", "JoinDate", "Status", "LeaveDate", "CardNo", "IsKaoQin" };
                    string filePath = MapPath("~/ExportFileTemp/") + DateTime.Now.Ticks + ".xls";
                    NPOIHelper.ExportExcel(list, header, properties, 5000, filePath);
                    PageHelper.ReturnHTTPStream(filePath, true);
                }
            }
            else
            {
                string LevelCondition = "";
                string ManagerCondition = "";
                string StatusCondition = "";
                string sql = SqlDep;
                model = PageHelper.GetModel<TWCadreModel>(pnlContent.Controls);
                if (!string.IsNullOrEmpty(this.DropDownCheckListLevelCode.SelectedValue.ToString()))
                {

                    string[] temVal = DropDownCheckListLevelCode.SelectedValuesToString(",").Split(',');
                    for (int iLoop = 0; iLoop < temVal.Length; iLoop++)
                    {
                        LevelCondition += "'" + temVal[iLoop] + "',";
                    }
                    LevelCondition = LevelCondition.Substring(0, LevelCondition.Length - 1);

                }
                if (!string.IsNullOrEmpty(this.DropDownCheckListManager.SelectedValue.ToString()))
                {
                    string[] temVal = DropDownCheckListManager.SelectedValuesToString(",").Split(',');
                    for (int iLoop = 0; iLoop < temVal.Length; iLoop++)
                    {
                        ManagerCondition += "'" + temVal[iLoop] + "',";
                    }
                    ManagerCondition = ManagerCondition.Substring(0, ManagerCondition.Length - 1);
                }
                if (!string.IsNullOrEmpty(this.DropDownCheckListStatus.SelectedValue.ToString()))
                {
                    string[] temVal = DropDownCheckListStatus.SelectedValuesToString(",").Split(',');
                    for (int iLoop = 0; iLoop < temVal.Length; iLoop++)
                    {
                        StatusCondition += "'" + temVal[iLoop] + "',";
                    }
                    StatusCondition = StatusCondition.Substring(0, StatusCondition.Length - 1);
                }
                string JoinDateFrom = this.txtJoinDateFrom.Text.Trim();
                string JoinDateTo = this.txtJoinDateTo.Text.Trim();
                string LeaveDateFrom = this.txtLeaveDateFrom.Text.Trim();
                string LeaveDateTo = this.txtLeaveDateTo.Text.Trim();
                DataTable newdt = tWCadreBll.GetTWCadreForExport(model, sql, LevelCondition, ManagerCondition, StatusCondition, JoinDateFrom, JoinDateTo, LeaveDateFrom, LeaveDateTo);
                if (newdt.Rows.Count == 0)
                {
                    ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "nodataexport", "alert('" + Message.NoDataExport + "');", true);
                }
                else
                {
                    List<TWCadreModel> list = tWCadreBll.GetList(newdt);
                    string[] header = { ControlText.gvOrgName, ControlText.gvWorkNo, ControlText.gvHeadLocalName, ControlText.gvSex, ControlText.gvIdentityNo, ControlText.gvByName, ControlText.gvLevel, ControlText.gvManager, ControlText.gvExtension, ControlText.gvHeadNotes, ControlText.gvJoinDate, ControlText.gvLeaveDate, ControlText.gvStatus, ControlText.gvCardNo, ControlText.gvIsKaoQin, ControlText.gvModifier, ControlText.gvModifyDate };
                    string[] properties = { "DepName", "WorkNo", "LocalName", "SexName", "IdentityNo", "ByName", "LevelName", "ManagerName", "Extension", "Notes", "JoinDate", "LeaveDate", "StatusName", "CardNo", "IsKaoQin", "UpdateUser", "UpdateDate" };
                    string filePath = MapPath("~/ExportFileTemp/") + DateTime.Now.Ticks + ".xls";
                    NPOIHelper.ExportExcel(list, header, properties, 5000, filePath);
                    PageHelper.ReturnHTTPStream(filePath, true);
                }
            }
        }
        protected void GridDataBind()
        {
            int totalCount;
            string LevelCondition = "";
            string ManagerCondition = "";
            string StatusCondition = "";
            string sql = SqlDep;
            model = PageHelper.GetModel<TWCadreModel>(pnlContent.Controls);
            if (!string.IsNullOrEmpty(this.DropDownCheckListLevelCode.SelectedValue.ToString()))
            {

                string[] temVal = DropDownCheckListLevelCode.SelectedValuesToString(",").Split(',');
                for (int iLoop = 0; iLoop < temVal.Length; iLoop++)
                {
                    LevelCondition += "'" + temVal[iLoop] + "',";
                }
                LevelCondition = LevelCondition.Substring(0, LevelCondition.Length - 1);

            }
            if (!string.IsNullOrEmpty(this.DropDownCheckListManager.SelectedValue.ToString()))
            {
                string[] temVal = DropDownCheckListManager.SelectedValuesToString(",").Split(',');
                for (int iLoop = 0; iLoop < temVal.Length; iLoop++)
                {
                    ManagerCondition += "'" + temVal[iLoop] + "',";
                }
                ManagerCondition = ManagerCondition.Substring(0, ManagerCondition.Length - 1);
            }
            if (!string.IsNullOrEmpty(this.DropDownCheckListStatus.SelectedValue.ToString()))
            {
                string[] temVal = DropDownCheckListStatus.SelectedValuesToString(",").Split(',');
                for (int iLoop = 0; iLoop < temVal.Length; iLoop++)
                {
                    StatusCondition += "'" + temVal[iLoop] + "',";
                }
                StatusCondition = StatusCondition.Substring(0, StatusCondition.Length - 1);
            }
            string JoinDateFrom = this.txtJoinDateFrom.Text.Trim();
            string JoinDateTo = this.txtJoinDateTo.Text.Trim();
            string LeaveDateFrom = this.txtLeaveDateFrom.Text.Trim();
            string LeaveDateTo = this.txtLeaveDateTo.Text.Trim();
            DataTable dt = tWCadreBll.GetTWCadrePageInfo(model, sql, LevelCondition, ManagerCondition, StatusCondition, JoinDateFrom, JoinDateTo, LeaveDateFrom, LeaveDateTo, pager.CurrentPageIndex, pager.PageSize, out totalCount);
            pager.RecordCount = totalCount;
            this.UltraWebGrid.DataSource = dt.DefaultView;
            this.UltraWebGrid.DataBind();
            pager.TextAfterPageIndexBox = "/" + pager.PageCount.ToString();
        }