public bool AddClass(Basic_Information basic) { string sql = "insert into Basic_Information(Garde,ClassId,Class,Department) values(" + basic.Garde + ",'" + Convert.ToInt32(basic.ClassId) + "','" + basic.Class + "','" + basic.Department + "')"; return(db.ExecSql(sql)); }
public event UpdateEventHandler updatelist1; //里面写事件 /// <summary> /// 确定添加 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btOk_Click(object sender, EventArgs e) { if (string.IsNullOrWhiteSpace(tbGrade.Text)) { MessageBox.Show("年级不能为空!", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Error); } else if (string.IsNullOrWhiteSpace(tbClass.Text)) { MessageBox.Show("班级不能为空!", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Error); } else if (string.IsNullOrWhiteSpace(tbClassId.Text)) { MessageBox.Show("班级代号不能为空!", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Error); } else if (string.IsNullOrWhiteSpace(tbDepartment.Text)) { MessageBox.Show("院系不能为空!", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { Basic_Information basic = new Basic_Information(); basic.Garde = tbGrade.Text.ToString(); basic.ClassId = Convert.ToInt32(tbClassId.Text.ToString()); basic.Class = tbClass.Text.ToString(); basic.Department = tbDepartment.Text.ToString(); if (Key == 1) { string oldGarde = Grade; int oldClassId = Convert.ToInt32(ClassID); string oldClass = Class; string oldDepartment = Department; if (addBll.UpdateClass(oldGarde, oldClassId, oldClass, oldDepartment, basic)) { MessageBox.Show("修改成功"); updatelist1(); DialogResult = System.Windows.Forms.DialogResult.OK; } else { MessageBox.Show("修改过程课程代号冲突!请重试"); } } else { if (addBll.AddClass(basic)) { MessageBox.Show("插入成功!"); updatelist1(); DialogResult = System.Windows.Forms.DialogResult.OK; } else { MessageBox.Show("插入过程课程代号冲突!请重试"); } } } }
/// <summary> /// 当年级改变时 搜索院系 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Garde_SelectedValueChanged(object sender, EventArgs e) { if (Garde.Text.ToString() == "--全部--") { Department.Text = ""; Dc = NewinNiTial();//初始化datatable dgv_课表.DataSource = null; return; } try { InitDatatabe(); Basic_Information information = (Basic_Information)Garde.SelectedItem; List <Basic_Information> informationList = new List <Basic_Information>(); informationList = bll.LoadCmbdt(information); Department.DataSource = informationList; Department.DisplayMember = "Department"; //Department.ValueMember = "Department"; if (CourseBuildingBLL.number == 0) { getOne(); ChangeHAndW(); NoSort(); return; } else { if (MessageBox.Show("是否保存", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Information) == DialogResult.Cancel) { FrmCourseBuildingAdd.CourseAdd.Clear(); CourseBuildingBLL.number = 0; InitDatatabe(); getOne(); ChangeHAndW(); NoSort(); } else { buttonX1_Click(sender, e);//Save(); //Dt[Garde.SelectedIndex, Class.SelectedIndex] = (DataTable)dgv_课表.DataSource; getOne(); ChangeHAndW(); NoSort(); } } } catch (Exception) { return; } }
/// <summary> /// 返回list实体类的年级信息 /// sqldb是基层辅助类 用来对数据库的基本操作 /// </summary> /// <returns></returns> public List <Basic_Information> LoadCobGrd() { List <Basic_Information> list = new List <Basic_Information>(); string sql = "select Garde from Basic_Information GROUP BY Garde"; SqlDB db = new SqlDB(); DataTable dt = db.FillDt(sql); foreach (DataRow item in dt.Rows) { Basic_Information information = new Basic_Information(); information.Garde = item["Garde"].ToString(); list.Add(information); } return(list); }
/// <summary> /// 根据院系查找班级并将班级list实体化返回 /// </summary> /// <param name="Grade"></param> /// <returns></returns> public List <Basic_Information> LoadCmbdt(Basic_Information Grade) { SqlDB db = new SqlDB(); string sql = "select distinct Department from Basic_Information where Garde='" + Grade.Garde + "'"; List <Basic_Information> list = new List <Basic_Information>(); DataTable dt = new DataTable(); dt = db.FillDt(sql); foreach (DataRow item in dt.Rows) { Basic_Information information = new Basic_Information(); information.Department = item["Department"].ToString(); list.Add(information); } return(list); }
/// <summary> /// 初始化基础信息 /// </summary> void Init() { Basic_Information xx = (Basic_Information)building.Garde.SelectedItem; GradeName = xx.Garde; ClassName = building.Class.Text; WeekDayNum = building.dgv_课表.CurrentCell.ColumnIndex; sectionNum = building.dgv_课表.CurrentCell.RowIndex; GardeNumberNow = building.Garde.SelectedIndex; ClassNumberNow = building.Class.SelectedIndex; WeekDay = building.dgv_课表.Columns[WeekDayNum].HeaderText; section = building.dgv_课表.Rows[sectionNum].Cells[0].Value.ToString(); Some = Building.Text + "|" + Building_id.Text + "|" + ClassRoom.Text + "|" + Course.Text + "|" + Teacher1.Text + "|" + Week.Text; whole = Some + "|" + GradeName + "|" + ClassName + "|" + WeekDay + "|" + section + "|" + building.year.Text + "|" + building.term.Text; oldwhole = building.Dt[GardeNumberNow, ClassNumberNow].Rows[sectionNum][WeekDay] + "|" + GradeName + "|" + ClassName + "|" + WeekDay + "|" + section + "|" + building.year.Text + "|" + building.term.Text; }
public bool UpdateClass(string oldGarde, int oldClassId, string oldClass, string oldDepartment, Basic_Information basic) { return(addDal.UpdateClass(oldGarde, oldClassId, oldClass, oldDepartment, basic)); }
public bool AddClass(Basic_Information basic) { return(addDal.AddClass(basic)); }
public bool UpdateClass(string oldGarde, int oldClassId, string oldClass, string oldDepartment, Basic_Information basic) { try { string sql = "update Basic_Information set Garde='" + basic.Garde + "',ClassId='" + basic.ClassId + "',Class='" + basic.Class + "',Department='" + basic.Department + "' where Garde='" + oldGarde + "' and ClassId='" + oldClassId + "' and Class='" + oldClass + "' and Department='" + oldDepartment + "'"; return(db.ExecSql(sql)); } catch { return(false); } }
/// <summary> /// 获取院系 /// </summary> /// <param name="information"></param> /// <returns></returns> public List <Basic_Information> LoadCmbdt(Basic_Information information) { return(dal.LoadCmbdt(information)); }