private void btn_submit_Click_1(object sender, RoutedEventArgs e)//todo : fix bug { ObservableCollection <ui_course> custdata; custdata = (ObservableCollection <ui_course>)dg_course.DataContext; int i = 0; foreach (ui_course ss in custdata) { if (ss.Delete == true) { sp_bll.Course.delete(sp_bll.Course.get_single_course(ss.Num)); } if (ss.Update == true) { tbl_course course_update = sp_bll.Course.get_single_course(tablebefore[i].Num); try { course_update.C_Num = ss.Num; course_update.C_Name = ss.Name; course_update.C_Course = ss.Describe; } catch (Exception ex) { ModernDialog.ShowMessage("Some important data may be change unsuccessful \nsystem message:" + ex.Message + MainWindow.loginuser.U_Power, "User Input ERROR", MessageBoxButton.OK); } sp_bll.Course.update(course_update); } i++; } loadtable(); }
public JsonResult Create(tbl_course course) { try{ // TODO: Add insert logic here db.tbl_course.Add(course); db.SaveChanges(); return(Json("success", JsonRequestBehavior.AllowGet)); } catch { return(Json("failure", JsonRequestBehavior.AllowGet)); } }
// POST: Course/Edit/5 public JsonResult Edit(int id, tbl_course course) { try { // TODO: Add update logic here var oldcourse = db.tbl_course.SingleOrDefault(x => x.courseID == id); oldcourse.courseName = course.courseName; oldcourse.courseInstructor = course.courseInstructor; oldcourse.courseDescription = course.courseDescription; db.SaveChanges(); return(Json("success", JsonRequestBehavior.AllowGet)); } catch { return(Json("failure", JsonRequestBehavior.AllowGet)); } }
public static Err delete(tbl_course cc) { Err e = new Err(); try { DataBase db = new DataBase(); db.DeleteObject(cc); db.SaveChanges(); } catch (Exception ex) { e.res = false; e.info = ex.Message; } return(e); }
public static Err update(tbl_course cc) { Err e = new Err(); try { DataBase db = new DataBase(); tbl_course c = ( from d in db.tbl_course where d.C_index == cc.C_index select d ).Single(); c = cc; db.SaveChanges(); } catch (Exception ex) { e.res = false; e.info = ex.Message; } return(e); }
internal static bool Insert(string sCourseNo, string sCourseName, float fCourseTime, out string errmsg) { bool bOk = false; using (var context = new TrainingSign_Entities()) { //var items = from x in context.tbl_course // where 0 == x.name.CompareTo(sname) // select x; //if (items.Any()) //{ // errmsg = string.Format("{0} already exist", sname); // return false; //} //insert var entity = new tbl_course() { id = Guid.NewGuid(), course_no = sCourseNo, course_context = sCourseName, course_time = fCourseTime }; try { context.tbl_course.Add(entity); context.SaveChanges(); bOk = true; errmsg = string.Empty; } catch (Exception ex) { //errmsg = ex.Message; errmsg = "课程号已存在,无法插入!"; } } return(bOk); }
private void button1_Click(object sender, EventArgs e) { var dept = _con.Departments.SingleOrDefault(c => c.name == box_dept.SelectedItem.ToString()); for (int i = 1; i < a; i++) { dynamic txtCourse = "txt_course" + i.ToString(); dynamic boxSemester = "box_semester" + i.ToString(); string dataSubject = ((TextBox)panel2.Controls[txtCourse]).Text; string dataSubCode = ((ComboBox)panel2.Controls[boxSemester]).SelectedItem.ToString(); //Checking with Subject Code int noOfSem = Int32.Parse(dataSubCode); var data = _con.Courses.SingleOrDefault(c => (c.tbl_departmentId == dept.id) && (c.name == dataSubject.ToUpper()) && (c.total_number_of_Semester == noOfSem)); if (data != null) { MessageBox.Show("Course Already Exist!", "Information", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); } else { var dataCode = new tbl_course { name = dataSubject.ToUpper(), total_number_of_Semester = Convert.ToInt32(dataSubCode), tbl_departmentId = dept.id }; _con.Courses.Add(dataCode); _con.SaveChanges(); } } if (MessageBox.Show("Saved Successfully!", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information) == DialogResult.OK) { FirstPage obj = new FirstPage(userName); this.Close(); obj.Show(); } }