Project Progress: Department, professional, class management these three no students, the teacher management part of the input projects, so the form is relatively simple, the code is simple, the process is smooth, with the previous writing experience, a lot of code can be copied directly over, the more the more successful writing, The last module has been run to the last department.
Experience: practice makes perfect, more exercises to master!
Department Management Code:
usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Data;usingSystem.Drawing;usingSystem.Linq;usingSystem.Text;usingSystem.Windows.Forms;usingSystem.Data.OleDb;usingSystem.Configuration;namespacegengdancontactsmis_winform{ Public Partial classDepartmentfrm:form {//string constr;DB DB; Publicdepartmentfrm () {//constr = configurationmanager.connectionstrings["ConnectionString"]. ToString (); InitializeComponent (); DB=NewDB (); Binddepartment (); } voidbinddepartment () {/*//string constr = @ "Provider=microsoft.ace.oledb.12.0;data source=| DATADIRECTORY|\GENGDANCONTACTSDB.ACCDB "; OleDbConnection con = new OleDbConnection (CONSTR); String sql = "Select DepartmentID as part number, departmentname as department name from Department"; OleDbDataAdapter ADP = new OleDbDataAdapter (sql, con); DataSet ds = new DataSet (); Adp. Fill (ds, "Department"); Datagridview1.datasource = ds. tables["Department"];*/ stringsql ="Select DepartmentID as department number, departmentname as department name from Department"; DataSet DS= db. GetDataSet (SQL,"Department"); Datagridview1.datasource= ds. tables["Department"]; } Private voidbtnAdd_Click (Objectsender, 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 + ", '" + Txtdepartmentna Me. Text + "')"; OleDbCommand cmd = new OleDbCommand (Sql,con); Con. Open (); Cmd. ExecuteNonQuery (); MessageBox.Show ("department information added successfully!"); Con. Close (); Binddepartment ();*/ stringsql ="INSERT INTO Department (departmentid,departmentname) VALUES ("+ Txtdepartmentid.text +", '"+ Txtdepartmentname.text +"')"; Db. ExecuteSQL (SQL); Binddepartment (); } Private voidBtnupdate_click (Objectsender, EventArgs e) { intRowIndex =DataGridView1.CurrentCell.RowIndex; stringDepartmentID = Datagridview1.rows[rowindex]. cells[0]. Value.tostring (); stringDepartmentname = Datagridview1.rows[rowindex]. cells[1]. Value.tostring (); stringsql ="Update Department set departmentname= '"+ Departmentname +"' where departmentid="+DepartmentID; Db. ExecuteSQL (SQL); } Private voidBtndelete_click (Objectsender, EventArgs e) { intRowIndex =DataGridView1.CurrentCell.RowIndex; stringDepartmentID = Datagridview1.rows[rowindex]. cells[0]. Value.tostring (); stringsql ="Delete from Department where departmentid="+DepartmentID; Db. ExecuteSQL (SQL); Binddepartment (); } Private voidbtnSearch_Click (Objectsender, EventArgs e) { /*String sql = "SELECT * from Department where departmentid=" +txtdepartmentid.text; DataSet ds = db. GetDataSet (SQL, "D"); Datagridview1.datasource = ds. tables["D"];*/ stringsql ="SELECT * from Department where departmentname= '"+ txtdepartmentname.text+"'"; DataSet DS= db. GetDataSet (SQL,"D"); Datagridview1.datasource= ds. tables["D"]; } Private voidBtncancel_click (Objectsender, EventArgs e) { This. Close (); } }}
Record Person: Wendy
Sprint Stage Day11