/// <summary> /// Adds a new record into the <c>GenerationRequest</c> table. /// </summary> /// <param name="value">The <see cref="GenerationRequestRow"/> object to be inserted.</param> public virtual void Insert(GenerationRequestRow value) { string sqlStr = "INSERT INTO [dbo].[GenerationRequest] (" + "[request_id], " + "[date_requested], " + "[date_to_process], " + "[number_of_batches], " + "[batch_size], " + "[lot_id]" + ") VALUES (" + _db.CreateSqlParameterName("Request_id") + ", " + _db.CreateSqlParameterName("Date_requested") + ", " + _db.CreateSqlParameterName("Date_to_process") + ", " + _db.CreateSqlParameterName("Number_of_batches") + ", " + _db.CreateSqlParameterName("Batch_size") + ", " + _db.CreateSqlParameterName("Lot_id") + ")"; IDbCommand cmd = _db.CreateCommand(sqlStr); AddParameter(cmd, "Request_id", value.Request_id); AddParameter(cmd, "Date_requested", value.Date_requested); AddParameter(cmd, "Date_to_process", value.Date_to_process); AddParameter(cmd, "Number_of_batches", value.Number_of_batches); AddParameter(cmd, "Batch_size", value.Batch_size); AddParameter(cmd, "Lot_id", value.Lot_id); cmd.ExecuteNonQuery(); }
public static bool AddLot(RetailAccountGenResponse pResponse, PersonDto pPerson) { bool _result = false; using (var _db = new Rbr_Db()) { _db.BeginTransaction(); try { InventoryLotRow _lotRow = _db.InventoryLotCollection.GetByServiceIdDenomination(pResponse.Request.ServiceId, pResponse.Request.Denomination); if (_lotRow == null) { _lotRow = new InventoryLotRow(); _lotRow.Service_id = pResponse.Request.ServiceId; _lotRow.Denomination = pResponse.Request.Denomination; _db.InventoryLotCollection.Insert(_lotRow); } var _requestRow = new GenerationRequestRow(); _requestRow.Date_requested = DateTime.Now; _requestRow.Date_completed = DateTime.Now; _requestRow.Date_to_process = DateTime.Now; _requestRow.Number_of_batches = pResponse.Request.NumberOfBatches; _requestRow.Batch_size = pResponse.Request.BatchSize; _requestRow.Lot_id = _lotRow.Lot_id; _db.GenerationRequestCollection.Insert(_requestRow); foreach (var _batch in pResponse.BatchList) { var _batchRow = new BatchRow(); _batchRow.Batch_id = _batch.BatchId; _batchRow.First_serial = _batch.FirstSerial; _batchRow.Last_serial = _batch.LastSerial; _batchRow.Request_id = _requestRow.Request_id; //_batchRow.Box_id = ???? xxx; NOT SET for now //_batchRow.Customer_acct_id = WILL BE SET ON LOAD/ACTIVATE; _batchRow.InventoryStatus = InventoryStatus.Generated; _db.BatchCollection.Insert(_batchRow); logInventoryHistory(_db, pPerson, DateTime.Now, _lotRow.Service_id, _lotRow.Denomination, _batchRow.Batch_id, _batchRow.NumberOfCards, InventoryCommand.Generate, 0, //CustomerAcctId - N/A FOR THIS COMMAND 0, //ResellerPartnerId - N/A FOR THIS COMMAND 0 //ResellerAgentId - N/A FOR THIS COMMAND ); } _db.CommitTransaction(); _result = true; } catch (Exception _ex) { _db.RollbackTransaction(); TimokLogger.Instance.LogRbr(LogSeverity.Critical, "InventoryController.AddLot", string.Format("Exception: {0}", _ex)); } } return(_result); }
/// <summary> /// Reads data from the provided data reader and returns /// an array of mapped objects. /// </summary> /// <param name="reader">The <see cref="System.Data.IDataReader"/> object to read data from the table.</param> /// <param name="startIndex">The index of the first record to map.</param> /// <param name="length">The number of records to map.</param> /// <param name="totalRecordCount">A reference parameter that returns the total number /// of records in the reader object if 0 was passed into the method; otherwise it returns -1.</param> /// <returns>An array of <see cref="GenerationRequestRow"/> objects.</returns> protected virtual GenerationRequestRow[] MapRecords(IDataReader reader, int startIndex, int length, ref int totalRecordCount) { if (0 > startIndex) { throw new ArgumentOutOfRangeException("startIndex", startIndex, "StartIndex cannot be less than zero."); } if (0 > length) { throw new ArgumentOutOfRangeException("length", length, "Length cannot be less than zero."); } int request_idColumnIndex = reader.GetOrdinal("request_id"); int date_requestedColumnIndex = reader.GetOrdinal("date_requested"); int date_to_processColumnIndex = reader.GetOrdinal("date_to_process"); int date_completedColumnIndex = reader.GetOrdinal("date_completed"); int number_of_batchesColumnIndex = reader.GetOrdinal("number_of_batches"); int batch_sizeColumnIndex = reader.GetOrdinal("batch_size"); int lot_idColumnIndex = reader.GetOrdinal("lot_id"); System.Collections.ArrayList recordList = new System.Collections.ArrayList(); int ri = -startIndex; while (reader.Read()) { ri++; if (ri > 0 && ri <= length) { GenerationRequestRow record = new GenerationRequestRow(); recordList.Add(record); record.Request_id = Convert.ToInt32(reader.GetValue(request_idColumnIndex)); record.Date_requested = Convert.ToDateTime(reader.GetValue(date_requestedColumnIndex)); record.Date_to_process = Convert.ToDateTime(reader.GetValue(date_to_processColumnIndex)); if (!reader.IsDBNull(date_completedColumnIndex)) { record.Date_completed = Convert.ToDateTime(reader.GetValue(date_completedColumnIndex)); } record.Number_of_batches = Convert.ToInt32(reader.GetValue(number_of_batchesColumnIndex)); record.Batch_size = Convert.ToInt32(reader.GetValue(batch_sizeColumnIndex)); record.Lot_id = Convert.ToInt32(reader.GetValue(lot_idColumnIndex)); if (ri == length && 0 != totalRecordCount) { break; } } } totalRecordCount = 0 == totalRecordCount ? ri + startIndex : -1; return((GenerationRequestRow[])(recordList.ToArray(typeof(GenerationRequestRow)))); }
/// <summary> /// Converts <see cref="System.Data.DataRow"/> to <see cref="GenerationRequestRow"/>. /// </summary> /// <param name="row">The <see cref="System.Data.DataRow"/> object to be mapped.</param> /// <returns>A reference to the <see cref="GenerationRequestRow"/> object.</returns> protected virtual GenerationRequestRow MapRow(DataRow row) { GenerationRequestRow mappedObject = new GenerationRequestRow(); DataTable dataTable = row.Table; DataColumn dataColumn; // Column "Request_id" dataColumn = dataTable.Columns["Request_id"]; if (!row.IsNull(dataColumn)) { mappedObject.Request_id = (int)row[dataColumn]; } // Column "Date_requested" dataColumn = dataTable.Columns["Date_requested"]; if (!row.IsNull(dataColumn)) { mappedObject.Date_requested = (System.DateTime)row[dataColumn]; } // Column "Date_to_process" dataColumn = dataTable.Columns["Date_to_process"]; if (!row.IsNull(dataColumn)) { mappedObject.Date_to_process = (System.DateTime)row[dataColumn]; } // Column "Date_completed" dataColumn = dataTable.Columns["Date_completed"]; if (!row.IsNull(dataColumn)) { mappedObject.Date_completed = (System.DateTime)row[dataColumn]; } // Column "Number_of_batches" dataColumn = dataTable.Columns["Number_of_batches"]; if (!row.IsNull(dataColumn)) { mappedObject.Number_of_batches = (int)row[dataColumn]; } // Column "Batch_size" dataColumn = dataTable.Columns["Batch_size"]; if (!row.IsNull(dataColumn)) { mappedObject.Batch_size = (int)row[dataColumn]; } // Column "Lot_id" dataColumn = dataTable.Columns["Lot_id"]; if (!row.IsNull(dataColumn)) { mappedObject.Lot_id = (int)row[dataColumn]; } return(mappedObject); }
/// <summary> /// Updates a record in the <c>GenerationRequest</c> table. /// </summary> /// <param name="value">The <see cref="GenerationRequestRow"/> /// object used to update the table record.</param> /// <returns>true if the record was updated; otherwise, false.</returns> public virtual bool Update(GenerationRequestRow value) { string sqlStr = "UPDATE [dbo].[GenerationRequest] SET " + "[date_requested]=" + _db.CreateSqlParameterName("Date_requested") + ", " + "[date_to_process]=" + _db.CreateSqlParameterName("Date_to_process") + ", " + "[number_of_batches]=" + _db.CreateSqlParameterName("Number_of_batches") + ", " + "[batch_size]=" + _db.CreateSqlParameterName("Batch_size") + ", " + "[lot_id]=" + _db.CreateSqlParameterName("Lot_id") + " WHERE " + "[request_id]=" + _db.CreateSqlParameterName("Request_id"); IDbCommand cmd = _db.CreateCommand(sqlStr); AddParameter(cmd, "Date_requested", value.Date_requested); AddParameter(cmd, "Date_to_process", value.Date_to_process); AddParameter(cmd, "Number_of_batches", value.Number_of_batches); AddParameter(cmd, "Batch_size", value.Batch_size); AddParameter(cmd, "Lot_id", value.Lot_id); AddParameter(cmd, "Request_id", value.Request_id); return(0 != cmd.ExecuteNonQuery()); }
internal static BatchDto MapToBatch(BatchRow pBatchRow, InventoryLotRow pInventoryLotRow, GenerationRequestRow pGenerationRequestRow) { if (pBatchRow == null || pInventoryLotRow == null || pGenerationRequestRow == null) { return(null); } var _batch = new BatchDto(); _batch.BatchId = pBatchRow.Batch_id; _batch.InventoryStatus = pBatchRow.InventoryStatus; _batch.BoxId = pBatchRow.Box_id; _batch.CustomerAcctId = pBatchRow.Customer_acct_id; _batch.FirstSerial = pBatchRow.First_serial; _batch.LastSerial = pBatchRow.Last_serial; _batch.RequestId = pBatchRow.Request_id; _batch.Selected = false; _batch.LotId = pInventoryLotRow.Lot_id; _batch.ServiceId = pInventoryLotRow.Service_id; _batch.Denomination = pInventoryLotRow.Denomination; _batch.NumberOfBatches = pGenerationRequestRow.Number_of_batches; _batch.BatchSize = pGenerationRequestRow.Batch_size; _batch.DateRequested = pGenerationRequestRow.Date_requested; _batch.DateToProcess = pGenerationRequestRow.Date_to_process; _batch.DateCopleted = pGenerationRequestRow.Date_completed; return(_batch); }
internal static BatchDto[] MapToBatches(BatchRow[] pBatchRows, InventoryLotRow pInventoryLotRow, GenerationRequestRow pGenerationRequestRow) { var _list = new ArrayList(); foreach (var _batchRow in pBatchRows) { _list.Add(MapToBatch(_batchRow, pInventoryLotRow, pGenerationRequestRow)); } return((BatchDto[])_list.ToArray(typeof(BatchDto))); }
/// <summary> /// Deletes the specified object from the <c>GenerationRequest</c> table. /// </summary> /// <param name="value">The <see cref="GenerationRequestRow"/> object to delete.</param> /// <returns>true if the record was deleted; otherwise, false.</returns> public bool Delete(GenerationRequestRow value) { return(DeleteByPrimaryKey(value.Request_id)); }