/// <summary> /// Edytuj książkę po otrzymaniu zmian, sortuj kontakty od dostępnego /// </summary> /// <param name="bookList"></param> private void EditBook(List <User> bookList) { if (ListViewAddressBook.Dispatcher.Thread == Thread.CurrentThread) { foreach (var user_item in bookList) { foreach (MyItem item in ListViewAddressBook.Items) { if (item.UserName == user_item.UserName) { if (user_item.UserState != Status.UNKNOWN) { item.UserState = user_item.UserState.ToString(); Console.WriteLine(item.UserState); //view.SortDescriptions.Add(new SortDescription("UserState", ListSortDirection.Ascending)); } if (user_item.UserDesc != null && user_item.UserDesc != "") { item.UserDesc = user_item.UserDesc; Console.Write(item.UserDesc); } } } } ListViewAddressBook.Items.SortDescriptions.Add(new SortDescription("UserState", ListSortDirection.Ascending)); ListViewAddressBook.Items.Refresh(); } else { SetUsersCallBack f = new SetUsersCallBack(EditBook); Dispatcher.Invoke(f, new object[] { bookList }); } }
/// <summary> /// Ustaw książkę, ukryj pierszą kolumnę /// (będzie ona służyła tylko do rozpoznawania statusów w kodzie, /// w interfejsie status będzie rozróżniany poprzez kolory) /// </summary> /// <param name="bookList"></param> public void SetBook(List <User> bookList) { if (ListViewAddressBook.InvokeRequired) { SetUsersCallBack f = new SetUsersCallBack(SetBook); Invoke(f, new object[] { bookList }); } else { ListViewAddressBook.View = View.Details; int itemHeight = 20; ImageList imgList = new ImageList(); imgList.ImageSize = new Size(1, itemHeight); ListViewAddressBook.SmallImageList = imgList; foreach (var item in bookList) { ListViewItem listViewItem = new ListViewItem(new string[] { item.UserState.ToString(), item.UserName, item.UserDesc }); ListViewAddressBook.Items.Add(listViewItem); } ListViewAddressBook.AutoResizeColumns(ColumnHeaderAutoResizeStyle.ColumnContent); ListViewAddressBook.Columns[0].Width = 0; } }
/// <summary> /// Edytuj książkę po otrzymaniu zmian, sortuj kontakty od dostępnego /// </summary> /// <param name="bookList"></param> private void EditBook(List <User> bookList) { if (ListViewAddressBook.InvokeRequired) { SetUsersCallBack f = new SetUsersCallBack(EditBook); this.Invoke(f, new object[] { bookList }); } else { foreach (ListViewItem lvi in ListViewAddressBook.Items) { foreach (var item in bookList) { if (lvi.SubItems[1].Text == item.UserName) { if (item.UserState != Status.UNKNOWN) { int stateIndex = (int)item.UserState; lvi.SubItems[0].Text = stateIndex.ToString(); //SetText("Użytkownik " + item.UserName + " zaktualizował swój status!"); PopUpTimer.Enabled = true; Console.WriteLine(stateIndex.ToString()); popUpForm.labelWho.Text = item.UserName; popUpForm.labelWhat.Text = "Użytkownik zaktualizował swój status!"; popUpForm.ShowDialog(); ListViewAddressBook.Sort(); } if (item.UserDesc != null && item.UserDesc != "") { lvi.SubItems[2].Text = item.UserDesc; //SetText("Użytkownik " + item.UserName + " zaktualizował swój opis!"); PopUpTimer.Enabled = true; popUpForm.labelWho.Text = item.UserName; popUpForm.labelWhat.Text = "Użytkownik zaktualizował swój opis!"; popUpForm.ShowDialog(); } } } } } }
/// <summary> /// Ustaw kolory na formatce, zgodnie z listą /// </summary> /// <param name="colorList"></param> public void SetColor(List <User> colorList) { if (ListViewAddressBook.InvokeRequired) { SetUsersCallBack f = new SetUsersCallBack(SetColor); this.Invoke(f, new object[] { colorList }); } else { foreach (ListViewItem lvi in ListViewAddressBook.Items) { foreach (var item in colorList) { if (lvi.SubItems[1].Text == item.UserName) { lvi.BackColor = item.StateColor; } } } } }
/// <summary> /// Ustaw książkę, ukryj pierszą kolumnę /// (będzie ona służyła tylko do rozpoznawania statusów w kodzie, /// w interfejsie status będzie rozróżniany poprzez kolory) /// </summary> /// <param name="bookList"></param> public void SetBook(List <User> bookList) { var path2 = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData); var img = new BitmapImage(new Uri("/Images/GrafikiMenu/avatar_placeholder.png", UriKind.Relative)); if (ListViewAddressBook.Dispatcher.Thread == Thread.CurrentThread) { bookList = bookList.OrderBy(x => x.UserState).ToList(); foreach (var item in bookList) { ListViewAddressBook.Items.Add(new MyItem { UserState = item.UserState.ToString(), UserName = item.UserName, UserDesc = item.UserDesc, Image = img }); //Utworz_pliki_json(item); //Wypelnij_pliki_json(item); } } else { SetUsersCallBack f = new SetUsersCallBack(SetBook); Dispatcher.Invoke(f, new object[] { bookList }); } }