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

📄 invoiceadd.aspx.cs

📁 c#三层架构项目开发的全过程
💻 CS
📖 第 1 页 / 共 2 页
字号:
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;
namespace 金利来分销管理系统.Invoice
{
    public partial class InvoiceAdd : System.Web.UI.Page
    {
        bool x = true;
        DataTable dt;
        //实例化的BLL层
        BLL.Invoice.InvoiceBll bllshow;
        BLL.Goods.ProductBll productbllshow;
        BLL.Store.StoreBll storeIDshow;
        List<Model.Invoice.InvoiceModel> show = new List<Model.Invoice.InvoiceModel>();
        public InvoiceAdd()
        {
            bllshow = new BLL.Invoice.InvoiceBll();
            productbllshow = new BLL.Goods.ProductBll();
            storeIDshow = new BLL.Store.StoreBll();
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!this.IsPostBack)
            {
                //将所有商品编号添加到DropDownList
                List<Model.Goods.ProductModel> productid = productbllshow.SelectProductID();
                foreach (var item in productid)
                {
                    this.ddlProductID.Items.Add(item.product_id);
                }
                //将单据类型名称添加到DropDownList
                List<Model.Invoice.InvoiceModel> invoicetype = bllshow.InvoiceTypeSelect();
                foreach (var item in invoicetype)
                {
                    this.ddlTypeName.Items.Add(item.invoice_type_name);
                }
                //获取当天时间
                this.lblInvoiceID.Text = "ZB" + DateTime.Now.ToString("yyyyMMddhhmmssfff");
               
            }
        }
        //创建一张虚拟表
        private void createDT()
        {
            dt = new DataTable();
            dt.Columns.Add("商品ID");
            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("数量");
            dt.Columns.Add("始");
            dt.Columns.Add("至");
        }
        //当商品编号选择项发生改变时
        protected void ddlProductID_SelectedIndexChanged(object sender, EventArgs e)
        {
            //当未选择商品编号时
            if (this.ddlProductID.Text == "请选择商品编号")
            {
                //提示“请选择商品编号”
                this.lblproductidcheck.Visible = true;
            }
            else
            {
                //提示框“请选择商品编号”
                this.lblproductidcheck.Visible = false;
            }
            //颜色框的值清空
            ddlColor.Items.Clear();
            txtProductName.Text = "";
            //获取商品信息
            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.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();
            }
            //尺码的文本框归零
            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";
        }
        //当点击‘提交’按钮时
        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            //‘请至少选择一件商品’lable隐藏
            this.lblSum.Visible = false;
            //‘请检查库存数量’lable隐藏
            this.lblShow.Visible = false;
            //当商品编号选择项不是‘请选择商品编号’,即有选定值时
            if (this.ddlProductID.SelectedValue != "请选择商品编号")
            {
                //当选择了单据的类型时,才运行以下功能
                if (this.ddlTypeName.Text != "请选择单据类型")
                {
                    //门店编号选择项有选定值时
                    if (ddlstorego.Text != "请选择门店编号" && ddlstoreto.Text != "请选择门店编号")
                    {
                        //如果ViewState["dt"]之前没有被创建
                        if (ViewState["dt"] == null)
                        {
                            createDT();
                        }
                        //ViewState["dt"]之前已被创建,那么把ViewState["dt"]的值给dt
                        else
                        {
                            dt = (DataTable)ViewState["dt"];
                        }
                        //dt虚拟表添加新值
                        DataRow dr = dt.NewRow();
                        dr[0] = this.ddlProductID.Text.Trim();
                        dr[1] = this.ddlColor.Text;
                        dr[2] = this.txtSize1.Text;
                        dr[3] = this.txtSize2.Text;
                        dr[4] = this.txtSize3.Text;
                        dr[5] = this.txtSize4.Text;
                        dr[6] = this.txtSize5.Text;
                        dr[7] = this.txtSize6.Text;
                        dr[8] = this.txtSize7.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);
                        dr[10] = this.ddlstorego.Text;
                        dr[11] = this.ddlstoreto.Text;
                        int s1 = int.Parse(this.txtSize1.Text);
                        int s2 = int.Parse(this.txtSize2.Text);
                        int s3 = int.Parse(this.txtSize3.Text);
                        int s4 = int.Parse(this.txtSize4.Text);
                        int s5 = int.Parse(this.txtSize5.Text);
                        int s6 = int.Parse(this.txtSize6.Text);
                        int s7 = int.Parse(this.txtSize7.Text);
                        //如果数量都是为“零”
                        if (int.Parse(dr[9].ToString()) == 0)
                        {
                            //‘请至少选择一件商品’lable显示
                            this.lblSum.Visible = true;
                        }
                        //大于零的时候
                        else
                        {
                            //通过商品在库存中的编号,颜色以及库存编号查找尺码是否大于所填写的数据
                            Model.Store.StoreModel storemodel = storeIDshow.SelectStoreByProduct(int.Parse(this.ddlstorego.Text), this.ddlProductID.Text, this.ddlColor.Text);
                            //在dt表里的每一行循环
                            foreach (DataRow item in dt.Rows)
                            {
                                //提交的信息,与dt表里存在的信息做对比
                                if (int.Parse(this.ddlstorego.Text) == Convert.ToInt32(item[10]) && this.ddlProductID.Text.Trim() == item[0].ToString() && this.ddlColor.Text.Trim() == item[1].ToString())
                                {
                                    //开始记录该仓库,该商品,该颜色,在dt表里已存在的尺码数量
                                    s1 += Convert.ToInt32(item[2]);
                                    s2 += Convert.ToInt32(item[3]);
                                    s3 += Convert.ToInt32(item[4]);
                                    s4 += Convert.ToInt32(item[5]);
                                    s5 += Convert.ToInt32(item[6]);
                                    s6 += Convert.ToInt32(item[7]);
                                    s7 += Convert.ToInt32(item[8]);
                                    //该仓库,该商品,该颜色的信息,是否小于(提交的信息加dt表里所对应的信息)
                                    if (storemodel.store_size1 < s1 || storemodel.store_size2 < s2 || storemodel.store_size3 < s3 || storemodel.store_size4 < s4 || storemodel.store_size5 < s5 || storemodel.store_size6 < s6 || storemodel.store_size7 < s7)
                                    {
                                        this.lblShow.Visible = true;
                                        //如果小于添加的数额,跳出
                                        return;
                                    }
                                }
                            }
                            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))
                            {
                                //‘请检查库存数量’lable显示
                                this.lblShow.Visible = true;
                            }
                            else
                            {
                                this.lblShow.Visible = false;
                                //当dt为空的时候
                                if (dt.Rows.Count == 0)
                                {
                                    dt.Rows.Add(dr);
                                }
                                else
                                {
                                    foreach (DataRow item in dt.Rows)
                                    {
                                        //当添加信息时,dt是否已有该信息
                                        if (item[0].ToString() == this.ddlProductID.Text.Trim() && item[1].ToString() == this.ddlColor.Text.Trim()&&item[10].ToString()==this.ddlstorego.Text&&item[11].ToString()==this.ddlstoreto.Text)
                                        {
                                            //如果存在  x = false;
                                            x = false;
                                            //修改该信息
                                            for (int i = 1; i <= 1; i++)

⌨️ 快捷键说明

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