Ejemplo n.º 1
0
        private static string Execute()
        {
            try
            {
                if (ConnectionHelper.conn.State == ConnectionState.Open)
                {
                    ConnectionHelper.conn.Close();
                }

                ConnectionHelper.conn.Open();
                reader = cmd.ExecuteReader();

                while (reader.Read())
                {
                    Sql = reader.GetString(0);
                }

                conn.Close();
                ConnectionHelper.conn.Dispose();
            }
            catch (SqlException ex)
            {
                ConnectionHelper.conn.Close();
                MessageErrorDialog error = new MessageErrorDialog("Izvor!?", "Spajanje na bazu izvora nije uspjelo! Provjerite ConnString izvora i dostupnost.", ex.ToString());
                error.ShowDialog();
                ConnectionHelper.conn.Dispose();
                return(String.Empty);
            }

            return(Sql);
        }
Ejemplo n.º 2
0
        public static string TestConnection(string connString)
        {
            PrepareSourceConn(CommandType.Text);
            conn.ConnectionString = connString;

            try
            {
                if (conn.State == ConnectionState.Open)
                {
                    conn.Close();
                }

                conn.Open();
                conn.Close();
                return("Konekcija uspješna!");
            }
            catch (Exception ex)
            {
                if (conn.State == ConnectionState.Open)
                {
                    conn.Close();
                }
                MessageErrorDialog error = new MessageErrorDialog("Spajanje!?", "Spajanje sa navedenim ConnString-om nije uspjelo.", ex.ToString());
                error.ShowDialog();
                return("Konekcija nije uspjela!");
            }
        }
Ejemplo n.º 3
0
        private static void ExecuteGridReader(ref GridControl grid)
        {
            try
            {
                if (ConnectionHelper.conn.State == ConnectionState.Open)
                {
                    ConnectionHelper.conn.Close();
                }
                try
                {
                    ConnectionHelper.conn.Open();
                }
                catch (SqlException ex)
                {
                    MessageErrorDialog error = new MessageErrorDialog("Izvor!?", "Spajanje na bazu nije uspjelo! Provjerite ConnString izvora.", ex.ToString());
                    error.ShowDialog();
                    return;
                }

                ConnectionHelper.ds = new DataSet();
                ConnectionHelper.adapter.Fill(ConnectionHelper.ds);
                ConnectionHelper.conn.Close();

                grid.DataSource = ConnectionHelper.ds.Tables[0];
            }
            catch (SqlException ex)
            {
                ConnectionHelper.conn.Close();
                MessageErrorDialog error = new MessageErrorDialog("Izvor!?", "Spajanje na bazu izvora nije uspjelo! Provjerite ConnString izvora i dostupnost.", ex.ToString());
                error.ShowDialog();
            }

            ConnectionHelper.conn.Dispose();
        }
 public void ShowError(string error)
 {
     using (MessageErrorDialog dlg = new MessageErrorDialog())
     {
         dlg.Message = error;
         dlg.ShowDialog();
     }
 }
