371 lines
12 KiB
C#
371 lines
12 KiB
C#
using System;
|
||
using System.Collections.Generic;
|
||
using System.Linq;
|
||
using System.Data;
|
||
using System.Data.SqlClient;
|
||
using AspNet = System.Web.UI.WebControls;
|
||
using System.Text;
|
||
using BLL;
|
||
|
||
namespace FineUIPro.Web.common.BaseInfo
|
||
{
|
||
public partial class Project : PageBase
|
||
{
|
||
#region 加载
|
||
/// <summary>
|
||
/// 加载页面
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
protected void Page_Load(object sender, EventArgs e)
|
||
{
|
||
if (!IsPostBack)
|
||
{
|
||
//if (this.CurrUser.Account != BLL.Const.Gly)
|
||
//{
|
||
// this.btnNew.Hidden = true;
|
||
//}
|
||
|
||
ddlPageSize.SelectedValue = Grid1.PageSize.ToString();
|
||
// 绑定表格
|
||
BindGrid();
|
||
|
||
}
|
||
}
|
||
|
||
#region 绑定数据/查询
|
||
|
||
private void BindGrid()
|
||
{
|
||
//string strSql = "select *, cast((case when PowerIsExtracted =1 then '已抽取' else '未抽取' end) as nvarchar(10)) as PowerExtract from Base_Project order by ProjectCode";
|
||
string strSql = @"select * from Base_Project where IsClosed=@IsClosed
|
||
and ProjectArea=@ProjectArea";
|
||
|
||
List<SqlParameter> parms = new List<SqlParameter>();
|
||
if (this.rbIsClosed.SelectedValue == "0")
|
||
{
|
||
parms.Add(new SqlParameter("@IsClosed", false));
|
||
}
|
||
else
|
||
{
|
||
parms.Add(new SqlParameter("@IsClosed", true));
|
||
}
|
||
|
||
if (this.CurrUser.LoginProjectArea != null)
|
||
{
|
||
parms.Add(new SqlParameter("@ProjectArea", this.CurrUser.LoginProjectArea));
|
||
}
|
||
|
||
if (!string.IsNullOrEmpty(this.txtProjectCode.Text))
|
||
{
|
||
strSql += " and ProjectCode = @ProjectCode";
|
||
parms.Add(new SqlParameter("@ProjectCode", this.txtProjectCode.Text.Trim()));
|
||
}
|
||
|
||
if (!string.IsNullOrEmpty(this.txtProjectName.Text))
|
||
{
|
||
strSql += " and ProjectName LIKE @ProjectName";
|
||
parms.Add(new SqlParameter("@ProjectName", "%" + this.txtProjectName.Text.Trim() + "%"));
|
||
}
|
||
|
||
//if (this.CurrUser.Account != BLL.Const.Gly)
|
||
//{
|
||
// strSql += " and ProjectId = @ProjectId";
|
||
// parms.Add(new SqlParameter("@ProjectId", this.CurrUser.LoginProjectId));
|
||
//}
|
||
strSql += " order by ProjectCode";
|
||
|
||
SqlParameter[] parameter = parms.ToArray();
|
||
DataTable dt = SQLHelper.GetDataTableRunText(strSql, parameter);
|
||
|
||
Grid1.RecordCount = dt.Rows.Count;
|
||
var table = this.GetPagedDataTable(Grid1, dt);
|
||
|
||
Grid1.DataSource = table;
|
||
Grid1.DataBind();
|
||
}
|
||
|
||
/// <summary>
|
||
/// 查询
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
protected void btnQuery_Click(object sender, EventArgs e)
|
||
{
|
||
this.BindGrid();
|
||
}
|
||
|
||
#endregion
|
||
#endregion
|
||
|
||
#region 编辑/查看/删除数据
|
||
/// <summary>
|
||
/// 编辑
|
||
/// </summary>
|
||
private void EditData()
|
||
{
|
||
if (GetButtonPower(Const.BtnModify))
|
||
{
|
||
if (GetButtonPower(BLL.Const.BtnModify))
|
||
{
|
||
if (Grid1.SelectedRowIndexArray.Length == 0)
|
||
{
|
||
Alert.ShowInTop(Resources.Lan.SelectLeastOneRecord, MessageBoxIcon.Warning);
|
||
return;
|
||
}
|
||
string projectId = Grid1.SelectedRowID;
|
||
|
||
PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("ProjectEdit.aspx?ProjectId={0}", projectId, "编辑 - ")));
|
||
}
|
||
else
|
||
{
|
||
Alert.ShowInTop(Resources.Lan.NoPrivilegePrompt, MessageBoxIcon.Warning);
|
||
return;
|
||
}
|
||
}
|
||
else
|
||
{
|
||
ShowNotify(Resources.Lan.NoPrivilegePrompt, MessageBoxIcon.Warning);
|
||
return;
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// Grid行双击事件
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
protected void Grid1_RowDoubleClick(object sender, GridRowClickEventArgs e)
|
||
{
|
||
EditData();
|
||
}
|
||
|
||
/// <summary>
|
||
/// 右键编辑事件
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
protected void btnMenuEdit_Click(object sender, EventArgs e)
|
||
{
|
||
this.EditData();
|
||
}
|
||
|
||
/// <summary>
|
||
/// 查看
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
protected void btnMenuView_Click(object sender, EventArgs e)
|
||
{
|
||
if (GetButtonPower(Const.BtnSee))
|
||
{
|
||
PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("ProjectView.aspx?ProjectId={0}", Grid1.SelectedRowID, "查看 - ")));
|
||
}
|
||
else
|
||
{
|
||
ShowNotify(Resources.Lan.NoPrivilegePrompt, MessageBoxIcon.Warning);
|
||
return;
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 批量删除数据
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
protected void btnMenuDelete_Click(object sender, EventArgs e)
|
||
{
|
||
if (GetButtonPower(BLL.Const.BtnDelete))
|
||
{
|
||
if (Grid1.SelectedRowIndexArray.Length > 0)
|
||
{
|
||
string strShowNotify = string.Empty;
|
||
foreach (int rowIndex in Grid1.SelectedRowIndexArray)
|
||
{
|
||
string rowID = Grid1.DataKeys[rowIndex][0].ToString();
|
||
var project = BLL.Base_ProjectService.GetProjectByProjectId(rowID);
|
||
string content = judgementDelete(rowID);
|
||
|
||
if (string.IsNullOrEmpty(content))
|
||
{
|
||
BLL.Base_ProjectService.DeleteProject(rowID);
|
||
BLL.Sys_LogService.AddLog(Const.System_1, this.CurrUser.LoginProjectId, this.CurrUser.UserId, Const.ProjectTypeMenuId, Const.BtnDelete, rowID);
|
||
}
|
||
else
|
||
{
|
||
strShowNotify += Resources.Lan.Project + ":" + project.ProjectName + content;
|
||
}
|
||
}
|
||
|
||
if (!string.IsNullOrEmpty(strShowNotify))
|
||
{
|
||
Alert.ShowInTop(strShowNotify, MessageBoxIcon.Warning);
|
||
}
|
||
else
|
||
{
|
||
BindGrid();
|
||
ShowNotify(Resources.Lan.DeletedSuccessfully, MessageBoxIcon.Success);
|
||
}
|
||
}
|
||
}
|
||
else
|
||
{
|
||
ShowNotify(Resources.Lan.NoPrivilegePrompt, MessageBoxIcon.Warning);
|
||
return;
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 判断是否可以删除
|
||
/// </summary>
|
||
/// <returns></returns>
|
||
private string judgementDelete(string projectId)
|
||
{
|
||
string content = "";
|
||
|
||
if (Funs.DB.Pipeline_Pipeline.FirstOrDefault(x => x.ProjectId == projectId) != null)
|
||
{
|
||
content += "已在【管线信息】中使用,不能删除!";
|
||
}
|
||
return content;
|
||
}
|
||
#endregion
|
||
|
||
#region 分页/排序
|
||
/// <summary>
|
||
/// 分页
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
protected void Grid1_PageIndexChange(object sender, GridPageEventArgs e)
|
||
{
|
||
Grid1.PageIndex = e.NewPageIndex;
|
||
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();
|
||
}
|
||
|
||
/// <summary>
|
||
/// 排序
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
protected void Grid1_Sort(object sender, FineUIPro.GridSortEventArgs e)
|
||
{
|
||
Grid1.SortDirection = e.SortDirection;
|
||
Grid1.SortField = e.SortField;
|
||
BindGrid();
|
||
}
|
||
|
||
#endregion
|
||
|
||
#region 关闭窗口
|
||
/// <summary>
|
||
/// 关闭窗口
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
protected void Window1_Close(object sender, EventArgs e)
|
||
{
|
||
BindGrid();
|
||
}
|
||
#endregion
|
||
|
||
#region 增加
|
||
/// <summary>
|
||
/// 新增项目
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
protected void btnNew_Click(object sender, EventArgs e)
|
||
{
|
||
if (GetButtonPower(Const.BtnAdd))
|
||
{
|
||
PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("ProjectEdit.aspx", "新增项目")));
|
||
}
|
||
else
|
||
{
|
||
ShowNotify(Resources.Lan.NoPrivilegePrompt, MessageBoxIcon.Warning);
|
||
return;
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
#region 导出按钮
|
||
/// 导出按钮
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
protected void btnOut_Click(object sender, EventArgs e)
|
||
{
|
||
Response.ClearContent();
|
||
string filename = Funs.GetNewFileName();
|
||
Response.AddHeader("content-disposition", "attachment; filename=" + System.Web.HttpUtility.UrlEncode(Resources.Lan.ProjectInformation + filename, System.Text.Encoding.UTF8) + ".xls");
|
||
Response.ContentType = "application/excel";
|
||
Response.ContentEncoding = System.Text.Encoding.UTF8;
|
||
Response.Write(GetGridTableHtml(Grid1));
|
||
Response.End();
|
||
}
|
||
|
||
/// <summary>
|
||
/// 导出方法
|
||
/// </summary>
|
||
/// <param name="grid"></param>
|
||
/// <returns></returns>
|
||
private string GetGridTableHtml(Grid grid)
|
||
{
|
||
StringBuilder sb = new StringBuilder();
|
||
grid.PageSize = 10000;
|
||
BindGrid();
|
||
sb.Append("<meta http-equiv=\"content-type\" content=\"application/excel; charset=UTF-8\"/>");
|
||
sb.Append("<table cellspacing=\"0\" rules=\"all\" border=\"1\" style=\"border-collapse:collapse;\">");
|
||
sb.Append("<tr>");
|
||
foreach (GridColumn column in grid.Columns)
|
||
{
|
||
sb.AppendFormat("<td>{0}</td>", column.HeaderText);
|
||
}
|
||
sb.Append("</tr>");
|
||
foreach (GridRow row in grid.Rows)
|
||
{
|
||
sb.Append("<tr>");
|
||
foreach (GridColumn column in grid.Columns)
|
||
{
|
||
string html = row.Values[column.ColumnIndex].ToString();
|
||
if (column.ColumnID == "tfNumber")
|
||
{
|
||
html = (row.FindControl("labNumber") as AspNet.Label).Text;
|
||
}
|
||
sb.AppendFormat("<td>{0}</td>", html);
|
||
}
|
||
|
||
sb.Append("</tr>");
|
||
}
|
||
|
||
sb.Append("</table>");
|
||
|
||
return sb.ToString();
|
||
}
|
||
#endregion
|
||
|
||
#region 获取按钮权限
|
||
/// <summary>
|
||
/// 获取按钮权限
|
||
/// </summary>
|
||
/// <param name="button"></param>
|
||
/// <returns></returns>
|
||
private bool GetButtonPower(string button)
|
||
{
|
||
return BLL.CommonService.GetAllButtonPowerList(this.CurrUser.LoginProjectId, this.CurrUser.UserId, BLL.Const.ProjectMenuId, button);
|
||
}
|
||
#endregion
|
||
}
|
||
} |