问题描述
usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Data;usingSystem.Drawing;usingSystem.Text;usingSystem.Windows.Forms;usingSystem.Data.SqlClient;usingMyForm.DBLibrary;usingMyForm.Common;namespaceMyForm{publicpartialclassfrmStudent:Form{DBBasedbBase=newDBBase();DataSetds=newDataSet();DataTabledt=newDataTable();Utilityutility;publicfrmStudent(){InitializeComponent();}privatevoidLoadStudent(){Stringsql="select*fromstudents";dt=dbBase.ExecuteSQLGetDataTable(sql);dgvStudent.DataSource=dt;}privatevoidLoadDep(){StringsqlText="select*fromDepartment";dt=dbBase.ExecuteSQLGetDataTable(sqlText);cmbSdept.DataSource=dt;cmbSdept.DisplayMember="Sdept";//cmbDep.r}privatevoidfrmStudent_Load(objectsender,EventArgse){LoadStudent();LoadDep();utility=newUtility(this);utility.SetControlsEnable(false);SetButtonStatus(false);}privatevoiddgvStudent_CellContentClick(objectsender,DataGridViewCellEventArgse){DataGridViewRowrow=dgvStudent.Rows[e.RowIndex];StringID=row.Cells["colSno"].Value.ToString().Trim();Stringname=row.Cells["colName"].Value.ToString().Trim();if(e.ColumnIndex==row.Cells["coldetail"].ColumnIndex){frmStudentDetailfrm=newfrmStudentDetail(name,ID);frm.Owner=this;frm.ShowDialog();}}privatevoiddgvStudent_KeyDown(objectsender,KeyEventArgse){if(e.KeyData==Keys.Enter){StringID=dgvStudent.Rows[dgvStudent.CurrentCellAddress.Y].Cells["colSno"].Value.ToString().Trim();//StringID=row.Cells["colSno"].Value.ToString().Trim();dgvStudent.Rows[dgvStudent.CurrentCellAddress.Y].Cells["colName"].Value.ToString().Trim()Stringname=dgvStudent.Rows[dgvStudent.CurrentCellAddress.Y].Cells["colName"].Value.ToString().Trim();frmStudentDetailfrm=newfrmStudentDetail(name,ID);frm.Owner=this;frm.ShowDialog();}}privatevoidbtnClose_Click(objectsender,EventArgse){this.Close();Dispose(true);}privatevoidSetButtonStatus(boolflag){btnAdd.Visible=!flag;btnSave.Visible=flag;btnCancel.Visible=flag;}privatevoidbtnAdd_Click(objectsender,EventArgse){utility.SetControlsEnable(true);SetButtonStatus(true);utility.ClearContent();}privatevoidbtnSave_Click(objectsender,EventArgse){if(!utility.CheckNull())return;//StringstrSno=tbSno.Text.Trim();StringstrName=tbSname.Text.Trim();StringstrSex=cmbSsex.Text.Trim();StringstrAge=tbSage.Text.Trim();StringstrDept=cmbSdept.Text.Trim();StringsqlText="insertintostudents(Sno,Sname,Ssex,Sage,Sdept)values('"+strSno+"','"+strName+"','"+strSex+"','"+strAge+"','"+strDept+"')";booltag=dbBase.ExecuteSQL(sqlText);if(tag){MessageBox.Show("插入成功!");}LoadStudent();utility.SetControlsEnable(false);SetButtonStatus(false);utility.ClearContent();dgvStudent.Rows[0].Selected=false;foreach(DataGridViewRowrowindgvStudent.Rows){if(row.Cells["colSno"].Value.ToString().Trim()==strSno){row.Selected=true;}}}privatevoidbtnCancel_Click(objectsender,EventArgse){SetButtonStatus(false);utility.SetControlsEnable(false);utility.ClearContent();}privatevoidtbSage_Validating(objectsender,CancelEventArgse){}privatevoidbtselect_Click(objectsender,EventArgse){}privatevoidbtdelete_Click(objectsender,EventArgse){}}}
解决方案
解决方案二:
各位高手帮帮忙啊,真的不知道从哪里下手,没学过C#或者提点点思路也可以.先谢谢拉!