• 企业400电话
  • 微网小程序
  • AI电话机器人
  • 电商代运营
  • 全 部 栏 目

    企业400电话 网络优化推广 AI电话机器人 呼叫中心 网站建设 商标✡知产 微网小程序 电商运营 彩铃•短信 增值拓展业务
    ASP.NET MVC使用EasyUI的datagrid多选提交保存教程
    需要实现EasyUI的datagrid组件加入选择checkbox列,并提交后台批量添加的功能,页面代码如下:
    复制代码 代码如下:

    script language="javascript" type="text/javascript">
    $(function() {
    //searchbox
    $('#selectgoods-keywords').searchbox({
    searcher: function(val, name) {
    searchInfo(val);
    }
    });
    //datagrid
    $('#selectgoods-grid').datagrid({
    url: '/Goods/List',
    pageNumber: 1,
    pageSize: 20,
    pageList: [20, 40, 60, 80, 100]
    });
    //form
    });
    function searchInfo(val){
    // var keytype=$('#keyType').combobox('getValue');
    var keytype = 'Goods_Name';
    var keywords = val;
    $('#selectgoods-grid').datagrid('reload', { keytype: keytype, keywords: keywords });
    }
    function saveSelectGoods() {
    var ids = [];
    var rows = $('#selectgoods-grid').datagrid('getSelections');
    for (var i = 0; i rows.length; i++) {
    ids.push(rows[i].Identifier);
    }
    var selectsupplier = '%=ViewData["supplier"] %>';
    $.post('/SupplierGoods/SaveSelect', { supplier: selectsupplier, checks: ids.join(',') }, function(data) {
    if (data) {
    $('#goodslist-grid').datagrid('reload');
    $('#goodsInfo-window').window('close');
    } else {
    alert('保存失败!');
    }
    }, 'json');
    }
    /script>
    div style="width:100%; height:100%">
    table id="selectgoods-grid" class="easyui-datagrid" fit="true" toolbar="#tlb_selectgoods_search" pagination="true"
    rownumbers="true" fitColumns="true" idField="Identifier">
    thead>
    tr>
    th field="ck" checkbox="true">/th>
    th field="Identifier" hidden="true" width="0" editor="text">Id/th>
    th field="Goods_Name" width="100" editor="{type:'validatebox',options:{required:true}}">商品名称/th>
    th field="Chemistry" width="100" editor="{type:'validatebox',options:{required:true}}">化学指标/th>
    th field="Physical" width="100" editor="{type:'validatebox',options:{required:true}}">物理指标/th>
    th field="Partner_Name" width="50" editor="{type:'validatebox',options:{required:true}}">合作状态/th>
    /tr>
    /thead>
    /table>
    div id="tlb_selectgoods_search">
    商品名称:input name="keywords" id="selectgoods-keywords" class="easyui-searchbox" />a href="#" class="easyui-linkbutton" iconCls="icon-save" plain="true" onclick="javascript:saveSelectGoods()">保存/a>
    /div>
    /div>

    ASP.NET MVC的Controller代码如下:
    复制代码 代码如下:

    /// summary>
    /// 多选商品添加
    /// /summary>
    /// param name="supplier">供货商ID/param>
    /// returns>/returns>
    public ActionResult SelectGoods(string supplier)
    {
    ViewData["supplier"] = supplier;
    return View();
    }
    /// summary>
    /// 保存批量添加的产品信息
    /// /summary>
    /// param name="checks">选中的商品ID/param>
    /// param name="supplier">供货商名称/param>
    /// returns>/returns>
    public JsonResult SaveSelect(string checks, string supplier)
    {
    JsonResult result = new JsonResult();
    result.Data = false;
    try
    {
    if (String.IsNullOrEmpty(supplier))
    return result;
    SupplierGoods goods = new SupplierGoods();
    goods.Identifier = 0;
    //拼装xml
    String ids=Communion.StringHelper.BuildXmlID(checks);
    goods.Goods_ID = -1;//标示批量插入
    goods.Note = ids;
    goods.Month_Output = Convert.ToDouble(String.IsNullOrEmpty(this.ReadFromRequest("Month_Output")) ? "0" : this.ReadFromRequest("Month_Output"));
    goods.Supplier_ID = Convert.ToInt32(supplier);
    goods.Create_Date = DateTime.Now;
    goods.Customers = this.ReadFromRequest("Customers");
    goods.Equipment = this.ReadFromRequest("Equipment");
    goods.Detail_Params = this.ReadFromRequest("Detail_Params");
    goods.IsDefault = Convert.ToInt32(String.IsNullOrEmpty(this.ReadFromRequest("IsDefault")) ? "0" : this.ReadFromRequest("IsDefault"));
    Business business = new BusinessLogic();
    int id = business.SaveSupplierGoods>(goods);
    if (goods.Identifier == 0)
    {
    goods.Identifier = id;
    }
    result.Data = true;
    return result;
    }
    catch (Exception e)
    {
    return result;
    }
    }

    存储过程利用xml变量对传入的xml类型的ID集合进行批量添加保存到数据库中,存储过程代码如下:
    复制代码 代码如下:

    ALTER PROCEDURE [dbo].[View_SupplierGoodsCreate]
    @Identifier int,
    @Supplier_ID int,
    @Goods_ID int,
    @isDefault int,
    @Create_Date datetime,
    @Month_Output float(8),
    @Goods_Name nvarchar(400)=NULL,
    @Physical nvarchar(400)=NULL,
    @Chemistry nvarchar(400)=NULL,
    @Customers nvarchar(400)=NULL,
    @Equipment nvarchar(400)=NULL,
    @Note nvarchar(MAX)=NULL,
    @Detail_Params nvarchar(400)=NULL
    AS
    IF @Goods_ID=-1
    BEGIN
    --批量插入商品
    DECLARE @xml xml
    SET @xml=@Note
    INSERT INTO Supplier_Goods(Supplier_ID,Goods_ID,Create_Date,Month_Output,Customers,Equipment,Note,isdefault,Detail_Params)
    SELECT @Supplier_ID,identifier,@Create_Date,0,null,null,null,0,null
    FROM Base_Goods
    WHERE
    Identifier in (Select
    T.ID.value('.', 'int') As ID
    From
    @xml.nodes('/XML/ID') as T(ID)) and Identifier not in (select goods_id from Supplier_Goods where Supplier_ID=@Supplier_ID)
    SET @Identifier=@Goods_ID
    END
    您可能感兴趣的文章:
    • Easyui和zTree两种方式分别实现树形下拉框
    • jQuery使用EasyUi实现三级联动下拉框效果
    • Jquery Easyui自定义下拉框组件使用详解(21)
    • jQuery+easyui中的combobox实现下拉框特效
    • EasyUI实现下拉框多选功能
    上一篇:asp.net中各种类型的JSON格式化
    下一篇:iis中为每个应用程序池单独设置aspnet.config配置文件
  • 相关文章
  • 

    © 2016-2020 巨人网络通讯 版权所有

    《增值电信业务经营许可证》 苏ICP备15040257号-8

    ASP.NET MVC使用EasyUI的datagrid多选提交保存教程 ASP.NET,MVC,使用,EasyUI,的,