private void BTN_Edit_Click(object sender, RoutedEventArgs e) { //First off make sure there is actually something selected if (LIV_CardList.SelectedIndex < 0) { return; } try { //What card we get is based on the //Card code so we get that first //So get the selected item from the list //Pull the card from the selected listitem Classes.CardOverview TagCard = (Classes.CardOverview)LIV_CardList.SelectedItem; //and get the full set code from it string SetCode = TagCard.CardSetCode; //Now after all of that we have a value to give to the card viewer CardEditor EditorWindow = new CardEditor(SetToView, false, SetCode); EditorWindow.ShowDialog(); //Make sure this window has the right values once this editor returns UpdateCardList(); } catch (Exception ex) { //If something goes wrong somehow show an error explaining what went wrong then kill the application MessageBox.Show($"An error occured {ex}"); } }
private void BTN_Add_Click(object sender, RoutedEventArgs e) { string CodeToUse = ""; //first of all check if there is a file containing unused SetCodes for this set exists, if it does get the first line of it //and use that for the Code, then delete it from the file obviously as to avoid confusion string UsableIndexFilePath = Directory.GetCurrentDirectory() + $"\\{SetToView}.txt"; if (File.Exists(UsableIndexFilePath)) { //if it does get the whole thing string[] UsableFilestring = File.ReadAllLines(UsableIndexFilePath); //make sure to trim the code down just in case there is a space or something that shouldnt be there CodeToUse = UsableFilestring[0].Trim(); //now if the file is only 1 line long simply delete it so the system will go back to generating the codes if (UsableFilestring.Length == 1) { File.Delete(UsableIndexFilePath); } else { //now if the file is longer than 1 line //now write everything thats in the array barring the first line because we used that //just make sure that you only write back everything that isnt the first line for (int i = 1; i < UsableFilestring.Length; i++) { using (StreamWriter sw = File.AppendText(UsableIndexFilePath)) { sw.WriteLine(UsableFilestring[i]); } } } } else { //if the file doesnt exist then there are no breaks in the set codes so you will have to make a new one from scratch CodeToUse = GetCleanSetCode(SetToView); } //now make a new card editor with the CardEditor editor = new CardEditor(SetToView, true, CodeToUse); //now show the new window editor.ShowDialog(); UpdateCardList(); }