当前位置:编程学习 > asp >>

求讲解ASP。NET代码

各位高手帮忙解释下每行代码的意思。感谢!!!!(大体思路也可以)

Shipping.aspx:

public partial class Manger_Shipping : System.Web.UI.Page
{
    MangerClass mcObj = new MangerClass();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Convert.ToString(Session["AID"]) == "")
        {
            Response.Redirect("Fail.aspx");
        }
        if (!IsPostBack)
        {
            if (this.Request.QueryString["Action"] == "Manage")
            {
                lblAction.Text = "配送方式管理";
                gvShipBind();
            }
            else if(this.Request.QueryString["Action"]=="Add" )
            {
               lblAction.Text="添加配送方式信息";
            }
            else if (this.Request.QueryString["Action"] == "Modify")
            {
                lblAction.Text = "修改配送方式信息";
                GetShipInfo();
            }

          
        }
    }
    public string GetVarStr(string P_Str_ShipFee)
    {
        return mcObj.VarStr(P_Str_ShipFee, 2);
   
    }
    public string GetClass(int P_Int_ClassID)
    {
        string P_Str_ClassName = mcObj.GetClass(P_Int_ClassID);
        return P_Str_ClassName;
    }
    public void gvShipBind()
    {
        DataSet ds = mcObj.ReturnShipDs("ShipInfo");
        gvShip.DataSource = ds.Tables["ShipInfo"].DefaultView;
        gvShip.DataBind();
   
    }
    protected void gvShip_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        gvShip.PageIndex = e.NewPageIndex;
        gvShipBind();
    }
    protected void gvShip_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        int P_Int_ShipID = Convert.ToInt32(gvShip.DataKeys[e.RowIndex].Value.ToString());
        mcObj.DeleteShipInfo(P_Int_ShipID);
        gvShipBind();
    }
    public void GetShipInfo()
    {
        DataSet ds = mcObj.ReturnShipDsByID(Convert.ToInt32(this.Request["ShipID"].ToString()), "ShipInfo");
        txtName.Text=ds.Tables["ShipInfo"].Rows[0][1].ToString();
        txtPrice.Text =mcObj.VarStr(ds.Tables["ShipInfo"].Rows[0][2].ToString(),2);
    }
    protected void btnSave_Click(object sender, EventArgs e)
    {

        if (this.Request.QueryString["Action"] == "Add")
        {
            if (txtName.Text == "" || txtPrice.Text == "")
            {
                Response.Write("<script>alert('请输入完整信息')</script>");
                return;
            }
            else
            {
                if (IsValidInt(txtPrice.Text.Trim()) == false)
                {
                    Response.Write("<script>alert('请正确输入(格式:1.00)!')</script>");
                    return;

                }
                else
                {
                    mcObj.InsertShip(txtName.Text.Trim(), float.Parse(txtPrice.Text.Trim()));
                  Response.Write("<script>alert('插入成功!')</script>");
                  return;
                }
           
            }

        }
        else if (this.Request.QueryString["Action"] == "Modify")
        {
        
            if (txtName.Text == "" || txtPrice.Text == "")
            {
                Response.Write("<script>alert('请输入完整信息')</script>");
                return;
            }
            else
            {
                if (IsValidInt(txtPrice.Text.Trim()) == false)
                {
                    Response.Write("<script>alert('请正确输入(格式:1.00)!')</script>");
                    return;

                }
                else
                {
                  mcObj.UpdateShip(Convert.ToInt32(this.Request["ShipID"].ToString()),txtName.Text.Trim(),float.Parse (txtPrice.Text.Trim()));
                  Response.Write("<script>alert('修改成功!')</script>");
                  return;
                }
           
            }
       
       
        }
    }
    public bool IsValidInt(string num)
    {
        return Regex.IsMatch(num, @"^[0-9]+(.[0-9]{2})?$");
   
    }
}

答案:public partial class Manger_Shipping : System.Web.UI.Page
        {
            MangerClass mcObj = new MangerClass();//调用自定义的类
            protected void Page_Load(object sender, EventArgs e)//每次加载页面执行
            {
                if (Convert.ToString(Session["AID"]) == "")//判断Session["AID"]是否为空
                {
                    Response.Redirect("Fail.aspx");//页面地址转向
                }
                if (!IsPostBack)//判断是否首次加载【首次加载才执行】
                {
                    if (this.Request.QueryString["Action"] == "Manage")//获取get方式传到该页面的值【如果get方式的值 == "Manage"】
                    {
                        lblAction.Text = "配送方式管理";//给控件赋值
                        gvShipBind();//绑定方法 绑定GridView的数据
                    }
                    else if (this.Request.QueryString["Action"] == "Add")//获取get方式传到该页面的值【如果get方式的值 == "Add"】
                    {
                        lblAction.Text = "添加配送方式信息";//给控件赋值
                    }
                    else if (this.Request.QueryString["Action"] == "Modify")//获取get方式传到该页面的值【如果get方式的值 == "Modify"】
                    {
                        lblAction.Text = "修改配送方式信息";//给控件赋值
                        GetShipInfo();//绑定方法 绑定GridView的数据
                    }


                }
            }
            public string GetVarStr(string P_Str_ShipFee)//调用自定义的类里的某个方法
            {
                return mcObj.VarStr(P_Str_ShipFee, 2);

            }
            public string GetClass(int P_Int_ClassID)//调用自定义的类里的某个方法 实例化一个对象 返回P_Str_ClassName 的值
            {
                string P_Str_ClassName = mcObj.GetClass(P_Int_ClassID);
                return P_Str_ClassName;
            }
            public void gvShipBind()//绑定GridView的数据
            {
                DataSet ds = mcObj.ReturnShipDs("ShipInfo");//调用自定义的类里的某个方法//设置容器的内容
                gvShip.DataSource = ds.Tables["ShipInfo"].DefaultView;//设置给GridView的数据源
                gvShip.DataBind();//绑定GridView的数据

            }
            protected void gvShip_PageIndexChanging(object sender, GridViewPageEventArgs e)//GridView的分页事件
            {
                gvShip.PageIndex = e.NewPageIndex;//GridView的当前显示页
                gvShipBind();//绑定GridView的数据
            }
            protected void gvShip_RowDeleting(object sender, GridViewDeleteEventArgs e)//GridView的删除事件
            {
                int P_Int_ShipID = Convert.ToInt32(gvShip.DataKeys[e.RowIndex].Value.ToString());//gvShip.DataKeys[e.RowIndex].Value.ToString() 当前行 获取主键ID
                mcObj.DeleteShipInfo(P_Int_ShipID);//调用自定义的类里的删除
                gvShipBind();//绑定GridView的数据
            }
            public void GetShipInfo()
            {
                DataSet ds = mcObj.ReturnShipDsByID(Convert.ToInt32(this.Request["ShipID"].ToString()), "ShipInfo");//调用自定义的类里的某个方法//设置容器的内容
                txtName.Text = ds.Tables["ShipInfo"].Rows[0][1].ToString();//DataSet的表的集合,1行2列
                txtPrice.Text = mcObj.VarStr(ds.Tables["ShipInfo"].Rows[0][2].ToString(), 2);//DataSet的表的集合,1行3列
            }
            protected void btnSave_Click(object sender, EventArgs e)//按钮事件
            {

&n

上一个:用C#编写asp网站的一个小问题
下一个:asp.net中的一点小问题

CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,