private void WriteLazada(string outputPath)
        {
            var results = new List <Item>();

            foreach (var topsell in _topSell)
            {
                var matched = MatchingHelper.MatchSku(topsell, _basePrice);

                var addedCost = MatchingHelper.Match(matched, _cost);

                results.Add(new Item()
                {
                    SKU           = matched.SKU,
                    Price         = matched.Price,
                    SalePrice     = matched.SalePrice,
                    SaleStartDate = matched.SaleStartDate,
                    SaleEndDate   = matched.SaleEndDate,
                    Name          = matched.Name,
                    Cost          = addedCost.Price,
                    Matched       = addedCost.Matched,
                });
            }

            using (FileStream stream = new FileStream(outputPath, FileMode.CreateNew, FileAccess.Write))
            {
                var workbook = new XSSFWorkbook();
                var sheet    = workbook.CreateSheet("sheet1");
                var row      = 0;

                var headerRow = sheet.CreateRow(row);
                headerRow.CreateCell(0).SetCellValue("SKU");
                headerRow.CreateCell(1).SetCellValue("Price");
                headerRow.CreateCell(2).SetCellValue("SalePrice");
                headerRow.CreateCell(3).SetCellValue("SaleStartDate");
                headerRow.CreateCell(4).SetCellValue("SaleEndDate");
                headerRow.CreateCell(5).SetCellValue("Name");
                headerRow.CreateCell(6).SetCellValue("Cost");
                headerRow.CreateCell(7).SetCellValue("Matched");

                foreach (var result in results)
                {
                    var rowtemp = sheet.CreateRow(++row);
                    rowtemp.CreateCell(0).SetCellValue(result.SKU);
                    rowtemp.CreateCell(1).SetCellValue(result.Price.ToString(CultureInfo.InvariantCulture));
                    rowtemp.CreateCell(2).SetCellValue(result.SalePrice.ToString(CultureInfo.InvariantCulture));
                    rowtemp.CreateCell(3).SetCellValue(result.SaleStartDate);
                    rowtemp.CreateCell(4).SetCellValue(result.SaleEndDate);
                    rowtemp.CreateCell(5).SetCellValue(result.Name);
                    rowtemp.CreateCell(6).SetCellValue(result.Cost.ToString(CultureInfo.InvariantCulture));
                    rowtemp.CreateCell(7).SetCellValue(!result.Matched ? "NO" : string.Empty);
                }

                workbook.Write(stream);
            }
        }
        private void WriteShopee(string outputPath)
        {
            var results = new List <Item>();

            foreach (var tergetStock in _targetStock)
            {
                var matched = MatchingHelper.Match(tergetStock, _baseStock);

                var result = new Item()
                {
                    Name         = tergetStock.Name,
                    Model        = tergetStock.Model + " : " + tergetStock.Price,
                    MatchedModel = matched.Matched && !string.IsNullOrEmpty(matched.Model) ? matched.Model + " : " + matched.Price : string.Empty,
                    Price        = matched.Matched ? MatchingHelper.IsPriceSoDifferance(matched.Price, tergetStock.Price) ? tergetStock.Price : matched.Price : tergetStock.Price,
                    Matched      = matched.Matched,
                    MultiPrices  = matched.MultiPrices,
                    Description  = matched.Matched ? MatchingHelper.IsPriceSoDifferance(matched.Price, tergetStock.Price) ? "Price So Differance": string.Empty : string.Empty,
                };

                results.Add(result);
            }

            using (FileStream stream = new FileStream(outputPath, FileMode.CreateNew, FileAccess.Write))
            {
                var workbook = new XSSFWorkbook();
                var sheet    = workbook.CreateSheet("sheet1");
                var row      = 0;

                var headerRow = sheet.CreateRow(row);
                headerRow.CreateCell(0).SetCellValue("Name");
                headerRow.CreateCell(1).SetCellValue("Model");
                headerRow.CreateCell(2).SetCellValue("MatchedModel");
                headerRow.CreateCell(3).SetCellValue("Price");
                headerRow.CreateCell(4).SetCellValue("Matched");
                headerRow.CreateCell(5).SetCellValue("MultiPrices");
                headerRow.CreateCell(6).SetCellValue("Price So Differance");

                foreach (var result in results)
                {
                    var rowtemp = sheet.CreateRow(++row);
                    rowtemp.CreateCell(0).SetCellValue(result.Name);
                    rowtemp.CreateCell(1).SetCellValue(result.Model);
                    rowtemp.CreateCell(2).SetCellValue(result.MatchedModel);
                    rowtemp.CreateCell(3).SetCellValue(result.Price.ToString(CultureInfo.InvariantCulture));
                    rowtemp.CreateCell(4).SetCellValue(result.Matched);
                    rowtemp.CreateCell(5).SetCellValue(result.MultiPrices);
                    headerRow.CreateCell(6).SetCellValue(result.Description);
                }

                workbook.Write(stream);
            }
        }
        public void AddMore(OrdersModel order, List <SizeRunModel> sizeRunList, List <AssemblyReleaseModel> assemblyReleaseList,
                            List <SewingOutputModel> sewingOutputList, List <OutsoleOutputModel> outsoleOutputList)
        {
            if (order == null)
            {
                return;
            }

            StackPanel sp = new StackPanel();

            sp.Orientation = Orientation.Vertical;
            sp.Margin      = new Thickness(0, 10, 0, 0);

            Grid grid = new Grid();

            for (int i = 1; i <= 10; i++)
            {
                ColumnDefinition cd = new ColumnDefinition();
                cd.Width = new GridLength(1, GridUnitType.Auto);

                grid.ColumnDefinitions.Add(cd);
            }
            ColumnDefinition cd1 = new ColumnDefinition();

            cd1.Width = new GridLength(1, GridUnitType.Star);
            grid.ColumnDefinitions.Add(cd1);

            TextBlock lbl1 = new TextBlock();

            Grid.SetColumn(lbl1, 0);
            lbl1.Text = "PO No.:";
            lbl1.VerticalAlignment = VerticalAlignment.Bottom;


            TextBlock lbl1_1 = new TextBlock();

            Grid.SetColumn(lbl1_1, 1);
            lbl1_1.Margin            = new Thickness(5, 0, 0, 0);
            lbl1_1.MinWidth          = 33;
            lbl1_1.Text              = order.ProductNo;
            lbl1_1.FontWeight        = FontWeights.Bold;
            lbl1_1.VerticalAlignment = VerticalAlignment.Bottom;

            TextBlock lbl2 = new TextBlock();

            Grid.SetColumn(lbl2, 2);
            lbl2.Margin            = new Thickness(10, 0, 0, 0);
            lbl2.Text              = "Style:";
            lbl2.VerticalAlignment = VerticalAlignment.Bottom;

            TextBlock lbl3 = new TextBlock();

            Grid.SetColumn(lbl3, 3);
            lbl3.Margin            = new Thickness(5, 0, 0, 0);
            lbl3.MinWidth          = 33;
            lbl3.Text              = order.ShoeName;
            lbl3.FontWeight        = FontWeights.Bold;
            lbl3.VerticalAlignment = VerticalAlignment.Bottom;

            TextBlock lbl4 = new TextBlock();

            Grid.SetColumn(lbl4, 4);
            lbl4.Margin            = new Thickness(10, 0, 0, 0);
            lbl4.Text              = "Article No.:";
            lbl4.VerticalAlignment = VerticalAlignment.Bottom;


            TextBlock lbl5 = new TextBlock();

            Grid.SetColumn(lbl5, 5);
            lbl5.Margin            = new Thickness(5, 0, 0, 0);
            lbl5.MinWidth          = 33;
            lbl5.Text              = order.ArticleNo;
            lbl5.FontWeight        = FontWeights.Bold;
            lbl5.VerticalAlignment = VerticalAlignment.Bottom;

            TextBlock lbl5_1 = new TextBlock();

            Grid.SetColumn(lbl5_1, 6);
            lbl5_1.Margin            = new Thickness(10, 0, 0, 0);
            lbl5_1.Text              = "Last Code:";
            lbl5_1.VerticalAlignment = VerticalAlignment.Bottom;


            TextBlock lbl5_2 = new TextBlock();

            Grid.SetColumn(lbl5_2, 7);
            lbl5_2.Margin            = new Thickness(5, 0, 0, 0);
            lbl5_2.MinWidth          = 33;
            lbl5_2.Text              = order.LastCode;
            lbl5_2.FontWeight        = FontWeights.Bold;
            lbl5_2.VerticalAlignment = VerticalAlignment.Bottom;

            TextBlock lbl6 = new TextBlock();

            Grid.SetColumn(lbl6, 8);
            lbl6.Margin            = new Thickness(10, 0, 0, 0);
            lbl6.Text              = "Released Qty:";
            lbl6.VerticalAlignment = VerticalAlignment.Bottom;

            int qtyReleasedTotal = assemblyReleaseList.Where(a => a.ReportId != reportId).Sum(o => o.Quantity);

            TextBlock lbl7 = new TextBlock();

            Grid.SetColumn(lbl7, 9);
            lbl7.Margin            = new Thickness(5, 0, 0, 0);
            lbl7.MinWidth          = 33;
            lbl7.Text              = String.Format("{0}/{1}", qtyReleasedTotal, order.Quantity);
            lbl7.FontWeight        = FontWeights.Bold;
            lbl7.VerticalAlignment = VerticalAlignment.Bottom;

            Button btnRemove = new Button();

            Grid.SetColumn(btnRemove, 10);
            btnRemove.Content             = " X ";
            btnRemove.HorizontalAlignment = HorizontalAlignment.Right;
            btnRemove.Tag       = order.ProductNo;
            btnRemove.IsEnabled = false;
            if (account.AssemblyMaster == true)
            {
                btnRemove.IsEnabled = true;
            }
            btnRemove.Click += new RoutedEventHandler(btnRemove_Click);

            grid.Children.Add(lbl1);
            grid.Children.Add(lbl1_1);
            grid.Children.Add(lbl2);
            grid.Children.Add(lbl3);
            grid.Children.Add(lbl4);
            grid.Children.Add(lbl5);
            grid.Children.Add(lbl5_1);
            grid.Children.Add(lbl5_2);
            grid.Children.Add(lbl6);
            grid.Children.Add(lbl7);
            grid.Children.Add(btnRemove);

            List <Object> tags = new List <Object>();

            tags.Add(order.ProductNo);
            tags.Add(qtyReleasedTotal);
            DataTable dt = new DataTable();
            DataGrid  dg = new DataGrid();

            Grid.SetColumn(dg, 0);
            Grid.SetColumnSpan(dg, 6);
            Grid.SetRow(dg, 1);
            dg.Margin              = new Thickness(0, 5, 0, 0);
            dg.SelectionUnit       = DataGridSelectionUnit.CellOrRowHeader;
            dg.AutoGenerateColumns = false;
            dg.CanUserDeleteRows   = false;
            dg.Tag             = tags;
            dg.CellEditEnding += new EventHandler <DataGridCellEditEndingEventArgs>(dg_CellEditEnding);

            dt.Columns.Add("Cycle", typeof(Int32));
            DataGridTextColumn column1 = new DataGridTextColumn();

            column1.Header   = String.Format("{0}\n{1}\n{2}\n{3}\n{4}\n\n{5}", "Size", "Quantity", "Upper In", "Outsole In", "Current Matching", "Cycle");
            column1.MinWidth = 100;
            column1.Binding  = new Binding(String.Format("Cycle"));
            dg.Columns.Add(column1);
            int qtyTotal          = 0;
            int qtyUpperInTotal   = 0;
            int qtyOutsoleInTotal = 0;
            int qtyMatchTotal     = 0;

            for (int i = 0; i <= sizeRunList.Count - 1; i++)
            {
                dt.Columns.Add(String.Format("Column{0}", i), typeof(Int32));
                SizeRunModel sizeRun = sizeRunList[i];

                int qtyMatch = 0;
                //if (sewingOutputList.Where(o => o.SizeNo == sizeRun.SizeNo).Count() >= 1)
                //{
                int qtyUpperIn   = sewingOutputList.Where(o => o.SizeNo == sizeRun.SizeNo).Sum(o => o.Quantity);
                int qtyOutsoleIn = outsoleOutputList.Where(o => o.SizeNo == sizeRun.SizeNo).Sum(o => o.Quantity);
                int qtyReleased  = assemblyReleaseList.Where(o => o.SizeNo == sizeRun.SizeNo && o.ReportId != reportId).Sum(o => o.Quantity);
                qtyMatch = MatchingHelper.Calculate(qtyUpperIn, qtyOutsoleIn, sizeRun.SizeNo) - qtyReleased;
                if (qtyMatch < 0)
                {
                    qtyMatch = 0;
                }
                qtyTotal          += sizeRun.Quantity;
                qtyUpperInTotal   += qtyUpperIn;
                qtyOutsoleInTotal += qtyOutsoleIn;
                qtyMatchTotal     += qtyMatch;
                //}

                DataGridTextColumn column = new DataGridTextColumn();
                column.SetValue(TagProperty, new Int32[] { i, qtyMatch });
                column.Header   = String.Format("{0}\n({1})\n({2})\n({3})\n({4})\n\n{5}", sizeRun.SizeNo, sizeRun.Quantity, qtyUpperIn, qtyOutsoleIn, qtyMatch, "");
                column.MinWidth = 40;
                Binding binding = new Binding();
                binding.Path = new PropertyPath(String.Format("Column{0}", i));
                binding.UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged;
                column.Binding = binding;
                dg.Columns.Add(column);
            }

            dt.Columns.Add("Total", typeof(Int32));
            DataGridTextColumn column2 = new DataGridTextColumn();

            //column2.Header = String.Format("{0}\n({1})", "Total Qty", qtyMatchTotal);
            column2.Header     = String.Format("{0}\n({1})\n({2})\n({3})\n({4})\n\n{5}", "Total Qty", qtyTotal, qtyUpperInTotal, qtyOutsoleInTotal, qtyMatchTotal, "");
            column2.MinWidth   = 80;
            column2.Binding    = new Binding(String.Format("Total"));
            column2.FontWeight = FontWeights.Bold;
            column2.IsReadOnly = true;
            dg.Columns.Add(column2);

            List <Int32> cycleList = assemblyReleaseList.Where(o => o.ReportId == reportId).Select(o => o.Cycle).Distinct().OrderBy(o => o).ToList();

            foreach (int cycle in cycleList)
            {
                DataRow dr1 = dt.NewRow();
                dr1["Cycle"] = cycle.ToString();
                int qtyReleaseTotal = 0;
                for (int i = 0; i <= sizeRunList.Count - 1; i++)
                {
                    SizeRunModel sizeRun    = sizeRunList[i];
                    int          qtyRelease = assemblyReleaseList.Where(o => o.Cycle == cycle && o.SizeNo == sizeRun.SizeNo && o.ReportId == reportId).Sum(o => o.Quantity);
                    qtyReleaseTotal += qtyRelease;
                    dr1[String.Format("Column{0}", i)] = qtyRelease;
                }
                dr1["Total"] = qtyReleaseTotal;
                dt.Rows.Add(dr1);
            }

            dg.ItemsSource = dt.AsDataView();

            sp.Children.Add(grid);
            sp.Children.Add(dg);

            spMain.Children.Add(sp);

            svMain.ScrollToBottom();
        }
        private void bwLoad_DoWork(object sender, DoWorkEventArgs e)
        {
            List <UpperWHInventoryDetailViewModel> upperWHInventoryDetailViewList = new List <UpperWHInventoryDetailViewModel>();
            DataTable dt = new UpperWHInventoryDataSet().Tables["UpperWHInventoryTable"];

            foreach (string productNo in productNoList)
            {
                DataRow dr = dt.NewRow();
                UpperWHInventoryDetailViewModel upperWHInventoryDetailView = new UpperWHInventoryDetailViewModel();
                dr["ProductNo"] = productNo;
                upperWHInventoryDetailView.ProductNo = productNo;
                OrdersModel order = orderList.Where(o => o.ProductNo == productNo).FirstOrDefault();
                if (order != null)
                {
                    upperWHInventoryDetailView.ShoeName  = order.ShoeName;
                    upperWHInventoryDetailView.ArticleNo = order.ArticleNo;
                    upperWHInventoryDetailView.ETD       = order.ETD;
                }
                int qtyUpperTotal   = 0;
                int qtyOutsoleTotal = 0;
                int qtyMatchTotal   = 0;
                int qtyQuantity     = order.Quantity;
                int qtyReleaseTotal = 0;
                List <AssemblyReleaseModel> assemblyReleaseList_D1 = assemblyReleaseList.Where(a => a.ProductNo == productNo).ToList();
                List <SewingOutputModel>    sewingOutputList_D1    = sewingOutputList.Where(s => s.ProductNo == productNo).ToList();
                List <OutsoleOutputModel>   outsoleOutputList_D1   = outsoleOutputList.Where(o => o.ProductNo == productNo).ToList();

                List <String> sizeNoList = sewingOutputList_D1.Select(s => s.SizeNo).Distinct().ToList();
                if (sizeNoList.Count == 0)
                {
                    sizeNoList = outsoleOutputList_D1.Select(o => o.SizeNo).Distinct().ToList();
                }
                foreach (string sizeNo in sizeNoList)
                {
                    int qtyRelease = assemblyReleaseList_D1.Where(a => a.SizeNo == sizeNo).Sum(a => a.Quantity);
                    int qtyUpper   = sewingOutputList_D1.Where(s => s.SizeNo == sizeNo).Sum(s => s.Quantity)
                                     - qtyRelease;
                    int qtyOutsole = outsoleOutputList_D1.Where(o => o.SizeNo == sizeNo).Sum(o => o.Quantity)
                                     - qtyRelease;
                    int qtyMatch =
                        MatchingHelper.Calculate(sewingOutputList_D1.Where(s => s.SizeNo == sizeNo).Sum(s => s.Quantity),
                                                 outsoleOutputList_D1.Where(o => o.SizeNo == sizeNo).Sum(o => o.Quantity), sizeNo)
                        - qtyRelease;
                    if (qtyUpper < 0)
                    {
                        qtyUpper = 0;
                    }
                    qtyUpperTotal += qtyUpper;
                    if (qtyOutsole < 0)
                    {
                        qtyOutsole = 0;
                    }
                    qtyOutsoleTotal += qtyOutsole;
                    if (qtyMatch < 0)
                    {
                        qtyMatch = 0;
                    }
                    qtyMatchTotal += qtyMatch;
                    if (qtyRelease < 0)
                    {
                        qtyRelease = 0;
                    }
                    qtyReleaseTotal += qtyRelease;
                }
                upperWHInventoryDetailView.Quantity        = qtyQuantity;
                upperWHInventoryDetailView.ReleaseQuantity = qtyReleaseTotal;
                upperWHInventoryDetailView.SewingOutput    = qtyUpperTotal;
                upperWHInventoryDetailView.OutsoleOutput   = qtyOutsoleTotal;
                upperWHInventoryDetailView.Matching        = qtyMatchTotal;
                dr["Quantity"]        = qtyQuantity;
                dr["ReleaseQuantity"] = qtyReleaseTotal;
                dr["SewingOutput"]    = qtyUpperTotal;
                dr["OutsoleOutput"]   = qtyOutsoleTotal;
                dr["Matching"]        = qtyMatchTotal;
                if (upperWHInventoryDetailView.SewingOutput != 0 || upperWHInventoryDetailView.OutsoleOutput != 0)
                {
                    upperWHInventoryDetailViewList.Add(upperWHInventoryDetailView);
                }
                dt.Rows.Add(dr);
            }
            e.Result = dt;
        }
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            List<UpperWHInventoryDetailViewModel> upperWHInventoryDetailViewList = new List<UpperWHInventoryDetailViewModel>();
            foreach (string productNo in productNoList)
            {
                UpperWHInventoryDetailViewModel upperWHInventoryDetailView = new UpperWHInventoryDetailViewModel();
                upperWHInventoryDetailView.ProductNo = productNo;
                OrdersModel order = orderList.Where(o => o.ProductNo == productNo).FirstOrDefault();
                if (order != null)
                {
                    upperWHInventoryDetailView.ShoeName = order.ShoeName;
                    upperWHInventoryDetailView.ArticleNo = order.ArticleNo;
                    upperWHInventoryDetailView.ETD = order.ETD;
                }
                int qtyUpperTotal = 0;
                int qtyOutsoleTotal = 0;
                int qtyMatchTotal = 0;
                int qtyQuantity = order.Quantity;
                int qtyReleaseTotal = 0;
                List<AssemblyReleaseModel> assemblyReleaseList_D1 = assemblyReleaseList.Where(a => a.ProductNo == productNo).ToList();
                List<SewingOutputModel> sewingOutputList_D1 = sewingOutputList.Where(s => s.ProductNo == productNo).ToList();
                List<OutsoleOutputModel> outsoleOutputList_D1 = outsoleOutputList.Where(o => o.ProductNo == productNo).ToList();

                List<String> sizeNoList = sewingOutputList_D1.Select(s => s.SizeNo).Distinct().ToList();
                if (sizeNoList.Count == 0)
                {
                    sizeNoList = outsoleOutputList_D1.Select(o => o.SizeNo).Distinct().ToList();
                }
                foreach (string sizeNo in sizeNoList)
                {
                    int qtyRelease = assemblyReleaseList_D1.Where(a => a.SizeNo == sizeNo).Sum(a => a.Quantity);
                    int qtyUpper = sewingOutputList_D1.Where(s => s.SizeNo == sizeNo).Sum(s => s.Quantity)
                        - qtyRelease;
                    int qtyOutsole = outsoleOutputList_D1.Where(o => o.SizeNo == sizeNo).Sum(o => o.Quantity)
                        - qtyRelease;
                    int qtyMatch =
                        MatchingHelper.Calculate(sewingOutputList_D1.Where(s => s.SizeNo == sizeNo).Sum(s => s.Quantity),
                        outsoleOutputList_D1.Where(o => o.SizeNo == sizeNo).Sum(o => o.Quantity), sizeNo)
                        - qtyRelease;
                    if (qtyUpper < 0)
                    {
                        qtyUpper = 0;
                    }
                    qtyUpperTotal += qtyUpper;
                    if (qtyOutsole < 0)
                    {
                        qtyOutsole = 0;
                    }
                    qtyOutsoleTotal += qtyOutsole;
                    if (qtyMatch < 0)
                    {
                        qtyMatch = 0;
                    }
                    qtyMatchTotal += qtyMatch;
                    if (qtyRelease < 0)
                    {
                        qtyRelease = 0;
                    }
                    qtyReleaseTotal += qtyRelease;
                }
                upperWHInventoryDetailView.Quantity = qtyQuantity;
                upperWHInventoryDetailView.ReleaseQuantity = qtyReleaseTotal;
                upperWHInventoryDetailView.SewingOutput = qtyUpperTotal;
                upperWHInventoryDetailView.OutsoleOutput = qtyOutsoleTotal;
                upperWHInventoryDetailView.Matching = qtyMatchTotal;
                if (upperWHInventoryDetailView.SewingOutput != 0 || upperWHInventoryDetailView.OutsoleOutput != 0)
                {
                    upperWHInventoryDetailViewList.Add(upperWHInventoryDetailView);
                }
            }

            dgInventory.ItemsSource = upperWHInventoryDetailViewList;
            lblQuantityTotal.Text = upperWHInventoryDetailViewList.Sum(u => u.Quantity).ToString();
            lblReleaseQuantityTotal.Text = upperWHInventoryDetailViewList.Sum(u => u.ReleaseQuantity).ToString();
            lblSewingOutput.Text = upperWHInventoryDetailViewList.Sum(u => u.SewingOutput).ToString();
            lblOutsoleOutput.Text = upperWHInventoryDetailViewList.Sum(u => u.OutsoleOutput).ToString();
            lblMatching.Text = upperWHInventoryDetailViewList.Sum(u => u.Matching).ToString();
        }
