冲刺阶段 day 9
项目进展
昨天终于完成了教师部分的内容,今天我们又重新开始对之前系部设置不能实现的内容进行了编写,之前缺少删除和查询也做了补充,在与数据库的连接上也做了修改和更新。
存在问题
由于是之前遇到困难没做完的内容,今天重新拾起,思路有些混乱,在编写上和学生教师管理也有所不同,所以编写起来还是很困难,数据库的连接上也总是出现问题。
心得体会
好在因为成功做了几个部分之后,再重新拾起这个当初暂且放下的部分,在方法上也有一些启发,虽然不是完全一样,但是更得心应手了。所以我们几个人一起通过查资料,上网将系部设置这个部分的内容做了修改补充完善,终于落成。通过小组作业,我们的配合更加默契,懂得做一个项目,小组的分工和配合。短短几周时间我们从散漫变得凝聚起来,都是来自于这个项目的力量。无论是知识还是经历,我都觉得很有收获!
以下为部分代码
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Data.OleDb; using System.Configuration; namespace GengdanContactsMIS_WinForm { public partial class DepartmentFrm : Form { //string conStr; DB db; public DepartmentFrm() { //conStr = ConfigurationManager.ConnectionStrings["ConnectionString"].ToString(); InitializeComponent(); db = new DB(); BindDepartment(); } void BindDepartment() { /* //string conStr = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|DataDirectory|\GengdanContactsDB.accdb"; OleDbConnection con = new OleDbConnection(conStr); string sql = "select DepartmentId as 系部编号,DepartmentName as 系部名称 from Department"; OleDbDataAdapter adp = new OleDbDataAdapter(sql, con); DataSet ds = new DataSet(); adp.Fill(ds, "Department"); dataGridView1.DataSource = ds.Tables["Department"];*/ string sql = "select DepartmentId as 系部编号,DepartmentName as 系部名称 from Department"; DataSet ds = db.GetDataSet(sql, "Department"); dataGridView1.DataSource = ds.Tables["Department"]; } private void btnAdd_Click(object sender, EventArgs e) { /*// string conStr = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|DataDirectory|\GengdanContactsDB.accdb"; OleDbConnection con = new OleDbConnection(conStr); string sql = "insert into Department(DepartmentId,DepartmentName)values(" + txtDepartmentId.Text + ",'" + txtDepartmentName.Text + "')"; OleDbCommand cmd = new OleDbCommand(sql,con); con.Open(); cmd.ExecuteNonQuery(); MessageBox.Show("系部信息增加成功!"); con.Close(); BindDepartment();*/ string sql = "insert into Department(DepartmentId,DepartmentName)values(" + txtDepartmentId.Text + ",'" + txtDepartmentName.Text + "')"; db.ExecuteSQL(sql); BindDepartment(); } private void btnUpdate_Click(object sender, EventArgs e) { int rowIndex = dataGridView1.CurrentCell.RowIndex; string DepartmentId = dataGridView1.Rows[rowIndex].Cells[0].Value.ToString(); string DepartmentName = dataGridView1.Rows[rowIndex].Cells[1].Value.ToString(); string sql = "update Department set DepartmentName='" + DepartmentName + "' where DepartmentId=" + DepartmentId; db.ExecuteSQL(sql); } private void btnDelete_Click(object sender, EventArgs e) { int rowIndex = dataGridView1.CurrentCell.RowIndex; string DepartmentId = dataGridView1.Rows[rowIndex].Cells[0].Value.ToString(); string sql = "delete from Department where DepartmentId=" + DepartmentId; db.ExecuteSQL(sql); BindDepartment(); } private void btnSearch_Click(object sender, EventArgs e) { /*string sql = "select * from Department where DepartmentId="+txtDepartmentId.Text; DataSet ds = db.GetDataSet(sql, "d"); dataGridView1.DataSource = ds.Tables["d"];*/ string sql = "select * from Department where DepartmentName='" + txtDepartmentName.Text+"'"; DataSet ds = db.GetDataSet(sql, "d"); dataGridView1.DataSource = ds.Tables["d"]; } private void btnCancel_Click(object sender, EventArgs e) { this.Close(); } private void DepartmentFrm_Load(object sender, EventArgs e) { } } }
记录人:于悦