using BLL; using System; using System.Collections.Generic; using System.Data; using System.Data.SqlClient; using System.Linq; namespace FineUIPro.Web.ManHours { public partial class ManHours : PageBase { #region 加载 protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { GetButtonPower();//权限设置 //项目类型 this.drpJobType.DataTextField = "ConstText"; this.drpJobType.DataValueField = "ConstValue"; this.drpJobType.DataSource = BLL.ConstService.GetConstListByGroupId(BLL.Const.ProjectPlanner_JobType); this.drpJobType.DataBind(); Funs.FineUIPleaseSelectJobType(this.drpJobType); //项目状态 this.drpJobStatus.DataTextField = "ConstText"; this.drpJobStatus.DataValueField = "ConstValue"; this.drpJobStatus.DataSource = BLL.ConstService.GetConstListByGroupId(BLL.Const.ProjectPlanner_JobStatus); this.drpJobStatus.DataBind(); Funs.FineUIPleaseSelectJobStatus(this.drpJobStatus); BindDeptTree(""); if (this.CurrUser.Account != BLL.Const.Gly && CurrUser.RoleId != BLL.Const.Role_PPE && CurrUser.DepartId != BLL.Const.CTEM_DepartId) { txtUserName.Hidden = true; this.tvUser.SelectedNodeID = "U@" + this.CurrUser.UserId; hidpersonnel.Text = this.tvUser.SelectedNodeID; BindGrid(hidpersonnel.Text); } else { BindGrid(""); } //右键的add和delete默认授权给PPE及CTE/M组 var user = BLL.Sys_UserService.GetUsersByUserId(this.CurrUser.UserId); if (user.RoleId == BLL.Const.Role_PPE || user.DepartId == BLL.Const.CTEM_DepartId || this.CurrUser.UserId == BLL.Const.GlyId) { this.MenuAdd.Hidden = false; this.btnMenuDel.Hidden = false; this.Grid1.EnableRowDoubleClickEvent = true; } else { this.MenuAdd.Hidden = true; this.btnMenuDel.Hidden = true; this.Grid1.EnableRowDoubleClickEvent = false; } } } #endregion #region 查询 protected void TextBox_TextChanged(object sender, EventArgs e) { string UserName = txtUserName.Text; BindDeptTree(UserName); } protected void rblAutoPostBack_SelectedIndexChanged(object sender, EventArgs e) { BindGrid(hidpersonnel.Text); //ShowNotify("选中项的值:" + rblAutoPostBack.SelectedValue); } #endregion #region 绑定数据 private void BindGrid(string sId) { string JobNo = ""; string JobType = ""; string JobStatus = ""; int Status = 1; int Layer = 0; string udsId = ""; if (this.drpJobType.SelectedValue != BLL.Const._Null) { JobType = this.drpJobType.SelectedValue; } if (this.drpJobStatus.SelectedValue != BLL.Const._Null && this.drpJobStatus.SelectedValue != null) { JobStatus = this.drpJobStatus.SelectedValue; } if (!string.IsNullOrEmpty(this.txtJobNo.Text.Trim())) { JobNo = this.txtJobNo.Text.Trim(); } Status = int.Parse(rblAutoPostBack.SelectedValue); string[] sIdArr = sId.Split('@'); if (sIdArr[0].ToString() == "U") { Layer = 1; udsId = sIdArr[1].ToString(); } if (sIdArr[0].ToString() == "D") { Layer = 2; //if (sIdArr[1].ToString() != Const.CTE_DepartId) //{ udsId = sIdArr[1].ToString(); //} //else //{ // udsId = ""; //} } string ids = ""; string d = CurrUser.DepartId; // 获取当前用户部门ID string r = CurrUser.RoleId; // 获取当前用户角色ID if (this.CurrUser.Account != BLL.Const.Gly && d != Const.CTEM_DepartId && r != Const.Role_PPE) { ids = this.CurrUser.UserId; Layer = 1; } else { ids = udsId; } int pageSize = Grid1.PageSize; int pageIndex = Grid1.PageIndex + 1; SqlParameter[] parameter = new SqlParameter[] { new SqlParameter("@JobNo",JobNo), new SqlParameter("@JobType",JobType), new SqlParameter("@JobStatus",JobStatus), new SqlParameter("@sId",ids), new SqlParameter("@pageSize",pageSize), new SqlParameter("@pageIndex",pageIndex), new SqlParameter("@Layer",Layer), new SqlParameter("@Status",Status) }; DataSet ds = SQLHelper.RunProcedure("Proc_NewManHours_Plan", parameter, "t"); DataTable table = ds.Tables[0]; Grid1.RecordCount = int.Parse(ds.Tables[1].Rows[0]["recordsTotal"].ToString()); Grid1.DataSource = table; Grid1.DataBind(); } #endregion #region 下拉框选择事件 /// /// 下拉框选择事件 /// /// /// protected void drpJobType_SelectedIndexChanged(object sender, EventArgs e) { this.drpJobStatus.Items.Clear(); if (drpJobType.SelectedText == "Other") { BLL.ConstService.InitConstValueProjectStatus(this.drpJobStatus, BLL.Const.ProjectPlanner_JobStatus, "3", true); } if (drpJobType.SelectedText != "Other") { BLL.ConstService.InitConstValueProjectStatus(this.drpJobStatus, BLL.Const.ProjectPlanner_JobStatus, "2", true); } if (hidpersonnel.Text == "D@" + BLL.Const.CTE_DepartId) { BindGrid(""); } else { BindGrid(hidpersonnel.Text); } } /// /// 下拉框选择事件 /// /// /// protected void drpJobStatus_SelectedIndexChanged(object sender, EventArgs e) { if (hidpersonnel.Text == "D@" + BLL.Const.CTE_DepartId) { BindGrid(""); } else { BindGrid(hidpersonnel.Text); } } #endregion #region 加载树节点 /// /// 加载部门人员 /// private void BindDeptTree(string UserName) { this.tvUser.Nodes.Clear(); TreeNode rootNode = new TreeNode(); rootNode.Text = "CTE"; rootNode.ToolTip = "CTE"; rootNode.NodeID = "D@" + BLL.Const.CTE_DepartId; rootNode.Expanded = true; rootNode.EnableClickEvent = true; this.tvUser.Nodes.Add(rootNode); var user = BLL.Sys_UserService.GetUsersByUserId(this.CurrUser.UserId); if (user != null) { if (this.CurrUser.Account == BLL.Const.Gly || user.RoleId == Const.Role_PPE || user.DepartId == Const.CTEM_DepartId) { List departs = BLL.DepartService.GetDepartListBySupCheckItem(BLL.Const.CTE_DepartId); foreach (var item in departs) { TreeNode departNode = new TreeNode();//定义根节点 departNode.Text = item.DepartName; departNode.NodeID = "D@" + item.DepartId; departNode.ToolTip = item.DepartName; departNode.EnableClickEvent = true; rootNode.Nodes.Add(departNode); BindDeptNode(departNode, item.DepartId, UserName); } } else { if (!string.IsNullOrEmpty(user.DepartId)) { Model.Base_Depart departs = BLL.DepartService.GetDepartById(user.DepartId); if (departs != null) { TreeNode departNode = new TreeNode();//定义根节点 departNode.Text = departs.DepartName; departNode.NodeID = "D@" + departs.DepartId; departNode.ToolTip = departs.DepartName; departNode.EnableClickEvent = true; departNode.Expanded = true; rootNode.Nodes.Add(departNode); BindDeptNode(departNode, departs.DepartId, UserName); } } } } } /// /// /// /// /// private void BindDeptNode(TreeNode DTnode, string DepartId, string UserName) { try { string strSql = @"SELECT UserId,UserName,DepartId FROM dbo.Sys_User WHERE IsPost=1 AND Account <> 'gly' AND DepartId=@DepartId "; List listStr = new List(); var user = BLL.Sys_UserService.GetUsersByUserId(this.CurrUser.UserId); if (user != null) { if (this.CurrUser.Account == BLL.Const.Gly || user.RoleId == Const.Role_PPE || user.DepartId == Const.CTEM_DepartId) { listStr.Add(new SqlParameter("@DepartId", DepartId)); if (!string.IsNullOrEmpty(UserName)) { strSql += " AND UserName LIKE @UserName "; listStr.Add(new SqlParameter("@UserName", "%" + UserName + "%")); } } else { if (!string.IsNullOrEmpty(user.DepartId)) { listStr.Add(new SqlParameter("@DepartId", user.DepartId)); } strSql += " AND UserId =@userId "; listStr.Add(new SqlParameter("@userId", this.CurrUser.UserId)); } } strSql += " ORDER BY UserName"; SqlParameter[] parameter = listStr.ToArray(); DataTable table = SQLHelper.GetDataTableRunText(strSql, parameter); for (int i = 0; i < table.Rows.Count; i++) { TreeNode node = new TreeNode(); node.Text = table.Rows[i]["UserName"].ToString(); node.NodeID = "U@" + table.Rows[i]["UserId"].ToString(); node.Expanded = true; node.EnableClickEvent = true; DTnode.Nodes.Add(node);//把指定的节点添加到控件中 } } catch (Exception ex) { Alert.ShowInParent(ex.ToString()); } } #endregion #region 点击树节点 /// /// 树节点选择 /// /// /// protected void tvUser_NodeCommand(object sender, FineUIPro.TreeCommandEventArgs e) { string id = e.Node.NodeID.ToString(); if (id == "D@" + BLL.Const.CTE_DepartId) { BindGrid(""); } else { BindGrid(id); } hidpersonnel.Text = id; } #endregion #region 分页、排序 /// /// 分页 /// /// /// protected void Grid1_PageIndexChange(object sender, GridPageEventArgs e) { Grid1.PageIndex = e.NewPageIndex; BindGrid(hidpersonnel.Text); } /// /// 分页显示条数下拉框 /// /// /// protected void ddlPageSize_SelectedIndexChanged(object sender, EventArgs e) { Grid1.PageSize = Convert.ToInt32(ddlPageSize.SelectedValue); BindGrid(hidpersonnel.Text); } /// /// 排序 /// /// /// protected void Grid1_Sort(object sender, FineUIPro.GridSortEventArgs e) { Grid1.SortDirection = e.SortDirection; Grid1.SortField = e.SortField; BindGrid(hidpersonnel.Text); } #endregion #region 编辑 /// /// 编辑实际人工时 /// /// /// protected void btnEdit_Click(object sender, EventArgs e) { string UserId = ""; if (CurrUser.Account == Const.Gly) { if (string.IsNullOrEmpty(hidpersonnel.Text)) { Alert.ShowInParent("Please select personnel!"); return; } string[] sIdArr = hidpersonnel.Text.Split('@'); if (sIdArr[0].ToString() == "U") { UserId = sIdArr[1].ToString(); } else { Alert.ShowInParent("Please select personnel!"); return; } } else { UserId = CurrUser.UserId; } PageContext.RegisterStartupScript(Window2.GetShowReference(String.Format("ManHoursActual.aspx?UserId={0}", UserId, "编辑 - "))); } /// /// 编辑计划人工时 /// /// /// protected void btnNew_Click(object sender, EventArgs e) { //if ((DateTime.Now.Day > 5 || (DateTime.Now.Day == 5 && DateTime.Now.Hour > 17)) && DateTime.Now.Day < 26) //{ // Alert.ShowInParent("StaffingPlan已冻结!提示:下月计划人工时从本月26号开放填写,到下月5号下午5点冻结!"); // return; //} string UserId = ""; if (CurrUser.Account == Const.Gly) { if (string.IsNullOrEmpty(hidpersonnel.Text)) { Alert.ShowInParent("Please select personnel!"); return; } string[] sIdArr = hidpersonnel.Text.Split('@'); if (sIdArr[0].ToString() == "U") { UserId = sIdArr[1].ToString(); } else { Alert.ShowInParent("Please select personnel!"); return; } } else { UserId = CurrUser.UserId; } PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("ManHoursPlanEditNew.aspx?UserId={0}", UserId, "编辑 - "))); } /// /// 右键编辑事件 /// /// /// protected void btnMenuEdit_Click(object sender, EventArgs e) { if (Grid1.SelectedRowIndexArray.Length == 0) { Alert.ShowInParent("Please select at least one record!"); return; } string Id = Grid1.SelectedRowID; PageContext.RegisterStartupScript(Window3.GetShowReference(String.Format("AccountDisabled.aspx?ManHoursPlanId={0}", Id, "人工时 - "))); // btnEdit_Click(null, null); } protected void btnMenuAdd_Click(object sender, EventArgs e) { if (Grid1.SelectedRowIndexArray.Length == 0) { Alert.ShowInParent("Please select at least one project!"); return; } string Id = Grid1.SelectedRowID; var p = from x in Funs.DB.ManHours_Plan where x.ManHoursPlanId == Id select x; if (p.Count() > 0) { PageContext.RegisterStartupScript(Window4.GetShowReference(String.Format("AddManHours.aspx?eprojectId={0}", p.First().EProjectId, "人工时 - "))); } } /// /// Grid行双击事件 /// /// /// protected void Grid1_RowDoubleClick(object sender, GridRowClickEventArgs e) { if (Grid1.SelectedRowIndexArray.Length == 0) { Alert.ShowInParent("Please select at least one record!"); return; } string Id = Grid1.SelectedRowID; PageContext.RegisterStartupScript(Window3.GetShowReference(String.Format("AccountDisabled.aspx?ManHoursPlanId={0}", Id, "人工时 - "))); } /// /// 删除 /// /// /// protected void btnMenuDel_Click(object sender, EventArgs e) { if (Grid1.SelectedRowIndexArray.Length > 0) { foreach (int rowIndex in Grid1.SelectedRowIndexArray) { string rowID = Grid1.SelectedRowID; if (!string.IsNullOrEmpty(rowID)) { BLL.PlanService.DeletePlanById(rowID); } } ShowNotify("Deleted successfully!"); BLL.Sys_LogService.AddLog(this.CurrUser.UserId, "Delete ManHours information"); BindGrid(""); } } #endregion #region 关闭弹出窗口 /// /// 关闭窗口 /// /// /// protected void Window1_Close(object sender, EventArgs e) { BindGrid(""); } /// /// 关闭窗口 /// /// /// protected void Window3_Close(object sender, EventArgs e) { BindGrid(""); } #endregion #region 权限设置 /// /// 菜单按钮权限 /// private void GetButtonPower() { var buttonList = BLL.CommonService.GetAllButtonList(this.CurrUser.UserId, BLL.Const.ManHoursMenuId); if (buttonList.Count() > 0) { if (buttonList.Contains(BLL.Const.BtnAccountDisabled)) { this.btnMenuEdit.Hidden = false; } if (buttonList.Contains(BLL.Const.BtnOtherPlanEdit)) { this.btnAddOther.Hidden = false; } } } #endregion protected void btnAddOther_Click(object sender, EventArgs e) { PageContext.RegisterStartupScript(Window4.GetShowReference(String.Format("AddManHours.aspx", "人工时 - "))); } } }