public async Task <IActionResult> PutTeaches(int id, Teaches teaches) { if (id != teaches.TeachId) { return(BadRequest()); } _context.Entry(teaches).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!TeachesExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> Edit(string id, [Bind("CourseId,EmpEmail")] Teaches teaches) { if (id != teaches.CourseId) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(teaches); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!TeachesExists(teaches.CourseId)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["CourseId"] = new SelectList(_context.Course, "CourseId", "CourseId", teaches.CourseId); ViewData["EmpEmail"] = new SelectList(_context.Employee, "EmpEmail", "EmpEmail", teaches.EmpEmail); return(View(teaches)); }
} //************************************** //练习3 如果还没有section,直接添加,如果已有,添加判断,遍历Teaches已有的section,只有没有该时段内的Teaches才能添加. public void AgreeToTeach(Section s) { Boolean l = false; if (Teaches.Count == 0) { Teaches.Add(s); } else { for (int i = 0; i < Teaches.Count; i++) { if (Teaches[i].TimeOfDay == s.TimeOfDay && Teaches[i].DayOfWeek == s.DayOfWeek) { l = true; } break; } if (l = false) { Teaches.Add(s); } // We need to link this bidirectionally. s.Instructor = this; } }
//************************************** // public void AgreeToTeach(Section s) { Teaches.Add(s); // We need to link this bidirectionally. s.Instructor = this; }
public bool DeleteTeaches(Teaches teaches) { try { if (teaches != null) { //SqlConnection connection; using (var connection = new SqlConnection(Database.ConnectionString)) { using (SqlCommand sqlCommand = new SqlCommand(Database.DELETEUSER, connection)) { //setting command type to stored procedure sqlCommand.CommandType = CommandType.StoredProcedure; //Defining parameters for StoredProcedure SqlParameter teacherID = new SqlParameter("@TeacherID", teaches.TeacherID); sqlCommand.Parameters.Add(teacherID); connection.Open(); int affectedRows = sqlCommand.ExecuteNonQuery(); if (affectedRows > 0) { return(true); } } } } } catch (Exception) { throw; } return(false); }
public async Task <ActionResult <Teaches> > PostTeaches(Teaches teaches) { _context.Teaches.Add(teaches); await _context.SaveChangesAsync(); return(CreatedAtAction("GetTeaches", new { id = teaches.TeachId }, teaches)); }
public async Task <IActionResult> Create([Bind("CourseId,EmpEmail")] Teaches teaches) { if (ModelState.IsValid) { _context.Add(teaches); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["CourseId"] = new SelectList(_context.Course, "CourseId", "CourseId", teaches.CourseId); ViewData["EmpEmail"] = new SelectList(_context.Employee, "EmpEmail", "EmpEmail", teaches.EmpEmail); return(View(teaches)); }
private void TeachesSaveButton_Click(object sender, EventArgs e) { if (String.IsNullOrEmpty(idComboBox.Text)) { MessageBox.Show("Enter a Instuctor ID"); return; } if (String.IsNullOrEmpty(courseIdComboBox.Text)) { MessageBox.Show("Select a Course ID"); return; } if (String.IsNullOrEmpty(sectionIdComboBox.Text)) { MessageBox.Show("Select a section ID"); return; } if (String.IsNullOrEmpty(semesterComboBox.Text)) { MessageBox.Show("Select a Semester"); return; } if (String.IsNullOrEmpty(yearComboBox.Text)) { MessageBox.Show("Select a year "); return; } Teaches teaches = new Teaches(); teaches.ID = idComboBox.Text; teaches.Course_id = courseIdComboBox.Text; teaches.sec_id = sectionIdComboBox.Text; teaches.Semester = semesterComboBox.Text; teaches.Year = Convert.ToDouble(yearComboBox.Text); string exist = teachesManager.IsExistOrInsert(teaches); if (!String.IsNullOrEmpty(exist)) { MessageBox.Show("Data is exist \n Please Check ID, course id, section id, year and semester are primary key"); } else { MessageBox.Show("Data Inserted successfully."); } }
//检查是否添加section,遍历已有的section,只有符合条件的才可以添加 public void AgreeToTeach(Section s) { Boolean l = false; if (Teaches.Count == 0) { Teaches.Add(s); } else { for (int i=0; i<Teaches.Count; i++) { if(Teaches[i].TimeOfDay==s.TimeOfDay &&Teaches[i].DayOfWeek==s.DayOfWeek) l =true; break; } } if(l=false) }
public string IsExistOrInsert(Teaches teaches) { string exist = ""; try { sqlConnection.Open(); commadString = "SELECT * FROM Teaches WHERE ID ='" + teaches.ID + "' AND course_id ='" + teaches.Course_id + "' AND sec_id ='" + teaches.sec_id + "' AND semester = '" + teaches.Semester + "' AND year =" + teaches.Year + ""; // commadString = "SELECT * FROM Teaches WHERE ID ='" + teaches.ID + "' AND course_id ='" + teaches.Course_id + "' AND sec_id ='" + teaches.sec_id + "' AND semester = '" + teaches.Semester + "' AND year =" + teaches.Year + ""; sqlCommand = new SqlCommand(commadString, sqlConnection); sqlDataAdapter = new SqlDataAdapter(sqlCommand); dataTable = new DataTable(); sqlDataAdapter.Fill(dataTable); if (dataTable.Rows.Count > 0) { exist = "Data is exist \n Please check duplicated data"; } sqlConnection.Close(); if (String.IsNullOrEmpty(exist)) { sqlConnection.Open(); commadString = "INSERT INTO Teaches VALUES('" + teaches.ID + "','" + teaches.Course_id + "','" + teaches.sec_id + "','" + teaches.Semester + "'," + teaches.Year + ")"; // commadString = "INSERT INTO Teaches VALUES('" + teaches.ID + "','" + teaches.Course_id + "','" + teaches.sec_id + "','" + teaches.Semester + "'," + teaches.Year + ")"; sqlCommand = new SqlCommand(commadString, sqlConnection); sqlCommand.ExecuteNonQuery(); sqlConnection.Close(); } } catch (Exception exception) { sqlConnection.Close(); } return(exist); }
//************************************** //练习3 public void AgreeToTeach(Section s) { bool isSameTime = true; for (int i = 1; i < Teaches.Count; i++) { if (Teaches[i].OfferedIn == s.OfferedIn) { if (Teaches[i].DayOfWeek == s.DayOfWeek) { if (Teaches[i].TimeOfDay == s.TimeOfDay) { isSameTime = false; } else { continue; } } else { continue; } } else { continue; } } if (isSameTime) { Teaches.Add(s); // We need to link this bidirectionally. s.Instructor = this; } else { Console.WriteLine("一位教授不能再同一天/同一时刻教授两门课"); } }
//************************************** // //题3:一位教授不能在同一天/同一时刻教两门课 public void AgreeToTeach(Section s) { foreach (Section s1 in Teaches) { if (s == s1) { Console.WriteLine("一位教授不能在同一天/同一时刻教两门课!"); } else { Teaches.Add(s); s.Instructor = this; } } // We need to link this bidirectionally. }
//************************************** //第3题 一位教授不能同时教授两门课程 public void AgreeToTeach(Section s) { bool T = false; Course c1 = s.RepresentedCourse; while (c.MoveNext()) { Section s2 = (Section)c.Current; Course c2 = s2.RepresentedCourse; if (c1 == c2) { T = true; break; } Teaches.Add(s); } // We need to link this bidirectionally. s.Instructor = this; }
//************************************** // public void AgreeToTeach(Section s) { //练习14.3 bool theSameTime = true; for (int i = 0; i < Teaches.Count; i++) { if (Teaches[i].OfferedIn == s.OfferedIn) { if (Teaches[i].DayOfWeek == s.DayOfWeek) { if (Teaches[i].TimeOfDay == s.TimeOfDay) { theSameTime = false; } else { continue; } } else { continue; } } else { continue; } } if (theSameTime) { Teaches.Add(s); // We need to link this bidirectionally. s.Instructor = this; } else { Console.WriteLine("同一天、同一时间教授上课时间冲突!"); } }
//************************************** // public void AgreeToTeach(Section s) { int jieguo; //第三题 bool status; status = true; for (int i = 0; i < Teaches.Count; i++) { jieguo = String.Compare(s.TimeOfDay, Teaches[i].TimeOfDay); if (jieguo == 0) { status = false; Console.WriteLine(s + "和" + Teaches[i] + "时间冲突"); break; } } if (status == true) { Teaches.Add(s); s.Instructor = this; } // We need to link this bidirectionally. }
protected override void WriteDataXML(XElement ele, ElderScrollsPlugin master) { XElement subEle; ele.TryPathTo("Aggression", true, out subEle); subEle.Value = Aggression.ToString(); ele.TryPathTo("Confidence", true, out subEle); subEle.Value = Confidence.ToString(); ele.TryPathTo("EnergyLevel", true, out subEle); subEle.Value = EnergyLevel.ToString(); ele.TryPathTo("Responsibility", true, out subEle); subEle.Value = Responsibility.ToString(); ele.TryPathTo("Mood", true, out subEle); subEle.Value = Mood.ToString(); WriteUnusedXML(ele, master); ele.TryPathTo("Services", true, out subEle); subEle.Value = Services.ToString(); ele.TryPathTo("Teaches", true, out subEle); subEle.Value = Teaches.ToString(); ele.TryPathTo("MaxTrainingLevel", true, out subEle); subEle.Value = MaxTrainingLevel.ToString(); ele.TryPathTo("Assistance", true, out subEle); subEle.Value = Assistance.ToString(); ele.TryPathTo("AggroRadiusBehavior", true, out subEle); subEle.Value = AggroRadiusBehavior.ToString(); ele.TryPathTo("AggroRadius", true, out subEle); subEle.Value = AggroRadius.ToString(); }
//************************************** // public void AgreeToTeach(Section s) { //练习14.3 Boolean r = true; for (int i = 0; i < Teaches.Count; i++) { Section s1 = Teaches[i]; if (s.TimeOfDay == s1.TimeOfDay && s.DayOfWeek == s1.DayOfWeek) { Console.Write("教师上课时间冲突"); r = false; break; } } if (r) { Teaches.Add(s); } // We need to link this bidirectionally. s.Instructor = this; }
public string IsExistOrInsert(Teaches teaches) { return(teachesRepository.IsExistOrInsert(teaches)); }
public TeachesUi() { InitializeComponent(); teachesManager = new TeachesManager(); teaches = new Teaches(); }