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

📄 addloss.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 System.Data;
using Model;
using BLL;

namespace 金利来分销管理系统.Loss
{
    public partial class AddLoss : System.Web.UI.Page
    {
        DataTable dt;
        //实例化的BLL层
        BLL.Loss.lossBll lossbllshow;
        BLL.Goods.ProductBll productbllshow;
        BLL.Loss.loss_listBll loss_listbllshow;
        BLL.Goods.ProductTypeBll producttypebllshow;
        BLL.Store.StoreBll storebllshow;
        BLL.Employee.EmployeeBll employeebllshow;

        List<Model.Loss.loss_listModel> show = new List<Model.Loss.loss_listModel>();
        public AddLoss()
        {
            lossbllshow = new BLL.Loss.lossBll();
            loss_listbllshow = new BLL.Loss.loss_listBll();

            productbllshow = new BLL.Goods.ProductBll();
            producttypebllshow = new BLL.Goods.ProductTypeBll();
            storebllshow = new BLL.Store.StoreBll();
            employeebllshow = new BLL.Employee.EmployeeBll();

        }

        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(), "25") == true)
                    {
                        //将商品表中所有商品编号添加到DropDownList里
                        List<Model.Goods.ProductModel> productid = productbllshow.SelectProductID();
                        foreach (var item in productid)
                        {
                            ddlProductID.Items.Add(item.product_id);
                        }
                        //获取当天时间
                       lblStockID.Text = "SY" + DateTime.Now.ToString("yyyyMMddhhmmssfff");
                    }
                    else
                    {
                        Response.Write("<script>alert('你无权查看此功能,请与管理员联系');location.href='../Aboutus.aspx'</script>");
                    }
                }
            }
        }
        //通过商品编号查询商品信息
        protected void ddlProductID_SelectedIndexChanged(object sender, EventArgs e)
        {
            //清空数据
            this.lblShowPID.Visible = false ;

            this.txtProductName.Text = "";
            this.txtBrand.Text = "";
            this.txtSize1.Text = "";
            this.txtSize2.Text = "";
            this.txtSize3.Text = "";
            this.txtSize4.Text = "";
            this.txtSize5.Text = "";
            this.txtSize6.Text = "";
            this.txtSize7.Text = "";
            ddlColor.Items.Clear();
            this.gvShow.DataSource = null;
            this.gvShow.DataBind();

            //获取商品信息(商品名称,单价,品牌)
            List<Model.Goods.ProductModel> p = productbllshow.SelectProductByID(this.ddlProductID.Text);
            foreach (Model.Goods.ProductModel item in p)
            {
                ddlColor.Items.Add(item.producttype_color);
                this.txtProductName.Text = item.product_name;
                this.txtBrand.Text = item.brand_name;
                this.lblsize1.Text = item.producttype_s1.ToString();
                this.lblsize2.Text = item.producttype_s2.ToString();
                this.lblsize3.Text = item.producttype_s3.ToString();
                this.lblsize4.Text = item.producttype_s4.ToString();
                this.lblsize5.Text = item.producttype_s5.ToString();
                this.lblsize6.Text = item.producttype_s6.ToString();
                this.lblsize7.Text = item.producttype_s7.ToString();
                //默认每个尺码的数量为“0”
                this.txtSize1.Text = "0";
                this.txtSize2.Text = "0";
                this.txtSize3.Text = "0";
                this.txtSize4.Text = "0";
                this.txtSize5.Text = "0";
                this.txtSize6.Text = "0";
                this.txtSize7.Text = "0";
            }
        }
        private void createDT()
        {
            dt = new DataTable();
            dt.Columns.Add("商品ID");
            dt.Columns.Add("31");
            dt.Columns.Add("32");
            dt.Columns.Add("33");
            dt.Columns.Add("34");
            dt.Columns.Add("35");
            dt.Columns.Add("36");
            dt.Columns.Add("37");
            dt.Columns.Add("损益商品颜色");
            dt.Columns.Add("数量");
        }
        //提交损益单据
        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            if (this.ddlProductID.SelectedValue == "请选择商品编号")
            {
                this.lblShowPID.Visible = true;
            }
            else
            {
                //通过商品在库存中的编号,颜色以及库存编号查找尺码是否大于所填写的数据
                Model.Store.StoreModel storemodel = storebllshow.SelectStoreByProduct(int.Parse (this.lblBranch.Text),this.ddlProductID.Text,this.ddlColor.Text);
                if (storemodel.store_size1 < int.Parse(this.txtSize1.Text) || storemodel.store_size2 < int.Parse(this.txtSize2.Text) || storemodel.store_size3 < int.Parse(this.txtSize3.Text) || storemodel.store_size4 < int.Parse(this.txtSize4.Text) || storemodel.store_size5 < int.Parse(this.txtSize5.Text) || storemodel.store_size6 < int.Parse(this.txtSize6.Text) || storemodel.store_size7 < int.Parse(this.txtSize7.Text))
                {
                    this.lblShow.Text = "请检查库存数量";
                }
                else
                {
                    this.lblShow.Text = "";
                    if (ViewState["dt"] == null)
                    {
                        createDT();
                    }
                    else
                    {
                        dt = (DataTable)ViewState["dt"];
                    }
                    DataRow dr = dt.NewRow();
                    dr[0] = this.ddlProductID.Text.Trim();
                    dr[1] = this.txtSize1.Text;
                    dr[2] = this.txtSize2.Text;
                    dr[3] = this.txtSize3.Text;
                    dr[4] = this.txtSize4.Text;
                    dr[5] = this.txtSize5.Text;
                    dr[6] = this.txtSize6.Text;
                    dr[7] = this.txtSize7.Text;
                    dr[8] = this.ddlColor.Text;
                    dr[9] = (Convert.ToInt32(this.txtSize1.Text) + Convert.ToInt32(this.txtSize2.Text) + Convert.ToInt32(this.txtSize3.Text) + Convert.ToInt32(this.txtSize4.Text) + Convert.ToInt32(this.txtSize5.Text) + Convert.ToInt32(this.txtSize6.Text) + Convert.ToInt32(this.txtSize7.Text)).ToString();
                    if (int.Parse(dr[9].ToString()) == 0)
                    {
                        this.lblSum.Visible = true;
                    }
                    else
                    {
                        this.lblSum.Visible = false;
                        this.btnLoss.Visible = true;
                        dt.Rows.Add(dr);
                        ViewState["dt"] = dt;
                        gvShow.DataSource = dt;
                        gvShow.DataBind();
                    }
                }
            }
        }
        //生成单据
        protected void btnLoss_Click(object sender, EventArgs e)
        {
            dt = (DataTable)ViewState["dt"];
            Model.Loss.loss_listModel mo;
            foreach (DataRow item in dt.Rows)
            {
                mo = new Model.Loss.loss_listModel();
                mo.loss_list_product_id = item[0].ToString();
                mo.loss_list_size1 = Convert.ToInt32(item[1]);
                mo.loss_list_size2 = Convert.ToInt32(item[2]);
                mo.loss_list_size3 = Convert.ToInt32(item[3]);
                mo.loss_list_size4 = Convert.ToInt32(item[4]);
                mo.loss_list_size5 = Convert.ToInt32(item[5]);
                mo.loss_list_size6 = Convert.ToInt32(item[6]);
                mo.loss_list_size7 = Convert.ToInt32(item[7]);
                mo.loss_list_color = item[8].ToString();
                mo.loss_list_sum = Convert.ToInt32(item[9]);
                show.Add(mo);
            }

            //添加损益单据
            lossbllshow.AddLoss(this.lblStockID.Text, this.lblName.Text, DateTime.Now, int.Parse (this.lblBranch.Text), this.tbAsk.Text, "未通过");
            foreach (Model.Loss.loss_listModel item in show)
            {
                //添加损益明细
                loss_listbllshow.AddLoss_List(this.lblStockID.Text, item.loss_list_product_id, item.loss_list_color, item.loss_list_size1, item.loss_list_size2, item.loss_list_size3, item.loss_list_size4, item.loss_list_size5, item.loss_list_size6, item.loss_list_size7, item.loss_list_sum);
            }
           
            Response.Write("<script>alert('损益申请已提交')</script>");
            this.ddlProductID.Text = "请选择商品编号";
            //获取当天时间
            lblStockID.Text = "SY" + DateTime.Now.ToString("yyyyMMddhhmmssfff");
            this.btnLoss.Visible = false;
            this.txtProductName.Text = "";
            this.txtBrand.Text = "";
            this.txtSize1.Text = "";
            this.txtSize2.Text = "";
            this.txtSize3.Text = "";
            this.txtSize4.Text = "";
            this.txtSize5.Text = "";
            this.txtSize6.Text = "";
            this.txtSize7.Text = "";
            this.lblsize1.Text = "32";
            this.lblsize2.Text = "33";
            this.lblsize3.Text = "34";
            this.lblsize4.Text = "35";
            this.lblsize5.Text = "36";
            this.lblsize6.Text = "37";
            this.lblsize7.Text = "38";
            ddlColor.Items.Clear();
            ViewState["dt"] = null;
            this.gvShow.DataSource = null;
            this.gvShow.DataBind();
        }
        //删除当前行数据
        protected void lbtnCancel_Click(object sender, EventArgs e)
        {
            dt = (DataTable)ViewState["dt"];
            DataRow x = dt.Rows[this.dt.Rows.Count - 1];
            dt.Rows.Remove(x);
            ViewState["dt"] = dt;
            gvShow.DataSource = ViewState["dt"];
            gvShow.DataBind();
        }
    }
}

⌨️ 快捷键说明

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