Beispiel #1
0
        public bool UpdateVolumes(VolumeList volumes, int periodTy, int periodID, bool IsCurrent)
        {
            //need to decide if we're going to do partial loads/deltas

            if (Configuration == null)
            {
                throw new Exception("Configuration object not set up");
            }

            if (Configuration.VolumeConfig == null)
            {
                throw new Exception("Volume Configuration not set up");
            }


            VolumeConfiguration config = Configuration.VolumeConfig;
            int bucketCount            = config.VolumeFields.Count;

            SqlConnection conn = GetConnection();
            IDataReader   rd   = null;

            try
            {
                BeginTrace("UpdateVolumes");

                volumes.Clear();

                SqlCommand cmd = GetVolumeCommand(conn, config, periodTy, periodID);

                rd = cmd.ExecuteReader();

                while (rd.Read())
                {
                    Volume sv = new Volume(bucketCount);

                    PopulateVolumeFromReader(rd, sv, config);

                    Customer c = null;
                    if (Customers.TryGetValue(sv.CustomerID, out c) && IsCurrent)
                    {
                        c.Volume = sv;
                    }
                    volumes.Add(rd.GetInt32(0), sv);
                }
                EndTrace("UpdateVolumes", $"PeriodVolume Refresh PeriodTy {periodTy}, PeriodID {periodID}");
            }
            finally
            {
                if (rd != null)
                {
                    rd.Close();
                }
                ReturnConnection(conn);
            }
            return(true);
        }
Beispiel #2
0
        private void PopulateVolumeFromReader(IDataReader rd, Volume sv, VolumeConfiguration config)
        {
            sv.CustomerID = rd.GetInt32(0);
            sv.RankID     = rd.GetInt32(1);
            sv.PaidRankID = rd.GetInt32(2);

            int cnt = 3;

            foreach (var f in config.VolumeFields)
            {
                //sv[cnt-2] = rd.GetDecimal(cnt++);
                sv[f.VolumeID] = rd.GetDecimal(cnt++);
            }
        }
Beispiel #3
0
        private SqlCommand GetVolumeCommand(SqlConnection conn, VolumeConfiguration vc, int PeriodTypeID, int PeriodID)
        {
            SqlCommand cmd = new SqlCommand();

            cmd.Connection = conn;

            StringBuilder sb = new StringBuilder("Select CustomerID, RankID, PaidRankID, ");

            foreach (var f in vc.VolumeFields)
            {
                sb.Append(f.FieldName + ",");
            }
            sb.Remove(sb.Length - 1, 1);
            sb.Append(" from PeriodVolumes where PeriodTypeID = @PeriodTypeID and PeriodID=@PeriodID");
            cmd.CommandText = sb.ToString();
            cmd.Parameters.Add("@PeriodTypeID", SqlDbType.Int).Value = PeriodTypeID;
            cmd.Parameters.Add("@PeriodID", SqlDbType.Int).Value     = PeriodID;
            return(cmd);
        }