SGGL_SHJ/SGGL/FineUIPro.Web/PHTGL/ContractCompile/Contract.aspx.cs

240 lines
8.0 KiB
C#

using BLL;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
namespace FineUIPro.Web.PHTGL.ContractCompile
{
public partial class Contract : PageBase
{
#region
/// <summary>
/// 加载页面
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
Funs.DropDownPageSize(this.ddlPageSize);
btnNew.OnClientClick = Window1.GetShowReference("ContractEdit.aspx", "基本信息") + "return false;";
GetButtonPower();
BindGrid();
}
}
/// <summary>
/// 数据绑定
/// </summary>
private void BindGrid()
{
string strSql = @"SELECT Con.ContractId, Con.ProjectId, Con.ContractName, Con.ContractNum, Con.Parties, Con.Currency, Con.ContractAmount, Con.DepartId,
Con.Agent, (CASE Con.ContractType WHEN '1' THEN '施工总承包分包合同' WHEN '2' THEN '施工专业分包合同' WHEN '3' THEN '上官红劳务分包合同' WHEN '4' THEN '试车服务合同'
WHEN '5' THEN '租赁合同' END) AS ContractType,Con.Remarks,Pro.ProjectCode,Pro.ProjectName,Dep.DepartName,U.PersonName AS AgentName"
+ @" FROM PHTGL_Contract AS Con"
+ @" LEFT JOIN Base_Project AS Pro ON Pro.ProjectId = Con.ProjectId"
+ @" LEFT JOIN Base_Depart AS Dep ON Dep.DepartId = Con.DepartId"
+ @" LEFT JOIN Person_Persons AS U ON U.PersonId = Con.Agent WHERE 1=1 ";
List<SqlParameter> listStr = new List<SqlParameter>();
if (!string.IsNullOrEmpty(this.txtContractName.Text.Trim()))
{
strSql += " AND Con.ContractName LIKE @ContractName";
listStr.Add(new SqlParameter("@ContractName", "%" + this.txtContractName.Text.Trim() + "%"));
}
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
/// <summary>
/// 改变索引事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Grid1_PageIndexChange(object sender, GridPageEventArgs e)
{
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)
{
BindGrid();
}
#endregion
#region
/// <summary>
/// 关闭弹出窗体
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Window1_Close(object sender, WindowCloseEventArgs e)
{
BindGrid();
}
#endregion
#region
/// <summary>
/// 查询按钮
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnSearch_Click(object sender, EventArgs e)
{
BindGrid();
}
#endregion
#region
/// <summary>
/// 双击事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Grid1_RowDoubleClick(object sender, GridRowClickEventArgs e)
{
this.EditData();
}
/// <summary>
/// 右键编辑事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnMenuEdit_Click(object sender, EventArgs e)
{
this.EditData();
}
/// <summary>
/// 编辑数据方法
/// </summary>
private void EditData()
{
if (Grid1.SelectedRowIndexArray.Length == 0)
{
Alert.ShowInTop("请至少选择一条记录!", MessageBoxIcon.Warning);
return;
}
string id = Grid1.SelectedRowID;
var contract = BLL.ContractService.GetContractById(id);
if (contract != null)
{
PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("ContractEdit.aspx?ContractId={0}", id, "编辑 - ")));
}
}
#endregion
#region
/// <summary>
/// 右键删除事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnMenuDelete_Click(object sender, EventArgs e)
{
if (Grid1.SelectedRowIndexArray.Length > 0)
{
bool isShow = false;
if (Grid1.SelectedRowIndexArray.Length == 1)
{
isShow = true;
}
foreach (int rowIndex in Grid1.SelectedRowIndexArray)
{
string rowID = Grid1.DataKeys[rowIndex][0].ToString();
if (this.judgementDelete(rowID, isShow))
{
var p = BLL.ContractService.GetContractById(rowID);
if (p != null)
{
BLL.LogService.AddSys_Log(this.CurrUser, p.ContractName, p.ContractId, BLL.Const.ContractMenuId, BLL.Const.BtnDelete);
BLL.ContractService.DeleteContractById(rowID);
}
}
}
BindGrid();
ShowNotify("删除数据成功!", MessageBoxIcon.Success);
}
}
/// <summary>
/// 判断是否可以删除
/// </summary>
/// <returns></returns>
private bool judgementDelete(string id, bool isShow)
{
string content = string.Empty;
if (string.IsNullOrEmpty(content))
{
return true;
}
else
{
if (isShow)
{
Alert.ShowInTop(content);
}
return false;
}
}
#endregion
#region
/// <summary>
/// 获取按钮权限
/// </summary>
/// <param name="button"></param>
/// <returns></returns>
private void GetButtonPower()
{
if (Request.Params["value"] == "0")
{
return;
}
var buttonList = CommonService.GetAllButtonList(CurrUser.LoginProjectId, CurrUser.PersonId, Const.ContractMenuId);
if (buttonList.Count() > 0)
{
if (buttonList.Contains(Const.BtnAdd))
{
btnNew.Hidden = false;
}
if (buttonList.Contains(Const.BtnModify))
{
btnMenuEdit.Hidden = false;
}
if (buttonList.Contains(Const.BtnDelete))
{
btnMenuDelete.Hidden = false;
}
}
}
#endregion
}
}