////////////////////////////////////////////////
        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;
        }
Esempio n. 2
0
        public ParkingParserItem(String name, PackingListItem item, DatabaseItem databaseItem)
        {
            this.nameProduct  = name;
            this.databaseItem = databaseItem;

            this.listItem = new List <PackingListItem>();
            if (item != null)
            {
                int phan_nguyen = (int)(item.GetQuantity() / databaseItem.GetMaxPacketSize());
                int phan_du     = (int)(item.GetQuantity()) - (int)(phan_nguyen * databaseItem.GetMaxPacketSize());

                if (phan_du == 0 || phan_nguyen == 0)
                {
                    if (phan_nguyen == 0)
                    {
                        item.SetNeedMerger(true);
                    }
                    else
                    {
                        item.SetNeedMerger(false);
                    }
                    listItem.Add(item);
                }
                else
                {
                    //add phan nguyen
                    item.SetQuantity(phan_nguyen * databaseItem.GetMaxPacketSize());
                    item.SetNeedMerger(false);
                    listItem.Add(item);

                    //add phan du
                    PackingListItem item_du = new PackingListItem();

                    item_du.SetColor1(item.GetColor1());
                    item_du.SetColor2(item.GetColor2());
                    item_du.SetNameProduct(item.GetNameProduct());
                    item_du.SetProductSize(item.GetProductSize());
                    item_du.SetQuantity(phan_du);

                    item_du.SetNeedMerger(true);
                    listItem.Add(item_du);
                }
            }
        }
Esempio n. 3
0
 public void SetDatabaseItem(DatabaseItem value)
 {
     this.databaseItem = value;
 }
Esempio n. 4
0
        ////////////////////////////////////////////////////////////////////
        private void CreateRowValueSheet_1(PackingListItem item, DatabaseItem databaseItem)
        {
            NPOI.SS.UserModel.IRow r;

            if (item.GetQuantity() < databaseItem.GetMaxPacketSize())
            {
                r = sheet_1.CreateRow(rowIndex_sheet_1);
                rowIndex_sheet_1++;

                numberPacket_sheet_1++;

                double valueMerger = item.GetQuantity();

                if (item.GetMergerList() != null && item.GetMergerList().Count > 0)
                {
                    foreach (MergerItem merger in item.GetMergerList())
                    {
                        valueMerger += merger.GetQuantity();
                    }
                }

                for (int idex = 0; idex < Sheet_1_Header.Length; idex++)
                {
                    ICell cell = r.CreateCell(idex);
                    cell.CellStyle = sheet_1_headerStyle;
                    switch (idex)
                    {
                    case 0:
                        cell.SetCellValue(this.packingParser.GetDateTime());
                        break;

                    case 1:
                        cell.SetCellValue(item.GetNameProduct());
                        break;

                    case 2:
                        cell.SetCellValue(item.GetColor1());
                        break;

                    case 3:
                        cell.SetCellValue(item.GetColor2());
                        break;

                    case 4:
                        cell.SetCellValue(item.GetProductSize());
                        break;

                    case 5:
                        cell.SetCellValue(item.GetQuantity());
                        if (valueMerger > item.GetQuantity())
                        {
                            cell.CellStyle = sheet_1_headerStyle_2;
                        }
                        break;

                    case 6:
                        cell.SetCellValue(1);
                        break;

                    case 7:
                        cell.SetCellValue(numberPacket_sheet_1);
                        break;

                    case 8:
                        if (valueMerger <= item.GetQuantity())
                        {
                            cell.SetCellValue(valueMerger);
                        }
                        break;

                    case 9:
                        cell.SetCellValue(databaseItem.GetNetWeight());
                        break;

                    case 10:
                        cell.SetCellValue(databaseItem.GetAllWeight());
                        break;

                    case 11:
                        cell.SetCellValue(databaseItem.GetPacketInformation());
                        break;

                    default:
                        break;
                    }
                }
            }
            else
            {
                for (int tmp = 0; tmp < (int)(item.GetQuantity() / databaseItem.GetMaxPacketSize()); tmp++)
                {
                    numberPacket_sheet_1++;

                    r = sheet_1.CreateRow(rowIndex_sheet_1);
                    rowIndex_sheet_1++;

                    for (int idex = 0; idex < Sheet_1_Header.Length; idex++)
                    {
                        ICell cell = r.CreateCell(idex);
                        cell.CellStyle = sheet_1_headerStyle;

                        switch (idex)
                        {
                        case 0:
                            cell.SetCellValue(this.packingParser.GetDateTime());
                            break;

                        case 1:
                            cell.SetCellValue(item.GetNameProduct());
                            break;

                        case 2:
                            cell.SetCellValue(item.GetColor1());
                            break;

                        case 3:
                            cell.SetCellValue(item.GetColor2());
                            break;

                        case 4:
                            cell.SetCellValue(item.GetProductSize());
                            break;

                        case 5:
                            cell.SetCellValue(databaseItem.GetMaxPacketSize());
                            break;

                        case 6:
                            cell.SetCellValue(1);
                            break;

                        case 7:
                            cell.SetCellValue(numberPacket_sheet_1);
                            break;

                        case 8:
                            cell.SetCellValue(databaseItem.GetMaxPacketSize());
                            break;

                        case 9:
                            cell.SetCellValue(databaseItem.GetNetWeight());
                            break;

                        case 10:
                            cell.SetCellValue(databaseItem.GetAllWeight());
                            break;

                        case 11:
                            cell.SetCellValue(databaseItem.GetPacketInformation());
                            break;

                        default:
                            break;
                        }
                    }
                }
            }

            if (item.GetMergerList() != null && item.GetMergerList().Count > 0)
            {
                foreach (MergerItem merger in item.GetMergerList())
                {
                    r = sheet_1.CreateRow(rowIndex_sheet_1);
                    rowIndex_sheet_1++;

                    for (int idex = 0; idex < Sheet_1_Header.Length; idex++)
                    {
                        ICell cell = r.CreateCell(idex);
                        cell.CellStyle = sheet_1_headerStyle;

                        switch (idex)
                        {
                        case 0:
                            cell.SetCellValue(this.packingParser.GetDateTime());
                            break;

                        case 1:
                            cell.SetCellValue(merger.GetNameProduct());
                            break;

                        case 2:
                            cell.SetCellValue(merger.GetColor1());
                            break;

                        case 3:
                            cell.SetCellValue(merger.GetColor2());
                            break;

                        case 4:
                            cell.SetCellValue(merger.GetProductSize());
                            break;

                        case 5:
                            cell.SetCellValue(merger.GetQuantity());
                            cell.CellStyle = sheet_1_headerStyle_2;
                            break;

                        case 6:
                            break;

                        case 7:
                            cell.SetCellValue(numberPacket_sheet_1);
                            break;

                        case 8:
                            break;

                        case 9:
                            //cell.SetCellValue(databaseItem.GetNetWeight());
                            break;

                        case 10:
                            //cell.SetCellValue(databaseItem.GetAllWeight());
                            break;

                        case 11:
                            //cell.SetCellValue(databaseItem.GetPacketInformation());
                            break;

                        default:
                            break;
                        }
                    }
                }

                r = sheet_1.GetRow(rowIndex_sheet_1 - (1 + item.GetMergerList().Count));
                String fomular = "SUM(F" + (rowIndex_sheet_1 - item.GetMergerList().Count) + ":F" + rowIndex_sheet_1 + ")";
                if (r.GetCell(8) != null)
                {
                    r.GetCell(8).CellFormula = fomular;
                }

                NPOI.SS.Util.CellRangeAddress range_1 = new NPOI.SS.Util.CellRangeAddress(rowIndex_sheet_1 - (1 + item.GetMergerList().Count),
                                                                                          rowIndex_sheet_1 - 1, 6, 6);

                NPOI.SS.Util.CellRangeAddress range_2 = new NPOI.SS.Util.CellRangeAddress(rowIndex_sheet_1 - (1 + item.GetMergerList().Count),
                                                                                          rowIndex_sheet_1 - 1, 8, 8);
                sheet_1.AddMergedRegion(range_1);
                sheet_1.AddMergedRegion(range_2);
            }
        }
