加入收藏 | 设为首页 | 会员中心 | 我要投稿 济南站长网 (https://www.0531zz.com/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > MsSql教程 > 正文

ASP.NET MVC5+EF6+EasyUI后台管理系统 微信公众平台开发之消息管

发布时间:2016-11-24 06:30:56 所属栏目:MsSql教程 来源:站长网
导读:前言 回顾上一节,我们熟悉的了解了消息的请求和响应,这一节我们来建立数据库的表,表的设计蛮复杂 你也可以按自己所分析的情形结构来建表 必须非常熟悉表的结果才能运用这张表,这表表的情形涵盖比较多 思维导图 我这个人比较喜欢用思维导图来分析和表达

Controller

[HttpPost]
    [SupportFilter(ActionName = "Edit")]
    public JsonResult PostData(WC_MessageResponseModel model)
    {
      WC_OfficalAccountsModel accountModel = account_BLL.GetCurrentAccount();
      if (string.IsNullOrEmpty(model.Id))
      {
        model.Id = ResultHelper.NewId;
      }
      
      model.CreateBy = GetUserId();
      model.CreateTime = ResultHelper.NowTime;
      model.ModifyBy = GetUserId();
      model.ModifyTime = ResultHelper.NowTime;
      model.OfficalAccountId = accountModel.Id;
      model.Enable = true;
      model.IsDefault = true;
      if (m_BLL.PostData(ref errors, model))
      {
        LogHandler.WriteServiceLog(GetUserId(), "Id" + model.Id + ",OfficalAccountId" + model.OfficalAccountId, "成功", "保存", "WC_MessageResponse");
        return Json(JsonHandler.CreateMessage(1, Resource.SaveSucceed));
      }
      else
      {
        string ErrorCol = errors.Error;
        LogHandler.WriteServiceLog(GetUserId(), "Id" + model.Id + ",OfficalAccountId" + model.OfficalAccountId + "," + ErrorCol, "失败", "保存", "WC_MessageResponse");
        return Json(JsonHandler.CreateMessage(0, Resource.SaveFail + ErrorCol));
      }

    }

BLL

public bool PostData(ref ValidationErrors errors, WC_MessageResponseModel model)
    {
      try
      {

        WC_MessageResponse entity = new WC_MessageResponse();

        if (IsExists(model.Id))
        {
          entity = m_Rep.GetById(model.Id);
        }

        entity.Id = model.Id;
        entity.OfficalAccountId = model.OfficalAccountId;
        entity.MessageRule = model.MessageRule;
        entity.Category = model.Category;
        entity.MatchKey = model.MatchKey;
        entity.TextContent = model.TextContent;
        entity.ImgTextContext = model.ImgTextContext;
        entity.ImgTextUrl = model.ImgTextUrl;
        entity.ImgTextLink = model.ImgTextLink;
        entity.MeidaUrl = model.MeidaUrl;
        entity.Enable = model.Enable;
        entity.IsDefault = model.IsDefault;
        entity.Remark = model.Remark;
        entity.CreateTime = model.CreateTime;
        entity.CreateBy = model.CreateBy;
        entity.Sort = model.Sort;
        entity.ModifyTime = model.ModifyTime;
        entity.ModifyBy = model.ModifyBy;
        if (m_Rep.PostData(entity))
        {
          return true;
        }
        else
        {
          errors.Add(Resource.NoDataChange);
          return false;
        }

      }
      catch (Exception ex)
      {
        errors.Add(ex.Message);
        ExceptionHander.WriteException(ex);
        return false;
      }
    }

DAL

public bool PostData(WC_MessageResponse model)
    {
      //如果所有开关都关掉,证明不启用回复
      if (model.Category == null)
      {
        return true;
      }
      //全部设置为不默认
      ExecuteSqlCommand(string.Format("update [dbo].[WC_MessageResponse] set IsDefault=0 where OfficalAccountId ='{0}' and MessageRule={1}", model.OfficalAccountId, model.MessageRule));
      //默认回复和订阅回复,且不是图文另外处理,因为他们有3种模式,但是只有一个是默认的
      if (model.Category!= (int)WeChatReplyCategory.Image && (model.MessageRule == (int)WeChatRequestRuleEnum.Default || model.MessageRule == (int)WeChatRequestRuleEnum.Subscriber))
      {
        //查看数据库是否存在数据
        var entity = Context.WC_MessageResponse.Where(p => p.OfficalAccountId == model.OfficalAccountId && p.MessageRule == model.MessageRule && p.Category == model.Category).FirstOrDefault();
        if (entity != null)
        {
          //删除原来的
          Context.WC_MessageResponse.Remove(entity);
        }
      }
      //全部设置为默认
      ExecuteSqlCommand(string.Format("update [dbo].[WC_MessageResponse] set IsDefault=1 where OfficalAccountId ='{0}' and MessageRule={1} and Category={2}", model.OfficalAccountId, model.MessageRule,model.Category));
      //修改
      if(IsExist(model.Id))
      {
        Context.Entry<WC_MessageResponse>(model).State = EntityState.Modified;
        return Edit(model);
      }
      else { 
        return Create(model);
      }
    }

DAL层有必要来说明一下 

默认回复和关注回复有3种类型:文本,图文,语音(但是只能有一种,所以有IsDefault字段来表明执行哪种回复)所以这两个规则必须另外处理,且看DAL的代码执行的SQL语句便明白。 

所以我们尽情的设计前端吧!

 ASP.NET MVC5+EF6+EasyUI后台管理系统 微信公众平台开发之消息管

前端如何设计? 

我们来看一个思维导图: 

ASP.NET MVC5+EF6+EasyUI后台管理系统 微信公众平台开发之消息管  

前端完整代码 

<style>
  .formtable td {
    vertical-align: top;
    padding: 10px;
  }

  .formtable th {
    text-align: left;
    padding: 10px;
    height: 30px;
  }

  .formtablenormal {
    width: 500px;
  }

    .formtablenormal th {
      border: 0px;
      text-align: right;
    }

    .formtablenormal td {
      border: 0px;
      vertical-align: middle;
    }
</style>
<script>
  //1文本2图文3语音
  var Category = {
    Text: 1,
    Image: 2,
    Voice: 3,
    Equal: 4,
    Contain: 5
  };
  //
  var RequestRule = {
    Default: 0,
    Subscriber: 1,
    Text: 2,
    Image: 3,
    Voice: 4,
    Video: 5,
    Link: 6,
    Location: 7
  };

  function initDefault() {
    $('#swText0').switchbutton({
      onChange: function(checked) {
        if (checked) {
          $('#swImage0').switchbutton("uncheck");
          $('#swVoice0').switchbutton("uncheck");
          $("#div01").show();
          $("#div02,#div03").hide();
          $("#Category").val(Category.Text);
        }
      }
    });
    $('#swImage0').switchbutton({
      onChange: function(checked) {
        if (checked) {
          $('#swVoice0').switchbutton("uncheck");
          $('#swText0').switchbutton("uncheck");
          $("#div02").show();
          $("#div01,#div03").hide();
          $("#Category").val(Category.Image);
          $("#List0").datagrid("resize");
        }
      }
    });
    $('#swVoice0').switchbutton({
      onChange: function(checked) {
        if (checked) {
          $('#swImage0').switchbutton("uncheck");
          $('#swText0').switchbutton("uncheck");
          $("#div03").show();
          $("#div01,#div02").hide();
          $("#Category").val(Category.Voice);
        }
      }
    });
    //文本
    $.post('@Url.Action("GetList")', {
      page: 1,
      rows: 1,
      category: Category.Text,
      messageRule: RequestRule.Default
    },
    function(data) {
      var rows = data.rows;
      for (var i = 0; i < rows.length; i++) {
        if (rows[i].Category == Category.Text) {
          $("#Text0").val(rows[i].TextContent);
          if (rows[i].IsDefault) {
            $('#swText0').switchbutton("check");
            $('#swImage0').switchbutton("uncheck");
            $('#swVoice0').switchbutton("uncheck");
          }
        }
      }
    });
    //语音
    $.post('@Url.Action("GetList")', {
      page: 1,
      rows: 1,
      category: Category.Voice,
      messageRule: RequestRule.Default
    },
    function (data) {
      var rows = data.rows;
      for (var i = 0; i < rows.length; i++) {
        if (rows[i].Category == Category.Voice) {
          $("#VoiceTitle0").val(rows[i].TextContent);
          $("#VoiceContent0").val(rows[i].Remark);
          $("#VoiceUrl0").val(rows[i].MeidaUrl);
          if (rows[i].IsDefault) {
            $('#swVoice0').switchbutton("check");
            $('#swText0').switchbutton("uncheck");
            $('#swImage0').switchbutton("uncheck");
          }
        }
      }
    });

    $('#List0').datagrid({
      url: '@Url.Action("GetList")?messageRule=' + RequestRule.Default + '&category=' + Category.Image,
      width: SetGridWidthSub(40),
      methord: 'post',
      height: SetGridHeightSub(175),
      fitColumns: true,
      sortName: 'Sort',
      sortOrder: 'asc',
      idField: 'Id',
      pageSize: 15,
      pageList: [15, 20, 30, 40, 50],
      pagination: true,
      striped: true,
      //奇偶行是否区分
      singleSelect: true,
      onLoadSuccess: function (data) {
        if (data.rows.length > 0)
        {
          if (data.rows[0].IsDefault) {
            $('#swImage0').switchbutton("check");
            $('#swText0').switchbutton("uncheck");
            $('#swVoice0').switchbutton("uncheck");
            $("#Category").val(Category.Image);
          }
        }
      },
      //单选模式
      //rownumbers: true,//行号
      columns: [[{
        field: 'Id',
        title: 'Id',
        width: 80,
        hidden: true
      },
      {
        field: 'TextContent',
        title: '标题',
        width: 80,
        sortable: true
      },
      {
        field: 'ImgTextUrl',
        title: '图片',
        width: 50,
        sortable: true,
        align: 'center', formatter: function (value) { return "<img width='80' height='80' src='" + value + "'/>" }
      },
      {
        field: 'ImgTextLink',
        title: '超链接',
        width: 80,
        sortable: true
      },
      {
        field: 'ImgTextContext',
        title: '回复内容',
        width: 180,
        sortable: true
      },

      ]]
    });

    $("#btnCreate02").unbind().click(function () {
      $("#modalwindow0").window({
        title: '@Resource.Create',
        width: 700,
        height: 500,
        iconCls: 'fa fa-plus'
      }).window('open');
    });

    

    $("#btnSava01").unbind().click(function() {
      //默认回复
      $("#MessageRule").val(RequestRule.Default);
      if ($.trim($("#Text0").val())=="")
      {
        $.messager.alert('@Resource.Tip', '内容必须填写!', 'warning');
        return;
      }
      $("#TextContent").val($.trim($("#Text0").val()));
      if ($("#form").valid()) {
        $.ajax({
          url: "@Url.Action("PostData")",
          type: "Post",
          data: $("#form").serialize(),
        dataType: "json",
        success: function(data) {
          $.messageBox5s('@Resource.Tip', data.message);
        }
      });
    }
    });




    $("#btnSava02").unbind().click(function () {
      if ($.trim($("#ImageTitle0").val()) == "") {
        $.messager.alert('@Resource.Tip', '标题必须填写!', 'warning');
        return;
      }
      if ($.trim($("#ImageUrl0").val()) == "") {
        $.messager.alert('@Resource.Tip', '图片必须上传!', 'warning');
        return;
      }
      if ($.trim($("#Sort0").val()) == "") {
        $.messager.alert('@Resource.Tip', '排序必须填写!', 'warning');
        return;
      }
      //图文回复
      $("#MessageRule").val(RequestRule.Default);
      $("#TextContent").val($("#ImageTitle0").val());
      $("#ImgTextUrl").val($("#ImageUrl0").val());
      $("#ImgTextContext").val($("#ImageContent0").val());
      $("#ImgTextLink").val($("#ImageLink0").val());
      $("#Sort").val($("#Sort0").val());
      

      if ($("#form").valid()) {
        $.ajax({
          url: "@Url.Action("PostData")",
          type: "Post",
        data: $("#form").serialize(),
        dataType: "json",
        success: function(data) {
          if (data.type == 1) {
            $("#Id").val("");
            $("#List0").datagrid('reload');
            $("#modalwindow0").window('close');
            $("#ImageTitle0").val("");
            $("#form02 img").attr("src", "/Content/Images/NotPic.jpg");
            $("#ImageContent0").val("");
            $("#ImageLink0").val("");
            $("#Sort0").val(0);
            $('#FileUpload02').val('');
          }
          $.messageBox5s('@Resource.Tip', data.message);
        }
      });
    }
    });
    $("#btnSava03").unbind().click(function() {
      //默认回复
      $("#MessageRule").val(RequestRule.Default);
      if ($.trim($("#Text0").val())=="")
      {
        if ($.trim($("#VoiceTitle0").val()) == "") {
          $.messager.alert('@Resource.Tip', '标题必须填写!', 'warning');
          return;
        }
        if ($.trim($("#VoiceUrl0").val()) == "") {
          $.messager.alert('@Resource.Tip', '必须上传语音!', 'warning');
          return;
        }
        $("#TextContent").val($("#VoiceTitle0").val());
        $("#MeidaUrl").val($("#VoiceUrl0").val());
        $("#Remark").val($("#VoiceContent0").val());
      }

      if ($("#form").valid()) {
        $.ajax({
          url: "@Url.Action("PostData")",
          type: "Post",
        data: $("#form").serialize(),
        dataType: "json",
        success: function(data) {
          $.messageBox5s('@Resource.Tip', data.message);
        }
      });
    }
    });
  }

  function initSubscriber() {
     $('#swText1').switchbutton({
      onChange: function(checked) {
        if (checked) {
          $('#swImage1').switchbutton("uncheck");
          $('#swVoice1').switchbutton("uncheck");
          $("#div11").show();
          $("#div12,#div13").hide();
          $("#Category").val(Category.Text);
        }
      }
    });
    $('#swImage1').switchbutton({
      onChange: function(checked) {
        if (checked) {
          $('#swVoice1').switchbutton("uncheck");
          $('#swText1').switchbutton("uncheck");
          $("#div12").show();
          $("#div11,#div13").hide();
          $("#Category").val(Category.Image);
          $("#List1").datagrid("resize");
        }
      }
    });
    $('#swVoice1').switchbutton({
      onChange: function(checked) {
        if (checked) {
          $('#swImage1').switchbutton("uncheck");
          $('#swText1').switchbutton("uncheck");
          $("#div13").show();
          $("#div11,#div12").hide();
          $("#Category").val(Category.Voice);
        }
      }
    });
    //文本
    $.post('@Url.Action("GetList")', {
      page: 1,
      rows: 1,
      category: Category.Text,
      messageRule: RequestRule.Subscriber
    },
    function(data) {
      var rows = data.rows;
      for (var i = 0; i < rows.length; i++) {
        if (rows[i].Category == Category.Text) {
          $("#Text1").val(rows[i].TextContent);
          if (rows[i].IsDefault) {
            $('#swText1').switchbutton("check");
            $('#swImage1').switchbutton("uncheck");
            $('#swVoice1').switchbutton("uncheck");
          }
        }
      }
    });
    //语音
    $.post('@Url.Action("GetList")', {
      page: 1,
      rows: 1,
      category: Category.Voice,
      messageRule: RequestRule.Subscriber
    },
    function (data) {
      var rows = data.rows;
      for (var i = 0; i < rows.length; i++) {
        if (rows[i].Category == Category.Voice) {
          $("#VoiceTitle1").val(rows[i].TextContent);
          $("#VoiceContent1").val(rows[i].Remark);
          if (rows[i].IsDefault) {
            $('#swVoice1').switchbutton("check");
            $('#swText1').switchbutton("uncheck");
            $('#swImage1').switchbutton("uncheck");
          }
        }
      }
    });

    $('#List1').datagrid({
      url: '@Url.Action("GetList")?messageRule=' + RequestRule.Subscriber + '&category=' + Category.Image,
      width: SetGridWidthSub(40),
      methord: 'post',
      height: SetGridHeightSub(175),
      fitColumns: true,
      sortName: 'Sort',
      sortOrder: 'asc',
      idField: 'Id',
      pageSize: 15,
      pageList: [15, 20, 30, 40, 50],
      pagination: true,
      striped: true,
      //奇偶行是否区分
      singleSelect: true,
      onLoadSuccess: function (data) {
        if (data.rows.length > 0)
        {
          if (data.rows[0].IsDefault) {
            $('#swImage1').switchbutton("check");
            $('#swText1').switchbutton("uncheck");
            $('#swVoice1').switchbutton("uncheck");
          }
        }
      },
      //单选模式
      //rownumbers: true,//行号
      columns: [[{
        field: 'Id',
        title: 'Id',
        width: 80,
        hidden: true
      },
      {
        field: 'TextContent',
        title: '标题',
        width: 80,
        sortable: true
      },
      {
        field: 'ImgTextUrl',
        title: '图片',
        width: 50,
        sortable: true,
        align: 'center', formatter: function (value) { return "<img width='80' height='80' src='" + value + "'/>" }
      },
      {
        field: 'ImgTextLink',
        title: '超链接',
        width: 80,
        sortable: true
      },
      {
        field: 'ImgTextContext',
        title: '回复内容',
        width: 180,
        sortable: true
      },

      ]]
    });

    $("#btnCreate12").unbind().click(function () {
      $("#modalwindow1").window({
        title: '@Resource.Create',
        width: 700,
        height: 500,
        iconCls: 'fa fa-plus'
      }).window('open');
    });
   

    $("#btnSava11").unbind().click(function() {
      //默认回复
      $("#MessageRule").val(RequestRule.Subscriber);
      if ($.trim($("#Text1").val())=="")
      {
        $.messager.alert('@Resource.Tip', '内容必须填写!', 'warning');
        return;
      }
      $("#TextContent").val($.trim($("#Text1").val()));
      if ($("#form").valid()) {
        $.ajax({
          url: "@Url.Action("PostData")",
          type: "Post",
          data: $("#form").serialize(),
        dataType: "json",
        success: function(data) {
          $.messageBox5s('@Resource.Tip', data.message);
        }
      });
    }
    });

    $("#btnSava12").unbind().click(function () {
      if ($.trim($("#ImageTitle1").val()) == "") {
        $.messager.alert('@Resource.Tip', '标题必须填写!', 'warning');
        return;
      }
      if ($.trim($("#ImageUrl1").val()) == "") {
        $.messager.alert('@Resource.Tip', '图片必须上传!', 'warning');
        return;
      }
      if ($.trim($("#Sort1").val()) == "") {
        $.messager.alert('@Resource.Tip', '排序必须填写!', 'warning');
        return;
      }
      //图文回复
      $("#MessageRule").val(RequestRule.Subscriber);
      $("#TextContent").val($("#ImageTitle1").val());
      $("#ImgTextUrl").val($("#ImageUrl1").val());
      $("#ImgTextContext").val($("#ImageContent1").val());
      $("#ImgTextLink").val($("#ImageLink1").val());
      $("#Sort").val($("#Sort1").val());
      
      if ($("#form").valid()) {
        $.ajax({
          url: "@Url.Action("PostData")",
          type: "Post",
        data: $("#form").serialize(),
        dataType: "json",
        success: function(data) {
          if (data.type == 1) {
            $("#Id").val("");
            $("#List1").datagrid('reload');
            $("#modalwindow1").window('close');
            $("#ImageTitle1").val("");
            $("#form12 img").attr("src", "/Content/Images/NotPic.jpg");
            $("#ImageContent1").val("");
            $("#ImageLink1").val("");
            $("#Sort1").val(0);
            $('#FileUpload12').val('');
          }
          $.messageBox5s('@Resource.Tip', data.message);
        }
      });
    }
    });
    $("#btnSava13").unbind().click(function() {
      //默认回复
      $("#MessageRule").val(RequestRule.Subscriber);
      if ($.trim($("#Text1").val())=="")
      {
        if ($.trim($("#VoiceTitle1").val()) == "") {
          $.messager.alert('@Resource.Tip', '标题必须填写!', 'warning');
          return;
        }
        if ($.trim($("#VoiceUrl1").val()) == "") {
          $.messager.alert('@Resource.Tip', '必须上传语音!', 'warning');
          return;
        }
        $("#TextContent").val($("#VoiceTitle1").val());
        $("#MeidaUrl").val($("#VoiceUrl1").val());
        $("#Remark").val($("#VoiceContent1").val());
      }

      if ($("#form").valid()) {
        $.ajax({
          url: "@Url.Action("PostData")",
          type: "Post",
        data: $("#form").serialize(),
        dataType: "json",
        success: function(data) {
          $.messageBox5s('@Resource.Tip', data.message);
        }
      });
    }
    });
  }

  function initText() {
    $("#Category").val(Category.Equal);
    $('#List2').datagrid({
      url: '@Url.Action("GetList")?messageRule=' + RequestRule.Text,
      width: SetGridWidthSub(40),
      methord: 'post',
      height: SetGridHeightSub(100),
      fitColumns: true,
      sortName: 'CreateTime',
      sortOrder: 'desc',
      idField: 'Id',
      pageSize: 15,
      pageList: [15, 20, 30, 40, 50],
      pagination: true,
      striped: true,
      //奇偶行是否区分
      singleSelect: true,
      //单选模式
      //rownumbers: true,//行号
      columns: [[{
        field: 'Id',
        title: 'Id',
        width: 80,
        hidden: true
      },
      {
        field: 'Category',
        title: 'Category',
        width: 80,
        sortable: true,
        hidden: true
      },
      {
        field: 'MatchKey',
        title: '关键字',
        width: 80,
        sortable: true,
        formatter: function (value,row,index){
          if (row.Category == Category.Equal) {
            return "(完全匹配)" + value
          } else {
            return "(模糊匹配)" + value
          }
        }
      },
      {
        field: 'TextContent',
        title: '回复内容',
        width: 80,
        sortable: true
      },

      ]]
    });

    $('#swMessageRule2').switchbutton({
      onChange: function(checked) {
        if (checked) {
          $("#Category").val(Category.Equal);
        } else {
          $("#Category").val(Category.Contain);
        }
      }
    });
    $("#btnCreate2").unbind().click(function () {
      $("#modalwindow2").window({
        title: '@Resource.Create',
        width: 700,
        height: 400,
        iconCls: 'fa fa-plus'
      }).window('open');
    });

    $("#btnSava2").unbind().click(function () {
      if ($.trim($("#TextMatchKey2").val()) == "") {
        $.messager.alert('@Resource.Tip', '关键字必须填写!', 'warning');
        return;
      }
      if ($.trim($("#Text2").val()) == "") {
        $.messager.alert('@Resource.Tip', '内容必须填写!', 'warning');
        return;
      }
      //文本回复
      $("#MessageRule").val(RequestRule.Text);
      $("#MatchKey").val($.trim($("#TextMatchKey2").val()));
      $("#TextContent").val($("#Text2").val());
      if ($("#form").valid()) {
        $.ajax({
          url: "@Url.Action("PostData")",
          type: "Post",
        data: $("#form").serialize(),
        dataType: "json",
        success: function(data) {
          if (data.type == 1) {
            $("#Id").val("");
            $("#List2").datagrid('reload');
            $("#modalwindow2").window('close');
            $("#TextMatchKey2").val("");
            $("#Text2").val("");
          }
          $.messageBox5s('@Resource.Tip', data.message);
        }
      });
    }
    });
  }


  function initImage() {
    $("#Category").val(Category.Equal);
    $('#List31').datagrid({
      url: '@Url.Action("GetListProperty")?messageRule=' + RequestRule.Image,
      width: 300,
      methord: 'post',
      height: SetGridHeightSub(100),
      fitColumns: true,
      sortName: 'CreateTime',
      sortOrder: 'desc',
      idField: 'Id',
      pageSize: 15,
      pageList: [15, 20, 30, 40, 50],
      pagination: true,
      striped: true,
      //奇偶行是否区分
      singleSelect: true,
      onClickRow: function (index,data) {
        var row = $('#List31').datagrid('getSelected');
        if (row != null)
        {
          $('#List3').datagrid({url:'@Url.Action("GetList")?messageRule='+RequestRule.Image+'&category='+row.Category+'&matchKey='+row.MatchKey});
        }
      },
      //单选模式
      //rownumbers: true,//行号
      columns: [[{
        field: 'Id',
        title: 'Id',
        width: 80,
        hidden: true
      },
      {
        field: 'Category',
        title: 'Category',
        width: 80,
        sortable: true,
        hidden: true
      },
      {
        field: 'MatchKey',
        title: '关键字',
        width: 130,
        sortable: true,
        formatter: function (value, row, index) {
          if (row.Category == Category.Equal) {
            return "(完全匹配)" + value
          } else {
            return "(模糊匹配)" + value
          }
        }
      },
      {
        field: 'CreateTime',
        title: '创建时间',
        width: 80,
        sortable: true
      },

      ]]
    }).datagrid('getPager').pagination({ showPageList: true, showRefresh: false, displayMsg: '' });


    $('#List3').datagrid({
      url:'@Url.Action("GetList")?messageRule='+RequestRule.Image+'&category=x&matchKey=x',
      width: SetGridWidthSub(340),
      methord: 'post',
      height: SetGridHeightSub(100),
      fitColumns: true,
      sortName: 'Sort',
      sortOrder: 'asc',
      idField: 'Id',
      pageSize: 15,
      pageList: [15, 20, 30, 40, 50],
      pagination: true,
      striped: true,
      //奇偶行是否区分
      singleSelect: true,
      //单选模式
      //rownumbers: true,//行号
      columns: [[{
        field: 'Id',
        title: 'Id',
        width: 80,
        hidden: true
      },
      {
        field: 'Category',
        title: 'Category',
        width: 80,
        sortable: true,
        hidden: true
      },
      {
        field: 'TextContent',
        title: '标题',
        width: 80,
        sortable: true
      },
      {
        field: 'MatchKey',
        title: '关键字',
        width: 80,
        sortable: true,
        formatter: function (value,row,index){
          if (row.Category == Category.Equal) {
            return "(完全匹配)" + value
          } else {
            return "(模糊匹配)" + value
          }
        }
      },
      {
        field: 'ImgTextUrl',
        title: '图片',
        width: 50,
        sortable: true,
        align: 'center', formatter: function (value) { return "<img width='80' height='80' src='" + value + "'/>" }
      },
      {
        field: 'ImgTextLink',
        title: '超链接',
        width: 80,
        sortable: true
      },
      {
        field: 'ImgTextContext',
        title: '回复内容',
        width: 180,
        sortable: true
      },
      {
        field: 'Sort',
        title: '排序',
        width: 50,
        sortable: true
      },
      ]]
    });

    $('#swMessageRule3').switchbutton({
      onChange: function(checked) {
        if (checked) {
          $("#Category").val(Category.Equal);
        } else {
          $("#Category").val(Category.Contain);
        }
      }
    });
    $("#btnCreate3").unbind().click(function () {
      $("#modalwindow3").window({
        title: '@Resource.Create',
        width: 700,
        height: 550,
        iconCls: 'fa fa-plus'
      }).window('open');
    });

   
    $("#btnSava3").unbind().click(function () {
      if ($.trim($("#ImageTitle3").val()) == "") {
        $.messager.alert('@Resource.Tip', '标题必须填写!', 'warning');
        return;
      }
      if ($.trim($("#TextMatchKey3").val()) == "") {
        $.messager.alert('@Resource.Tip', '关键字必须填写!', 'warning');
        return;
      }
      if ($.trim($("#ImageUrl3").val()) == "") {
        $.messager.alert('@Resource.Tip', '图片必须上传!', 'warning');
        return;
      }
      //图文回复
      $("#MessageRule").val(RequestRule.Image);
      $("#MatchKey").val($.trim($("#TextMatchKey3").val()));
      $("#TextContent").val($("#ImageTitle3").val());
      $("#ImgTextUrl").val($("#ImageUrl3").val());
      $("#ImgTextContext").val($("#ImageContent3").val());
      $("#ImgTextLink").val($("#ImageLink3").val());
      $("#Sort").val($("#Sort3").val());
      if ($("#form").valid()) {
        $.ajax({
          url: "@Url.Action("PostData")",
          type: "Post",
        data: $("#form").serialize(),
        dataType: "json",
        success: function(data) {
          if (data.type == 1) {
            $("#Id").val("");
            $("#List3").datagrid('reload');
            $("#List31").datagrid('reload');
            $("#modalwindow3").window('close');
            $("#ImageTitle3").val("");
            $("#form3 img").attr("src", "/Content/Images/NotPic.jpg");
            $("#ImageContent3").val("");
            $("#ImageLink3").val("");
            $("#Sort3").val(0);
            $('#FileUpload3').val('');
            $("#TextMatchKey3").val('');
          }
          $.messageBox5s('@Resource.Tip', data.message);
        }
      });
    }
    });
  }

  function initVoice() {
    $("#Category").val(Category.Equal);
    $('#List4').datagrid({
      url: '@Url.Action("GetList")?messageRule=' + RequestRule.Voice,
      width: SetGridWidthSub(40),
      methord: 'post',
      height: SetGridHeightSub(100),
      fitColumns: true,
      sortName: 'CreateTime',
      sortOrder: 'desc',
      idField: 'Id',
      pageSize: 15,
      pageList: [15, 20, 30, 40, 50],
      pagination: true,
      striped: true,
      //奇偶行是否区分
      singleSelect: true,
      //单选模式
      //rownumbers: true,//行号
      columns: [[{
        field: 'Id',
        title: 'Id',
        width: 80,
        hidden: true
      },
      {
        field: 'Category',
        title: 'Category',
        width: 80,
        sortable: true,
        hidden: true
      },
      {
        field: 'TextContent',
        title: '标题',
        width: 80,
        sortable: true
      },
      {
        field: 'MatchKey',
        title: '关键字',
        width: 80,
        sortable: true,
        formatter: function (value,row,index){
          if (row.Category == Category.Equal) {
            return "(完全匹配)" + value
          } else {
            return "(模糊匹配)" + value
          }
        }
      },
      {
        field: 'MeidaUrl',
        title: '语音',
        width: 80,
        sortable: true,
        align: 'center', formatter: function (value) { return "<img width='80' height='80' src='" + value + "'/>" }
      },
      {
        field: 'ImgTextLink',
        title: '超链接',
        width: 80,
        sortable: true
      },
      {
        field: 'ImgTextContext',
        title: '回复内容',
        width: 80,
        sortable: true
      },

      ]]
    });

    $('#swMessageRule4').switchbutton({
      onChange: function(checked) {
        if (checked) {
          $("#Category").val(Category.Equal);
        } else {
          $("#Category").val(Category.Contain);
        }
      }
    });
    $("#btnCreate4").unbind().click(function() {
      $("#modalwindow4").window({
        title: '@Resource.Create',
        width: 700,
        height: 500,
        iconCls: 'fa fa-plus'
      }).window('open');
    });

  
    $("#btnSava4").unbind().click(function () {
      if ($.trim($("#VoiceTitle4").val()) == "") {
        $.messager.alert('@Resource.Tip', '标题必须填写!', 'warning');
        return;
      }
      if ($.trim($("#TextMatchKey4").val()) == "") {
        $.messager.alert('@Resource.Tip', '关键字必须填写!', 'warning');
        return;
      }
      if ($.trim($("#VoiceUrl4").val()) == "") {
        $.messager.alert('@Resource.Tip', '必须上传语音!', 'warning');
        return;
      }
      //图文回复
      $("#MessageRule").val(RequestRule.Voice);
      $("#MatchKey").val($("#TextMatchKey4").val());
      $("#TextContent").val($("#VoiceTitle4").val());
      $("#MeidaUrl").val($("#VoiceUrl4").val());
      $("#Remark").val($("#VoiceContent4").val());
      if ($("#form").valid()) {
        $.ajax({
          url: "@Url.Action("PostData")",
          type: "Post",
        data: $("#form").serialize(),
        dataType: "json",
        success: function(data) {
          if (data.type == 1) {
            $("#Id").val("");
            $("#List4").datagrid('reload');
            $("#modalwindow4").window('close');
            $("#TextMatchKey4").val("");
            $("#VoiceTitle4").val("");
            $("#VoiceUrl4").val("");
            $("#VoiceContent4").val("");
            $("#FileUpload4").val("");
            $("#form3 img").attr("src", "/Content/Images/NotPic.jpg");
          }
          $.messageBox5s('@Resource.Tip', data.message);
        }
      });
    }
    });
  }
  $(function() {
    $('#tt').tabs({
      justified: true,
      width: '100%',
      height: $(window).height() - 20
    });
    $('#tt').tabs({
      onSelect: function(title, index) {
        switch (index) {
          case RequestRule.Default:
            initDefault();
            break;
          case RequestRule.Subscriber:
            initSubscriber();
            break;
          case RequestRule.Text:
            initText();
            break;
          case RequestRule.Image:
            initImage();
            break;
          case RequestRule.Voice:
            initVoice();
            break;
        }
      }
    });
    //初始化第一个标签
    initDefault();

    //自动宽高
    $(window).resize(function() {
      $('#tt').tabs({
        height:$(window).height() - 20
      });
      //$('#List2').datagrid('resize', {
      //  width: SetGridWidthSub(40),
      //  height: SetGridHeightSub(100)
      /                        

(编辑:济南站长网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

热点阅读