Beispiel #1
0
        private async Task SearchUsers(DateTime date, string group_id)
        {
            /*parse JSON string in JSON Object, responseUsers has link on this object*/
            dynamic responseUsers = await API.users.search(
                CountryID,
                CityID,
                (checkUniversity.IsChecked == true && cbUniversity.SelectedItem != null)?cbUniversity.SelectedValue.ToString() : null,
                    cbSex.SelectedValue.ToString(),
                    checkBRelation.IsChecked == true?cbRelationStatus.SelectedValue.ToString() : null,
                        "1000",
                        _searchFields,
                        date,
                        group_id
                );


            /*add users from query to list*/
            foreach (var item in responseUsers.response.items)
            {
                /*Check if phone number is valid, if not, skip user*/
                if (CheckPhoneNumber.IsChecked == true)
                {
                    string phoneNumber = item["mobile_phone"] != null ? item.mobile_phone : null;
                    if (phoneNumber == null || !(ExpMethods.ValidPhoneNumber(phoneNumber)))
                    {
                        continue;
                    }
                }

                UsersData.Add(new User
                {
                    Id        = ExpMethods.UrlFromID(item.id.ToString()),/*transform user id to link*/
                    FirstName = item.first_name,
                    LastName  = item.last_name,
                    Sex       = ExpMethods.SexFromNumber(item.sex.ToString()),
                    BDate     = date.ToShortDateString(),
                    /*if country is known write it from comboBox, otherwise from JSON*/
                    Country = item["country"] != null ? item.country.title : null,
                    /*if city is known write it from comboBox, otherwise from JSON*/
                    City           = item["city"] != null ? item.city.title : null,
                    PrivateMessage = item.can_write_private_message,
                    MobilePhone    = item["mobile_phone"] != null ? item.mobile_phone : null,
                    Skype          = item["skype"] != null ? item.skype : null,
                    Instagram      = item["instagram"] != null ? item.instagram : null,
                    HomePhone      = item["home_phone"] != null ? item.home_phone : null,
                    /*convert unix format to datetime*/
                    Time = item["last_seen"] != null ? ExpMethods.UnixTimeToDateTime(item.last_seen.time.ToString()) : null,
                    /*if relation is known write it from comboBox, otherwise from JSON*/
                    Relation = item.relation != null ? item.relation : null,
                    /*transform partner id to link*/
                    Partner = item["relation_partner"] != null ? ExpMethods.UrlFromID(item.relation_partner.id.ToString()) : null
                });
            }
            /*refresh datagrid after adding users*/
            dgUsers.Items.Refresh();
        }
Beispiel #2
0
        /*save button click*/
        private async void SaveBtn_Click(object sender, RoutedEventArgs e)
        {
            Microsoft.Win32.SaveFileDialog dlg = new Microsoft.Win32.SaveFileDialog();
            dlg.FileName   = "Document";
            dlg.DefaultExt = ".csv";
            dlg.Filter     = "(.csv)|*.csv";
            bool?result = dlg.ShowDialog();

            if (result == true)
            {
                bool successed = await ExpMethods.WriteToCSV(UsersData, dlg.FileName);

                MessageBox.Show(successed == true ? "Файл успешно сохранен" : "Произошла ошибка");
            }
        }
Beispiel #3
0
        /*executes after clicking on search Button*/
        private async void Search_Click(object sender, RoutedEventArgs e)
        {
            /*Disable options after clicking*/
            SearchInProgress(true);
            /*Cancellation token for killing this task, cancel executes on click stop btn or logout btn*/
            _cts = new CancellationTokenSource();
            /*get urls from groups box*/
            string[] urls = textListOfGroups.Text.Split(',');

            /*set progress bar in 0*/
            progrBar.Value = 0;
            /*set porgressBar`s maximum rely on qty days in search`s options*/
            progrBar.Maximum = (DateEnd.DisplayDate.Subtract(DateStart.DisplayDate).Days + 1);

            try
            {
                /*general search if checkBox inGroups unchecked*/
                if (!(checkInGroups.IsChecked ?? false))
                {
                    /*pass null if it doesnt need to search in groups*/
                    await SearchGroup(null);
                }
                /*search in groups*/
                else
                {
                    /*it gets group ids from group urls*/
                    string[] groupsID = await ExpMethods.GroupUrlToId(urls);

                    /*increase progressBar maximum in groups.lenght times*/
                    progrBar.Maximum *= groupsID.Length;
                    /*pass each group id in SearchGroup*/
                    foreach (var group_id in groupsID)
                    {
                        await SearchGroup(group_id);
                    }
                }
            }
            catch (OperationCanceledException ocex)
            {
            }
            finally
            {
                _cts = null;
            }
            /*unblock options interface after searching*/
            SearchInProgress(false);
        }