ChengDa_English/SGGL/BLL/ZHGL/DataSync/ProjectDataSync/Project_HJGLData_DefectServ...

260 lines
9.7 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using FineUIPro;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace BLL
{
public static class Project_HJGLData_DefectService
{
public static Model.SGGLDB db = Funs.DB;
#region
/// <summary>
/// 记录数
/// </summary>
public static int count
{
get;
set;
}
public static List<Model.Project_HJGLData_Defect> GetProject_HJGLData_DefectByModle(Model.Project_HJGLData_Defect table)
{
var q = from x in db.Project_HJGLData_Defect
where
(string.IsNullOrEmpty(table.Id) || x.Id.Contains(table.Id)) &&
(string.IsNullOrEmpty(table.ProjectId) || x.Id.Contains(table.ProjectId)) &&
(string.IsNullOrEmpty(table.UnitId) || x.UnitId.Contains(table.UnitId)) &&
(string.IsNullOrEmpty(table.CollCropCode) || x.CollCropCode.Contains(table.CollCropCode)) &&
(string.IsNullOrEmpty(table.UnitName) || x.UnitName.Contains(table.UnitName)) &&
(string.IsNullOrEmpty(table.DefectName) || x.DefectName.Contains(table.DefectName))
select x
;
return q.ToList();
}
/// 获取分页列表
/// </summary>
/// <param name="PageIndex">页码</param>
/// <param name="PageSize">每页数量</param>
/// <returns></returns>
public static IEnumerable getListData(Model.Project_HJGLData_Defect table, Grid Grid1)
{
var q = GetProject_HJGLData_DefectByModle(table);
count = q.Count();
if (count == 0)
{
return null;
}
// q = SortConditionHelper.SortingAndPaging(q, Grid1.SortField, Grid1.SortDirection, Grid1.PageIndex, Grid1.PageSize);
return from x in q
select new
{
x.Id,
x.ProjectId,
x.UnitId,
x.CollCropCode,
x.UnitName,
x.ReportDate,
x.DefectName,
x.DefectNum,
};
}
#endregion
public static Model.Project_HJGLData_Defect GetProject_HJGLData_DefectById(string Id)
{
return db.Project_HJGLData_Defect.FirstOrDefault(x => x.Id == Id);
}
/// <summary>
/// 获取项目该日期的缺陷分析数据
/// </summary>
/// <param name="reportDate"></param>
/// <param name="projectid"></param>
/// <returns></returns>
public static List<Model.Project_HJGLData_Defect> GetProject_HJGLData_DefectByDate(DateTime? reportDate, string projectid)
{
var q = from x in db.Project_HJGLData_Defect
where x.ReportDate.Value.Date.CompareTo(reportDate.Value.Date) == 0 && x.ProjectId == projectid
select x;
return q.ToList();
}
public static void AddProject_HJGLData_Defect(Model.Project_HJGLData_Defect newtable)
{
Model.Project_HJGLData_Defect table = new Model.Project_HJGLData_Defect
{
Id = newtable.Id,
ProjectId = newtable.ProjectId,
UnitId = newtable.UnitId,
CollCropCode = newtable.CollCropCode,
UnitName = newtable.UnitName,
ReportDate = newtable.ReportDate,
DefectName = newtable.DefectName,
DefectNum = newtable.DefectNum,
};
db.Project_HJGLData_Defect.InsertOnSubmit(table);
db.SubmitChanges();
}
public static void UpdateProject_HJGLData_Defect(Model.Project_HJGLData_Defect newtable)
{
Model.Project_HJGLData_Defect table = db.Project_HJGLData_Defect.FirstOrDefault(x => x.Id == newtable.Id);
if (table != null)
{
table.Id = newtable.Id;
table.ProjectId = newtable.ProjectId;
table.UnitId = newtable.UnitId;
table.CollCropCode = newtable.CollCropCode;
table.UnitName = newtable.UnitName;
table.ReportDate = newtable.ReportDate;
table.DefectName = newtable.DefectName;
table.DefectNum = newtable.DefectNum;
db.SubmitChanges();
}
}
public static void DeleteProject_HJGLData_DefectById(string Id)
{
Model.Project_HJGLData_Defect table = db.Project_HJGLData_Defect.FirstOrDefault(x => x.Id == Id);
if (table != null)
{
db.Project_HJGLData_Defect.DeleteOnSubmit(table);
db.SubmitChanges();
}
}
public static void DeleteProject_HJGLData_DefectByDate(DateTime? reportDate, string projectid)
{
var table = db.Project_HJGLData_Defect.Where(x => x.ReportDate.Value.Date.CompareTo(reportDate.Value.Date) == 0 && x.ProjectId == projectid);
if (table != null)
{
db.Project_HJGLData_Defect.DeleteAllOnSubmit(table);
db.SubmitChanges();
}
}
/// <summary>
/// 判断当天是否已统计数据
/// </summary>
/// <returns></returns>
public static bool IsReportByToday(string projectid, string type)
{
var result = false;
var q = (from x in Funs.DB.Project_HJGLData_Defect
where x.ReportDate < DateTime.Now.AddDays(1).Date && x.ReportDate >= DateTime.Now.Date && x.ProjectId == projectid && x.DefectName == type
select x).ToList();
if (q != null && q.Count > 0)
{
result = true;
}
return result;
}
/// <summary>
/// 根据projectid获取当天的统计后的数据
/// </summary>
/// <param name="projectid"></param>
/// <returns></returns>
public static Model.Project_HJGLData_Defect getTodayProject_HJGLData_Defect(string projectid, string type)
{
var q = (from x in Funs.DB.Project_HJGLData_Defect
where x.ReportDate < DateTime.Now.AddDays(1).Date && x.ReportDate >= DateTime.Now.Date && x.ProjectId == projectid && x.DefectName == type
select x).FirstOrDefault();
return q;
}
public static List<Model.HJGLDataDefectItems> getTodayProject_HJGLData_Defect()
{
var q = (from x in Funs.DB.Project_HJGLData_Defect
where x.ReportDate < DateTime.Now.AddDays(1).Date && x.ReportDate >= DateTime.Now.Date
group x by x.DefectName into g
select new Model.HJGLDataDefectItems
{
Id = SQLHelper.GetNewID(),
DefectName = g.Key,
DefectNum=g.Sum (p=>p.DefectNum)
}).ToList();
return q;
}
/// <summary>
/// 统计所有在建项目数据
/// </summary>
public static void StatisticalAllProjectData()
{
var projectlist = ProjectService.GetProjectWorkList();
foreach (var item in projectlist)
{
StatisticalData(item.ProjectId);
}
}
/// <summary>
/// 统计数据
/// </summary>
/// <param name="projectid"></param>
public static void StatisticalData(string projectid)
{
string thisUnitId = BLL.Const.UnitId_CD;
var base_Unit = BLL.UnitService.GetUnitByUnitId(thisUnitId);
var list = from x in db.CH_CheckItem
join y in db.CH_Check on x.CHT_CheckID equals y.CHT_CheckID
where y.ProjectId == projectid
select x;
var types = (from x in list select x.Defects_Definition).Distinct().ToList();
foreach (var t in types)
{
if (!string.IsNullOrEmpty(t))
{
Model.Project_HJGLData_Defect table = new Model.Project_HJGLData_Defect
{
UnitId = thisUnitId,
CollCropCode = base_Unit.CollCropCode,
UnitName = base_Unit.UnitName,
ProjectId = projectid,
ReportDate = DateTime.Now.Date,
DefectName = t,
DefectNum = list.Count(x => x.Defects_Definition == t),
};
if (IsReportByToday(projectid, t))
{
table.Id = getTodayProject_HJGLData_Defect(projectid, t).Id;
UpdateProject_HJGLData_Defect(table);
}
else
{
table.Id = SQLHelper.GetNewID();
AddProject_HJGLData_Defect(table);
}
}
}
}
/// <summary>
/// 获取缺陷名称
/// </summary>
/// <returns></returns>
public static string GetDefectName(string projectid)
{
string result = "";
return result;
}
/// <summary>
/// 获取缺陷数量
/// </summary>
/// <returns></returns>
public static int GetDefectNum(string projectid)
{
int result = 0;
return result;
}
}
}