private void btnCompleted_Click(object sender, RoutedEventArgs e)
        {
            DataRow dr = ((DataRowView)dgInsockMaterial.CurrentItem).Row;

            if (dr == null)
            {
                return;
            }
            InsockSuppliersModel insockSupplier = dr["Supplier"] as InsockSuppliersModel;

            if (insockSupplier == null)
            {
                return;
            }
            if (insockSupplier.InsockSupplierName != "Reject")
            {
                dr["ActualDate"] = String.Format(new CultureInfo("en-US"), "{0:M/dd}", DateTime.Now);
            }
            for (int i = 0; i <= sizeRunList.Count - 1; i++)
            {
                SizeRunModel sizeRun = sizeRunList[i];
                dr[String.Format("Column{0}", i)] = sizeRun.Quantity;
            }
            dgInsockMaterial.ItemsSource = null;
            dgInsockMaterial.ItemsSource = dt.AsDataView();
        }
Esempio n. 2
0
        private void btnOK_Click(object sender, RoutedEventArgs e)
        {
            if (dgOutsoleWHFG.CurrentItem == null)
            {
                return;
            }
            DataRow dr = ((DataRowView)dgOutsoleWHFG.CurrentItem).Row;

            if (dr == null)
            {
                return;
            }
            if (dr["Status"].ToString().Contains("Balance"))
            {
                return;
            }
            for (int i = 0; i <= sizeRunList.Count - 1; i++)
            {
                SizeRunModel sizeRun = sizeRunList[i];
                dr[String.Format("Column{0}", i)] = sizeRun.Quantity;
            }
            dr["Total"] = sizeRunList.Select(s => s.Quantity).Sum();
            dgOutsoleWHFG.ItemsSource = null;
            dgOutsoleWHFG.ItemsSource = dt.AsDataView();
        }
Esempio n. 3
0
        private void bwLoadData_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            //dt.Columns.Clear();
            for (int i = 0; i <= sizeRunList.Count - 1; i++)
            {
                SizeRunModel sizeRun = sizeRunList[i];
                dt.Columns.Add(String.Format("Column{0}", i), typeof(Int32));
                DataGridTextColumn column = new DataGridTextColumn();
                column.SetValue(TagProperty, sizeRun.SizeNo);
                column.Header   = String.Format("{0}\n({1})", sizeRun.SizeNo, sizeRun.Quantity);
                column.MinWidth = 40;
                column.Binding  = new Binding(String.Format("Column{0}", i));
                dgOutsoleMaterial.Columns.Add(column);
            }
            colCompleted.DisplayIndex = dgOutsoleMaterial.Columns.Count - 1;

            DataRow dr = dt.NewRow();

            for (int j = 0; j <= sizeRunList.Count - 1; j++)
            {
                SizeRunModel sizeRun = sizeRunList[j];
                dr[String.Format("Column{0}", j)] = outsoleOutputList.Where(o => o.SizeNo == sizeRun.SizeNo).Sum(o => o.Quantity);
            }
            dt.Rows.Add(dr);

            dgOutsoleMaterial.ItemsSource = dt.AsDataView();

            lblQtyTotal.Text = outsoleOutputList.Sum(s => s.Quantity).ToString();
            lblQtyOrder.Text = String.Format("/{0}", sizeRunList.Sum(s => s.Quantity));

            btnSave.IsEnabled = true;
            this.Cursor       = null;
        }
Esempio n. 4
0
 private void btnUpdateSizeRun_Click(object sender, RoutedEventArgs e)
 {
     if (MessageBox.Show("Confirm Save?", this.Title, MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.No)
     {
         return;
     }
     sizeRunToUpdateList.Clear();
     dt = ((DataView)dgSizeRun.ItemsSource).ToTable();
     foreach (DataRow dr in dt.Rows)
     {
         for (int i = 0; i <= sizeRunList.Count - 1; i++)
         {
             string sizeNo   = sizeRunList[i].SizeNo;
             int    quantity = (Int32)dr[String.Format("Column{0}", i)];
             if (quantity >= 0)
             {
                 var model = new SizeRunModel
                 {
                     ProductNo = productNo,
                     SizeNo    = sizeNo,
                     Quantity  = quantity,
                 };
                 sizeRunToUpdateList.Add(model);
             }
         }
     }
     if (bwUpdateSizeRun.IsBusy == false)
     {
         this.Cursor = Cursors.Wait;
         btnUpdateSizeRun.IsEnabled = false;
         bwUpdateSizeRun.RunWorkerAsync();
     }
 }
        private void btnExport_Click(object sender, RoutedEventArgs e)
        {
            DataTable dtToExport = new AssemblyReleaseDataSet().Tables["AssemblyReleaseTable"];

            foreach (StackPanel sp in spMain.Children)
            {
                foreach (UIElement ui in sp.Children)
                {
                    if (ui.GetType() == typeof(DataGrid))
                    {
                        DataGrid            dg               = (DataGrid)ui;
                        List <Object>       tags             = dg.Tag as List <Object>;
                        string              productNo        = tags[0] as String;
                        int?                qtyReleasedTotal = tags[1] as Int32?;
                        OrdersModel         order            = orderAllList.Where(o => o.ProductNo == productNo).FirstOrDefault();
                        List <SizeRunModel> sizeRunList      = sizeRunAllList.Where(s => s.ProductNo == productNo).ToList();
                        DataTable           dt               = ((DataView)dg.ItemsSource).ToTable();
                        foreach (DataRow dr in dt.Rows)
                        {
                            int cycle = 0;
                            if (int.TryParse(dr["Cycle"].ToString(), out cycle) == true)
                            {
                                for (int i = 0; i <= sizeRunList.Count - 1; i++)
                                {
                                    SizeRunModel sizeRun    = sizeRunList[i];
                                    int          qtyRelease = 0;
                                    int.TryParse(dr[String.Format("Column{0}", i)].ToString(), out qtyRelease);
                                    DataRow drToExport = dtToExport.NewRow();
                                    drToExport["ProductNo"]     = productNo;
                                    drToExport["OrderQuantity"] = sizeRun.Quantity;
                                    if (order != null)
                                    {
                                        drToExport["ShoeName"]           = order.ShoeName;
                                        drToExport["ArticleNo"]          = order.ArticleNo;
                                        drToExport["LastCode"]           = order.LastCode;
                                        drToExport["TotalOrderQuantity"] = order.Quantity;
                                    }
                                    drToExport["TotalReleasedQuantity"] = qtyReleasedTotal.Value;
                                    drToExport["Cycle"]    = cycle;
                                    drToExport["SizeNo"]   = sizeRun.SizeNo;
                                    drToExport["Quantity"] = qtyRelease;
                                    dtToExport.Rows.Add(drToExport);
                                }
                            }
                        }
                    }
                }
            }

            if (dtToExport.Rows.Count <= 0)
            {
                return;
            }
            AssemblyReleaseReportWindow window = new AssemblyReleaseReportWindow(reportId, dtToExport);

            window.ShowDialog();
        }
        private void bwLoad_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            for (int i = 0; i <= sizeRunList.Count - 1; i++)
            {
                SizeRunModel sizeRun = sizeRunList[i];
                dt.Columns.Add(String.Format("Column{0}", i), typeof(Int32));
                DataGridTextColumn column = new DataGridTextColumn();
                column.SetValue(TagProperty, sizeRun.SizeNo);
                column.Header   = String.Format("{0}\n({1})", sizeRun.SizeNo, sizeRun.Quantity);
                column.MinWidth = 40;
                column.Binding  = new Binding(String.Format("Column{0}", i));

                Style  styleColumn           = new Style();
                Setter setterColumnForecolor = new Setter();
                setterColumnForecolor.Property = DataGridCell.ForegroundProperty;
                setterColumnForecolor.Value    = new Binding(String.Format("Column{0}Foreground", i));
                styleColumn.Setters.Add(setterColumnForecolor);

                DataColumn columnForeground = new DataColumn(String.Format("Column{0}Foreground", i), typeof(SolidColorBrush));
                columnForeground.DefaultValue = Brushes.Black;

                column.CellStyle = styleColumn;
                dt.Columns.Add(columnForeground);
                dgSockliningInput.Columns.Add(column);
            }
            colCompleted.DisplayIndex = dgSockliningInput.Columns.Count - 1;

            DataRow dr = dt.NewRow();

            for (int j = 0; j <= sizeRunList.Count - 1; j++)
            {
                SizeRunModel sizeRun    = sizeRunList[j];
                int          qtyPerSize = sockliningInputList.Where(s => s.SizeNo == sizeRun.SizeNo).Sum(s => s.Quantity);
                dr[String.Format("Column{0}", j)] = qtyPerSize;
                if (qtyPerSize == sizeRun.Quantity)
                {
                    dr[String.Format("Column{0}Foreground", j)] = Brushes.Blue;
                }
                else
                {
                    dr[String.Format("Column{0}Foreground", j)] = Brushes.Red;
                }
            }

            dt.Rows.Add(dr);

            dgSockliningInput.ItemsSource = dt.AsDataView();

            lblQtyTotal.Text = sockliningInputList.Sum(s => s.Quantity).ToString();
            lblQtyOrder.Text = String.Format("/{0}", sizeRunList.Sum(s => s.Quantity));

            btnSave.IsEnabled = true;
            this.Cursor       = null;
        }
 private void bwLoad_DoWork(object sender, DoWorkEventArgs e)
 {
     Excel.Application excelApplication = new Excel.Application();
     Excel.Workbook    excelWorkbook    = excelApplication.Workbooks.Open(filePath);
     //excelApplication.Visible = true;
     Excel.Worksheet excelWorksheet;
     Excel.Range     excelRange;
     try
     {
         excelWorksheet = (Excel.Worksheet)excelWorkbook.Worksheets[1];
         excelRange     = excelWorksheet.UsedRange;
         progressBar.Dispatcher.Invoke((Action)(() => progressBar.Maximum = excelRange.Rows.Count));
         for (int i = 2; i <= excelRange.Rows.Count; i++)
         {
             var productNoValue = (excelRange.Cells[i, 4] as Excel.Range).Value2;
             if (productNoValue != null)
             {
                 string productNo = productNoValue.ToString();
                 //for (int j = 17; j <= 65; j++)
                 for (int j = 17; j <= 67; j++)
                 {
                     var qtyValue = (excelRange.Cells[i, j] as Excel.Range).Value2;
                     if (qtyValue != null)
                     {
                         int qty = 0;
                         int.TryParse(qtyValue.ToString(), out qty);
                         string sizeNo = (excelRange.Cells[1, j] as Excel.Range).Value2.ToString();
                         //if (qty > 0)
                         //{
                         SizeRunModel sizeRun = new SizeRunModel
                         {
                             ProductNo = productNo,
                             SizeNo    = sizeNo,
                             Quantity  = qty,
                         };
                         sizeRunList.Add(sizeRun);
                         //}
                     }
                 }
             }
             progressBar.Dispatcher.Invoke((Action)(() => progressBar.Value = i));
         }
     }
     catch
     {
         sizeRunList.Clear();
     }
     finally
     {
         excelWorkbook.Close(false, Missing.Value, Missing.Value);
         excelApplication.Quit();
     }
 }
