Пример #1
0
 protected void lBtnDeleteAll_Click(object sender, EventArgs e)
 {
     //删除全部数据
     using (var da = new t_wip_delivery_remarkTableAdapter())
     {
         //执行删除
         da.DeleteAllData();
     }
     //重新绑定数据源
     lvWipDeliveryRemark.DataBind();
 }
Пример #2
0
        /// <summary>
        /// 修改排单信息数据
        /// </summary>
        /// <param name="context">封装的http信息对象</param>
        /// <returns></returns>
        private ydJsonResult<string> SaveDeliveryRemark(HttpContext context)
        {
            //检测参数
            var parameters = context.Request.Params;
            if (string.IsNullOrWhiteSpace(parameters[string.Format("{0}[{1}][{2}]", "updated", 0, "order_id")]))
            {
                return new ydJsonResult<string>
                {
                    IsSuccess = false,
                    Data = "提供的参数不正确!"
                };
            }
            try
            {
                //数据库连接
                using (var da = new t_wip_delivery_remarkTableAdapter())
                using (var conn = da.Connection)
                {
                    //打开数据库连接
                    conn.Open();
                    //开启事务
                    using (var tran = conn.BeginTransaction(System.Data.IsolationLevel.RepeatableRead))
                    {
                        try
                        {
                            //设置事务
                            da.Transaction = tran;
                            da.Adapter.InsertCommand.Transaction = tran;
                            da.Adapter.DeleteCommand.Transaction = tran;
                            da.Adapter.UpdateCommand.Transaction = tran;

                            //更新多行需要试用事务
                            da.Adapter.AcceptChangesDuringUpdate = false;

                            for (int i = 0; i < parameters.Count; i++)
                            {
                                //更新参数订单序号
                                var orderId = parameters[string.Format("{0}[{1}][{2}]", "updated", i, "order_id")];
                                //检测值
                                if (string.IsNullOrWhiteSpace(orderId))
                                {
                                    break;
                                }
                                //更新参数交货备注与级别
                                var deliveryRemark = parameters[string.Format("{0}[{1}][{2}]", "updated", i, "delivery_remark")];
                                var hurriedLevel = parameters[string.Format("{0}[{1}][{2}]", "updated", i, "hurried_level")];
                                //执行删除本张单之前的备注
                                da.Delete(orderId);
                                //检测是否提供了交货备注和级别
                                if (string.IsNullOrWhiteSpace(deliveryRemark) || string.IsNullOrWhiteSpace(hurriedLevel))
                                {
                                    //完成本次循环
                                    continue;
                                }
                                //插入新的备注和级别
                                if (da.Insert(
                                    orderId,
                                    deliveryRemark,
                                     Convert.ToByte(hurriedLevel),
                                     context.Session["user_name"].ToString(),
                                     DateTime.Now,
                                     DateTime.Now
                                ) <= 0)
                                {
                                    //返回成功
                                    return new ydJsonResult<string>
                                    {
                                        IsSuccess = false,
                                        Data = "插入保存送货备注数据发生错误!<br />" + orderId
                                    };
                                }
                            }
                            //提交事务
                            tran.Commit();
                            //返回成功
                            return new ydJsonResult<string>
                            {
                                IsSuccess = true,
                                Data = null
                            };
                        }
                        catch (Exception exx)
                        {
                            //回滚事务
                            tran.Rollback();
                            //返回错误
                            return new ydJsonResult<string>
                            {
                                IsSuccess = false,
                                Data = string.Format("保存发生错误!<br />{0}", exx.Message)
                            };
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                //返回错误
                return new ydJsonResult<string>
                {
                    IsSuccess = false,
                    Data = string.Format("数据库连接发生错误!<br />{0}", ex.Message)
                };
            }
        }