public bool WriteMovementResult(long documentId, DataTable resultTable) { var q = DB.NewQuery("select max(LineNumber) lastRowNumber from SubMovingNomenclatureInfo where IdDoc = @IdDoc"); q.AddInputParameter("IdDoc", documentId); var lastLineNumber = q.SelectInt64(); var document = new Moving(); var currentTime = SystemConfiguration.ServerDateTime; // ��� ������ ������ ���� � ���� �����, �.�. ����� ��������� ������� ����� ���������� � ��������, ��� ��� �� null var docTable = document.NomenclatureInfo; var palletCode = Convert.ToInt64(resultTable.Rows[0][document.PalletCode.ColumnName]); new BoxesFinder(resultTable, palletCode); var userId = getUserId(); for (int rowIndex = 0; rowIndex < resultTable.Rows.Count; rowIndex++) { var sourceRow = resultTable.Rows[rowIndex]; var newRow = docTable.GetNewRow(document); newRow[document.RowState] = (int)RowsStates.Completed; newRow[document.RowDate] = currentTime; var isTare = rowIndex != 0; if (!isTare) { var sticker = new Stickers() { ReadingId = palletCode }; newRow[document.Party] = sticker.GetRef("Party"); } newRow[document.Nomenclature] = Convert.ToInt64(sourceRow[document.Nomenclature.ColumnName]); newRow[document.PlanValue] = Convert.ToDecimal(sourceRow[document.PlanValue.ColumnName]); newRow[document.FactValue] = Convert.ToDecimal(sourceRow[document.FactValue.ColumnName]); newRow[document.PalletCode] = palletCode; newRow[document.StartCodeOfPreviousPallet] = Convert.ToInt64(sourceRow[document.StartCodeOfPreviousPallet.ColumnName]); newRow[document.FinalCodeOfPreviousPallet] = Convert.ToInt64(sourceRow[document.FinalCodeOfPreviousPallet.ColumnName]); newRow[document.StartCell] = Convert.ToInt64(sourceRow[document.StartCell.ColumnName]); newRow[document.FinalCell] = Convert.ToInt64(sourceRow[document.FinalCell.ColumnName]); newRow[document.Employee] = userId; newRow[CONSTS.LINE_NUMBER_COLUMN_NAME] = lastLineNumber + rowIndex + 1; newRow.AddRowToTable(document); } var rowsToInsert = document.NomenclatureInfo; q = DB.NewQuery(@"insert into subMovingNomenclatureInfo([IdDoc],[LineNumber],[PalletCode],[Nomenclature], [PlanValue],[FactValue],[RowState],[RowDate], [StartCodeOfPreviousPallet] ,[FinalCodeOfPreviousPallet], [StartCell],[FinalCell], [Party], [Employee]) select @IdDoc, [LineNumber],[PalletCode],[Nomenclature], [PlanValue],[FactValue],[RowState],[RowDate], [StartCodeOfPreviousPallet] ,[FinalCodeOfPreviousPallet], [StartCell],[FinalCell], [Party], [Employee] from @table"); q.AddInputTVPParameter("table", rowsToInsert, "dbo.tvp_Moving_NomenclatureInfo"); q.AddInputParameter("IdDoc", documentId); q.Execute(); return q.ThrowedException == null; }
public bool SetBarcode(string barcode, long stickerId, out bool recordWasAdded) { var sticker = new Stickers() { ReadingId = stickerId }; var nomenclatureId = sticker.GetRef("Nomenclature"); DataTable allWares; GetWares(barcode, SelectionFilters.All, out allWares); foreach (DataRow row in allWares.Rows) { var barcodeAlreadyAttached = (long)row["Id"] == nomenclatureId; if (barcodeAlreadyAttached) { recordWasAdded = false; return true; } } var barcodeRecord = new Barcodes() { Description = barcode }; barcodeRecord.SetRef("Nomenclature", nomenclatureId); recordWasAdded = barcodeRecord.Write() == WritingResult.Success; return recordWasAdded; }
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); }
public bool GetPickingTask(long documentId, long palletId, int predefinedTaskLineNumber, int currentLineNumber, out long stickerId, out long wareId, out string wareDescription, out long cellId, out string cellDescription, out long partyId, out DateTime productionDate, out int unitsPerBox, out int unitsToPick, out int lineNumber) { const string sql = @" select top 1 cap.[State], task.PalletCode stickerId, task.LineNumber, task.Nomenclature wareId, rtrim(n.[description]) wareDescription, task.StartCell cellId, ISNULL(rtrim(c.[Description]), '') cellDescription, task.Party partyId, isnull(p.DateOfManufacture, '0001-01-01') productionDate, n.UnitsQuantityPerPack unitsPerBox, task.PlanValue unitsToPick from SubMovingNomenclatureInfo task join Nomenclature n on n.Id = task.Nomenclature left join Cells c on c.Id = task.StartCell left join Parties p on p.Id = task.Party join Moving cap on cap.Id = task.IdDoc where IdDoc = @IdDoc and (RowState = @PlannedPickingState or (RowState = @ProcessingState and Employee = @userId)) and (@currentLineNumber = 0 or task.LineNumber = @currentLineNumber) and (@nomenclature = 0 or task.Nomenclature = @nomenclature) order by [LineNumber]"; var q = DB.NewQuery(sql); q.AddInputParameter("IdDoc", documentId); q.AddInputParameter("PlannedPickingState", RowsStates.PlannedPicking); q.AddInputParameter("ProcessingState", RowsStates.Processing); q.AddInputParameter("userId", getUserId()); q.AddInputParameter("currentLineNumber", predefinedTaskLineNumber); var nomenclatureId = 0L; if (palletId != 0) { var sticker = new Stickers() { ReadingId = palletId }; nomenclatureId = sticker.GetRef("Nomenclature"); } q.AddInputParameter("nomenclature", nomenclatureId); stickerId = wareId = cellId = partyId = unitsToPick = unitsPerBox = lineNumber = 0; wareDescription = cellDescription = string.Empty; productionDate = DateTime.MinValue; // � ���������� ����� ������������� �������� ������ � ���������� �������� palletId, � ����� � �� ������������� using (var locker = new DatabaseObjectLocker(typeof(Moving), documentId)) { if (!locker.LockForCurrentPdtThread()) return false; var qResult = q.SelectRow(); if (qResult == null) { return true; } var documentState = (StatesOfDocument)Convert.ToInt32(qResult["State"]); if (documentState == StatesOfDocument.Planned) { var moving = new Moving() { ReadingId = documentId }; moving.State = StatesOfDocument.Processing; moving.Write(); } stickerId = Convert.ToInt64(qResult["stickerId"]); wareId = Convert.ToInt64(qResult["wareId"]); wareDescription = qResult["wareDescription"].ToString(); cellId = Convert.ToInt64(qResult["cellId"]); cellDescription = qResult["cellDescription"].ToString(); partyId = Convert.ToInt64(qResult["partyId"]); productionDate = (DateTime)qResult["productionDate"]; unitsPerBox = Convert.ToInt32(qResult["unitsPerBox"]); unitsToPick = Convert.ToInt32(qResult["unitsToPick"]); lineNumber = Convert.ToInt32(qResult["LineNumber"]); if (currentLineNumber > 0) { documentId.SetRowState(typeof(Moving), currentLineNumber, RowsStates.PlannedPicking); } documentId.SetRowState(typeof(Moving), lineNumber, RowsStates.Processing, employee: getUserId()); } return true; }
internal bool WriteStickerFact(long stickerId, long cellId, long previousStickerId, long trayId, long linerId, int linersQuantity, int packsCount, int unitsCount) { var goodsRows = findStickerRows(stickerId); var isReturnFromHaul = Contractor.Empty; if (isReturnFromHaul) { var sticker = new Stickers() { ReadingId = stickerId }; if (goodsRows.WareRow == null) { goodsRows.WareRow = addNewNomenclatureRow(stickerId, sticker.GetRef("Nomenclature")); goodsRows.WareRow[NomenclatureParty] = sticker.GetRef("Party"); } if (packsCount > 0 && goodsRows.BoxRow == null) { var packId = sticker.Nomenclature.GetRef("BoxType"); if (packId > 0) { goodsRows.BoxRow = addNewNomenclatureRow(stickerId, packId); } } } setFactOnRow(goodsRows.WareRow, unitsCount, cellId, false); goodsRows.WareRow[PreviousPalletCode] = previousStickerId; if (goodsRows.BoxRow != null) { setFactOnRow(goodsRows.BoxRow, packsCount, cellId, true); } if (linersQuantity > 0 && linerId > 0) { if (goodsRows.LinerRow == null) { goodsRows.LinerRow = addNewNomenclatureRow(stickerId, linerId); } setFactOnRow(goodsRows.LinerRow, linersQuantity, cellId, true); } int traysQuantity = trayId > 0 ? 1 : 0; if (goodsRows.TrayRow == null && traysQuantity > 0) { goodsRows.TrayRow = addNewNomenclatureRow(stickerId, trayId); } if (goodsRows.TrayRow != null) { setFactOnRow(goodsRows.TrayRow, traysQuantity, cellId, true); } SetSubtableModified(NomenclatureInfo.TableName); var result = Write() == WritingResult.Success; return result; }