Пример #1
0
        public void Resolve()
        {
            switch (this.Direction)
            {
                case Enums.VOIPUsageDirection.Incomming:
                {
                    this._temp_type = qnaxLib.Enums.RangePriceType.Any;
                    this._temp_costprice = 0;
                    this._temp_retailprice = 0;
                    break;
                }

                case Enums.VOIPUsageDirection.Outgoing:
                {
                    string anumber = Regex.Replace (this._anumber, "^(0)*", string.Empty);
                    string bnumber = Regex.Replace (this._bnumber, "^(0)*", string.Empty);
                    Enums.NumberType anumbertype =  qnaxLib.Enums.NumberType.Landline;
                    Enums.NumberType bnumbertype =  qnaxLib.Enums.NumberType.Landline;
                    Enums.RangePriceType rangepricetype = qnaxLib.Enums.RangePriceType.Any;

                    int duration  = this._duration;

                    RangeGroup rangegroup = RangeGroup.FindByNumber (bnumber);
                    Range range = Range.FindByNumber (bnumber);
                    List<RangePrice> costprices = new List<RangePrice> ();
                    List<RangePrice> retailprices = new List<RangePrice> ();

                    if (range != null)
                    {
                        costprices = range.CostPrices;
                        retailprices = range.RetailPrices;
                        bnumbertype = range.Type;
                        if (!range.CountryCode.DialCodes.Contains ("45"))
                        {
                            this._temp_international = true;
                        }

                        _temp_range = range;
                    }

                    if (rangegroup != null)
                    {
                        costprices = rangegroup.CostPrices;
                        retailprices = rangegroup.RetailPrices;
                    }

                    #region SET RANGEPRICETYPE
                    switch (anumbertype)
                    {
                        case Enums.NumberType.Landline:
                        {
                            if (bnumbertype == qnaxLib.Enums.NumberType.Landline)
                            {
                                rangepricetype = qnaxLib.Enums.RangePriceType.LTL;
                            }
                            else
                            {
                                rangepricetype = qnaxLib.Enums.RangePriceType.LTM;
                            }
                            break;
                        }

                        case Enums.NumberType.Mobile:
                        {
                            if (bnumbertype == qnaxLib.Enums.NumberType.Landline)
                            {
                                rangepricetype = qnaxLib.Enums.RangePriceType.MTL;
                            }
                            else
                            {
                                rangepricetype = qnaxLib.Enums.RangePriceType.MTM;
                            }
                            break;
                        }
                    }
                    #endregion

                    #region CREATE INTERVALS
                    decimal costdialcharge = 0;
                    decimal retaildialcharge = 0;
                    decimal cost = 0;
                    decimal retail = 0;

                    bool lala = false;

                    List<DateTime> interval = new List<DateTime> ();
                    {
                        DateTime tick = SNDK.Date.TimestampToDateTime (this._timestamp);

                        if (lala)
                        {
                            for (int count = 0; count < duration; count++)
                            {
                                interval.Add (tick.AddSeconds (count));
                            }
                        }
                        else
                        {
                            for (int count = 0; count < duration; count += 60)
                            {
                                tick = tick.AddMinutes (1);
                                interval.Add (tick);
                            }
                        }
                    }

                    foreach (DateTime t in interval)
                    {
                        string ti = t.ToString ("HH:mm");
                        foreach (RangePrice rp in costprices)
                        {
                            if (rangepricetype == rp.Type)
                            {
                                if ((int.Parse (ti.Replace (":", string.Empty))) >= (int.Parse (rp.HourBegin.Replace (":", string.Empty))))
                                {
                                    if ((int.Parse (ti.Replace (":", string.Empty))) <= (int.Parse (rp.HourEnd.Replace (":", string.Empty))))
                                    {
                                        if (lala)
                                        {
                                            cost += rp.Price / 60;
                                        }
                                        else
                                        {
                                            cost += rp.Price;
                                        }
                                        break;
                                    }
                                }
                            }
                        }

                        foreach (RangePrice rp in retailprices)
                        {
                            if (rangepricetype == rp.Type)
                            {
                                if ((int.Parse (ti.Replace (":", string.Empty))) >= (int.Parse (rp.HourBegin.Replace (":", string.Empty))))
                                {
                                    if ((int.Parse (ti.Replace (":", string.Empty))) <= (int.Parse (rp.HourEnd.Replace (":", string.Empty))))
                                    {
                                        if (lala)
                                        {
                                            retail += rp.Price / 60;
                                        }
                                        else
                                        {
                                            retail += rp.Price;
                                        }
                                        break;
                                    }
                                }
                            }
                        }
                    }

            //					foreach (DateTime t2 in interval)
            //					{
            //						Console.WriteLine (t2);
            //					}
            //
            //
            //					Environment.Exit (0);

            //					List<string> interval = new List<string> ();
            //
            //					string time = SNDK.Date.TimestampToDateTime (this._timestamp).ToString ("HH:mm");
            //					interval.Add (time);
            //
            //					int i2 = 0;
            //					int i3 = 0;
            //					for (int i = 0; i < duration; i++)
            //					{
            //						bool change = false;
            //						string[] split = time.Split (":".ToCharArray ());
            //
            //						int h = int.Parse (split[0]);
            //						int m = int.Parse (split[1]);
            //
            //						if (i2 > 59)
            //						{
            //							i2 = 0;
            //							m++;
            //
            //							if (m > 59)
            //							{
            //								m = 0;
            //								h++;
            //							}
            //
            //							if (h > 23)
            //							{
            //								h = 0;
            //							}
            //
            //							change = true;
            //						}
            //
            //						if (change)
            //						{
            //							time = string.Empty;
            //							if (h < 10)
            //							{
            //								time += "0"+ h.ToString () +":";
            //							}
            //							else
            //							{
            //								time += h.ToString () +":";
            //							}
            //
            //							if (m < 10)
            //							{
            //								time += "0"+ m.ToString ();
            //							}
            //							else
            //							{
            //								time += m.ToString ();
            //							}
            //
            //							interval.Add (time);
            //						}
            //
            //						i2++;
            //						i3++;
            //					}
                    #endregion

                    #region CALCULATE RANGEPRICES
            //					foreach (string ti in interval)
            //					{
            //						foreach (RangePrice rp in costprices)
            //						{
            //							if (rangepricetype == rp.Type)
            //							{
            //								if ((int.Parse (ti.Replace (":", string.Empty))) >= (int.Parse (rp.HourBegin.Replace (":", string.Empty))))
            //								{
            //									if ((int.Parse (ti.Replace (":", string.Empty))) <= (int.Parse (rp.HourEnd.Replace (":", string.Empty))))
            //									{
            //										cost += rp.Price;
            //										break;
            //									}
            //								}
            //							}
            //						}
            //
            //						foreach (RangePrice rp in retailprices)
            //						{
            //							if (rangepricetype == rp.Type)
            //							{
            //								if ((int.Parse (ti.Replace (":", string.Empty))) >= (int.Parse (rp.HourBegin.Replace (":", string.Empty))))
            //								{
            //									if ((int.Parse (ti.Replace (":", string.Empty))) <= (int.Parse (rp.HourEnd.Replace (":", string.Empty))))
            //									{
            //										retail += rp.Price;
            //										break;
            //									}
            //								}
            //							}
            //						}
            //					}
                    #endregion

                    #region CALCULATE DIALCHARGE
            //					if (this.Status != qnaxLib.Enums.VOIPUsageStatus.Failed)
                    {
                        string ti = SNDK.Date.TimestampToDateTime (this._timestamp).ToString ("HH:mm");

                        foreach (RangePrice rp in costprices)
                        {
                            if (rangepricetype == rp.Type)
                            {
                                if ((int.Parse (ti.Replace (":", string.Empty))) >= (int.Parse (rp.HourBegin.Replace (":", string.Empty))))
                                {
                                    if ((int.Parse (ti.Replace (":", string.Empty))) <= (int.Parse (rp.HourEnd.Replace (":", string.Empty))))
                                    {
                                        costdialcharge += rp.CallCharge;
                                        break;
                                    }
                                }
                            }
                        }

                        foreach (RangePrice rp in retailprices)
                        {
                            if (rangepricetype == rp.Type)
                            {
                                if ((int.Parse (ti.Replace (":", string.Empty))) >= (int.Parse (rp.HourBegin.Replace (":", string.Empty))))
                                {
                                    if ((int.Parse (ti.Replace (":", string.Empty))) <= (int.Parse (rp.HourEnd.Replace (":", string.Empty))))
                                    {
                                        retaildialcharge += rp.CallCharge;
                                        break;
                                    }
                                }
                            }
                        }
                    }
                    #endregion

            //					Console.WriteLine (bnumber +" "+ retail +" "+ this._temp_international);

            //					Console.WriteLine (retail);
                    this._temp_costdialcharge = costdialcharge;
                    this._temp_retaildialcharge = retaildialcharge;
                    this._temp_costprice = cost;
                    this._temp_retailprice = retail;
                    this._temp_type = rangepricetype;

                    break;
                }
            }

            this._temp_resolved = true;
        }
