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 dgvClass_UserDeletingRow(object sender, DataGridViewRowCancelEventArgs e) { int id = 0; if (int.TryParse(e.Row.Cells[0].Value.ToString(), out id)) { var db = new LINQDataContext(); db.Priority_ProfessorDeleteClass(id); db.Classroom_TimeDeleteClass(id); db.Group_ID_ListDeleteClass(id); db.ClassDelete(id); db.Dispose(); } }
private void ProfessorForm_FormClosing(object sender, FormClosingEventArgs e) { dgvProfessor[0, 0].Selected = true; // ---------------------------------------------------------------------------------------------- // var db = new LINQDataContext(); for (int rowCounter = 0; rowCounter < dgvProfessor.RowCount - 1; rowCounter++) { // // search dgvProfessor.rows in db.Professor // int ID_No = 0; int.TryParse(dgvProfessor[0, rowCounter].Value.ToString(), out ID_No); // Define the query expression. IEnumerable <int> query = from prof in db.Professors where prof.ID == ID_No select prof.ID; if (query.ToArray().Length > 0) // EDIT { db.ProfessorEdit(ID_No, (dgvProfessor[1, rowCounter].Value != null) ? (string)dgvProfessor[1, rowCounter].Value.ToString() : "", (dgvProfessor[2, rowCounter].Value != null) ? (string)dgvProfessor[2, rowCounter].Value.ToString() : "", (dgvProfessor[3, rowCounter].Value != null && dgvProfessor[3, rowCounter].Value.ToString().ValidateEmail()) ? (string)dgvProfessor[3, rowCounter].Value.ToString() : "", (dgvProfessor[4, rowCounter].Value != null) ? (string)dgvProfessor[4, rowCounter].Value.ToString() : "", (dgvProfessor[6, rowCounter].Value != null) ? (string)dgvProfessor[6, rowCounter].Value.ToString() : ""); } else // SAVE NEW { db.ProfessorSave(ID_No, (dgvProfessor[1, rowCounter].Value != null) ? (string)dgvProfessor[1, rowCounter].Value.ToString() : "", (dgvProfessor[2, rowCounter].Value != null) ? (string)dgvProfessor[2, rowCounter].Value.ToString() : "", (dgvProfessor[3, rowCounter].Value != null && dgvProfessor[3, rowCounter].Value.ToString().ValidateEmail()) ? (string)dgvProfessor[3, rowCounter].Value.ToString() : "", (dgvProfessor[4, rowCounter].Value != null) ? (string)dgvProfessor[4, rowCounter].Value.ToString() : "", (dgvProfessor[6, rowCounter].Value != null) ? (string)dgvProfessor[6, rowCounter].Value.ToString() : ""); } } db.Dispose(); }
private void RoomForm_FormClosing(object sender, FormClosingEventArgs e) { dgvRoom[0, 0].Selected = true; // ---------------------------------------------------------------------------------------------- // var db = new LINQDataContext(); for (int rowCounter = 0; rowCounter < dgvRoom.RowCount - 1; rowCounter++) { try { // // search dgvRoom.rows in db.Room // int ID_No = 0; int.TryParse(dgvRoom[0, rowCounter].Value.ToString(), out ID_No); // Define the query expression. IEnumerable <int> query = from room in db.Rooms where room.Room_ID == ID_No select room.Room_ID; if (query.ToArray().Length > 0) // EDIT { int size = 0; db.RoomEdit(ID_No, (dgvRoom[1, rowCounter].Value != null) ? (string)dgvRoom[1, rowCounter].Value.ToString() : "", (dgvRoom[2, rowCounter].Value != null) ? dgvRoom[2, rowCounter].Value.ToString() : "", (dgvRoom[3, rowCounter].Value != null) ? (int.TryParse(dgvRoom[3, rowCounter].Value.ToString(), out size)) ? size : 0 : 0); } else { int size = 0; db.RoomSave(ID_No, (dgvRoom[1, rowCounter].Value != null) ? (string)dgvRoom[1, rowCounter].Value.ToString() : "", (dgvRoom[2, rowCounter].Value != null) ? dgvRoom[2, rowCounter].Value.ToString() : "", (dgvRoom[3, rowCounter].Value != null) ? (int.TryParse(dgvRoom[3, rowCounter].Value.ToString(), out size)) ? size : 0 : 0); } } catch { } } db.Dispose(); }
private void dgvCourse_UserDeletingRow(object sender, DataGridViewRowCancelEventArgs e) { int id = 0; if (int.TryParse(e.Row.Cells[0].Value.ToString(), out id)) { var db = new LINQDataContext(); // Define the query expression. IEnumerable <int> query = from classs in db.Classes where classs.Course_ID == id select classs.Class_ID; // // if exist data in class table : // if (query.ToArray().Length > 0) { string class_ID_List = ""; foreach (var anyClass in query) { class_ID_List += anyClass.ToString() + " and "; } class_ID_List = class_ID_List.Substring(0, class_ID_List.Length - 4); e.Cancel = true; MessageBox.Show("Information classes with class numbers " + class_ID_List + "is related to Course " + ((e.Row.Cells[10].Value != null) ? e.Row.Cells[10].Value.ToString() : "NULL") + ".\n First, this information can change classes.", "Delete Row Error", MessageBoxButtons.OK, MessageBoxIcon.Stop, MessageBoxDefaultButton.Button1); } else { db.CourseDelete(id); } db.Dispose(); } }
private void BranchForm_FormClosing(object sender, FormClosingEventArgs e) { dgvBranch[0, 0].Selected = true; // ---------------------------------------------------------------------------------------------- // var db = new LINQDataContext(); for (int rowCounter = 0; rowCounter < dgvBranch.RowCount - 1; rowCounter++) { try { // // search dgvBranch.rows in db.Branch // int ID_No = 0; int.TryParse(dgvBranch[0, rowCounter].Value.ToString(), out ID_No); // Define the query expression. var query = (from branch in db.Branches where branch.ID_Branch == ID_No select branch).SingleOrDefault(); if (query != null) // EDIT { db.BranchEdit(ID_No, (dgvBranch[1, rowCounter].Value != null) ? (string)dgvBranch[1, rowCounter].Value.ToString() : "", (dgvBranch[2, rowCounter].Value != null) ? (string)dgvBranch[2, rowCounter].Value.ToString() : ""); } else // save { db.BranchSave(ID_No, (dgvBranch[1, rowCounter].Value != null) ? (string)dgvBranch[1, rowCounter].Value.ToString() : "", (dgvBranch[2, rowCounter].Value != null) ? (string)dgvBranch[2, rowCounter].Value.ToString() : ""); } } catch { } } db.Dispose(); }
private void dgvGroup_UserDeletingRow(object sender, DataGridViewRowCancelEventArgs e) { int id = 0; if (int.TryParse(e.Row.Cells[0].Value.ToString(), out id)) { var db = new LINQDataContext(); // Define the query expression. var cquery = (from classs in db.Group_ID_Lists where classs.Group_ID == id select classs).ToArray(); if (cquery != null) { string query = @"DELETE From dbo.Group_ID_List Where Group_ID = {0}"; db.ExecuteQuery<object>(query, id); } else { db.New_GroupsPerClassDeleteByGroupID(id); db.GroupsDelete(id); } db.Dispose(); } }
private void dgvGroup_UserDeletingRow(object sender, DataGridViewRowCancelEventArgs e) { int id = 0; if (int.TryParse(e.Row.Cells[0].Value.ToString(), out id)) { var db = new LINQDataContext(); // Define the query expression. var cquery = (from classs in db.Group_ID_Lists where classs.Group_ID == id select classs).ToArray(); if (cquery != null) { string query = @"DELETE From dbo.Group_ID_List Where Group_ID = {0}"; db.ExecuteQuery <object>(query, id); } else { db.New_GroupsPerClassDeleteByGroupID(id); db.GroupsDelete(id); } db.Dispose(); } }
private void ProfessorForm_FormClosing(object sender, FormClosingEventArgs e) { dgvProfessor[0, 0].Selected = true; // ---------------------------------------------------------------------------------------------- // var db = new LINQDataContext(); for (int rowCounter = 0; rowCounter < dgvProfessor.RowCount - 1; rowCounter++) { // // search dgvProfessor.rows in db.Professor // int ID_No = 0; int.TryParse(dgvProfessor[0, rowCounter].Value.ToString(), out ID_No); // Define the query expression. IEnumerable<int> query = from prof in db.Professors where prof.ID == ID_No select prof.ID; if (query.ToArray().Length > 0) // EDIT { db.ProfessorEdit(ID_No, (dgvProfessor[1, rowCounter].Value != null) ? (string)dgvProfessor[1, rowCounter].Value.ToString() : "", (dgvProfessor[2, rowCounter].Value != null) ? (string)dgvProfessor[2, rowCounter].Value.ToString() : "", (dgvProfessor[3, rowCounter].Value != null && dgvProfessor[3, rowCounter].Value.ToString().ValidateEmail()) ? (string)dgvProfessor[3, rowCounter].Value.ToString() : "", (dgvProfessor[4, rowCounter].Value != null) ? (string)dgvProfessor[4, rowCounter].Value.ToString() : "", (dgvProfessor[6, rowCounter].Value != null) ? (string)dgvProfessor[6, rowCounter].Value.ToString() : ""); } else // SAVE NEW { db.ProfessorSave(ID_No, (dgvProfessor[1, rowCounter].Value != null) ? (string)dgvProfessor[1, rowCounter].Value.ToString() : "", (dgvProfessor[2, rowCounter].Value != null) ? (string)dgvProfessor[2, rowCounter].Value.ToString() : "", (dgvProfessor[3, rowCounter].Value != null && dgvProfessor[3, rowCounter].Value.ToString().ValidateEmail()) ? (string)dgvProfessor[3, rowCounter].Value.ToString() : "", (dgvProfessor[4, rowCounter].Value != null) ? (string)dgvProfessor[4, rowCounter].Value.ToString() : "", (dgvProfessor[6, rowCounter].Value != null) ? (string)dgvProfessor[6, rowCounter].Value.ToString() : ""); } } db.Dispose(); }
private void dgvBranch_UserDeletingRow(object sender, DataGridViewRowCancelEventArgs e) { int id = 0; if (int.TryParse(e.Row.Cells[0].Value.ToString(), out id)) { var db = new LINQDataContext(); // Define the query expression. IEnumerable <int> qGroupID = from groups in db.Groups where groups.Branch_Selection == id select groups.ID; // // Define the query expression. IEnumerable <int> qCourseID = from course in db.Courses where course.Branch_ID == id select course.Course_ID; // // if exist data in the Groups table : // if (qGroupID.ToArray().Length > 0) { string groups_ID_List = ""; foreach (var anyGroup in qGroupID) { groups_ID_List += anyGroup.ToString() + " and "; } groups_ID_List = groups_ID_List.Substring(0, groups_ID_List.Length - 4); e.Cancel = true; MessageBox.Show("Information Groups with group numbers " + groups_ID_List + "is related to Branch (" + ((e.Row.Cells[1].Value != null) ? e.Row.Cells[1].Value.ToString() : "NULL") + ").\n First, this information can change groups.", "Delete Row Error", MessageBoxButtons.OK, MessageBoxIcon.Stop, MessageBoxDefaultButton.Button1); } // // if exist data in the Groups table : // else if (qCourseID.ToArray().Length > 0) { string course_ID_List = ""; foreach (var anyCourse in qCourseID) { course_ID_List += anyCourse.ToString() + " and "; } course_ID_List = course_ID_List.Substring(0, course_ID_List.Length - 4); e.Cancel = true; MessageBox.Show("Information courses with course numbers " + course_ID_List + "is related to Branch (" + ((e.Row.Cells[1].Value != null) ? e.Row.Cells[1].Value.ToString() : "NULL") + ").\n First, this information can change courses.", "Delete Row Error", MessageBoxButtons.OK, MessageBoxIcon.Stop, MessageBoxDefaultButton.Button1); } else { db.BranchDelete(id); } 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(); }
private void dgvCourse_UserDeletingRow(object sender, DataGridViewRowCancelEventArgs e) { int id = 0; if (int.TryParse(e.Row.Cells[0].Value.ToString(), out id)) { var db = new LINQDataContext(); // Define the query expression. IEnumerable<int> query = from classs in db.Classes where classs.Course_ID == id select classs.Class_ID; // // if exist data in class table : // if (query.ToArray().Length > 0) { string class_ID_List = ""; foreach (var anyClass in query) { class_ID_List += anyClass.ToString() + " and "; } class_ID_List = class_ID_List.Substring(0, class_ID_List.Length - 4); e.Cancel = true; MessageBox.Show("Information classes with class numbers " + class_ID_List + "is related to Course " + ((e.Row.Cells[10].Value != null) ? e.Row.Cells[10].Value.ToString() : "NULL") + ".\n First, this information can change classes.", "Delete Row Error", MessageBoxButtons.OK, MessageBoxIcon.Stop, MessageBoxDefaultButton.Button1); } else { db.CourseDelete(id); } db.Dispose(); } }
private void ImportMDF() { try { Set_Cursor_Value("WaitCursor"); var originDB = new LINQDataContext(); var newDB = new LINQDataContext(FileName); Set_prbMain_Value(0); #region 1. Professor DATA // // Delete old Professor data and Fill it by newDB data // var aryProfessor = newDB.Professors.ToArray(); if (aryProfessor.Length > 0) { string query = @"DELETE FROM dbo.New_GroupsPerClass " + @"DELETE FROM dbo.Classroom_time " + @"DELETE FROM dbo.Priority_Professor " + @"DELETE FROM dbo.Professor"; originDB.ExecuteQuery<object>(query); // // read and save new data // foreach (var row in aryProfessor) { originDB.ProfessorSave(row.ID, row.Name_Professor, row.Branch, row.Email, row.EducationDegree, row.Schedule); } } #endregion Set_prbMain_Value(10); #region 2. Branch DATA // // Delete old Branch data and Fill it by newDB data // var aryBranch = newDB.Branches.ToArray(); if (aryBranch.Length > 0) { string query = @"DELETE FROM dbo.New_GroupsPerClass " + @"DELETE FROM dbo.Group_ID_List " + @"DELETE FROM dbo.Classroom_Time " + @"DELETE FROM dbo.Class " + @"DELETE FROM dbo.Course " + @"DELETE FROM dbo.Groups " + @"DELETE FROM dbo.Branch"; originDB.ExecuteQuery<object>(query); // // read and save new data // foreach (var row in aryBranch) { originDB.BranchSave(row.ID_Branch, row.Branch_Name, row.Degree); } } #endregion Set_prbMain_Value(20); #region 3. Room_Type DATA // // Delete old Room_Type data and Fill it by newDB data // var aryRoom_Type = newDB.Room_Types.ToArray(); if (aryRoom_Type.Length > 0) { string query = @"DELETE FROM dbo.New_GroupsPerClass " + @"DELETE FROM dbo.Classroom_time " + @"DELETE FROM dbo.Room " + @"DELETE FROM dbo.Priority_Professor " + @"DELETE FROM dbo.Group_ID_List " + @"DELETE FROM dbo.Class " + @"DELETE FROM dbo.Room_Type"; originDB.ExecuteQuery<object>(query); // // read and save new data // foreach (var row in aryRoom_Type) { originDB.Room_TypeSave(row.Type_Name); } } #endregion Set_prbMain_Value(30); #region 4. Course DATA // // Delete old Course data and Fill it by newDB data // var aryCourse = newDB.Courses.ToArray(); if (aryCourse.Length > 0) { string query = @"DELETE FROM dbo.New_GroupsPerClass " + @"DELETE FROM dbo.Classroom_time " + @"DELETE FROM dbo.Group_ID_List " + @"DELETE FROM dbo.Priority_Professor " + @"DELETE FROM dbo.Class " + @"DELETE FROM dbo.Course"; originDB.ExecuteQuery<object>(query); // // read and save new data // foreach (var row in aryCourse) { originDB.CourseSave(row.Course_ID, row.Branch_ID, row.TermNo, row.Name_Course, row.Type_Course, row.CourseCode, row.TheoryUnitNo, row.PracticalUnitNo, row.InRequisite_CourseID, row.PreRequisite_CourseID); } } #endregion Set_prbMain_Value(40); #region 5. Groups DATA // // Delete old Group data and Fill it by newDB data // var aryGroup = newDB.Groups.ToArray(); if (aryGroup.Length > 0) { string query = @"DELETE FROM dbo.New_GroupsPerClass " + @"DELETE FROM dbo.Group_ID_List " + @"DELETE FROM dbo.Groups"; originDB.ExecuteQuery<object>(query); // // read and save new data // foreach (var row in aryGroup) { originDB.GroupsSave(row.ID, row.Semester_Entry_Year, row.Semester_Entry_FS, row.Branch_Selection, row.Size_No); } } #endregion Set_prbMain_Value(50); #region 6. Room DATA // // Delete old Room data and Fill it by newDB data // var aryRoom = newDB.Rooms.ToArray(); if (aryRoom.Length > 0) { string query = @"DELETE FROM dbo.New_GroupsPerClass " + @"DELETE FROM dbo.Classroom_time " + @"DELETE FROM dbo.Room"; originDB.ExecuteQuery<object>(query); // // read and save new data // foreach (var row in aryRoom) { originDB.RoomSave(row.Room_ID, row.Name_Room, row.Type_Room, row.Size_No); } } #endregion Set_prbMain_Value(60); #region 7. Class DATA // // Delete old Class data and Fill it by newDB data // var aryClass = newDB.Classes.ToArray(); if (aryClass.Length > 0) { string query = @"DELETE FROM dbo.New_GroupsPerClass " + @"DELETE FROM dbo.Group_ID_List " + @"DELETE FROM dbo.Classroom_Time " + @"DELETE FROM dbo.Priority_Professor " + @"DELETE FROM dbo.Class"; originDB.ExecuteQuery<object>(query); // // read and save new data // foreach (var row in aryClass) { originDB.ClassSave(row.Class_ID, row.Course_ID, row.Practical_unit, row.Theory_unit, row.RoomType); } } #endregion Set_prbMain_Value(70); #region 8. Group_ID_List DATA // // Delete old Group_ID_List data and Fill it by newDB data // var aryGroup_ID_List = newDB.Group_ID_Lists.ToArray(); if (aryGroup_ID_List.Length > 0) { string query = @"DELETE FROM dbo.Group_ID_List"; originDB.ExecuteQuery<object>(query); // // read and save new data // foreach (var row in aryGroup_ID_List) { originDB.Group_ID_ListSave(row.Group_ID, row.Class_ID); } } #endregion Set_prbMain_Value(80); #region 9. Priority_Professor DATA // // Delete old Classroom_Time data and Fill it by newDB data // var aryPriority_Professor = newDB.Priority_Professors.ToArray(); if (aryPriority_Professor.Length > 0) { string query = @"DELETE FROM dbo.Priority_Professor"; originDB.ExecuteQuery<object>(query); // // read and save new data // foreach (var row in aryPriority_Professor) { originDB.Priority_ProfessorSave(row.Professor_ID, row.Class_ID, row.Priority); } } #endregion Set_prbMain_Value(90); #region 10. Classroom_Time DATA // // Delete old Classroom_Time data and Fill it by newDB data // var aryClassroom_Time = newDB.Classroom_Times.ToArray(); var aryNew_GroupsPerClass = newDB.New_GroupsPerClasses.ToArray(); if (aryClassroom_Time.Length > 0) { originDB.Classroom_TimeDeleteAll(); // // read and save new data about Classroom_Time // foreach (var row in aryClassroom_Time) { originDB.Classroom_TimeSave(row.Room_ID, row.Class_ID, row.Professor_ID, row.StartTime, row.Duration, row.Day_No); } // // read and save new data about New_GroupsPerClass // foreach (var row in aryNew_GroupsPerClass) { originDB.New_GroupsPerClassSave(row.Room_ID, row.Class_ID, row.StartTime, row.Day_No, row.Group_ID); } } #endregion Set_prbMain_Value(98); originDB.Connection.Close(); originDB.Dispose(); newDB.Connection.Close(); newDB.Dispose(); Set_prbMain_Value(100); } catch (Exception ex) { MessageBox.Show(ex.Message, "اشکال در بازیابی اطلاعات"); thImport.Abort(); return; } finally { Thread.CurrentThread.Join(1000); Set_prbMain_Value(0); Set_Cursor_Value("Default"); bwExportBtnCheck.RunWorkerAsync(); Thread.CurrentThread.Abort(); } }
private void RoomForm_FormClosing(object sender, FormClosingEventArgs e) { dgvRoom[0, 0].Selected = true; // ---------------------------------------------------------------------------------------------- // var db = new LINQDataContext(); for (int rowCounter = 0; rowCounter < dgvRoom.RowCount - 1; rowCounter++) { try { // // search dgvRoom.rows in db.Room // int ID_No = 0; int.TryParse(dgvRoom[0, rowCounter].Value.ToString(), out ID_No); // Define the query expression. IEnumerable<int> query = from room in db.Rooms where room.Room_ID == ID_No select room.Room_ID; if (query.ToArray().Length > 0) // EDIT { int size = 0; db.RoomEdit(ID_No, (dgvRoom[1, rowCounter].Value != null) ? (string)dgvRoom[1, rowCounter].Value.ToString() : "", (dgvRoom[2, rowCounter].Value != null) ? dgvRoom[2, rowCounter].Value.ToString() : "", (dgvRoom[3, rowCounter].Value != null) ? (int.TryParse(dgvRoom[3, rowCounter].Value.ToString(), out size)) ? size : 0 : 0); } else { int size = 0; db.RoomSave(ID_No, (dgvRoom[1, rowCounter].Value != null) ? (string)dgvRoom[1, rowCounter].Value.ToString() : "", (dgvRoom[2, rowCounter].Value != null) ? dgvRoom[2, rowCounter].Value.ToString() : "", (dgvRoom[3, rowCounter].Value != null) ? (int.TryParse(dgvRoom[3, rowCounter].Value.ToString(), out size)) ? size : 0 : 0); } } catch { } } db.Dispose(); }
// Parse file and store parsed object public void ParseFile(LINQDataContext db) { // clear previously parsed objects _professors.Clear(); _studentGroups.Clear(); _courses.Clear(); _rooms.Clear(); _courseClasses.Clear(); Room.RestartIDs(); // // Save Professor Data // foreach (var any in db.Professors) { ProfessorInfoCompiler pIc = new ProfessorInfoCompiler(); Professor p; if (pIc.StartScanner(any.Schedule)) { p = new Professor(any.ID, any.Name_Professor, pIc.CompiledData); _professors.Add(p.GetId, p); } } // // Save StudentsGroup Data // foreach (var any in db.Groups) { StudentsGroup sg; string sg_name = string.Format(CultureInfo.CurrentCulture, "{0} {1} {2}-{3}", any.Branch.Degree, any.Branch.Branch_Name, any.Semester_Entry_Year, (any.Semester_Entry_FS) ? "1" : "2"); sg = new StudentsGroup(any.ID, sg_name, any.Size_No); _studentGroups.Add(sg.GetId, sg); } // // Save Course Data // foreach (var any in db.Courses) { Course c; c = new Course(any.Course_ID, any.Name_Course); _courses.Add(c.GetId, c); } // // Save Room Data // foreach (var any in db.Rooms) { Room r; r = new Room(any.Room_ID, any.Name_Room, any.Type_Room, any.Size_No); _rooms.Add(r.GetId, r); } // // Save CourseClass Data ----------------------------------------------------------------------------- // foreach (var any in db.Classes) { // // set Professor by best priority // var prof = (from p1 in db.Priority_Professors join p2 in db.Professors on p1.Professor_ID equals p2.ID where (p1.Class_ID == any.Class_ID) orderby p1.Priority select new { p1.Professor_ID, p2.Name_Professor, p2.Schedule }).ToArray()[0]; ProfessorInfoCompiler pIc = new ProfessorInfoCompiler(); Professor p = (pIc.StartScanner(prof.Schedule)) ? new Professor(prof.Professor_ID, prof.Name_Professor, pIc.CompiledData) : new Professor(prof.Professor_ID, prof.Name_Professor, pIc.CompiledData); // // set selected course for class // Course c = new Course(any.Course_ID, any.Course.Name_Course); // // set StudentsGroup in List // List<StudentsGroup> g = new List<StudentsGroup>(); foreach (var lstGroup in (from gil in db.Group_ID_Lists join groups in db.Groups on gil.Group_ID equals groups.ID where gil.Class_ID == any.Class_ID select new { gil.Group_ID, groups.Size_No, sg_name = string.Format(CultureInfo.CurrentCulture, "{0} {1} {2}-{3}", groups.Branch.Degree, groups.Branch.Branch_Name, groups.Semester_Entry_Year, (groups.Semester_Entry_FS) ? "1" : "2") })) { StudentsGroup sg = new StudentsGroup(lstGroup.Group_ID, lstGroup.sg_name, lstGroup.Size_No); g.Add(sg); } // // save class by created data // CourseClass cc = new CourseClass(p, c, g, any.RoomType, (any.Practical_unit + any.Theory_unit), any.Class_ID); _courseClasses.Add(cc); } //---------------------------------------------------------------------------------------------------------------- // db.Dispose(); _isEmpty = false; }
// Parse file and store parsed object public void ParseFile(LINQDataContext db) { // clear previously parsed objects _professors.Clear(); _studentGroups.Clear(); _courses.Clear(); _rooms.Clear(); _courseClasses.Clear(); Room.RestartIDs(); // // Save Professor Data // foreach (var any in db.Professors) { ProfessorInfoCompiler pIc = new ProfessorInfoCompiler(); Professor p; if (pIc.StartScanner(any.Schedule)) { p = new Professor(any.ID, any.Name_Professor, pIc.CompiledData); _professors.Add(p.GetId, p); } } // // Save StudentsGroup Data // foreach (var any in db.Groups) { StudentsGroup sg; string sg_name = string.Format(CultureInfo.CurrentCulture, "{0} {1} {2}-{3}", any.Branch.Degree, any.Branch.Branch_Name, any.Semester_Entry_Year, (any.Semester_Entry_FS) ? "1" : "2"); sg = new StudentsGroup(any.ID, sg_name, any.Size_No); _studentGroups.Add(sg.GetId, sg); } // // Save Course Data // foreach (var any in db.Courses) { Course c; c = new Course(any.Course_ID, any.Name_Course); _courses.Add(c.GetId, c); } // // Save Room Data // foreach (var any in db.Rooms) { Room r; r = new Room(any.Room_ID, any.Name_Room, any.Type_Room, any.Size_No); _rooms.Add(r.GetId, r); } // // Save CourseClass Data ----------------------------------------------------------------------------- // foreach (var any in db.Classes) { // // set Professor by best priority // var prof = (from p1 in db.Priority_Professors join p2 in db.Professors on p1.Professor_ID equals p2.ID where (p1.Class_ID == any.Class_ID) orderby p1.Priority select new { p1.Professor_ID, p2.Name_Professor, p2.Schedule }).ToArray()[0]; ProfessorInfoCompiler pIc = new ProfessorInfoCompiler(); Professor p = (pIc.StartScanner(prof.Schedule)) ? new Professor(prof.Professor_ID, prof.Name_Professor, pIc.CompiledData) : new Professor(prof.Professor_ID, prof.Name_Professor, pIc.CompiledData); // // set selected course for class // Course c = new Course(any.Course_ID, any.Course.Name_Course); // // set StudentsGroup in List // List <StudentsGroup> g = new List <StudentsGroup>(); foreach (var lstGroup in (from gil in db.Group_ID_Lists join groups in db.Groups on gil.Group_ID equals groups.ID where gil.Class_ID == any.Class_ID select new { gil.Group_ID, groups.Size_No, sg_name = string.Format(CultureInfo.CurrentCulture, "{0} {1} {2}-{3}", groups.Branch.Degree, groups.Branch.Branch_Name, groups.Semester_Entry_Year, (groups.Semester_Entry_FS) ? "1" : "2") })) { StudentsGroup sg = new StudentsGroup(lstGroup.Group_ID, lstGroup.sg_name, lstGroup.Size_No); g.Add(sg); } // // save class by created data // CourseClass cc = new CourseClass(p, c, g, any.RoomType, (any.Practical_unit + any.Theory_unit), any.Class_ID); _courseClasses.Add(cc); } //---------------------------------------------------------------------------------------------------------------- // db.Dispose(); _isEmpty = false; }
private void dgvBranch_UserDeletingRow(object sender, DataGridViewRowCancelEventArgs e) { int id = 0; if (int.TryParse(e.Row.Cells[0].Value.ToString(), out id)) { var db = new LINQDataContext(); // Define the query expression. IEnumerable<int> qGroupID = from groups in db.Groups where groups.Branch_Selection == id select groups.ID; // // Define the query expression. IEnumerable<int> qCourseID = from course in db.Courses where course.Branch_ID == id select course.Course_ID; // // if exist data in the Groups table : // if (qGroupID.ToArray().Length > 0) { string groups_ID_List = ""; foreach (var anyGroup in qGroupID) { groups_ID_List += anyGroup.ToString() + " and "; } groups_ID_List = groups_ID_List.Substring(0, groups_ID_List.Length - 4); e.Cancel = true; MessageBox.Show("Information Groups with group numbers " + groups_ID_List + "is related to Branch (" + ((e.Row.Cells[1].Value != null) ? e.Row.Cells[1].Value.ToString() : "NULL") + ").\n First, this information can change groups.", "Delete Row Error", MessageBoxButtons.OK, MessageBoxIcon.Stop, MessageBoxDefaultButton.Button1); } // // if exist data in the Groups table : // else if (qCourseID.ToArray().Length > 0) { string course_ID_List = ""; foreach (var anyCourse in qCourseID) { course_ID_List += anyCourse.ToString() + " and "; } course_ID_List = course_ID_List.Substring(0, course_ID_List.Length - 4); e.Cancel = true; MessageBox.Show("Information courses with course numbers " + course_ID_List + "is related to Branch (" + ((e.Row.Cells[1].Value != null) ? e.Row.Cells[1].Value.ToString() : "NULL") + ").\n First, this information can change courses.", "Delete Row Error", MessageBoxButtons.OK, MessageBoxIcon.Stop, MessageBoxDefaultButton.Button1); } else { db.BranchDelete(id); } db.Dispose(); } }