private void BtnDelete_Click(object sender, EventArgs e) { studId = (int)gridStudent[0, gridStudent.CurrentRow.Index].Value; using (DB.Context db = new DB.Context()) { DB.Student stud = db.Students.Where(i => i.IdStudent == studId).FirstOrDefault(); var result = MessageBox.Show($"Вы хотите удалить студента {stud.FIO}?", "Внимание!", MessageBoxButtons.YesNo, MessageBoxIcon.Information); if (DialogResult.Yes == result) { db.Students.Remove(stud); db.SaveChanges(); MessageBox.Show($"Вы успешно удалили студента {stud.FIO}!", "Внимание!", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show("Удаление отменено!", "Внимание!", MessageBoxButtons.OK, MessageBoxIcon.Information); } } UpdateGrid(); ClearAll(); }
/// <summary> /// 检查短信是否重复生成 /// 重复返回false /// 不重复返回true /// </summary> /// <param name="student"></param> /// <param name="sendSMSEvery"></param> /// <returns></returns> public bool SendMsgInfo_CheckHave(DB.Student student, XXT.SendSMSEvery sendSMSEvery) { DateTime dateTime = DateTime.Now.Date; return(DataList.Current[Name].DB.SendMsgInfos.Where(p => p.StudentId == student.Id && p.SendSMSEvery == sendSMSEvery && p.CreateTime > dateTime).Count() == 0); }
private void BtnUpdate_Click(object sender, EventArgs e) { studId = (int)gridStudent[0, gridStudent.CurrentRow.Index].Value; FIOstudentTemp = txtFIOStudent.Text.ToString(); AgeTemp = Int32.Parse(txtAgeStudent.Text); FIOMotherTemp = txtFIOMom.Text.ToString(); MobileMomTemp = txtMobileMom.Text.ToString(); FIOFatherTemp = txtFIOFather.Text.ToString(); MobileFatherTemp = txtMobileFather.Text.ToString(); idgrouptemp = (int)cmbGroups.SelectedValue; countMobileFather = txtMobileFather.Text.Count(); countMobileMom = txtMobileMom.Text.Count(); if (MobileMomTemp != "") { if (countMobileMom > 10) { MessageBox.Show("Вы должны ввести телефон без +7 и разделителей", "Ошибка!", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { using (DB.Context db = new DB.Context()) { DB.Student stud = db.Students.Where(i => i.IdStudent == studId).FirstOrDefault(); stud.FIO = FIOstudentTemp; stud.Age = AgeTemp; stud.IdGroup = idgrouptemp; stud.NumberMother = MobileMomTemp; stud.FIOMother = FIOMotherTemp; db.SaveChanges(); MessageBox.Show($"Вы успешно изменили данные о студенте {stud.FIO}!", "Внимание!", MessageBoxButtons.OK, MessageBoxIcon.Information); } } } if (MobileFatherTemp != "") { if (countMobileMom > 10) { MessageBox.Show("Вы должны ввести телефон без +7 и разделителей", "Ошибка!", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { using (DB.Context db = new DB.Context()) { DB.Student stud = db.Students.Where(i => i.IdStudent == studId).FirstOrDefault(); stud.FIO = FIOstudentTemp; stud.Age = AgeTemp; stud.IdGroup = idgrouptemp; stud.NumberFather = MobileFatherTemp; stud.FIOFather = FIOFatherTemp; stud.NumberMother = MobileMomTemp; stud.FIOMother = FIOMotherTemp; db.SaveChanges(); MessageBox.Show($"Вы успешно изменили данные о студенте {stud.FIO}!", "Внимание!", MessageBoxButtons.OK, MessageBoxIcon.Information); } } } else { using (DB.Context db = new DB.Context()) { DB.Student stud = db.Students.Where(i => i.IdStudent == studId).FirstOrDefault(); stud.FIO = FIOstudentTemp; stud.Age = AgeTemp; stud.IdGroup = idgrouptemp; db.SaveChanges(); } } UpdateGrid(); ClearAll(); }