Пример #2
0
        public static Range FromXmlDocument(XmlDocument xmlDocument)
        {
            Hashtable item = (Hashtable)SNDK.Convert.FromXmlDocument (xmlDocument);

            Range result;

            if (item.ContainsKey ("id"))
            {
                try
                {
                    result = Range.Load (new Guid ((string)item["id"]));
                }
                catch
                {
                    result = new Range ();
                    result._id = new Guid ((string)item["id"]);
                }
            }
            else
            {
                result = new Range ();
            }

            if (item.ContainsKey ("name"))
            {
                result.Name = (string)item["name"];
            }

            if (item.ContainsKey ("countrycodeid"))
            {
                result._countrycodeid = new Guid ((string)item["countrycodeid"]);
            }

            if (item.ContainsKey ("type"))
            {
                result._type = SNDK.Convert.StringToEnum<Enums.NumberType> ((string)item["type"]);
            }

            if (item.ContainsKey ("dialcodes"))
            {
                try
                {
                result._dialcodes.Clear ();
                foreach (XmlDocument dialcode in (List<XmlDocument>)item["dialcodes"])
                {
                    result._dialcodes.Add ((string)((Hashtable)SNDK.Convert.FromXmlDocument (dialcode))["value"]);
                }
                }
                catch
                {}
            }

            return result;
        }
