172 lines
6.6 KiB
C#
172 lines
6.6 KiB
C#
using FineUIPro;
|
|
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
|
|
|
|
namespace BLL
|
|
{
|
|
|
|
public static class Information_EnvironmentalDataService
|
|
{
|
|
public static Model.SGGLDB db = Funs.DB;
|
|
|
|
|
|
#region 获取列表
|
|
/// <summary>
|
|
/// 记录数
|
|
/// </summary>
|
|
public static int count
|
|
{
|
|
get;
|
|
set;
|
|
}
|
|
public static List<Model.Information_EnvironmentalData> GetInformation_EnvironmentalDataByModle(Model.Information_EnvironmentalData table)
|
|
{
|
|
var q = from x in db.Information_EnvironmentalData
|
|
where
|
|
(string.IsNullOrEmpty(table.Id) || x.Id.Contains(table.Id)) &&
|
|
(string.IsNullOrEmpty(table.UnitId) || x.UnitId.Contains(table.UnitId)) &&
|
|
(string.IsNullOrEmpty(table.CreateMan) || x.CreateMan.Contains(table.CreateMan))
|
|
select x
|
|
;
|
|
|
|
return q.ToList();
|
|
}
|
|
|
|
/// 获取分页列表
|
|
/// </summary>
|
|
/// <param name="PageIndex">页码</param>
|
|
/// <param name="PageSize">每页数量</param>
|
|
/// <returns></returns>
|
|
public static IEnumerable getListData(Model.Information_EnvironmentalData table, Grid Grid1)
|
|
{
|
|
var q = GetInformation_EnvironmentalDataByModle(table);
|
|
count = q.Count();
|
|
if (count == 0)
|
|
{
|
|
return null;
|
|
}
|
|
// q= q.Take(Grid1.PageSize * Grid1.PageIndex).Skip(Grid1.PageSize * (Grid1.PageIndex)).ToList();
|
|
// q = SortConditionHelper.SortingAndPaging(q, Grid1.SortField, Grid1.SortDirection, Grid1.PageIndex, Grid1.PageSize);
|
|
return from x in q
|
|
select new
|
|
{
|
|
x.Id,
|
|
UnitName=BLL.UnitService.GetUnitNameByUnitId(x.UnitId) ,
|
|
x.TotalEnergyConsumption,
|
|
x.IncomeComprehensiveEnergyConsumption,
|
|
x.NewWaterConsumption,
|
|
x.ReportDate,
|
|
CreateMan= UserService.GetUserNameByUserId(x.CreateMan),
|
|
x.CreateDate,
|
|
|
|
};
|
|
}
|
|
#endregion
|
|
|
|
public static Model.Information_EnvironmentalData GetInformation_EnvironmentalDataById(string Id)
|
|
{
|
|
return db.Information_EnvironmentalData.FirstOrDefault(x => x.Id == Id);
|
|
}
|
|
public static Model.Information_EnvironmentalData GetInformation_EnvironmentalDataByReportDate(DateTime ReportDate)
|
|
{
|
|
var q= (from x in db.Information_EnvironmentalData where x.ReportDate.Value.Year.ToString()==ReportDate.Year.ToString() && x.ReportDate.Value.Month.ToString() == ReportDate.Month.ToString() select x).FirstOrDefault();
|
|
return q;
|
|
}
|
|
public static bool IsExitDataByReportDate(DateTime? ReportDate)
|
|
{
|
|
bool result = false;
|
|
var q = (from x in db.Information_EnvironmentalData where x.ReportDate.Value.Year.ToString() == ReportDate.Value.Year.ToString() && x.ReportDate.Value.Month.ToString() == ReportDate.Value.Month.ToString() select x).FirstOrDefault();
|
|
if (q != null)
|
|
{
|
|
result = true;
|
|
}
|
|
return result;
|
|
}
|
|
public static int GetLatstTimeTotalEnergyConsumption()
|
|
{
|
|
int? result = 0;
|
|
var q = (from x in db.Information_EnvironmentalData orderby x.ReportDate descending select x).FirstOrDefault();
|
|
if (q!=null)
|
|
{
|
|
result= q.TotalEnergyConsumption;
|
|
}
|
|
return (int)result;
|
|
|
|
}
|
|
public static int GetLatstTimeIncomeComprehensiveEnergyConsumption()
|
|
{
|
|
int? result = 0;
|
|
var q = (from x in db.Information_EnvironmentalData orderby x.ReportDate descending select x).FirstOrDefault();
|
|
if (q != null)
|
|
{
|
|
result = q.IncomeComprehensiveEnergyConsumption;
|
|
}
|
|
return (int)result;
|
|
|
|
}
|
|
public static int GetLatstTimeNewWaterConsumption()
|
|
{
|
|
int? result = 0;
|
|
var q = (from x in db.Information_EnvironmentalData orderby x.ReportDate descending select x).FirstOrDefault();
|
|
if (q != null)
|
|
{
|
|
result = q.NewWaterConsumption;
|
|
}
|
|
return (int)result;
|
|
|
|
}
|
|
public static void AddInformation_EnvironmentalData(Model.Information_EnvironmentalData newtable)
|
|
{
|
|
|
|
Model.Information_EnvironmentalData table = new Model.Information_EnvironmentalData
|
|
{
|
|
Id = newtable.Id,
|
|
UnitId = newtable.UnitId,
|
|
TotalEnergyConsumption = newtable.TotalEnergyConsumption,
|
|
IncomeComprehensiveEnergyConsumption = newtable.IncomeComprehensiveEnergyConsumption,
|
|
NewWaterConsumption = newtable.NewWaterConsumption,
|
|
ReportDate = newtable.ReportDate,
|
|
CreateMan = newtable.CreateMan,
|
|
CreateDate = newtable.CreateDate,
|
|
};
|
|
db.Information_EnvironmentalData.InsertOnSubmit(table);
|
|
db.SubmitChanges();
|
|
}
|
|
|
|
|
|
public static void UpdateInformation_EnvironmentalData(Model.Information_EnvironmentalData newtable)
|
|
{
|
|
|
|
Model.Information_EnvironmentalData table = db.Information_EnvironmentalData.FirstOrDefault(x => x.Id == newtable.Id);
|
|
if (table != null)
|
|
{
|
|
table.Id = newtable.Id;
|
|
table.UnitId = newtable.UnitId;
|
|
table.TotalEnergyConsumption = newtable.TotalEnergyConsumption;
|
|
table.IncomeComprehensiveEnergyConsumption = newtable.IncomeComprehensiveEnergyConsumption;
|
|
table.NewWaterConsumption = newtable.NewWaterConsumption;
|
|
table.ReportDate = newtable.ReportDate;
|
|
table.CreateMan = newtable.CreateMan;
|
|
table.CreateDate = newtable.CreateDate;
|
|
db.SubmitChanges();
|
|
}
|
|
|
|
}
|
|
public static void DeleteInformation_EnvironmentalDataById(string Id)
|
|
{
|
|
|
|
Model.Information_EnvironmentalData table = db.Information_EnvironmentalData.FirstOrDefault(x => x.Id == Id);
|
|
if (table != null)
|
|
{
|
|
db.Information_EnvironmentalData.DeleteOnSubmit(table);
|
|
db.SubmitChanges();
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
} |