Esempio n. 8
0
        private void btnCompleted_Click(object sender, RoutedEventArgs e)
        {
            DataRow dr = ((DataRowView)dgOutsoleMaterial.CurrentItem).Row;

            for (int i = 0; i <= sizeRunList.Count - 1; i++)
            {
                SizeRunModel sizeRun = sizeRunList[i];
                dr[String.Format("Column{0}", i)] = sizeRun.Quantity;
            }
            dgOutsoleMaterial.ItemsSource = null;
            dgOutsoleMaterial.ItemsSource = dt.AsDataView();
        }
        public static bool Update(SizeRunModel model)
        {
            var @ProductNo = new SqlParameter("@ProductNo", model.ProductNo);
            var @SizeNo    = new SqlParameter("@SizeNo", model.SizeNo);
            var @Quantity  = new SqlParameter("@Quantity", model.Quantity);

            SaovietMasterScheduleEntities db = new SaovietMasterScheduleEntities();

            if (db.ExecuteStoreCommand("EXEC spm_UpdateSizeRun @ProductNo,@SizeNo,@Quantity", @ProductNo, @SizeNo, @Quantity) > 0)
            {
                return(true);
            }
            return(false);
        }
 private void btnRelease_Click(object sender, RoutedEventArgs e)
 {
     if (MessageBox.Show("Confirm Release?", this.Title, MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.No)
     {
         return;
     }
     assemblyReleaseToInsertList.Clear();
     foreach (StackPanel sp in spMain.Children)
     {
         foreach (UIElement ui in sp.Children)
         {
             if (ui.GetType() == typeof(DataGrid))
             {
                 DataGrid            dg          = (DataGrid)ui;
                 List <Object>       tags        = dg.Tag as List <Object>;
                 string              productNo   = tags[0] as String;
                 List <SizeRunModel> sizeRunList = sizeRunAllList.Where(s => s.ProductNo == productNo).ToList();
                 DataTable           dt          = ((DataView)dg.ItemsSource).ToTable();
                 foreach (DataRow dr in dt.Rows)
                 {
                     int cycle = 0;
                     if (int.TryParse(dr["Cycle"].ToString(), out cycle) == true)
                     {
                         for (int i = 0; i <= sizeRunList.Count - 1; i++)
                         {
                             SizeRunModel sizeRun    = sizeRunList[i];
                             int          qtyRelease = 0;
                             int.TryParse(dr[String.Format("Column{0}", i)].ToString(), out qtyRelease);
                             AssemblyReleaseModel assemblyRelease = new AssemblyReleaseModel
                             {
                                 ReportId  = reportId,
                                 ProductNo = productNo,
                                 Cycle     = cycle,
                                 SizeNo    = sizeRun.SizeNo,
                                 Quantity  = qtyRelease,
                             };
                             assemblyReleaseToInsertList.Add(assemblyRelease);
                         }
                     }
                 }
             }
         }
     }
     if (assemblyReleaseToInsertList.Count > 0 && bwInsert.IsBusy == false)
     {
         this.Cursor          = Cursors.Wait;
         btnRelease.IsEnabled = false;
         bwInsert.RunWorkerAsync();
     }
 }
        private void btnCompleted_Click(object sender, RoutedEventArgs e)
        {
            DataRow dr = ((DataRowView)dgSockliningInput.CurrentItem).Row;

            for (int i = 0; i <= sizeRunList.Count - 1; i++)
            {
                SizeRunModel sizeRun = sizeRunList[i];
                dr[String.Format("Column{0}", i)]           = sizeRun.Quantity;
                dr[String.Format("Column{0}Foreground", i)] = Brushes.Blue;
            }
            dgSockliningInput.ItemsSource = null;
            dgSockliningInput.ItemsSource = dt.AsDataView();

            lblQtyTotal.Text = sizeRunList.Sum(s => s.Quantity).ToString();
        }
Esempio n. 12
0
        public static bool UpdateSizeMap(SizeRunModel model)
        {
            var @ProductNo   = new SqlParameter("@ProductNo", model.ProductNo);
            var @SizeNo      = new SqlParameter("@SizeNo", model.SizeNo);
            var @OutsoleSize = new SqlParameter("@OutsoleSize", model.OutsoleSize);
            var @MidsoleSize = new SqlParameter("@MidsoleSize", model.MidsoleSize);
            var @UpdateOutsoleSizeByArticle = new SqlParameter("@UpdateOutsoleSizeByArticle", model.UpdateOutsoleSizeByArticle);

            SaovietMasterScheduleEntities db = new SaovietMasterScheduleEntities();

            if (db.ExecuteStoreCommand("EXEC spm_UpdateSizeRunMap_1 @ProductNo,@SizeNo,@OutsoleSize,@MidsoleSize,@UpdateOutsoleSizeByArticle", @ProductNo, @SizeNo, @OutsoleSize, @MidsoleSize, @UpdateOutsoleSizeByArticle) > 0)
            {
                return(true);
            }
            return(false);
        }
Esempio n. 13
0
        private void CreateGridShowData(DataGrid dgInput, DataTable dtInput)
        {
            dgInput.AutoGenerateColumns = false;
            dgInput.CanUserAddRows      = false;
            dgInput.SelectionUnit       = DataGridSelectionUnit.CellOrRowHeader;
            dgInput.HeadersVisibility   = DataGridHeadersVisibility.None;

            dtInput.Columns.Add("Status", typeof(String));
            DataGridTextColumn colStatus = new DataGridTextColumn();

            colStatus.Header     = "Order Size\nOutsole Size\nMidsole Size\nSố lượng";
            colStatus.Width      = 100;
            colStatus.IsReadOnly = true;
            colStatus.Binding    = new Binding("Status");
            dgInput.Columns.Add(colStatus);

            for (int i = 0; i <= sizeRunList.Count - 1; i++)
            {
                SizeRunModel sizeRun = sizeRunList[i];
                dtInput.Columns.Add(String.Format("Column{0}", i, typeof(String)));
                DataGridTextColumn col = new DataGridTextColumn();
                col.SetValue(TagProperty, sizeRun.SizeNo);
                col.Header     = String.Format("{0}\n{1}\n{2}\n({3})", sizeRun.SizeNo, sizeRun.OutsoleSize, sizeRun.MidsoleSize, sizeRun.Quantity);
                col.MinWidth   = 40;
                col.IsReadOnly = true;
                col.Binding    = new Binding(String.Format("Column{0}", i));
                dgInput.Columns.Add(col);
            }

            dtInput.Columns.Add("Total", typeof(String));
            var colTotal = new DataGridTextColumn();

            colTotal.Header     = _TOTAL;
            colTotal.IsReadOnly = true;
            colTotal.Binding    = new Binding("Total");

            Style styleColTotal = new Style(typeof(DataGridCell));

            styleColTotal.Setters.Add(new Setter(TextBlock.FontWeightProperty, FontWeights.Bold));
            styleColTotal.Setters.Add(new Setter(TextBlock.TextAlignmentProperty, TextAlignment.Center));
            colTotal.CellStyle = styleColTotal;

            dgInput.Columns.Add(colTotal);
        }
        public AddRejectForMaterialWindow(List <RejectModel> rejectUpperAccessoriesList, SizeRunModel sizeRunClicked, MaterialPlanModel materialPlanChecking, DataRowView rowEditting, List <MaterialInspectModel> deliveryCurrentList, int totalRejectCurrent, string workerId, List <SizeRunModel> sizeRunList)
        {
            this.rejectUpperAccessoriesList = rejectUpperAccessoriesList;
            this.sizeRunClicked             = sizeRunClicked;
            this.materialPlanChecking       = materialPlanChecking;
            this.rowEditting        = rowEditting;
            this.inspectListCurrent = deliveryCurrentList;
            this.totalRejectCurrent = totalRejectCurrent;
            this.workerId           = workerId;
            this.sizeRunList        = sizeRunList;
            bwUpload                     = new BackgroundWorker();
            bwUpload.DoWork             += BwUpload_DoWork;
            bwUpload.RunWorkerCompleted += BwUpload_RunWorkerCompleted;

            rejectClickedList    = new List <RejectModel>();
            inspectListHasReject = new List <MaterialInspectModel>();
            dtReject             = new DataTable();
            InitializeComponent();
        }
Esempio n. 15
0
        public static bool InsertNew(SizeRunModel model)
        {
            var @ProductNo   = new SqlParameter("@ProductNo", model.ProductNo);
            var @SizeNo      = new SqlParameter("@SizeNo", model.SizeNo);
            var @Quantity    = new SqlParameter("@Quantity", model.Quantity);
            var @OutsoleSize = new SqlParameter("@OutsoleSize", model.OutsoleSize);
            var @MidsoleSize = new SqlParameter("@MidsoleSize", model.MidsoleSize);
            var @LastSize    = new SqlParameter("@LastSize", model.LastSize);

            using (var db = new SaovietMasterScheduleEntities())
            {
                if (db.ExecuteStoreCommand("EXEC spm_InsertSizeRun_2  @ProductNo, @SizeNo, @Quantity, @OutsoleSize, @MidsoleSize, @LastSize",
                                           @ProductNo, @SizeNo, @Quantity, @OutsoleSize, @MidsoleSize, @LastSize) > 0)
                {
                    return(true);
                }
                return(false);
            }
        }
Esempio n. 16
0
        private void bwAddMore_DoWork(object sender, DoWorkEventArgs e)
        {
            // Excute Store.
            outsoleMaterialDetailList = OutsoleMaterialDetailController.Select(productNo).Where(w => w.OutsoleSupplierId == supplierClicked.OutsoleSupplierId && w.IndexNo == INDEXNO && w.Round == ROUND).ToList();

            // Create column
            Dispatcher.Invoke(new Action(() => {
                dtAdd.Columns.Add("Title", typeof(String));
                DataGridTextColumn colTitle = new DataGridTextColumn();
                colTitle.Header             = String.Format("Nhà cung cấp\n{0}\nCông đoạn: {1}\nLần kiểm: {2}", supplierClicked.Name, INDEXNO, ROUND.ToString());
                colTitle.IsReadOnly         = true;
                colTitle.Binding            = new Binding("Title");
                dgAdd.Columns.Add(colTitle);

                dtAdd.Columns.Add("Status", typeof(String));
                DataGridTextColumn colStatus = new DataGridTextColumn();
                colStatus.Header             = "Order Size\nO/S Size\nM/S Size\nSố lượng";
                colStatus.IsReadOnly         = true;
                colStatus.Binding            = new Binding("Status");
                dgAdd.Columns.Add(colStatus);

                for (int i = 0; i <= sizeRunList.Count - 1; i++)
                {
                    SizeRunModel sizeRun = sizeRunList[i];
                    dtAdd.Columns.Add(String.Format("Column{0}", i, typeof(String)));
                    DataGridTextColumn col = new DataGridTextColumn();
                    col.SetValue(TagProperty, sizeRun.SizeNo);
                    col.Header   = String.Format("{0}\n{1}\n{2}\n({3})", sizeRun.SizeNo, sizeRun.OutsoleSize, sizeRun.MidsoleSize, sizeRun.Quantity);
                    col.MinWidth = 40;
                    col.Binding  = new Binding(String.Format("Column{0}", i));
                    dgAdd.Columns.Add(col);
                }

                DataGridTemplateColumn buttonColumn   = new DataGridTemplateColumn();
                DataTemplate buttonTemplate           = new DataTemplate();
                FrameworkElementFactory buttonFactory = new FrameworkElementFactory(typeof(Button));
                buttonTemplate.VisualTree             = buttonFactory;
                buttonFactory.AddHandler(Button.ClickEvent, new RoutedEventHandler(btnOK_Click));
                buttonFactory.SetValue(ContentProperty, "OK");
                buttonColumn.CellTemplate = buttonTemplate;
                dgAdd.Columns.Add(buttonColumn);
            }));
        }
        private void bwLoadData_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            foreach (OutsoleSuppliersModel outsoleSupplier in outsoleSupplierList)
            {
                outsoleSupplierModifiedList.Add(outsoleSupplier);
                outsoleSupplierModifiedList.Add(new OutsoleSuppliersModel
                {
                    Name = _REJECT,
                    OutsoleSupplierId = outsoleSupplier.OutsoleSupplierId,
                });
                outsoleSupplierModifiedList.Add(new OutsoleSuppliersModel
                {
                    Name = _REJECT_ASSEMBLY,
                    OutsoleSupplierId = outsoleSupplier.OutsoleSupplierId,
                });
            }
            colSuppliers.ItemsSource = outsoleSupplierModifiedList;
            //dt.Columns.Clear();
            dt.Columns.Add("Supplier", typeof(OutsoleSuppliersModel));
            dt.Columns.Add("ETD", typeof(String));
            dt.Columns.Add("ActualDate", typeof(String));

            for (int i = 0; i <= sizeRunList.Count - 1; i++)
            {
                SizeRunModel sizeRun = sizeRunList[i];
                dt.Columns.Add(String.Format("Column{0}", i), typeof(Int32));
                DataGridTextColumn column = new DataGridTextColumn();
                column.SetValue(TagProperty, sizeRun.SizeNo);
                column.Header   = String.Format("{0}\n{1}\n{2}\n({3})", sizeRun.SizeNo, sizeRun.OutsoleSize, sizeRun.MidsoleSize, sizeRun.Quantity);
                column.MinWidth = 40;
                if (account.OutsoleMaterialEdit == false)
                {
                    column.IsReadOnly = true;
                }
                column.Binding = new Binding(String.Format("Column{0}", i));
                dgOutsoleMaterial.Columns.Add(column);
            }
            colCompleted.DisplayIndex = dgOutsoleMaterial.Columns.Count - 1;
            colAddRack.DisplayIndex   = dgOutsoleMaterial.Columns.Count - 1;

            dt.Columns.Add("RackPosition", typeof(String));
            DataGridTextColumn colRackPosition = new DataGridTextColumn();

            colRackPosition.Header     = "RackNumber - CartonNumber";
            colRackPosition.MinWidth   = 100;
            colRackPosition.IsReadOnly = true;
            colRackPosition.Binding    = new Binding("RackPosition");
            dgOutsoleMaterial.Columns.Add(colRackPosition);
            colRackPosition.DisplayIndex = dgOutsoleMaterial.Columns.Count - 1;

            List <Int32> outsoleSupplierIdList = outsoleRawMaterialList.Select(o => o.OutsoleSupplierId).Distinct().ToList();

            for (int i = 0; i <= outsoleSupplierIdList.Count - 1; i++)
            {
                int     outsoleSupplierId = outsoleSupplierIdList[i];
                DataRow dr = dt.NewRow();
                dr["Supplier"] = outsoleSupplierModifiedList.Where(w => w.OutsoleSupplierId == outsoleSupplierId && w.Name != _REJECT && w.Name != _REJECT_ASSEMBLY).FirstOrDefault();
                DateTime dtETD = outsoleRawMaterialList.Where(o => o.OutsoleSupplierId == outsoleSupplierId).FirstOrDefault().ETD;
                {
                    if (dtETD.Date != dtDefault)
                    {
                        dr["ETD"] = String.Format(new CultureInfo("en-US"), "{0:dd-MMM}", dtETD);
                    }
                }

                DateTime dtActualDate = outsoleRawMaterialList.Where(o => o.OutsoleSupplierId == outsoleSupplierId).FirstOrDefault().ActualDate;
                if (dtActualDate.Date != dtDefault)
                {
                    dr["ActualDate"] = String.Format(new CultureInfo("en-US"), "{0:dd-MMM}", dtActualDate);
                }
                DataRow drReject         = dt.NewRow();
                DataRow drRejectAssembly = dt.NewRow();
                drReject["Supplier"]         = outsoleSupplierModifiedList.Where(o => o.OutsoleSupplierId == outsoleSupplierId && o.Name == _REJECT).FirstOrDefault();
                drRejectAssembly["Supplier"] = outsoleSupplierModifiedList.Where(o => o.OutsoleSupplierId == outsoleSupplierId && o.Name == _REJECT_ASSEMBLY).FirstOrDefault();
                for (int j = 0; j <= sizeRunList.Count - 1; j++)
                {
                    SizeRunModel sizeRun = sizeRunList[j];

                    int qtyLoad = outsoleMaterialList.Where(o => o.OutsoleSupplierId == outsoleSupplierId && o.SizeNo == sizeRun.SizeNo).Sum(o => o.Quantity);
                    if (qtyLoad > 0)
                    {
                        dr[String.Format("Column{0}", j)] = qtyLoad;
                    }

                    int rejectLoad = outsoleMaterialList.Where(o => o.OutsoleSupplierId == outsoleSupplierId && o.SizeNo == sizeRun.SizeNo).Sum(o => o.QuantityReject);
                    if (rejectLoad > 0)
                    {
                        drReject[String.Format("Column{0}", j)] = rejectLoad;
                    }

                    int rejectAssemblyLoad = outsoleMaterialList.Where(o => o.OutsoleSupplierId == outsoleSupplierId && o.SizeNo == sizeRun.SizeNo).Sum(o => o.RejectAssembly);
                    if (rejectAssemblyLoad > 0)
                    {
                        drRejectAssembly[String.Format("Column{0}", j)] = rejectAssemblyLoad;
                    }
                }


                var outsoleMaterialRackPositionPerSupplierList = outsoleMaterialRackPositionList.Where(w => w.OutsoleSupplierId == outsoleSupplierId).ToList();
                dr["RackPosition"] = RackPositionString(outsoleMaterialRackPositionPerSupplierList);

                dt.Rows.Add(dr);
                dt.Rows.Add(drReject);
                dt.Rows.Add(drRejectAssembly);
            }

            dgOutsoleMaterial.ItemsSource = dt.AsDataView();
            btnSave.IsEnabled             = true;
            this.Cursor = null;
        }
        private void bwLoadData_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            foreach (InsockSuppliersModel insockSupplier in insockSupplierList)
            {
                insockSupplierModifiedList.Add(insockSupplier);
                insockSupplierModifiedList.Add(new InsockSuppliersModel
                {
                    InsockSupplierName = "Reject",
                    InsockSupplierId   = insockSupplier.InsockSupplierId,
                });
            }
            colSuppliers.ItemsSource = insockSupplierModifiedList;
            //dt.Columns.Clear();
            dt.Columns.Add("Supplier", typeof(InsockSuppliersModel));
            dt.Columns.Add("ETD", typeof(String));
            dt.Columns.Add("ActualDate", typeof(String));
            for (int i = 0; i <= sizeRunList.Count - 1; i++)
            {
                SizeRunModel sizeRun = sizeRunList[i];
                dt.Columns.Add(String.Format("Column{0}", i), typeof(Int32));
                DataGridTextColumn column = new DataGridTextColumn();
                column.SetValue(TagProperty, sizeRun.SizeNo);
                column.Header   = String.Format("{0}\n({1})", sizeRun.SizeNo, sizeRun.Quantity);
                column.MinWidth = 40;
                column.Binding  = new Binding(String.Format("Column{0}", i));
                dgInsockMaterial.Columns.Add(column);
            }
            colCompleted.DisplayIndex = dgInsockMaterial.Columns.Count - 1;

            List <Int32> insockSupplierIdList = insockRawMaterialList.Select(o => o.InsockSupplierId).Distinct().ToList();

            for (int i = 0; i <= insockSupplierIdList.Count - 1; i++)
            {
                int     insockSupplierId = insockSupplierIdList[i];
                DataRow dr = dt.NewRow();
                dr["Supplier"] = insockSupplierModifiedList.Where(o => o.InsockSupplierId == insockSupplierId && o.InsockSupplierName != "Reject").FirstOrDefault();
                DateTime dtETD = insockRawMaterialList.Where(o => o.InsockSupplierId == insockSupplierId).FirstOrDefault().ETD;
                {
                    if (dtETD.Date != dtDefault)
                    {
                        dr["ETD"] = String.Format(new CultureInfo("en-US"), "{0:dd-MMM}", dtETD);
                    }
                }
                DateTime dtActualDate = insockRawMaterialList.Where(o => o.InsockSupplierId == insockSupplierId).FirstOrDefault().ActualDate;
                if (dtActualDate.Date != dtDefault)
                {
                    dr["ActualDate"] = String.Format(new CultureInfo("en-US"), "{0:dd-MMM}", dtActualDate);
                }
                DataRow dr1 = dt.NewRow();
                dr1["Supplier"] = insockSupplierModifiedList.Where(o => o.InsockSupplierId == insockSupplierId && o.InsockSupplierName == "Reject").FirstOrDefault();
                for (int j = 0; j <= sizeRunList.Count - 1; j++)
                {
                    SizeRunModel sizeRun = sizeRunList[j];
                    dr[String.Format("Column{0}", j)]  = insockMaterialList.Where(o => o.InsockSupplierId == insockSupplierId && o.SizeNo == sizeRun.SizeNo).Sum(o => o.Quantity);
                    dr1[String.Format("Column{0}", j)] = insockMaterialList.Where(o => o.InsockSupplierId == insockSupplierId && o.SizeNo == sizeRun.SizeNo).Sum(o => o.QuantityReject);
                }
                dt.Rows.Add(dr);
                dt.Rows.Add(dr1);
            }

            dgInsockMaterial.ItemsSource = dt.AsDataView();
            btnSave.IsEnabled            = true;
            this.Cursor = null;
        }
        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();
        }
