⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 goodsadd.aspx.cs

📁 c#三层架构项目开发的全过程
💻 CS
字号:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BLL;
using Model;
using System.Data;
namespace 金利来分销管理系统.Goods
{
    public partial class GoodsAdd : System.Web.UI.Page
    {
        DataTable dt;
       #region 添加商品,BLL层构造函数
       BLL.Goods.ProductAddBll ProductAddShow;
       BLL.Goods.BrandAddBll BrandAddShow;
       BLL.Employee.EmployeeBll employeebllshow;
       
       List<Model.Goods.ProductTypeModel> li = new List<Model.Goods.ProductTypeModel>();
       public GoodsAdd()
       {
           ProductAddShow = new BLL.Goods.ProductAddBll();
           BrandAddShow = new BLL.Goods.BrandAddBll();
           employeebllshow = new BLL.Employee.EmployeeBll();

       }
       #endregion

       protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                //用户权限
                if (Session["employee_id"] == null)
                {
                    Response.Write("<script>alert('请您登陆系统');location.href='../Enter.aspx'</script>");
                }
                else 
                {
                    if (employeebllshow.UserRole(Session["role_id"].ToString(), "14") == true)
                    {
                        //自动获取商品编号(按照时间)
                        this.lalid.Text = "SP" + DateTime.Now.ToString("yyyyMMddhhmmssfff");
                        //通过绑定商品品牌名称来添加商品
                        List<Model.Goods.BrandAdd> brand = BrandAddShow.SelectbrandByName();
                        foreach (var item in brand)
                        {
                            ddlbrandname.Items.Add(item.brand_Name);
                        }
                        //通过绑定商品编号来查看商品信息
                        //List<Model.Goods.ProductModel> productid = 
                    }
                    else
                    {
                        Response.Write("<script>alert('你无权查看此功能,请与管理员联系');location.href='../Aboutus.aspx'</script>");
                    }
                }  
           }
           
        }
    
       #region 把商品详细添加到显示区
       private void createDT()
       {
           dt = new DataTable();
           dt.Columns.Add("商品ID");
           dt.Columns.Add("商品明细名称");
           dt.Columns.Add("商品品牌名称");
           dt.Columns.Add("商品尺码1");
           dt.Columns.Add("商品尺码2");
           dt.Columns.Add("商品尺码3");
           dt.Columns.Add("商品尺码4");
           dt.Columns.Add("商品尺码5");
           dt.Columns.Add("商品尺码6");
           dt.Columns.Add("商品尺码7");
           dt.Columns.Add("商品颜色");
       }
       #endregion

       #region 显示添加商品按钮
       protected void btn_Click(object sender, EventArgs e)
        {
     
           //如果虚拟表面为空,则继续添加,反之赋值给表
            if (ViewState["dt"] == null)
            {
                createDT();
            }
            else
            {
                //创建虚拟表
                dt = (DataTable)ViewState["dt"];
            }
            //将值赋给虚拟表的制定列
            DataRow dr = dt.NewRow();
            dr[0] = this.lalid.Text;
            dr[1] = this.txtna.Text.Trim();
            dr[2] = this.ddlbrandname.Text;
            dr[3] = this.txts1.Text;
            dr[4] = this.txts2.Text;
            dr[5] = this.txts3.Text;
            dr[6] = this.txts4.Text;
            dr[7] = this.txts5.Text;
            dr[8] = this.txts6.Text;
            dr[9] = this.txts7.Text;
            dr[10] = this.ddlco.Text;

            dt.Rows.Add(dr);  //添加表里面的每一行数据,再传到虚拟表里面
            ViewState["dt"] = dt;
            gvgood.DataSource = dt;
            gvgood.DataBind();
          
       }
       #endregion

       #region 添加进数据库按钮
       protected void Button1_Click(object sender, EventArgs e)
       {
           dt = (DataTable)ViewState["dt"];  //接收表中的数据
           Model.Goods.ProductTypeModel mo;
           foreach (DataRow item in dt.Rows)
           {
               mo = new Model.Goods.ProductTypeModel();
               mo.Product_id = item[0].ToString();
               mo.producttype_name = item[1].ToString();
               mo.producttype_brand = item[2].ToString();
               mo.producttype_s1 = Convert.ToInt32(item[3]);
               mo.producttype_s2 = Convert.ToInt32(item[4]);
               mo.producttype_s3 = Convert.ToInt32(item[5]);
               mo.producttype_s4 = Convert.ToInt32(item[6]);
               mo.producttype_s5 = Convert.ToInt32(item[7]);
               mo.producttype_s6 = Convert.ToInt32(item[8]);
               mo.producttype_s7 = Convert.ToInt32(item[9]);
               mo.producttype_color = item[10].ToString();
               li.Add(mo);   //将Model中的数据添加到List泛型集合

           }

           //先添加商品表,再添加商品明细表
           ProductAddShow.Addproduct(this.lalid.Text, BrandAddShow.BrandById(this.ddlbrandname.Text), decimal.Parse(this.txtsaleprice.Text), decimal.Parse(this.txtcostprice.Text), decimal.Parse(this.txttradeprice.Text), this.txtname.Text);
           Response.Write("<script>alert('添加商品 【" + this.txtname.Text + "】 成功!')</script>");
           foreach (Model.Goods.ProductTypeModel item in li)
           {
               //添加商品明细
               ProductAddShow.AddProductType(item.Product_id,item.producttype_name, item.producttype_brand, item.producttype_s1, item.producttype_s2, item.producttype_s3, item.producttype_s4, item.producttype_s5, item.producttype_s6, item.producttype_s7, item.producttype_color);
           }
           this.lalid.Text = "SP" + DateTime.Now.ToString("yyyyMMddhhmmssfff");
       }
        #endregion
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -