// use ordinals to speed up access to DataReader
 // links:
 //  crud definition: https://en.wikipedia.org/wiki/Create,_read,_update_and_delete
 //  docLink: http://sql2x.org/documentationLink/327451c3-64a8-4de8-b359-76742d634497
 // parameters:
 //  reader: IDataReader from SQLClient
 public void Populate(IDataReader reader, TransactionsCreditDebitBalanceDataOrdinals ordinals)
 {
     if (!reader.IsDBNull(ordinals.Date))
     {
         Date = reader.GetString(ordinals.Date);
     }
     if (!reader.IsDBNull(ordinals.DebitAmount))
     {
         DebitAmount = reader.GetDecimal(ordinals.DebitAmount);
     }
     if (!reader.IsDBNull(ordinals.CreditAmount))
     {
         CreditAmount = reader.GetDecimal(ordinals.CreditAmount);
     }
 }
Пример #2
0
        /// <summary>Get credit debit transaction balances pr day</summary>
        /// <cardinality>Many</cardinality>
        public List <TransactionsCreditDebitBalanceData> TransactionsCreditDebitBalance(
            DateTime fromDateTime,
            DateTime untilDateTime
            )
        {
            var ret = new List <TransactionsCreditDebitBalanceData>();

            string sql = @" 
                    select top 50
                            cast(datepart(year, fl.from_date_time)	as char(4))
						  + cast(datepart(month, fl.from_date_time) as varchar(2))
						  + cast(datepart(day, fl.from_date_time)	as varchar(2))	as date
						,(	select sum(fbt.amount)						
							from financial_booking_transaction	as fbt
							where 
									datepart(year, fbt.date_time) = datepart(year, fl.from_date_time)
								and datepart(month, fbt.date_time) = datepart(month, fl.from_date_time)
								and datepart(day, fbt.date_time) = datepart(day, fl.from_date_time)
								and fbt.financial_payment_id is null
								and fbt.financial_adjustment_id is null
						  )											as debit_amount
						,(	select sum(fbt.amount)						
							from financial_booking_transaction	as fbt
							where 
									datepart(year, fbt.date_time) = datepart(year, fl.from_date_time)
								and datepart(month, fbt.date_time) = datepart(month, fl.from_date_time)
								and datepart(day, fbt.date_time) = datepart(day, fl.from_date_time)
						      and (fbt.financial_payment_id is not null
                                or fbt.financial_adjustment_id is not null)
						  )											as credit_amount

                    from flight as fl
                    --realwhere
                    where fl.from_date_time between @from_date_time and @until_date_time
                      and fl.became_flight_id is null
					group by 
                         datepart(year, fl.from_date_time)
						,datepart(month, fl.from_date_time)
						,datepart(day, fl.from_date_time)
						
					order by
						 datepart(year, fl.from_date_time)
						,datepart(month, fl.from_date_time)
						,datepart(day, fl.from_date_time)
                ";

            using (var conn = new SqlConnection(Conn.ConnectionString)) {
                conn.Open();
                conn.BeginTransaction(IsolationLevel.ReadUncommitted).Commit();

                using (var command = new SqlCommand(sql, conn)) {
                    command.Parameters.Add("@from_date_time", SqlDbType.DateTime).Value  = fromDateTime;
                    command.Parameters.Add("@until_date_time", SqlDbType.DateTime).Value = untilDateTime;

                    Logging log = Logging.PerformanceTimeStart("SolutionNorSolutionPort.DataAccessLayer.FlightSearch.TransactionsCreditDebitBalance");

                    IDataReader reader = command.ExecuteReader(CommandBehavior.SingleResult);

                    log.PerformanceTimeStop(sql, command);

                    var ordinals = new TransactionsCreditDebitBalanceDataOrdinals(reader);

                    while (reader.Read())
                    {
                        var data = new TransactionsCreditDebitBalanceData();
                        data.Populate(reader, ordinals);
                        ret.Add(data);
                    }

                    reader.Close();
                }

                return(ret);
            }
        }