using System; using System.Collections.Generic; using System; using System.Collections.Generic; using System.Data; using System.Data.SqlClient; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using BLL; using System.IO; namespace FineUIPro.Web.DocManage { public partial class DocFind : PageBase { protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { GetButtonPower(); ddlPageSize.SelectedValue = Grid1.PageSize.ToString(); // 绑定表格 BindGrid(); // btnNew.OnClientClick = Window1.GetShowReference("ProjectSubItemEdit.aspx") + "return false;"; } } #region 绑定数据与查看数据 /// /// 绑定数据 /// public void BindGrid() { DataTable tb = BindData(); Grid1.RecordCount = tb.Rows.Count; tb = GetFilteredTable(Grid1.FilteredData, tb); var table = this.GetPagedDataTable(Grid1, tb); Grid1.DataSource = table; Grid1.DataBind(); } protected DataTable BindData() { string strSql = @"SELECT AttachFileDetaiId ,ToKeyId ,Name ,AliasName ,Type ,AttachUrl ,Classify ,SourcePath ,HtmlPath ,Content ,size ,UploadTime ,U.UserName FROM dbo.AttachFileDetail as Att left join Sys_User U on att.UploadMan=U.UserId left join Doc_DocManage doc on doc.DocId =Att.ToKeyId where doc.ProjectId=@ProjectId "; List listStr = new List(); listStr.Add(new SqlParameter("@ProjectId", CurrUser.LoginProjectId)); strSql += " AND (doc.ReceivUnitIds like @ReceivUnitId or doc.SendUnitId = @SendUnitId )"; if (string.IsNullOrEmpty(this.CurrUser.UnitId)) { return new DataTable(); } listStr.Add(new SqlParameter("@SendUnitId", this.CurrUser.UnitId)); listStr.Add(new SqlParameter("@ReceivUnitId", "%" + this.CurrUser.UnitId + "%")); if (!string.IsNullOrEmpty(this.txtkeyword.Text.Trim())) { if (ListFindType.SelectedValue == "Name") { strSql += " AND AliasName like @keyword"; } else { strSql += " AND Content like @keyword"; } listStr.Add(new SqlParameter("@keyword", "%" + this.txtkeyword.Text.Trim() + "%")); } SqlParameter[] parameter = listStr.ToArray(); DataTable tb = SQLHelper.GetDataTableRunText(strSql, parameter); return tb; } private void LookData() { if (Grid1.SelectedRowIndexArray.Length == 0) { Alert.ShowInTop("请至少选择一条记录!", MessageBoxIcon.Warning); return; } var model = AttachFileDetailService.GetAttachFileDetaiIdById(Grid1.SelectedRowID); if (!string.IsNullOrEmpty(model.SourcePath)) { PageContext.RegisterStartupScript(Window2.GetShowReference(String.Format("..{0}", model.SourcePath, "查看 - "))); } } #endregion #region 右键菜单事件 protected void btnMenuView_Click(object sender, EventArgs e) { LookData(); } #endregion #region 获取按钮权限 /// /// 获取按钮权限 /// /// /// private void GetButtonPower() { if (Request.Params["value"] == "0") { return; } var buttonList = BLL.CommonService.GetAllButtonList(this.CurrUser.LoginProjectId, this.CurrUser.UserId, BLL.Const.DocFindMenuId); if (buttonList.Count() > 0) { if (buttonList.Contains(BLL.Const.BtnAdd)) { // this.btnNew.Hidden = false; } if (buttonList.Contains(BLL.Const.BtnModify)) { // this.btnMenuModify.Hidden = false; } if (buttonList.Contains(BLL.Const.BtnDelete)) { //this.btnMenuDel.Hidden = false; } } } #endregion #region 下拉列表事件 protected void DropProjectSubject_SelectedIndexChanged(object sender, EventArgs e) { BindGrid(); } #endregion #region 表格事件 protected void Grid1_RowDoubleClick(object sender, GridRowClickEventArgs e) { LookData(); } protected void Grid1_PageIndexChange(object sender, GridPageEventArgs e) { BindGrid(); } protected void Grid1_RowCommand(object sender, GridCommandEventArgs e) { if (e.CommandName == "Preview") { var model = BLL.AttachFileDetailService.GetAttachFileDetaiIdById(e.RowID); if (model != null) { string savedName = model.Name; string xnUrl = model.AttachUrl; string url = Funs.RootPath + xnUrl; FileInfo info = new FileInfo(url); if (!info.Exists || string.IsNullOrEmpty(savedName)) { url = Funs.RootPath + "Images//Null.jpg"; info = new FileInfo(url); } var FiletExtension = Path.GetExtension(savedName); bool isSupportType = AttachFileDetailService.IsSupportFileType(FiletExtension); if (isSupportType) { PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("../AttachFile/Look.aspx?fileUrl={0}", model.HtmlPath, "查看 -"))); } else { ShowNotify("不支持预览", MessageBoxIcon.Warning); } } } } protected void ddlPageSize_SelectedIndexChanged(object sender, EventArgs e) { Grid1.PageSize = Convert.ToInt32(ddlPageSize.SelectedValue); BindGrid(); } #endregion #region 按钮事件 protected void btnSearch_Click(object sender, EventArgs e) { BindGrid(); } /// /// 重置 /// /// /// protected void btnRset_Click(object sender, EventArgs e) { txtkeyword.Text = ""; BindGrid(); } #endregion #region 窗体事件 protected void Window1_Close(object sender, WindowCloseEventArgs e) { BindGrid(); } #endregion } }