/// <summary> /// 对象 /// </summary> /// <param name="id"></param> /// <param name="isRead">为true改变状态</param> /// <returns></returns> public static SysMailSender GetObj(string id, bool isRead) { SysMailSender obj = new SysMailSender(); OpResult re = new OpResult(); if (isRead) { var objRece = BaseService <SysMailReceive> .CurrentRepository.QueryEntity.Include(o => o.Attachments).SingleOrDefault(o => o.Id == id); if (objRece != null) { if (objRece.State == 0) { objRece.State = 1; objRece.ReadDate = DateTime.Now; re = BaseService <SysMailReceive> .Update(objRece); #region 写入日志 Sys.LogEngine log = new Sys.LogEngine(); string msg = "成功修改邮件状态!"; var module = Pharos.Sys.LogModule.邮件管理; if (re.Successed) { msg += "<br />Id=" + objRece.Id + ",<br />状态=已读" + "。"; log.WriteUpdate(msg, module); } else { msg = "修改邮件状态失败!"; log.WriteUpdate(msg, module); } #endregion } objRece.ToCopyProperty(obj); obj.SenderCode = objRece.SenderCode; obj.SenderName = objRece.SenderName; obj.Attachments = objRece.Attachments; } } else { obj = CurrentRepository.QueryEntity.Include(o => o.Attachments).SingleOrDefault(o => o.Id == id); } return(obj); }
public ActionResult SetState(string[] ids) { var receives = BaseService <SysMailReceive> .FindList(o => ids.Contains(o.Id) && o.ReceiveCode == Sys.CurrentUser.UserName && o.State == 0); foreach (var rece in receives) { rece.State = 1; rece.ReadDate = DateTime.Now; } var op = new OpResult(); if (receives.Any()) { op = BaseService <SysMailReceive> .Update(receives); #region 写入日志 Sys.LogEngine log = new Sys.LogEngine(); string msg = "成功修改邮件状态!"; var module = Pharos.Sys.LogModule.邮件管理; if (op.Successed) { for (int i = 0; i < receives.Count(); i++) { msg += "<br />Id=" + receives[i].Id + ",<br />状态=已读" + "。"; log.WriteUpdate(msg, module); msg = "成功修改邮件状态!"; } } else { msg = "修改邮件状态失败!"; log.WriteUpdate(msg, module); } #endregion } else { op.Message = "无需要更新的记录"; } return(new JsonNetResult(op)); }
/// <summary> /// 发送,草稿,回复,转发 /// </summary> /// <param name="obj"></param> /// <param name="httpFiles">附件</param> /// <param name="fileId">原存在附件ID</param> /// <returns></returns> public static OpResult SendMail(SysMailSender obj, System.Web.HttpFileCollectionBase httpFiles, string fileId) { var op = new OpResult(); try { var mailReceives = new List <SysMailReceive>(); obj.ReceiverCodes.IsNullThrow("收件人不能空!"); var receiverIds = obj.ReceiverCodes.Split(';'); var createDate = DateTime.Now; var sendCode = Sys.CurrentUser.UserName; var sendName = Sys.CurrentUser.FullName; foreach (var o in receiverIds) { if (o.IsNullOrEmpty()) { continue; } string uid = "", uname = ""; if (o.Contains("(")) { uid = o.Substring(o.LastIndexOf("(") + 1).TrimEnd(')'); uname = o.Substring(0, o.IndexOf("(")); } else { var user = GetUser(o); if (user == null) { continue; } uid = user.UserCode.ToString(); uname = user.FullName; } var rece = new SysMailReceive(); obj.ToCopyProperty(rece); rece.ReceiveCode = uid; rece.ReceiveName = uname; rece.SenderCode = sendCode; rece.SenderName = sendName; rece.State = 0; rece.Type = 1; rece.Id = CommonRules.GUID; rece.CreateDT = createDate; rece.BatchNo = createDate.ToString("yyyyMMddHHmmssfff"); mailReceives.Add(rece); } if (!obj.CopytoCodes.IsNullOrEmpty()) { var copytoIds = obj.CopytoCodes.Split(';'); foreach (var o in copytoIds) { if (o.IsNullOrEmpty()) { continue; } string uid = "", uname = ""; if (o.Contains("(")) { uid = o.Substring(o.LastIndexOf("(") + 1).TrimEnd(')'); uname = o.Substring(0, o.IndexOf("(")); } else { var user = GetUser(o); if (user == null) { continue; } uid = user.UserCode.ToString(); uname = user.FullName; } var rece = new SysMailReceive(); obj.ToCopyProperty(rece); rece.ReceiveCode = uid; rece.ReceiveName = uname; rece.SenderCode = sendCode; rece.SenderName = sendName; rece.State = 0; rece.Type = 2; rece.Id = CommonRules.GUID; rece.CreateDT = createDate; rece.BatchNo = createDate.ToString("yyyyMMddHHmmssfff"); mailReceives.Add(rece); } } if (obj.State == 1) { foreach (var rece in mailReceives) { rece.Attachments = GetAttachs(httpFiles, fileId, obj.Id.IsNullOrEmpty() && !obj.BatchNo.IsNullOrEmpty()); } } obj.Attachments = GetAttachs(httpFiles, fileId, obj.Id.IsNullOrEmpty() && !obj.BatchNo.IsNullOrEmpty()); obj.CompanyId = CommonService.CompanyId; if (obj.Id.IsNullOrEmpty()) { obj.BatchNo = createDate.ToString("yyyyMMddHHmmssfff"); obj.Id = CommonRules.GUID; obj.CreateDT = createDate; obj.SenderCode = sendCode; obj.SenderName = sendName; if (obj.State == 1)//发送 { Add(obj, false); op = BaseService <SysMailReceive> .AddRange(mailReceives, true); } else { op = Add(obj); } #region 写入日志 string StateTitle = obj.State == 1 ? "已发送" : "存草稿"; string msg = obj.State == 1 ? "成功发送邮件!" : "成功保存草稿到发件箱!"; var module = Pharos.Sys.LogModule.邮件管理; if (op.Successed) { string copyCodes = string.IsNullOrEmpty(obj.CopytoCodes) ? "" : (",抄送人=" + obj.CopytoCodes); msg += "<br />Id=" + obj.Id + ","; msg += "<br />收件人=" + obj.ReceiverCodes + copyCodes + ",状态=" + StateTitle + ",主题=" + obj.Title + ",批次=" + obj.BatchNo + "。"; } else { msg = obj.State == 1 ? "发送邮件失败!" : "保存草稿到发件箱失败!"; } log.WriteInsert(msg, module); #endregion } else//草稿时 { var resour = CurrentRepository.QueryEntity.Include(o => o.Attachments).SingleOrDefault(o => o.Id == obj.Id); var isUpdateRec = obj.ReceiverCodes != resour.ReceiverCodes; var isUpdateCop = obj.CopytoCodes != resour.CopytoCodes; var isUpdateState = obj.State != resour.State; var isUpdateTitle = obj.Title != resour.Title; var isUpdateBody = obj.Body != resour.Body; bool isUpdate = isUpdateRec || isUpdateCop || isUpdateState || isUpdateTitle || isUpdateBody; obj.ToCopyProperty(resour); foreach (var att in obj.Attachments) { if (!resour.Attachments.Any(o => o.Title == att.Title)) { resour.Attachments.Add(att); } } if (obj.State == 1)//发送 { Update(resour, false); op = BaseService <SysMailReceive> .AddRange(mailReceives, true); } else { op = Update(resour); } #region 写入日志 string StateTitle = obj.State == 1 ? "已发送" : "存草稿"; string msg = obj.State == 1 ? "成功发送邮件!" : "成功修改草稿!"; var module = Pharos.Sys.LogModule.邮件管理; if (op.Successed) { int n = 0; if (isUpdate) { msg += "<br />Id=" + obj.Id + ",<br />"; if (isUpdateState) { msg += "状态由草稿改为已发送"; n = n + 1; } if (isUpdateRec) { msg += n > 0 ? ",收件人=" + obj.ReceiverCodes : "收件人=" + obj.ReceiverCodes; n = n + 1; } if (isUpdateCop) { msg += n > 0 ? ",抄送人=" + obj.CopytoCodes : "抄送人=" + obj.CopytoCodes; n = n + 1; } if (isUpdateTitle) { msg += n > 0 ? ",主题=" + obj.Title : "主题=" + obj.Title; n = n + 1; } if (isUpdateBody) { msg += n > 0 ? ",正文=" + obj.Body : "正文=" + obj.Body; } msg += "。"; log.WriteUpdate(msg, module); } } else { msg = obj.State == 1 ? "发送邮件失败(从发件箱的草稿发送)!" : "修改草稿失败!"; log.WriteUpdate(msg, module); } #endregion } } catch (Exception ex) { op.Message = ex.Message; Log.WriteError(ex); } return(op); }
/// <summary> /// 保存或修改 /// </summary> /// <param name="obj"></param> /// <returns></returns> public static OpResult NoticeSaveOrUpdate(Notice obj) { var re = new OpResult(); try { if (obj.Id == 0) { obj.CreateDT = DateTime.Now; obj.CreateUID = Sys.CurrentUser.UID; obj.CompanyId = CommonService.CompanyId; re = Add(obj); #region 写入日志 string msg = "成功新增公告!"; var module = Pharos.Sys.LogModule.通知公告; if (re.Successed) { string TypeName = "", storeTitle = ""; TypeName = (obj.Type == 1 ? "公告" : "活动"); storeTitle = obj.StoreId == "0" ? "后台系统" : CommonService.GetStoreTitleList(obj.StoreId); msg += "<br />Id=" + obj.Id + ","; msg += "<br />显示范围=" + storeTitle + ",类型=" + TypeName + ",状态=" + Enum.GetName(typeof(NoticeState), obj.State) + ",主题=" + obj.Theme + ",开始日期=" + obj.BeginDate.ToString("yyyy-MM-dd") + ",截止日期=" + obj.ExpirationDate.ToString("yyyy-MM-dd") + "。"; } else { msg = "新增公告失败!"; } log.WriteInsert(msg, module); #endregion } else { var notice = CurrentRepository.QueryEntity.FirstOrDefault(n => n.Id == obj.Id); var isUpdateStore = obj.StoreId != notice.StoreId; var isUpdateType = obj.Type != notice.Type; var isUpdateState = obj.State != notice.State; var isUpdateTheme = obj.Theme != notice.Theme; var isUpdateBegindate = obj.BeginDate.ToString("yyyy-MM-dd") != notice.BeginDate.ToString("yyyy-MM-dd"); var isUpdateExpirationdate = obj.ExpirationDate.ToString("yyyy-MM-dd") != notice.ExpirationDate.ToString("yyyy-MM-dd"); var isUpdateContent = obj.NoticeContent != notice.NoticeContent; bool isUpdate = isUpdateStore || isUpdateType || isUpdateState || isUpdateTheme || isUpdateBegindate || isUpdateExpirationdate || isUpdateContent; if (notice != null) { notice.Theme = obj.Theme; notice.NoticeContent = obj.NoticeContent; notice.StoreId = obj.StoreId; notice.State = obj.State; notice.Type = obj.Type; notice.BeginDate = obj.BeginDate; notice.ExpirationDate = obj.ExpirationDate; re = Update(notice); #region 写入日志 string msg = "成功修改公告!"; var module = Pharos.Sys.LogModule.通知公告; if (re.Successed) { int n = 0; if (isUpdate) { msg += "<br />Id=" + obj.Id + ",<br />"; if (isUpdateStore) { var storeTitle = obj.StoreId == "0" ? "后台系统" : CommonService.GetStoreTitleList(obj.StoreId); msg += "显示范围=" + storeTitle; n = n + 1; } if (isUpdateType) { var TypeName = (obj.Type == 1 ? "公告" : "活动"); msg += n > 0 ? ",类型=" + TypeName : "类型=" + TypeName; n = n + 1; } if (isUpdateState) { var StateTitle = Enum.GetName(typeof(NoticeState), obj.State); msg += n > 0 ? ",状态=" + StateTitle : "状态=" + StateTitle; n = n + 1; } if (isUpdateTheme) { msg += n > 0 ? ",主题=" + obj.Theme : "主题=" + obj.Theme; n = n + 1; } if (isUpdateBegindate) { msg += n > 0 ? ",开始日期=" + obj.BeginDate.ToString("yyyy-MM-dd") : "开始日期=" + obj.BeginDate.ToString("yyyy-MM-dd"); n = n + 1; } if (isUpdateExpirationdate) { msg += n > 0 ? ",开始日期=" + obj.ExpirationDate.ToString("yyyy-MM-dd") : "开始日期=" + obj.ExpirationDate.ToString("yyyy-MM-dd"); n = n + 1; } if (isUpdateContent) { msg += n > 0 ? ",详细内容=" + obj.NoticeContent : "详细内容=" + obj.NoticeContent; } msg += "。"; log.WriteUpdate(msg, module); } } else { msg = "修改公告失败!"; log.WriteUpdate(msg, module); } #endregion } } if (re.Successed) { Pharos.Infrastructure.Data.Redis.RedisManager.Publish("SyncDatabase", new Pharos.ObjectModels.DTOs.DatabaseChanged() { CompanyId = obj.CompanyId, StoreId = obj.StoreId, Target = "Notice" }); } } catch (Exception ex) { re.Message = ex.Message; Log.WriteError(ex); } return(re); }
public static OpResult SaveOrUpdate(Supplier obj) { var re = new OpResult(); var classify = SysDataDictService.GetSupplierTypes(); List <SysUserInfo> list = new List <SysUserInfo>(); string desig = GetUser(obj.Designee, list); string stateTitle = obj.MasterState == 1 ? "可用" : "关闭"; obj.CompanyId = CommonService.CompanyId; if (!obj.MasterAccount.IsNullOrEmpty() && SupplierService.IsExist(o => o.Id != obj.Id && o.MasterAccount == obj.MasterAccount && o.BusinessType == 1 && o.CompanyId == obj.CompanyId)) { re.Message = "账号已存在"; } else if (!obj.Title.IsNullOrEmpty() && SupplierService.IsExist(o => o.Id != obj.Id && o.Title == obj.Title && o.BusinessType == 1 && o.CompanyId == obj.CompanyId)) { re.Message = "供应商简称已存在"; } else if (!obj.FullTitle.IsNullOrEmpty() && SupplierService.IsExist(o => o.Id != obj.Id && o.FullTitle == obj.FullTitle && o.BusinessType == 1 && o.CompanyId == obj.CompanyId)) { re.Message = "供应商全称已存在"; } else if (obj.Id.IsNullOrEmpty()) { obj.Id = Logic.CommonRules.GUID; obj.BusinessType = 1; re = SupplierService.Add(obj); #region 写入日志 string msg = "成功新增供应商!"; var module = Pharos.Sys.LogModule.档案管理; if (re.Successed) { string designee = (string.IsNullOrEmpty(obj.Designee) && string.IsNullOrEmpty(desig)) ? "" : ",指派人=" + desig; string phoneNum = string.IsNullOrEmpty(obj.MobilePhone) ? "" : ",手机=" + obj.MobilePhone; string telNum = string.IsNullOrEmpty(obj.Tel) ? "" : ",电话=" + obj.Tel; string email = string.IsNullOrEmpty(obj.Email) ? "" : ",邮箱=" + obj.Email; string address = string.IsNullOrEmpty(obj.Address) ? "" : ",地址=" + obj.Address; msg += "<br />Id=" + obj.Id + ","; msg += "<br />分类=" + GetTitle(classify, obj.ClassifyId) + designee + ",简称=" + obj.Title + ",全称=" + obj.FullTitle + ",联系人=" + obj.Linkman + phoneNum + telNum + email + address + ",账号=" + obj.MasterAccount + ",状态=" + stateTitle + "。"; } else { msg = "新增供应商失败!"; } log.WriteInsert(msg, module); #endregion } else { var supp = SupplierService.FindById(obj.Id); var exc = new List <string>(); if (obj.MasterPwd.IsNullOrEmpty()) { exc.Add("MasterPwd"); } exc.Add("CompanyId"); var isUpdateClassify = obj.ClassifyId != supp.ClassifyId; var isUpdateDesignee = obj.Designee != supp.Designee; var isUpdateLinkman = obj.Linkman != supp.Linkman; var isUpdatePhone = obj.MobilePhone != supp.MobilePhone; var isUpdateTel = obj.Tel != supp.Tel; var isUpdateEmail = obj.Email != supp.Email; var isUpdateAddress = obj.Address != supp.Address; var isUpdateState = obj.MasterState != supp.MasterState; var isUpdatePwd = string.IsNullOrEmpty(obj.MasterPwd) ? false : (obj.MasterPwd != supp.MasterPwd); bool isUpdate = isUpdateClassify || isUpdateDesignee || isUpdateLinkman || isUpdatePhone || isUpdateTel || isUpdateEmail || isUpdateAddress || isUpdatePwd || isUpdateState; obj.ToCopyProperty(supp, exc); re = SupplierService.Update(supp); #region 写入日志 string msg = "成功修改供应商!"; var module = Pharos.Sys.LogModule.档案管理; if (re.Successed) { int n = 0; if (isUpdate) { msg += "<br />Id=" + obj.Id + ",<br />"; if (isUpdateClassify) { var classifyTitle = GetTitle(classify, obj.ClassifyId); msg += "分类=" + classifyTitle; n = n + 1; } if (isUpdateDesignee) { msg += n > 0 ? ",指派人=" + desig : "指派人=" + desig; n = n + 1; } if (isUpdateLinkman) { msg += n > 0 ? ",联系人=" + obj.Linkman : "联系人=" + obj.Linkman; n = n + 1; } if (isUpdatePhone) { msg += n > 0 ? ",手机=" + obj.MobilePhone : "手机=" + obj.MobilePhone; n = n + 1; } if (isUpdateTel) { msg += n > 0 ? ",电话=" + obj.Tel : "电话=" + obj.Tel; n = n + 1; } if (isUpdateEmail) { msg += n > 0 ? ",邮箱=" + obj.Email : "邮箱=" + obj.Email; n = n + 1; } if (isUpdateAddress) { msg += n > 0 ? ",地址=" + obj.Address : "地址=" + obj.Address; n = n + 1; } if (isUpdateState) { msg += n > 0 ? ",状态=" + stateTitle : "状态=" + stateTitle; n = n + 1; } if (isUpdatePwd) { msg += n > 0 ? ",并修改了密码" : "修改了密码"; } msg += "。"; log.WriteUpdate(msg, module); } } else { msg = "修改供应商失败!"; log.WriteUpdate(msg, module); } #endregion } return(re); }