• 牛腩购物29:用户中心订单页面制作,com+事务的运用(Transactions/TransactionScope)


    用户中心订单页面的制作,显示订单,显示订单详细页,改变订单状态,com+事务的运用(Transactions/TransactionScope)

    image

    前台页面的  订单状态的修改

    <table width="100%" border="0" cellspacing="0" cellpadding="0">
                        <tr>
                            <td>       
                                <asp:CheckBoxList ID="chkState" runat="server" RepeatDirection="Horizontal">
                                    <asp:ListItem Value="0" Selected="True" Enabled="false">未作任何处理</asp:ListItem>
                                    <asp:ListItem Value="1">用户已经划出款</asp:ListItem>
                                    <asp:ListItem Value="2" Enabled="false">服务商已经收到款</asp:ListItem>
                                    <asp:ListItem Value="3" Enabled="false">服务商已经发货</asp:ListItem>
                                    <asp:ListItem Value="4">用户已经收到货</asp:ListItem>
                                </asp:CheckBoxList>                     
                                <asp:Button ID="UpdateState" runat="server" Text="修改订单状态" 
                                    OnClick="UpdateState_Click" />
                                
                            </td>
                        </tr>
                    </table>

    后台对应的代码

    /*********************************************************
     * 开发人员:Joey  QQ:1727050508   博客: http://1727050508.cnblogs.com
     * 创建时间:2012/4/19 11:54:17
     * 描述说明:showorder.aspx.cs  订单详情 
     * 
     * 更改历史:2012/4/20 10:16:17  增加一个 事务处理,用于当订单完成的时候,给用户增加积分
     * 
     * *******************************************************/
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Transactions;  //事务处理
    
    namespace Niunan.Shop.Web.user
    {
        public partial class showorder : System.Web.UI.Page
        {
            protected void Page_Load(object sender, EventArgs e)
            {
                //首次加载需要执行的
                if (!Page.IsPostBack)
                {
                    string id = Request.QueryString["id"];
                    int x;
                    if (int.TryParse(id, out x))
                    {
                        Model.Order order = new DAL.OrderDAO().GetModel(x);
                        if (order!=null)
                        {
                            repOrderdetails.DataSource = new DAL.OrderdetailsDAO().GetList("orderid=" + order.id);
                            repOrderdetails.DataBind();
    
                            litBH.Text = order.orderbh;
                            litrecname.Text = order.recname;
                            litPhone.Text = order.phone;
                            litAddress.Text = order.address;
                            litPostCode.Text = order.postcode;
                            litEmail.Text = order.email;
                            litSendtype.Text = order.sendmoney.ToString("c2");
                            litPayType.Text = order.paytype;
                            litCreateDate.Text = order.createdate.ToString(); ;
                            litShopPrice.Text = order.detailsmoney.ToString("c2");
                            litsendMoney.Text = order.sendmoney.ToString("c2");
                            litTotalPrice.Text = (order.detailsmoney + order.sendmoney).ToString("c2");
                            litRemark.Text = order.remark;
                            if (order.fp == 1)
                            {
                                litfp.Text = "<font color=red>需要</font>";
                            }
                            else
                                litfp.Text = "<font color=blue>不需要</font>";
    
                           
                            if (order.isdel==1)
                            {
                                litIsdel.Text = "(<span style='color:Red'>已经删除</span>)";
                                btnDelete.Enabled = false;
                            }
                            //0 未作任何处理  1用户已经划出款  2服务商已经收到款    3服务商已经发货  4用户已经收到货
                            ;
                            switch (order.state)
                            {
    
                                    //默认是等于0的,那么就应该把 0号位打勾,并且处于不可选,1号可选,但是由于我们是用户,
                                  所以2和3都是不能点的,4是最后才能选.修改按钮需要我们在判断的时候开启能否修改,建议以后写到另外一个表。
                                case 0:
                                    
                                    chkState.Items[1].Enabled = true;
                                    chkState.Items[4].Enabled = false;
                                    UpdateState.Enabled = true;
                                    break;
                                case 1://当为1的时候,4不能点,修改按钮不能选
                                    chkState.Items[1].Enabled = false;
                                    chkState.Items[1].Selected = true;
                                    chkState.Items[4].Enabled = false;
                                    UpdateState.Enabled = false;
                                    break;
                                case 2://当为2的时候,0到2都是选择上,并且不能点,4还是不能点
                                    for (int i = 0; i <= 2; i++)
                                    {
                                        chkState.Items[i].Enabled = false;
                                        chkState.Items[i].Selected = true;
                                    }
                                    chkState.Items[4].Enabled = false;
                                    UpdateState.Enabled = false;
                                    break;
                                case 3://当状态为3的时候,0到3都默认为选择上,不可点,4这个时候可以点了
                                     for (int i = 0; i <= 3; i++)
                                    {
                                        chkState.Items[i].Enabled = false;
                                        chkState.Items[i].Selected = true;
                                    }
                                    chkState.Items[4].Enabled = true;
                                    UpdateState.Enabled = true;
                                    break;
                                case 4://当状态为4的时候,全部都选择上了,全部都不能点
                                    for (int i = 0; i <= 4; i++)
                                    {
                                        chkState.Items[i].Enabled = false;
                                        chkState.Items[i].Selected = true;
                                    }
                                    UpdateState.Enabled = false;
                                    break;
                            }
                            
    
                            
                        }
                    }
                    else
                    {
                        Utility.Tool.alert("编号不能为空", this.Page);
                        Response.End();
                    }
                }
            }
    
            //修改订单状态
            protected void UpdateState_Click(object sender, EventArgs e)
            {
                 string id = Request.QueryString["id"];
                    int x;
                    if (int.TryParse(id, out x))
                    {
                        DAL.OrderDAO orderdao = new DAL.OrderDAO();
                        Model.Order od = orderdao.GetModel(x);
                        if (od!=null)
                        {
    
                            switch (od.state)
                            {
                                case 0:
                                    if (chkState.Items[1].Selected == true)
                                    {
                                        orderdao.UpdateState(od.id, 1);
                                        Utility.Tool.alert("状态更新成功",Request.Url.ToString(),this.Page);
                                    }
                                    else
                                    {
                                        Utility.Tool.alert("请勾选用户已经划出款", this.Page);
                                        return;
                                    }
                                        break;
                                case 3:
                                        if (chkState.Items[4].Selected == true)
                                        {
                                            //这里完成订单,给用户增加积分,我们用事务来处理
                                            using (TransactionScope scope=new TransactionScope())
                                            {
                                                try
                                                {
                                                    orderdao.UpdateState(od.id, 4);
                                                    //把订单中的商品金额,增加到用户的积分。
                                                    int jifen = Convert.ToInt16(od.detailsmoney);
                                                    new DAL.UserDAO().UpdateIntegral(User.Identity.Name, jifen);
                                                    Utility.Tool.alert("状态更新成功,积分 " + jifen + " 分已经发送", 
    Request.Url.ToString(), this.Page);
                                                    //处理完事务之后,记得提交,不然,他还是不执行的
                                                    scope.Complete();
                                                }
                                                catch (Exception re)
                                                {
    
                                                    Response.Write("事务错误,请联系管理员"+re.Message);
                                                    Response.End();
    
                                                }
                                                
                                            }
                                            
                                        }
                                        else
                                        {
                                            Utility.Tool.alert("请勾选用户已经收到货", this.Page);
                                            return;
                                        }
                                        break;
                                default:
                                    break;
                            }
                        }
    
                    }
            }
            //删除订单
            protected void btnDelete_Click(object sender, EventArgs e)
            {
                string id = Request.QueryString["id"];
                    int x;
                    if (int.TryParse(id, out x))
                    {
                        new DAL.OrderDAO().Delete(x);  //删除不是实际的删除,而是把isdel从默认的0 修改为1
                        Utility.Tool.alert("订单删除成功", Request.Url.ToString(), this.Page);
                    }
            }
    
            //获取商品的名称
            protected string GetProName(string proid)
            {
                string temp = "";
                Model.Product pt = new DAL.ProductDAO().GetModel(int.Parse(proid));
                if (pt!=null)
                {
                    temp = pt.proname;
                }
                
                return temp;
            }
        }
    }
  • 相关阅读:
    Matlab Tricks(二十九) —— 使用 deal 将多个输入赋值给多个输出
    释名 —— 名称的含义、来源
    Eclipse快捷键 今天又学会了几个不常用的 收藏了
    HDU 2527
    UVAlive 2326 Moving Tables(贪心 + 区间问题)
    STM32关于优先级设定的理解 NVIC_SetPriority()
    linux6.2安装mysql
    【PAT】1009. Product of Polynomials (25)
    Android的重力传感器(3轴加速度传感器)简单实例
    out/target/common/obj/PACKAGING/public_api.txt android.view.KeyEvent.KEYCODE_has changed value from
  • 原文地址:https://www.cnblogs.com/iceicebaby/p/2459452.html
Copyright © 2020-2023  润新知