CNCEC_SUBQHSE_WUHUAN/SGGL/FineUIPro.Web/JDGL/Check/MonthPlan.aspx.cs

184 lines
8.2 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using BLL;
using Newtonsoft.Json.Linq;
namespace FineUIPro.Web.JDGL.Check
{
public partial class MonthPlan : PageBase
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
GetButtonPower();
btnNew.OnClientClick = Window1.GetShowReference("MonthPlanEdit.aspx") + "return false;";
this.txtMonths.Text = string.Format("{0:yyyy-MM-dd}", DateTime.Now);
BindGrid();
}
}
#region
/// <summary>
/// 获取按钮权限
/// </summary>
/// <param name="button"></param>
/// <returns></returns>
private void GetButtonPower()
{
if (Request.Params["value"] == BLL.Const._Null)
{
return;
}
var buttonList = BLL.CommonService.GetAllButtonList(this.CurrUser.LoginProjectId, this.CurrUser.UserId, BLL.Const.MonthPlanMenuId);
if (buttonList.Count() > 0)
{
if (buttonList.Contains(BLL.Const.BtnSave))
{
this.btnNew.Hidden = false;
this.btnModify.Hidden = false;
this.btnMenuDel.Hidden = false;
}
}
}
#endregion
protected void btnModify_Click(object sender, EventArgs e)
{
PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("MonthPlanEdit.aspx?Months={0}", this.txtMonths.Text, "编辑 - ")));
}
/// <summary>
/// 加载Grid
/// </summary>
private void BindGrid()
{
string strSql = @"select qc.MonthPlanId,(select PlanNum from JDGL_MonthPlan where QuantityListId=ql.QuantityListId and Months=@month) as PlanNum,
(select RealNum from JDGL_MonthPlan where QuantityListId=ql.QuantityListId and Months=@month) as RealNum,
(select NextNum from JDGL_MonthPlan where QuantityListId=ql.QuantityListId and Months=@month) as NextNum,ql.DesignNum,ql.Name,ql.Unit,ql.SortIndex,
CONVERT(FLOAT, (select sum(ISNULL(PlanNum, 0)) from JDGL_MonthPlan where ProjectId = ql.ProjectId and QuantityListId = qc.QuantityListId and Months <= @month)) as TotalPlanNum,
CONVERT(FLOAT, (select sum(ISNULL(RealNum, 0)) from JDGL_MonthPlan where ProjectId = ql.ProjectId and QuantityListId = qc.QuantityListId and Months <= @month)) as TotalRealNum,
CONVERT(NVARCHAR(10), ((CAST(CASE ISNULL(qc.PlanNum, 0) WHEN 0 THEN 0
ELSE 100 * ISNULL(qc.RealNum, 0) / (1.0 * qc.PlanNum) END AS DECIMAL(9, 2))))) + '%'
AS Rate,
CONVERT(NVARCHAR(10), ((CAST(CASE(select sum(ISNULL(PlanNum, 0)) from JDGL_MonthPlan where ProjectId = ql.ProjectId and QuantityListId = qc.QuantityListId and Months <= @month) WHEN 0 THEN 0
ELSE 100 * (select sum(ISNULL(RealNum, 0)) from JDGL_MonthPlan where ProjectId = ql.ProjectId and QuantityListId = qc.QuantityListId and Months <= @month) / (1.0 * (select sum(ISNULL(PlanNum, 0)) from JDGL_MonthPlan where ProjectId = ql.ProjectId and QuantityListId = qc.QuantityListId and Months <= @month)) END AS DECIMAL(9, 2)))))+'%'
AS TotalRate,
CONVERT(NVARCHAR(10), ((CAST(CASE ISNULL(ql.DesignNum, 0) WHEN 0 THEN 0
ELSE 100 * (select sum(ISNULL(RealNum, 0)) from JDGL_MonthPlan where ProjectId = ql.ProjectId and QuantityListId = qc.QuantityListId and Months <= @month) / (1.0 * ql.DesignNum) END AS DECIMAL(9, 2)))))+'%'
AS SumRate,
CONVERT(FLOAT, (select sum(ISNULL(PlanNum, 0)) from JDGL_MonthPlan where ProjectId = ql.ProjectId and QuantityListId = qc.QuantityListId and Months < qc.Months)) as LastTotalPlanNum,
CONVERT(FLOAT, (select sum(ISNULL(RealNum, 0)) from JDGL_MonthPlan where ProjectId = ql.ProjectId and QuantityListId = qc.QuantityListId and Months < qc.Months)) as LastTotalRealNum
from[dbo].JDGL_QuantityList ql
left join dbo.[JDGL_MonthPlan] qc on ql.QuantityListId=qc.QuantityListId
where qc.MonthPlanId=(select top 1 MonthPlanId from[JDGL_MonthPlan] q where q.QuantityListId=qc.QuantityListId and q.Months<=@month order by q.Months desc) and qc.ProjectId=@ProjectId order by ql.SortIndex, ql.Name";
//string strSql = @"select *
// from dbo.View_JDGL_MonthPlan qc
// where qc.ProjectId=@ProjectId order by qc.SortIndex, qc.Name";
List<SqlParameter> listStr = new List<SqlParameter>();
listStr.Add(new SqlParameter("@ProjectId", this.CurrUser.LoginProjectId));
listStr.Add(new SqlParameter("@month", string.Format("{0:yyyy-MM-dd}", Convert.ToDateTime(this.txtMonths.Text.Trim() + "-01"))));
SqlParameter[] parameter = listStr.ToArray();
DataTable tb = SQLHelper.GetDataTableRunText(strSql, parameter);
Grid1.RecordCount = tb.Rows.Count;
//tb = GetFilteredTable(Grid1.FilteredData, tb);
var table = this.GetPagedDataTable(Grid1, tb);
Grid1.DataSource = table;
Grid1.DataBind();
}
#region
/// <summary>
/// 月份选择事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void txtMonths_TextChanged(object sender, EventArgs e)
{
BindGrid();
}
#endregion
#region
/// <summary>
/// 保存按钮
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnSave_Click(object sender, EventArgs e)
{
if (this.Grid1.Rows.Count > 0)
{
JArray mergedData = Grid1.GetMergedData();
foreach (JObject mergedRow in mergedData)
{
JObject values = mergedRow.Value<JObject>("values");
int i = mergedRow.Value<int>("index");
Model.JDGL_MonthPlan MonthPlan = BLL.MonthPlanService.GetMonthPlanById(this.Grid1.Rows[i].RowID);
if (MonthPlan != null)
{
MonthPlan.CompileMan = this.CurrUser.UserId;
MonthPlan.CompileDate = DateTime.Now;
BLL.MonthPlanService.UpdateMonthPlan(MonthPlan);
}
}
Alert.ShowInTop("保存成功!", MessageBoxIcon.Success);
}
else
{
Alert.ShowInTop("请至少选择一条记录!", MessageBoxIcon.Warning);
return;
}
}
#endregion
protected void btnMenuDel_Click(object sender, EventArgs e)
{
if (Grid1.SelectedRowIndexArray.Length > 0)
{
foreach (int rowIndex in Grid1.SelectedRowIndexArray)
{
string rowID = Grid1.DataKeys[rowIndex][0].ToString();
BLL.MonthPlanService.DeleteMonthPlanByMonthPlanId(rowID);
}
BindGrid();
ShowNotify("删除数据成功!", MessageBoxIcon.Success);
}
}
#region
/// <summary>
/// 导入按钮
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnImport_Click(object sender, EventArgs e)
{
PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("MonthPlanIn.aspx?ProjectId={0}", this.CurrUser.LoginProjectId, "导入 - ")));
}
/// <summary>
/// 关闭导入弹出窗口
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Window1_Close(object sender, WindowCloseEventArgs e)
{
BindGrid();
}
#endregion
}
}