資源簡介
根據http://study.163.com/course/courseMain.htm?courseId=1004094049課程編寫的代碼,進行了一些優化,可以參考一下。功能是從txt文件中讀取數據顯示到界面,可以進行增刪改查等操作,編輯器用的vs2017。可用的txt文件就在項目根目錄下。

代碼片段和文件信息
using?System;
using?System.Collections.Generic;
using?System.ComponentModel;
using?System.Data;
using?System.Drawing;
using?System.IO;
using?System.Linq;
using?System.Text;
using?System.Threading.Tasks;
using?System.Windows.Forms;
namespace?StudentManage
{
????public?partial?class?frmStudent?:?Form
????{
????????#region?移動窗體
????????///?
????????///?重寫WndProc方法實現窗體移動和禁止雙擊最大化
????????///?
????????///?Windows?消息
????????protected?override?void?WndProc(ref?Message?m)
????????{
????????????switch?(m.Msg)
????????????{
????????????????case?0x4e:
????????????????case?0xd:
????????????????case?0xe:
????????????????case?0x14:
????????????????????base.WndProc(ref?m);
????????????????????break;
????????????????case?0x84://鼠標點任意位置后可以拖動窗體
????????????????????this.DefWndProc(ref?m);
????????????????????if?(m.Result.ToInt32()?==?0x01)
????????????????????{
????????????????????????m.Result?=?new?IntPtr(0x02);
????????????????????}
????????????????????break;
????????????????case?0xA3://禁止雙擊最大化
????????????????????break;
????????????????default:
????????????????????base.WndProc(ref?m);
????????????????????break;
????????????}
????????}
????????#endregion
????????private?string?fileName?=?string.Empty;//定義變量保存文件路徑,string.Empty等同于““
????????private?string?photoName?=?string.Empty;//上傳圖片路徑
????????private?List?objListStudent?=?new?List();//定義List存儲讀取到的學生數據
????????private?List?queryList?=?new?List();//定義List存儲讀取到的學生數據
????????private?int?flag?=?0;//1為添加,2為修改
????????public?frmStudent()
????????{
????????????InitializeComponent();
????????????//禁用詳細信息編輯框
????????????gboxStudentDetail.Enabled?=?false;
????????????//修改DateTimePicker時間格式
????????????dtpBirthday.Format?=?DateTimePickerFormat.Custom;
????????????dtpBirthday.CustomFormat?=?“yyyy/MM/dd“;
????????}
????????//控件方法
????????
????????private?void?btnImport_Click(object?sender?EventArgs?e)//導入數據
????????{
????????????//1.選擇文件
????????????OpenFileDialog?openFile?=?new?OpenFileDialog();
????????????openFile.Filter?=?“TXT文件(*.txt)|*.txt|所有文件(*.*)|*.*“;//文件類型
????????????if(openFile.ShowDialog()?==?DialogResult.OK)
????????????{
????????????????fileName?=?openFile.FileName;//把選擇的文件路徑賦值給定義的全局變量
????????????}
????????????else
????????????{
????????????????return;
????????????}
????????????//2.把文件的數據讀取到List中
????????????try
????????????{
????????????????objListStudent?=?ReadFileToList(fileName);
????????????}catch(Exception?ex)
????????????{
????????????????MessageBox.Show(“讀取文件出現錯誤,具體錯誤如下:“?+?ex.Message?“系統消息“?MessageBoxButtons.OK?MessageBoxIcon.Information);
????????????}
????????????if?(objListStudent.Count?!=?0)//有數據
????????????{
????????????????
????????????????try
????????????????{
????????????????????//3.把List中數據展示在datagridview中
????????????????????LoadDataToDateGrid(objListStudent);
????????????????????//4.把datagridview第一行的數據顯示在明細中
?????????
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件????????150??2018-07-26?16:43??StudentManage\.vs\StudentManage\DesignTimeBuild\.dtbcache
????..A..H.?????45568??2018-07-26?16:43??StudentManage\.vs\StudentManage\v15\.suo
?????文件??????????0??2018-07-23?14:46??StudentManage\.vs\StudentManage\v15\Server\sqlite3\db.lock
?????文件?????598016??2018-07-26?09:11??StudentManage\.vs\StudentManage\v15\Server\sqlite3\storage.ide
?????文件??????32768??2018-07-26?14:44??StudentManage\.vs\StudentManage\v15\Server\sqlite3\storage.ide-shm
?????文件????4128272??2018-07-26?16:43??StudentManage\.vs\StudentManage\v15\Server\sqlite3\storage.ide-wal
?????文件????????189??2018-07-23?14:46??StudentManage\StudentManage\App.config
?????文件?????538623??2018-07-25?17:30??StudentManage\StudentManage\bin\Debug\image\2018072517295988.png
?????文件?????538623??2018-07-25?17:44??StudentManage\StudentManage\bin\Debug\image\2018072517445342.png
?????文件?????538623??2018-07-26?09:05??StudentManage\StudentManage\bin\Debug\image\2018072609052312.png
?????文件?????538623??2018-07-26?09:05??StudentManage\StudentManage\bin\Debug\image\2018072609054514.png
?????文件?????138901??2018-07-26?10:35??StudentManage\StudentManage\bin\Debug\image\20180726103533(29).png
?????文件?????138901??2018-07-26?11:47??StudentManage\StudentManage\bin\Debug\image\20180726114740(87).png
?????文件?????138901??2018-07-26?11:55??StudentManage\StudentManage\bin\Debug\image\20180726115512(16).png
?????文件?????539648??2018-07-26?16:42??StudentManage\StudentManage\bin\Debug\StudentManage.exe
?????文件????????189??2018-07-23?14:46??StudentManage\StudentManage\bin\Debug\StudentManage.exe.config
?????文件??????36352??2018-07-26?16:42??StudentManage\StudentManage\bin\Debug\StudentManage.pdb
?????文件?????538623??2018-07-25?17:30??StudentManage\StudentManage\bin\Release\image\2018072517295988.png
?????文件?????538623??2018-07-25?17:44??StudentManage\StudentManage\bin\Release\image\2018072517445342.png
?????文件?????538623??2018-07-26?09:05??StudentManage\StudentManage\bin\Release\image\2018072609052312.png
?????文件?????538623??2018-07-26?09:05??StudentManage\StudentManage\bin\Release\image\2018072609054514.png
?????文件?????138901??2018-07-26?10:35??StudentManage\StudentManage\bin\Release\image\20180726103533(29).png
?????文件?????138901??2018-07-26?11:47??StudentManage\StudentManage\bin\Release\image\20180726114740(87).png
?????文件?????138901??2018-07-26?11:55??StudentManage\StudentManage\bin\Release\image\20180726115512(16).png
?????文件?????538624??2018-07-26?16:42??StudentManage\StudentManage\bin\Release\StudentManage.exe
?????文件????????189??2018-07-23?14:46??StudentManage\StudentManage\bin\Release\StudentManage.exe.config
?????文件??????34304??2018-07-26?16:42??StudentManage\StudentManage\bin\Release\StudentManage.pdb
?????文件??????16958??2018-07-26?16:41??StudentManage\StudentManage\favicon.ico
?????文件??????19355??2018-07-26?14:13??StudentManage\StudentManage\frmStudent.cs
?????文件??????30414??2018-07-26?10:29??StudentManage\StudentManage\frmStudent.Designer.cs
............此處省略63個文件信息
評論
共有 條評論