Example #1
0
        public bool ComplateInventory(long documentId, bool forceCompletion, out string errorMessage)
        {
            var inventory = new Inventory() { ReadingId = documentId };
            errorMessage = string.Empty;

            inventory.State = StatesOfDocument.Completed;
            return inventory.Write() == WritingResult.Success;
        }
Example #2
0
        public bool GetNewInventoryId(out long documentId)
        {
            var doc = new Inventory();
            doc.SetRef("Responsible", getUserId());
            doc.Date = SystemConfiguration.ServerDateTime;
            var writeResult = doc.Write();

            documentId = doc.Id;
            return writeResult == WritingResult.Success;
        }
Example #3
0
        private bool writeInventoryResult(long documentId, DataTable resultTable, bool resultOfOnePallet)
        {
            if (resultTable.Rows.Count == 0) return true;

            var q = DB.NewQuery("select max(LineNumber) lastRowNumber from subInventoryNomenclatureInfo where IdDoc = @IdDoc");
            q.AddInputParameter("IdDoc", documentId);
            var lastLineNumber = q.SelectInt64();

            var inventory = new Inventory();
            var currentTime = SystemConfiguration.ServerDateTime;

            // ��� ������ ������ ���� � ���� �����, �.�. ����� ��������� ������� ����� ���������� � ��������, ��� ��� �� null
            var docTable = inventory.NomenclatureInfo;

            var palletCode = 0L;
            var firstDataRow = resultTable.Rows[0];
            if (resultOfOnePallet)
                {
                palletCode = Convert.ToInt64(firstDataRow[inventory.PalletCode.ColumnName]);
                new BoxesFinder(resultTable, palletCode);
                }

            long startCodeOfPreviousPallet = 0;
            long finalCodeOfPreviousPallet = 0;

            for (int rowIndex = 0; rowIndex < resultTable.Rows.Count; rowIndex++)
                {
                var sourceRow = resultTable.Rows[rowIndex];
                var newRow = docTable.GetNewRow(inventory);
                newRow[inventory.RowState] = (int)RowsStates.Completed;
                newRow[inventory.RowDate] = currentTime;

                if (resultOfOnePallet)
                    {
                    var isTare = rowIndex != 0;
                    if (!isTare)
                        {
                        var sticker = new Stickers() { ReadingId = palletCode };
                        newRow[inventory.Party] = sticker.GetRef("Party");

                        startCodeOfPreviousPallet = Convert.ToInt64(sourceRow[inventory.StartCodeOfPreviousPallet.ColumnName]);
                        finalCodeOfPreviousPallet = Convert.ToInt64(sourceRow[inventory.FinalCodeOfPreviousPallet.ColumnName]);
                        }
                    }
                else
                    {
                    newRow[inventory.Party] = Convert.ToInt64(sourceRow[inventory.Party.ColumnName]);
                    }

                newRow[inventory.Nomenclature] = Convert.ToInt64(sourceRow[inventory.Nomenclature.ColumnName]);
                newRow[inventory.PlanValue] = Convert.ToDecimal(sourceRow[inventory.PlanValue.ColumnName]);
                newRow[inventory.FactValue] = Convert.ToDecimal(sourceRow[inventory.FactValue.ColumnName]);

                newRow[inventory.PalletCode] = Convert.ToInt64(sourceRow[inventory.PalletCode.ColumnName]);

                newRow[inventory.StartCodeOfPreviousPallet] = Convert.ToInt64(sourceRow[inventory.StartCodeOfPreviousPallet.ColumnName]);
                newRow[inventory.FinalCodeOfPreviousPallet] = Convert.ToInt64(sourceRow[inventory.FinalCodeOfPreviousPallet.ColumnName]);

                newRow[inventory.StartCell] = Convert.ToInt64(sourceRow[inventory.StartCell.ColumnName]);
                newRow[inventory.FinalCell] = Convert.ToInt64(sourceRow[inventory.FinalCell.ColumnName]);

                newRow[CONSTS.LINE_NUMBER_COLUMN_NAME] = lastLineNumber + rowIndex + 1;
                newRow.AddRowToTable(inventory);
                }

            if (resultOfOnePallet)
                {
                // ���� ��-�� �������� �������� ���� ������� � �����-������ ������ ���, �� ����� ��������
                q = DB.NewQuery(@"
            select @palet PalletCode, 0 StartCodeOfPreviousPallet, 0 FinalCodeOfPreviousPallet, Nomenclature, Party, Quantity PlanValue, Cell StartCell, 0 FinalCell
            from dbo.GetStockBalance('0001-01-01', 0, 0, 2, 0, @palet) balance
            where Cell <> @cell

            union all

            select rel.Pallet PalletCode, case when rel.Quantity > 0 then rel.PreviousPallet else 0 end StartCodeOfPreviousPallet,
            case when rel.Quantity > 0 then 0 else rel.PreviousPallet end FinalCodeOfPreviousPallet, 0 Nomenclature, 0 Party,
            0 PlanValue, @emptyCell StartCell, @emptyCell FinalCell
            from dbo.GetPalletsRelations('0001-01-01', @palet, 0) rel
            where rel.PreviousPallet <> @startPrevPalet and @palet > 0

            union all

            select rel.Pallet PalletCode, case when rel.Quantity > 0 then @finishPrevPalet else 0 end StartCodeOfPreviousPallet,
            case when rel.Quantity > 0 then 0 else @finishPrevPalet end FinalCodeOfPreviousPallet, 0 Nomenclature, 0 Party,
            0 PlanValue, @emptyCell StartCell, @emptyCell FinalCell
            from dbo.GetPalletsRelations('0001-01-01', 0, @finishPrevPalet) rel
            where rel.Pallet <> @palet and @finishPrevPalet > 0
            ");
                q.AddInputParameter("palet", palletCode);
                q.AddInputParameter("emptyCell", Consts.EmptyCell.Id);
                q.AddInputParameter("cell", firstDataRow[inventory.StartCell.ColumnName]);
                q.AddInputParameter("startPrevPalet", startCodeOfPreviousPallet);
                q.AddInputParameter("finishPrevPalet", finalCodeOfPreviousPallet);
                var addTable = q.SelectToTable();

                var emptyCell = Consts.EmptyCell.Id;
                lastLineNumber = Convert.ToInt64(docTable.Rows[docTable.Rows.Count - 1][CONSTS.LINE_NUMBER_COLUMN_NAME]);
                for (int rowIndex = 0; rowIndex < addTable.Rows.Count; rowIndex++)
                    {
                    var sourceRow = addTable.Rows[rowIndex];

                    var newRow = docTable.GetNewRow(inventory);
                    newRow[inventory.RowState] = (int)RowsStates.Completed;
                    newRow[inventory.RowDate] = currentTime;
                    newRow[inventory.Party] = Convert.ToInt64(sourceRow[inventory.Party.ColumnName]);

                    newRow[inventory.Nomenclature] = Convert.ToInt64(sourceRow[inventory.Nomenclature.ColumnName]);
                    newRow[inventory.PlanValue] = Convert.ToDecimal(sourceRow[inventory.PlanValue.ColumnName]);
                    newRow[inventory.FactValue] = 0M;

                    newRow[inventory.PalletCode] = Convert.ToInt64(sourceRow[inventory.PalletCode.ColumnName]);

                    newRow[inventory.StartCodeOfPreviousPallet] = Convert.ToInt64(sourceRow[inventory.StartCodeOfPreviousPallet.ColumnName]);
                    newRow[inventory.FinalCodeOfPreviousPallet] = Convert.ToInt64(sourceRow[inventory.FinalCodeOfPreviousPallet.ColumnName]);

                    newRow[inventory.StartCell] = Convert.ToInt64(sourceRow[inventory.StartCell.ColumnName]);
                    newRow[inventory.FinalCell] = Convert.ToInt64(sourceRow[inventory.FinalCell.ColumnName]);

                    newRow[CONSTS.LINE_NUMBER_COLUMN_NAME] = lastLineNumber + rowIndex + 1;
                    newRow.AddRowToTable(inventory);
                    }
                }

            return appendRowsToInventory(documentId, docTable);
        }