using BLL; using System; using System.Collections.Generic; using System.Data; using System.Data.SqlClient; using System.IO; using System.Linq; using System.Text; using System.Web; using AspNet = System.Web.UI.WebControls; namespace FineUIPro.Web.HSSE.EduTrain { public partial class StudyZone : PageBase { #region 加载 /// /// 加载页面 /// /// /// protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { Funs.DropDownPageSize(this.ddlPageSize); this.GetButtonPower(); //WorkPostService.InitWorkPostDropDownList(drpWorkPost, true); InitTreeMenu(); } } #endregion #region 加载树 /// /// 初始化树 /// private void InitTreeMenu() { trStudyZone.Nodes.Clear(); trStudyZone.ShowBorder = false; trStudyZone.ShowHeader = false; trStudyZone.EnableIcons = true; trStudyZone.AutoScroll = true; trStudyZone.EnableSingleClickExpand = true; TreeNode rootNode = new TreeNode { Text = "学习园地", NodeID = "0", Expanded = true }; this.trStudyZone.Nodes.Add(rootNode); BoundTree(rootNode.Nodes, "0"); } private void BoundTree(TreeNodeCollection nodes, string menuId) { var dt = GetNewTraining(menuId); if (dt.Count() > 0) { TreeNode tn = null; foreach (var dr in dt) { tn = new TreeNode { Text = dr.StudyZoneName, NodeID = dr.StudyZoneId, EnableClickEvent = true, ToolTip = dr.StudyZoneName }; nodes.Add(tn); BoundTree(tn.Nodes, dr.StudyZoneId); } } } /// /// 得到菜单方法 /// /// /// private List GetNewTraining(string parentId) { return (from x in Funs.DB.Training_StudyZone where x.SupStudyZoneId == parentId orderby x.StudyZoneCode select x).ToList(); ; } #endregion #region 增加、修改、删除学习园地类别 /// /// 增加学习园地类别 /// /// /// protected void btnNew_Click(object sender, EventArgs e) { if (this.trStudyZone.SelectedNode != null) { Model.Training_StudyZone training = BLL.StudyZoneService.GetStudyZoneById(this.trStudyZone.SelectedNode.NodeID); if ((training != null && training.IsEndLever == false) || this.trStudyZone.SelectedNode.NodeID == "0") //根节点或者非末级节点,可以增加 { PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("StudyZoneSave.aspx?SupStudyZoneId={0}", this.trStudyZone.SelectedNode.NodeID, "编辑 - "))); } else { ShowNotify("选择的项已是末级!", MessageBoxIcon.Warning); } } else { ShowNotify("请选择树节点!", MessageBoxIcon.Warning); } } /// /// 修改学习园地类别 /// /// /// protected void btnEdit_Click(object sender, EventArgs e) { if (this.trStudyZone.SelectedNode != null) { if (this.trStudyZone.SelectedNode.NodeID != "0") //非根节点可以编辑 { PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("StudyZoneSave.aspx?StudyZoneId={0}", this.trStudyZone.SelectedNode.NodeID, "编辑 - "))); } else { ShowNotify("根节点无法编辑!", MessageBoxIcon.Warning); } } else { ShowNotify("请选择树节点!", MessageBoxIcon.Warning); } } /// /// 删除学习园地类别 /// /// /// protected void btnDelete_Click(object sender, EventArgs e) { if (this.trStudyZone.SelectedNode != null) { var q = BLL.StudyZoneService.GetStudyZoneById(this.trStudyZone.SelectedNode.NodeID); if (q != null && BLL.StudyZoneService.IsDeleteStudyZone(this.trStudyZone.SelectedNode.NodeID)) { BLL.StudyZoneService.DeleteStudyZone(this.trStudyZone.SelectedNode.NodeID); InitTreeMenu(); } else { ShowNotify("存在下级菜单或已增加资源数据或者为内置项,不允许删除!", MessageBoxIcon.Warning); } } else { ShowNotify("请选择删除项!", MessageBoxIcon.Warning); } } #endregion #region 树点击事件 /// /// 树点击事件 /// /// /// protected void trStudyZone_NodeCommand(object sender, FineUIPro.TreeCommandEventArgs e) { BindGrid(); } #endregion #region 下拉触发事件 /// /// 适用岗位下拉触发事件 /// /// /// protected void drp_SelectedIndexChanged(object sender, EventArgs e) { this.BindGrid(); } #endregion #region 绑定数据 /// /// 绑定数据 /// private void BindGrid() { if (this.trStudyZone.SelectedNode != null && !string.IsNullOrEmpty(this.trStudyZone.SelectedNode.NodeID)) { //string strSql = @"SELECT item.StudyZoneItemId,(item.StudyZoneItemId+'_'+CAST(row_number() over(order by item.StudyZoneItemCode) AS nvarchar(10))) AS StudyZoneItemIdNum," // + @" item.StudyZoneItemId,item.StudyZoneId,item.StudyZoneItemCode,item.StudyZoneItemName,--A.AttachUrl," // + @" item.CompileMan, item.CompileDate,--dbo.GetFileName(A.AttachUrl) AS AttachUrlName, " // + @" (CASE WHEN WorkPostNames IS NULL THEN '通用' ELSE WorkPostNames END) AS WorkPostNames " // + @" FROM dbo.Training_StudyZoneItem AS item" // //+ @" LEFT JOIN (SELECT ToKeyId ,F1 as AttachUrl" // //+ @" FROM AttachFile CROSS APPLY (SELECT * FROM dbo.f_splitstr(AttachUrl,',')) t" // //+ @" WHERE LEN(F1) > 0) AS A ON A.ToKeyId=item.StudyZoneItemId " // + @" WHERE item.StudyZoneId=@StudyZoneId"; string strSql = @"SELECT item.StudyZoneItemId,(item.StudyZoneItemId+'_'+CAST(row_number() over(order by item.StudyZoneItemCode) AS nvarchar(10))) AS StudyZoneItemIdNum," + @" item.StudyZoneItemId,item.StudyZoneId,item.StudyZoneItemCode,item.StudyZoneItemName," + @" item.CompileMan, item.CompileDate," + @" (CASE WHEN WorkPostNames IS NULL THEN '通用' ELSE WorkPostNames END) AS WorkPostNames " + @" FROM dbo.Training_StudyZoneItem AS item" + @" WHERE item.StudyZoneId=@StudyZoneId"; List listStr = new List { new SqlParameter("@StudyZoneId", this.trStudyZone.SelectedNode.NodeID) }; if (!string.IsNullOrEmpty(this.txtStudyZoneItemCode.Text.Trim())) { strSql += " AND StudyZoneItemCode LIKE @StudyZoneItemCode"; listStr.Add(new SqlParameter("@StudyZoneItemCode", "%" + this.txtStudyZoneItemCode.Text.Trim() + "%")); } if (!string.IsNullOrEmpty(this.txtStudyZoneItemName.Text.Trim())) { strSql += " AND StudyZoneItemName LIKE @StudyZoneItemName"; listStr.Add(new SqlParameter("@StudyZoneItemName", "%" + this.txtStudyZoneItemName.Text.Trim() + "%")); } //if (!string.IsNullOrEmpty(this.drpWorkPost.SelectedValue) && this.drpWorkPost.SelectedValue != Const._Null) //{ // strSql += " AND (WorkPostIds IS NULL OR WorkPostIds LIKE @WorkPostId)"; // listStr.Add(new SqlParameter("@WorkPostId", "%" + this.drpWorkPost.SelectedValue + "%")); //} SqlParameter[] parameter = listStr.ToArray(); DataTable tb = SQLHelper.GetDataTableRunText(strSql, parameter); Grid1.RecordCount = tb.Rows.Count; var table = this.GetPagedDataTable(Grid1, tb); Grid1.DataSource = table; Grid1.DataBind(); } } #endregion #region 弹出窗关闭事件 protected void Window1_Close(object sender, EventArgs e) { InitTreeMenu(); } protected void Window2_Close(object sender, EventArgs e) { BindGrid(); } #endregion #region 排序、分页 protected void Grid1_PageIndexChange(object sender, GridPageEventArgs e) { Grid1.PageIndex = e.NewPageIndex; BindGrid(); } protected void ddlPageSize_SelectedIndexChanged(object sender, EventArgs e) { Grid1.PageSize = Convert.ToInt32(ddlPageSize.SelectedValue); BindGrid(); } protected void Grid1_Sort(object sender, FineUIPro.GridSortEventArgs e) { Grid1.SortDirection = e.SortDirection; Grid1.SortField = e.SortField; BindGrid(); } #endregion #region 查询 /// /// 查询 /// /// /// protected void TextBox_TextChanged(object sender, EventArgs e) { this.BindGrid(); } #endregion #region 增加、修改、删除明细信息 #region 新增明细 /// /// 新增明细 /// /// /// protected void btnNewDetail_Click(object sender, EventArgs e) { if (this.trStudyZone.SelectedNode != null) { if (this.trStudyZone.SelectedNode.Nodes.Count == 0) { PageContext.RegisterStartupScript(Window2.GetShowReference(String.Format("StudyZoneItemSave.aspx?StudyZoneId={0}", this.trStudyZone.SelectedNode.NodeID, "编辑 - "))); } else { ShowNotify("请选择末级节点!", MessageBoxIcon.Warning); } } else { ShowNotify("请选择树节点!", MessageBoxIcon.Warning); } } #endregion #region 编辑明细 protected void btnEditDetail_Click(object sender, EventArgs e) { this.EditData(); } protected void Grid1_RowDoubleClick(object sender, GridRowClickEventArgs e) { this.EditData(); } /// /// 右键编辑事件 /// /// /// protected void btnMenuEdit_Click(object sender, EventArgs e) { this.EditData(); } /// /// 编辑数据方法 /// private void EditData() { if (Grid1.SelectedRowIndexArray.Length == 0) { Alert.ShowInTop("请至少选择一条记录!", MessageBoxIcon.Warning); return; } string companyTrainingItemId = Grid1.SelectedRowID; companyTrainingItemId = companyTrainingItemId.Substring(0, companyTrainingItemId.IndexOf("_")); PageContext.RegisterStartupScript(Window2.GetShowReference(String.Format("StudyZoneItemSave.aspx?StudyZoneItemId={0}", companyTrainingItemId, "编辑 - "))); } #endregion #region 删除明细 // 删除数据 protected void btnDeleteDetail_Click(object sender, EventArgs e) { this.DeleteData(); } /// /// 右键删除事件 /// /// /// protected void btnMenuDelete_Click(object sender, EventArgs e) { this.DeleteData(); } /// /// 删除方法 /// private void DeleteData() { if (Grid1.SelectedRowIndexArray.Length > 0) { foreach (int rowIndex in Grid1.SelectedRowIndexArray) { string rowID = Grid1.DataKeys[rowIndex][0].ToString(); rowID = rowID.Substring(0, rowID.IndexOf("_")); var getD = BLL.StudyZoneItemService.GetStudyZoneItemById(rowID); if (getD != null) { BLL.LogService.AddSys_Log(this.CurrUser, getD.StudyZoneItemCode, getD.StudyZoneItemId, BLL.Const.StudyZoneMenuId, BLL.Const.BtnDelete); BLL.StudyZoneItemService.DeleteStudyZoneItemById(rowID); } } BindGrid(); ShowNotify("删除数据成功!"); } } #endregion #endregion #region 按钮权限 /// /// 获取按钮权限 /// /// /// private void GetButtonPower() { var buttonList = BLL.CommonService.GetAllButtonList(this.CurrUser.LoginProjectId, this.CurrUser.UserId, BLL.Const.StudyZoneMenuId); if (buttonList.Count() > 0) { if (buttonList.Contains(BLL.Const.BtnAdd)) { this.btnNew.Hidden = false; //this.btnImport.Hidden = false; this.btnNewDetail.Hidden = false; } if (buttonList.Contains(BLL.Const.BtnModify)) { this.btnEdit.Hidden = false; this.btnMenuEdit.Hidden = false; } if (buttonList.Contains(BLL.Const.BtnDelete)) { this.btnDelete.Hidden = false; this.btnMenuDelete.Hidden = false; } } } #endregion #region 导入 /// /// 导入按钮 /// /// /// protected void btnImport_Click(object sender, EventArgs e) { PageContext.RegisterStartupScript(Window3.GetShowReference(String.Format("StudyZoneItemIn.aspx", "导入 - "))); } protected void Window3_Close(object sender, EventArgs e) { this.InitTreeMenu(); this.BindGrid(); } #endregion /// /// 导出 /// /// /// protected void btnOut_Click(object sender, EventArgs e) { Response.ClearContent(); string filename = Funs.GetNewFileName(); Response.AddHeader("content-disposition", "attachment; filename=" + System.Web.HttpUtility.UrlEncode("学习园地" + filename, System.Text.Encoding.UTF8) + ".xls"); Response.ContentType = "application/excel"; Response.ContentEncoding = System.Text.Encoding.UTF8; this.Grid1.PageSize = Grid1.RecordCount; BindGrid(); Response.Write(GetGridTableHtml(Grid1, 5)); Response.End(); } #region 导出方法 /// /// 导出方法 /// /// /// public static string GetGridTableHtml(Grid grid, int count) { StringBuilder sb = new StringBuilder(); sb.Append(""); sb.Append(""); sb.Append(""); foreach (GridColumn column in grid.Columns) { if (column.ColumnIndex < count) { sb.AppendFormat("", column.HeaderText); } } sb.Append(""); foreach (GridRow row in grid.Rows) { sb.Append(""); foreach (GridColumn column in grid.Columns) { if (column.ColumnIndex < count) { string html = row.Values[column.ColumnIndex].ToString(); if (column.ColumnID == "tfNumber" && (row.FindControl("lbNumber") as AspNet.Label) != null) { html = (row.FindControl("lbNumber") as AspNet.Label).Text; } if (column.ColumnID == "tfStudyZoneItemCode" && (row.FindControl("lbStudyZoneItemCode") as AspNet.Label) != null) { html = (row.FindControl("lbStudyZoneItemCode") as AspNet.Label).Text; } if (column.ColumnID == "tfStudyZoneItemName" && (row.FindControl("lbStudyZoneItemName") as AspNet.Label) != null) { html = (row.FindControl("lbStudyZoneItemName") as AspNet.Label).Text; } if (column.ColumnID == "tfCompileMan" && (row.FindControl("lbCompileMan") as AspNet.Label) != null) { html = (row.FindControl("lbCompileMan") as AspNet.Label).Text; } if (column.ColumnID == "tfCompileDate" && (row.FindControl("lbCompileDate") as AspNet.Label) != null) { html = (row.FindControl("lbCompileDate") as AspNet.Label).Text; } sb.AppendFormat("", html); } } sb.Append(""); } sb.Append("
{0}
{0}
"); return sb.ToString(); } #endregion /// /// 行事件 /// /// /// protected void Grid1_RowCommand(object sender, GridCommandEventArgs e) { if (e.CommandName == "Attach") { string attUrl = this.Grid1.Rows[e.RowIndex].Values[this.Grid1.Columns.Count - 1].ToString(); try { string url = Funs.RootPath + attUrl; FileInfo info = new FileInfo(url); string savedName = Path.GetFileName(url); if (!info.Exists || string.IsNullOrEmpty(savedName)) { url = Funs.RootPath + "Images//Null.jpg"; info = new FileInfo(url); } if (Path.GetExtension(savedName) == ".mp4" || Path.GetExtension(savedName).ToLower() == ".mp4" || Path.GetExtension(savedName) == ".m4v") { string mpUrl = HttpUtility.UrlEncode(attUrl.Replace('\\', '/')); PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("~/AttachFile/player.aspx?url={0}", attUrl.Replace('\\', '/'), "播放 - "), "播放视频", 700, 560)); } else { string fileName = Path.GetFileName(url); long fileSize = info.Length; System.Web.HttpContext.Current.Response.Clear(); //System.Web.HttpContext.Current.Response.ContentType = "application/x-zip-compressed"; System.Web.HttpContext.Current.Response.ContentType = "application/octet-stream"; System.Web.HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment;filename=" + System.Web.HttpUtility.UrlEncode(fileName, System.Text.Encoding.UTF8)); System.Web.HttpContext.Current.Response.AddHeader("Content-Length", fileSize.ToString()); System.Web.HttpContext.Current.Response.TransmitFile(url, 0, fileSize); System.Web.HttpContext.Current.Response.Flush(); System.Web.HttpContext.Current.Response.End(); } } catch (Exception) { } } } } }