public string PreviewTemplate(SmsTemplateInfo model) { try { model.TemplateType = model.TemplateType.Trim(); model.SmsContent = model.SmsContent.Trim(); model.OrderCode = model.OrderCode.Trim(); model.ParamsCode = model.ParamsCode.Trim(); model.ParamsCode = model.ParamsCode.Trim(); if (model.TemplateType == "auto") { if (model.OrderCode == "") { return("订单号不能为空字符串,自动模板类型必须有订单号才能预览"); } } SmsTemplate smstBll = new SmsTemplate(); return(smstBll.GetTemplateContent(model.OrderCode, model)); } catch (Exception ex) { return("异常:" + ex.Message + ""); } }
public SmsTemplateInfo GetModelByEnumCode(string enumCode) { SmsTemplateInfo model = null; string cmdText = @"select top 1 smst.Id,smst.UserId,smst.Title,smst.ParamsCode,smst.ParamsName,smst.ParamsValue,smst.SmsContent,smst.TemplateType,smst.IsDefault,smst.LastUpdatedDate from [Sms_Template] smst join Sys_Enum se on se.EnumValue = smst.Title and se.EnumCode = @EnumCode "; SqlParameter parm = new SqlParameter("@EnumCode", enumCode); using (SqlDataReader reader = SqlHelper.ExecuteReader(SqlHelper.SqlProviderConnString, CommandType.Text, cmdText, parm)) { if (reader != null) { while (reader.Read()) { model = new SmsTemplateInfo(); model.Id = reader["Id"]; model.UserId = reader["UserId"]; model.Title = reader.GetString(2); model.ParamsCode = reader.GetString(3); model.ParamsName = reader.GetString(4); model.ParamsValue = reader.GetString(5); model.SmsContent = reader.GetString(6); model.TemplateType = reader.GetString(7); model.IsDefault = reader.GetBoolean(8); model.LastUpdatedDate = reader.GetDateTime(9); } } } return(model); }
public int Insert(SmsTemplateInfo model) { if (model == null) { return(-1); } string cmdText = @"insert into [Sms_Template] (UserId,Title,ParamsCode,ParamsName,ParamsValue,SmsContent,TemplateType,IsDefault,LastUpdatedDate) values (@UserId,@Title,@ParamsCode,@ParamsName,@ParamsValue,@SmsContent,@TemplateType,@IsDefault,@LastUpdatedDate)"; SqlParameter[] parms = { new SqlParameter("@UserId", SqlDbType.UniqueIdentifier), new SqlParameter("@Title", SqlDbType.NVarChar, 50), new SqlParameter("@ParamsCode", SqlDbType.VarChar, 256), new SqlParameter("@ParamsName", SqlDbType.NVarChar, 256), new SqlParameter("@ParamsValue", SqlDbType.NVarChar, 400), new SqlParameter("@SmsContent", SqlDbType.NVarChar, 500), new SqlParameter("@TemplateType", SqlDbType.VarChar, 20), new SqlParameter("@IsDefault", SqlDbType.Bit), new SqlParameter("@LastUpdatedDate", SqlDbType.DateTime) }; parms[0].Value = model.UserId; parms[1].Value = model.Title; parms[2].Value = model.ParamsCode; parms[3].Value = model.ParamsName; parms[4].Value = model.ParamsValue; parms[5].Value = model.SmsContent; parms[6].Value = model.TemplateType; parms[7].Value = model.IsDefault; parms[8].Value = model.LastUpdatedDate; return(SqlHelper.ExecuteNonQuery(SqlHelper.SqlProviderConnString, CommandType.Text, cmdText, parms)); }
public SmsTemplateInfo GetModel(object Id) { SmsTemplateInfo model = null; string cmdText = @"select top 1 Id,UserId,Title,ParamsCode,ParamsName,ParamsValue,SmsContent,TemplateType,IsDefault,LastUpdatedDate from [Sms_Template] where Id = @Id "; SqlParameter parm = new SqlParameter("@Id", SqlDbType.UniqueIdentifier); parm.Value = Guid.Parse(Id.ToString()); using (SqlDataReader reader = SqlHelper.ExecuteReader(SqlHelper.SqlProviderConnString, CommandType.Text, cmdText, parm)) { if (reader != null) { while (reader.Read()) { model = new SmsTemplateInfo(); model.Id = reader["Id"]; model.UserId = reader["UserId"]; model.Title = reader.GetString(2); model.ParamsCode = reader.GetString(3); model.ParamsName = reader.GetString(4); model.ParamsValue = reader.GetString(5); model.SmsContent = reader.GetString(6); model.TemplateType = reader.GetString(7); model.IsDefault = reader.GetBoolean(8); model.LastUpdatedDate = reader.GetDateTime(9); } } } return(model); }
public HandlerResponse AddTemplate() { SmsTemplateInfo info = new SmsTemplateInfo(); info.EnterpriseID = AppContent.Current.GetCurrentUser().EnterpriseID; info.SmsContent = Request.Params["template"]; info.CreateTime = DateTime.Now; SmsTemplateManage.Instance.AddTemplate(info); return CreateHandler(1, "添加成功"); }
public HandlerResponse AddTemplate() { SmsTemplateInfo info = new SmsTemplateInfo(); info.EnterpriseID = AppContent.Current.GetCurrentUser().EnterpriseID; info.SmsContent = Request.Params["template"]; info.CreateTime = DateTime.Now; SmsTemplateManage.Instance.AddTemplate(info); return(CreateHandler(1, "添加成功")); }
public HandlerResponse EditTemplate() { SmsTemplateInfo info = new SmsTemplateInfo(); info.EnterpriseID = AppContent.Current.GetCurrentUser().EnterpriseID; info.SmsContent = Request.Params["template"]; info.CreateTime = DateTime.Now; info.ID = Convert.ToInt32(Request.Params["id"]); SmsTemplateManage.Instance.EditTemplate(info); return CreateHandler(1, "修改成功"); }
public HandlerResponse EditTemplate() { SmsTemplateInfo info = new SmsTemplateInfo(); info.EnterpriseID = AppContent.Current.GetCurrentUser().EnterpriseID; info.SmsContent = Request.Params["template"]; info.CreateTime = DateTime.Now; info.ID = Convert.ToInt32(Request.Params["id"]); SmsTemplateManage.Instance.EditTemplate(info); return(CreateHandler(1, "修改成功")); }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { int id = Convert.ToInt32(Request.QueryString["id"]); TemplateHandler handler = new TemplateHandler(); SmsTemplateInfo info = handler.GetTemplateInfo(id); template = info.SmsContent; tid = info.ID.ToString(); Page.DataBind(); } }
public List <SmsTemplateInfo> GetList(int pageIndex, int pageSize, out int totalRecords, string sqlWhere, params SqlParameter[] cmdParms) { //获取数据集总数 string cmdText = "select count(*) from [Sms_Template] "; if (!string.IsNullOrEmpty(sqlWhere)) { cmdText += "where 1=1 " + sqlWhere; } totalRecords = (int)SqlHelper.ExecuteScalar(SqlHelper.SqlProviderConnString, CommandType.Text, cmdText, cmdParms); //返回分页数据 int startIndex = (pageIndex - 1) * pageSize + 1; int endIndex = pageIndex * pageSize; cmdText = @"select * from(select row_number() over(order by LastUpdatedDate desc) as RowNumber, Id,UserId,Title,ParamsCode,ParamsName,ParamsValue,SmsContent,TemplateType,IsDefault,LastUpdatedDate from [Sms_Template] "; if (!string.IsNullOrEmpty(sqlWhere)) { cmdText += "where 1=1 " + sqlWhere; } cmdText += ")as objTable where RowNumber between " + startIndex + " and " + endIndex + " "; List <SmsTemplateInfo> list = new List <SmsTemplateInfo>(); using (SqlDataReader reader = SqlHelper.ExecuteReader(SqlHelper.SqlProviderConnString, CommandType.Text, cmdText, cmdParms)) { if (reader != null && reader.HasRows) { while (reader.Read()) { SmsTemplateInfo model = new SmsTemplateInfo(); model.Id = reader["Id"]; model.UserId = reader["UserId"]; model.Title = reader.GetString(3); model.ParamsCode = reader.GetString(4); model.ParamsName = reader.GetString(5); model.ParamsValue = reader.GetString(6); model.SmsContent = reader.GetString(7); model.TemplateType = reader.GetString(8); model.IsDefault = reader.GetBoolean(9); model.LastUpdatedDate = reader.GetDateTime(10); list.Add(model); } } } return(list); }
/// <summary> /// 获取模板内容 /// </summary> /// <param name="dt">订单号对应的参数集</param> /// <param name="model"></param> /// <returns></returns> public string GetTemplateContentByTranNode(DataTable dt, SmsTemplateInfo model) { if (model == null) { return(""); } if (model.TemplateType == "auto") { if (dt == null || dt.Rows.Count == 0) { return(""); } DataRow dr = dt.Rows[0]; DataColumnCollection dcc = dt.Columns; string[] tParms = model.ParamsCode.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); string[] tParmsValues = new string[tParms.Length]; for (int i = 0; i < tParms.Length; i++) { if (dcc.Contains(tParms[i])) { if (dr[tParms[i]] != DBNull.Value) { tParmsValues[i] = dr[tParms[i]].ToString(); } else { tParmsValues[i] = ""; } } else { tParmsValues[i] = ""; } } return(string.Format(model.SmsContent, tParmsValues)); } else if (model.TemplateType == "custom") { return(string.Format(model.SmsContent, model.ParamsValue.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries))); } else { return(model.SmsContent); } }
/// <summary> /// 获取当前模板内容 /// </summary> /// <param name="orderCode"></param> /// <param name="model"></param> /// <returns></returns> public string GetTemplateContent(string orderCode, SmsTemplateInfo model) { if (model.TemplateType == "auto") { DataTable dt = null; SmsSend ssBll = new SmsSend(); DataSet ds = ssBll.GetSmsParams(orderCode); if (ds != null && ds.Tables.Count > 0) { dt = ds.Tables[0]; } return(GetTemplateContentByAuto(dt, model.SmsContent, model.ParamsCode)); } else if (model.TemplateType == "custom") { return(string.Format(model.SmsContent, model.ParamsValue.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries))); } else { return(model.SmsContent); } }
public List <SmsTemplateInfo> GetList(string sqlWhere, params SqlParameter[] cmdParms) { string cmdText = @"select Id,UserId,Title,ParamsCode,ParamsName,ParamsValue,SmsContent,TemplateType,IsDefault,LastUpdatedDate from [Sms_Template] "; if (!string.IsNullOrEmpty(sqlWhere)) { cmdText += "where 1=1 " + sqlWhere; } List <SmsTemplateInfo> list = new List <SmsTemplateInfo>(); using (SqlDataReader reader = SqlHelper.ExecuteReader(SqlHelper.SqlProviderConnString, CommandType.Text, cmdText, cmdParms)) { if (reader != null && reader.HasRows) { while (reader.Read()) { SmsTemplateInfo model = new SmsTemplateInfo(); model.Id = reader["Id"]; model.UserId = reader["UserId"]; model.Title = reader.GetString(2); model.ParamsCode = reader.GetString(3); model.ParamsName = reader.GetString(4); model.ParamsValue = reader.GetString(5); model.SmsContent = reader.GetString(6); model.TemplateType = reader.GetString(7); model.IsDefault = reader.GetBoolean(8); model.LastUpdatedDate = reader.GetDateTime(9); list.Add(model); } } } return(list); }
/// <summary> /// 修改数据 /// </summary> /// <param name="model"></param> /// <returns></returns> public int Update(SmsTemplateInfo model) { return(dal.Update(model)); }
public string SaveSmgTemplate(SmsTemplateInfo model) { try { if (string.IsNullOrWhiteSpace(model.Title) || string.IsNullOrWhiteSpace(model.SmsContent)) { return(MessageContent.Submit_Params_InvalidError); } model.Title = model.Title.Trim(); model.ParamsCode = model.ParamsCode.Trim(); model.ParamsName = model.ParamsName.Trim(); model.ParamsValue = model.ParamsValue.Trim(); model.SmsContent = model.SmsContent.Trim(); model.TemplateType = model.TemplateType.Trim(); if (model.TemplateType != "") { if (model.ParamsCode == "" || model.ParamsValue == "" || model.ParamsName == "") { return("模板类型不为空字符串时,则已选参数不能为空字符串"); } } try { if (model.TemplateType == "auto") { string content = string.Format(model.SmsContent, model.ParamsCode.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries)); } else if (model.TemplateType == "custom") { string content = string.Format(model.SmsContent, model.ParamsValue.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries)); } } catch { return("保存失败,原因:已选参数与短信内容匹配有错,请正确操作"); } model.LastUpdatedDate = DateTime.Now; model.UserId = Common.GetUserId(context); SmsTemplate smstBll = new SmsTemplate(); if (model.Id != null && !string.IsNullOrEmpty(model.Id.ToString())) { Guid gId = Guid.Empty; Guid.TryParse(model.Id.ToString(), out gId); if (gId.Equals(Guid.Empty)) { return(MessageContent.GetString(MessageContent.Request_InvalidArgument, "当前数据行主键标识")); } model.Id = gId; smstBll.Update(model); } else { smstBll.Insert(model); } return("1"); } catch (Exception ex) { return(ex.Message); } }
/// <summary> /// 添加数据到数据库 /// </summary> /// <param name="model"></param> /// <returns></returns> public int Insert(SmsTemplateInfo model) { return(dal.Insert(model)); }
/// <summary> /// 获取订单各个运输节点发送模板内容 /// </summary> /// <param name="dt"></param> /// <param name="tranNode"></param> /// <param name="receiver"></param> /// <returns></returns> public List <string> GetTemplateContentByTranNode(DataTable dt, string tranNode) { List <string> list = new List <string>(); SmsTemplateInfo model = null; switch (tranNode) { case "SendGoods": model = GetModelByEnumCode("SendGoodsTemplate"); #region 取货模板 string content = GetTemplateContentByTranNode(dt, model); if (!string.IsNullOrEmpty(content)) { list.Add(content); } #endregion break; case "MainSend": model = GetModelByEnumCode("MainSendForSenderTemplate"); #region 干线发运发货方短信模板 content = GetTemplateContentByTranNode(dt, model); if (!string.IsNullOrEmpty(content)) { list.Add(content); } #endregion model = GetModelByEnumCode("MainSendForReceiverTemplate"); #region 干线发运收货方短信模板 content = GetTemplateContentByTranNode(dt, model); if (!string.IsNullOrEmpty(content)) { list.Add(content); } #endregion break; case "MainReach": model = GetModelByEnumCode("MainReachForSenderTemplate"); content = GetTemplateContentByTranNode(dt, model); if (!string.IsNullOrEmpty(content)) { list.Add(content); } model = GetModelByEnumCode("MainReachForReceiverTemplate"); content = GetTemplateContentByTranNode(dt, model); if (!string.IsNullOrEmpty(content)) { list.Add(content); } break; case "GoodsShipment": model = GetModelByEnumCode("GoodsShipmentForSenderTemplate"); content = GetTemplateContentByTranNode(dt, model); if (!string.IsNullOrEmpty(content)) { list.Add(content); } model = GetModelByEnumCode("GoodsShipmentForReceiverTemplate"); content = GetTemplateContentByTranNode(dt, model); if (!string.IsNullOrEmpty(content)) { list.Add(content); } break; case "CustomerReceive": model = GetModelByEnumCode("CustomerReceiveTemplate"); content = GetTemplateContentByTranNode(dt, model); if (!string.IsNullOrEmpty(content)) { list.Add(content); } break; default: break; } return(list); }