//печать private void btnPrint_Click(object sender, EventArgs e) { if (ExamVedId == null) { return; } try { WordDoc wd = new WordDoc(string.Format(@"{0}\Templates\CryptoExamsVed.dot", Application.StartupPath)); TableDoc td = wd.Tables[0]; using (PriemEntities context = new PriemEntities()) { extExamsVed ved = (from ev in context.extExamsVed where ev.Id == ExamVedId select ev).FirstOrDefault(); wd.Fields["Faculty"].Text = cbFaculty.Text.ToLower(); wd.Fields["Exam"].Text = ved.ExamName; wd.Fields["StudyBasis"].Text = Util.ToStr(ved.StudyBasisId == null ? "все" : ved.StudyBasisName); wd.Fields["Date"].Text = ved.Date.ToShortDateString(); wd.Fields["VedNum"].Text = ved.Number.ToString(); int i = 1; // печать из грида foreach (DataGridViewRow dgvr in dgvList.Rows) { td[0, i] = i.ToString(); td[1, i] = dgvr.Cells["Фамилия"].Value.ToString(); td[2, i] = dgvr.Cells["Имя"].Value.ToString(); td[3, i] = dgvr.Cells["Отчество"].Value.ToString(); td[4, i] = DateTime.Parse(dgvr.Cells["Дата_рождения"].Value.ToString()).ToShortDateString(); td[5, i] = dgvr.Cells["Ид_номер"].Value.ToString(); td[6, i] = FacultyId.ToString(); td[7, i] = ved.ExamName; td[8, i] = ved.ExamId.ToString(); td[9, i] = ved.Date.ToShortDateString();; td.AddRow(1); i++; } td.DeleteLastRow(); } } catch (Exception exc) { WinFormsServ.Error("Ошибка вывода в Word: \n" + exc.Message); } }
private void btnPrintVed_Click(object sender, EventArgs e) { if (!_isLoad) { return; } try { WordDoc wd = new WordDoc(string.Format(@"{0}\Templates\CryptoEnterMarks.dot", Application.StartupPath)); TableDoc td = wd.Tables[0]; //переменные string examId; string examName; DateTime examDate; string facultyId; using (PriemEntities context = new PriemEntities()) { extExamsVed exVed = (from ev in context.extExamsVed where ev.Id == _vedId select ev).FirstOrDefault(); examId = _examId; examName = exVed.ExamName; examDate = _dateExam; facultyId = _facultyId; wd.Fields["Faculty"].Text = exVed.FacultyName; wd.Fields["Exam"].Text = examName; wd.Fields["StudyBasis"].Text = exVed.StudyBasisId == null ? "все" : exVed.StudyBasisName; wd.Fields["Date"].Text = examDate.ToShortDateString(); wd.Fields["VedNum"].Text = exVed.Number.ToString(); int i = 1; var persMark = from evh in context.ExamsVedHistory join pers in context.extForeignPerson on evh.PersonId equals pers.Id where evh.ExamsVedId == _vedId select new { evh.ExamsVedId, pers.Surname, pers.Name, pers.SecondName, pers.BirthDate, pers.PersonNum, evh.PersonId, evh.PersonVedNumber, evh.Mark, evh.OralMark }; foreach (var pm in persMark) { td[0, i] = i.ToString(); td[1, i] = pm.Surname; td[2, i] = pm.Name; td[3, i] = pm.SecondName; td[4, i] = pm.BirthDate.ToShortDateString(); td[5, i] = pm.PersonNum; td[6, i] = facultyId; td[7, i] = examName; td[8, i] = examId; td[9, i] = examDate.ToShortDateString(); int?sumMark = 0; if (pm.Mark == null && pm.OralMark == null) { sumMark = null; } else { sumMark = (pm.Mark ?? 0) + (pm.OralMark ?? 0); } td[10, i] = sumMark == null ? "" : sumMark.ToString(); td.AddRow(1); i++; } td.DeleteLastRow(); } } catch (Exception exc) { WinFormsServ.Error("Ошибка вывода в Word: \n" + exc.Message); } }