/// <summary> /// Получить список записей журнала /// </summary> /// <param name="idAccount">ID исполнителя</param> /// <param name="from">дата начала периода</param> /// <param name="to">дата окончания периода</param> private static List <Journal> GetJournalList(int?idAccount, DateTime?from, DateTime?to) { List <Journal> list = new List <Journal>(); try { using (MySqlConnection connection = new MySqlConnection(Criptex.UnCript(ProgramSettings.ConnectionString))) { connection.Open(); string fromDate = string.Empty; string toDate = string.Empty; if (from != null && to != null) { fromDate = String.Format(@"'{0}-{1}-{2}T00:00:00.000'", ((DateTime)from).Year, ((DateTime)from).Month, ((DateTime)from).Day); toDate = String.Format(@"'{0}-{1}-{2}T23:59:59.000'", ((DateTime)to).Year, ((DateTime)to).Month, ((DateTime)to).Day); } string sql = String.Format(@"SELECT `JOU`.`ID`, `JOU`.`DATE`, `JOU`.`ID_ACCOUNT`, `JOU`.`ACT`, `ACC`.`NAME`, `ACC`.`SURNAME`, `ACC`.`PATRONYMIC` FROM `JOURNAL` AS `JOU` LEFT JOIN `ACCOUNT` AS `ACC` ON `ACC`.`ID` = `JOU`.`ID_ACCOUNT`"); if (idAccount != null) { sql += " WHERE `JOU`.`ID_ACCOUNT` = " + (int)idAccount; if (from != null && to != null) { sql += " AND `JOU`.`DATE` >= " + fromDate + " AND `JOU`.`DATE` <= " + toDate; } } else if (from != null && to != null) { sql += " WHERE `JOU`.`DATE` >= " + fromDate + " AND `JOU`.`DATE` <= " + toDate; } using (MySqlCommand command = new MySqlCommand(sql, connection)) { using (MySqlDataReader reader = command.ExecuteReader()) { while (reader.Read()) { Journal journal = new Journal(); journal.ID = Conversion.ToInt(reader["ID"].ToString()); journal.Date = Conversion.ToDateTime(reader["DATE"].ToString()); journal.ID_Account = Conversion.ToInt(reader["ID_ACCOUNT"].ToString()); journal.Act = reader["ACT"].ToString(); if (journal.ID_Account != 0) { string accName = reader["NAME"].ToString(); string accSurname = reader["SURNAME"].ToString(); string accPatronymic = reader["PATRONYMIC"].ToString(); journal.Account = new Account { ID = journal.ID_Account }; journal.Account.PersonalData.Name = accName; journal.Account.PersonalData.Surname = accSurname; journal.Account.PersonalData.Patronymic = accPatronymic; } list.Add(journal); } } } connection.Close(); } } catch (Exception ex) { Dialog.ErrorMessage(null, "Ошибка получения журнала событий", ex.Message); } return(list); }