触摸屏租赁
Touch screen rental
广告机租赁
Advertising rental
机器人租赁
Robot leasing
 当前位置:首页 > > C# 结合Coolite应用事务处理批量删除记录

C# 结合Coolite应用事务处理批量删除记录

一、批量删除记录(删除主表单据号及附表明细记录)
例:采购入库
前台:
<script type="text/javascript">
var DelCheck = function() {
            var row = Ext.getCmp("plist").getSelectionModel().getSelections();
            if (row.length == 0) {
                alertE("提示信息", "您没有选中任何行!");
            }
            else {
                var no2 = Ext.getCmp("plist").getSelectionModel().getSelections()[0].data['STAT'];
                if (no2 == 0 || no2 == null || no2 == 9) {

                    Ext.Msg.confirm("提示!", "您确定要删除单据号【" + row[0].data['code'] + "】吗?删除后不能恢复!",

function(btn) {
                        if (btn == "yes") {
                            var id = Ext.getCmp("plist").getSelectionModel().getSelections()[0].data['id'];
                            var code = Ext.getCmp("plist").getSelectionModel().getSelections()[0].data['code'];
                            Ext.net.DirectMethods.DeleteEvent(id, code);
                        }
                    });
                }
                else if (no2 == 7) {
                    alertE("提示信息", "该记录已经审核,不能删除该记录!");
                }
            }
        }
</script>
后台:
        /// <summary>
        /// 删除记录
        /// </summary>ss
        /// <param name="wno"></param>
        [DirectMethod]
        public void DeleteEvent(string id, string code)
        {
            try
            {
                string query = "";
                string number = "";
                if (code != "")
                {
                    query += "A.code='" + code + "' AND ";
                }
                if (query != "")
                    query = query.Remove(query.Length - 4, 4);
                DataTable dtINMX = dalINMX.GetList(query).Tables[0];
                for (int i = 0; i < dtINMX.Rows.Count; i++)//表二内循环(入库记录)
                {
                    number = dtINMX.Rows[i]["shulian"].ToString();//取附表入库明细数量
                    //获取与库存数据(与附表二huohao关联)
                    modelSTORE = dalSTORE.GetModel(dtINMX.Rows[i]["huohao"].ToString());
                    //库存数减少(减附表二数量)
                    modelSTORE.shulian = int.Parse(modelSTORE.shulian.ToString()) - int.Parse(number);
                    //更新库存表
                    dalSTORE.Update1(modelSTORE);
                    //删除附表二记录
                    dalINMX.Delete(int.Parse(dtINMX.Rows[i]["id"].ToString()));
                }
                //删除附表一记录
                dal.Delete(int.Parse(id));
                log.WriteLogParam("物品管理", "删除", "删除GOODSIN:" + id);
                this.plist.AddScript(" #{plist}.reload();");
            }
            catch (Exception ex)
            {
                //     throw ex;
                log.WriteLogParam("物品管理", "删除", "删除GOODSINMX:" + ex);
            }
        }

二、指量删除记录(删除主表记录及循环删除附表上传记录及相关附件)
例:知识库管理
前台:
        var DelCheck = function() {
            var row = Ext.getCmp("plist").getSelectionModel().getSelections();
            if (row.length == 0) {
                alertE("提示信息", "您没有选中任何行!");
            }
            else {
                var no2 = Ext.getCmp("plist").getSelectionModel().getSelections()[0].data['STAT'];
                if (no2 == 0 || no2 == null || no2 == 9) {

                    Ext.Msg.confirm("提示!", "您确定要删除【" + row[0].data['title'] + "】吗?删除后不能恢复!", function

(btn) {
                        if (btn == "yes") {
                            var id = Ext.getCmp("plist").getSelectionModel().getSelections()[0].data['id'];
                            var code = Ext.getCmp("plist").getSelectionModel().getSelections()[0].data['code'];
                            Ext.net.DirectMethods.DeleteEvent(id, code);
                        }
                    });
                }
                else if (no2 == 7) {
                    alertE("提示信息", "该记录已经审核,不能删除该记录!");
                }
            }
        }
后台:
        /// <summary>
        /// 删除记录
        /// </summary>
        /// <param name="id"></param>
        [DirectMethod]
        public void DeleteEvent(string id, string code)
        {
            try
            {
                string query = "";
                if (code != "")
                {
                    query += "GGBH='" + code + "' AND ";
                }
                if (query != "")
                    query = query.Remove(query.Length - 4, 4);
                DataTable dtfj = dalfj.GetList(query).Tables[0];
                for (int i = 0; i < dtfj.Rows.Count; i++)//(循环删除附表上传记录及相关附件)
                {
                    try
                    {
                        //以下删除附表附件文件
                        modelfj = dalfj.GetModel(dtfj.Rows[i]["IDSTR"].ToString());
                        string path = modelfj.FJFILEIMAGE;
                        string filename = Server.MapPath("~" + path);  //取得相对路径
                        System.IO.FileInfo file = new System.IO.FileInfo(filename);
                        if (file.Exists)
                        {                           
                            file.Delete();
                        }
                        else
                        {
                            //该文件不存在 怎么提示你自己写。
                            ScriptManager1.AddScript("alertE('提示','文件不存在!');");
                        }
                        //以上删除附表附件文件
                        //以下删除附表记录
                        dalfj.Delete(dtfj.Rows[i]["IDSTR"].ToString());
                        //以上删除附表记录
                        log.WriteLogParam("知识库文件管理", "删除", "删除KNOWINFO:" + dtfj.Rows[i]["IDSTR"].ToString());
                        this.plist.AddScript(" #{plist}.reload();");
                    }
                    catch (Exception ex)
                    {
                        throw ex;
                    }
                }

                //删除主表一记录
                dal.Delete(int.Parse(id));
                log.WriteLogParam("知识库管理", "删除", "删除KNOWINFO:" + id);
                this.plist.AddScript(" #{plist}.reload();");
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }


工作室地址:重庆石桥铺电脑城B座 | 微信:z35544216 | 网址:www.35544216.com