基于C#+SqlServer+CS架构实现的学生信息管理系统,学生信息录入系统,系统采用多层C/S软件架构,采用C#编程语言开发技术实现界面窗口版本的学生管理系统程序界面,实现CS架构窗口事件监听,完成学生信息创建,编辑,删除等。
一、程序设计
本次基于C#+SqlServer+CS架构实现的学生信息管理系统,学生信息录入系统,主要内容涉及:
主要功能模块:学生管理、学生信息新增、学生信息在线编辑、学生信息删除,系统管理,分析统计等等
主要包含技术:C#编程语言,MFC,C#多线程,窗口事件监听,数据库,SQLSERVER,GUI
主要包含算法:其他等
二、效果实现
学生添加
学生管理
其他效果省略
三、核心代码
1.学生添加
本系统添加学生信息,主要采用窗口监听用户操作动作,记录用户输入的学生信息进行校验,校验通过后存入数据库等。
namespace StuManger { public partial class AddStudent : Form { SqlConnection conn; SqlCommand cmd; public AddStudent() { InitializeComponent(); this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None; string ss = ConfigurationManager.ConnectionStrings["Stu"].ToString(); //建立数据库连接 conn = new SqlConnection(ss); try { //开启连接 conn.Open(); // MessageBox.Show("数据库连接成功!"); } catch (Exception) { MessageBox.Show("数据库连接失败!"); } } private void AddStudent_Load(object sender, EventArgs e) { } private void label1_Click(object sender, EventArgs e) { } protected override bool ProcessCmdKey(ref System.Windows.Forms.Message msg, System.Windows.Forms.Keys keyData) { switch (keyData) { case Keys.Escape: this.Close();//esc关闭窗体 break; } return false; } private void button1_Click(object sender, EventArgs e) { string StuNum = textBox1.Text.Trim(); string StuName = textBox2.Text.Trim(); int StuAge; Int32.TryParse(textBox3.Text.Trim(), out StuAge); string StuClass = textBox5.Text.Trim(); string StuPhone = textBox6.Text.Trim(); string StuSex = radioButton1.Checked ? "男" : "女"; if (String.IsNullOrEmpty(StuNum)) { MessageBox.Show("学号不能为空!"); } if (String.IsNullOrEmpty(StuName)) { MessageBox.Show("姓名不能为空!"); }
<span class="token keyword">if</span> <span class="token punctuation">(</span><span class="token class-name">String<span class="token punctuation">.</span>IsNullOrEmpty</span><span class="token punctuation">(</span><span class="token class-name">StuClass</span><span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token punctuation">{<!-- --></span> <span class="token class-name">MessageBox<span class="token punctuation">.</span>Show</span><span class="token punctuation">(</span><span class="token string">"班级不能为空!"</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token punctuation">}</span> <span class="token keyword">if</span> <span class="token punctuation">(</span><span class="token class-name">String<span class="token punctuation">.</span>IsNullOrEmpty</span><span class="token punctuation">(</span><span class="token class-name">StuPhone</span><span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token punctuation">{<!-- --></span> <span class="token class-name">MessageBox<span class="token punctuation">.</span>Show</span><span class="token punctuation">(</span><span class="token string">"联系方式不能为空!"</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token punctuation">}</span> string sql <span class="token operator">=</span> <span class="token class-name"><span class="token namespace">string<span class="token punctuation">.</span></span>Format</span><span class="token punctuation">(</span><span class="token string">"insert into Stu_dent values ('{0}','{1}','{2}','{3}','{4}','{5}')"</span><span class="token punctuation">,</span> <span class="token class-name">StuNum</span><span class="token punctuation">,</span> <span class="token class-name">StuName</span><span class="token punctuation">,</span><span class="token class-name">StuAge</span><span class="token punctuation">,</span><span class="token class-name">StuSex</span><span class="token punctuation">,</span> <span class="token class-name">StuClass</span><span class="token punctuation">,</span> <span class="token class-name">StuPhone</span> <span class="token punctuation">)</span><span class="token punctuation">;</span> cmd <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">SqlCommand</span><span class="token punctuation">(</span>sql<span class="token punctuation">,</span> conn<span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token keyword">int</span> count <span class="token operator">=</span> <span class="token class-name"><span class="token namespace">cmd<span class="token punctuation">.</span></span>ExecuteNonQuery</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token keyword">if</span> <span class="token punctuation">(</span>count <span class="token operator">></span> <span class="token number">0</span><span class="token punctuation">)</span> <span class="token punctuation">{<!-- --></span> <span class="token class-name">MessageBox<span class="token punctuation">.</span>Show</span><span class="token punctuation">(</span><span class="token string">"添加成功!"</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token punctuation">}</span> <span class="token keyword">else</span> <span class="token punctuation">{<!-- --></span> <span class="token class-name">MessageBox<span class="token punctuation">.</span>Show</span><span class="token punctuation">(</span><span class="token string">"添加失败!"</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token punctuation">}</span> <span class="token class-name"><span class="token namespace">this<span class="token punctuation">.</span></span>Close</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token punctuation">}</span> <span class="token punctuation">}</span>
}
2.系统程序主入口
本系统主入口为系统启动时候执行的加载类,实现系统初始化参数等。
static class Program
{
/// <summary>
/// 应用程序的主入口点。
/// </summary>
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Login login = new Login();
Form1 f = new Form1();
login.StartPosition = FormStartPosition.CenterScreen;
Application.Run(login);
if(Form1.isLogin)
{
f.StartPosition = FormStartPosition.CenterScreen;
Application.Run(f);
}
}
}