ViewBlock _getProjectViewBlock(DataTable dataSource, int belongYear) { var result = new ViewBlock(); var obj = dataSource.Compute("Sum(DataValue)", " BelongYear = '" + belongYear + "'"); result.Main = obj != null && obj != DBNull.Value ? Math.Round(Convert.ToDecimal(obj), 2) : 0; var lastYear = belongYear - 1; obj = dataSource.Compute("Sum(DataValue)", " BelongYear = '" + lastYear + "' and BelongMonth<='" + DateTime.Now.Month + "'"); var lastYearValue = obj != null && obj != DBNull.Value ? Convert.ToDecimal(obj) : 0; result.SubAreaTip = "去年同期:{0};同比{1}:{2}"; var scale = lastYearValue == 0 ? 100 : Math.Round((result.Main - lastYearValue) / lastYearValue * 100, 0); result.Sub = Math.Round(scale); if (result.Sub > 0) { result.SubAreaTip = String.Format(result.SubAreaTip, lastYearValue, "上升", Math.Abs(scale) + "%"); } else { result.SubAreaTip = String.Format(result.SubAreaTip, lastYearValue, "下降", Math.Abs(scale) + "%"); } obj = dataSource.Compute("Sum(DataValue)", ""); result.SubRight = obj != null && obj != DBNull.Value ? Math.Round(Convert.ToDecimal(obj), 2) : 0; obj = dataSource.Compute("Sum(DataValue)", " SignContractCount>0 "); var value = obj != null && obj != DBNull.Value ? Math.Round(Convert.ToDecimal(obj), 2) : 0; result.progressMain = result.SubRight == 0 ? 0 : Math.Round(value / result.SubRight * 100, 0); obj = dataSource.Compute("Sum(DataValue)", " State in ('" + ProjectState.Create.ToString() + "','" + ProjectState.Plan.ToString() + "','" + ProjectState.Execute.ToString() + "') "); value = obj != null && obj != DBNull.Value ? Math.Round(Convert.ToDecimal(obj)) : 0; result.SubViewBlockList.Add(this._createSubViewBlock(value.ToString(), "在建项目数", "个", 100)); obj = dataSource.Compute("Sum(DataValue)", " SignContractCount=0 "); value = obj != null && obj != DBNull.Value ? Math.Round(Convert.ToDecimal(obj)) : 0; result.SubViewBlockList.Add(this._createSubViewBlock(value.ToString(), "未签约项目数", "个", 200)); obj = dataSource.Compute("Sum(DataValue)", " State in ('" + ProjectState.Pause.ToString() + "','" + ProjectState.Terminate.ToString() + "') "); value = obj != null && obj != DBNull.Value ? Math.Round(Convert.ToDecimal(obj)) : 0; result.SubViewBlockList.Add(this._createSubViewBlock(value.ToString(), "暂停项目数", "个", 300)); return(result); }
ViewBlock _getViewBlock(DataTable indicatorDt, DataTable dataSource, int belongYear, string indicatorField, string title = "", bool formatCurreny = true) { var result = new ViewBlock(); var obj = dataSource.Compute("Sum(DataValue)", " BelongYear = '" + belongYear + "' and BelongMonth<='" + DateTime.Now.Month + "'"); result.Main = obj != null && obj != DBNull.Value ? Math.Round(Convert.ToDecimal(obj), 2) : 0; if (formatCurreny) { result.Main = Math.Round(result.Main / 10000, 2); } var lastYear = belongYear - 1; obj = dataSource.Compute("Sum(DataValue)", " BelongYear = '" + lastYear + "' and BelongMonth<='" + DateTime.Now.Month + "'"); var lastYearValue = obj != null && obj != DBNull.Value ? Convert.ToDecimal(obj) : 0; if (formatCurreny) { lastYearValue = Math.Round(lastYearValue / 10000, 2); } result.SubAreaTip = "去年同期:{0};同比{1}:{2}"; var scale = lastYearValue == 0 ? 100 : Math.Round((result.Main - lastYearValue) / lastYearValue * 100, 0); result.Sub = Math.Round(scale); if (result.Sub > 0) { result.SubAreaTip = String.Format(result.SubAreaTip, lastYearValue, "上升", Math.Abs(scale) + "%"); } else { result.SubAreaTip = String.Format(result.SubAreaTip, lastYearValue, "下降", Math.Abs(scale) + "%"); } if (indicatorDt.Rows.Count > 0) { var objSubRight = indicatorDt.Compute("sum(" + indicatorField + ")", ""); if (objSubRight != null && objSubRight != DBNull.Value) { result.SubRight = Math.Round(Convert.ToDecimal(objSubRight), 0); } //result.SubRight = indicatorDt.Rows[0][indicatorField] == null || indicatorDt.Rows[0][indicatorField] == DBNull.Value ? 0 : //Math.Round(Convert.ToDecimal(indicatorDt.Rows[0][indicatorField]), 0); } else { result.SubRight = 0; } if (formatCurreny) { result.SubRight = result.SubRight / 10000; } result.progressMain = result.SubRight == 0 ? 0 : Math.Round(result.Main / result.SubRight * 100); result.progressSub = Math.Round(Convert.ToDecimal(DateTime.Now.DayOfYear) / 365 * 100); obj = dataSource.Compute("Sum(DataValue)", " BelongYear = '" + belongYear + "' and BelongQuarter='" + MarketHelper.GetQuarter(DateTime.Now) + "'"); var subValue = obj == null || obj == DBNull.Value ? 0 : Math.Round(Convert.ToDecimal(obj), 2); if (formatCurreny) { subValue = Math.Round(subValue / 10000, 2); } var quater = this._createSubViewBlock(subValue.ToString(), "本季度" + title, "万元", 100); result.SubViewBlockList.Add(this._createSubViewBlock(subValue.ToString(), "本季度" + title, "万元", 100)); obj = dataSource.Compute("Sum(DataValue)", " BelongYear = '" + belongYear + "' and BelongMonth='" + DateTime.Now.Month + "'"); subValue = obj == null || obj == DBNull.Value ? 0 : Math.Round(Convert.ToDecimal(obj), 2); if (formatCurreny) { subValue = Math.Round(subValue / 10000, 2); } result.SubViewBlockList.Add(this._createSubViewBlock(subValue.ToString(), "本月" + title, "万元", 100)); var lastMonth = DateTime.Now.Month == 1 ? 12 : DateTime.Now.Month - 1; if (lastMonth == 12) { obj = dataSource.Compute("Sum(DataValue)", " BelongYear = '" + lastYear + "' and BelongMonth='" + lastMonth + "'"); } else { obj = dataSource.Compute("Sum(DataValue)", " BelongYear = '" + belongYear + "' and BelongMonth='" + lastMonth + "'"); } subValue = obj == null || obj == DBNull.Value ? 0 : Math.Round(Convert.ToDecimal(obj), 2); if (formatCurreny) { subValue = Math.Round(subValue / 10000, 2); } result.SubViewBlockList.Add(this._createSubViewBlock(subValue.ToString(), "上月" + title, "万元", 100)); return(result); }