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

📄 productimport.cs

📁 动易SiteFactory&#8482 网上商店系统1.0源代码
💻 CS
字号:
namespace PowerEasy.WebSite.Admin.Shop
{
    using PowerEasy.Common;
    using PowerEasy.CommonModel;
    using PowerEasy.Contents;
    using PowerEasy.Controls;
    using PowerEasy.Shop;
    using PowerEasy.Web.UI;
    using PowerEasy.WebSite.Controls;
    using PowerEasy.WebSite.Controls.FieldControl;
    using System;
    using System.Collections;
    using System.Data;
    using System.Web.UI;
    using System.Web.UI.WebControls;

    public class ProductImport : AdminPage
    {
        protected DropDownList DropModelList;
        protected DropDownList DropShopNodeList;
        protected ProductManageNavigation Pmn;
        protected Repeater RepeaterExcelFields;
        protected ScriptManager ScriptManager1;
        protected ExtendedSiteMapPath SmpNavigator;
        protected SpecialType SpecialType1;
        protected System.Web.UI.UpdatePanel UpdatePanel1;
        protected FileUpload UpExcellFile;
        protected WizardStep WizardStep1;
        protected WizardStep WizardStep2;
        protected Wizard WzdProductImport;

        protected void DropShopNodeList_SelectedIndexChanged(object sender, EventArgs e)
        {
            this.DropModelList.DataSource = ModelManager.GetShopModelListByNodeId(DataConverter.CLng(this.DropShopNodeList.SelectedValue), true);
            this.DropModelList.DataBind();
        }

        private DataTable GetTableFields(string[] fieldsDescription)
        {
            string[] strArray = new string[] { "ProductName", "ProductNum", "Unit", "Price", "Price_Market", "Weight", "Stocks", "AlarmNum", "ProducerName", "TrademarkName", "BarCode", "ProductIntro", "ProductExplain", "Stars" };
            DataTable table = new DataTable();
            table.Columns.Add("Name", typeof(string));
            table.Columns.Add("Description", typeof(string));
            for (int i = 0; i < strArray.Length; i++)
            {
                DataRow row = table.NewRow();
                row[0] = strArray[i];
                row[1] = fieldsDescription[i];
                table.Rows.Add(row);
            }
            return table;
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!base.IsPostBack)
            {
                this.DropShopNodeList.DataSource = PowerEasy.Contents.Nodes.GetShopNodeList();
                this.DropShopNodeList.DataBind();
                this.DropShopNodeList_SelectedIndexChanged(sender, e);
            }
        }

        protected void RepeaterExcelFields_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if ((e.Item.ItemType == ListItemType.Item) || (e.Item.ItemType == ListItemType.AlternatingItem))
            {
                Literal literal = (Literal) e.Item.FindControl("LiteralTableField");
                DropDownList list = (DropDownList) e.Item.FindControl("DropExcelFields");
                literal.Text = e.Item.DataItem.ToString();
                list.DataSource = this.ExcelFields;
                for (int i = 0; i < this.ExcelFields.Count; i++)
                {
                    if (string.Compare(this.ExcelFields[i].ToString(), e.Item.DataItem.ToString()) == 0)
                    {
                        list.SelectedValue = this.ExcelFields[i].ToString();
                    }
                }
                list.DataBind();
            }
        }

        protected void WzdProductImport_FinishButtonClick(object sender, WizardNavigationEventArgs e)
        {
            DataTable dtField = new DataTable();
            dtField.Columns.Add("FieldValueName", typeof(string));
            dtField.Columns.Add("FieldName", typeof(string));
            for (int i = 0; i < this.RepeaterExcelFields.Items.Count; i++)
            {
                string selectedValue = ((DropDownList) this.RepeaterExcelFields.Items[i].FindControl("DropExcelFields")).SelectedValue;
                DataRow row = dtField.NewRow();
                string text = ((Literal) this.RepeaterExcelFields.Items[i].FindControl("LiteralTableField")).Text;
                row[0] = selectedValue;
                DataRow[] rowArray = this.TableFields.Select("Description='" + text + "'");
                if (rowArray.Length != 0)
                {
                    row[1] = rowArray[0][0];
                }
                dtField.Rows.Add(row);
            }
            AdminPage.WriteSuccessMsg("成功导入商品" + Product.BatchImport(dtField, this.FileSource, DataConverter.CLng(this.SpecialType1.FieldValue), DataConverter.CLng(this.DropShopNodeList.SelectedValue), DataConverter.CLng(this.DropModelList.SelectedValue)).ToString() + "个!" + Product.MessgeOfBatchImport, "ProductImport.aspx");
        }

        protected void WzdProductImport_NextButtonClick(object sender, WizardNavigationEventArgs e)
        {
            if (this.UpExcellFile.PostedFile.ContentLength <= 0)
            {
                AdminPage.WriteErrMsg("<li>请选择你要上传的文件!</li>");
            }
            int startIndex = this.UpExcellFile.PostedFile.FileName.LastIndexOf(@"\");
            this.FileSource = base.Server.MapPath("~/Temp/" + this.UpExcellFile.PostedFile.FileName.Substring(startIndex));
            this.UpExcellFile.PostedFile.SaveAs(this.FileSource);
            string[] fieldsDescription = new string[] { "商品名称", "商品编号", "单位", "价格", "市场参考价", "重量(kg)", "库存数量", "库存报警下限", "生产商", "品牌/商标", "条形码", "商品简介", "详细介绍", "商品推荐等级" };
            this.TableFields = this.GetTableFields(fieldsDescription);
            this.ExcelFields = Product.GetExcelFields(this.FileSource);
            this.RepeaterExcelFields.DataSource = fieldsDescription;
            this.RepeaterExcelFields.DataBind();
        }

        private ArrayList ExcelFields
        {
            get
            {
                return (ArrayList) this.ViewState["ExcelFields"];
            }
            set
            {
                this.ViewState["ExcelFields"] = value;
            }
        }

        private string FileSource
        {
            get
            {
                return this.ViewState["FileSource"].ToString();
            }
            set
            {
                this.ViewState["FileSource"] = value;
            }
        }

        private DataTable TableFields
        {
            get
            {
                return (DataTable) this.ViewState["TableFields"];
            }
            set
            {
                this.ViewState["TableFields"] = value;
            }
        }
    }
}

⌨️ 快捷键说明

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