예제 #1
0
 /// <summary>
 /// 获取发货消息并保存进消息队列
 /// </summary>
 /// <param name="OrderID">订单ID</param>
 /// <param name="UserID">用户ID</param>
 /// <param name="MessageType">消息类型 0:邮件 1:短信</param>
 /// <returns></returns>
 public bool SetDeliveryMessage(Guid OrderID, Guid UserID, byte MessageType, int DefaultCulture)
 {
     bool result = false;//返回值 true 正确 false 错误
     string Message = null;//提醒的消息内容
     string Recipient = null;//消息发送的地址或者手机号
     string Title = null;//消息标题-----------------------------------------------------------------应有资源文件代替
     string EmailCode = "DeliveryEmail";//Email模板代码
     string ShortMessageCode = "DeliverySms";//短信模板代码
     string Code = null;//模板代码
     switch (MessageType)//Code,标题赋值
     {
         case (byte)ModelEnum.MessageType.EMAIL: Code = EmailCode; Title = "ZhuChao's Email"; break;
         case (byte)ModelEnum.MessageType.SMS: Code = ShortMessageCode; Title = "ZhuChao's SMS"; break;
     }
     MemberUser oMemberUser = dbEntity.MemberUsers.Where(u => u.Gid == UserID && u.Deleted == false).FirstOrDefault();//查找出用户
     if (oMemberUser != null)
     {
         GeneralMessageTemplate oMessageTemp = new GeneralMessageTemplate();
         //根据订单组织取出对应的组织消息模板
         oMessageTemp = (from t in dbEntity.GeneralMessageTemplates
                         join o in dbEntity.OrderInformations on t.OrgID equals o.OrgID
                         where o.Gid == OrderID && t.Code == Code && o.Deleted == false && t.Deleted == false
                         select t).FirstOrDefault();
         if (oMessageTemp != null)
         {
             int culture = oMemberUser.Culture == null? DefaultCulture : oMemberUser.Culture.LCID;//语言
             Message = oMessageTemp.Matter.GetLargeObject(culture);
             //替换模板宏信息
             Message = ReplaceTempMessage(OrderID, Message);
             if (Message != null)
             {
                  switch (MessageType)//消息发送的地址赋值 手机/Eamil
                 {
                     case (byte)ModelEnum.MessageType.EMAIL: Recipient = oMemberUser.Email; break;
                     case (byte)ModelEnum.MessageType.SMS: Recipient = oMemberUser.CellPhone; break;
                 }
                 GeneralMessagePending oNewMessagePending = new GeneralMessagePending
                 {
                     UserID = UserID,
                     Mtype = MessageType,
                     Name = oMemberUser.DisplayName,
                     Mstatus = (byte)ModelEnum.MessageStatus.PENDING,//初始化状态为 未发送
                     Recipient = Recipient,
                     Title = Title,
                     Matter = Message,//消息内容
                     RefType = (byte)ModelEnum.NoteType.ORDER,//关联单据类型 订单
                     RefID = OrderID,//关联单据号 订单号
                     //Schedule
                     //SentTime
                     //Remark
                 };
                 try
                 {
                     dbEntity.GeneralMessagePendings.Add(oNewMessagePending);
                     dbEntity.SaveChanges();
                     result = true;
                 }
                 catch
                 { //如果添加有错
                     oEventBLL.WriteEvent("Order:" + OrderID + "| UserID:" + UserID + "| MessagePendingAddingError(消息队列添加失败)");
                     result = false;
                 }
             }
         }
     }
     return result;
 }
예제 #2
0
        /// <summary>
        /// 导入消息模板
        /// </summary>
        /// <param name="sExcelFile">Excel文件名</param>
        /// <param name="sSheetName">Sheet名</param>
        public void ImportMessageTemplate(string sExcelFile, string sSheetName)
        {
            try
            {
                ExcelData oExcel = new ExcelData(sExcelFile, sSheetName);
                DataColumn colOrgan = oExcel.ExcelTable.Columns["组织"];
                DataColumn colCode = oExcel.ExcelTable.Columns["代码"];
                DataColumn colNameCN = oExcel.ExcelTable.Columns["中文名称"];
                DataColumn colNameUS = oExcel.ExcelTable.Columns["英文名称"];
                DataColumn colMatterCN = oExcel.ExcelTable.Columns["中文内容"];
                DataColumn colMatterUS = oExcel.ExcelTable.Columns["英文内容"];
                DataColumn colRemark = oExcel.ExcelTable.Columns["备注"];

                foreach (DataRow row in oExcel.ExcelTable.Rows)
                {
                    string sOrganCode = row[colOrgan].ToString();
                    var oOrgan = (from o in dbEntity.MemberOrganizations
                                  where o.Code == sOrganCode && o.Otype == (byte)ModelEnum.OrganizationType.CORPORATION
                                  select o).FirstOrDefault();
                    string sCode = row[colCode].ToString();
                    GeneralResource oName = new GeneralResource(ModelEnum.ResourceType.STRING, 2052, row[colNameCN].ToString(), 1033, row[colNameUS].ToString());
                    GeneralLargeObject oMatter = new GeneralLargeObject(2052, row[colMatterCN].ToString(), 1033, row[colMatterUS].ToString());
                    string sRemark = row[colRemark].ToString();

                    var oTemplate = (from t in dbEntity.GeneralMessageTemplates
                                     where t.OrgID == oOrgan.Gid && t.Code == sCode
                                     select t).FirstOrDefault();
                    if (oTemplate == null)
                    {
                        oTemplate = new GeneralMessageTemplate { Organization = oOrgan, Code = sCode };
                        dbEntity.GeneralMessageTemplates.Add(oTemplate);
                    }
                    if (oTemplate.Name == null)
                        oTemplate.Name = oName;
                    else
                        oTemplate.Name.SetResource(ModelEnum.ResourceType.STRING, oName);
                    if (oTemplate.Matter == null)
                        oTemplate.Matter = oMatter;
                    else
                        oTemplate.Matter.SetLargeObject(oMatter);
                    oTemplate.Remark = sRemark;
                    dbEntity.SaveChanges();
                    if (Utility.ConfigHelper.GlobalConst.IsDebug)
                        Debug.WriteLine("{0} {1} {2}", this.ToString(), sCode, sRemark);
                }
                oEventBLL.WriteEvent(String.Format("导入GeneralMessageTemplate成功: {0} {1}", sExcelFile, sSheetName),
                    ModelEnum.ActionLevel.GENERIC, ModelEnum.ActionSource.SYSTEM, this.ToString());
            }
            catch (Exception ex)
            {
                oEventBLL.WriteEvent(String.Format("导入GeneralMessageTemplate错误: {0} {1} {2}", sExcelFile, sSheetName, ex.Message),
                    ModelEnum.ActionLevel.ERROR, ModelEnum.ActionSource.SYSTEM, this.ToString());
            }
        }
예제 #3
0
 public ActionResult MessageTemplateEditPost(GeneralMessageTemplate template,Guid gid)
 {
     try
     {
         //GeneralLargeObject o = dbEntity.GeneralLargeObjects.Single(item => item.Gid == gid);
         //o.CLOB.SetLargeObject(o);
         //o.CLOB = largeObject.CLOB;
         GeneralMessageTemplate oTemplate = dbEntity.GeneralMessageTemplates.Single(item => item.Gid == template.Gid);
         oTemplate.Matter.SetLargeObject(template.Matter);
         dbEntity.Entry(oTemplate).State = EntityState.Modified;
         dbEntity.SaveChanges();
         return RedirectToAction("Message");
     }
     catch
     {
         return RedirectToAction("Error");
     }
 }