Пример #3
0
        private static Range Load(Guid id, string dialcode)
        {
            bool success = false;
            Range result = new Range ();

            QueryBuilder qb = new QueryBuilder (QueryBuilderType.Select);
            qb.Table (DatabaseTableName);
            qb.Columns
                (
                    "id",
                    "createtimestamp",
                    "updatetimestamp",
                    "countrycodeid",
                    "type",
                    "name",
                    "dialcodes",
                    "costpriceids"
                );

            if (id != Guid.Empty)
            {
                qb.AddWhere ("id", "=", id);
            }
            else if (dialcode != string.Empty)
            {
                qb.AddWhere ("dialcodes like '%"+ dialcode +";%'");
            }

            Query query = Runtime.DBConnection.Query (qb.QueryString);

            if (query.Success)
            {
                if (query.NextRow ())
                {
                    result._id = query.GetGuid (qb.ColumnPos ("id"));
                    result._createtimestamp = query.GetInt (qb.ColumnPos ("createtimestamp"));
                    result._updatetimestamp = query.GetInt (qb.ColumnPos ("updatetimestamp"));
                    result._countrycodeid = query.GetGuid (qb.ColumnPos ("countrycodeid"));
                    result._type = query.GetEnum<Enums.NumberType> (qb.ColumnPos ("type"));
                    result._name = query.GetString (qb.ColumnPos ("name"));
                    result._dialcodes = SNDK.Convert.StringToList<string> (query.GetString (qb.ColumnPos ("dialcodes")));
                    result._costpriceids = SNDK.Convert.StringToList<Guid> (query.GetString (qb.ColumnPos ("costpriceids")));

                    success = true;
                }
            }

            query.Dispose ();
            query = null;
            qb = null;

            if (!success)
            {
                throw new Exception (string.Format (Strings.Exception.RangeLoad, id));
            }

            return result;
        }
Пример #4
0
        public static List<RangePrice> List(Range Range)
        {
            List<RangePrice> result = new List<RangePrice> ();

            QueryBuilder qb = new QueryBuilder (QueryBuilderType.Select);
            qb.Table (DatabaseTableName);
            qb.Columns ("id");

            Query query = Runtime.DBConnection.Query (qb.QueryString);
            if (query.Success)
            {
                while (query.NextRow ())
                {
                    try
                    {
                        result.Add (Load (query.GetGuid (qb.ColumnPos ("id"))));
                    }
                    catch
                    {}
                }
            }

            query.Dispose ();
            query = null;
            qb = null;

            return result;
        }