public void LoadSelectedConversionData(GenderId gender, ConversionId conversion, string region, BrandId brand)
 {
     this.SelectedConversionData = this.conversiondsDB.ConversionData.Where(c => c.Gender == gender &&
                                                                            c.Conversion == conversion &&
                                                                            c.Region == region &&
                                                                            c.Brand == brand).FirstOrDefault();
 }
        public void NominateConversion(ConversionId cId)
        {
            List <MeasurementId> missingMeasurementIds = this.Conversions[cId].MissingMeasurements;

            foreach (Measurement m in this.FullMeasurements)
            {
                m.IsNeeded = missingMeasurementIds.Contains(m.MeasurementId);
            }
            this.PendingCurrentNominatedConversion = cId;
        }
        protected async override void OnNavigatedTo(NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);


            // Load up the data using a query string in case of tombstoning
            string profileIdStr, conversionIdStr;

            NavigationContext.QueryString.TryGetValue("ProfileId", out profileIdStr);
            int profileId = System.Int32.Parse(profileIdStr);

            NavigationContext.QueryString.TryGetValue("ConversionId", out conversionIdStr);
            ConversionId conversionId = (ConversionId)Enum.Parse(typeof(ConversionId), conversionIdStr, true);

            if (App.VM.GroupedConversions == null ||
                !App.VM.SkipLoadConversionPageData)
            {
                if (App.VM.SkipLoadConversionPageData)
                {
                    App.VM.SkipLoadConversionPageData = false;
                }
                await App.VM.LoadConversionsPageDataAsyncTask(profileId, conversionId);

                // Have to raise these synchronously to avoid crashes
                App.VM.NotifyPropertyChanged("SelectedProfile");
                App.VM.NotifyPropertyChanged("SelectedConversionType");
            }
            else
            {
                if (App.VM.SkipLoadConversionPageData)
                {
                    App.VM.SkipLoadConversionPageData = false;
                }
            }

            // Add the advert is not paid
            if (!(bool)App.Settings.GetValueOrDefault("DisableAds", false) &&
                this.adControl == null)
            {
                this.adControl = new AdDuplex.AdControl()
                {
                    AppId = AppConstants.ADDUPLEX_APP_ID,
                    HorizontalAlignment = HorizontalAlignment.Left,
                };
                this.LayoutRoot.Children.Add(this.adControl);
                Grid.SetColumn(this.adControl, 0);
                Grid.SetRow(this.adControl, 3);
            }
        }
