using FineUIPro;
using Model;
using Newtonsoft.Json;
using NPOI.POIFS.Crypt.Dsig;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
namespace BLL
{
public static class CQMSDataService
{
public static Model.SGGLDB db = Funs.DB;
///
/// 集团接口地址
///
public static string CNCECServerUrl
{
get;
set;
}
#region 获取列表
///
/// 记录数
///
public static int count
{
get;
set;
}
public static List GetCQMSData_CQMSByModle(Model.CQMSData_CQMS table)
{
Model.SGGLDB db = Funs.DB;
var q = from x in db.CQMSData_CQMS
where
(string.IsNullOrEmpty(table.Id) || x.Id.Contains(table.Id)) &&
(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))
orderby x.ReportDate descending
select x
;
return q.ToList();
}
/// 获取分页列表
///
/// 页码
/// 每页数量
///
public static IEnumerable getListData(Model.CQMSData_CQMS table, Grid Grid1)
{
var q = GetCQMSData_CQMSByModle(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,
x.UnitId,
x.CollCropCode,
x.UnitName,
x.ReportDate,
x.TrainPersonNum,
x.TechnicalDisclosePersonNum,
x.UseNum,
x.OKNum,
x.CompanyPersonNum,
x.BranchPersonNum,
x.ProjectPersonNum,
x.ProblemNum,
x.ProblemCompletedNum,
x.ProblemNotCompletedNum,
x.SNum,
x.ANum,
x.BNum,
x.CNum,
x.KeyProcessNum,
x.KeyProcessOKNum,
x.SpecialProcessNum,
x.SpecialProcessOKNum,
x.ConcealedWorksNum,
x.ConcealedWorksOKNum,
x.UnitProjectOnesNum,
x.UnitProjectOnesOKNum,
x.MaterialInRecheckNum,
x.MaterialInRecheckOKNum,
x.SingleProjectNum,
x.UnitProjectNum,
x.SubProjectNum,
x.SubdivisionalWorksNum,
x.InspectionLotNum,
x.State,
x.CreateDate,
x.CreateMan,
};
}
#endregion 获取列表
public static void AddCQMSData_CQMS(Model.CQMSData_CQMS newtable)
{
Model.SGGLDB db = Funs.DB;
Model.CQMSData_CQMS table = new Model.CQMSData_CQMS
{
Id = newtable.Id,
UnitId = newtable.UnitId,
CollCropCode = newtable.CollCropCode,
UnitName = newtable.UnitName,
ReportDate = newtable.ReportDate,
TrainPersonNum = newtable.TrainPersonNum,
TechnicalDisclosePersonNum = newtable.TechnicalDisclosePersonNum,
UseNum = newtable.UseNum,
OKNum = newtable.OKNum,
CompanyPersonNum = newtable.CompanyPersonNum,
BranchPersonNum = newtable.BranchPersonNum,
ProjectPersonNum = newtable.ProjectPersonNum,
ProblemNum = newtable.ProblemNum,
ProblemCompletedNum = newtable.ProblemCompletedNum,
ProblemNotCompletedNum = newtable.ProblemNotCompletedNum,
SNum = newtable.SNum,
ANum = newtable.ANum,
BNum = newtable.BNum,
CNum = newtable.CNum,
KeyProcessNum = newtable.KeyProcessNum,
KeyProcessOKNum = newtable.KeyProcessOKNum,
SpecialProcessNum = newtable.SpecialProcessNum,
SpecialProcessOKNum = newtable.SpecialProcessOKNum,
ConcealedWorksNum = newtable.ConcealedWorksNum,
ConcealedWorksOKNum = newtable.ConcealedWorksOKNum,
UnitProjectOnesNum = newtable.UnitProjectOnesNum,
UnitProjectOnesOKNum = newtable.UnitProjectOnesOKNum,
MaterialInRecheckNum = newtable.MaterialInRecheckNum,
MaterialInRecheckOKNum = newtable.MaterialInRecheckOKNum,
SingleProjectNum = newtable.SingleProjectNum,
UnitProjectNum = newtable.UnitProjectNum,
SubProjectNum = newtable.SubProjectNum,
SubdivisionalWorksNum = newtable.SubdivisionalWorksNum,
InspectionLotNum = newtable.InspectionLotNum,
State = newtable.State,
CreateDate = newtable.CreateDate,
CreateMan = newtable.CreateMan,
};
db.CQMSData_CQMS.InsertOnSubmit(table);
db.SubmitChanges();
}
public static void DeleteCQMSData_CQMSById(string Id)
{
Model.SGGLDB db = Funs.DB;
Model.CQMSData_CQMS table = db.CQMSData_CQMS.FirstOrDefault(x => x.Id == Id);
if (table != null)
{
db.CQMSData_CQMS.DeleteOnSubmit(table);
db.SubmitChanges();
}
}
public static Model.CQMSData_CQMS GetCQMSData_CQMSById(string Id)
{
Model.SGGLDB db = Funs.DB;
return db.CQMSData_CQMS.FirstOrDefault(x => x.Id == Id);
}
public static Model.CQMSData GetItemById(string Id)
{
var model = GetCQMSData_CQMSById(Id);
CQMSData data = new CQMSData();
CqmsDataItem item = new CqmsDataItem();
if (model != null)
{
item.Id = model.Id;
item.ReportDate = model.ReportDate.Value.ToShortDateString();
item.UnitId = model.UnitId;
item.CollCropCode = model.CollCropCode;
item.TrainPersonNum = model.TrainPersonNum;
item.TechnicalDisclosePersonNum = model.TechnicalDisclosePersonNum;
item.UseNum = model.UseNum;
item.OKNum = model.OKNum;
item.CompanyPersonNum = model.CompanyPersonNum;
item.BranchPersonNum = model.BranchPersonNum;
item.ProjectPersonNum = model.ProjectPersonNum;
item.ProblemNum = model.ProblemNum;
item.ProblemCompletedNum = model.ProblemCompletedNum;
item.ProblemNotCompletedNum = model.ProblemNotCompletedNum;
item.ProblemRate = "";
item.SNum = model.SNum;
item.ANum = model.ANum;
item.BNum = model.BNum;
item.CNum = model.CNum;
item.KeyProcessNum = model.KeyProcessNum;
item.KeyProcessOKNum = model.KeyProcessOKNum;
item.KeyProcessRate = "";
item.SpecialProcessNum = model.SpecialProcessNum;
item.SpecialProcessOKNum = model.SpecialProcessOKNum;
item.SpecialProcessRate = "";
item.ConcealedWorksNum = model.ConcealedWorksNum;
item.ConcealedWorksOKNum = model.ConcealedWorksOKNum;
item.ConcealedWorksRate = "";
item.UnitProjectOnesNum = model.UnitProjectOnesNum;
item.UnitProjectOnesOKNum = model.UnitProjectOnesOKNum;
item.UnitProjectOnesRate = "";
item.MaterialInRecheckNum = model.MaterialInRecheckNum;
item.MaterialInRecheckOKNum = model.MaterialInRecheckOKNum;
item.MaterialInRecheckRate = "";
item.SingleProjectNum = model.SingleProjectNum;
item.UnitProjectNum = model.UnitProjectNum;
item.SubProjectNum = model.SubProjectNum;
item.SubdivisionalWorksNum = model.SubdivisionalWorksNum;
item.InspectionLotNum = model.InspectionLotNum;
}
List cqmsDataItems = new List();
cqmsDataItems.Add(item);
data.CQMSDataItems = cqmsDataItems;
return data;
}
public static Model.CQMSData GetTodayCQMSData_CQMS()
{
var q = GetTodayData();
CQMSData data = new CQMSData();
if (q != null && q.State == Const.CNCEC_State_S)
{
data = GetDataByCQMSData_CQMS(q);
}
else
{
data = StatisticalData();
}
return data;
}
public static Model.CQMSData_CQMS GetTodayData()
{
var q = (from x in Funs.DB.CQMSData_CQMS
where x.ReportDate < DateTime.Now.AddDays(1).Date && x.ReportDate >= DateTime.Now.Date
select x).FirstOrDefault();
return q;
}
public static void UpdateTodyData_State()
{
var q = GetTodayData();
if (q!=null )
{
q.State = Const.CNCEC_State_1;
UpdateCQMSData_CQMS(q);
}
}
public static bool IsReportByDate(DateTime dateTime)
{
var result = false;
var q = (from x in Funs.DB.CQMSData_CQMS
where x.ReportDate >= dateTime.Date && x.ReportDate < (dateTime.Date.AddDays(1).Date)
select x).ToList();
if (q != null && q.Count > 0)
{
result = true;
}
return result;
}
///
/// 判断当天是否已统计
///
///
public static bool IsReportByToday()
{
var result = false;
var q = (from x in Funs.DB.CQMSData_CQMS
where x.ReportDate < DateTime.Now.AddDays(1).Date && x.ReportDate >= DateTime.Now.Date
select x).ToList();
if (q != null && q.Count > 0)
{
result = true;
}
return result;
}
public static Model.ReturnData PushCNCEC(string Id)
{
string baseurl = "/api/CQMSData/SaveCQMSData";
var item = GetItemById(Id);
string str = JsonConvert.SerializeObject(item);
var responeData = BLL.ServerService.PushCNCEC(str, baseurl);
return responeData;
}
public static CQMSData StatisticalData()
{
string thisUnitId = string.Empty;
var thisUnit = Const.UnitId_CWCEC;
if (thisUnit != null)
{
thisUnitId = thisUnit;
}
var base_Unit = BLL.UnitService.GetUnitByUnitId(thisUnitId);
Project_CQMSDataService.StatisticalAllProjectData();
var ProjectData = (from x in Funs.DB.Project_CQMSData_CQMS
where x.ReportDate < DateTime.Now.AddDays(1).Date && x.ReportDate >= DateTime.Now.Date
select x).ToList();
Model.CQMSData_CQMS table = new Model.CQMSData_CQMS
{
UnitId = thisUnitId,
CollCropCode = base_Unit.CollCropCode,
UnitName = base_Unit.UnitName,
ReportDate = DateTime.Now.Date,
TrainPersonNum = ProjectData.Sum(x => x.TrainPersonNum),
TechnicalDisclosePersonNum = ProjectData.Sum(x => x.TechnicalDisclosePersonNum),
UseNum = ProjectData.Sum(x => x.UseNum),
OKNum = ProjectData.Sum(x => x.OKNum),
CompanyPersonNum = ProjectData.Sum(x => x.CompanyPersonNum),
BranchPersonNum = ProjectData.Sum(x => x.BranchPersonNum),
ProjectPersonNum = ProjectData.Sum(x => x.ProjectPersonNum),
ProblemNum = ProjectData.Sum(x => x.ProblemNum),
ProblemCompletedNum = ProjectData.Sum(x => x.ProblemCompletedNum),
ProblemNotCompletedNum = ProjectData.Sum(x => x.ProblemNotCompletedNum),
SNum = ProjectData.Sum(x => x.SNum),
ANum = ProjectData.Sum(x => x.ANum),
BNum = ProjectData.Sum(x => x.BNum),
CNum = ProjectData.Sum(x => x.CNum),
KeyProcessNum = ProjectData.Sum(x => x.KeyProcessNum),
KeyProcessOKNum = ProjectData.Sum(x => x.KeyProcessOKNum),
SpecialProcessNum = ProjectData.Sum(x => x.SpecialProcessNum),
SpecialProcessOKNum = ProjectData.Sum(x => x.SpecialProcessOKNum),
ConcealedWorksNum = ProjectData.Sum(x => x.ConcealedWorksNum),
ConcealedWorksOKNum = ProjectData.Sum(x => x.ConcealedWorksOKNum),
UnitProjectOnesNum = ProjectData.Sum(x => x.UnitProjectOnesNum),
UnitProjectOnesOKNum = ProjectData.Sum(x => x.UnitProjectOnesOKNum),
MaterialInRecheckNum = ProjectData.Sum(x => x.MaterialInRecheckNum),
MaterialInRecheckOKNum = ProjectData.Sum(x => x.MaterialInRecheckOKNum),
SingleProjectNum = ProjectData.Sum(x => x.SingleProjectNum),
UnitProjectNum = ProjectData.Sum(x => x.UnitProjectNum),
SubProjectNum = ProjectData.Sum(x => x.SubProjectNum),
SubdivisionalWorksNum = ProjectData.Sum(x => x.SubdivisionalWorksNum),
InspectionLotNum = ProjectData.Sum(x => x.InspectionLotNum),
CreateMan = Const.sysglyId,
CreateDate = DateTime.Now,
};
if (IsReportByToday())
{
table.Id = GetTodayData().Id;
table.State = Const.CNCEC_State_1;
UpdateCQMSData_CQMS(table);
}
else
{
table.Id = SQLHelper.GetNewID();
table.State = Const.CNCEC_State_0;
AddCQMSData_CQMS(table);
}
CQMSData data = new CQMSData();
data = GetDataByCQMSData_CQMS(table);
return data;
}
public static CQMSData GetDataByCQMSData_CQMS(Model.CQMSData_CQMS table)
{
CQMSData data = new CQMSData();
CqmsDataItem item = new CqmsDataItem();
item.Id = table.Id;
item.ReportDate = table.ReportDate.Value.ToShortDateString();
item.UnitId = table.UnitId;
item.CollCropCode = table.CollCropCode;
item.TrainPersonNum = table.TrainPersonNum;
item.TechnicalDisclosePersonNum = table.TechnicalDisclosePersonNum;
item.UseNum = table.UseNum;
item.OKNum = table.OKNum;
item.CompanyPersonNum = table.CompanyPersonNum;
item.BranchPersonNum = table.BranchPersonNum;
item.ProjectPersonNum = table.ProjectPersonNum;
item.ProblemNum = table.ProblemNum;
item.ProblemCompletedNum = table.ProblemCompletedNum;
item.ProblemNotCompletedNum = table.ProblemNotCompletedNum;
item.ProblemRate = "";
item.SNum = table.SNum;
item.ANum = table.ANum;
item.BNum = table.BNum;
item.CNum = table.CNum;
item.KeyProcessNum = table.KeyProcessNum;
item.KeyProcessOKNum = table.KeyProcessOKNum;
item.KeyProcessRate = "";
item.SpecialProcessNum = table.SpecialProcessNum;
item.SpecialProcessOKNum = table.SpecialProcessOKNum;
item.SpecialProcessRate = "";
item.ConcealedWorksNum = table.ConcealedWorksNum;
item.ConcealedWorksOKNum = table.ConcealedWorksOKNum;
item.ConcealedWorksRate = "";
item.UnitProjectOnesNum = table.UnitProjectOnesNum;
item.UnitProjectOnesOKNum = table.UnitProjectOnesOKNum;
item.UnitProjectOnesRate = "";
item.MaterialInRecheckNum = table.MaterialInRecheckNum;
item.MaterialInRecheckOKNum = table.MaterialInRecheckOKNum;
item.MaterialInRecheckRate = "";
item.SingleProjectNum = table.SingleProjectNum;
item.UnitProjectNum = table.UnitProjectNum;
item.SubProjectNum = table.SubProjectNum;
item.SubdivisionalWorksNum = table.SubdivisionalWorksNum;
item.InspectionLotNum = table.InspectionLotNum;
List cqmsDataItems = new List();
cqmsDataItems.Add(item);
data.CQMSDataItems = cqmsDataItems;
return data;
}
public static void UpdateCQMSData_CQMS(Model.CQMSData_CQMS newtable)
{
Model.SGGLDB db = Funs.DB;
Model.CQMSData_CQMS table = db.CQMSData_CQMS.FirstOrDefault(x => x.Id == newtable.Id);
if (table != null)
{
table.Id = newtable.Id;
table.UnitId = newtable.UnitId;
table.CollCropCode = newtable.CollCropCode;
table.UnitName = newtable.UnitName;
table.ReportDate = newtable.ReportDate;
table.TrainPersonNum = newtable.TrainPersonNum;
table.TechnicalDisclosePersonNum = newtable.TechnicalDisclosePersonNum;
table.UseNum = newtable.UseNum;
table.OKNum = newtable.OKNum;
table.CompanyPersonNum = newtable.CompanyPersonNum;
table.BranchPersonNum = newtable.BranchPersonNum;
table.ProjectPersonNum = newtable.ProjectPersonNum;
table.ProblemNum = newtable.ProblemNum;
table.ProblemCompletedNum = newtable.ProblemCompletedNum;
table.ProblemNotCompletedNum = newtable.ProblemNotCompletedNum;
table.SNum = newtable.SNum;
table.ANum = newtable.ANum;
table.BNum = newtable.BNum;
table.CNum = newtable.CNum;
table.KeyProcessNum = newtable.KeyProcessNum;
table.KeyProcessOKNum = newtable.KeyProcessOKNum;
table.SpecialProcessNum = newtable.SpecialProcessNum;
table.SpecialProcessOKNum = newtable.SpecialProcessOKNum;
table.ConcealedWorksNum = newtable.ConcealedWorksNum;
table.ConcealedWorksOKNum = newtable.ConcealedWorksOKNum;
table.UnitProjectOnesNum = newtable.UnitProjectOnesNum;
table.UnitProjectOnesOKNum = newtable.UnitProjectOnesOKNum;
table.MaterialInRecheckNum = newtable.MaterialInRecheckNum;
table.MaterialInRecheckOKNum = newtable.MaterialInRecheckOKNum;
table.SingleProjectNum = newtable.SingleProjectNum;
table.UnitProjectNum = newtable.UnitProjectNum;
table.SubProjectNum = newtable.SubProjectNum;
table.SubdivisionalWorksNum = newtable.SubdivisionalWorksNum;
table.InspectionLotNum = newtable.InspectionLotNum;
table.State = newtable.State;
table.CreateMan = newtable.CreateMan;
table.CreateDate = newtable.CreateDate;
db.SubmitChanges();
}
}
}
}