Ejemplo n.º 1
0
        public bool ExecuteUpdateQuery(string query, Dictionary <string, object> parameters)
        {
            bool updated = false;

            if (!IsConnectionOpened())
            {
                return(updated);
            }

            try {
                FbCommand update = new FbCommand(query, connection);

                if (parameters.Count > 0)
                {
                    foreach (KeyValuePair <string, object> parameter in parameters)
                    {
                        update.Parameters.AddWithValue(parameter.Key, parameter.Value);
                    }
                }

                updated = update.ExecuteNonQuery() > 0 ? true : false;
            } catch (Exception e) {
                string subject = (Program.itemReport is null ? string.Empty : Program.itemReport.Type.ToString()) + " Ошибка выполнения запроса к БД";
                string body    = e.Message + Environment.NewLine + e.StackTrace;
                SystemMail.SendMail(subject, body, Properties.Settings.Default.MailCopy);
                Logging.ToLog(subject + " " + body);
                connection.Close();
                Program.hasError = true;
            }

            return(updated);
        }
Ejemplo n.º 2
0
        public DataTable GetDataTable(string query, Dictionary <string, object> parameters)
        {
            DataTable dataTable = new DataTable();

            if (!IsConnectionOpened())
            {
                return(dataTable);
            }

            try {
                using (FbCommand command = new FbCommand(query, connection)) {
                    if (parameters.Count > 0)
                    {
                        foreach (KeyValuePair <string, object> parameter in parameters)
                        {
                            command.Parameters.AddWithValue(parameter.Key, parameter.Value);
                        }
                    }

                    using (FbDataAdapter fbDataAdapter = new FbDataAdapter(command))
                        fbDataAdapter.Fill(dataTable);
                }
            } catch (Exception e) {
                string subject = (Program.itemReport is null ? string.Empty : Program.itemReport.Type.ToString()) + " Ошибка выполнения запроса к БД";
                string body    = e.Message + Environment.NewLine + e.StackTrace;
                SystemMail.SendMail(subject, body, Properties.Settings.Default.MailCopy);
                Logging.ToLog(subject + " " + body);
                connection.Close();
                Program.hasError = true;
            }

            return(dataTable);
        }
Ejemplo n.º 3
0
        private bool IsConnectionOpened()
        {
            if (connection.State != ConnectionState.Open)
            {
                try {
                    connection.Open();
                } catch (Exception e) {
                    string subject = "Ошибка подключения к БД";
                    string body    = e.Message + Environment.NewLine + e.StackTrace;
                    SystemMail.SendMail(subject, body, Properties.Settings.Default.MailCopy);
                    Logging.ToLog(subject + " " + body);
                }
            }

            return(connection.State == ConnectionState.Open);
        }
Ejemplo n.º 4
0
        private bool IsConnectionOpened()
        {
            if (connection.State != ConnectionState.Open)
            {
                try {
                    connection.Open();
                } catch (Exception e) {
                    string subject = (Program.itemReport is null ? string.Empty : Program.itemReport.Type.ToString()) + " Ошибка подключения к БД";
                    string body    = e.Message + Environment.NewLine + e.StackTrace;
                    SystemMail.SendMail(subject, body, Properties.Settings.Default.MailCopy);
                    Logging.ToLog(subject + " " + body);
                    Program.hasError = true;
                }
            }

            return(connection.State == ConnectionState.Open);
        }