CNCEC_SUBQHSE_WUHUAN/SGGL/FineUIPro.Web/DocManage/FileCabinet.aspx.cs

325 lines
12 KiB
C#

using BLL;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.IO;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace FineUIPro.Web.DocManage
{
public partial class FileCabinet : PageBase
{
public string TreeCommand
{
get
{
return (string)ViewState["TreeCommand"];
}
set
{
ViewState["TreeCommand"] = value;
}
}
#region
/// <summary>
/// 页面加载
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
GetButtonPower();
InitTreeMenu();
}
}
#endregion
#region
/// <summary>
/// 加载树
/// </summary>
private void InitTreeMenu()
{
if (string.IsNullOrEmpty(this.CurrUser.UnitId))
{
return;
}
this.tree1.Nodes.Clear();
this.tree1.ShowBorder = false;
this.tree1.ShowHeader = false;
this.tree1.EnableIcons = true;
this.tree1.AutoScroll = true;
this.tree1.EnableSingleClickExpand = true;
if (RadioType.SelectedValue == "Unit")
{
List<Model.Base_Unit> base_Unit = new List<Model.Base_Unit>();
// base_Unit = BLL.UnitService.GetUnitListByProjectId(this.CurrUser.LoginProjectId);
var list = BLL.UnitService.GetUnitByUnitId(this.CurrUser.UnitId);
base_Unit.Add(list);
foreach (var q in base_Unit) //二级树
{
TreeNode newNode = new TreeNode();
newNode.Text = q.UnitName;
newNode.NodeID = q.UnitId;
newNode.CommandName = "Unit";
newNode.EnableExpandEvent = true;
newNode.EnableClickEvent = true;
this.tree1.Nodes.Add(newNode);
//TreeNode emptyNode = new TreeNode();
//emptyNode.Text = "";
//emptyNode.NodeID = "";
//newNode.Nodes.Add(emptyNode);
}
}
else
{
var DocTypeList= DocTypeService.GetDocTypeList();
foreach (var q in DocTypeList)
{
TreeNode newNode = new TreeNode();
newNode.Text = q.DocTypeName;
newNode.NodeID = q.DocTypeId;
newNode.CommandName = "DocType";
newNode.EnableExpandEvent = true;
newNode.EnableClickEvent = true;
this.tree1.Nodes.Add(newNode);
}
}
}
#endregion
#region Tree事件
/// <summary>
/// Tree点击事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void tree1_NodeCommand(object sender, TreeCommandEventArgs e)
{
TreeCommand = e.CommandName;
BindGrid();
}
protected void tree1_NodeExpand(object sender, TreeNodeEventArgs e)
{
e.Node.Nodes.Clear();
if (e.Node.CommandName == "Unit") //展开部门
{
var DepartList= DepartService.GetDepartList(e.Node.NodeID);
foreach (var depart in DepartList)
{
TreeNode newNode1 = new TreeNode();
newNode1.Text = depart.DepartName;
newNode1.NodeID = depart.DepartId;
newNode1.CommandName = "Depart";
newNode1.EnableExpandEvent = true;
newNode1.EnableClickEvent = true;
e.Node.Nodes.Add(newNode1);
}
}
}
#endregion
#region
private void BindGrid()
{
string strSql = @"SELECT doc.DocId,doc.ProjectId,doc.DocCode,doc.DocName,unit.UnitName as SendUnitName,doc.ReceivUnitIds,docType.DocTypeName,"
+ @" doc.CompileMan,doc.CompileDate,CNProfessional.ProfessionalName,doc.State,u.userName"
+ @" FROM Doc_DocManage doc "
+ @" left join Base_Unit unit on unit.unitId=doc.SendUnitId "
+ @" left join Base_DocType docType on docType.DocTypeId=doc.DocTypeId "
+ @" left join Base_CNProfessional CNProfessional on CNProfessional.CNProfessionalId=doc.CNProfessionalId "
+ @" left join sys_User u on u.userId = doc.CompileMan"
+ @" where doc.ProjectId=@ProjectId";
List<SqlParameter> listStr = new List<SqlParameter>();
listStr.Add(new SqlParameter("@ProjectId", CurrUser.LoginProjectId));
if (TreeCommand== "Unit" && !string.IsNullOrEmpty(tree1.SelectedNodeID))
{
strSql += " AND doc.SendUnitId=@unitId";
listStr.Add(new SqlParameter("@unitId", tree1.SelectedNodeID));
}
else if (TreeCommand== "Depart" && !string.IsNullOrEmpty(tree1.SelectedNodeID))
{
strSql += " AND doc.DepartId=@DepartId";
listStr.Add(new SqlParameter("@DepartId", tree1.SelectedNodeID));
}
else if (TreeCommand== "DocType")
{
//ReceivUnitIds SendUnitId
strSql += " AND (doc.ReceivUnitIds like @ReceivUnitId or doc.SendUnitId = @SendUnitId )";
listStr.Add(new SqlParameter("@SendUnitId", this.CurrUser.UnitId));
listStr.Add(new SqlParameter("@ReceivUnitId", "%" + this.CurrUser.UnitId + "%"));
strSql += " AND doc.DocTypeId=@DocTypeId";
listStr.Add(new SqlParameter("@DocTypeId", tree1.SelectedNodeID));
}
SqlParameter[] parameter = listStr.ToArray();
DataTable tb = SQLHelper.GetDataTableRunText(strSql, parameter);
tb = GetFilteredTable(Grid1.FilteredData, tb);
var table = GetPagedDataTable(Grid1, tb);
Grid1.RecordCount = tb.Rows.Count;
Grid1.DataSource = table;
Grid1.DataBind();
}
#endregion
#region
protected void Grid1_PageIndexChange(object sender, GridPageEventArgs e)
{
Grid1.PageIndex = e.NewPageIndex;
BindGrid();
}
/// <summary>
/// Grid1排序
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Grid1_Sort(object sender, GridSortEventArgs e)
{
Grid1.SortDirection = e.SortDirection;
Grid1.SortField = e.SortField;
BindGrid();
}
/// <summary>
/// 分页下拉选择事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void ddlPageSize_SelectedIndexChanged(object sender, EventArgs e)
{
Grid1.PageSize = Convert.ToInt32(ddlPageSize.SelectedValue);
BindGrid();
}
protected void Grid1_RowDoubleClick(object sender, GridRowClickEventArgs e)
{
if (Grid1.SelectedRowIndexArray.Length == 0)
{
Alert.ShowInTop("请至少选择一条记录!", MessageBoxIcon.Warning);
return;
}
PageContext.RegisterStartupScript(Window2.GetShowReference(String.Format("../DocManage/DocManageView.aspx?DocId={0}", Grid1.SelectedRowID, "查看 - ")));
}
/// <summary>
/// 行点击事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Grid1_RowCommand(object sender, GridCommandEventArgs e)
{
string id = e.RowID;
if (e.CommandName.Equals("AttachUrl"))
{
string menuId = Const.ProjectControlPointMenuId;
PageContext.RegisterStartupScript(WindowAtt.GetShowReference(
String.Format("../AttachFile/Fileuploader.aspx?type=-1&source=1&toKeyId={0}&path=FileUpload/BreakdownProject&menuId={1}", id, menuId)));
}
else if (e.CommandName == "Print")
{
Print(id);
}
}
#endregion
private void Print(string DocId)
{
var model = DocManageService.GetDocByDocId(DocId);
if (model.State != Const.Doc_State_2)
{
ShowNotify("当前状态未闭环无法打印", MessageBoxIcon.Warning);
return;
}
DataTable dt = new DataTable();
dt = DocManageApproveService.GetListData(DocId);
if (dt.Columns.Count == 0)
{
dt.Columns.Add("RoleName", typeof(String));
dt.Columns.Add("ApproveMan", typeof(String));
dt.Columns.Add("ApproveDate", typeof(String));
dt.Columns.Add("ApproveIdea", typeof(String));
}
var keyValuePairs = BLL.DocManageService.GetPairs(DocId);
dt.TableName = "Table1";
BLL.Common.FastReport.ResetData();
BLL.Common.FastReport.AddFastreportTable(dt);
BLL.Common.FastReport.AddFastreportParameter(keyValuePairs);
string initTemplatePath = "File/Fastreport/新疆文件管理流转表.frx";
string rootPath = Server.MapPath("~/");
if (File.Exists(rootPath + initTemplatePath))
{
PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("../Controls/Fastreport.aspx?ReportPath={0}", rootPath + initTemplatePath)));
}
}
#region
protected void btnMenuView_Click(object sender, EventArgs e)
{
if (Grid1.SelectedRowIndexArray.Length == 0)
{
Alert.ShowInTop("请至少选择一条记录!", MessageBoxIcon.Warning);
return;
}
PageContext.RegisterStartupScript(Window2.GetShowReference(String.Format("../DocManage/DocManageView.aspx?DocId={0}", Grid1.SelectedRowID, "查看 - ")));
}
#endregion
#region
/// <summary>
/// 获取按钮权限
/// </summary>
/// <param name="button"></param>
/// <returns></returns>
private void GetButtonPower()
{
if (Request.Params["value"] == "0")
{
return;
}
var buttonList = BLL.CommonService.GetAllButtonList(this.CurrUser.LoginProjectId, this.CurrUser.UserId, BLL.Const.ProjectControlPointMenuId);
if (buttonList.Count() > 0)
{
if (buttonList.Contains(BLL.Const.BtnAdd))
{
// this.btnNew.Hidden = false;
}
}
}
#endregion
protected void RadioButtonList1_SelectedIndexChanged(object sender, EventArgs e)
{
InitTreeMenu();
}
}
}