コード例 #1
0
        private async void btnBrowser_Click(object sender, RoutedEventArgs e)
        {
            var picker = new Windows.Storage.Pickers.FileOpenPicker();

            picker.ViewMode = Windows.Storage.Pickers.PickerViewMode.Thumbnail;
            picker.SuggestedStartLocation =
                Windows.Storage.Pickers.PickerLocationId.PicturesLibrary;
            picker.FileTypeFilter.Add(".jpg");
            picker.FileTypeFilter.Add(".jpeg");
            picker.FileTypeFilter.Add(".png");
            var file = await picker.PickSingleFileAsync();


            if (file != null)
            {
                UserAdd addimg = new UserAdd()
                {
                    avatar = file.Path, nameimg = file.Name
                };

                lstUser.Add(addimg);
                txtBrowser.Text = file.Path;


                var local = ApplicationData.Current.LocalFolder;
                await local.CreateFolderAsync("Data", CreationCollisionOption.OpenIfExists);

                StorageFolder folder = await local.GetFolderAsync("Data");

                await file.CopyAsync(folder);
            }
        }
コード例 #2
0
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            navigationHelper.OnNavigatedTo(e);
            UserAdd user = e.Parameter as UserAdd;

            if (user != null)
            {
                UserAdd u = new UserAdd();
                namen  = user.name;
                phonen = user.phone;
                groupn = user.group;

                txtName2.DataContext  = user;
                txtPhone2.DataContext = user;
                txtGroup2.DataContext = user;
            }
        }
コード例 #3
0
        private async void lstBox_DoubleTapped(object sender, Windows.UI.Xaml.Input.DoubleTappedRoutedEventArgs e)
        {
            int a = lstBox.SelectedIndex;

            if (a != -1)
            {
                var            local     = ApplicationData.Current.LocalFolder;
                List <UserAdd> lolstUser = new List <UserAdd>();
                var            file      = await local.GetFileAsync(@"\Data\data.txt");

                IList <string> lines = await FileIO.ReadLinesAsync(file);

                foreach (var item in lines)
                {
                    string[] d    = item.Split(' ', '\n');
                    UserAdd  user = new UserAdd();
                    user.name      = d[0];
                    user.phone     = d[1];
                    user.group     = d[2];
                    user.location  = d[3];
                    user.avatar    = d[4];
                    user.nameimg   = d[5];
                    user.imgavatar = await loadimg(d[5]);

                    lolstUser.Add(user);
                }

                UserAdd muluser = new UserAdd()
                {
                    name = lolstUser[a].name, phone = lolstUser[a].phone, group = lolstUser[a].group
                };
                if (this.Frame != null)
                {
                    this.Frame.Navigate(typeof(Edit), muluser);
                }
            }
            else
            {
                MessageDialog msg = new MessageDialog("Click Item");
                await msg.ShowAsync();
            }
        }
コード例 #4
0
        private async void btnAdd_Click(object sender, RoutedEventArgs e)
        {
            if (txtName.Text.Length != 0 && txtPhone.Text.Length != 0 && txtBrowser.Text.Length != 0 &&
                cbbGroup.SelectionBoxItem.ToString().Length != 0 && radSd.IsChecked == true || radIntermark.IsChecked == true)
            {
                UserAdd user = new UserAdd();
                user.name      = txtName.Text;
                user.phone     = txtPhone.Text;
                user.group     = cbbGroup.SelectionBoxItem.ToString();
                user.location  = (radSd.IsChecked == true) ? "SD" : "Intermark";
                user.avatar    = lstUser[0].avatar;
                user.imgavatar = lstUser[0].imgavatar;
                user.nameimg   = lstUser[0].nameimg;

                var local = ApplicationData.Current.LocalFolder;
                var file  = await local.CreateFileAsync(@"\Data\data.txt", CreationCollisionOption.OpenIfExists);

                await FileIO.AppendTextAsync(file, user.ToString());

                await new MessageDialog("Write Data").ShowAsync();
            }
        }
コード例 #5
0
        private async void btnSearch_Click(object sender, RoutedEventArgs e)
        {
            if (txtName.Text.Length != 0)
            {
                List <UserAdd> lstUser = new List <UserAdd>();
                var            local   = ApplicationData.Current.LocalFolder;

                var file = await local.GetFileAsync(@"\Data\data.txt");

                IList <string> lines = await FileIO.ReadLinesAsync(file);

                foreach (var item in lines)
                {
                    string[] d    = item.Split(' ', '\n');
                    UserAdd  user = new UserAdd();
                    user.name      = d[0];
                    user.phone     = d[1];
                    user.group     = d[2];
                    user.location  = d[3];
                    user.avatar    = d[4];
                    user.nameimg   = d[5];
                    user.imgavatar = await loadimg(d[5]);

                    lstUser.Add(user);
                }


                UserAdd        addus = lstUser.Find(x => x.name.Contains(txtName.Text));
                List <UserAdd> lstU  = new List <UserAdd>();
                lstU.Add(addus);
                lstBox.ItemsSource = lstU;
            }
            else
            {
                await new MessageDialog("Enter search name").ShowAsync();
            }
        }
コード例 #6
0
        private async void loadpage()
        {
            var            local     = ApplicationData.Current.LocalFolder;
            List <UserAdd> lolstUser = new List <UserAdd>();
            var            file      = await local.GetFileAsync(@"\Data\data.txt");

            IList <string> lines = await FileIO.ReadLinesAsync(file);

            foreach (var item in lines)
            {
                string[] d    = item.Split(' ', '\n');
                UserAdd  user = new UserAdd();
                user.name      = d[0];
                user.phone     = d[1];
                user.group     = d[2];
                user.location  = d[3];
                user.avatar    = d[4];
                user.nameimg   = d[5];
                user.imgavatar = await loadimg(d[5]);

                lolstUser.Add(user);
            }
            lstBox.ItemsSource = lolstUser;
        }
コード例 #7
0
        private async void btnDelete_Click(object sender, RoutedEventArgs e)
        {
            if (txtName2.Text.Length != 0 &&
                txtPhone2.Text.Length != 0 &&
                txtGroup2.Text.Length != 0)
            {
                var            local   = ApplicationData.Current.LocalFolder;
                List <UserAdd> lstUser = new List <UserAdd>();
                var            file    = await local.GetFileAsync(@"\Data\data.txt");

                IList <string> lines = await FileIO.ReadLinesAsync(file);

                foreach (var item in lines)
                {
                    string[] d    = item.Split(' ', '\n');
                    UserAdd  user = new UserAdd();
                    user.name     = d[0];
                    user.phone    = d[1];
                    user.group    = d[2];
                    user.location = d[3];
                    user.avatar   = d[4];
                    user.nameimg  = d[5];

                    lstUser.Add(user);
                }

                UserAdd addu = lstUser.Find(x => x.name.Contains(namen) && x.phone.Contains(phonen) && x.group.Contains(groupn));
                string  ab   = addu.nameimg;

                StorageFolder folder = await local.GetFolderAsync("Data");

                IReadOnlyList <StorageFile> sfileimg = await folder.GetFilesAsync();

                foreach (StorageFile item in sfileimg)
                {
                    if (item.Name.Equals(ab))
                    {
                        await item.DeleteAsync();
                    }
                }


                List <UserAdd> lstUse = new List <UserAdd>();
                lstUser.Remove(addu);
                lstUse.AddRange(lstUser);
                string abc = "";
                for (int i = 0; i < lstUse.Count; i++)
                {
                    UserAdd user = new UserAdd();
                    user.name      = lstUse[i].name;
                    user.phone     = lstUse[i].phone;
                    user.group     = lstUse[i].group;
                    user.location  = lstUse[i].location;
                    user.avatar    = lstUse[i].avatar;
                    user.nameimg   = lstUse[i].nameimg;
                    user.imgavatar = lstUse[i].imgavatar;
                    abc           += user.ToString();
                }
                var files = await local.CreateFileAsync(@"\Data\data.txt", CreationCollisionOption.OpenIfExists);

                await FileIO.WriteTextAsync(files, abc);

                await new MessageDialog("Delete Data Success").ShowAsync();
                txtName2.Text  = "";
                txtPhone2.Text = "";
                txtGroup2.Text = "";
            }
            else
            {
                await new MessageDialog("Not Empty").ShowAsync();
            }
        }