public RangePrice() { this._id = Guid.NewGuid (); this._createtimestamp = SNDK.Date.CurrentDateTimeToTimestamp (); this._updatetimestamp = SNDK.Date.CurrentDateTimeToTimestamp (); this._validfrom = System.DateTime.Now; this._validto = System.DateTime.Now.AddYears (1); this._type = qnaxLib.Enums.RangePriceType.Any; this._price = 0; this._hourbegin = "00:00"; this._hourend = "23:59"; this._weekdays = qnaxLib.Enums.Weekday.Monday | qnaxLib.Enums.Weekday.Tuesday | qnaxLib.Enums.Weekday.Wednesday | qnaxLib.Enums.Weekday.Thursday | qnaxLib.Enums.Weekday.Friday | qnaxLib.Enums.Weekday.Saturday | qnaxLib.Enums.Weekday.Sunday; }
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; }