首页 > 其他 > 详细

关于telerik控件里radGrid显示数据的使用方法及技巧

时间:2014-03-28 11:12:42      阅读:742      评论:0      收藏:0      [点我收藏+]
bubuko.com,布布扣
<head id="Head1" runat="server">
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
    <title></title>
    <link href="../../css/style.css" rel="stylesheet" type="text/css" />
    <link href="../../Css/css.css" rel="stylesheet" />
     <script type="text/javascript" language="javascript" src="../../Share/zDialog.js"></script>
    <script type="text/javascript" language="javascript">
        IMAGESPATH = ../../Images/Alert/;
    </script>
    
    <script language="javascript" type="text/javascript">
        document.write(<iframe id=CalFrame name=CalFrame frameborder=0 src=../../Share/calendar.htm style=display:none;position:absolute;z-index:100></iframe>);
        </script>
    <script language="javascript" src="../../share/calendarnew.js" type="text/javascript"></script>
</head>
<body>
    <form id="form1" runat="server">
        <asp:ScriptManager ID="Manager" runat="server"></asp:ScriptManager>
        <asp:UpdatePanel ID="udp" runat="server"> 
        <ContentTemplate>
        <div class="xiangdan">              
            <div class="tittle_daohang"><span class="dh"><asp:Label ID="lab_Choubei" runat="server" Text="项目管理"></asp:Label>><font color="blue"><asp:Label ID="lbl_ProName" runat="server"></asp:Label></font>>资源管理&gt;人员设置</span></div> 
            <table id="tbl_Round" cellpadding="2" cellspacing="2" width="99%">
                <tr>
                    <td>
                        <uc1:ShowMessage ID="Msg" runat="server" Visible="false"></uc1:ShowMessage>
                    </td>
                </tr>
            </table> 
            <div class="tittle_btfenlan" style="width:99%;">进场登记</div>         
            <div class="table_liebiao"> 
                <telerik:RadGrid ID="dg_ProExprienceInfo" runat="server" AutoGenerateColumns="False" 
                    onneeddatasource="dg_ProExprienceInfo_NeedDataSource" GridLines="None" ShowStatusBar="true" 
                        onitemdatabound="dg_ProExprienceInfo_ItemDataBound"  PagerStyle-AlwaysVisible="true" AllowPaging="True"
                        onitemcommand="dg_ProExprienceInfo_ItemCommand" PageSize="5">
                    <HeaderStyle Font-Bold="true" HorizontalAlign="Center" />
                    <ItemStyle Height="30px" />
                    <PagerStyle Mode="NextPrevAndNumeric" AlwaysVisible="true" HorizontalAlign="Right"
                       ShowPagerText="false" />
                        <MasterTableView DataKeyNames="SYS_User_Id,SYS_User_Name,Hr_ProjExpr_StartDate,SYS_User_Other1,hr_ProjExpr_StartDate_Check,Hr_ProjExpr_PlanFinish">
                        <NoRecordsTemplate>
                                <div align="center" style="color: Red;">
                                    暂无角色人员信息</div>
                        </NoRecordsTemplate>  
                           <PagerTemplate>
                        <asp:Panel ID="PagerPanel" Style="padding: 6px; line-height: 24px" runat="server">
                            <div style="float: left">
                                <span style="margin-right: 3px;">每页记录数:</span>
                                <telerik:RadComboBox ID="rcmb_PageSize" DataSource="<%# new object[]{5,10, 20, 30, 40, 50} %>"
                                    Style="margin-right: 20px;" Width="40px" SelectedValue=<%# DataBinder.Eval(Container, "Paging.PageSize") %>
                                    runat="server" OnClientSelectedIndexChanged="rcmb_PageSize_SelectedIndexChanged">
                                </telerik:RadComboBox>
                            </div>
                            <div style="margin: 0px; float: right;">
                                总记录数:
                                <%# DataBinder.Eval(Container, "Paging.DataSourceCount")%>
                            </div>
                            <div style="margin: 0px; padding: 0px; float: left; margin-right: 10px; white-space: nowrap;">
                                <asp:ImageButton ID="img_Fist" runat="server" OnClientClick="changePage(‘first‘); return false;"
                                    CommandArgument="First" CommandName="Page" ImageUrl="~/images/first.gif" />
                                <asp:ImageButton ID="img_Prev" runat="server" OnClientClick="changePage(‘prev‘); return false;"
                                    CommandName="Page" CommandArgument="Prev" ImageUrl="~/images/prev.gif" />
                                <span style="vertical-align: middle;">选择页:</span>
                                <telerik:RadNumericTextBox ID="rntxt_Count" Width="25px" Value=<%# (int)DataBinder.Eval(Container, "Paging.CurrentPageIndex") + 1 %>
                                    runat="server">
                                    <ClientEvents OnValueChanged="rntxt_Count_ValueChanged" />
                                    <NumberFormat DecimalDigits="0" />
                                </telerik:RadNumericTextBox>
                                <span style="vertical-align: middle;">of
                                    <%# DataBinder.Eval(Container, "Paging.PageCount")%>
                                </span>
                                <asp:ImageButton ID="img_Next" runat="server" OnClientClick="changePage(‘next‘); return false;"
                                    CommandName="Page" CommandArgument="Next" ImageUrl="~/images/next.gif" />
                                <asp:ImageButton ID="img_Last" runat="server" OnClientClick="changePage(‘last‘); return false;"
                                    CommandName="Page" CommandArgument="Last" ImageUrl="~/images/last.gif" />
                            </div>
                        </asp:Panel>
                    </PagerTemplate>                 
                        <Columns>
                            <telerik:GridBoundColumn  DataField="SYS_User_Id" Visible="false">                                    
                            </telerik:GridBoundColumn>                                                         
                            <telerik:GridBoundColumn  DataField="SYS_User_Name"
                                HeaderText="人员">
                                <HeaderStyle Width="10%" CssClass="tit"/>
                            </telerik:GridBoundColumn>
                            <telerik:GridTemplateColumn HeaderText="进场日期">
                                <ItemTemplate> 
                                      <asp:TextBox id="txt_Start" runat="server"  Text=<%# DataBinder.Eval(Container, "DataItem.Hr_ProjExpr_StartDate") %> 
                                        Enabled=<%#DataBinder.Eval(Container, "DataItem.hr_ProjExpr_StartDate_Check").ToString()!="1"%>>
                                    </asp:TextBox>
                                    <asp:Label   id="IMG_StartDate" runat="server"  Text=<%# BindImg(Convert.ToInt32(DataBinder.Eval(Container, "DataItem.iIndex")),0) %>
                                            Visible=<%#DataBinder.Eval(Container, "DataItem.hr_ProjExpr_StartDate_Check").ToString()!="1"%>>
                                    </asp:Label>
                                </ItemTemplate>
                                <HeaderStyle Width="20%"  CssClass="tit"/>
                            </telerik:GridTemplateColumn>
                            <telerik:GridTemplateColumn HeaderText="计划离场日期">
                                <ItemTemplate> 
                                   <asp:TextBox id="txt_PlanFinish" runat="server" Text=<%# DataBinder.Eval(Container, "DataItem.Hr_ProjExpr_PlanFinish") %> 
                                        Enabled=<%#DataBinder.Eval(Container, "DataItem.hr_ProjExpr_StartDate_Check").ToString()!="1"%>>
                                    </asp:TextBox>
                                    <asp:Label   id="IMG_PlanFinish" runat="server"  Text=<%# BindImg(Convert.ToInt32(DataBinder.Eval(Container, "DataItem.iIndex")),1) %>
                                            Visible=<%#DataBinder.Eval(Container, "DataItem.hr_ProjExpr_StartDate_Check").ToString()!="1"%>>
                                    </asp:Label>
                                </ItemTemplate>
                                <HeaderStyle Width="20%"  CssClass="tit"/>
                            </telerik:GridTemplateColumn>                                            
                            <telerik:GridBoundColumn  DataField="Hr_ProjExpr_RoleName"
                                HeaderText="角色">
                                <HeaderStyle Width="30%" CssClass="tit"/>
                            </telerik:GridBoundColumn>
                            <telerik:GridTemplateColumn HeaderText="操作" ItemStyle-Width="7%">
                                <HeaderStyle Width="20%" CssClass="tit" />
                                <ItemTemplate>                                                                     
                                    <asp:LinkButton ID="lbtn_Edit" CommandName="Edit" runat="server" Text="设置角色"></asp:LinkButton>
                                    <asp:LinkButton ID="lbtn_Save" CommandName="Save" runat="server" Text="保存"></asp:LinkButton>  
                                    <asp:LinkButton ID="lbtn_Delete" CommandName="Delete" runat="server" Text="删除"></asp:LinkButton>                                       
                                </ItemTemplate>                                    
                            </telerik:GridTemplateColumn>
                        </Columns> 
                    </MasterTableView>                       
                </telerik:RadGrid>
       <telerik:RadScriptBlock ID="RadScriptBlock1" runat="server">
          <script type="text/javascript">
              var tableView = null;
              function pageLoad(sender, args) {
                  tableView = $find("<%= dg_ProExprienceInfo.ClientID %>").get_masterTableView();
              }

              function rcmb_PageSize_SelectedIndexChanged(sender, args) {
                  tableView.set_pageSize(sender.get_value());
              }

              function changePage(argument) {
                  tableView.page(argument);
              }

              function rntxt_Count_ValueChanged(sender, args) {
                  tableView.page(sender.get_value());
              } 
           </script>
    </telerik:RadScriptBlock>  
                <div style="text-align:center">                    
                    <asp:Button ID="btn_AllSubmit" runat="server" CssClass="blue" Text="批量保存" OnClick="btn_AllSubmit_Click" >
                    </asp:Button>
                </div>
                <table>
                    <tr>
                        <td class="tit" style="width:30%">
                            <asp:RadioButtonList ID="radlist_PeopleType" runat="server" RepeatDirection="Horizontal"
                                AutoPostBack="True"  onselectedindexchanged="radlist_PeopleType_SelectedIndexChanged">
                                <asp:ListItem Value="1" Selected="True">行内部门</asp:ListItem>
                                <asp:ListItem Value="2">合作公司</asp:ListItem>
                            </asp:RadioButtonList>
                        </td>
                        <td  class="tit" style="width:20%"><font face="宋体"></font></td>                    
                        <td  class="tit" align="center" style="width:30%">已有人员信息</td>
                    </tr>
                    <tr>
                        <td>                            
                            <telerik:RadComboBox ID="rcbox_dept" runat="server" Width="100%" AutoPostBack="true"
                                OnSelectedIndexChanged="rcbox_dept_SelectedIndexChanged">
                            </telerik:RadComboBox>
                            <br />
                            <asp:ListBox ID="list_AllPeople" runat="server" Width="100%" SelectionMode="Multiple"
                                Height="200px"></asp:ListBox>
                        </td>
                        <td align="center" style="text-align:center;width:20%">                        
                            <asp:Button ID="Button4" runat="server" Text="" ToolTip="添加选定人员" CssClass="btn_Right"
                                OnClick="Button4_Click"></asp:Button>
                            <br />
                            <br />                          
                            <asp:Button ID="Button5" runat="server" Text="" ToolTip="全部添加" CssClass="btn_AllRight"
                                OnClick="Button5_Click"></asp:Button>
                            <br />
                            <br />
                            <asp:Button ID="Button2" runat="server" Text="" ToolTip="删除选定人员" CssClass="btn_Left"
                                OnClick="Button2_Click"></asp:Button>
                            <br />
                            <br />
                            <asp:Button ID="Button3" runat="server" Text="" ToolTip="全部删除" CssClass="btn_AllLeft"
                                OnClick="Button3_Click"></asp:Button>
                        </td>
                        <td>
                            <br />
                            <asp:ListBox ID="list_Aready" runat="server" Width="100%" SelectionMode="Multiple"
                                Height="200px"></asp:ListBox>
                        </td>
                    </tr>                
                </table> 
                <div style="text-align:center">                    
                    <asp:Button ID="btn_Submit" runat="server" CssClass="blue" Text="保 存" OnClick="btn_Submit_Click">
                    </asp:Button>&nbsp;&nbsp;&nbsp;&nbsp;                           
                    <asp:Button ID="btn_Return" runat="server" CssClass="gray" Text="返 回" OnClick="btn_Return_Click">                       
                    </asp:Button>
                </div>
            </div> 
             <asp:ListBox ID="lst_DelUser" Style="z-index: 101; position: absolute; top: 584px;
            left: 424px" runat="server" Visible="False" SelectionMode="Multiple"></asp:ListBox>           
        </div>
        </ContentTemplate>
        </asp:UpdatePanel>
    </form>