예제 #4
0
        public void JumpToConversionBtn(ConversionId cId)
        {
            List <ConversionId> bottomHalfConversions = new List <ConversionId>()
            {
                ConversionId.WetsuitSize,
                ConversionId.SkiBootSize,
                ConversionId.ShoeSize,
            };

            if (bottomHalfConversions.Contains(cId))
            {
                this.ScrollDownAfterPivotJump = 800;
            }
            if (this.mainPivot.SelectedIndex != 0)
            {
                this.mainPivot.SelectedIndex = 0;
            }
        }
 public override int GetHashCode()
 {
     unchecked
     {
         var hashCode = (Description != null ? Description.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (Currency != null ? Currency.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ AmountFrom.GetHashCode();
         hashCode = (hashCode * 397) ^ AmountTo.GetHashCode();
         hashCode = (hashCode * 397) ^ (Status != null ? Status.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ PaymentDateFrom.GetHashCode();
         hashCode = (hashCode * 397) ^ PaymentDateTo.GetHashCode();
         hashCode = (hashCode * 397) ^ TransferredAtFrom.GetHashCode();
         hashCode = (hashCode * 397) ^ TransferredAtTo.GetHashCode();
         hashCode = (hashCode * 397) ^ CreatedAtFrom.GetHashCode();
         hashCode = (hashCode * 397) ^ CreatedAtTo.GetHashCode();
         hashCode = (hashCode * 397) ^ UpdatedAtFrom.GetHashCode();
         hashCode = (hashCode * 397) ^ UpdatedAtTo.GetHashCode();
         hashCode = (hashCode * 397) ^ (BeneficiaryId != null ? BeneficiaryId.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (ConversionId != null ? ConversionId.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ WithDeleted.GetHashCode();
         hashCode = (hashCode * 397) ^ (PaymentGroupId != null ? PaymentGroupId.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (UniqueRequestId != null ? UniqueRequestId.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (Scope != null ? Scope.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (BuyCurrency != null ? BuyCurrency.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (SellCurrency != null ? SellCurrency.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ ClientBuyAmountFrom.GetHashCode();
         hashCode = (hashCode * 397) ^ ClientBuyAmountTo.GetHashCode();
         hashCode = (hashCode * 397) ^ ClientSellAmountFrom.GetHashCode();
         hashCode = (hashCode * 397) ^ ClientSellAmountTo.GetHashCode();
         hashCode = (hashCode * 397) ^ PartnerBuyAmountFrom.GetHashCode();
         hashCode = (hashCode * 397) ^ PartnerBuyAmountTo.GetHashCode();
         hashCode = (hashCode * 397) ^ PartnerSellAmountFrom.GetHashCode();
         hashCode = (hashCode * 397) ^ PartnerSellAmountTo.GetHashCode();
         hashCode = (hashCode * 397) ^ (ClientStatus != null ? ClientStatus.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (PartnerStatus != null ? PartnerStatus.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ ConversionDateFrom.GetHashCode();
         hashCode = (hashCode * 397) ^ ConversionDateTo.GetHashCode();
         hashCode = (hashCode * 397) ^ SettlementDateFrom.GetHashCode();
         hashCode = (hashCode * 397) ^ SettlementDateTo.GetHashCode();
         return(hashCode);
     }
 }
 public static FeedbackAdjustment GetAdjustmentOrNull(ConversionId cId, string rId, GenderId gender, BrandId bId)
 {
     throw new NotImplementedException();
 }
 public override int GetHashCode()
 {
     return(ConversionId.GetHashCode());
 }
예제 #8
0
        public object Convert(Object value, Type targetType, Object parameter, CultureInfo cultureInfo)
        {
            ConversionId cId = (ConversionId)value;

            return(Lookup.Conversions[cId]);
        }
예제 #9
0
        public static void ReadFileIntoDb(ConversionsDataContext db, ConversionId conversionId)
        {
            Uri uri = new Uri(AppConstants.CSV_DATA_DIRECTORY + conversionId.ToString() + ".txt", UriKind.Relative);
            var res = System.Windows.Application.GetResourceStream(uri);

            System.IO.StreamReader fh = new System.IO.StreamReader(res.Stream);

            int           lineNum = 0;
            List <string> headers = new List <string>();

            Pocketailor.Model.ConversionData cd = null;

            while (!fh.EndOfStream)
            {
                lineNum++;
                string line = fh.ReadLine();
                // Read headers
                if (lineNum == 1)
                {
                    headers = line.Split(AppConstants.CSV_DELIMITERS).ToList <string>();
                    continue;
                }
                // Skip commented lines
                if (line.StartsWith("#"))
                {
                    continue;
                }
                // Skip empty lines
                if (line.Trim() == String.Empty)
                {
                    continue;
                }
                var els = line.Split(AppConstants.CSV_DELIMITERS).ToList <string>();
                // We make the assumption that data for a particular brand, gender, region, conversion are contiguous,
                // so when any one of these change, we change the object
                CsvLine csvLine = new CsvLine();
                csvLine.Conversion = conversionId;
                for (int i = 0; i < els.Count; i++)
                {
                    els[i] = els[i].Trim();
                    switch (headers[i].ToLower())
                    {
                    //case "conversion":
                    //    csvLine.Conversion = (ConversionId)Enum.Parse(typeof(ConversionId), els[i], true);
                    //    continue;
                    case "brand":
                        csvLine.Brand = (BrandId)Enum.Parse(typeof(BrandId), els[i], true);
                        continue;

                    case "region":
                        csvLine.Region = els[i];
                        continue;

                    case "gender":
                        csvLine.Gender = (GenderId)Enum.Parse(typeof(GenderId), els[i], true);
                        continue;

                    case "sizeid":
                        csvLine.SizeId = Int32.Parse(els[i]);
                        continue;

                    case "size":
                        csvLine.Size = els[i];
                        continue;

                    // Assume all remaining properties are numbers
                    default:
                        double d;
                        if (els[i] == String.Empty)
                        {
                            d = -1;
                        }
                        else
                        {
                            d = Double.Parse(els[i]);
                        }
                        MeasurementId mId = (MeasurementId)Enum.Parse(typeof(MeasurementId), headers[i], true);
                        csvLine.Measurements.Add(mId, d);
                        break;
                    }
                }
                // Take into account the first line
                if (cd == null)
                {
                    cd            = new Pocketailor.Model.ConversionData();
                    cd.Region     = csvLine.Region;
                    cd.Brand      = csvLine.Brand;
                    cd.Conversion = csvLine.Conversion;
                    cd.Gender     = csvLine.Gender;
                }
                // See if need to write a new object to the database i.e. the dataset has changed
                if (csvLine.Region != cd.Region ||
                    csvLine.Brand != cd.Brand ||
                    csvLine.Conversion != cd.Conversion ||
                    csvLine.Gender != cd.Gender)
                {
                    // Write to DB
                    cd.JsonifyData();
                    db.ConversionData.InsertOnSubmit(cd);
                    db.SubmitChanges();
                    // Create next database object
                    cd            = new Pocketailor.Model.ConversionData();
                    cd.Region     = csvLine.Region;
                    cd.Brand      = csvLine.Brand;
                    cd.Conversion = csvLine.Conversion;
                    cd.Gender     = csvLine.Gender;
                }
                // Add the measurements for this line ...
                foreach (MeasurementId mId in csvLine.Measurements.Keys)
                {
                    if (!cd.Measurements.Keys.Contains(mId))
                    {
                        cd.Measurements.Add(mId, new List <double>());
                    }
                    cd.Measurements[mId].Add(csvLine.Measurements[mId]);
                }
                cd.Sizes.Add(csvLine.Size);
                cd.SizeIds.Add(csvLine.SizeId);

                // Write to db is obj count too high
                //if ((objNum % AppConstants.DB_OBJECT_BUFFER_BEFORE_WRITE) == 0)
                //{
                //    db.SubmitChanges();
                //}
            }
            // Write any remaining object to the DB
            if (cd != null)
            {
                cd.JsonifyData();
                db.ConversionData.InsertOnSubmit(cd);
                db.SubmitChanges();
            }
        }
예제 #10
0
        public void LoadRequiredMeasurements(GenderId gender, ConversionId conversion)
        {
            // Get the conversion specific data
            switch (conversion)
            {
            case ConversionId.TrouserSize:
                if (gender == GenderId.Male)
                {
                    this.LoadConversionMeasurements(RequiredMeasurements.TrousersMens);
                }
                else
                {
                    this.LoadConversionMeasurements(RequiredMeasurements.TrousersWomens);
                }
                break;

            case ConversionId.ShirtSize:
                if (gender == GenderId.Male)
                {
                    this.LoadConversionMeasurements(RequiredMeasurements.ShirtMens);
                }
                else
                {
                    this.LoadConversionMeasurements(RequiredMeasurements.ShirtWomens);
                }
                break;

            case ConversionId.HatSize:
                this.LoadConversionMeasurements(RequiredMeasurements.Hat);
                break;

            case ConversionId.SuitSize:
                if (gender == GenderId.Male)
                {
                    this.LoadConversionMeasurements(RequiredMeasurements.SuitMens);
                }
                else
                {
                    this.LoadConversionMeasurements(RequiredMeasurements.SuitWomens);
                }
                break;

            case ConversionId.DressSize:
                this.LoadConversionMeasurements(RequiredMeasurements.DressSize);
                break;

            case ConversionId.BraSize:
                this.LoadConversionMeasurements(RequiredMeasurements.Bra);
                break;

            case ConversionId.HosierySize:
                this.LoadConversionMeasurements(RequiredMeasurements.Hosiery);
                break;

            case ConversionId.ShoeSize:
                this.LoadConversionMeasurements(RequiredMeasurements.Shoes);
                break;

            case ConversionId.SkiBootSize:
                this.LoadConversionMeasurements(RequiredMeasurements.SkiBoots);
                break;

            case ConversionId.WetsuitSize:
                if (gender == GenderId.Male)
                {
                    this.LoadConversionMeasurements(RequiredMeasurements.WetsuitMens);
                }
                else
                {
                    this.LoadConversionMeasurements(RequiredMeasurements.WetsuitWomens);
                }
                break;

            default:
                return;
            }
        }
예제 #11
0
        public async Task LoadConversionsPageDataAsyncTask(int profileId, ConversionId conversionId)
        {
            // Fire the event off
            this.IsConversionDataLoading = true;
            if (this.ConversionDataLoading != null)
            {
                this.ConversionDataLoading(this);
            }

            // Load up the data in case of tombstone situation
            await TaskEx.Run(() =>
            {
                // Modify the vars directly to avoid raising NotifyPropertyChanged
                if (App.VM.SelectedProfile == null || App.VM.SelectedProfile.Id != profileId)
                {
                    App.VM._selectedProfile = (from Profile p in App.VM.appDB.Profiles where p.Id == profileId select p).FirstOrDefault();
                }
                if (App.VM.SelectedConversionType != conversionId)
                {
                    App.VM._selectedConversionType = conversionId;
                }
            });

            // TODO: If gender not specified, then return Female measurements. Note only perform gener query on tables that have
            // Gender fields (even after casting) because it still generate SQL to query gender
            GenderId qGender = (this.SelectedProfile.Gender == GenderId.Unspecified) ? GenderId.Female : this.SelectedProfile.Gender;

            this.LoadRequiredMeasurements(qGender, this.SelectedConversionType);

            Dictionary <MeasurementId, double> measuredVals = this.ConversionMeasurements.ToDictionary(k => k.MeasurementId, v => Double.Parse(v.Value));

            // Check we have all the necessary measurements
            if (measuredVals == null)
            {
                return;
            }
            // Build up by regions
            string selectedRegion = this.SelectedRegion;

            // Await the resolution of BlacklistedBrands
            BrandId[]    blacklistedBrands = App.VM.BlacklistedBrands.ToArray();
            ConversionId conversion        = App.VM.SelectedConversionType;

            this.GroupedConversions = await TaskEx.Run(() =>
            {
                string r = selectedRegion;
                List <ConversionData> conversions     = new List <ConversionData>();
                IEnumerable <BrandId> collectedBrands = new List <BrandId>();
                while (true) // I know ...
                {
                    // Do database (Linq-to-sql) stuff first, so this should translate to SQL and run SQL with AsList
                    conversions.AddRange(from d in this.conversiondsDB.ConversionData
                                         where d is ConversionData
                                         // Filter to specific region, gender, conversion
                                         && d.Region == r &&
                                         d.Gender == qGender &&
                                         d.Conversion == conversion &&
                                         !blacklistedBrands.Contains(d.Brand) &&
                                         !collectedBrands.Contains(d.Brand)
                                         select d);
                    collectedBrands = from d in conversions select d.Brand;
                    if (r == Globalisation.CustomRegions.GlobalRegion)
                    {
                        break;
                    }
                    r = Globalisation.CustomRegions.RegionParents[r];
                }
                conversions.Sort((a, b) => { return(a.BrandName.CompareTo(b.BrandName)); });
                // Group up the brand names
                string groupKeys = "#abcdefghijklmnopqrstuvwxyz";
                // Initially store in a dictionary
                Dictionary <string, List <ConversionData> > groupDict = new Dictionary <string, List <ConversionData> >();
                foreach (char c in groupKeys)
                {
                    groupDict.Add(c.ToString(), new List <ConversionData>());
                }
                foreach (ConversionData cd in conversions)
                {
                    // Find the best fit whilst at it
                    cd.FindBestFit(measuredVals);
                    // Add to the right group according to the first letter of the brand name
                    char key = char.ToLower(cd.BrandName[0]);
                    if (key < 'a' || key > 'z')
                    {
                        key = '#';
                    }
                    groupDict[key.ToString()].Add(cd);
                }
                // Buffer first to avoid triggering the NotifyPropertyChanged events on ObservableCollection hundreds of times
                List <LongListSelectorGroup <ConversionData> > buff = new List <LongListSelectorGroup <ConversionData> >();
                foreach (char key in groupKeys)
                {
                    string k = key.ToString();
                    buff.Add(new LongListSelectorGroup <ConversionData>(k, groupDict[k]));
                }
                return(new ObservableCollection <LongListSelectorGroup <ConversionData> >(buff));
            });

            // Fire the end event
            if (this.ConversionDataLoaded != null)
            {
                this.ConversionDataLoaded(this);
            }
            this.IsConversionDataLoading = false;
        }
예제 #12
0
        private void newlyUnlockedBtn_Tap(object sender, System.Windows.Input.GestureEventArgs e)
        {
            ConversionId cId = ((sender as NewlyUnlockedConversionNotificationBtn).DataContext as ConversionBtnData).ConversionId;

            this.JumpToConversionBtn(cId);
        }