Experimental procedure: ToDoList
This blog mainly records the development process of experimental procedures.
1 Public voidSave ()2 {3System.Text.StringBuilder report =NewSystem.Text.StringBuilder ();4 foreach(Task ToDoIteminchtaskList)5 {6Report. Append (toDoItem.TaskTitle.ToString () +"\ t"+ toDoItem.TaskDescription.ToString () +"\ t"+ toDoItem.TaskDueDate.ToString () +"\ t"+ toDoItem.TaskPriority.ToString () +"\ t"+ toDoItem.CreationDate.ToString () +"\ t"+ toDoItem.IsTaskComplete.ToString () +"\ n");7 }8 9Microsoft.Win32.SaveFileDialog dlg =NewMicrosoft.Win32.SaveFileDialog ();TenDlg. FileName ="ToDoList";//Default file name OneDlg. DEFAULTEXT =". txt";//Default File extension ADlg. Filter ="Text documents (. txt) |*.txt";//Filter files by extension - - //Show Save File dialog box thenullable<BOOL> result =dlg. ShowDialog (); - - //Process Save File dialog box results - if(Result = =true) + { - //Save Document + File.writealltext (dlg. FileName, report. ToString ()); A } at}//End Save ()
The above code is mainly implemented to save the data in TXT format, there is a local file.
Public voidLoad () {tasklist.clear (); Microsoft.Win32.OpenFileDialog Dlg=NewMicrosoft.Win32.OpenFileDialog (); Dlg. FileName="ToDoList";//Default file nameDlg. DEFAULTEXT =". txt";//Default File extensionDlg. Filter ="Text documents (. txt) |*.txt";//Filter files by extension//Show Open File dialog boxnullable<BOOL> result =dlg. ShowDialog (); //Process Open File dialog box results if(Result = =true) { //Open DocumentSystem.IO.StreamReader MyFile =NewSystem.IO.StreamReader (@dlg. FileName); intLineCount =0; using(varReader =File.OpenText (@dlg. FileName) { while(Reader. ReadLine ()! =NULL) {LineCount++; } } for(inti =1; I <= LineCount; i++) { stringMyString =Myfile.readline (); string[] obj = Mystring.split ('\ t'); Tasklist.add (NewTask {tasktitle = obj[0]. ToString (), taskdescription = obj[1]. ToString (), taskduedate = obj[2]. ToString (), taskpriority = obj[3]. ToString (), CreationDate = obj[4], Istaskcomplete = Convert.toboolean (obj[5]) }); }//End for Loop }//END Statement } //End public bool Load ()
corresponding to the local data that is bound to it from the program.
The front interface is designed as follows
Where the button code for the capture event is as follows
1 Private voidAddtask_click (Objectsender, RoutedEventArgs e)2 {3 if(!tasktitletextbox.text.equals (string. Empty) &&!descriptiontextbox.text.equals (string. Empty) &&!datefield.text.equals (string. Empty) &&!prioritydropbox.text.equals (string. Empty))4 {5 Todo.additem (Tasktitletextbox.text, Descriptiontextbox.text, Datefield.text, prioritydropbox.text); 6 ToDoListView.Items.Refresh ();7 changeuistate (uistate.addstate);8isprogramsaved =false;9 }Ten Else One { AMessageBox.Show ("Make sure all fields is filled in!","Error", Messageboxbutton.ok, messageboximage.error); - } -}
This includes filling decisions for task time priority topics and descriptions
Add the data to the text if all is filled in if any of the items are not filled in, the error is returned.
In contrast, the foreground interface design is slightly simpler than the background program development.
C # experiment inspiration for WPF