public bool BatchAdd(DataSet pDs) { StudentInfo stu = new StudentInfo(); //bool final = true; foreach (DataRow dr in pDs.Tables[0].Rows) { stu = new StudentInfo(); stu.SID=dr[0].ToString(); stu.SName=dr[1].ToString(); stu.LabClassID=dr[2].ToString(); stu.Rate=Int32.Parse(dr[3].ToString()); //出错会影响后面的数据 //if (final) // final = AddStudent(stu); cqme.StudentInfo.AddObject(stu); } try { cqme.SaveChanges(); return true; } catch (Exception ex) { throw ex; } }
private void BtnAdd_Click(object sender, EventArgs e) { if (txtSID.Text == string.Empty || txtSName.Text == string.Empty) { MessageBox.Show("����д����������Ϣ"); return; } StudentBLL bllstu = new StudentBLL(); if (bllstu.GetStudentBySID(txtSID.Text) != null) { MessageBox.Show("�Ѿ����ڸ�ѧ��"); return; } int Rate=0; try { StudentInfo student = new StudentInfo() { SID = txtSID.Text, SName = txtSName.Text, LabClassID = cmbClass.ClassID, Rate = Rate }; if (bllstu.AddStudent(student)) { MessageBox.Show("��ӳɹ�"); } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void btnSearch_Click(object sender, EventArgs e) { StudentBLL bstudent = new StudentBLL(); LabClassBLL cls = new LabClassBLL(); stuinfo = bstudent.GetStudentBySID(txtSID.Text); if (stuinfo == null) { MessageBox.Show("û�����ѧ��"); return; } lblSName.Text = stuinfo.SName; cmbClass.BindClass(ClassType.LabClass); cmbClass.ClassID = stuinfo.LabClassID; }
public Mark(string pSID) { InitializeComponent(); SID = pSID; lblSID.Text = SID; stuinfo = bStudent.GetStudentBySID(pSID); if (stuinfo == null || stuinfo.SID == null) { MessageBox.Show("û�����ѧ����", "����", MessageBoxButtons.OK, MessageBoxIcon.Error); this.Dispose(); return; } cmbMark.DataSource = ClassQuestionMark.BLL.Setting.Grades; cmbMark.SelectedIndex = 1; lblSName.Text = stuinfo.SName; }
public bool AddStudent(StudentInfo pStudent) { if (string.IsNullOrEmpty(pStudent.SID)) return false; if (string.IsNullOrEmpty(pStudent.SName)) pStudent.SName = ""; if (string.IsNullOrEmpty(pStudent.LabClassID)) return false; try { cqme.StudentInfo.AddObject(pStudent); cqme.SaveChanges(); return true; } catch (Exception ex) { throw ex; } }
public bool UpdateStudent(StudentInfo pStudent) { var linqstr = cqme.StudentInfo.Where(x => x.SID == pStudent.SID); if (linqstr.Count() > 0) { StudentInfo student = linqstr.First(); student = pStudent;//不知直接修改引用是否正确 try { cqme.SaveChanges(); } catch (Exception ex) { throw ex; } return true; } else return false; }
/// <summary> /// 创建新的 StudentInfo 对象。 /// </summary> /// <param name="sID">SID 属性的初始值。</param> public static StudentInfo CreateStudentInfo(global::System.String sID) { StudentInfo studentInfo = new StudentInfo(); studentInfo.SID = sID; return studentInfo; }
/// <summary> /// 用于向 StudentInfo EntitySet 添加新对象的方法,已弃用。请考虑改用关联的 ObjectSet<T> 属性的 .Add 方法。 /// </summary> public void AddToStudentInfo(StudentInfo studentInfo) { base.AddObject("StudentInfo", studentInfo); }