Esempio n. 20
0
        private void bwLoad_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            this.Cursor         = null;
            btnSearch.IsEnabled = true;

            txtIndexNo.IsEnabled = false;
            btnSave.IsEnabled    = false;

            // Clear value
            stkSuppliers.Children.Clear();

            tblArticleNo.Text  = "";
            tblStyle.Text      = "";
            tblOSCode.Text     = "";
            tblTotalPairs.Text = "";
            txtCreatedBy.Text  = "";

            dgAdd.ItemsSource = null;
            dgAdd.Columns.Clear();

            spLoadDetail.Children.Clear();
            spTitle.Children.Clear();
            groupLoadDetail.Visibility = Visibility.Collapsed;

            btnAddIndexNo.IsEnabled = false;
            btnAddIndexNo.IsDefault = false;
            txtIndexNo.Clear();
            groupAddIndexNo.Header = "Supplier (Nhà Cung Cấp)";


            if (outsoleMaterialList.Count() == 0 || orderSearch == null)
            {
                MessageBox.Show("Not Found !", this.Title, MessageBoxButton.OK, MessageBoxImage.Information);
                txtProductNo.Focus();
                txtProductNo.SelectAll();
                return;
            }

            tblArticleNo.Text  = orderSearch.ArticleNo;
            tblStyle.Text      = orderSearch.ShoeName;
            tblOSCode.Text     = orderSearch.OutsoleCode;
            tblTotalPairs.Text = orderSearch.Quantity.ToString();

            var outsoleMaterialSupplierIdPerPOList = outsoleMaterialList.OrderBy(o => o.OutsoleSupplierId).Select(s => s.OutsoleSupplierId).Distinct().ToList();

            // Create Supplier Button
            foreach (var supplierId in outsoleMaterialSupplierIdPerPOList)
            {
                var outsoleMaterialDetailPerSupplier = outsoleMaterialDetailList.Where(w => w.OutsoleSupplierId == supplierId).ToList();

                var    supplier    = outsoleSupplierList.FirstOrDefault(f => f.OutsoleSupplierId == supplierId);
                Button btnSupplier = new Button();


                btnSupplier.FontSize  = 16;
                btnSupplier.MinHeight = 30;
                btnSupplier.Margin    = new Thickness(0, 0, 10, 0);
                btnSupplier.ToolTip   = "Supplier";
                btnSupplier.Tag       = supplierId;
                btnSupplier.Content   = supplier == null ? "" : supplier.Name;

                var style = FindResource("MyButton") as Style;
                if (outsoleMaterialDetailPerSupplier.Select(s => s.Quantity).Sum() >= sizeRunList.Select(s => s.Quantity).Sum())
                {
                    style = (Style)FindResource("MyButtonFinished");
                }
                else if (outsoleMaterialDetailPerSupplier.Select(s => s.Quantity).Sum() != 0 &&
                         outsoleMaterialDetailPerSupplier.Select(s => s.Quantity).Sum() < sizeRunList.Select(s => s.Quantity).Sum())
                {
                    style = (Style)FindResource("MyButtonInProcess");
                }
                btnSupplier.Style = style;

                btnSupplier.Click += new RoutedEventHandler(btnSupplier_Click);
                stkSuppliers.Children.Add(btnSupplier);
            }

            // Create Summary
            if (outsoleMaterialDetailList.Count > 0)
            {
                groupLoadDetail.Visibility = Visibility.Visible;
                // Title
                spTitle.Children.Add(CreateDataGridTitle());

                // Grid
                var suppliedIdList = outsoleMaterialDetailList.Select(s => s.OutsoleSupplierId).Distinct().ToList();
                foreach (var suppliedId in suppliedIdList)
                {
                    var supplierName  = outsoleSupplierList.FirstOrDefault(f => f.OutsoleSupplierId == suppliedId) == null ? "" : outsoleSupplierList.FirstOrDefault(f => f.OutsoleSupplierId == suppliedId).Name;
                    var spTitleDetail = new StackPanel();
                    spTitleDetail.Orientation = Orientation.Horizontal;
                    spTitleDetail.Margin      = new Thickness(0, 5, 0, 0);

                    var txtTitleDetail = new TextBlock();
                    txtTitleDetail.Text       = String.Format("Supplier (Nhà cung cấp):  {0}", supplierName);
                    txtTitleDetail.FontWeight = FontWeights.Bold;
                    txtTitleDetail.FontStyle  = FontStyles.Italic;
                    txtTitleDetail.FontSize   = 14;

                    spTitleDetail.Children.Add(txtTitleDetail);

                    //Create grid
                    var dtSummary = new DataTable();
                    var dgSummary = new DataGrid();
                    CreateGridShowData(dgSummary, dtSummary);

                    // Fill Data
                    var drQuantity = dtSummary.NewRow();
                    var drReject   = dtSummary.NewRow();
                    drQuantity["Status"] = _QUANTITY;
                    drReject["Status"]   = _REJECT;

                    var outsoleMaterialDetailPerSupplierList = outsoleMaterialDetailList.Where(w => w.OutsoleSupplierId == suppliedId).ToList();
                    for (int i = 0; i <= sizeRunList.Count - 1; i++)
                    {
                        SizeRunModel sizeRun = sizeRunList[i];
                        var          outsoleMaterialDetailPerSupplierPerSizeList = outsoleMaterialDetailPerSupplierList.Where(w => w.SizeNo == sizeRun.SizeNo).ToList();
                        if (outsoleMaterialDetailPerSupplierPerSizeList.Count == 0)
                        {
                            continue;
                        }
                        int qty = 0, reject = 0;
                        qty    = outsoleMaterialDetailPerSupplierPerSizeList.Sum(s => s.Quantity);
                        reject = outsoleMaterialDetailPerSupplierPerSizeList.Sum(s => s.Reject);

                        if (qty > 0)
                        {
                            drQuantity[String.Format("Column{0}", i)] = qty;
                        }
                        if (reject > 0)
                        {
                            drReject[String.Format("Column{0}", i)] = reject;
                        }
                    }

                    string qtyTotalString = "", rejectTotalString = "";
                    if (outsoleMaterialDetailPerSupplierList.Sum(s => s.Quantity) > 0)
                    {
                        qtyTotalString = outsoleMaterialDetailPerSupplierList.Sum(s => s.Quantity).ToString();
                    }
                    if (outsoleMaterialDetailPerSupplierList.Sum(s => s.Reject) > 0)
                    {
                        rejectTotalString = outsoleMaterialDetailPerSupplierList.Sum(s => s.Reject).ToString();
                    }

                    drQuantity["Total"] = qtyTotalString;
                    drReject["Total"]   = rejectTotalString;
                    dtSummary.Rows.Add(drQuantity);
                    dtSummary.Rows.Add(drReject);

                    dgSummary.ItemsSource = dtSummary.AsDataView();

                    spLoadDetail.Children.Add(spTitleDetail);
                    spLoadDetail.Children.Add(dgSummary);
                }
            }
        }
