private void CourseForm_FormClosing(object sender, FormClosingEventArgs e) { dgvCourse[0, 0].Selected = true; // ---------------------------------------------------------------------------------------------- // var db = new LINQDataContext(); for (int rowCounter = 0; rowCounter < dgvCourse.RowCount - 1; rowCounter++) { // // search dgvClass.rows in db.Class // int ID_No = 0; int.TryParse(dgvCourse[0, rowCounter].Value.ToString(), out ID_No); // Define the query expression. IEnumerable<int> query = from course in db.Courses where course.Course_ID == ID_No select course.Course_ID; // try { if (query.ToArray().Length > 0) // EDIT { int intBuffer = 0; decimal decBuffer = 0; db.CourseEdit(ID_No, BranchID, (dgvCourse[1, rowCounter].Value != null) ? int.Parse(dgvCourse[1, rowCounter].Value.ToString()) : 0, (dgvCourse[10, rowCounter].Value != null) ? (string)dgvCourse[10, rowCounter].Value.ToString() : "", (dgvCourse[9, rowCounter].Value != null) ? (string)dgvCourse[9, rowCounter].Value.ToString() : "", (dgvCourse[11, rowCounter].Value != null) ? decimal.TryParse(dgvCourse[11, rowCounter].Value.ToString(), out decBuffer) ? decBuffer : 0 : 0, (dgvCourse[6, rowCounter].Value != null) ? (int.TryParse(dgvCourse[6, rowCounter].Value.ToString(), out intBuffer)) ? intBuffer : 0 : 0, (dgvCourse[7, rowCounter].Value != null) ? (int.TryParse(dgvCourse[7, rowCounter].Value.ToString(), out intBuffer)) ? intBuffer : 0 : 0, (dgvCourse[2, rowCounter].Value != null) ? (string)dgvCourse[2, rowCounter].Value.ToString() : "", (dgvCourse[4, rowCounter].Value != null) ? (string)dgvCourse[4, rowCounter].Value.ToString() : ""); } else // save { int intBuffer = 0; decimal decBuffer = 0; db.CourseSave(ID_No, BranchID, (dgvCourse[1, rowCounter].Value != null) ? int.Parse(dgvCourse[1, rowCounter].Value.ToString()) : 0, (dgvCourse[10, rowCounter].Value != null) ? (string)dgvCourse[10, rowCounter].Value.ToString() : "", (dgvCourse[9, rowCounter].Value != null) ? (string)dgvCourse[9, rowCounter].Value.ToString() : "", (dgvCourse[11, rowCounter].Value != null) ? decimal.TryParse(dgvCourse[11, rowCounter].Value.ToString(), out decBuffer) ? decBuffer : 0 : 0, (dgvCourse[6, rowCounter].Value != null) ? (int.TryParse(dgvCourse[6, rowCounter].Value.ToString(), out intBuffer)) ? intBuffer : 0 : 0, (dgvCourse[7, rowCounter].Value != null) ? (int.TryParse(dgvCourse[7, rowCounter].Value.ToString(), out intBuffer)) ? intBuffer : 0 : 0, (dgvCourse[2, rowCounter].Value != null) ? (string)dgvCourse[2, rowCounter].Value.ToString() : "", (dgvCourse[4, rowCounter].Value != null) ? (string)dgvCourse[4, rowCounter].Value.ToString() : ""); } } catch { } } db.Dispose(); }
private void CourseForm_FormClosing(object sender, FormClosingEventArgs e) { dgvCourse[0, 0].Selected = true; // ---------------------------------------------------------------------------------------------- // var db = new LINQDataContext(); for (int rowCounter = 0; rowCounter < dgvCourse.RowCount - 1; rowCounter++) { // // search dgvClass.rows in db.Class // int ID_No = 0; int.TryParse(dgvCourse[0, rowCounter].Value.ToString(), out ID_No); // Define the query expression. IEnumerable <int> query = from course in db.Courses where course.Course_ID == ID_No select course.Course_ID; // try { if (query.ToArray().Length > 0) // EDIT { int intBuffer = 0; decimal decBuffer = 0; db.CourseEdit(ID_No, BranchID, (dgvCourse[1, rowCounter].Value != null) ? int.Parse(dgvCourse[1, rowCounter].Value.ToString()) : 0, (dgvCourse[10, rowCounter].Value != null) ? (string)dgvCourse[10, rowCounter].Value.ToString() : "", (dgvCourse[9, rowCounter].Value != null) ? (string)dgvCourse[9, rowCounter].Value.ToString() : "", (dgvCourse[11, rowCounter].Value != null) ? decimal.TryParse(dgvCourse[11, rowCounter].Value.ToString(), out decBuffer) ? decBuffer : 0 : 0, (dgvCourse[6, rowCounter].Value != null) ? (int.TryParse(dgvCourse[6, rowCounter].Value.ToString(), out intBuffer)) ? intBuffer : 0 : 0, (dgvCourse[7, rowCounter].Value != null) ? (int.TryParse(dgvCourse[7, rowCounter].Value.ToString(), out intBuffer)) ? intBuffer : 0 : 0, (dgvCourse[2, rowCounter].Value != null) ? (string)dgvCourse[2, rowCounter].Value.ToString() : "", (dgvCourse[4, rowCounter].Value != null) ? (string)dgvCourse[4, rowCounter].Value.ToString() : ""); } else // save { int intBuffer = 0; decimal decBuffer = 0; db.CourseSave(ID_No, BranchID, (dgvCourse[1, rowCounter].Value != null) ? int.Parse(dgvCourse[1, rowCounter].Value.ToString()) : 0, (dgvCourse[10, rowCounter].Value != null) ? (string)dgvCourse[10, rowCounter].Value.ToString() : "", (dgvCourse[9, rowCounter].Value != null) ? (string)dgvCourse[9, rowCounter].Value.ToString() : "", (dgvCourse[11, rowCounter].Value != null) ? decimal.TryParse(dgvCourse[11, rowCounter].Value.ToString(), out decBuffer) ? decBuffer : 0 : 0, (dgvCourse[6, rowCounter].Value != null) ? (int.TryParse(dgvCourse[6, rowCounter].Value.ToString(), out intBuffer)) ? intBuffer : 0 : 0, (dgvCourse[7, rowCounter].Value != null) ? (int.TryParse(dgvCourse[7, rowCounter].Value.ToString(), out intBuffer)) ? intBuffer : 0 : 0, (dgvCourse[2, rowCounter].Value != null) ? (string)dgvCourse[2, rowCounter].Value.ToString() : "", (dgvCourse[4, rowCounter].Value != null) ? (string)dgvCourse[4, rowCounter].Value.ToString() : ""); } } catch { } } db.Dispose(); }