////////////////////////////////////////////////
        private void AddPackingItem(PackingListItem item)
        {
            ParkingParserItem parserItem = null;

            DatabaseItem dataItem = databaseInfor.FindItem(item.GetNameProduct());

            if (dataItem == null)
            {
                this.errorCode += item.GetNameProduct() + ": is empty in database\r\n";

                dataItem = new DatabaseItem();
            }

            if (listPackingParser == null)
            {
                listPackingParser = new List <ParkingParserItem>();
            }



            //add new
            if (listPackingParser.Count == 0)
            {
                parserItem = new ParkingParserItem(item.GetNameProduct(), item, dataItem);

                listPackingParser.Add(parserItem);

                return;
            }


            //add to exist
            for (int index = 0; index < listPackingParser.Count; index++)
            {
                if (item.GetNameProduct() == listPackingParser.ElementAt(index).GetNameProduct())
                {
                    listPackingParser.ElementAt(index).AddNewItemInList(item);

                    return;
                }
            }

            parserItem = new ParkingParserItem(item.GetNameProduct(), item, dataItem);
            //add new
            listPackingParser.Add(parserItem);

            return;
        }
        private void SliptToMerger(ParkingParserItem parserItem)
        {
            PackingListItem packingItem;
            int             base_index = 0;

            double totalQunatity = 0;
            double numberItem    = 0;

            foreach (PackingListItem item in parserItem.GetListItem())
            {
                if (item.IsNeedMerger())
                {
                    totalQunatity += item.GetQuantity();
                    numberItem++;
                }
            }

            if (totalQunatity >= parserItem.GetDatabaseItem().GetMaxPacketSize())
            {
                double          sliptQuantity = 0;
                PackingListItem itemAdd       = null;

                for (int run = 0; run < parserItem.GetListItem().Count; run++)
                {
                    if (parserItem.GetListItem().ElementAt(run).IsNeedMerger())
                    {
                        base_index = run;
                        break;
                    }
                }

                //Need to slipt
                parserItem.GetListItem().ElementAt(base_index).SetNeedMerger(false);

                sliptQuantity = parserItem.GetDatabaseItem().GetMaxPacketSize() -
                                parserItem.GetListItem().ElementAt(base_index).GetQuantity();

                while (sliptQuantity > 0)
                {
                    bool found = false;

                    for (int run = base_index + 1; run < parserItem.GetListItem().Count; run++)
                    {
                        if (parserItem.GetListItem().ElementAt(run).IsNeedMerger())
                        {
                            if (parserItem.GetListItem().ElementAt(run).GetQuantity() > sliptQuantity)
                            {
                                found = true;

                                itemAdd = new PackingListItem();

                                itemAdd.SetColor1(parserItem.GetListItem().ElementAt(run).GetColor1());
                                itemAdd.SetColor2(parserItem.GetListItem().ElementAt(run).GetColor2());
                                itemAdd.SetNameProduct(parserItem.GetListItem().ElementAt(run).GetNameProduct());
                                itemAdd.SetNeedMerger(false);
                                itemAdd.SetProductSize(parserItem.GetListItem().ElementAt(run).GetProductSize());
                                itemAdd.SetQuantity(sliptQuantity);

                                parserItem.GetListItem().ElementAt(run).SetQuantity(parserItem.GetListItem().ElementAt(run).GetQuantity() - sliptQuantity);

                                sliptQuantity = 0;
                                parserItem.GetListItem().ElementAt(base_index).AddMergerItem(itemAdd);
                            }
                            else
                            {
                                found = true;

                                packingItem = parserItem.GetListItem().ElementAt(run);

                                packingItem.SetNeedMerger(false);

                                parserItem.GetListItem().RemoveAt(run);

                                parserItem.GetListItem().ElementAt(base_index).AddMergerItem(packingItem);

                                sliptQuantity -= packingItem.GetQuantity();
                            }

                            break;
                        }
                    }

                    if (!found)
                    {
                        break;
                    }
                }

                SliptToMerger(parserItem);
            }
            else /*less than*/ if (numberItem != 0)
            {
                for (int run = 0; run < parserItem.GetListItem().Count; run++)
                {
                    if (parserItem.GetListItem().ElementAt(run).IsNeedMerger())
                    {
                        parserItem.GetListItem().ElementAt(run).SetNeedMerger(false);
                        base_index = run;
                        break;
                    }
                }

                numberItem -= 1;

                while (numberItem > 0)
                {
                    packingItem = null;

                    if (base_index >= parserItem.GetListItem().Count)
                    {
                        break;
                    }

                    for (int run = base_index; run < parserItem.GetListItem().Count; run++)
                    {
                        if (parserItem.GetListItem().ElementAt(run).IsNeedMerger())
                        {
                            packingItem = parserItem.GetListItem().ElementAt(run);

                            packingItem.SetNeedMerger(false);

                            parserItem.GetListItem().RemoveAt(run);
                            break;
                        }
                    }

                    if (packingItem != null)
                    {
                        parserItem.GetListItem().ElementAt(base_index).AddMergerItem(packingItem);
                    }

                    numberItem -= 1;
                }
            }
        }
        private void CreateMergerItem(int type, ParkingParserItem item, PackingListItem packItem)
        {
            NPOI.SS.UserModel.IRow row;
            int start_index;
            int end_index;

            int total = Sheet_2_GetNumberOfColum();

            CombineMergerListItem combine = new CombineMergerListItem(packItem);

            combine.RunCombineMergerListItem();

            List <CombineItem> listCombine = combine.GetListCombineItem();

            ICell cell;
            ICell cellSum = null;

            start_index = sheet_2_rowIndex;

            for (int itemIndex = 0; itemIndex < listCombine.Count; itemIndex++)
            {
                //create new row
                row = sheet_2.CreateRow(sheet_2_rowIndex);
                sheet_2_rowIndex++;

                for (int run = 0; run < Sheet_2_GetNumberOfColum(); run++)
                {
                    cell = row.CreateCell(run);

                    cell.CellStyle = sheet_2_mainStyle_2;

                    switch (run)
                    {
                    case 0:
                        if (itemIndex == 0)
                        {
                            sheet_2_numberPacket++;
                            cell.SetCellValue(sheet_2_numberPacket + "");
                        }
                        break;

                    case 1:
                        if (itemIndex == 0)
                        {
                            cell.SetCellValue(1);
                        }
                        break;

                    case 2:
                        cell.SetCellValue(packItem.GetNameProduct());
                        break;

                    case 3:
                        cell.SetCellValue(listCombine.ElementAt(itemIndex).GetColor1());
                        break;

                    case 4:
                        cell.SetCellValue(listCombine.ElementAt(itemIndex).GetColor2());
                        break;

                    default:
                        if ((total - 4) == run)
                        {
                            if (itemIndex == 0)
                            {
                                cellSum = cell;
                            }
                        }
                        else if ((total - 3) == run)
                        {
                            if (itemIndex == 0)
                            {
                                cell.SetCellValue("PCS");
                            }
                        }
                        else if ((total - 2) == run)
                        {
                            if (itemIndex == 0)
                            {
                                String formula = item.GetDatabaseItem().GetNetWeight() + "*B" + sheet_2_rowIndex;
                                cell.SetCellFormula(formula);
                            }
                        }
                        else if ((total - 1) == run)
                        {
                            if (itemIndex == 0)
                            {
                                String formula = item.GetDatabaseItem().GetAllWeight() + "*B" + sheet_2_rowIndex;
                                cell.SetCellFormula(formula);
                            }
                        }
                        else
                        {
                            cell.SetCellValue("");
                        }
                        break;
                    }
                }

                foreach (CombineEle element in listCombine.ElementAt(itemIndex).GetListElement())
                {
                    int size_index = Sheet_2_GetColumIndex(type, element.GetSize());

                    ICell cellSize = row.GetCell(size_index);

                    cellSize.SetCellValue(element.GetQuality());
                }
            }

            end_index = sheet_2_rowIndex - 1;

            String columName  = Sheet_2_GetStringOfColum(Sheet_2_GetNumberOfColum() - 4);
            String formulaSum = "SUM(F" + (start_index + 1) + ":" + columName + (end_index + 1) + ")";

            if (cellSum != null)
            {
                cellSum.SetCellFormula(formulaSum);
            }

            if (end_index != start_index)
            {
                NPOI.SS.Util.CellRangeAddress range_1 = new NPOI.SS.Util.CellRangeAddress(start_index, end_index, 0, 0);
                NPOI.SS.Util.CellRangeAddress range_2 = new NPOI.SS.Util.CellRangeAddress(start_index, end_index, 1, 1);
                NPOI.SS.Util.CellRangeAddress range_3 = new NPOI.SS.Util.CellRangeAddress(start_index, end_index, total - 4, total - 4);
                NPOI.SS.Util.CellRangeAddress range_4 = new NPOI.SS.Util.CellRangeAddress(start_index, end_index, total - 3, total - 3);
                NPOI.SS.Util.CellRangeAddress range_5 = new NPOI.SS.Util.CellRangeAddress(start_index, end_index, total - 2, total - 2);
                NPOI.SS.Util.CellRangeAddress range_6 = new NPOI.SS.Util.CellRangeAddress(start_index, end_index, total - 1, total - 1);

                sheet_2.AddMergedRegion(range_1);
                sheet_2.AddMergedRegion(range_2);
                sheet_2.AddMergedRegion(range_3);
                sheet_2.AddMergedRegion(range_4);
                sheet_2.AddMergedRegion(range_5);
                sheet_2.AddMergedRegion(range_6);

                sheet_2.GetRow(start_index).GetCell(0).CellStyle         = sheet_2_mergerStyle;
                sheet_2.GetRow(start_index).GetCell(1).CellStyle         = sheet_2_mergerStyle;
                sheet_2.GetRow(start_index).GetCell(total - 4).CellStyle = sheet_2_mergerStyle;
                sheet_2.GetRow(start_index).GetCell(total - 3).CellStyle = sheet_2_mergerStyle;
                sheet_2.GetRow(start_index).GetCell(total - 2).CellStyle = sheet_2_mergerStyle;
                sheet_2.GetRow(start_index).GetCell(total - 1).CellStyle = sheet_2_mergerStyle;
            }
        }
        private void CreateRowValueSheet_2(ParkingParserItem item)
        {
            NPOI.SS.UserModel.IRow row;
            ICell  cell;
            int    type;
            String nametype = "";

            int start_row, end_row;

            if (!(item != null && item.GetListItem() != null && item.GetListItem().Count > 0))
            {
                return;
            }

            //Clear header value
            row = sheet_2.CreateRow(sheet_2_rowIndex);
            sheet_2_rowIndex++;
            start_row = sheet_2_rowIndex + 1;

            if (CheckExistsSize_2(item.GetListItem().ElementAt(0).GetProductSize()) < 0)
            {
                type = 1;
            }
            else
            {
                type = 2;
            }

            for (int run = 0; run < Sheet_2_GetNumberOfColum(); run++)
            {
                cell = row.CreateCell(run);

                cell.SetCellValue(Sheet_2_GetHeaderString(type, run));

                if (item.GetNameProduct().StartsWith("R"))
                {
                    nametype = " - BRASSIERES";
                }
                else
                {
                    nametype = " - BRIEFS";
                }

                if (run == 0)
                {
                    cell.SetCellValue(item.GetNameProduct() + nametype);


                    cell.CellStyle = sheet_2_headerStyle_1;
                }
                else
                {
                    cell.CellStyle = sheet_2_headerStyle_2;
                }
            }

            NPOI.SS.Util.CellRangeAddress range = new NPOI.SS.Util.CellRangeAddress(sheet_2_rowIndex - 1, sheet_2_rowIndex - 1, 0, 4);
            sheet_2.AddMergedRegion(range);


            foreach (PackingListItem packItem in item.GetListItem())
            {
                if (packItem.GetMergerList() != null && packItem.GetMergerList().Count > 0)
                {
                    CreateMergerItem(type, item, packItem);
                }
                else
                {
                    CreateNotMergerItem(type, item, packItem);
                }
            }

            end_row = sheet_2_rowIndex;

            //sum row
            row = sheet_2.CreateRow(sheet_2_rowIndex);
            sheet_2_rowIndex++;

            for (int run = 0; run < Sheet_2_GetNumberOfColum(); run++)
            {
                cell = row.CreateCell(run);
                if (run == 2)
                {
                    cell.CellStyle = sheet_2_bottomStyle_2;
                }
                else
                {
                    cell.CellStyle = sheet_2_bottomStyle_1;
                }
                switch (run)
                {
                case 0:
                    cell.SetCellValue("P'KGS");
                    break;

                case 2:
                    cell.SetCellValue("SUB TOTAL:");
                    break;

                case 3:
                case 4:
                    break;

                default:
                {
                    String colum  = Sheet_2_GetStringOfColum(run + 1);
                    String fomula = "SUM(" + colum + start_row + ":" + colum + end_row + ")";
                    cell.SetCellFormula(fomula);
                    break;
                }
                }
            }
        }
        private void CreateNotMergerItem(int type, ParkingParserItem item, PackingListItem packItem)
        {
            ICell cell;

            NPOI.SS.UserModel.IRow row;

            //create new row
            row = sheet_2.CreateRow(sheet_2_rowIndex);
            sheet_2_rowIndex++;

            int phan_nguyen = (int)(packItem.GetQuantity() / item.GetDatabaseItem().GetMaxPacketSize());
            int size_index  = Sheet_2_GetColumIndex(type, packItem.GetProductSize());

            for (int run = 0; run < Sheet_2_GetNumberOfColum(); run++)
            {
                cell = row.CreateCell(run);

                cell.CellStyle = sheet_2_mainStyle_2;

                switch (run)
                {
                case 0:
                    if (phan_nguyen > 1)
                    {
                        double from = sheet_2_numberPacket + 1;
                        double to   = sheet_2_numberPacket + phan_nguyen;
                        cell.SetCellValue(from + " - " + to);

                        sheet_2_numberPacket += phan_nguyen;
                    }
                    else
                    {
                        sheet_2_numberPacket++;
                        cell.SetCellValue(sheet_2_numberPacket + "");
                    }
                    break;

                case 1:
                    if (phan_nguyen > 0)
                    {
                        cell.SetCellValue(phan_nguyen);
                    }
                    else
                    {
                        cell.SetCellValue(1);
                    }
                    break;

                case 2:
                    cell.SetCellValue(packItem.GetNameProduct());
                    break;

                case 3:
                    cell.SetCellValue(packItem.GetColor1());
                    break;

                case 4:
                    cell.SetCellValue(packItem.GetColor2());
                    break;

                default:
                    if (run == size_index)
                    {
                        if (phan_nguyen > 0)
                        {
                            String formula = item.GetDatabaseItem().GetMaxPacketSize() + "*$B" + sheet_2_rowIndex;
                            cell.SetCellFormula(formula);
                        }
                        else
                        {
                            cell.SetCellValue(packItem.GetQuantity());
                        }
                    }
                    else
                    {
                        int total = Sheet_2_GetNumberOfColum();

                        if ((total - 4) == run)
                        {
                            String columName = Sheet_2_GetStringOfColum(Sheet_2_GetNumberOfColum() - 4);
                            String formula   = "SUM(F" + sheet_2_rowIndex + ":" + columName + sheet_2_rowIndex + ")";
                            cell.SetCellFormula(formula);
                        }
                        else if ((total - 3) == run)
                        {
                            cell.SetCellValue("PCS");
                        }
                        else if ((total - 2) == run)
                        {
                            String formula = item.GetDatabaseItem().GetNetWeight() + "*B" + sheet_2_rowIndex;
                            cell.SetCellFormula(formula);
                        }
                        else if ((total - 1) == run)
                        {
                            String formula = item.GetDatabaseItem().GetAllWeight() + "*B" + sheet_2_rowIndex;
                            cell.SetCellFormula(formula);
                        }
                        else
                        {
                            cell.SetCellValue("");
                        }
                    }
                    break;
                }
            }
        }