private List<WarnRecord> InsertSYdata(List<WarnRecord> list) { int index = 0; string sql=string.Empty; if (Org!=null) { sql=" where OrgID='"+Org.OrgCode+"'"; } IList<PS_aqgj> aqgjlist = ClientHelper.PlatformSqlMap.GetList<PS_aqgj>(sql); foreach (PS_aqgj aqgj in aqgjlist) { index++; string sqlsy = " where sbID='" + aqgj.sbID + "' order by xcsyrq desc"; IList<PJ_14aqgjsy> aqgjsylist = ClientHelper.PlatformSqlMap.GetList<PJ_14aqgjsy>(sqlsy); if (aqgjsylist.Count>0&&aqgjsylist[0].xcsyrq>DateTime.Now) { WarnRecord record=new WarnRecord () { Type = "实验", WarnType = "安全工具", Times = 1, WritTime = aqgjsylist[0].xcsyrq, LinkID = "", TableName = "PJ_14aqgjsy", Des = " 编号:" + aqgj.sbCode + " 名称:" + aqgj.sbName, Remark = "下次实验在" + aqgjsylist[0].xcsyrq.ToShortDateString() }; record.ID += index; list.Add(record); } } return list; }
/// <summary> /// 初始化数据 /// </summary> public void InitData() { //找到所有启用的提醒设置 List<WarnRecord> list = new List<WarnRecord>(); string sqlwarn = "where IsUse=1" ; if (type!=string.Empty) { sqlwarn += " and Type='" + type + "'"; } IList<WarnSet> wslist = MainHelper.PlatformSqlMap.GetList<WarnSet>(sqlwarn); DateTime dtnow = DateTime.Now; int index = 0; foreach (WarnSet ws in wslist) { //如果此提醒设置对该单位不起作用,则不用计算 if (Org!=null&&!ws.BYScol1.Contains(Org.OrgCode)) { break; } index++; string tablename=ws.TableName; string field=ws.FieldName; string orgfield=ws.OrgField; string sql = string.Empty; sql=" select top(1) "+field+" from "+tablename ; if (orgfield != string.Empty && Org!=null) { sql+=" where "+orgfield+" ='"+Org.OrgCode+"'"; } sql += " order by cast(" + field + " as datetime) desc"; DateTime lastneeddate = new DateTime(); int needtimes = 0; try { //查找符合条件的日期最后值 object dt= MainHelper.PlatformSqlMap.GetObject("GetWarnResultBySqlWhere", sql); DateTime resdt = DateTime.Parse(dt.ToString()); //每月类型 if (ws.WarnType==frmWarnSetEdit.WarinType1) { if (IsNeedWarnMonth(ws.BeforeDays,ws.OrderDays,ws.AfterDays,resdt,out lastneeddate,out needtimes)) { WarnRecord record = new WarnRecord() { Type = ws.Type, WarnType = ws.WarnType, Times = needtimes, WritTime = lastneeddate, LinkID = ws.LinkID, TableName = ws.TableName, Remark="每月["+ws.OrderDays+" ]号填写", Des=ws.Remark }; record.ID += index; list.Add(record); } } else { if (IsNeedWarnDays(ws.BeforeDays, ws.SpaceDays, ws.AfterDays, resdt, out lastneeddate, out needtimes)) { WarnRecord record = new WarnRecord() { Type = ws.Type, WarnType = ws.WarnType, Times = needtimes, WritTime = lastneeddate, LinkID = ws.LinkID, TableName = ws.TableName, Des=ws.Remark, Remark = "每隔[" + ws.SpaceDays + " ]日填写" }; record.ID += index; list.Add(record); } } } catch (Exception) { break; } } if (type=="实验") { list = InsertSYdata(list); } gridControl1.DataSource = list; }