Esempio n. 21
0
        private void bwLoad_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            btnSearch.IsEnabled = true;
            btnSearch.IsDefault = true;
            this.Cursor         = null;

            if (sizeRunList.Count() == 0)
            {
                MessageBox.Show("Not Found !", this.Title, MessageBoxButton.OK, MessageBoxImage.Information);
                txtProductNo.Focus();
                txtProductNo.SelectAll();

                return;
            }

            // Created Column
            dt.Columns.Add("CreatedDate", typeof(DateTime));
            DataGridTextColumn columnCreatedDate = new DataGridTextColumn();

            columnCreatedDate.Header  = "Date";
            columnCreatedDate.Binding = new Binding("CreatedDate");
            columnCreatedDate.Binding.StringFormat = "MM/dd";
            dgOutsoleWHFG.Columns.Add(columnCreatedDate);

            dt.Columns.Add("Status", typeof(String));
            DataGridTextColumn columnStatus = new DataGridTextColumn();

            columnStatus.Header  = productNo;
            columnStatus.Binding = new Binding("Status");

            columnStatus.IsReadOnly = true;
            columnStatus.MinWidth   = 80;

            dgOutsoleWHFG.Columns.Add(columnStatus);

            for (int i = 0; i <= sizeRunList.Count - 1; i++)
            {
                SizeRunModel sizeRun = sizeRunList[i];
                dt.Columns.Add(String.Format("Column{0}", i), typeof(Int32));
                DataGridTextColumn column = new DataGridTextColumn();
                column.SetValue(TagProperty, sizeRun.SizeNo);
                column.Header   = String.Format("{0}\n({1})", sizeRun.SizeNo, sizeRun.Quantity);
                column.MinWidth = 40;
                column.Binding  = new Binding(String.Format("Column{0}", i))
                {
                    Mode = BindingMode.TwoWay, UpdateSourceTrigger = UpdateSourceTrigger.LostFocus
                };
                dgOutsoleWHFG.Columns.Add(column);
            }

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

            columnTotal.Header  = string.Format("Total\n{0}", sizeRunList.Select(s => s.Quantity).Sum());
            columnTotal.Binding = new Binding("Total")
            {
                Mode = BindingMode.TwoWay, UpdateSourceTrigger = UpdateSourceTrigger.LostFocus
            };
            columnTotal.MinWidth   = 50;
            columnTotal.IsReadOnly = true;
            dgOutsoleWHFG.Columns.Add(columnTotal);

            DataGridTemplateColumn  buttonColumn   = new DataGridTemplateColumn();
            DataTemplate            buttonTemplate = new DataTemplate();
            FrameworkElementFactory buttonFactory  = new FrameworkElementFactory(typeof(Button));

            buttonTemplate.VisualTree = buttonFactory;
            buttonFactory.AddHandler(Button.ClickEvent, new RoutedEventHandler(btnOK_Click));
            buttonFactory.SetValue(ContentProperty, "OK");
            buttonColumn.CellTemplate = buttonTemplate;
            dgOutsoleWHFG.Columns.Add(buttonColumn);

            Style style = new Style(typeof(DataGridCell));

            style.Setters.Add(new Setter(TextBlock.TextAlignmentProperty, TextAlignment.Center));
            dgOutsoleWHFG.CellStyle = style;

            // Fill data
            if (outsoleWHFGList.Count() > 0)
            {
                var createdDateList = outsoleWHFGList.Select(s => s.CreatedDate).Distinct().ToList();
                foreach (var createdDate in createdDateList)
                {
                    DataRow dr = dt.NewRow();
                    dr["CreatedDate"] = createdDate;
                    dr["Status"]      = "Quantity";
                    var sizeNoAndQtyList = outsoleWHFGList.Where(w => w.CreatedDate == createdDate).Select(s => new { SizeNo = s.SizeNo, Quantity = s.Quantity }).ToList();
                    for (int i = 0; i < sizeNoAndQtyList.Count; i++)
                    {
                        dr[String.Format("Column{0}", i)] = sizeNoAndQtyList[i].Quantity;
                    }
                    dr["Total"] = outsoleWHFGList.Where(w => w.CreatedDate == createdDate).Select(s => s.Quantity).Sum();

                    dt.Rows.Add(dr);
                }
            }

            dgOutsoleWHFG.ItemsSource = dt.AsDataView();

            btnAddRow.IsEnabled  = true;
            btnBalance.IsEnabled = true;
        }
        private void bwLoad_DoWork(object sender, DoWorkEventArgs e)
        {
            Excel.Application excelApplication = new Excel.Application();
            Excel.Workbook    excelWorkbook    = excelApplication.Workbooks.Open(filePath);
            //excelApplication.Visible = true;
            Excel.Worksheet excelWorksheet;
            Excel.Range     excelRange;
            try
            {
                privateDef = PrivateDefineController.GetDefine();
                var regex = new Regex("[a-z]|[A-Z]");

                excelWorksheet = (Excel.Worksheet)excelWorkbook.Worksheets[1];
                excelRange     = excelWorksheet.UsedRange;
                progressBar.Dispatcher.Invoke((Action)(() => progressBar.Maximum = excelRange.Rows.Count));
                int noOfPO = 0;
                for (int i = 5; i <= excelRange.Rows.Count; i++)
                {
                    var productNoValue = (excelRange.Cells[i, 4] as Excel.Range).Value2;
                    if (productNoValue != null)
                    {
                        noOfPO++;
                        string productNo = productNoValue.ToString();
                        // Order
                        var    order              = new OrdersModel();
                        string UCustomerCode      = "";
                        var    uCustomerCodeValue = (excelRange.Cells[i, 2] as Excel.Range).Value2;
                        if (uCustomerCodeValue != null)
                        {
                            UCustomerCode = uCustomerCodeValue.ToString();
                        }
                        order.UCustomerCode = UCustomerCode;

                        string GTNPONo      = "";
                        var    GTNPONoValue = (excelRange.Cells[i, 3] as Excel.Range).Value2;
                        if (GTNPONoValue != null)
                        {
                            GTNPONo = GTNPONoValue.ToString();
                        }
                        order.GTNPONo = GTNPONo;

                        order.ProductNo = productNo;

                        double csdOADate = 0;
                        Double.TryParse((excelRange.Cells[i, 5] as Excel.Range).Value2.ToString(), out csdOADate);
                        DateTime csd = DateTime.FromOADate(csdOADate);
                        order.ETD = csd.AddDays(-10);

                        string articleNo = (excelRange.Cells[i, 6] as Excel.Range).Value2.ToString();
                        order.ArticleNo = articleNo;

                        string shoeName = (excelRange.Cells[i, 7] as Excel.Range).Value2.ToString();
                        order.ShoeName = shoeName;

                        int quantity = 0;
                        int.TryParse((excelRange.Cells[i, 8] as Excel.Range).Value2.ToString(), out quantity);
                        order.Quantity = quantity;

                        string patternNo = (excelRange.Cells[i, 12] as Excel.Range).Value2.ToString();
                        order.PatternNo = patternNo;

                        var    midsoleCodeValue = (excelRange.Cells[i, 13] as Excel.Range).Value2;
                        string midsoleCode      = "";
                        if (midsoleCodeValue != null)
                        {
                            midsoleCode = midsoleCodeValue.ToString();
                        }
                        order.MidsoleCode = midsoleCode;

                        var    outsoleCodeValue = (excelRange.Cells[i, 14] as Excel.Range).Value2;
                        string outsoleCode      = "";
                        if (outsoleCodeValue != null)
                        {
                            outsoleCode = outsoleCodeValue.ToString();
                        }
                        order.OutsoleCode = outsoleCode;

                        var    lastCodeValue = (excelRange.Cells[i, 15] as Excel.Range).Value2;
                        string lastCode      = "";
                        if (lastCodeValue != null)
                        {
                            lastCode = lastCodeValue.ToString();
                        }
                        order.LastCode = lastCode;

                        var    countryValue = (excelRange.Cells[i, 16] as Excel.Range).Value2;
                        string country      = "";
                        if (countryValue != null)
                        {
                            country = countryValue.ToString();
                        }
                        order.Country = country;
                        order.Reviser = acc.UserName;

                        ordersList.Add(order);

                        //for (int j = 17; j <= 65; j++)
                        // Size Run
                        int noOfColumnLoad = privateDef != null ? privateDef.NoOfColumnOrderExcelFile : 100;
                        for (int j = 18; j <= privateDef.NoOfColumnOrderExcelFile; j++)
                        {
                            var qtyValue      = (excelRange.Cells[i, j] as Excel.Range).Value2;
                            var sizeNoValue   = (excelRange.Cells[i - noOfPO, j] as Excel.Range).Value2;
                            var osSizeValue   = (excelRange.Cells[i - noOfPO - 1, j] as Excel.Range).Value2;
                            var midSizeValue  = (excelRange.Cells[i - noOfPO - 2, j] as Excel.Range).Value2;
                            var lastSizeValue = (excelRange.Cells[i - noOfPO - 3, j] as Excel.Range).Value2;
                            if (qtyValue != null && sizeNoValue != null)
                            {
                                int qty = 0;
                                int.TryParse(qtyValue.ToString(), out qty);
                                //string sizeNo = (excelRange.Cells[1, j] as Excel.Range).Value2.ToString();
                                string sizeNo      = sizeNoValue.ToString();
                                string outsoleSize = osSizeValue != null?osSizeValue.ToString() : sizeNo;

                                string midsoleSize = midSizeValue != null?midSizeValue.ToString() : sizeNo;

                                string lastSize = lastSizeValue != null?lastSizeValue.ToString() : sizeNo;

                                SizeRunModel sizeRun = new SizeRunModel
                                {
                                    ProductNo   = productNo,
                                    SizeNo      = regex.IsMatch(sizeNo) ? regex.Replace(sizeNo, "") : sizeNo,
                                    OutsoleSize = regex.IsMatch(outsoleSize) ? regex.Replace(outsoleSize, "") : outsoleSize,
                                    MidsoleSize = regex.IsMatch(midsoleSize) ? regex.Replace(midsoleSize, "") : midsoleSize,
                                    LastSize    = regex.IsMatch(lastSize) ? regex.Replace(lastSize, "") : lastSize,
                                    Quantity    = qty,
                                };
                                sizeRunList.Add(sizeRun);
                            }
                        }
                    }
                    else
                    {
                        i      = i + 4;
                        noOfPO = 0;
                    }

                    progressBar.Dispatcher.Invoke((Action)(() => progressBar.Value = i));
                }
            }
            catch
            {
                sizeRunList.Clear();
            }
            finally
            {
                excelWorkbook.Close(false, Missing.Value, Missing.Value);
                excelApplication.Quit();
            }
        }
