Exemplo n.º 1
0
        private void GoodsDownloadWorker_DownloadData(object sender, GoodsDownloadDataEventArgs e)
        {
            Debug.WriteLine("GoodsDownloadWorker_DownloadData");
            GoodsDownloadWorker worker = sender as GoodsDownloadWorker;

            this.Dispatcher.BeginInvoke(new Action(() => AppendDataToUi(e.Goods, worker.shop, worker.title, worker.code, worker.stockCode, worker.state)));
        }
Exemplo n.º 2
0
 private void btnQuery_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         //运行中或者暂停中
         if (this.goodsDownloadWorker != null)
         {
             if (goodsDownloadWorker.WorkerState == WorkerState.PAUSE)
             {
                 goodsDownloadWorker.GoOn();
             }
             if (goodsDownloadWorker.WorkerState == WorkerState.WORKING)
             {
                 goodsDownloadWorker.Pause(false, "用户暂停", 0);
             }
         }
         else
         {
             //创建新线程开始
             string        title     = this.tbTitle.Text.Trim();
             string        code      = this.tbCode.Text.Trim();
             string        stockCode = this.tbStockCode.Text.Trim();
             PopGoodsState state     = this.cbbStatus.GetSelectedEnum <PopGoodsState>();
             this.lastShop = this.cbbShops.SelectedItem as Shop;
             if (this.lastShop == null)
             {
                 throw new Exception("未选择店铺");
             }
             if (this.lastShop.AppEnabled == false)
             {
                 string htmlRet = this.wb1.GetTextAsync().Result;
                 if (htmlRet.Contains(this.lastShop.PopSellerId) == false)
                 {
                     throw new Exception("选择店铺与当前登录店铺不一致");
                 }
             }
             goodsDownloadWorker = new GoodsDownloadWorker(this.lastShop, title, code, stockCode, state);
             this.popGoodsInfoViewModels.Clear();
             goodsDownloadWorker.Download     += GoodsDownloadWorker_Download;
             goodsDownloadWorker.DownloadData += GoodsDownloadWorker_DownloadData;
             goodsDownloadWorker.Pausing      += GoodsDownloadWorker_Pausing;
             goodsDownloadWorker.Start();
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }
Exemplo n.º 3
0
        private void ExportToPddTask(Shop shop, PopGoodsInfoViewModel[] pgs, float[] buyInPrice)
        {
            string exportMsg = "";

            for (int i = 0; i < pgs.Length && this.isStop == false; i++)
            {
                int index = i;
                this.SetUiMsg(this.btnExportToPdd, "正在导入: " + (index + 1) + "/" + pgs.Length + " " + pgs[index].PopGoodsInfo.Id + " " + pgs[index].SkuCodesInfo, true, "停止", "导入");
                try
                {
                    var ret = ServiceContainer.GetService <GoodsService>().AddGoods(shop, pgs[i].PopGoodsInfo, buyInPrice[i]);
                    exportMsg = ret.Datas[0];
                    if (index < pgs.Length - 1)
                    {
                        this.SetUiMsg(this.btnExportToPdd, "等待60秒后继续导入", true, "停止", "导入");
                        Thread.Sleep(60000);
                    }
                }
                catch (Exception ee)
                {
                    exportMsg = ee.Message;
                }
                finally
                {
                    pgs[i].GoodsTask.Comment = exportMsg;
                    ServiceContainer.GetService <GoodsTaskService>().Save(pgs[i].GoodsTask);
                    this.Dispatcher.BeginInvoke(new Action(() => pgs[index].State = exportMsg));
                }
            }
            this.goodsDownloadWorker = null;
            this.isStop = true;
            this.Dispatcher.BeginInvoke(new Action(() =>
            {
                this.task = null;
                this.SetUiMsg(this.btnExportToPdd, "导入完成", false, "停止", "导入");
                MessageBox.Show("导入完成");
            }));
        }
Exemplo n.º 4
0
        private void GoodsDownloadWorker_Download(object sender, GoodsDownloadWorkerEventArgs e)
        {
            Debug.WriteLine("GoodsDownloadWorker_Download");
            GoodsDownloadWorkerEventArgs le = e;

            this.Dispatcher.BeginInvoke(new Action(() =>
            {
                this.btnQuery.Content  = le.BtnQueryTitle;
                this.btnStop.IsEnabled = le.BtnStopEnabled;
                this.tbMsg.Text        = le.Msg;
                if (e.IsComppleted)
                {
                    for (int i = 0; i < this.popGoodsInfoViewModels.Count; i++)
                    {
                        var v = this.popGoodsInfoViewModels[i];
                        if (v.PopGoodsInfo.Skus.Any(o => string.IsNullOrWhiteSpace(o.Code)))
                        {
                            v.State = "有SKU库存编码为空";
                        }
                        if (this.popGoodsInfoViewModels.Any(obj => obj != v && obj.SkuCodesInfo.Equals(v.SkuCodesInfo, StringComparison.OrdinalIgnoreCase)))
                        {
                            v.State += "商品重复";
                        }
                    }
                    if (this.popGoodsInfoViewModels.Any(obj => string.IsNullOrWhiteSpace(obj.State) == false))
                    {
                        MessageBox.Show("下载完成,有商品库存编码为空或者商品重复");
                    }
                    else
                    {
                        MessageBox.Show("下载完成");
                    }
                    this.goodsDownloadWorker = null;
                }
            }));
        }