示例#1
0
        private void bwSearchOutsoleCode_DoWork(object sender, DoWorkEventArgs e)
        {
            orderList = OrdersController.Select();
            sizeRunPerOutsoleCodeList = SizeRunController.SelectPerOutsoleCode(outsoleCode).Where(w => w.UpdateOutsoleSizeByArticle == false).ToList();
            var outsoleCodeList = orderList.Select(s => s.OutsoleCode).Distinct().ToList();

            Dispatcher.Invoke(new Action(() =>
            {
                dgSizeMap.Columns.Clear();
                if (outsoleCodeList.Contains(outsoleCode) == false)
                {
                    MessageBox.Show("Not Found !", this.Title, MessageBoxButton.OK, MessageBoxImage.Information);
                    txtOutsoleCode.SelectAll();
                    txtOutsoleCode.Focus();
                    return;
                }
                FillDataSearch(dtSizeMap, dgSizeMap, sizeRunPerOutsoleCodeList);
            }));
        }
        private void bwImport_DoWork(object sender, DoWorkEventArgs e)
        {
            // Insert SizeRun
            int i = 1;

            progressBar.Dispatcher.Invoke((Action)(() => progressBar.Maximum = sizeRunToImportList.Count));
            foreach (SizeRunModel sizeRun in sizeRunToImportList)
            {
                SizeRunController.Insert(sizeRun);
                dgSizeRun.Dispatcher.Invoke((Action)(() =>
                {
                    dgSizeRun.SelectedItem = sizeRun;
                    dgSizeRun.ScrollIntoView(sizeRun);
                }));
                Dispatcher.Invoke(new Action(() =>
                {
                    lblStatus.Text    = "Importing SizeRun ...";
                    progressBar.Value = i;
                }));
                i++;
            }

            // Update OutsoleSize, MidSoleSize
            var productNoList = sizeRunToImportList.Select(s => s.ProductNo).Distinct().ToList();
            var orderList     = OrdersController.Select();
            int indexPO       = 1;

            progressBar.Dispatcher.Invoke((Action)(() => progressBar.Value = 0));
            progressBar.Dispatcher.Invoke((Action)(() => progressBar.Maximum = productNoList.Count));
            foreach (var productNo in productNoList)
            {
                var orderPerPOModel = orderList.FirstOrDefault(f => f.ProductNo == productNo);
                if (orderPerPOModel == null)
                {
                    continue;
                }
                string outsoleCode = orderPerPOModel.OutsoleCode;
                string articleNo   = orderPerPOModel.ArticleNo.Contains("-") ? orderPerPOModel.ArticleNo.Split('-')[0].ToString() : orderPerPOModel.ArticleNo;

                var sizeRunPerArticleList     = SizeRunController.SelectPerArticle(articleNo).Where(w => w.UpdateOutsoleSizeByArticle == true).ToList();
                var sizeRunPerOutsoleCodeList = SizeRunController.SelectPerOutsoleCode(outsoleCode).Where(w => w.UpdateOutsoleSizeByArticle == false).ToList();

                if (sizeRunPerOutsoleCodeList.Count == 0 && sizeRunPerArticleList.Count == 0)
                {
                    continue;
                }

                var sizeRunUpdateSizeMapList = sizeRunToImportList.Where(w => w.ProductNo == productNo).ToList();

                foreach (var sizeRun in sizeRunUpdateSizeMapList)
                {
                    string outsoleSize = "", midsoleSize = "";

                    var sizeRunInOutsoleCode = sizeRunPerOutsoleCodeList.FirstOrDefault(f => f.SizeNo == sizeRun.SizeNo);
                    if (sizeRunPerArticleList.Count > 0)
                    {
                        sizeRunInOutsoleCode = sizeRunPerArticleList.FirstOrDefault(f => f.SizeNo == sizeRun.SizeNo);
                    }

                    if (sizeRunInOutsoleCode == null)
                    {
                        continue;
                    }
                    outsoleSize = sizeRunInOutsoleCode.OutsoleSize;
                    midsoleSize = sizeRunInOutsoleCode.MidsoleSize;

                    if (String.IsNullOrEmpty(outsoleSize) == true && String.IsNullOrEmpty(midsoleSize) == true)
                    {
                        continue;
                    }

                    sizeRun.OutsoleSize = outsoleSize;
                    sizeRun.MidsoleSize = midsoleSize;
                    sizeRun.UpdateOutsoleSizeByArticle = sizeRunPerArticleList.Count > 0 ? true : false;

                    SizeRunController.UpdateSizeMap(sizeRun);
                }
                Dispatcher.Invoke(new Action(() =>
                {
                    lblStatus.Text    = "Updating OutsoleSize, MidsoleSize ...";
                    progressBar.Value = indexPO;
                }));
                indexPO++;
            }
        }