Esempio n. 23
0
        private void bwLoad_DoWork(object sender, DoWorkEventArgs e)
        {
            // Excute DB
            rejectIssuesList = OutsoleMaterialRejectIssuesController.Select();
            rejectDetailList = OutsoleMaterialRejectDetailController.SelectPerPOPerSupplierPerIndexNoPerRound(productNo, supplierClicked.OutsoleSupplierId, INDEXNO, ROUND);

            // Create Table
            Dispatcher.Invoke(new Action(() => {
                // Reject Issues Id
                dt.Columns.Add("OutsoleMaterialRejectIssuesId", typeof(Int32));
                DataGridTextColumn columnRejectIssuesId = new DataGridTextColumn();
                columnRejectIssuesId.Binding            = new Binding("OutsoleMaterialRejectIssuesId");
                columnRejectIssuesId.Visibility         = Visibility.Hidden;
                dgOutsoleMaterialRejectDetail.Columns.Add(columnRejectIssuesId);

                // Reject Issues Name
                dt.Columns.Add("OutsoleMaterialRejectIssuesVietNamese", typeof(String));
                DataGridTextColumn columnRejectIssuesVietNamese = new DataGridTextColumn();
                columnRejectIssuesVietNamese.Binding            = new Binding("OutsoleMaterialRejectIssuesVietNamese");
                columnRejectIssuesVietNamese.Header             = "Vấn Đề";
                columnRejectIssuesVietNamese.MinWidth           = 100;
                columnRejectIssuesVietNamese.IsReadOnly         = true;
                dgOutsoleMaterialRejectDetail.Columns.Add(columnRejectIssuesVietNamese);

                for (int i = 0; i <= sizeRunList.Count - 1; i++)
                {
                    SizeRunModel sizeRun = sizeRunList[i];

                    dt.Columns.Add(String.Format("Column{0}", i), typeof(Int32));
                    DataGridTextColumn column = new DataGridTextColumn();
                    column.SetValue(TagProperty, sizeRun.SizeNo);
                    column.Header = String.Format("{0}\n{1}\n{2}", sizeRun.SizeNo, sizeRun.OutsoleSize, sizeRun.MidsoleSize);

                    Style style = new Style(typeof(DataGridCell));
                    style.Setters.Add(new Setter(TextBlock.TextAlignmentProperty, TextAlignment.Center));
                    column.CellStyle = style;

                    column.MinWidth = 40;
                    column.Binding  = new Binding(String.Format("Column{0}", i))
                    {
                        Mode = BindingMode.TwoWay, UpdateSourceTrigger = UpdateSourceTrigger.LostFocus
                    };
                    dgOutsoleMaterialRejectDetail.Columns.Add(column);
                }

                // Fill Data
                foreach (var rejectIssues in rejectIssuesList)
                {
                    var rejectDetailPerRejectIssuesId = rejectDetailList.Where(w => w.OutsoleMaterialRejectIssuesId == rejectIssues.OutsoleMaterialRejectIssuesId).ToList();

                    DataRow dr = dt.NewRow();
                    dr["OutsoleMaterialRejectIssuesId"]         = rejectIssues.OutsoleMaterialRejectIssuesId;
                    dr["OutsoleMaterialRejectIssuesVietNamese"] = rejectIssues.OutsoleMaterialRejectIssuesVietNamese;

                    for (int i = 0; i <= sizeRunList.Count - 1; i++)
                    {
                        var sizeRun = sizeRunList[i];
                        var rejectDetailPerRejectIssuesIdPerSize = rejectDetailPerRejectIssuesId.FirstOrDefault(f => f.SizeNo == sizeRun.SizeNo);
                        if (rejectDetailPerRejectIssuesIdPerSize != null)
                        {
                            dr[String.Format("Column{0}", i)] = rejectDetailPerRejectIssuesIdPerSize.QuantityReject;
                        }
                    }
                    dt.Rows.Add(dr);
                }
                dgOutsoleMaterialRejectDetail.ItemsSource = dt.AsDataView();
                e.Result = dt;
            }));
        }
        public void AddMore(OrdersModel order, List <SizeRunModel> sizeRunList, List <OutsoleReleaseMaterialModel> outsoleReleaseMaterialList, List <OutsoleMaterialModel> outsoleMaterialList)
        {
            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 <= 8; 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          = 50;
            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              = "Outsole Code:";
            lbl2.VerticalAlignment = VerticalAlignment.Bottom;

            TextBlock lbl3 = new TextBlock();

            Grid.SetColumn(lbl3, 3);
            lbl3.Margin            = new Thickness(5, 0, 0, 0);
            lbl3.MinWidth          = 50;
            lbl3.Text              = order.OutsoleCode;
            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          = 50;
            lbl5.Text              = order.ArticleNo;
            lbl5.FontWeight        = FontWeights.Bold;
            lbl5.VerticalAlignment = VerticalAlignment.Bottom;

            TextBlock lbl6 = new TextBlock();

            Grid.SetColumn(lbl6, 6);
            lbl6.Margin            = new Thickness(10, 0, 0, 0);
            lbl6.Text              = releaseTo == ERelease.ReleaseToOutsole ? "Released Qty:" : "Released to WH Inspection Qty:";
            lbl6.VerticalAlignment = VerticalAlignment.Bottom;

            int qtyReleasedTotal = outsoleReleaseMaterialList.Sum(o => o.Quantity);

            TextBlock lbl7 = new TextBlock();

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

            Button btnRemove = new Button();

            Grid.SetColumn(btnRemove, 8);
            btnRemove.Content             = " X ";
            btnRemove.HorizontalAlignment = HorizontalAlignment.Right;
            btnRemove.Tag       = order.ProductNo;
            btnRemove.IsEnabled = false;
            if (account.OutsoleRMSchedule == 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(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   = "Cycle";
            column1.MinWidth = 100;
            column1.Binding  = new Binding(String.Format("Cycle"));
            dg.Columns.Add(column1);
            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 (outsoleMaterialList.Where(o => o.SizeNo == sizeRun.SizeNo).Count() >= 1)
                {
                    qtyMatch = outsoleMaterialList.Where(o => o.SizeNo == sizeRun.SizeNo).Select(o => (o.Quantity - o.QuantityReject)).Min()
                               - outsoleReleaseMaterialList.Where(o => o.SizeNo == sizeRun.SizeNo).Sum(o => o.Quantity);
                    if (qtyMatch < 0)
                    {
                        qtyMatch = 0;
                    }
                    qtyMatchTotal += qtyMatch;
                }

                DataGridTextColumn column = new DataGridTextColumn();
                column.SetValue(TagProperty, new Int32[] { i, qtyMatch });
                column.Header   = String.Format("{0}\n({1})", sizeRun.SizeNo, 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.MinWidth   = 80;
            column2.Binding    = new Binding(String.Format("Total"));
            column2.FontWeight = FontWeights.Bold;
            column2.IsReadOnly = true;
            dg.Columns.Add(column2);

            dg.ItemsSource = dt.AsDataView();

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

            spMain.Children.Add(sp);

            svMain.ScrollToBottom();
        }
Esempio n. 25
0
        private void GetDataFromTable(DataGrid dg, List <SizeRunModel> sizeRunList, bool updateOutsoleSizeByArticle)
        {
            var dt = new DataTable();

            dt = ((DataView)(dg.ItemsSource)).ToTable();
            var regex               = new Regex("[a-z]|[A-Z]");
            var sizeNoList          = sizeRunList.Select(s => s.SizeNo).Distinct().OrderBy(s => regex.IsMatch(s) ? Double.Parse(regex.Replace(s, "")) : Double.Parse(s)).ToList();
            var productNoListUpdate = sizeRunList.Select(s => s.ProductNo).Distinct().ToList();

            var outsoleSizeRunList = new List <SizeRunModel>();
            var midsoleSizeRunList = new List <SizeRunModel>();

            foreach (DataRow dr in dt.Rows)
            {
                string typeSize = dr["TypeSize"].ToString();
                foreach (var productNo in productNoListUpdate)
                {
                    var sizeRunPerPO = sizeRunList.Where(w => w.ProductNo == productNo).ToList();
                    for (int i = 0; i < sizeNoList.Count; i++)
                    {
                        string sizeNoBinding  = sizeNoList[i].Contains(".") ? sizeNoList[i].Replace(".", "@") : sizeNoList[i];
                        var    sizeRunPerSize = sizeRunPerPO.Where(w => w.SizeNo == sizeNoList[i]).FirstOrDefault();
                        if (sizeRunPerSize == null)
                        {
                            continue;
                        }
                        string outsoleSize = "", midsoleSize = "";
                        if (typeSize.Contains("Outsole Size"))
                        {
                            outsoleSize = dr[String.Format("Column{0}", sizeNoBinding)].ToString();
                            var outsoleSizeRun = new SizeRunModel()
                            {
                                ProductNo   = productNo,
                                SizeNo      = sizeNoList[i],
                                OutsoleSize = outsoleSize,
                            };
                            outsoleSizeRunList.Add(outsoleSizeRun);
                        }
                        if (typeSize.Contains("Midsole Size"))
                        {
                            midsoleSize = dr[String.Format("Column{0}", sizeNoBinding)].ToString();
                            var midsoleSizeRun = new SizeRunModel()
                            {
                                ProductNo   = productNo,
                                SizeNo      = sizeNoList[i],
                                MidsoleSize = midsoleSize,
                            };
                            midsoleSizeRunList.Add(midsoleSizeRun);
                        }
                    }
                }
            }
            foreach (var sizeRun in outsoleSizeRunList)
            {
                var sizeRunMapUpdate = new SizeRunModel()
                {
                    ProductNo   = sizeRun.ProductNo,
                    SizeNo      = sizeRun.SizeNo,
                    MidsoleSize = midsoleSizeRunList.Where(w => w.ProductNo == sizeRun.ProductNo && w.SizeNo == sizeRun.SizeNo).FirstOrDefault().MidsoleSize,
                    OutsoleSize = sizeRun.OutsoleSize,
                    UpdateOutsoleSizeByArticle = updateOutsoleSizeByArticle
                };
                sizeRunMapToUpdateList.Add(sizeRunMapUpdate);
            }
        }
        private void loadReleaseDetail(List <OutsoleMaterialConfirmWorkingCartModel> confirmListByPO,
                                       List <OutsoleMaterialConfirmWorkingCartModel> releaseList)
        {
            var workingCartInfo = confirmListByPO.FirstOrDefault();

            if (workingCartInfo != null)
            {
                gridInfo.DataContext = new
                {
                    ProductNo        = workingCartInfo.ProductNo,
                    Name             = workingCartInfo.Name,
                    ArticleNo        = workingCartInfo.ArticleNo,
                    OutsoleCode      = workingCartInfo.OutsoleCode,
                    OutsoleLine      = workingCartInfo.OutsoleLine,
                    OutsoleStartDate = String.Format("{0: dd-MM-yyyy}", workingCartInfo.OutsoleStartDate),
                    WorkingCart      = "Release Detail"
                }
            }
            ;

            dgReleaseDetail.Columns.Clear();
            var dt = new DataTable();

            DataGridTemplateColumn colTitle = new DataGridTemplateColumn();

            dt.Columns.Add(String.Format("ReleaseDate"), typeof(String));
            colTitle.Header = String.Format("ReleaseDate");
            DataTemplate            tplTitle = new DataTemplate();
            FrameworkElementFactory tblTitle = new FrameworkElementFactory(typeof(TextBlock));

            tplTitle.VisualTree = tblTitle;
            tblTitle.SetBinding(TextBlock.TextProperty, new Binding(String.Format("ReleaseDate")));
            tblTitle.SetValue(TextBlock.TextAlignmentProperty, TextAlignment.Center);
            tblTitle.SetValue(TextBlock.VerticalAlignmentProperty, VerticalAlignment.Center);
            colTitle.CellTemplate            = tplTitle;
            colTitle.SortMemberPath          = "ReleaseDate";
            colTitle.ClipboardContentBinding = new Binding(String.Format("ReleaseDate"));
            dgReleaseDetail.Columns.Add(colTitle);

            DataGridTemplateColumn colIndexNo = new DataGridTemplateColumn();

            dt.Columns.Add(String.Format("IndexNo"), typeof(String));
            colIndexNo.Header = String.Format("IndexNo");
            DataTemplate            tplIndexNo = new DataTemplate();
            FrameworkElementFactory tblIndexNo = new FrameworkElementFactory(typeof(TextBlock));

            tplIndexNo.VisualTree = tblIndexNo;
            tblIndexNo.SetBinding(TextBlock.TextProperty, new Binding(String.Format("IndexNo")));
            tblIndexNo.SetValue(TextBlock.TextAlignmentProperty, TextAlignment.Center);
            tblIndexNo.SetValue(TextBlock.VerticalAlignmentProperty, VerticalAlignment.Center);
            colIndexNo.CellTemplate            = tplIndexNo;
            colIndexNo.SortMemberPath          = "IndexNo";
            colIndexNo.ClipboardContentBinding = new Binding(String.Format("IndexNo"));
            dgReleaseDetail.Columns.Add(colIndexNo);

            for (int i = 0; i <= sizeRunList.Count - 1; i++)
            {
                SizeRunModel sizeRun = sizeRunList[i];
                dt.Columns.Add(String.Format("Column{0}", i), typeof(String));
                DataGridTemplateColumn colSize = new DataGridTemplateColumn();
                colSize.Header   = string.Format("{0}\n{1}\n{2}", sizeRun.SizeNo, sizeRun.OutsoleSize, sizeRun.Quantity);
                colSize.MinWidth = 45;
                DataTemplate            tplSize = new DataTemplate();
                FrameworkElementFactory tblSize = new FrameworkElementFactory(typeof(TextBlock));
                tplSize.VisualTree = tblSize;

                tblSize.SetBinding(TextBlock.TextProperty, new Binding(String.Format("Column{0}", i)));
                tblSize.SetValue(TextBlock.TextAlignmentProperty, TextAlignment.Center);
                tblSize.SetValue(TextBlock.VerticalAlignmentProperty, VerticalAlignment.Center);
                colSize.CellTemplate            = tplSize;
                colSize.ClipboardContentBinding = new Binding(String.Format("Column{0}", i));
                dgReleaseDetail.Columns.Add(colSize);
            }

            DataGridTemplateColumn colTotalRelease = new DataGridTemplateColumn();

            dt.Columns.Add(String.Format("TotalRelease"), typeof(String));
            colTotalRelease.Header = String.Format("Total\n\n{0}", sizeRunList.Sum(s => s.Quantity));
            DataTemplate            tplTotalRelease = new DataTemplate();
            FrameworkElementFactory tblTotalRelease = new FrameworkElementFactory(typeof(TextBlock));

            tplTotalRelease.VisualTree = tblTotalRelease;
            tblTotalRelease.SetBinding(TextBlock.TextProperty, new Binding(String.Format("TotalRelease")));
            tblTotalRelease.SetValue(TextBlock.TextAlignmentProperty, TextAlignment.Center);
            tblTotalRelease.SetValue(TextBlock.VerticalAlignmentProperty, VerticalAlignment.Center);
            colTotalRelease.CellTemplate            = tplTotalRelease;
            colTotalRelease.SortMemberPath          = "TotalRelease";
            colTotalRelease.ClipboardContentBinding = new Binding(String.Format("TotalRelease"));
            dgReleaseDetail.Columns.Add(colTotalRelease);

            // Bindind data
            foreach (var cfItem in confirmListByPO)
            {
                var checkReleased = releaseList.FirstOrDefault(f => f.OSCheckingID == cfItem.OSCheckingID);
                if (checkReleased != null)
                {
                    cfItem.IsRelease    = true;
                    cfItem.ReleasedTime = checkReleased.ReleasedTime;
                }
            }
            var releasedList = confirmListByPO.Where(w => w.IsRelease == true).ToList();
            var dateList     = releasedList.Select(s => s.ReleasedTime?.Date).Distinct().ToList();

            if (dateList.Count() > 0)
            {
                dateList = dateList.OrderBy(o => o).ToList();
            }

            foreach (var date in dateList)
            {
                var releaseByDate    = releasedList.Where(w => w.ReleasedTime?.Date == date).ToList();
                var displayFirstDate = false;
                var cartList         = releaseByDate.OrderBy(o => o.ReleasedTime).Select(s => s.WorkingCard).Distinct().ToList();
                foreach (var cart in cartList)
                {
                    DataRow dr            = dt.NewRow();
                    var     releaseByCart = releaseByDate.Where(w => w.WorkingCard == cart).ToList();
                    if (!displayFirstDate)
                    {
                        dr["ReleaseDate"] = String.Format("{0:dd/MM/yyyy}", date);
                    }
                    dr["IndexNo"] = cart.ToString();

                    var sizeList = releaseByCart.Select(s => s.SizeNo).Distinct().ToList();
                    for (int i = 0; i < sizeRunList.Count; i++)
                    {
                        var sizeRun       = sizeRunList[i];
                        var sizeCompare   = sizeRun.OutsoleSize != "" ? sizeRun.OutsoleSize : sizeRun.SizeNo;
                        var releaseBySize = releaseByCart.FirstOrDefault(f => f.SizeNo == sizeCompare);
                        if (releaseBySize != null)
                        {
                            dr[String.Format("Column{0}", i)] = releaseBySize.Quantity.ToString();
                        }

                        var sizeDouble = sizeRunList.Where(w => w.OutsoleSize == sizeCompare).ToList();
                        if (sizeDouble.Count() > 1)
                        {
                            i = i + 1;
                        }
                    }
                    if (releaseByCart.Count() > 0)
                    {
                        dr["TotalRelease"] = releaseByCart.Sum(s => s.Quantity).ToString();
                    }

                    displayFirstDate = true;
                    dt.Rows.Add(dr);
                }
            }

            dgReleaseDetail.ItemsSource = dt.AsDataView();
        }