using BLL; using Model; using Newtonsoft.Json.Linq; using System; using System.Collections.Generic; using System.Data; using System.Data.SqlClient; using System.Linq; namespace FineUIPro.Web.DataShow { public partial class SecurityCost : PageBase { #region 加载页面 /// /// 加载页面 /// /// /// protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { Funs.DropDownPageSize(this.ddlPageSize); ddlPageSize.SelectedValue = Grid1.PageSize.ToString(); BLL.ProjectService.InitProjectDropDownList(this.drpProject, true); // 绑定表格t BindGrid(); // 合计 OutputSummaryData(); this.Panel1.Title = "安全费用(" + BLL.UnitService.GetUnitNameByUnitId(BLL.CommonService.GetThisUnitId()) + ")"; } } /// /// 绑定数据 /// private void BindGrid() { string strSql = string.Empty; List listStr = new List(); strSql = @"SELECT cost.CostSmallDetailId, p.ProjectId,p.ProjectCode,p.ProjectName,cost.UnitId,Unit.UnitName,cost.Months ,(CAST((SELECT SUM(ISNULL(CostMoney,0)) FROM CostGoods_CostSmallDetailItem WHERE CostSmallDetailId=cost.CostSmallDetailId) *1.0 /10000 as decimal(18, 2) ))AS SUMCost FROM CostGoods_CostSmallDetail as cost left join Base_Project as p on cost.ProjectId =p.ProjectId left join Base_Unit as Unit on cost.UnitId =Unit.UnitId WHERE cost.CompileDate > '2023-01-01'and (p.ProjectState2 is null or p.ProjectState2 !=9) "; if (this.drpProject.SelectedValue != Const._Null) { strSql += " AND cost.ProjectId = @ProjectId"; listStr.Add(new SqlParameter("@ProjectId", this.drpProject.SelectedValue)); } if (!string.IsNullOrEmpty(this.txtStartTime.Text)) { strSql += " AND cost.Months >=@StartTime"; listStr.Add(new SqlParameter("@StartTime", this.txtStartTime.Text)); } if (!string.IsNullOrEmpty(this.txtEndTime.Text)) { strSql += " AND cost.Months <=@EndTime"; listStr.Add(new SqlParameter("@EndTime", this.txtEndTime.Text)); } 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 查询 /// /// 查询 /// /// /// protected void TextBox_TextChanged(object sender, EventArgs e) { this.BindGrid(); } #endregion #region 表排序、分页、关闭窗口 /// /// 分页 /// /// /// protected void Grid1_PageIndexChange(object sender, GridPageEventArgs e) { BindGrid(); } /// /// 排序 /// /// /// protected void Grid1_Sort(object sender, GridSortEventArgs e) { BindGrid(); } /// /// 分页显示条数下拉框 /// /// /// protected void ddlPageSize_SelectedIndexChanged(object sender, EventArgs e) { Grid1.PageSize = Convert.ToInt32(ddlPageSize.SelectedValue); BindGrid(); } /// /// 关闭弹出窗 /// /// /// protected void Window1_Close(object sender, WindowCloseEventArgs e) { BindGrid(); } #endregion #region Grid双击事件 编辑 /// /// Grid行双击事件 /// /// /// protected void Grid1_RowDoubleClick(object sender, GridRowClickEventArgs e) { EditData(); } /// /// /// private void EditData() { if (Grid1.SelectedRowIndexArray.Length == 0) { Alert.ShowInTop("请至少选择一条记录!", MessageBoxIcon.Warning); return; } PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("../HSSE/CostGoods/CostSmallDetailView.aspx?CostSmallDetailId={0}", Grid1.SelectedRowID, "查看 - "))); } #endregion protected void btnView_Click(object sender, EventArgs e) { EditData(); } #region 合计 private void OutputSummaryData() { string strSql = string.Empty; List listStr = new List(); strSql = @"SELECT cost.CostSmallDetailId, p.ProjectId,p.ProjectCode,p.ProjectName,cost.UnitId,Unit.UnitName,cost.Months ,(CAST((SELECT SUM(ISNULL(CostMoney,0)) FROM CostGoods_CostSmallDetailItem WHERE CostSmallDetailId=cost.CostSmallDetailId) *1.0 /10000 as decimal(18, 2) ))AS SUMCost FROM CostGoods_CostSmallDetail as cost left join Base_Project as p on cost.ProjectId =p.ProjectId left join Base_Unit as Unit on cost.UnitId =Unit.UnitId WHERE (p.ProjectState2 is null or p.ProjectState2 !=9) and cost.CompileDate > '2023-01-01'"; SqlParameter[] parameter = listStr.ToArray(); DataTable tb = SQLHelper.GetDataTableRunText(strSql, parameter); float SUMCost = 0.0f; foreach (DataRow row in tb.Rows) { SUMCost += float.Parse(row["SUMCost"].ToString()); } JObject summary = new JObject(); summary.Add("Months", "合计:"); summary.Add("SUMCost", SUMCost.ToString("F2")); Grid1.SummaryData = summary; } #endregion } }