Exemple #1
0
        public ServiceResult Run(RunMethod runMethod)
        {
            /*====Get WebService URL and UserName and Password====*/
            SAPWebServiceEntity webServiceEntity = System.Configuration.ConfigurationManager.GetSection("MaterialTransferConfig") as SAPWebServiceEntity;

            if (webServiceEntity == null)
            {
                return(new ServiceResult(false, "没有维护MaterialTransferConfig对应的Service地址", this.m_Argument.TransactionCode));
            }

            #region Begin for Prepare input Paremente
            // Prepare input parameter
            DT_MES_MATERIAL_REQ materialParameter = new DT_MES_MATERIAL_REQ();
            materialParameter.MaintainDate_B   = this.m_Argument.MaintainDate_B.Date.ToString("yyyyMMdd", new System.Globalization.CultureInfo("en-US"));
            materialParameter.MaintainDate_E   = this.m_Argument.MaintainDate_E.Date.ToString("yyyyMMdd", new System.Globalization.CultureInfo("en-US"));
            materialParameter.OrgID            = this.m_Argument.OrgID.ToString();
            materialParameter.Transaction_code = this.m_Argument.TransactionCode;
            #endregion

            // Serialize the Input Parameter
            string xmlFilePath = SerializeUtil.SerializeFile(this.m_Argument.TransactionCode + "_Request.xml",
                                                             typeof(DT_MES_MATERIAL_REQ), materialParameter);

            #region For Request Log
            DBDateTime         requestDateTime = FormatHelper.GetNowDBDateTime(this.DataProvider);
            SAPDataTransferLog log             = new SAPDataTransferLog();
            TransferFacade     transferFacade  = new TransferFacade(this.DataProvider);
            log.JobID               = TransferFacade.MaterialTransferJobID;
            log.TransactionCode     = this.m_Argument.TransactionCode;
            log.TransactionSequence = 1;
            log.RequestDate         = requestDateTime.DBDate;
            log.RequestTime         = requestDateTime.DBTime;
            log.RequestContent      = xmlFilePath;
            log.OrganizationID      = this.m_Argument.OrgID;
            log.SendRecordCount     = 1;
            transferFacade.AddSAPDataTransferLog(log);
            #endregion

            #region Begin for Calling WebService
            // Call Web Service through MaterialServiceClientProxy
            DT_MES_MATERIAL_RESP returnValue;
ReTryLabel:
            m_RetriedTimes++;
            try
            {
                MaterialServiceClientProxy clientProxy = new MaterialServiceClientProxy();
                clientProxy.RequestEncoding = Encoding.UTF8;
                clientProxy.Timeout         = InternalVariables.MS_TimeOut * 1000;
                clientProxy.Url             = webServiceEntity.Url;
                clientProxy.PreAuthenticate = true;
                System.Uri uri = new Uri(clientProxy.Url);
                clientProxy.Credentials = new NetworkCredential(webServiceEntity.UserName, webServiceEntity.Password).GetCredential(uri, "");
                returnValue             = clientProxy.MI_MES_MATERIAL_REQ(materialParameter);
                clientProxy.Dispose();
                clientProxy = null;

                //Serialize the output Parameter
                xmlFilePath = SerializeUtil.SerializeFile(this.m_Argument.TransactionCode + "_Response.xml",
                                                          typeof(DT_MES_MATERIAL_RESP), returnValue);

                // Update Log
                DBDateTime responseDateTime = FormatHelper.GetNowDBDateTime(this.DataProvider);
                log.ResponseDate    = responseDateTime.DBDate;
                log.ResponseTime    = responseDateTime.DBTime;
                log.ResponseContent = xmlFilePath;
                transferFacade.UpdateSAPDataTransferLog(log);
            }
            catch (Exception e)
            {
                #region Retry or log it
                if (e.Message.IndexOf("Server Error", StringComparison.CurrentCultureIgnoreCase) >= 0)
                {
                    if (m_RetriedTimes < InternalVariables.MS_ReTryTimes)
                    {
                        System.Threading.Thread.Sleep(InternalVariables.MS_ReTryInterval * 1000);
                        goto ReTryLabel;
                    }
                    else
                    {
                        log.Result       = "Fail";
                        log.ErrorMessage = e.Message;
                        transferFacade.UpdateSAPDataTransferLog(log);
                        return(new ServiceResult(false, e.Message, log.TransactionCode));
                    }
                }
                else
                {
                    if (e is System.Net.WebException)
                    {
                        if (((System.Net.WebException)e).Status == WebExceptionStatus.Timeout)
                        {
                            if (m_RetriedTimes < InternalVariables.MS_ReTryTimes)
                            {
                                System.Threading.Thread.Sleep(InternalVariables.MS_ReTryInterval * 1000);
                                goto ReTryLabel;
                            }
                            else
                            {
                                log.Result       = "Fail";
                                log.ErrorMessage = e.Message;
                                transferFacade.UpdateSAPDataTransferLog(log);
                                return(new ServiceResult(false, e.Message, log.TransactionCode));
                            }
                        }
                        else
                        {
                            log.Result       = "Fail";
                            log.ErrorMessage = e.Message;
                            transferFacade.UpdateSAPDataTransferLog(log);
                            return(new ServiceResult(false, e.Message, log.TransactionCode));
                        }
                    }
                    else
                    {
                        log.Result       = "Fail";
                        log.ErrorMessage = e.Message;
                        transferFacade.UpdateSAPDataTransferLog(log);
                        return(new ServiceResult(false, e.Message, log.TransactionCode));
                    }
                }
                #endregion
            }
            #endregion

            // Generate Material Object and Save it
            if (string.Compare(returnValue.FLAG, "Y", true) == 0)
            {
                int materialCount = returnValue.Material_Tab.Length;

                ((BenQGuru.eMES.Common.DomainDataProvider.SQLDomainDataProvider)DataProvider).PersistBroker.AutoCloseConnection = false;
                ((BenQGuru.eMES.Common.DomainDataProvider.SQLDomainDataProvider)DataProvider).PersistBroker.OpenConnection();
                this.DataProvider.BeginTransaction();

                try
                {
                    ItemFacade  itemFacade  = new ItemFacade(this.DataProvider);
                    ModelFacade modelFacade = new ModelFacade(this.DataProvider);
                    BenQGuru.eMES.Domain.MOModel.Material material;
                    DT_MES_MATERIAL_TAB_RESP materialObj;
                    DBDateTime currentDateTime = FormatHelper.GetNowDBDateTime(this.DataProvider);

                    #region Get Parameters
                    // Get CheckOPCode and LotSize
                    SystemSettingFacade ssf      = new SystemSettingFacade(this.DataProvider);
                    string finishGoodCheckOPCode = "AWGJC1";
                    object para = ssf.GetParameter("FINISHEDPRODUCTOPCODE", "ITEMCHECKOP");
                    if (para != null)
                    {
                        finishGoodCheckOPCode = (para as Parameter).ParameterAlias.Trim().ToUpper();
                    }
                    string semiGoodCheckOPCode = "ATSH1";
                    para = ssf.GetParameter("SEMIMANUFACTUREOPCODE", "ITEMCHECKOP");
                    if (para != null)
                    {
                        semiGoodCheckOPCode = (para as Parameter).ParameterAlias.Trim().ToUpper();
                    }
                    int finishGoodLotSize = 200;
                    para = ssf.GetParameter("FINISHEDPRODUCTLOTSIZE", "ITEMLOTSIZE");
                    if (para != null)
                    {
                        finishGoodLotSize = int.Parse((para as Parameter).ParameterAlias.Trim());
                    }
                    int semiGoodLotSize = 500;
                    para = ssf.GetParameter("SEMIMANUFACTURELOTSIZE", "ITEMLOTSIZE");
                    if (para != null)
                    {
                        semiGoodLotSize = int.Parse((para as Parameter).ParameterAlias.Trim());
                    }

                    // Get NeedCheckCarton and NeedCheckAccessory from parameter table
                    string importFGCheckCarton = "1";
                    para = ssf.GetParameter("FGIMPORTCHKCARTON", "CHECKPACKING");
                    if (para != null)
                    {
                        importFGCheckCarton = (para as Parameter).ParameterAlias.Trim();
                    }
                    string exportFGCheckCarton = "1";
                    para = ssf.GetParameter("FGEXPORTCHKCARTON", "CHECKPACKING");
                    if (para != null)
                    {
                        exportFGCheckCarton = (para as Parameter).ParameterAlias.Trim();
                    }
                    string importFGCheckAccessory = "1";
                    para = ssf.GetParameter("FGIMPORTCHKACCESSORY", "CHECKPACKING");
                    if (para != null)
                    {
                        importFGCheckAccessory = (para as Parameter).ParameterAlias.Trim();
                    }
                    string exportFGCheckAccessory = "0";
                    para = ssf.GetParameter("FGEXPORTCHKACCESSORY", "CHECKPACKING");
                    if (para != null)
                    {
                        exportFGCheckAccessory = (para as Parameter).ParameterAlias.Trim();
                    }
                    #endregion

                    for (int i = 0; i < materialCount; i++)
                    {
                        #region Material Object
                        bool needAddNew = false;
                        materialObj = returnValue.Material_Tab[i];
                        object oldMaterial = itemFacade.GetMaterial(InternalVariables.MatchItemCode(materialObj.Itemcode.ToUpper()), int.Parse(materialObj.OrgID.Trim()));

                        if (oldMaterial == null)
                        {
                            material = itemFacade.CreateNewMaterial();
                            material.MaintainUser       = "******";
                            material.EAttribute1        = "";
                            material.CheckStatus        = "";
                            material.MaterialParseType  = "";
                            material.MaterialCheckType  = "";
                            material.MaterialModelGroup = "";

                            if (string.Compare(materialObj.ITEMCONTROL, "A", true) == 0 ||
                                string.Compare(materialObj.ITEMCONTROL, "B", true) == 0)
                            {
                                material.MaterialCheckType = OPBOMDetailCheckType.CHECK_LINKBARCODE;
                            }

                            needAddNew = true;
                        }
                        else
                        {
                            material   = oldMaterial as BenQGuru.eMES.Domain.MOModel.Material;
                            needAddNew = false;
                        }

                        #region 属性赋值
                        /*---------------------  Web Service 节点数据 ---------------------*/
                        material.MaterialCode        = InternalVariables.MatchItemCode(materialObj.Itemcode.ToUpper());
                        material.OrganizationID      = int.Parse(materialObj.OrgID);
                        material.MaterialName        = materialObj.itemname.ToUpper();
                        material.MaterialDescription = materialObj.itemname.ToUpper();
                        material.MaterialUOM         = materialObj.ITEMUOM;

                        if (string.Compare(materialObj.ITEMTYPE, "FERT", true) == 0)
                        {
                            material.MaterialType = ItemType.ITEMTYPE_FINISHEDPRODUCT;
                        }
                        else if (string.Compare(materialObj.ITEMTYPE, "HALB", true) == 0)
                        {
                            material.MaterialType = ItemType.ITEMTYPE_SEMIMANUFACTURE;
                        }
                        else if (string.Compare(materialObj.ITEMTYPE, "ROH", true) == 0)
                        {
                            material.MaterialType = ItemType.ITEMTYPE_RAWMATERIAL;
                        }
                        else
                        {
                            continue;
                        }

                        material.MaterialMachineType      = materialObj.ItemMachineType;
                        material.MaterialVolume           = materialObj.Itemvolume;
                        material.MaterialGroup            = materialObj.ItemGroup;
                        material.MaterialGroupDescription = materialObj.ItemGroupDesc.ToUpper();
                        material.MaterialModelGroup       = "";

                        if (string.Compare(materialObj.ITEMCONTROL, "A", true) == 0)
                        {
                            material.MaterialControlType = BOMItemControlType.ITEM_CONTROL_KEYPARTS;
                        }
                        else if (string.Compare(materialObj.ITEMCONTROL, "B", true) == 0)
                        {
                            material.MaterialControlType = BOMItemControlType.ITEM_CONTROL_LOT;
                        }
                        else
                        {
                            material.MaterialControlType = BOMItemControlType.ITEM_CONTROL_NOCONTROL;
                        }

                        if (materialObj.itemname.Split('.').Length > 3)
                        {
                            material.MaterialModelCode = materialObj.itemname.Split('.')[2];
                        }
                        else
                        {
                            material.MaterialModelCode = "";
                        }

                        if (materialObj.itemname.Contains("中国"))
                        {
                            material.MaterialExportImport = "IMPORT";
                        }
                        else
                        {
                            material.MaterialExportImport = "EXPORT";
                        }

                        if (material.MaterialDescription.Length >= 3)
                        {
                            if (string.Compare(material.MaterialDescription.Substring(material.MaterialDescription.Length - 3, 3),
                                               "ROH", true) == 0)
                            {
                                material.ROHS = "Y";
                            }
                            else
                            {
                                material.ROHS = "";
                            }
                        }
                        else
                        {
                            material.ROHS = "";
                        }
                        #endregion

                        // Save
                        if (needAddNew)
                        {
                            itemFacade.AddMaterial(material);
                        }
                        else
                        {
                            itemFacade.UpdateMaterial(material);
                        }
                        #endregion

                        #region Finish Good & Semi Finish Good
                        /*------------ 如果ItemType是半成品或者成品,则同时更新或插入tblitem----------*/
                        if (material.MaterialType == ItemType.ITEMTYPE_FINISHEDPRODUCT ||
                            material.MaterialType == ItemType.ITEMTYPE_SEMIMANUFACTURE)
                        {
                            needAddNew = false;
                            BenQGuru.eMES.Domain.MOModel.Item item;
                            object oldItem = itemFacade.GetItem(material.MaterialCode.ToUpper(), material.OrganizationID);

                            if (oldItem == null)
                            {
                                item = itemFacade.CreateNewItem();

                                /*-------------- 固定数据 ----------*/
                                item.ItemVersion             = "";
                                item.MaintainUser            = "******";
                                item.ItemUser                = "******";
                                item.ItemDate                = currentDateTime.DBDate;
                                item.EAttribute1             = "";
                                item.ItemConfigration        = "";
                                item.ItemCartonQty           = 1;
                                item.ItemBurnInQty           = 0;
                                item.ElectricCurrentMaxValue = 0;
                                item.ElectricCurrentMinValue = 0;
                                item.ItemProductCode         = "";

                                if (material.MaterialType == ItemType.ITEMTYPE_FINISHEDPRODUCT)
                                {
                                    item.CheckItemOP = finishGoodCheckOPCode;
                                    item.LotSize     = finishGoodLotSize;
                                }
                                else if (material.MaterialType == ItemType.ITEMTYPE_SEMIMANUFACTURE)
                                {
                                    item.CheckItemOP = semiGoodCheckOPCode;
                                    item.LotSize     = semiGoodLotSize;
                                }

                                if (material.MaterialType == ItemType.ITEMTYPE_FINISHEDPRODUCT)
                                {
                                    if (material.MaterialExportImport == "IMPORT")
                                    {
                                        item.NeedCheckCarton    = importFGCheckCarton;
                                        item.NeedCheckAccessory = importFGCheckAccessory;
                                    }
                                    else
                                    {
                                        item.NeedCheckCarton    = exportFGCheckCarton;
                                        item.NeedCheckAccessory = exportFGCheckAccessory;
                                    }
                                }
                                else
                                {
                                    item.NeedCheckCarton    = "0";
                                    item.NeedCheckAccessory = "0";
                                }

                                needAddNew = true;
                            }
                            else
                            {
                                item = oldItem as Item;

                                needAddNew = false;
                            }

                            /*----- Web Service 节点数据 -----*/
                            item.ItemCode        = material.MaterialCode;
                            item.OrganizationID  = material.OrganizationID;
                            item.ItemName        = material.MaterialName.ToUpper();
                            item.ItemDescription = material.MaterialName.ToUpper();
                            item.ItemUOM         = material.MaterialUOM;
                            item.ItemType        = material.MaterialType;
                            item.ItemControlType = material.MaterialControlType;

                            if (needAddNew)
                            {
                                itemFacade.AddItem(item);
                            }
                            else
                            {
                                itemFacade.UpdateItem(item);
                            }

                            // ItemSNCheck
                            if (itemFacade.GetItem2SNCheck(item.ItemCode, ItemCheckType.ItemCheckType_SERIAL) == null)
                            {
                                Item2SNCheck item2SNCheck = new Item2SNCheck();
                                item2SNCheck.ItemCode     = item.ItemCode;
                                item2SNCheck.EAttribute1  = "";
                                item2SNCheck.MaintainUser = "******";
                                if (material.MaterialType == ItemType.ITEMTYPE_FINISHEDPRODUCT)
                                {
                                    item2SNCheck.SNLength = 24;
                                    item2SNCheck.SNPrefix = item.ItemCode;
                                }
                                else // ITEMTYPE_SEMIMANUFACTURE
                                {
                                    item2SNCheck.SNLength = 10;
                                    item2SNCheck.SNPrefix = "";
                                }
                                item2SNCheck.SNContentCheck = "Y";
                                item2SNCheck.Type           = "SERIAL";
                                itemFacade.AddItem2SNCheck(item2SNCheck);
                            }

                            /*----------- 物料所属物料别插入tblmodel2item中,取物料料号的第二位为物料别 ---------*/
                            object oldModel2Item = modelFacade.GetModel2Item(item.ItemCode.Substring(1, 1), item.ItemCode, item.OrganizationID);
                            if (oldModel2Item == null)
                            {
                                Model2Item model2Item = new Model2Item();
                                model2Item.ModelCode      = item.ItemCode.Substring(1, 1);
                                model2Item.ItemCode       = item.ItemCode;
                                model2Item.OrganizationID = item.OrganizationID;
                                model2Item.MaintainUser   = "******";

                                modelFacade.AddModel2Item(model2Item);
                            }

                            /*---- 在tblmodel2item中Distinct tblmodel2item.modelcode,如果不存在于tblmodel中,则插入tblmodel ----*/
                            object oldModel = modelFacade.GetModel(item.ItemCode.Substring(1, 1), item.OrganizationID);
                            if (oldModel == null)
                            {
                                Model model = new Model();
                                model.ModelCode        = item.ItemCode.Substring(1, 1);
                                model.OrganizationID   = item.OrganizationID;
                                model.MaintainUser     = "******";
                                model.ModelDescription = model.ModelCode;
                                model.DataLinkQty      = 0;
                                model.DimQty           = 0;
                                model.EAttribute1      = "";
                                model.IsCheckDataLink  = "0";
                                model.IsDim            = "0";
                                model.IsInventory      = "1";
                                model.IsReflow         = "0";

                                modelFacade.AddModel(model);
                            }
                        }
                        #endregion
                    }

                    this.DataProvider.CommitTransaction();

                    log.Result       = "OK";
                    log.ErrorMessage = "";
                }
                catch (Exception ex)
                {
                    this.DataProvider.RollbackTransaction();
                    // Log
                    log.Result       = "Fail";
                    log.ErrorMessage = ex.Message;
                }
                finally
                {
                    ((BenQGuru.eMES.Common.DomainDataProvider.SQLDomainDataProvider)DataProvider).PersistBroker.CloseConnection();
                    ((BenQGuru.eMES.Common.DomainDataProvider.SQLDomainDataProvider)DataProvider).PersistBroker.AutoCloseConnection = true;
                }

                log.ReceivedRecordCount = materialCount;
                DBDateTime finishedDateTime = FormatHelper.GetNowDBDateTime(this.DataProvider);
                log.FinishedDate = finishedDateTime.DBDate;
                log.FinishedTime = finishedDateTime.DBTime;
                transferFacade.UpdateSAPDataTransferLog(log);

                if (log.Result == "OK")
                {
                    return(new ServiceResult(true, "", log.TransactionCode));
                }
                else
                {
                    return(new ServiceResult(false, log.ErrorMessage, log.TransactionCode));
                }
            }
            else //  status!="OK"
            {
                log.Result              = "Fail";
                log.ErrorMessage        = returnValue.message;
                log.ReceivedRecordCount = 0;
                transferFacade.UpdateSAPDataTransferLog(log);
                return(new ServiceResult(false, log.ErrorMessage, log.TransactionCode));
            }
        }
        protected void btnAddNoteBook_Click(object sender, EventArgs e)
        {
            ItemFacade itemFacade = new ItemFacade(varHelper.TOP_AppKey, varHelper.TOP_AppSecret);
            string iid = "d67dda3331e09275f623eaca0fddec1b";
            string nick = "hzwdf";
            try
            {
                string sessionKey = TOP_SessionKey;
                ItemDetail itemDetail = itemFacade.GetItem(iid, nick);
                if (itemDetail != null)
                {
                    string province = EncodeHelper.GB2312ToUTF8(itemDetail.Location.State);// "浙江"ddlProvince.SelectedValue;
                    string city = EncodeHelper.GB2312ToUTF8(itemDetail.Location.City);// "杭州"ddlCity.SelectedValue;
                    string description = EncodeHelper.GB2312ToUTF8(itemDetail.Description);
                    string imgPath = null;
                    string title = "ThinkPad SL400 2743P9C";// itemDetail.Title;
                    string props = "20879:21456;1627207:28341;20000:21642;20155:3218646;1626045:13243855;31356:100692;20100:21373;20143:45566;31359:3218681;22572:37064;20121:21482;22623:47286;20122:685;20137:21487;20145:21588;21530:42376;20183:21968;31357:3220749;20930:32998;31696:107066;1626817:3227612;1626975:3229217";// itemDetail.Properties;
                    string propAlias = "";// itemDetail.PropertyAlias;

                    if (itemDetail.ItemImgList != null && itemDetail.ItemImgList.Count > 0)
                    {
                        string imgUrl = itemDetail.ItemImgList[0].ImgUrl;
                        string dirPath = Server.MapPath("~/Images/Shops") + @"\" + nick;
                        if (!Directory.Exists(dirPath))
                        {
                            Directory.CreateDirectory(dirPath);
                        }
                        string filePath = string.Empty;
                        using (WebClient client = new WebClient())
                        {
                            filePath = SaveItem(itemDetail.ItemImgList[0], dirPath, client);
                        }
                        if (!string.IsNullOrEmpty(filePath))
                        {
                            if (File.Exists(filePath))
                            {
                                imgPath = filePath;
                            }
                        }
                    }
                    List<string> sku_properties = new List<string>();
                    List<string> sku_quantities = new List<string>();
                    List<string> sku_prices = new List<string>();
                    List<string> sku_outer_ids = new List<string>();

                    foreach (Sku sku in itemDetail.SkuList)
                    {
                        // Sku s = itemFacade.GetSku(sku.Id, nick);
                        sku_properties.Add(sku.Properties);
                        sku_quantities.Add(sku.Quantity.ToString());
                        sku_prices.Add(sku.Price);
                        sku_outer_ids.Add(sku.OuterId);
                    }
                    Response.Write("<BR />");
                    string response = itemFacade.AddItem(itemDetail.Number
                        , itemDetail.Price
                        , itemDetail.ItemType
                        , itemDetail.StuffStatus
                        , title
                        , description
                        , province
                        , city
                        , itemDetail.CategoryId
                        , props
                        , itemDetail.ApproveStatus
                        , itemDetail.FreightPayer
                        , itemDetail.ValidateDate
                        , itemDetail.HasInvoice
                        , itemDetail.HasWarranty
                        , itemDetail.AutoRepost
                        , string.Empty              // 橱窗推荐。可选值:true,false;默认值:false(不推荐)
                        , string.Empty              // 商品所属的店铺类目列表。按逗号分隔。结构:",cid1,cid2,...,",如果店铺类目存在二级类目,必须传入子类目cids。
                        , itemDetail.HasDiscount
                        , itemDetail.FeePost
                        , itemDetail.FeeExpress
                        , itemDetail.FeeEms
                        , itemDetail.ListTime
                        , itemDetail.Increment
                        , string.Empty              // 宝贝所属的运费模板ID。模板可以通过taobao.postages.get获得
                        , imgPath
                        , itemDetail.AuctionPoint
                        , propAlias
                        , itemDetail.InputPids
                        , itemDetail.InputStr
                        , string.Join(";", sku_properties.ToArray())
                        , string.Join(",", sku_quantities.ToArray())
                        , string.Join(",", sku_prices.ToArray())
                        , string.Join(",", sku_outer_ids.ToArray())
                        , string.Empty, itemDetail.OuterId, itemDetail.ProductId
                        , TOP_SessionKey);
                    Response.Write("从店铺\"" + itemDetail.Nick + "\"导入\"" + itemDetail.Title + "\"成功!");
                }
            }
            catch (ResponseException ex)
            {
                Response.Write(ex.ErrorCode + ": " + ex.ErrorMessageCh + ": " + ex.ErrorDescription);
            }
        }
        protected void btnAddNoteBook_Click(object sender, EventArgs e)
        {
            ItemFacade itemFacade = new ItemFacade(varHelper.TOP_AppKey, varHelper.TOP_AppSecret);
            string     iid        = "d67dda3331e09275f623eaca0fddec1b";
            string     nick       = "hzwdf";

            try
            {
                string     sessionKey = TOP_SessionKey;
                ItemDetail itemDetail = itemFacade.GetItem(iid, nick);
                if (itemDetail != null)
                {
                    string province    = EncodeHelper.GB2312ToUTF8(itemDetail.Location.State); // "浙江"ddlProvince.SelectedValue;
                    string city        = EncodeHelper.GB2312ToUTF8(itemDetail.Location.City);  // "杭州"ddlCity.SelectedValue;
                    string description = EncodeHelper.GB2312ToUTF8(itemDetail.Description);
                    string imgPath     = null;
                    string title       = "ThinkPad SL400 2743P9C";                                                                                                                                                                                                                                                                       // itemDetail.Title;
                    string props       = "20879:21456;1627207:28341;20000:21642;20155:3218646;1626045:13243855;31356:100692;20100:21373;20143:45566;31359:3218681;22572:37064;20121:21482;22623:47286;20122:685;20137:21487;20145:21588;21530:42376;20183:21968;31357:3220749;20930:32998;31696:107066;1626817:3227612;1626975:3229217"; // itemDetail.Properties;
                    string propAlias   = "";                                                                                                                                                                                                                                                                                             // itemDetail.PropertyAlias;

                    if (itemDetail.ItemImgList != null && itemDetail.ItemImgList.Count > 0)
                    {
                        string imgUrl  = itemDetail.ItemImgList[0].ImgUrl;
                        string dirPath = Server.MapPath("~/Images/Shops") + @"\" + nick;
                        if (!Directory.Exists(dirPath))
                        {
                            Directory.CreateDirectory(dirPath);
                        }
                        string filePath = string.Empty;
                        using (WebClient client = new WebClient())
                        {
                            filePath = SaveItem(itemDetail.ItemImgList[0], dirPath, client);
                        }
                        if (!string.IsNullOrEmpty(filePath))
                        {
                            if (File.Exists(filePath))
                            {
                                imgPath = filePath;
                            }
                        }
                    }
                    List <string> sku_properties = new List <string>();
                    List <string> sku_quantities = new List <string>();
                    List <string> sku_prices     = new List <string>();
                    List <string> sku_outer_ids  = new List <string>();

                    foreach (Sku sku in itemDetail.SkuList)
                    {
                        // Sku s = itemFacade.GetSku(sku.Id, nick);
                        sku_properties.Add(sku.Properties);
                        sku_quantities.Add(sku.Quantity.ToString());
                        sku_prices.Add(sku.Price);
                        sku_outer_ids.Add(sku.OuterId);
                    }
                    Response.Write("<BR />");
                    string response = itemFacade.AddItem(itemDetail.Number
                                                         , itemDetail.Price
                                                         , itemDetail.ItemType
                                                         , itemDetail.StuffStatus
                                                         , title
                                                         , description
                                                         , province
                                                         , city
                                                         , itemDetail.CategoryId
                                                         , props
                                                         , itemDetail.ApproveStatus
                                                         , itemDetail.FreightPayer
                                                         , itemDetail.ValidateDate
                                                         , itemDetail.HasInvoice
                                                         , itemDetail.HasWarranty
                                                         , itemDetail.AutoRepost
                                                         , string.Empty // 橱窗推荐。可选值:true,false;默认值:false(不推荐)
                                                         , string.Empty // 商品所属的店铺类目列表。按逗号分隔。结构:",cid1,cid2,...,",如果店铺类目存在二级类目,必须传入子类目cids。
                                                         , itemDetail.HasDiscount
                                                         , itemDetail.FeePost
                                                         , itemDetail.FeeExpress
                                                         , itemDetail.FeeEms
                                                         , itemDetail.ListTime
                                                         , itemDetail.Increment
                                                         , string.Empty // 宝贝所属的运费模板ID。模板可以通过taobao.postages.get获得
                                                         , imgPath
                                                         , itemDetail.AuctionPoint
                                                         , propAlias
                                                         , itemDetail.InputPids
                                                         , itemDetail.InputStr
                                                         , string.Join(";", sku_properties.ToArray())
                                                         , string.Join(",", sku_quantities.ToArray())
                                                         , string.Join(",", sku_prices.ToArray())
                                                         , string.Join(",", sku_outer_ids.ToArray())
                                                         , string.Empty, itemDetail.OuterId, itemDetail.ProductId
                                                         , TOP_SessionKey);
                    Response.Write("从店铺\"" + itemDetail.Nick + "\"导入\"" + itemDetail.Title + "\"成功!");
                }
            }
            catch (ResponseException ex)
            {
                Response.Write(ex.ErrorCode + ": " + ex.ErrorMessageCh + ": " + ex.ErrorDescription);
            }
        }