private void SetAutoCategory() { // Done:Kolla ordningen på sakerna, i base, sätt kategori närmare info // Done: Gör denna som kollar knapp-nyckel i ovan istället, så inte flera klick körs // Done: sätt i egen funktin var i = comboBoxCategories.SelectedIndex; #region Check values if (i < 0 && clickedItem == null) { return; } #endregion // Get selected values // Get selected items cat var selEntry = (KontoEntry)clickedItem.Tag; var selItemsCat = selEntry != null && !string.IsNullOrEmpty(selEntry.TypAvKostnad) ? selEntry.TypAvKostnad : null; var selectedCategoryText = selItemsCat ?? comboBoxCategories.Items[i].ToString(); // Done:Byt namn var slectedInfoDescription = clickedItem.SubItems[1].Text; var newAutoCategeory = new AutoCategorise { InfoDescription = slectedInfoDescription }; #region Fråga anv. om den är säker // Fråga anv. om den är säker var autoCatMessage = "Spara autokategori? Alltså att altid välja:" + Environment.NewLine + selectedCategoryText + Environment.NewLine + "Varje gång info är:" + Environment.NewLine + slectedInfoDescription + Environment.NewLine + "?"; if (!UserAcceptsFurtherAction(autoCatMessage, AutoCatCpation)) { return; } #endregion // Sätt autokategori (lägg till eller ändra) if (!CategoriesHolder.AllCategories.SetNewAutoCategorize(selectedCategoryText, newAutoCategeory)) { return; } // Spara till fil CategoriesHolder.Save(); // Todo. ev. kopiera savad xml-fil till utvecklingsarea.Eg. ej, föra att anv. ska ha egen datafil... // Uppdera listan men nya entries UpdateCategoriesWithAutoCatList(Items, newAutoCategeory.InfoDescription); }
internal bool SetNewAutoCategorize(string selectedCategoryText, AutoCategorise newAutoCategeory) { #region Sätt autokategori (lägg till eller ändra) var cats = this; // Done: om kategorin redan finns, ändra i den istället för att lägga till if (cats.CategoryWithDescriptionExists(selectedCategoryText)) { var selCategory = cats.GetCategoryWithDescription(selectedCategoryText); // Done: om InfoDescription redan finns, ändra i den istället för att lägga till // Kolla om samma kategori redan har samma infodescription var newAcId = newAutoCategeory.InfoDescription; if (selCategory.ObjectWithDescriptionExists(newAcId)) { // Då finns redan samm InfoDescription under samma kategori, så gör ingenting // Meddela inte anv., effekten blir den samma... } else { // Kolla om någon annan kategori redan har beskrivningen if (cats.AutoCategoriseWithDescriptionExists(newAcId)) { // Isåfall ta bort den och lägg till en i den nyavalda kategorien. Fråga användaren först. #region Fråga anv. om den är säker // Fråga anv. om den är säker var autoCatMessage = "Autokategorin finns redan som annan kategori:" + Environment.NewLine + cats.GetCategoryForAutoCategoriseWithDescription(newAcId) + Environment.NewLine + Environment.NewLine + "Vill du skriva över med autokategorin:" + Environment.NewLine + selCategory.Description + Environment.NewLine + "Varje gång info är:" + Environment.NewLine + cats.GetAutoCategoriseWithDescription(newAcId) + Environment.NewLine + "Will du skriva over?"; if ( !ListViewWithComboBox.UserAcceptsFurtherAction( autoCatMessage, ListViewWithComboBox.AutoCatCpation)) { return false; } #endregion if (!cats.RemoveAutoCategoriseWithDescriptionIfItExists(newAcId)) { MessageBox.Show("Mystical Error! " + newAcId + " did not exist or other error."); } } // Lägg till InfoDescription till kategori som redan finns. selCategory.AutoCategoriseList.Add(newAutoCategeory); } } else { cats.CategoryList.Add( new Category { Description = selectedCategoryText, AutoCategoriseList = new List<AutoCategorise> { newAutoCategeory } }); } #endregion return true; }