private void dgvApplications_CellDoubleClick(object sender, DataGridViewCellEventArgs e) { if (Classes.Settings.CurrentCampaignID == 0) { MessageBox.Show("Не выбрана текущая кампания. Перейдите в Главное меню -> Приемная кампания -> Приемные кампании."); } else { _SelectedAppID = (uint)(int)dgvApplications.CurrentRow.Cells[dgvApplications_ID.Index].Value; StopTableAutoUpdating(); Form form; if (_DB_Helper.GetCampaignType(Classes.Settings.CurrentCampaignID) == DB_Helper.CampaignType.MASTER) { form = new ApplicationMagEdit(_DB_Connection, Classes.Settings.CurrentCampaignID, _UserLogin, _SelectedAppID); } else { List <object[]> campaidnEduLevels = _DB_Connection.Select(DB_Table._CAMPAIGNS_HAS_DICTIONARIES_ITEMS, new string[] { "dictionaries_items_item_id" }, new List <Tuple <string, Relation, object> > { new Tuple <string, Relation, object>("campaigns_id", Relation.EQUAL, Classes.Settings.CurrentCampaignID), new Tuple <string, Relation, object>("dictionaries_items_dictionary_id", Relation.EQUAL, (uint)FIS_Dictionary.EDU_LEVEL) }); bool spo = false; foreach (object[] eduLevel in campaidnEduLevels) { if (DB_Helper.EduLevelSPO == _DB_Helper.GetDictionaryItemName(FIS_Dictionary.EDU_LEVEL, (uint)eduLevel[0])) { spo = true; } } if (spo) { form = new ApplicationSPOEdit(_DB_Connection, Classes.Settings.CurrentCampaignID, _UserLogin, _SelectedAppID); } else { form = new ApplicationEdit(_DB_Connection, Classes.Settings.CurrentCampaignID, _UserLogin, _SelectedAppID); } } form.ShowDialog(); UpdateApplicationsTable(); timer.Start(); } }
public MainForm() { InitializeComponent(); //_DB_Connection = new DB_Connector("server = localhost; port = 3306; database = pk_db;"/*Properties.Settings.Default.pk_db_CS*/, "administrator", "adm1234"); _DB_Connection = new DB_Connector("server = serv-priem; port = 3306; database = pk_db;" /*Properties.Settings.Default.pk_db_CS*/, "administrator", "adm1234"); _DB_Helper = new DB_Helper(_DB_Connection); Dictionary <uint, string> campaigns = new Dictionary <uint, string>(); foreach (object[] campaign in _DB_Connection.Select(DB_Table.CAMPAIGNS, new string[] { "id", "name" })) { if (_DB_Helper.GetCampaignType((uint)campaign[0]) == DB_Helper.CampaignType.BACHELOR_SPECIALIST) { campaigns.Add((uint)campaign[0], campaign[1].ToString()); } } cbCampaigns.DataSource = campaigns.ToList(); cbCampaigns.ValueMember = "Key"; cbCampaigns.DisplayMember = "Value"; cbAdress.SelectedIndex = 0; cbAdress.Enabled = cbPost.Checked; cbUnits.SelectedIndex = 1; for (int i = 1; i <= 60; i++) { cbInterval.Items.Add(i); } cbInterval.SelectedItem = 15; _SubjectsCodes = new Dictionary <uint, string> { { _DB_Helper.GetDictionaryItemID(FIS_Dictionary.SUBJECTS, DB_Helper.SubjectMath), "Math" }, { _DB_Helper.GetDictionaryItemID(FIS_Dictionary.SUBJECTS, DB_Helper.SubjectPhis), "Phis" }, { _DB_Helper.GetDictionaryItemID(FIS_Dictionary.SUBJECTS, DB_Helper.SubjectRus), "Rus" }, { _DB_Helper.GetDictionaryItemID(FIS_Dictionary.SUBJECTS, DB_Helper.SubjectObsh), "Obsh" }, { _DB_Helper.GetDictionaryItemID(FIS_Dictionary.SUBJECTS, DB_Helper.SubjectForen), "Foren" } }; }
public OrderEdit(DB_Connector connection, string number) { _DB_Connection = connection; _DB_Helper = new DB_Helper(_DB_Connection); _EditNumber = number; #region Components InitializeComponent(); cbType.DisplayMember = "Item2"; cbType.ValueMember = "Item1"; cbType.DataSource = new List <Tuple <string, string> > { Tuple.Create("admission", "Зачисление"), Tuple.Create("exception", "Отчисление"), Tuple.Create("hostel", "Выделение мест в общежитии") }; rbBudget.Tag = new RB_Tag("budget", _DB_Helper.GetDictionaryItemID(FIS_Dictionary.EDU_SOURCE, DB_Helper.EduSourceB)); rbPaid.Tag = new RB_Tag(null, _DB_Helper.GetDictionaryItemID(FIS_Dictionary.EDU_SOURCE, DB_Helper.EduSourceP)); rbTarget.Tag = new RB_Tag(null, _DB_Helper.GetDictionaryItemID(FIS_Dictionary.EDU_SOURCE, DB_Helper.EduSourceT)); rbQuota.Tag = new RB_Tag("quota", _DB_Helper.GetDictionaryItemID(FIS_Dictionary.EDU_SOURCE, DB_Helper.EduSourceQ)); rbO.Tag = new RB_Tag("o", _DB_Helper.GetDictionaryItemID(FIS_Dictionary.EDU_FORM, DB_Helper.EduFormO)); rbOZ.Tag = new RB_Tag("oz", _DB_Helper.GetDictionaryItemID(FIS_Dictionary.EDU_FORM, DB_Helper.EduFormOZ)); rbZ.Tag = new RB_Tag("z", _DB_Helper.GetDictionaryItemID(FIS_Dictionary.EDU_FORM, DB_Helper.EduFormZ)); if (_EditNumber != null) { dtpDate.Tag = true; } else { dtpDate.Tag = false; } #endregion cbFDP.ValueMember = "Value"; _CampaignType = _DB_Helper.GetCampaignType(Classes.Settings.CurrentCampaignID); if (_CampaignType != DB_Helper.CampaignType.BACHELOR_SPECIALIST) { dataGridView_Status.Visible = false; dataGridView_MFR.Visible = false; dataGridView_MOR.Visible = false; dataGridView_ROI.Visible = false; dataGridView_Math.Visible = false; dataGridView_Physics.Visible = false; dataGridView_Russian.Visible = false; dataGridView_Social.Visible = false; dataGridView_Foreign.Visible = false; if (_CampaignType == DB_Helper.CampaignType.MASTER) { dataGridView_Sum.Visible = true; dataGridView_Exam.Visible = true; dataGridView_IndAch.Visible = true; //dataGridView_Honors.Visible = true; lFDP.Text = "Программа:"; } } if (_EditNumber != null) { object[] order = _DB_Connection.Select( DB_Table.ORDERS, new string[] { "type", "date", "edu_form_id", "edu_source_id", "faculty_short_name", /**/ "direction_id" /**/, "profile_short_name", "protocol_number" },
private void bPrint_Click(object sender, EventArgs e) { if (!cbActs.Checked && !cbReceipts.Checked && !cbExamSheets.Checked) { MessageBox.Show("Не отмечена информация к печати.", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } Cursor.Current = Cursors.WaitCursor; IEnumerable <string> ordersNumbers; if (rbDate.Checked) { ordersNumbers = _DB_Connection.Select( DB_Table.ORDERS, new string[] { "number" }, new List <Tuple <string, Relation, object> > { new Tuple <string, Relation, object>("date", Relation.GREATER_EQUAL, dtpStart.Value.Date), new Tuple <string, Relation, object>("date", Relation.LESS, dtpEnd.Value.Date.AddDays(1)) }).Select(s => s[0].ToString()); } else { ordersNumbers = new string[] { tbNumber.Text } }; DB_Helper dbHelper = new DB_Helper(_DB_Connection); var orders = ordersNumbers.Join( _DB_Connection.Select( DB_Table.ORDERS,//TODO убрать лишние поля new string[] { "number", "type", "date", "protocol_number", "protocol_date", "edu_form_id", "edu_source_id", "faculty_short_name", "direction_id", "profile_short_name", "campaign_id" }, new List <Tuple <string, Relation, object> > { new Tuple <string, Relation, object>("campaign_id", Relation.EQUAL, Classes.Settings.CurrentCampaignID), new Tuple <string, Relation, object>("type", Relation.EQUAL, "admission"), new Tuple <string, Relation, object>("protocol_number", Relation.NOT_EQUAL, null) }), k1 => k1, k2 => k2[0], (s1, s2) => new { Number = s1, Date = (DateTime)s2[2], ProtocolNumber = (ushort)s2[3], ProtocolDate = (DateTime)s2[4], EduForm = (uint)s2[5], EduSource = (uint)s2[6], Faculty = s2[7].ToString(), Direction = (uint)s2[8], Profile = s2[9] as string, Master = dbHelper.GetCampaignType((uint)s2[10]) == DB_Helper.CampaignType.MASTER }); if (orders.Count() == 0) { MessageBox.Show("Не найдено соответствующих приказов.", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } Dictionary <uint, string> forms = new Dictionary <uint, string> { { 11, "очной формы" }, { 12, "очно-заочной (вечерней) формы" }, { 10, "заочной формы" } }; uint mathID = dbHelper.GetDictionaryItemID(FIS_Dictionary.SUBJECTS, DB_Helper.SubjectMath); uint physID = dbHelper.GetDictionaryItemID(FIS_Dictionary.SUBJECTS, DB_Helper.SubjectPhis); uint rusID = dbHelper.GetDictionaryItemID(FIS_Dictionary.SUBJECTS, DB_Helper.SubjectRus); uint socID = dbHelper.GetDictionaryItemID(FIS_Dictionary.SUBJECTS, DB_Helper.SubjectObsh); uint forID = dbHelper.GetDictionaryItemID(FIS_Dictionary.SUBJECTS, DB_Helper.SubjectForen); List <Classes.DocumentCreator.DocumentParameters> actsDocs = new List <Classes.DocumentCreator.DocumentParameters>(); List <Classes.DocumentCreator.DocumentParameters> receiptsDocs = new List <Classes.DocumentCreator.DocumentParameters>(); List <Classes.DocumentCreator.DocumentParameters> sheetsDocs = new List <Classes.DocumentCreator.DocumentParameters>(); foreach (var order in orders) { var applications = _DB_Connection.Select( DB_Table.ORDERS_HAS_APPLICATIONS, new string[] { "applications_id", "record_book_number" }, new List <Tuple <string, Relation, object> > { new Tuple <string, Relation, object>("orders_number", Relation.EQUAL, order.Number) } ).Join( _DB_Connection.Select(DB_Table.APPLICATIONS, "id", "entrant_id", "status"), k1 => k1[0], k2 => k2[0], (s1, s2) => new { ApplID = (uint)s2[0], EntrID = (uint)s2[1], RecordBook = s1[1].ToString() } ).Join( _DB_Connection.Select(DB_Table.ENTRANTS_VIEW, "id", "last_name", "first_name", "middle_name"), k1 => k1.EntrID, k2 => k2[0], (s1, s2) => new { s1.ApplID, s1.EntrID, s1.RecordBook, LastName = s2[1].ToString(), FirstName = s2[2].ToString(), MiddleName = s2[3] as string } ); List <Tuple <string, Relation, object> > whereExpr = new List <Tuple <string, Relation, object> > { new Tuple <string, Relation, object>("type", Relation.EQUAL, "exception"), new Tuple <string, Relation, object>("protocol_number", Relation.NOT_EQUAL, null), new Tuple <string, Relation, object>("edu_form_id", Relation.EQUAL, order.EduForm), new Tuple <string, Relation, object>("edu_source_id", Relation.EQUAL, order.EduSource), new Tuple <string, Relation, object>("faculty_short_name", Relation.EQUAL, order.Faculty), new Tuple <string, Relation, object>("direction_id", Relation.EQUAL, order.Direction) }; if (order.Profile != null) { whereExpr.Add(new Tuple <string, Relation, object>("profile_short_name", Relation.EQUAL, order.Profile)); } applications = applications.Where(s => { IEnumerable <DateTime> admDates = _DB_Connection.Select( DB_Table.ORDERS_HAS_APPLICATIONS, new string[] { "orders_number" }, new List <Tuple <string, Relation, object> > { new Tuple <string, Relation, object>("applications_id", Relation.EQUAL, s.ApplID) } ).Join( _DB_Connection.Select(DB_Table.ORDERS, new string[] { "number", "date" }, whereExpr ), k1 => k1[0], k2 => k2[0], (s1, s2) => (DateTime)s2[1] ); return(!admDates.Any(d => d > order.Date)); }); if (applications.Count() == 0) { continue; } if (dbHelper.GetCampaignType(Classes.Settings.CurrentCampaignID) == DB_Helper.CampaignType.MASTER) { var table = applications.Join( _DB_Connection.Select( DB_Table.MASTERS_EXAMS_MARKS, new string[] { "entrant_id", "mark", "bonus" }, new List <Tuple <string, Relation, object> > { new Tuple <string, Relation, object>("campaign_id", Relation.EQUAL, Classes.Settings.CurrentCampaignID), new Tuple <string, Relation, object>("faculty", Relation.EQUAL, order.Faculty), new Tuple <string, Relation, object>("direction_id", Relation.EQUAL, order.Direction), new Tuple <string, Relation, object>("profile_short_name", Relation.EQUAL, order.Profile), }), k1 => k1.EntrID, k2 => k2[0], (s1, s2) => new { s1.ApplID, s1.LastName, s1.FirstName, s1.MiddleName, s1.RecordBook, Mark = (short)s2[1] + (ushort)s2[2] } ); //Tuple<string, string> dirNameCode = dbHelper.GetDirectionNameAndCode(order.Direction); //string dirSocr = dbHelper.GetDirectionShortName(order.Faculty, order.Direction); //if (cbActs.Checked) // actsDocs.Add(new Classes.DocumentCreator.DocumentParameters( // Classes.Settings.DocumentsTemplatesPath + "Act.xml", // null, // null, // new string[] // { // DateTime.Now.ToShortDateString(), // order.Date.Year.ToString(), // forms[order.EduForm] + " обучения" + // (order.EduSource == dbHelper.GetDictionaryItemID(FIS_Dictionary.EDU_SOURCE, DB_Helper.EduSourceP) ? " по договорам с оплатой стоимости обучения" : ""), // order.Faculty, // dirNameCode.Item2, // dirNameCode.Item1, // order.Master?"Магистерская программа: " :(order.Profile != null ?(dirNameCode.Item2.Split('.')[1]=="05"?"Специализация": "Профиль")+": " : ""), // order.Profile != null ? order.Profile + " - " + DB_Queries.GetProfileName(_DB_Connection,order.Faculty,order.Direction,order.Profile).Split('|')[0] : "" // }, // new IEnumerable<string[]>[] { table.Select(s=>new // { // Name = s.LastName + " " + s.FirstName + " " + s.MiddleName, // s.RecordBook // }).OrderBy(s => s.Name).Select(s => new string[] { s.Name, s.RecordBook }) })); foreach (var appl in table) { //if (cbReceipts.Checked) // receiptsDocs.Add(new Classes.DocumentCreator.DocumentParameters( // Classes.Settings.DocumentsTemplatesPath + "AdmReceipt.xml", // null, // null, // new string[] // { // order.Number, // order.Date.ToShortDateString(), // (appl.LastName+" "+appl.FirstName[0]+"."+(appl.MiddleName.Length!=0?appl.MiddleName[0].ToString()+".":"")).ToUpper(), // order.Faculty, // order.Profile != null ?order.Profile:dirSocr // }, // null // )); if (cbExamSheets.Checked) { sheetsDocs.Add(new Classes.DocumentCreator.DocumentParameters( Classes.Settings.DocumentsTemplatesPath + "ExamSheetM.xml", null, null, new string[] { appl.Mark.ToString(), dbHelper.GetDictionaryItemName(FIS_Dictionary.EDU_FORM, order.EduForm), appl.ApplID.ToString(), appl.LastName.ToUpper(), appl.FirstName.ToUpper(), appl.MiddleName.ToUpper(), order.Profile }, null )); } } } else { IEnumerable <DB_Queries.Mark> marks = DB_Queries.GetMarks(_DB_Connection, applications.Select(s => s.ApplID), Classes.Settings.CurrentCampaignID); var table = applications.Join( marks.GroupBy( k => Tuple.Create(k.ApplID, k.SubjID), (k, g) => new { g.First().ApplID, Mark = g.First(s => s.Value == g.Max(m => m.Value)) } ).GroupBy( k => k.ApplID, (k, g) => new { g.First().ApplID, Subjects = g.Select(s => s.Mark) } ), k1 => k1.ApplID, k2 => k2.ApplID, (s1, s2) => new { s1.ApplID, s1.LastName, s1.FirstName, s1.MiddleName, s1.RecordBook, s2.Subjects } ); Tuple <string, string> dirNameCode = dbHelper.GetDirectionNameAndCode(order.Direction); string dirSocr = dbHelper.GetDirectionShortName(order.Faculty, order.Direction); if (cbActs.Checked) { actsDocs.Add(new Classes.DocumentCreator.DocumentParameters( Classes.Settings.DocumentsTemplatesPath + "Act.xml", null, null, new string[] { DateTime.Now.ToShortDateString(), order.Date.Year.ToString(), forms[order.EduForm] + " обучения" + (order.EduSource == dbHelper.GetDictionaryItemID(FIS_Dictionary.EDU_SOURCE, DB_Helper.EduSourceP) ? " по договорам с оплатой стоимости обучения" : ""), order.Faculty, dirNameCode.Item2, dirNameCode.Item1, order.Master?"Магистерская программа: " :(order.Profile != null ?(dirNameCode.Item2.Split('.')[1] == "05"?"Специализация": "Профиль") + ": " : ""), order.Profile != null ? order.Profile + " - " + DB_Queries.GetProfileName(_DB_Connection, order.Faculty, order.Direction, order.Profile).Split('|')[0] : "" }, new IEnumerable <string[]>[] { table.Select(s => new { Name = s.LastName + " " + s.FirstName + " " + s.MiddleName, s.RecordBook }).OrderBy(s => s.Name).Select(s => new string[] { s.Name, s.RecordBook }) })); } foreach (var appl in table) { if (cbReceipts.Checked) { receiptsDocs.Add(new Classes.DocumentCreator.DocumentParameters( Classes.Settings.DocumentsTemplatesPath + "AdmReceipt.xml", null, null, new string[] { order.Number, order.Date.ToShortDateString(), (appl.LastName + " " + appl.FirstName[0] + "." + (appl.MiddleName.Length != 0?appl.MiddleName[0].ToString() + ".":"")).ToUpper(), order.Faculty, order.Profile != null ?order.Profile:dirSocr }, null )); } if (cbExamSheets.Checked) { sheetsDocs.Add(new Classes.DocumentCreator.DocumentParameters( Classes.Settings.DocumentsTemplatesPath + "ExamSheet.xml", null, null, new string[] { appl.Subjects.SingleOrDefault(s => s.SubjID == mathID)?.Value.ToString(), dbHelper.GetDictionaryItemName(FIS_Dictionary.EDU_FORM, order.EduForm), appl.Subjects.SingleOrDefault(s => s.SubjID == physID)?.Value.ToString(), appl.ApplID.ToString(), appl.Subjects.SingleOrDefault(s => s.SubjID == rusID)?.Value.ToString(), appl.LastName.ToUpper(), appl.Subjects.SingleOrDefault(s => s.SubjID == socID)?.Value.ToString(), appl.FirstName.ToUpper(), appl.Subjects.SingleOrDefault(s => s.SubjID == forID)?.Value.ToString(), appl.MiddleName.ToUpper(), order.Profile != null ?order.Profile:dirSocr }, null )); } } } } if (cbActs.Checked) { string doc = Classes.Settings.TempPath + "acts" + new Random().Next(); Classes.DocumentCreator.Create(doc, actsDocs, false); System.Diagnostics.Process.Start(doc + ".docx"); } if (cbReceipts.Checked) { string doc = Classes.Settings.TempPath + "receipts" + new Random().Next(); Classes.DocumentCreator.Create(doc, receiptsDocs, false); System.Diagnostics.Process.Start(doc + ".docx"); } if (cbExamSheets.Checked) { string doc = Classes.Settings.TempPath + "examSheets" + new Random().Next(); Classes.DocumentCreator.Create(doc, sheetsDocs, false); System.Diagnostics.Process.Start(doc + ".docx"); } Cursor.Current = Cursors.Default; } }