</body>


public partial class Resource_Checkin : PTSPage
    {
        UserInfoFacade uif = new UserInfoFacade();
        ResourceFacade rsf = new ResourceFacade();
        ProjectFacade pfd = new ProjectFacade();
        RoleFacade role = new RoleFacade();
        HrFacade hrFd = new HrFacade();
        ProUserRoleFacade purFd = new ProUserRoleFacade();
        UserFacade ufd = new UserFacade();
        ProjectBLL proBLL = new ProjectBLL();
        ProjectGroupFacade pgfd = new ProjectGroupFacade();
        PropreBLL Proprebll = new PropreBLL();
        int RoleID;
        int iUserId;
        int iProId;
        bool Choubei = false;
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                iUserId = userInfo.Sys_User_Id;
                iProId = int.Parse(Session["ProjectID"].ToString());
                //RoleID = int.Parse(Request["RoleID"].ToString()); 
                int ProType = proBLL.GetProjectBasicType(iProId);
                if (ProType == 3)//是否为项目筹备
                { Choubei = true; }
            }
            catch (Exception ex)
            {
                SysLog sl = new SysLog();
                sl.WriteErrorLog("0", "Tasklist错误:", ex);
                throw (new Exception("SE10001:页面停留时间超时,请重新登录"));

            }
            Msg.Visible = false;
            if (!IsPostBack)
            {

                if (Choubei)
                {
                    lab_Choubei.Text = "项目筹备";
                }
                dg_ProExprienceInfo.Skin = RadControl_Skin; 
                this.initInputParameter();                
                if (Request["UpdateLeft"] != null)
                {
                    string url = "UserTree.aspx";
                    Response.Write("<script language=‘javascript‘>parent.frames(‘contents‘).location.href=‘" + url + "‘;</script>");
                }
                
                rcbox_dept.Skin = Constant.S_SKIN_VALUE;
                
                fillallPeople();
                FillUserByPeopleType("0");
            }
            lbl_ProName.Text = pfd.GetProjectName(iProId);
        }

        private void ShowMess(string strMess, bool bIsSuccess)
        {
            if (bIsSuccess)
            {
                Msg.Visible = true;
                Msg.Message = strMess;
                Msg.ShowSuccessMessage = bIsSuccess;
            }
            else
            {
                ScriptManager.RegisterStartupScript(this, typeof(UpdatePanel), "javascript", "Dialog.alert(‘" + strMess + "‘);", true);
                return;
            }
        }
        //在选择部门或者公司的时候加载所有人员显示在列表中
        private void FillUserByPeopleType(string PeopleType)
        {
            DataTable dt = rsf.GetUserListBySYSUserOther1(PeopleType);
            DataColumn dc = new DataColumn("username", typeof(string), "sys_user_name+‘(‘+sys_user_loginname+‘)‘");
            dt.Columns.Add(dc);
            DataTable dtMember = rsf.GetHrProInfoByProID(iProId);
            string strTemp = "";
            foreach (DataRow drMember in dtMember.Rows)
            {
                if (strTemp.Length > 0)
                {
                    strTemp = strTemp + ",";
                }
                strTemp = strTemp + drMember[0].ToString();
            }
            if (strTemp.Length > 0)
            {
                dt.DefaultView.RowFilter = dt.Columns[0].ColumnName + " Not In (" + strTemp + ")";
            }
            
            DataView dv = dt.DefaultView;
            dv.Sort = "username";
            list_AllPeople.DataSource = dv;
            list_AllPeople.DataTextField = "username";
            list_AllPeople.DataValueField = "Sys_User_Id";
            list_AllPeople.DataBind();

        }
        //无参数情况下页面加载时下拉列表内容默认为部门人员
        private void fillallPeople()
        {
            DeptFacade dfd = new DeptFacade();
            int isSubCount = 1;
            DataTable dt = dfd.CreateDeptTable(isSubCount);

            this.rcbox_dept.DataSource = dt;
            this.rcbox_dept.DataTextField = "sys_dept_name";
            this.rcbox_dept.DataValueField = "sys_dept_id";
            this.rcbox_dept.DataBind();
            this.rcbox_dept.Items.Insert(0, new RadComboBoxItem("", "0"));

            //根据所选人员类型绑定用户
            GetUser();
        }      
        //绑定所有人员列表
        private void InitControls()
        {
            UserFacade userClass = new UserFacade();
            DataTable dtUser = userClass.GetProRoleUser(iProId, Constant.STR_ACTIVE);           
            this.FillAllPeopleList();
           
        }     
        private void FillAllPeopleList()
        {
            DeptFacade dfd = new DeptFacade();
            int isSubCount =int.Parse( radlist_PeopleType.SelectedValue.ToString());
            DataTable dt = dfd.CreateDeptTable(isSubCount);

            this.rcbox_dept.DataSource = dt;
            this.rcbox_dept.DataTextField = "sys_dept_name";
            this.rcbox_dept.DataValueField = "sys_dept_id";
            this.rcbox_dept.DataBind();
            this.rcbox_dept.Items.Insert(0, new RadComboBoxItem("", "0"));

            //根据所选人员类型绑定用户
            GetUser();
        }
        #region   初始化从别的页面传入的参数
        public static string strProjectID = "1";
        public static string strRoleID = "2";
        private void initInputParameter()
        {
            try
            {
                ViewState["strProjectID"] = iProId.ToString();
              
            }
            catch
            {
                throw new Exception("UI20001:传入页面的参数不符合要求");
            }

        }
        #endregion     

        private void GetUser()
        {
            UserFacade ufd = new UserFacade();
            DataTable dt = new DataTable();
            if (this.rcbox_dept.SelectedIndex > 0)
            {
                dt = ufd.GetUserListByDeptId(int.Parse(this.rcbox_dept.SelectedValue)).Tables[0];
                DataColumn dc = new DataColumn("username", typeof(string), "sys_user_name+‘(‘+sys_user_loginname+‘)‘");
                dt.Columns.Add(dc);
                FillList(this.list_AllPeople, dt);
            }
        }
        private void FillList(ListBox target, DataTable dtUser)
        {
            target.Items.Clear();
            DataTable dtMember = rsf.GetHrProInfoByProID(iProId);
            string strTemp = "";
            foreach (DataRow drMember in dtMember.Rows)
            {
                if (strTemp.Length > 0)
                {
                    strTemp = strTemp + ",";
                }
                strTemp = strTemp + drMember[0].ToString();
            }
            if (strTemp.Length > 0)
            {
                dtUser.DefaultView.RowFilter = dtUser.Columns[0].ColumnName + " Not In (" + strTemp + ")";
            }
            DataView dv = dtUser.DefaultView;
            dv.Sort = "username";
            target.DataSource = dv;
            target.DataTextField = "username";
            target.DataValueField = "Sys_User_Id";
            target.DataBind();
        }
        
        protected void Button4_Click(object sender, EventArgs e)
        {
            foreach (ListItem li in list_AllPeople.Items)
            {
                if (li.Selected)
                {
                    bool found = false;
                    foreach (ListItem i in list_Aready.Items)
                    {
                        if (i.Value == li.Value)
                        {
                            found = true;
                            break;
                        }
                    }
                    if (!found)
                    {
                        list_Aready.Items.Add(li);
                    }
                }
            }
        }

        protected void Button5_Click(object sender, EventArgs e)
        {
            for (int i = 0; i < list_AllPeople.Items.Count; i++)
            {
                if (!list_Aready.Items.Contains(list_AllPeople.Items[i]))
                {
                    list_Aready.Items.Add(list_AllPeople.Items[i]);

                }

            }
        }

        protected void Button3_Click(object sender, EventArgs e)
        {
            list_Aready.Items.Clear();
        }

        protected void Button2_Click(object sender, EventArgs e)
        {
            if (list_Aready.SelectedItem != null)
            {
                for (int i = list_Aready.Items.Count - 1; i >= 0; i--)
                {
                    if (list_Aready.Items[i].Selected)
                    {
                        lst_DelUser.Items.Add(list_Aready.Items[i]);
                        list_Aready.Items.Remove(list_Aready.Items[i]);
                    }

                }
            }
        }

        protected void btn_Return_Click(object sender, EventArgs e)
        {
             
             if (Request["Page"] != null)
                 Response.Redirect("Resource_List.aspx?Page=" + Request["Page"].ToString() + "&Back=t");
             else
                 Response.Redirect("Resource_List.aspx?Page=0&Back=t");          
        }

        protected void btn_Submit_Click(object sender, EventArgs e)
        {
           
            ArrayList UserArray = new ArrayList();
            if (this.list_Aready.Items.Count == 0)
            {

                ShowMess(" 请至少添加一个人员", false); return;
            }
            //保存人员
            string strMess = "";
            foreach (ListItem item in list_Aready.Items)
            {
                UserArray.Add(item.Value);
            }            
            //这里将用户信息添加进项目历史信息表中
            for (int i = 0; i < UserArray.Count; i++)
            {
                if (Choubei)
                {
                    purFd.EditProUserRole(int.Parse(UserArray[i].ToString()), iProId, 102, 0, 1);//这里将用户信息保存到项目筹备用户角色信息表中,新添加人员默认角色ID=102
                }
                else
                {
                    purFd.EditProUserRole(int.Parse(UserArray[i].ToString()), iProId, 2, 0, 1); //这里将用户信息保存到项目用户角色信息表中,新添加人员默认角色ID=2
                }
                if (rsf.Hr_ProjExperience_InfoIsExist(UserArray[i].ToString(),iProId.ToString()))//判断若有原始数据,则将该数据离场日期清空,否则插入新数据
                {
                    int SYS_User_Id = Convert.ToInt32(UserArray[i].ToString());
                    DataTable dt= rsf.GetHr_Pro_InfoByID(SYS_User_Id,iProId);
                    if (dt.Rows[0]["Hr_ProjExpr_FinishDate"].ToString() != "")
                    {
                        ShowMess("进场人员里面有已经离场人员,请确认后在保存!", false); return;
                    }
                    else
                    {
                        int Expr_Id = int.Parse(dt.Rows[0]["Hr_ProjExpr_Id"].ToString());
                        //string strStartDate = dt.Rows[0]["Hr_ProjExpr_StartDate"].ToString();
                        //string strFinishDate = "";
                        //string strProjectName = dt.Rows[0]["Hr_ProjExpr_ProjectName"].ToString();
                        //string strProjectDes = dt.Rows[0]["Hr_ProjExpr_ProjectDes"].ToString();
                        //string strRoleName = dt.Rows[0]["Hr_ProjExpr_RoleName"].ToString();
                        ////更新项目里是数据
                        //hrFd.UpdateExpInfo(Expr_Id, strStartDate, strFinishDate, strProjectName, strProjectDes, strRoleName, iProId);
                        rsf.UpdateHRExpInfo(Expr_Id);
                        purFd.EditProUserRole(int.Parse(UserArray[i].ToString()), iProId, -1, 0, 10);
                        string strStartDate = System.DateTime.Now.ToString("yyyy-MM-dd");
                        int User_Id = Convert.ToInt32(UserArray[i].ToString());
                        uif.SaveUserOtherInfo(User_Id, 1, strStartDate, "");//更新用户入组日期和新一代状态
                    }
                    
                }
                else
                {
                    
                    string strStartDate = System.DateTime.Now.ToString("yyyy-MM-dd");
                    string strFinishDate = "";
                    string strPlanFinish = System.DateTime.Now.ToString("yyyy-MM-dd");
                    string strProjectName = rsf.GetProjectNameByProId(iProId);
                    string strProjectDes = "";
                    int User_Id = Convert.ToInt32(UserArray[i].ToString());
                    int ProId = iProId;
                    string strRoleName = "2";
                    //新增项目历史信息
                    hrFd.AddExpInfo(strStartDate, strFinishDate, strProjectName, strProjectDes, User_Id, ProId, strRoleName, iProId, strPlanFinish);
                    uif.SaveUserOtherInfo(User_Id, 1, strStartDate, "");//更新用户入组日期和新一代状态
                }
            }
            LogFacade cls_Log = new LogFacade();
            int iModId = Constant.I_PLAN_RESOURCE_MOD_ID;
            string strReCode = cls_Log.AddLog(iModId, 0, 0, 0, iProId, 0, iUserId, "");
            if (strReCode != "0")
            {
                strReCode = strReCode.Replace("\r\n", "<br>");
                Response.Redirect("~/Err.aspx?strErr=" + strReCode);
            }

            if (strMess != "")
            {
                Msg.Message = strMess;
                return;
            }
            
            ShowMess("保存成功!", true);
            list_Aready.Items.Clear();
            dg_ProExprienceInfo.Rebind();
        }

        protected void rcbox_dept_SelectedIndexChanged(object o, RadComboBoxSelectedIndexChangedEventArgs e)
        {
            GetUser();
        }

        protected void radlist_PeopleType_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (radlist_PeopleType.SelectedValue == "1")
            {
                InitControls();
                FillUserByPeopleType("0");
            }
            else if (radlist_PeopleType.SelectedValue == "2")
            {
                InitControls();
                FillUserByPeopleType("1");
            }
        }

        protected void dg_ProExprienceInfo_ItemCommand(object source, GridCommandEventArgs e)
        {
            if (e.CommandName == "Save")
            {
                string strErrorMessage = string.Empty;
                string strUserId = dg_ProExprienceInfo.MasterTableView.DataKeyValues[e.Item.ItemIndex]["SYS_User_Id"].ToString();

                TextBox indate = (TextBox)e.Item.FindControl("txt_Start");
                TextBox palnfinishdate = (TextBox)e.Item.FindControl("txt_PlanFinish");
                string strInDate = indate.Text;
                string strPlanFinishDate = palnfinishdate.Text;

                LinkButton SaveInfo = (LinkButton)e.Item.FindControl("lbtn_Save");

                //这里添加进场日期判断,提示“请输入有效日期,并且在项目日期范围内!”
                try
                {
                    ProjectBaseInfo dtpro = proBLL.GetProBaseInfoById(iProId);
                    string CreateTime = dtpro.CreatedTime.ToString().Equals(string.Empty) ? "" : Convert.ToDateTime(dtpro.CreatedTime).ToString("yyyy-MM-dd");
                    DateTime create=Convert.ToDateTime(CreateTime);
                    DateTime indateTime = Convert.ToDateTime(strInDate);
                    if (string.IsNullOrEmpty(strPlanFinishDate))
                    {
                        ShowMess("计划离场日期不能为空!", false); return;
                    }
                    DateTime planfinish = Convert.ToDateTime(strPlanFinishDate);
                    if (indateTime < create)
                    {

                        ShowMess("进场日期不能早于项目创建日期!", false); return;
                    }
                    if (planfinish < indateTime)
                    {
                        ShowMess("计划离场日期不能早于进场日期!", false); return;
                    }

                }
                catch
                {
                    
                    //防止获取时间格式错误
                }
                try
                {
                    DataTable dtHrEx = rsf.GetHr_Pro_InfoByID(int.Parse(strUserId), iProId);
                    int Expr_Id = int.Parse(dtHrEx.Rows[0]["Hr_ProjExpr_Id"].ToString());
                    string strStartDate = strInDate;
                    string strFinishDate = dtHrEx.Rows[0]["Hr_ProjExpr_FinishDate"].ToString();
                    string strProjectName = dtHrEx.Rows[0]["Hr_ProjExpr_ProjectName"].ToString();
                    string strProjectDes = dtHrEx.Rows[0]["Hr_ProjExpr_ProjectDes"].ToString();
                    string strRoleName = dtHrEx.Rows[0]["Hr_ProjExpr_RoleName"].ToString();
                    string strPlanFinish = strPlanFinishDate;
                    //更新项目里是数据
                    hrFd.UpdateExpInfo(Expr_Id, strStartDate, strFinishDate, strProjectName, int.Parse(strUserId), strProjectDes, strRoleName, iProId, strPlanFinish);
                    indate.Enabled = false;
                    SaveInfo.Enabled = false;
                    palnfinishdate.Enabled = false;
                    ShowMess("修改成功", true);                    

                }
                catch (Exception ex)
                {
                    ShowMess("修改历史项目信息失败,失败原因为:" + ex.Message, false);
                  
                }
            }
            if (e.CommandName == "Edit")
            {
                string userID = dg_ProExprienceInfo.MasterTableView.DataKeyValues[e.Item.ItemIndex]["SYS_User_Id"].ToString();
                Response.Redirect("../../PMP/Resource/Resource_UserRole.aspx?UserId=" + userID);

            }
            if (e.CommandName == "Delete")
            {
                string userID = dg_ProExprienceInfo.MasterTableView.DataKeyValues[e.Item.ItemIndex]["SYS_User_Id"].ToString();
                DataTable dtGroup = pgfd.GetProGroup(iProId.ToString()).Tables[0];
                DataRow[] dtGroupRow = dtGroup.Select("PMP_ProGroup_Leader=" + userID);
                if (uif.UserIsHaveTask(userID, iProId.ToString()))
                {
                    ShowMess("该人员在该项目内有已分配任务,不能做删除操作,只允许做离场操作!", false); return;
                }
                if (dtGroupRow.Length > 0)
                {

                    ShowMess("当前选定人员为项目小组长,不能删除!", false);
                    return;
                }
                try
                {
                    DataTable dt = rsf.GetRoleInfoByUserId(int.Parse(userID), iProId);
                    if (dt.Rows.Count > 0)
                    {
                        string HrProExId = dt.Rows[0]["Hr_ProjExpr_Id"].ToString();
                        hrFd.DelExpInfo(int.Parse(HrProExId));                        

                    }
                    //如果存在多个角色,循环处理
                    DataTable dtuserRole = rsf.GetRoleInfoByUserId(int.Parse(userID), iProId);
                    if (dtuserRole.Rows.Count > 0)
                    {
                        for (int i = 0; i < dtuserRole.Rows.Count; i++)
                        {
                            string RoleId = dt.Rows[i]["SYS_Role_Id"].ToString();
                            purFd.EditProUserRole(int.Parse(userID), iProId, int.Parse(RoleId), 0, 8);
                        }
                    }
                    ShowMess("删除成功", true);
                    dg_ProExprienceInfo.Rebind();
                }
                catch (Exception ex)
                {
                    ShowMess("修改历史项目信息失败,失败原因为:" + ex.Message, false);

                }
            }
        }

        protected void dg_ProExprienceInfo_NeedDataSource(object source, GridNeedDataSourceEventArgs e)
        {
            try
            {                
                DataTable dt = rsf.GetHrProInfoByProID(iProId,"");//获取离场日期为空的人员列表
                dt.Columns.Add("iIndex", typeof(int));
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    dt.Rows[i]["iIndex"] = i;
                }  
                dg_ProExprienceInfo.DataSource = dt;               
            }
            catch
            {
            }

        }

        protected void dg_ProExprienceInfo_ItemDataBound(object sender, GridItemEventArgs e)
        {
            if (e.Item.ItemType == GridItemType.Item || e.Item.ItemType == GridItemType.AlternatingItem)
            {
                LinkButton lbtn_Edit = e.Item.FindControl("lbtn_Edit") as LinkButton;
                LinkButton lbtn_Save = e.Item.FindControl("lbtn_Save") as LinkButton;
                string userID = dg_ProExprienceInfo.MasterTableView.DataKeyValues[e.Item.ItemIndex]["SYS_User_Id"].ToString();
                string other1 = dg_ProExprienceInfo.MasterTableView.DataKeyValues[e.Item.ItemIndex]["SYS_User_Other1"].ToString();//获取人员公司行内标示
                if (other1 != "0")//行外人员
                {
                    lbtn_Edit.Enabled = false;
                }
                string StartDate_Check = dg_ProExprienceInfo.MasterTableView.DataKeyValues[e.Item.ItemIndex]["hr_ProjExpr_StartDate_Check"].ToString();
                if (StartDate_Check == "1")
                {
                    lbtn_Save.Enabled = false;
                }
            }
        }

        #region 绑定日历控件
        /// <summary>
        /// 绑定日历控件
        /// </summary>
        /// <param name="iDataSetIdx"></param>
        /// <param name="iflag">0为开始日期,1为结束日期</param>
        /// <returns></returns>
        public string BindImg(int iDataSetIdx, int iflag)
        {
            iDataSetIdx = iDataSetIdx - dg_ProExprienceInfo.CurrentPageIndex * dg_ProExprienceInfo.PageSize;
            iDataSetIdx = (iDataSetIdx + 1) * 2 + 2;
            string strHref;
            string strIdx = iDataSetIdx < 10 ? "0" + iDataSetIdx.ToString() : iDataSetIdx.ToString();
            if (iflag == 0)
            {
                string strCtrlName = "dg_ProExprienceInfo_ctl00_ctl" + strIdx + "_txt_Start";
                string strImgName = "dg_ProExprienceInfo_ctl00_ctl" + strIdx + "_IMG_StartDate";
                strHref = "<A  onmouseover=\"window.status=‘Calendar‘;return true;\" onmouseout=\"window.status=‘‘;\"" +
                    "href=\"javascript:showCalendar(‘" + strImgName + "‘,false,‘" + strCtrlName + "‘,‘‘,‘‘,‘2008-12-01‘,‘2010-12-30‘,‘‘,‘‘,‘‘)\"" +
                    " target=\"_self\"><IMG  id=\"IMG_StartDate\" src=\"../../Images/imgbtn_Date.jpg\" align=\"absMiddle\" border=\"0\"></A>";
            }
            else
            {
                string strCtrlName = "dg_ProExprienceInfo_ctl00_ctl" + strIdx + "_txt_PlanFinish";
                string strImgName ="dg_ProExprienceInfo_ctl00_ctl" + strIdx + "_IMG_PlanFinish";
                strHref = "<A onmouseover=\"window.status=‘Calendar‘;return true;\" onmouseout=\"window.status=‘‘;\"" +
                    "href=\"javascript:showCalendar(‘" + strImgName + "‘,false,‘" + strCtrlName + "‘,‘‘,‘‘,‘2008-12-01‘,‘2010-12-30‘,‘‘,‘‘,‘‘)\"" +
                    " target=\"_self\"><IMG  id=\"IMG_FinishDate\" src=\"../../Images/imgbtn_Date.jpg\" align=\"absMiddle\" border=\"0\"></A>";
            }
            return strHref;

        }
        #endregion

        protected void btn_AllSubmit_Click(object sender, EventArgs e)
        {
            var items = dg_ProExprienceInfo.Items;
            string CreateTime = "";
            if (Choubei)
            {
                DataTable dtPropre = Proprebll.GetProjectPrepareInfo_ByID(iProId);
                CreateTime = dtPropre.Rows[0]["CreateTime"].ToString().Equals(string.Empty) ? "" : Convert.ToDateTime(dtPropre.Rows[0]["CreateTime"].ToString()).ToString("yyyy-MM-dd");
            }
            else
            {
                ProjectBaseInfo dtpro = proBLL.GetProBaseInfoById(iProId);
                CreateTime = dtpro.CreatedTime.ToString().Equals(string.Empty) ? "" : Convert.ToDateTime(dtpro.CreatedTime).ToString("yyyy-MM-dd");
            }
            DateTime create = Convert.ToDateTime(CreateTime);
            string strReturnVal = "无有效进场和计划离场日期,保存失败!";
            for (int i = 0; i < items.Count; i++)
            {
                TextBox PlanLeaveDate = (TextBox)items[i].FindControl("txt_PlanFinish");
                TextBox InDate = (TextBox)items[i].FindControl("txt_Start");

                LinkButton SaveInfo = (LinkButton)items[i].FindControl("lbtn_Save");                
                string strUserId = dg_ProExprienceInfo.MasterTableView.DataKeyValues[i]["SYS_User_Id"].ToString();                
                if (!string.IsNullOrEmpty(InDate.Text) && !string.IsNullOrEmpty(PlanLeaveDate.Text) && PlanLeaveDate.Enabled == true)
                {
                    var strInDate = System.DateTime.Now;
                    var strPlanLeaveDate = System.DateTime.Now;
                    try
                    {
                        strInDate = DateTime.Parse(InDate.Text);
                        strPlanLeaveDate = DateTime.Parse(PlanLeaveDate.Text);
                        if (strInDate < create)
                        {

                            ShowMess("进场日期不能早于项目创建日期!", false); return;
                        }
                        if (strPlanLeaveDate < strInDate)
                        {
                            ShowMess("计划离场日期不能早于进场日期!", false); return;

                        }
                    }
                    catch
                    {/*防止时间出错*/ }

                    try
                    {
                        string strStartDate = strInDate.ToString("yyyy-MM-dd");
                        string strPlanFinish = strPlanLeaveDate.ToString("yyyy-MM-dd");
                        //更新项目里是数据
                        hrFd.UpdateExpInfo(strStartDate, int.Parse(strUserId), iProId, strPlanFinish);
                        strReturnVal = "批量保存成功!";
                    }
                    catch (Exception ex)
                    {
                        ShowMess("保存历史项目信息失败,失败原因为:" + ex.Message, false);
                    }
                }
            }
            dg_ProExprienceInfo.Rebind();
            ShowMess(strReturnVal, true);
        }
      
    }
}
bubuko.com,布布扣

本实例带有时间编辑框和操作按钮

关于telerik控件里radGrid显示数据的使用方法及技巧,布布扣,bubuko.com

关于telerik控件里radGrid显示数据的使用方法及技巧

原文:http://www.cnblogs.com/jeforser/p/3628760.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!