Exemple #6
0
 public BaseRepository()
 {
     _matchingHelper = new MatchingHelper();
     _bulkRequest    = new BulkRequest(100);
 }
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            DataTable dt = new UpperWHInventoryDetailDataSet().Tables["UpperWHInventoryDetailTable"];

            assemblyMasterList  = AssemblyMasterController.Select();
            sewingOutputList    = SewingOutputController.SelectByAssemblyMaster();
            outsoleOutputList   = OutsoleOutputController.SelectByAssemblyMaster();
            assemblyReleaseList = AssemblyReleaseController.SelectByAssemblyMaster();
            orderList           = OrdersController.SelectByAssemblyMaster();

            List <UpperWHInventoryViewModel> upperWHInventoryViewList = new List <UpperWHInventoryViewModel>();

            assemblyLineList = assemblyMasterList.Where(a => String.IsNullOrEmpty(a.AssemblyLine) == false).Select(a => a.AssemblyLine).Distinct().OrderBy(l => l).ToList();

            // Total value
            //int upperTotal = 0;
            //int outsoleTotal = 0;
            //int matchingTotal = 0;
            // Sum value
            int upperSum, outsoleSum, matchingSum;

            foreach (string assemblyLine in assemblyLineList)
            {
                List <String> productNoList = assemblyMasterList.Where(a => a.AssemblyLine == assemblyLine).Select(o => o.ProductNo).OrderBy(l => l).Distinct().ToList();
                List <UpperWHInventoryDetailViewModel> upperWHInventoryDetailViewList = new List <UpperWHInventoryDetailViewModel>();
                foreach (string productNo in productNoList)
                {
                    UpperWHInventoryDetailViewModel upperWHInventoryDetailView = new UpperWHInventoryDetailViewModel();
                    OrdersModel order = orderList.Where(o => o.ProductNo == productNo).FirstOrDefault();
                    if (order != null)
                    {
                        upperWHInventoryDetailView.ProductNo = productNo;
                        upperWHInventoryDetailView.ShoeName  = order.ShoeName;
                        upperWHInventoryDetailView.ArticleNo = order.ArticleNo;
                    }
                    int qtyUpperTotal   = 0;
                    int qtyOutsoleTotal = 0;
                    int qtyMatchTotal   = 0;
                    int qtyQuantity     = order.Quantity;
                    int qtyReleaseTotal = 0;
                    List <AssemblyReleaseModel> assemblyReleaseList_D1 = assemblyReleaseList.Where(a => a.ProductNo == productNo).ToList();
                    List <SewingOutputModel>    sewingOutputList_D1    = sewingOutputList.Where(s => s.ProductNo == productNo).ToList();
                    List <OutsoleOutputModel>   outsoleOutputList_D1   = outsoleOutputList.Where(o => o.ProductNo == productNo).ToList();

                    List <String> sizeNoList = sewingOutputList_D1.Select(s => s.SizeNo).Distinct().ToList();
                    if (sizeNoList.Count == 0)
                    {
                        sizeNoList = outsoleOutputList_D1.Select(o => o.SizeNo).Distinct().ToList();
                    }
                    foreach (string sizeNo in sizeNoList)
                    {
                        int qtyRelease = assemblyReleaseList_D1.Where(a => a.SizeNo == sizeNo).Sum(a => a.Quantity);
                        int qtyUpper   = sewingOutputList_D1.Where(s => s.SizeNo == sizeNo).Sum(s => s.Quantity)
                                         - qtyRelease;
                        int qtyOutsole = outsoleOutputList_D1.Where(o => o.SizeNo == sizeNo).Sum(o => o.Quantity)
                                         - qtyRelease;
                        int qtyMatch =
                            MatchingHelper.Calculate(sewingOutputList_D1.Where(s => s.SizeNo == sizeNo).Sum(s => s.Quantity),
                                                     outsoleOutputList_D1.Where(o => o.SizeNo == sizeNo).Sum(o => o.Quantity), sizeNo)
                            - qtyRelease;
                        if (qtyUpper < 0)
                        {
                            qtyUpper = 0;
                        }
                        qtyUpperTotal += qtyUpper;
                        if (qtyOutsole < 0)
                        {
                            qtyOutsole = 0;
                        }
                        qtyOutsoleTotal += qtyOutsole;
                        if (qtyMatch < 0)
                        {
                            qtyMatch = 0;
                        }
                        qtyMatchTotal += qtyMatch;
                        if (qtyRelease < 0)
                        {
                            qtyRelease = 0;
                        }
                        qtyReleaseTotal += qtyRelease;
                    }
                    upperWHInventoryDetailView.Quantity        = qtyQuantity;
                    upperWHInventoryDetailView.ReleaseQuantity = qtyReleaseTotal;
                    upperWHInventoryDetailView.SewingOutput    = qtyUpperTotal;
                    upperWHInventoryDetailView.OutsoleOutput   = qtyOutsoleTotal;
                    upperWHInventoryDetailView.Matching        = qtyMatchTotal;

                    //UpperWHInventoryViewModel upperWHInventoryView = new UpperWHInventoryViewModel
                    //{
                    //    AssemblyLine = assemblyLine,
                    //    ProductNoList = productNoList,
                    //    SewingOutput = qtyUpperTotal,
                    //    OutsoleOutput = qtyOutsoleTotal,
                    //    Matching = qtyMatchTotal,
                    //};
                    //upperWHInventoryViewList.Add(upperWHInventoryView);


                    if (upperWHInventoryDetailView.SewingOutput != 0 || upperWHInventoryDetailView.OutsoleOutput != 0)
                    {
                        upperWHInventoryDetailViewList.Add(upperWHInventoryDetailView);
                    }
                }

                Int32.TryParse(upperWHInventoryDetailViewList.Sum(o => o.SewingOutput).ToString(), out upperSum);
                Int32.TryParse(upperWHInventoryDetailViewList.Sum(o => o.OutsoleOutput).ToString(), out outsoleSum);
                Int32.TryParse(upperWHInventoryDetailViewList.Sum(o => o.Matching).ToString(), out matchingSum);

                //List<int> upperSumList = upperWHInventoryDetailViewList.Where(o => o.SewingOutput != 0).Select(p => p.SewingOutput).ToList();
                //List<int> ousoleSumList = upperWHInventoryDetailViewList.Where(o => o.OutsoleOutput != 0).Select(p => p.OutsoleOutput).ToList();
                //List<int> matchingSumList = upperWHInventoryDetailViewList.Where(o => o.Matching != 0).Select(p => p.Matching).ToList();

                foreach (UpperWHInventoryDetailViewModel print in upperWHInventoryDetailViewList)
                {
                    DataRow dr = dt.NewRow();
                    dr["ProductNo"]    = print.ProductNo;
                    dr["ShoeName"]     = print.ShoeName;
                    dr["ArticleNo"]    = print.ArticleNo;
                    dr["AssemblyLine"] = assemblyLine;
                    //dr["AssemblyLineSum"] = assemblyLine;
                    dr["Quantity"] = print.Quantity;
                    dr["Release"]  = print.ReleaseQuantity;
                    dr["Upper"]    = print.SewingOutput;
                    dr["OutSole"]  = print.OutsoleOutput;
                    dr["Matching"] = print.Matching;

                    //dr["UpperSum"] = upperWHInventoryDetailViewList.Sum(o => o.SewingOutput).ToString();
                    //dr["OutSoleSum"] = upperWHInventoryDetailViewList.Sum(o => o.OutsoleOutput).ToString();
                    //dr["MatchingSum"] = upperWHInventoryDetailViewList.Sum(o => o.Matching).ToString();
                    dr["UpperSum"]    = upperSum;
                    dr["OutSoleSum"]  = outsoleSum;
                    dr["MatchingSum"] = matchingSum;

                    dt.Rows.Add(dr);
                }
            }


            ReportDataSource rds = new ReportDataSource();

            rds.Name = "UpperWHInventoryDetail_DataSetV9";
            //rds.Name = "UpperWHInventoryDetailFinal";
            rds.Value = dt;
            //reportViewer.LocalReport.ReportPath = @"C:\Users\IT02\Documents\Visual Studio 2010\Projects\Saoviet Master Schedule Solution\MasterSchedule\Reports\DelayReport.rdlc";
            reportViewer.LocalReport.ReportPath = @"Reports\UpperWHInventoryDetailReport.rdlc";
            //reportViewer.LocalReport.ReportPath = @"Reports\UpperWHInventoryDetailReportV11.rdlc";
            reportViewer.LocalReport.DataSources.Add(rds);
            reportViewer.RefreshReport();
            this.Cursor = null;
        }
