📄 wincourse.cs
字号:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Xml;
using System.IO;
using System.Threading;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Binary;
namespace WinPaike
{
public partial class WinCourse : Form
{
public WinCourse()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
BindToGridView(FromDB("Course.dat"));
}
List<Course> FromDB(string filename)
{
List<Course> CourseList = new List<Course>();
FileStream fs = new FileStream(filename, FileMode.Open);
BinaryFormatter formatter = new BinaryFormatter();
if(fs.Length>0)
CourseList=(List<Course>)formatter.Deserialize(fs);
fs.Close();
return CourseList;
}
void BindToGridView(List<Course> courseList)
{
dataGridView1.Rows.Clear();
if (courseList.Count <= 0)
return;
dataGridView1.Rows.Add(courseList.Count);
int i = 0;
foreach (Course course in courseList)
{
DataGridViewRow row = dataGridView1.Rows[i++];
row.Cells["CourseName"].Value=course.Name;
row.Cells["TeacherName"].Value = course.TeacherName;
row.Cells["TeacherID"].Value = course.TeacherID.ToString();
row.Cells["Priority"].Value = course.Priority.ToString();
}
}
private void button1_Click(object sender, EventArgs e)
{
}
private void button2_Click(object sender, EventArgs e)
{
BindToGridView(FromDB("Course.dat"));
}
private void button3_Click(object sender, EventArgs e)
{
/*
textBox1.Clear();
PaiKe pp = new PaiKe();
pp.TxtBox = textBox1;
Thread th = new Thread(new ThreadStart(pp.Test1));
th.Start();
*/
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
}
private void button4_Click(object sender, EventArgs e)
{
(new WinClass()).Show();
}
private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
}
private void splitContainer1_Panel1_Paint(object sender, PaintEventArgs e)
{
}
private void splitContainer2_Panel2_Paint(object sender, PaintEventArgs e)
{
}
private void button5_Click(object sender, EventArgs e)
{
new WinCourseInClass().Show();
}
private void btnNext_Click(object sender, EventArgs e)
{
}
private void tbtnNext_Click(object sender, EventArgs e)
{
Course.Seed = 0;
List<Course> CourseList = new List<Course>();
for (int i = 0; i < dataGridView1.RowCount; i++)
{
DataGridViewRow row = dataGridView1.Rows[i];
int j = 0;
for (j = 0; j < row.Cells.Count; j++)
{
if (row.Cells[j].Value == null || row.Cells[j].Value.ToString().Trim() == "")
{
break;
}
}
if (j >= row.Cells.Count)
{
Course course = new Course
(
row.Cells["CourseName"].Value.ToString().Trim(),
int.Parse(row.Cells["TeacherID"].Value.ToString().Trim()),
row.Cells["TeacherName"].Value.ToString().Trim(),
int.Parse(row.Cells["Priority"].Value.ToString().Trim())
);
CourseList.Add(course);
}
}
FileStream fs = new FileStream("Course.dat", FileMode.Create);
BinaryFormatter formatter = new BinaryFormatter();
formatter.Serialize(fs, CourseList);
fs.Close();
WinClass form = new WinClass();
form.MdiParent = WinMain.MDIForm;
form.Show();
this.Close();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -