Esempio n. 1
0
        protected void btnSub_Click(object sender, EventArgs e)
        {
            if (txtProNo.Text.Trim() == "")
            {
                base.ClientScript.RegisterStartupScript(base.GetType(), null, "<script>alert('请填写 销售退货单号!');</script>");
                return;
            }
            else
            {
                if (CheckProNo(txtProNo.Text) == false)
                {
                    return;
                }
            }
            //查询项目信息是否存在
            string sql = string.Format("select Id,PoNo from Sell_OrderInHouse where ProNo='{0}' and status='通过'", txtProNo.Text.Trim());
            var    obj = DBHelp.getDataTable(sql);

            if (obj.Rows.Count != 1)
            {
                base.ClientScript.RegisterStartupScript(base.GetType(), null, "<script>alert('销售退货信息不存在!');</script>");
                return;
            }
            Sell_OrderInHousesService ordersSer     = new Sell_OrderInHousesService();
            TB_HouseGoodsService      houseGoodsSer = new TB_HouseGoodsService();

            //查询销售退货信息
            List <Sell_OrderInHouses> orders = ordersSer.GetListArray(" 1=1 and Sell_OrderInHouses.id=" + obj.Rows[0]["Id"]);

            sql = string.Format(@"--销售退货还原--25	销售退货
delete from tb_EForm where e_No='{0}' and proId=25;
delete from tb_EForms where e_Id in (select id from tb_EForm where e_No='{0}' and proId=25);
delete from Sell_OrderInHouses where id = (select ID from Sell_OrderInHouse where ProNo='{0}');
delete from Sell_OrderInHouse where ProNo='{0}';", txtProNo.Text.Trim());

            using (SqlConnection conn = DBHelp.getConn())
            {
                conn.Open();
                SqlTransaction tan        = conn.BeginTransaction();
                SqlCommand     objCommand = conn.CreateCommand();
                objCommand.Transaction = tan;
                try
                {
                    for (int i = 0; i < orders.Count; i++)
                    {
                        if (orders[i].GoodPriceSecond != 0)
                        {
                            houseGoodsSer.OutHouse(orders[i].HouseID, orders[i].GooId, orders[i].GoodNum, orders[i].GoodPriceSecond, objCommand);
                        }
                        else
                        {
                            houseGoodsSer.OutHouse(orders[i].HouseID, orders[i].GooId, orders[i].GoodNum, orders[i].GoodPrice, objCommand);
                        }
                    }
                    objCommand.CommandText = sql;
                    objCommand.ExecuteNonQuery();
                    tan.Commit();
                }
                catch (Exception)
                {
                    tan.Rollback();
                    conn.Close();
                    base.ClientScript.RegisterStartupScript(base.GetType(), null, "<script>alert('删除失败!');</script>");
                    return;
                }
                conn.Close();
                string PONO = obj.Rows[0]["PoNo"].ToString();
                Sell_OrderOutHouseService SellOutSer = new Sell_OrderOutHouseService();
                SellOutSer.SellOrderUpdatePoStatus2(PONO);
                new CG_POOrdersService().GetListArrayToFpsAndUpdatePoStatue(PONO, "通过");
                new CG_POOrderService().GetOrder_ToInvoiceAndUpdatePoStatus(PONO);
                base.ClientScript.RegisterStartupScript(base.GetType(), null, "<script>alert('删除成功!');</script>");
            }
        }