Exemple #8
0
        private void bwLoadData_DoWork(object sender, DoWorkEventArgs e)
        {
            assemblyMasterList  = AssemblyMasterController.Select();
            sewingOutputList    = SewingOutputController.SelectByAssemblyMaster();
            outsoleOutputList   = OutsoleOutputController.SelectByAssemblyMaster();
            assemblyReleaseList = AssemblyReleaseController.SelectByAssemblyMaster();
            orderList           = OrdersController.SelectByAssemblyMaster();

            List <UpperWHInventoryViewModel> upperWHInventoryViewList = new List <UpperWHInventoryViewModel>();

            assemblyLineList = assemblyMasterList.Where(a => String.IsNullOrEmpty(a.AssemblyLine) == false).Select(a => a.AssemblyLine).Distinct().OrderBy(l => l).ToList();
            foreach (string assemblyLine in assemblyLineList)
            {
                List <String> productNoList = assemblyMasterList.Where(a => a.AssemblyLine == assemblyLine).Select(o => o.ProductNo).Distinct().ToList();

                List <AssemblyReleaseModel> assemblyReleaseList_D1 = assemblyReleaseList.Where(a => productNoList.Contains(a.ProductNo) == true).ToList();
                List <SewingOutputModel>    sewingOutputList_D1    = sewingOutputList.Where(s => productNoList.Contains(s.ProductNo) == true).ToList();
                List <OutsoleOutputModel>   outsoleOutputList_D1   = outsoleOutputList.Where(o => productNoList.Contains(o.ProductNo) == true).ToList();

                int qtyUpperTotal   = 0;
                int qtyOutsoleTotal = 0;
                int qtyMatchTotal   = 0;
                foreach (string productNo in productNoList)
                {
                    List <AssemblyReleaseModel> assemblyReleaseList_D2 = assemblyReleaseList_D1.Where(a => a.ProductNo == productNo).ToList();
                    List <SewingOutputModel>    sewingOutputList_D2    = sewingOutputList_D1.Where(s => s.ProductNo == productNo).ToList();
                    List <OutsoleOutputModel>   outsoleOutputList_D2   = outsoleOutputList_D1.Where(o => o.ProductNo == productNo).ToList();

                    List <String> sizeNoList = sewingOutputList_D2.Select(s => s.SizeNo).Distinct().ToList();
                    if (sizeNoList.Count == 0)
                    {
                        sizeNoList = outsoleOutputList_D2.Select(o => o.SizeNo).Distinct().ToList();
                    }
                    foreach (string sizeNo in sizeNoList)
                    {
                        int qtyRelease = assemblyReleaseList_D2.Where(a => a.SizeNo == sizeNo).Sum(a => a.Quantity);
                        int qtyUpper   = sewingOutputList_D2.Where(s => s.SizeNo == sizeNo).Sum(s => s.Quantity)
                                         - qtyRelease;
                        int qtyOutsole = outsoleOutputList_D2.Where(o => o.SizeNo == sizeNo).Sum(o => o.Quantity)
                                         - qtyRelease;
                        int qtyMatch =
                            MatchingHelper.Calculate(sewingOutputList_D2.Where(s => s.SizeNo == sizeNo).Sum(s => s.Quantity),
                                                     outsoleOutputList_D2.Where(o => o.SizeNo == sizeNo).Sum(o => o.Quantity), sizeNo)
                            - qtyRelease;
                        if (qtyUpper < 0)
                        {
                            qtyUpper = 0;
                        }
                        qtyUpperTotal += qtyUpper;
                        if (qtyOutsole < 0)
                        {
                            qtyOutsole = 0;
                        }
                        qtyOutsoleTotal += qtyOutsole;
                        if (qtyMatch < 0)
                        {
                            qtyMatch = 0;
                        }
                        qtyMatchTotal += qtyMatch;
                    }
                }
                UpperWHInventoryViewModel upperWHInventoryView = new UpperWHInventoryViewModel
                {
                    AssemblyLine  = assemblyLine,
                    ProductNoList = productNoList,
                    SewingOutput  = qtyUpperTotal,
                    OutsoleOutput = qtyOutsoleTotal,
                    Matching      = qtyMatchTotal,
                };

                upperWHInventoryViewList.Add(upperWHInventoryView);
            }

            e.Result = upperWHInventoryViewList;
        }