public void Alarm() { //判定间隔,如果上次提醒日期为空,则认为是第一次提醒,直接发送 if (this.LastAlarmDate.HasValue) { if (this.LastAlarmDate.Value.AddDays(this.AlarmFrequency) >= DateTime.Now) { return; } } //循环数据源,进行提醒操作 foreach (DataRow dataRow in this.AlarmDataSource.Rows) { #region 替换关键字 string title = this.Title; string content = this.AlarmContentTemplate; string linkUrl = this.LinkUrl; while (title.Contains('{')) { title = Tools.ReplaceString(title, dataRow); } while (linkUrl.Contains('{')) { linkUrl = Tools.ReplaceString(linkUrl, dataRow); } while (content.Contains('{')) { content = Tools.ReplaceString(content, dataRow); } #endregion //设置提醒的过期期限,如果计划日期大于当前日期,则过期期限为计划日期,否则为当前日期+7天(已过期的) var deadLine = DateTime.Now.AddDays(7); if (dataRow[this.PlanDateField] != null && dataRow[this.PlanDateField] != DBNull.Value && !String.IsNullOrEmpty(dataRow[this.PlanDateField].ToString())) { var planDate = Convert.ToDateTime(dataRow[this.PlanDateField]); if (planDate > DateTime.Now) { deadLine = planDate; } } this.instanceReceivers.Clear(); //初始化配置信息中的系统角色,人员和组织角色(由于这些角色固定,不需要动态数据获取,所以每个模板都是固定的,不要重复取) _initConfigReceivers(); //动态获取项目角色信息 var projectInfoID = string.Empty; if (dataRow.Table.Columns.Contains(this.ProjectInfoIDField)) { projectInfoID = dataRow[this.ProjectInfoIDField].ToString(); _setProjectReceivers(this.ReceiversString, dataRow); } //动态获取表单字段作为接收人 if (!string.IsNullOrEmpty(this.ReceiverIDField)) { foreach (var rIDField in this.ReceiverIDField.Split(',')) { if (dataRow.Table.Columns.Contains(rIDField)) { _setFormReceivers(rIDField, dataRow); } } } AlarmHelper.SendAlarmMulti(title, content, linkUrl, this.instanceReceivers, deadLine, "", projectInfoID, "EarlyWarning", null, null, this.Important, this.Ugencry); } string sql = "UPDATE S_S_AlarmConfig SET LastAlarmDate ='" + DateTime.Now.ToString("yyyy-MM-dd") + "' WHERE ID='" + this.ConfigID + "'"; this.BaseDB.ExecuteNonQuery(sql); }