Exemple #1
0
        /// <summary>
        /// 批量删除数据
        /// </summary>
        private void OnDelete()
        {
            string itemsAppend = hV.Value.Trim();

            if (string.IsNullOrEmpty(itemsAppend))
            {
                WebHelper.MessageBox.Messager(this.Page, lbtnPostBack, "请至少勾选一行进行操作", "操作错误", "error");
                return;
            }

            if (bll == null)
            {
                bll = new BLL.Product();
            }
            string[]      itemsAppendArr = itemsAppend.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
            string        pIdAppend      = "";
            List <string> list           = new List <string>();

            foreach (string item in itemsAppendArr)
            {
                list.Add(item);
                pIdAppend += string.Format("'{0}',", item);
            }

            pIdAppend = pIdAppend.Trim(',');
            IList <ProductInfo> imagesList = bll.GetImagesListInProductIds(pIdAppend);

            UploadFilesHelper ufh      = new UploadFilesHelper();
            string            errorMsg = "";

            try
            {
                TransactionOptions options = new TransactionOptions();
                options.IsolationLevel = System.Transactions.IsolationLevel.ReadUncommitted;
                options.Timeout        = TimeSpan.FromSeconds(90);
                using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required, options))
                {
                    if (bll.DeleteBatch(list))
                    {
                        if (imagesList != null)
                        {
                            foreach (ProductInfo model in imagesList)
                            {
                                ufh.DeleteProductImage(model.ImagesUrl);

                                var sLImages = model.LImagesUrl.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                                foreach (string item in sLImages)
                                {
                                    ufh.DeleteProductImage(item);
                                }
                                var sMImages = model.MImagesUrl.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                                foreach (string item in sMImages)
                                {
                                    ufh.DeleteProductImage(item);
                                }
                                var sSImages = model.SImagesUrl.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                                foreach (string item in sSImages)
                                {
                                    ufh.DeleteProductImage(item);
                                }
                            }
                        }
                    }

                    //提交事务
                    scope.Complete();
                }
            }
            catch (Exception ex)
            {
                errorMsg = ex.Message;
            }

            if (!string.IsNullOrEmpty(errorMsg))
            {
                WebHelper.MessageBox.Messager(this.Page, lbtnPostBack, errorMsg, "系统异常提示");
                return;
            }

            WebHelper.MessageBox.MessagerShow(this.Page, lbtnPostBack, "操作成功");
            Bind();
        }