Esempio n. 5
0
        public bool CreateListDatabase(String pathFile)
        {
            bool         addItem;
            DatabaseItem item = null;

            if (!File.Exists(pathFile))
            {
                this.errorCode = "Find not found";
                return(false);
            }

            listDatabase = new List <DatabaseItem>();

            try
            {
                // get sheets list from xlsx
                FileStream fs = new FileStream(pathFile, FileMode.Open, FileAccess.Read);

                XSSFWorkbook wb = new XSSFWorkbook(fs);

                if (wb.Count <= 0)
                {
                    this.errorCode = "Sheet in file is empty";
                    return(false);
                }

                XSSFSheet sh = (XSSFSheet)wb.GetSheetAt(0);

                int index = 0;
                while (sh.GetRow(index) != null)
                {
                    if (index == 0)
                    {
                        index++;

                        continue;
                    }

                    addItem = false;


                    // write row value
                    for (int j = 0; j < sh.GetRow(index).Cells.Count; j++)
                    {
                        var cell = sh.GetRow(index).GetCell(j);

                        if (j == 0 && cell != null)
                        {
                            if (cell.CellType != NPOI.SS.UserModel.CellType.String)
                            {
                                break;
                            }
                            else if (sh.GetRow(index).GetCell(j).StringCellValue == null ||
                                     sh.GetRow(index).GetCell(j).StringCellValue == "")
                            {
                                break;
                            }
                            else
                            {
                                item = new DatabaseItem();
                            }
                        }

                        if (cell != null)
                        {
                            // TODO: you can add more cell types capatibility, e. g. formula
                            switch (cell.CellType)
                            {
                            case NPOI.SS.UserModel.CellType.Numeric:

                                addItem = true;
                                item.SetDataValue(j, sh.GetRow(index).GetCell(j).NumericCellValue + "");
                                break;

                            case NPOI.SS.UserModel.CellType.String:
                                addItem = true;
                                item.SetDataValue(j, sh.GetRow(index).GetCell(j).StringCellValue + "");

                                break;
                            }
                        }
                    }
                    if (addItem)
                    {
                        listDatabase.Add(item);
                    }
                    index++;
                }

                fs.Close();
            }
            catch (IOException ex)
            {
                this.errorCode = ex.Message;

                return(false);
            }

            return(true);
        }