using BLL; using System; using System.Collections.Generic; using System.Data; using System.Data.SqlClient; using System.IO; using System.IO.Compression; using System.Linq; namespace FineUIPro.Web.Person { public partial class PersonTotal : PageBase { /// /// 加载页面 /// /// /// protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { Funs.DropDownPageSize(this.ddlPageSize); ////权限按钮方法 this.GetButtonPower(); if (this.CurrUser.PersonId == BLL.Const.sysglyId || this.CurrUser.PersonId == BLL.Const.hfnbdId) { this.btnOut.Hidden = false; } this.btnNew.OnClientClick = Window1.GetShowReference("PersonTotalEdit.aspx") + "return false;"; this.ddlPageSize.SelectedValue = Grid1.PageSize.ToString(); // 绑定表格 this.BindGrid(); } } /// /// 绑定数据 /// private void BindGrid() { string strSql = @"select PersonTotalId, T.PersonId, Content, StartTime, EndTime ,U.PersonName,RoleName from PersonTotal T left join Person_Persons U on T.UserId=U.PersonId Where 1=1"; List listStr = new List(); if (!string.IsNullOrEmpty(this.txtUserName.Text.Trim())) { strSql += " And U.PersonName LIKE @PersonName"; listStr.Add(new SqlParameter("@PersonName", "%" + this.txtUserName.Text.Trim() + "%")); } if (!string.IsNullOrEmpty(this.txtStartTime.Text.Trim())) { strSql += " And T.StartTime >= @StartTime"; listStr.Add(new SqlParameter("@StartTime", this.txtStartTime.Text.Trim())); } if (!string.IsNullOrEmpty(this.txtEndTime.Text.Trim())) { strSql += " And T.EndTime <= @EndTime"; listStr.Add(new SqlParameter("@EndTime", this.txtEndTime.Text.Trim())); } var buttonList = BLL.CommonService.GetAllButtonList(this.CurrUser.LoginProjectId, this.CurrUser.PersonId, BLL.Const.PersonTotalMenuId); if (this.CurrUser.PersonId != BLL.Const.sysglyId && this.CurrUser.PersonId != BLL.Const.hfnbdId) { if (!buttonList.Contains(Const.BtnSeeAll)) //不能查看全部 { strSql += " And T.UserId = @UserId"; listStr.Add(new SqlParameter("@UserId", this.CurrUser.PersonId)); } } 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(); } #region 查询 /// /// 查询 /// /// /// protected void TextBox_TextChanged(object sender, EventArgs e) { this.BindGrid(); } #endregion #region 获取按钮权限 /// /// 获取按钮权限 /// /// /// private void GetButtonPower() { var buttonList = BLL.CommonService.GetAllButtonList(this.CurrUser.LoginProjectId, this.CurrUser.PersonId, BLL.Const.PersonTotalMenuId); if (buttonList.Count() > 0) { if (buttonList.Contains(BLL.Const.BtnAdd)) { this.btnNew.Hidden = false; } if (buttonList.Contains(BLL.Const.BtnModify)) { this.btnMenuEdit.Hidden = false; } if (buttonList.Contains(BLL.Const.BtnDelete)) { this.btnMenuDelete.Hidden = false; } if (buttonList.Contains(BLL.Const.BtnSeeAll)) { this.btnOut.Hidden = false; } } } #endregion #region 删除数据 /// /// 右键删除事件 /// /// /// protected void btnMenuDelete_Click(object sender, EventArgs e) { this.DeleteData(); } /// /// 删除方法 /// private void DeleteData() { if (Grid1.SelectedRowIndexArray.Length > 0) { string strShowNotify = string.Empty; foreach (int rowIndex in Grid1.SelectedRowIndexArray) { string rowID = Grid1.DataKeys[rowIndex][0].ToString(); var user = BLL.Person_PersonsService.GetPerson_PersonsById(rowID); if (user != null) { string cont = string.Empty; //string cont = judgementDelete(rowID); if (string.IsNullOrEmpty(cont)) { BLL.LogService.AddSys_Log(this.CurrUser, user.JobNum, user.PersonId, BLL.Const.PersonTotalMenuId, BLL.Const.BtnDelete); BLL.PersonTotalService.DeletePersonTotal(Grid1.SelectedRowID); } else { strShowNotify += "人员:" + user.PersonName + cont; } } } BindGrid(); if (!string.IsNullOrEmpty(strShowNotify)) { Alert.ShowInTop(strShowNotify, MessageBoxIcon.Warning); } else { ShowNotify("删除数据成功!", MessageBoxIcon.Success); } } } #endregion #region 分页 /// /// 分页 /// /// /// protected void Grid1_PageIndexChange(object sender, GridPageEventArgs e) { 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) { BindGrid(); } #endregion #region 编辑 /// /// Grid行双击事件 /// /// /// protected void Grid1_RowDoubleClick(object sender, GridRowClickEventArgs e) { this.EditData(); } /// /// 右键编辑事件 /// /// /// protected void btnMenuEdit_Click(object sender, EventArgs e) { this.EditData(); } protected void MenuView_Click(object sender, EventArgs e) { PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("PersonTotalView.aspx?PersonTotalId={0}", Grid1.SelectedRowID, "查看 - "))); } /// /// 编辑数据方法 /// private void EditData() { if (Grid1.SelectedRowIndexArray.Length == 0) { Alert.ShowInParent("请至少选择一条记录!", MessageBoxIcon.Warning); return; } string Id = Grid1.SelectedRowID; if (BLL.CommonService.GetAllButtonPowerList(CurrUser.LoginProjectId, this.CurrUser.PersonId, BLL.Const.PersonTotalMenuId, BLL.Const.BtnModify)) { PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("PersonTotalEdit.aspx?PersonTotalId={0}", Id, "编辑 - "))); } else { PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("PersonTotalView.aspx?PersonTotalId={0}", Id, "查看 - "))); } } #endregion #region 判断是否可删除 /// /// 判断是否可以删除 /// /// private string judgementDelete(string id) { string content = string.Empty; if (Funs.DB.SitePerson_Person.FirstOrDefault(x => x.PersonId == id) != null) { content += "已在【项目用户】中使用,不能删除!"; } return content; } #endregion #region 导出按钮 /// 导出按钮 /// /// /// protected void btnOut_Click(object sender, EventArgs e) { string rootPath = Server.MapPath("~/"); var personTotals = from x in Funs.DB.PersonTotal select x; if (!string.IsNullOrEmpty(this.txtStartTime.Text.Trim())) { personTotals = personTotals.Where(x => x.StartTime >= Convert.ToDateTime(this.txtStartTime.Text.Trim())); } if (!string.IsNullOrEmpty(this.txtEndTime.Text.Trim())) { personTotals = personTotals.Where(x => x.EndTime <= Convert.ToDateTime(this.txtEndTime.Text.Trim())); } List list = new List(); if (personTotals.Count() > 0) { string filePath = rootPath + "FileUpload\\员工总结\\"; if (!Directory.Exists(filePath)) { Directory.CreateDirectory(filePath); } foreach (var detail in personTotals) { string userName = string.Empty; userName = BLL.Person_PersonsService.GetPersonsNameById(detail.UserId); string attachFileUrls = BLL.AttachFileService.getFileUrl(detail.PersonTotalId); string[] urls = attachFileUrls.Split(','); foreach (var url in urls) { string atturl = Funs.RootPath + url; if (File.Exists(atturl)) { string newUrlPath = url.Substring(url.LastIndexOf("/")); string newUrl = filePath + "/" + userName + "-" + newUrlPath.Substring(newUrlPath.IndexOf("_") + 1); if (!File.Exists(newUrl)) { File.Copy(atturl, newUrl); list.Add(newUrl); } } } } string startPath = rootPath + "FileUpload\\员工总结\\"; string zipPath = rootPath + "FileUpload\\员工总结.zip"; ZipFile.CreateFromDirectory(startPath, zipPath); string fileName = Path.GetFileName(zipPath); FileInfo info = new FileInfo(zipPath); long fileSize = info.Length; Response.ClearContent(); Response.ContentType = "application/x-zip-compressed"; Response.AddHeader("content-disposition", "attachment;filename=" + System.Web.HttpUtility.UrlEncode(fileName, System.Text.Encoding.UTF8)); Response.AddHeader("Content-Length", fileSize.ToString()); Response.TransmitFile(zipPath, 0, fileSize); Response.Flush(); Response.Close(); File.Delete(zipPath); foreach (var item in list) { File.Delete(item); } } else { ShowNotify("尚无员工总结可以导出!", MessageBoxIcon.Warning); } } #endregion } }