protected override void SaveManyToMany(PriemEntities context, Guid id) { //добавл¤ем записи оценок if (_Id == null) { for (int i = 0; i < dgvExams.Rows.Count; i++) { if (dgvExams["Ѕаллы", i].Value != null && dgvExams["Ѕаллы", i].Value.ToString() != "") { context.EgeMark_Insert((int)dgvExams["Ѕаллы", i].Value, (int)dgvExams["ExamId", i].Value, id, Util.ToBool(dgvExams["јпелл¤ци¤", i].Value), Util.ToBool(dgvExams["«ачетна¤", i].Value)); } } } else { for (int i = 0; i < dgvExams.Rows.Count; i++) { if (dgvExams["MarkId", i].Value != null && dgvExams["MarkId", i].Value.ToString() != "") { if (dgvExams["Ѕаллы", i].Value == null || dgvExams["Ѕаллы", i].Value.ToString() == "") { context.EgeMark_Delete((Guid)dgvExams["MarkId", i].Value); } else { context.EgeMark_Update((int)dgvExams["Ѕаллы", i].Value, (int)dgvExams["ExamId", i].Value, Util.ToBool(dgvExams["јпелл¤ци¤", i].Value), (Guid)dgvExams["MarkId", i].Value); context.EgeMark_UpdateCurMark(Util.ToBool(dgvExams["«ачетна¤", i].Value), (Guid)dgvExams["MarkId", i].Value); } } else { if (dgvExams["Ѕаллы", i].Value != null && dgvExams["Ѕаллы", i].Value.ToString() != "") { context.EgeMark_Insert((int)dgvExams["Ѕаллы", i].Value, (int)dgvExams["ExamId", i].Value, id, Util.ToBool(dgvExams["јпелл¤ци¤", i].Value), Util.ToBool(dgvExams["«ачетна¤", i].Value)); } } } } }
//reads fbs answer and saves ege certificates 2011 and 2012 private void FBSAnswer2(StreamReader sr) { string line = string.Empty; string[] arr; char[] splitChars = { '%' }; SortedList <int, string> slEges = GetEgeSubjectsList(); //SortedList<string, EgeInstance> slCerts = new SortedList<string, EgeInstance>(); List <ObjListItem> lCerts = new List <ObjListItem>(); using (PriemEntities context = new PriemEntities()) { //main loop while (!sr.EndOfStream) { //read line line = sr.ReadLine(); try { //check strings when need to skip if (line.Length == 0) { continue; } else if (line.ToLower().StartsWith("комментарий", StringComparison.InvariantCultureIgnoreCase)) { continue; } else if (line.ToLower().StartsWith("не найдено", StringComparison.InvariantCultureIgnoreCase)) { continue; } else if (line.ToLower().StartsWith("аннулировано", StringComparison.InvariantCultureIgnoreCase)) { continue; } else { //get ege cert number string egeNum = line.Substring(line.IndexOf('%') - 15, 15); //skip year < 2011 if (!egeNum.EndsWith("-11") && !egeNum.EndsWith("-12")) { continue; } //split string arr = line.Split(splitChars /*, COLUMNS_NUMBER*/); //check ege cert status if (arr[6].ToLower().CompareTo("действительно") != 0) { continue; } //create ege FBSEgeCert sert = new FBSEgeCert(arr[0], arr[1], arr[5]); //get ege marks int FBSnumber = 1; for (int i = 7; i < 34; i = i + 2, FBSnumber++) { if (arr[i].Length <= 0) { continue; } int mrk = (int)double.Parse(arr[i].Replace("ќшибка (", "").Replace(",0)", "").Replace("!", "")); if (mrk != 0) { sert.AddMark(new FBSEgeMark(slEges[FBSnumber], mrk, arr[i + 1].CompareTo("0") != 0)); } } string pspSer = arr[2]; string pspNum = arr[3]; //get person id by document's data Guid?personid = (from pers in context.Person where pers.PassportSeries == pspSer && pers.PassportNumber == pspNum select pers.Id).FirstOrDefault(); if (personid != null) { lCerts.Add(new ObjListItem(personid, sert)); } } } catch (Exception exc) { throw new Exception("ќшибка при сохранении данных: " + exc.Message); } } //save to database foreach (ObjListItem item in lCerts) { Guid person = (Guid)item.Key; FBSEgeCert egecert = (FBSEgeCert)item.Value; Guid certId; //using (TransactionScope transaction = new TransactionScope(TransactionScopeOption.RequiresNew)) //{ try { int cnt = (from cert in context.EgeCertificate where cert.Number == egecert.Name && cert.Year == egecert.Year select cert).Count(); if (cnt > 0) { var crt = (from cert in context.EgeCertificate where cert.Number == egecert.Name && cert.Year == egecert.Year select new { cert.Id, cert.FBSStatusId }).FirstOrDefault(); if (crt.FBSStatusId == 1 || crt.FBSStatusId == 4) { continue; } certId = crt.Id; context.EgeMark_DeleteByCertId(certId); } else { ObjectParameter entId = new ObjectParameter("id", typeof(Guid)); context.EgeCertificate_Insert(egecert.Name, egecert.Tipograf, egecert.Year, person, "", true, entId); certId = (Guid)entId.Value; } foreach (FBSEgeMark mark in egecert.Marks) { int examId = int.Parse(mark.ExamId); if (mark.Value > 0 && mark.Value < 101) { context.EgeMark_Insert(mark.Value, examId, certId, mark.isApl, false); } } context.EgeCertificate_UpdateFBSStatus(1, "", certId); //transaction.Complete(); } catch (Exception exc) { throw new Exception("ќшибка при сохранении данных: " + exc.Message); } //} } } return; }