批量删除操作

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

开发工具与关键技术:Adobe JavaScript

作者:陈钰桃

撰写时间:2021428

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

成果图

 

  1. 写出按钮     

    2.复选框进行多条选择

   3.页面传参

 function doDeleteMore() {

    var checkStatus = layuiTable.checkStatus('tabCommodity'); //tabCommodity 即为基础参数 id 对应值

if (checkStatus.data.length > 0) { //获取选中行数量

  var strIds = '';

    //循环获取选中的ID

    for (var i = 0; i < checkStatus.data.length; i++) {

                    //"1;3;5;7;"

          strIds += checkStatus.data[i].commodityID + ';';

   }

 strIds = strIds.substring(0, strIds.length - 1);//去除最后的 ; 号

 layer.confirm('您确定要删除选中的' + checkStatus.data.length + '条商品信息?', { icon: 3, title: "提示" }, function (index) {

        $.post("@Url.Content("~/SystemBase/Product/DeleteCommoditys")",

        { strCommodityIDs: strIds }, function (returnJson) {

            if (returnJson.State == true) {

                     layer.close(index);

                     //刷新table

                     tabCommoditySearch();

              }

           layer.alert(returnJson.Text, { icon: 6 });

        });

  });

 } else {

       layer.alert("请选择要删除的数据", { icon: 0 });

 }

}

   4.控制器接收参数并进行删除操作返回到页面

 public ActionResult DeleteCommoditys(string strCommodityIDs)

{

     ReturnJsonVo msg = new ReturnJsonVo();

    //声明变量

     int intSuceessCount = 0;//记录成功数

     int intFailCount = 0; //记录失败数

  if (!String.IsNullOrEmpty(strCommodityIDs))

     {

       //(1)字符串分割

       string[] ptudentIDs = strCommodityIDs.Split(';');

 foreach(string strId in ptudentIDs)

        {

           try

             {

               //(2)获取商品ID

               int intCommodityID = Convert.ToInt32(strId);

              //(3)查询库存表中是否有数据

       int intCount = myModels.R_Repertory.Count(o => o.commodityID == intCommodityID);

 if (intCount == 0)

         {

            //(4)查询要删除的数据

         S_Commodity delCommodity = myModels.S_Commodity.Single(o => o.commodityID == intCommodityID);

          //判断是否有图片

if (!string.IsNullOrEmpty(delCommodity.commodityPictureName))

 {

      //获取路径

string filePath = Server.MapPath("~/Document/commodityPicture/") + delCommodity.commodityPictureName;

     //判断文件是否存在

     if (System.IO.File.Exists(filePath))

       {

         //3、删除图片文件

         System.IO.File.Delete(filePath);   }   }

         //删除

         myModels.S_Commodity.Remove(delCommodity);

         myModels.SaveChanges();

         intSuceessCount++;

       }

       else

        {

           msg.Text = "已发生业务的商品不能删除";

        }   }

 catch (Exception e)

   {

      intFailCount++;

      Debug.WriteLine(e);

      msg.Text = "删除异常"; } }

      msg.State = true;

      msg.Text = "总共删除" + ptudentIDs.Length + "条商品信息";

if (intSuceessCount > 0)

  {

     msg.Text += ",成功" + intSuceessCount + "条";

}

if (intFailCount > 0)

  {

     msg.Text += ",失败" + intFailCount + "条";

 } }

   else

   {

      msg.Text = "请选择要删除的数据";}

return Json(msg, JsonRequestBehavior.AllowGet);

}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值