Ejemplo n.º 5
0
        private static void Execute()
        {
            try
            {
                if (conn.State == ConnectionState.Open)
                {
                    conn.Close();
                }

                conn.Open();
                cmd.ExecuteNonQuery();
                conn.Close();
            }
            catch (Exception ex)
            {
                conn.Close();
                MessageErrorDialog error = new MessageErrorDialog("Izvor!?", "Ažuriranje podataka na izvoru nije uspjelo! Provjerite ConnString izvora i dostupnost.", ex.ToString());
                error.ShowDialog();
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Use this procedure when destination connString is known.
        /// </summary>
        /// <param name="combo"></param>
        /// <param name="query"></param>
        public static void FillComboDestData(ref ComboBoxEdit combo, string query)
        {
            conn = new SqlConnection(GetDestConnString());

            cmd             = new SqlCommand();
            cmd.Connection  = conn;
            cmd.CommandType = CommandType.Text;
            cmd.CommandText = query;

            try
            {
                if (conn.State == ConnectionState.Open)
                {
                    conn.Close();
                }

                conn.Open();
                reader = cmd.ExecuteReader();
            }
            catch (SqlException ex)
            {
                if (conn.State == ConnectionState.Open)
                {
                    conn.Close();
                }

                MessageErrorDialog error = new MessageErrorDialog("Destinacija!?", "Čitanje podataka na destinaciji nije uspjelo! Provjerite ConnString destinacije i VPN.", ex.ToString());
                error.ShowDialog();
                return;
            }

            combo.Properties.Items.Clear();
            while (reader.Read())
            {
                combo.Properties.Items.Add(reader.GetString(0));
            }

            reader.Close();
            conn.Close();
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Use this procedure when destination connString is known.
        /// </summary>
        /// <param name="cmbDatabase"></param>
        public static void GetDestDatabases2(ref ComboBoxEdit cmbDatabase)
        {
            conn = new SqlConnection(GetDestConnString());

            cmd             = new SqlCommand();
            cmd.Connection  = conn;
            cmd.CommandType = CommandType.Text;
            cmd.CommandText = "SELECT name FROM master..sysdatabases";

            try
            {
                if (conn.State == ConnectionState.Open)
                {
                    conn.Close();
                }

                conn.Open();
                reader = cmd.ExecuteReader();
            }
            catch (SqlException ex)
            {
                if (conn.State == ConnectionState.Open)
                {
                    conn.Close();
                }

                MessageErrorDialog error = new MessageErrorDialog("Destinacija!?", "Čitanje baza na destinaciji nije uspjelo! Provjerite ConnString destinacije i VPN.", ex.ToString());
                error.ShowDialog();
                return;
            }

            cmbDatabase.Properties.Items.Clear();
            while (reader.Read())
            {
                cmbDatabase.Properties.Items.Add(reader.GetString(0));
            }

            reader.Close();
            conn.Close();
        }
Ejemplo n.º 8
0
        /// <summary>
        /// This procedure is used before destination ConnString was created. For any subsequent use GetDestDatabases2.
        /// </summary>
        /// <param name="cmbDatabase"></param>
        /// <param name="server"></param>
        /// <param name="username"></param>
        /// <param name="password"></param>
        public static void GetDestDatabases(ref ComboBoxEdit cmbDatabase, string server, string username, string password)
        {
            conn = new SqlConnection("Data source=" + server + ";User ID=" + username + ";Password="******"sp_databases";

            try
            {
                if (conn.State == ConnectionState.Open)
                {
                    conn.Close();
                }

                conn.Open();
                reader = cmd.ExecuteReader();
            }
            catch (SqlException ex)
            {
                if (conn.State == ConnectionState.Open)
                {
                    conn.Close();
                }

                MessageErrorDialog error = new MessageErrorDialog("Destinacija!?", "Čitanje baza na destinaciji nije uspjelo! Provjerite ConnString destinacije i VPN.", ex.ToString());
                error.ShowDialog();
                return;
            }

            cmbDatabase.Properties.Items.Clear();
            while (reader.Read())
            {
                cmbDatabase.Properties.Items.Add(reader.GetString(0));
            }

            reader.Close();
            conn.Close();
        }
Ejemplo n.º 9
0
        public static string GetDestConnString()
        {
            appPath = Path.GetDirectoryName(Application.ExecutablePath);

            try
            {
                if (System.IO.File.Exists(appPath + "\\DestConnString.txt"))
                {
                    return(System.IO.File.ReadAllText(appPath + "\\DestConnString.txt"));
                }
                else
                {
                    //create file
                    System.IO.File.WriteAllText(appPath + "\\DestConnString.txt", "");
                    return("");
                }
            }
            catch (Exception ex)
            {
                MessageErrorDialog error = new MessageErrorDialog(".txt datoteka!?", "Čitanje i pisanje iz datoteke DestConnString.txt nije uspjelo.", ex.ToString());
                error.ShowDialog();
                return(ex.ToString());
            }
        }
        public virtual void ProcessError(Exception error, bool showError = true)
        {
            Exception innerError = ExtractFromAggregateException(error);

            if (IsCancelation(innerError) || innerError == null)
            {
                return;
            }

            innerError.GenerateReferenceId();

            Log.Debug(GetErrorMessage(innerError).Message);
            Log.Error(innerError);
            if (innerError is HttpClientException)
            {
                HttpClientException httpException = innerError as HttpClientException;
                ErrorInfo           errorInfo     = httpException.ErrorInfo;
                if (httpException.StatusCode == HttpStatusCode.Unauthorized)
                {
                    if (!IsLoogedIn)
                    {
                        return;
                    }
                    LogoutAction();
                    if (!showError)
                    {
                        return;
                    }
                    using (MessageDialog dlgResult = CreateMessageDialog())
                    {
                        dlgResult.Title          = Resources.Session_Expired;
                        dlgResult.Messsage       = GetErrorMessage(httpException).Message;
                        dlgResult.OkText         = "Login";
                        dlgResult.AllowReporting = false;
                        if (dlgResult.ShowDialog() == DialogResult.OK)
                        {
                            LoginAction();
                        }
                    }
                    return;
                }
                if (httpException.StatusCode == HttpStatusCode.Forbidden)
                {
                    if (errorInfo?.Code == Constants.ADDIN_VERSION_LOGIN ||
                        errorInfo?.Code == Constants.ADDIN_VERSION_LOGOUT)
                    {
                        if (!IsLoogedIn)
                        {
                            return;
                        }
                        LogoutAction();
                    }
                    if (!showError)
                    {
                        return;
                    }
                    using (MessageDialog dialog = CreateMessageDialog())
                    {
                        dialog.Title          = httpException.StatusCode.ToString();
                        dialog.Messsage       = GetErrorMessage(httpException).Message;
                        dialog.ShowCancel     = false;
                        dialog.OkText         = Resources.Ok;
                        dialog.AllowReporting = true;
                        dialog.ShowHandledDialog();
                    }
                    return;
                }
                if (httpException.StatusCode == HttpStatusCode.BadRequest)
                {
                    if (!showError)
                    {
                        return;
                    }
                    using (MessageDialog dialog = CreateMessageDialog())
                    {
                        dialog.Title          = httpException.StatusCode.ToString();
                        dialog.Messsage       = GetErrorMessage(httpException).Message;
                        dialog.ShowCancel     = false;
                        dialog.OkText         = Resources.Ok;
                        dialog.AllowReporting = true;
                        dialog.ShowHandledDialog();
                    }
                    return;
                }
                if (httpException.StatusCode == HttpStatusCode.ServiceUnavailable)
                {
                    if (!showError)
                    {
                        return;
                    }
                    using (MessageDialog dialog = CreateMessageDialog())
                    {
                        dialog.Title          = httpException.StatusCode.ToString();
                        dialog.Messsage       = GetErrorMessage(httpException).Message;
                        dialog.ShowCancel     = false;
                        dialog.OkText         = Resources.Ok;
                        dialog.AllowReporting = true;
                        dialog.ShowHandledDialog();
                    }
                    return;
                }
            }

            if (innerError is HttpRequestException)
            {
                if (innerError.InnerException is WebException)
                {
                    if (!showError)
                    {
                        return;
                    }
                    using (MessageDialog dialog = CreateMessageDialog())
                    {
                        dialog.Title          = Resources.Network_Error;
                        dialog.Messsage       = GetErrorMessage((WebException)innerError.InnerException);
                        dialog.ShowCancel     = false;
                        dialog.OkText         = Resources.Ok;
                        dialog.AllowReporting = true;
                        dialog.ShowHandledDialog();
                    }
                    return;
                }
            }

            if (innerError is IeVersionException)
            {
                if (!showError)
                {
                    return;
                }
                using (MessageDialog dialog = CreateMessageDialog())
                {
                    dialog.Title          = "Error";
                    dialog.Messsage       = Resources.To_use_addin_please_install_IE_with_version_10_or_upper;
                    dialog.ShowCancel     = false;
                    dialog.OkText         = Resources.Ok;
                    dialog.AllowReporting = true;
                    dialog.ShowHandledDialog();
                }
                return;
            }

            if (!showError)
            {
                return;
            }
            using (MessageErrorDialog dlg = CreateMessageErrorDialog())
            {
                var info = GetErrorMessage(error);
                dlg.Message        = info.Message;
                dlg.MessageDetails = info.Details;
                dlg.AllowReporting = true;
                dlg.ShowDialog();
            }
        }