Esempio n. 1
0
        /// <summary>
        /// Updates the specified dto.
        /// </summary>
        /// <param name="dto">The dto.</param>
        /// <param name="completed">The completed.</param>
        public void Update(DTO.DatasourceDto dto, Action <bool, Exception> completed)
        {
            _updCompleted = completed;
            dsCtx         = new AdminDatasourcesDomainContext();
            InvokeOperation <bool> updResult = dsCtx.UpdateDatasource(dto);

            updResult.Completed += new EventHandler(updResult_Completed);
        }
Esempio n. 2
0
        /// <summary>
        /// Adds the specified dto.
        /// </summary>
        /// <param name="dto">The dto.</param>
        /// <param name="completed">The completed.</param>
        public void Add(DTO.DatasourceDto dto, Action <bool, Exception> completed)
        {
            _addCompleted = completed;
            dsCtx         = new AdminDatasourcesDomainContext();
            InvokeOperation <bool> addResult = dsCtx.AddDatasource(dto);

            addResult.Completed += new EventHandler(addResult_Completed);
        }
Esempio n. 3
0
        public bool UpdateDatasource(DTO.DatasourceDto dsDto)
        {
            MySqlConnection mySqlConn = new MySqlConnection(this.ConnectionString);

            mySqlConn.Open();

            MySqlCommand addDSCommand     = mySqlConn.CreateCommand();
            MySqlCommand addUserDSCommand = mySqlConn.CreateCommand();

            addDSCommand.CommandType = System.Data.CommandType.StoredProcedure;

            addDSCommand.CommandText = "usp_update_datasource";

            Cryptography cy = new Cryptography();

            addDSCommand.Parameters.Add("DatasourceNameArg", dsDto.DatasourceName);
            addDSCommand.Parameters.Add("DatabaseType", dsDto.Connection.DatabaseType.ToString());
            addDSCommand.Parameters.Add("PersistSecurityInfo", dsDto.Connection.PersistSecurityInfo.ToString());
            addDSCommand.Parameters.Add("InitialCatalog", cy.Encrypt(dsDto.Connection.DatabaseName));
            addDSCommand.Parameters.Add("DatasourceServerName", cy.Encrypt(dsDto.Connection.ServerName));
            addDSCommand.Parameters.Add("DatabaseUserID", cy.Encrypt(dsDto.Connection.UserId));
            addDSCommand.Parameters.Add("Password", cy.Encrypt(dsDto.Connection.Password));
            addDSCommand.Parameters.Add("DatabaseObject", cy.Encrypt(dsDto.Connection.DatabaseObject));
            addDSCommand.Parameters.Add("DatasourceID", dsDto.DatasourceId);

            addDSCommand.Parameters.Add("active", dsDto.IsActive);

            try
            {
                string assUsers     = "";
                string datasourceID = "";

                foreach (Ewav.DTO.UserDTO item in dsDto.AssociatedUsers)
                {
                    assUsers     += string.Format("{0},", item.UserID.ToString());
                    datasourceID += string.Format("{0},", dsDto.DatasourceId.ToString());
                }
            }
            catch (Exception)
            {
            }

            try
            {
                int dsId = Convert.ToInt32(addDSCommand.ExecuteScalar());
            }
            catch (Exception)
            {
                return(false);
            }

            return(true);

            return(true);
        }
Esempio n. 4
0
        /// <summary>
        /// Adds the datasource.
        /// </summary>
        /// <param name="dsDto">The ds dto.</param>
        /// <returns></returns>
        public bool AddDatasource(DTO.DatasourceDto dsDto)
        {
            MySqlConnection mySqlConn = new MySqlConnection(this.ConnectionString);

            mySqlConn.Open();

            MySqlCommand addDSCommand     = mySqlConn.CreateCommand();
            MySqlCommand addUserDSCommand = mySqlConn.CreateCommand();

            int dsId = -1;

            addDSCommand.CommandType = System.Data.CommandType.StoredProcedure;

            addDSCommand.CommandText = "usp_add_datasource"; //TBD

            Cryptography cy = new Cryptography();

            addDSCommand.Parameters.Add("DatasourceNameArg", dsDto.DatasourceName);
            addDSCommand.Parameters.Add("OrganizationId", dsDto.OrganizationId);
            addDSCommand.Parameters.Add("DatasourceServerName", cy.Encrypt(dsDto.Connection.ServerName));
            addDSCommand.Parameters.Add("DatabaseType", dsDto.Connection.DatabaseType.ToString());
            addDSCommand.Parameters.Add("InitialCatalog", cy.Encrypt(dsDto.Connection.DatabaseName));
            addDSCommand.Parameters.Add("PersistSecurityInfo", dsDto.Connection.PersistSecurityInfo.ToString());
            addDSCommand.Parameters.Add("DatabaseUserID", cy.Encrypt(dsDto.Connection.UserId));
            addDSCommand.Parameters.Add("Password", cy.Encrypt(dsDto.Connection.Password));
            addDSCommand.Parameters.Add("DatabaseObject", cy.Encrypt(dsDto.Connection.DatabaseObject));
            addDSCommand.Parameters.Add("SQLQuery", dsDto.SQLQuery());

            addDSCommand.Parameters.Add("active", dsDto.IsActive);

            addDSCommand.Parameters.Add("@DatasourceUser", SqlDbType.Structured);
            addDSCommand.Parameters["@DatasourceUser"].Direction = ParameterDirection.Input;

            addDSCommand.Parameters.Add("portnumber", cy.Encrypt(dsDto.Connection.PortNumber));

            try
            {
                string assUsers     = "";
                string datasourceID = "";

                foreach (Ewav.DTO.UserDTO item in dsDto.AssociatedUsers)
                {
                    assUsers     += string.Format("{0},", item.UserID.ToString());
                    datasourceID += string.Format("{0},", dsDto.DatasourceId.ToString());
                }


                addDSCommand.Parameters.Add("datasource_ids", datasourceID);
                addDSCommand.Parameters.Add("user_ids", assUsers);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }

            try
            {
                dsId = Convert.ToInt32(addDSCommand.ExecuteScalar());
            }
            catch (Exception)
            {
                return(false);
            }

            return(true);
        }
        /// <summary>
        /// Updates the datasource.
        /// </summary>
        /// <param name="dsDto">The ds dto.</param>
        /// <returns></returns>
        /// <exception cref="System.Exception"></exception>
        public bool UpdateDatasource(DTO.DatasourceDto dsDto)
        {
            PostgreSQLDB postDb = new PostgreSQLDB(this.ConnectionString);

            NpgsqlCommand Command = new NpgsqlCommand();

            Command.CommandType = System.Data.CommandType.StoredProcedure;

            Command.CommandText = "update_datasource";


            Cryptography cy = new Cryptography();

            NpgsqlParameter parameter = new NpgsqlParameter("dsname", NpgsqlTypes.NpgsqlDbType.Varchar);

            parameter.Value     = dsDto.DatasourceName;
            parameter.Direction = ParameterDirection.Input;
            Command.Parameters.Add(parameter);

            parameter           = new NpgsqlParameter("dbtype", NpgsqlTypes.NpgsqlDbType.Varchar);
            parameter.Value     = dsDto.Connection.DatabaseType.ToString();
            parameter.Direction = ParameterDirection.Input;
            Command.Parameters.Add(parameter);

            parameter           = new NpgsqlParameter("psinfo", NpgsqlTypes.NpgsqlDbType.Varchar);
            parameter.Value     = dsDto.Connection.PersistSecurityInfo.ToString();
            parameter.Direction = ParameterDirection.Input;
            Command.Parameters.Add(parameter);

            parameter           = new NpgsqlParameter("icatalog", NpgsqlTypes.NpgsqlDbType.Varchar);
            parameter.Value     = cy.Encrypt(dsDto.Connection.DatabaseName);
            parameter.Direction = ParameterDirection.Input;
            Command.Parameters.Add(parameter);

            parameter           = new NpgsqlParameter("dsservername", NpgsqlTypes.NpgsqlDbType.Varchar);
            parameter.Value     = cy.Encrypt(dsDto.Connection.ServerName);
            parameter.Direction = ParameterDirection.Input;
            Command.Parameters.Add(parameter);

            parameter           = new NpgsqlParameter("dbuid", NpgsqlTypes.NpgsqlDbType.Varchar);
            parameter.Value     = cy.Encrypt(dsDto.Connection.UserId);
            parameter.Direction = ParameterDirection.Input;
            Command.Parameters.Add(parameter);

            parameter           = new NpgsqlParameter("pwd", NpgsqlTypes.NpgsqlDbType.Varchar);
            parameter.Value     = cy.Encrypt(dsDto.Connection.Password);
            parameter.Direction = ParameterDirection.Input;
            Command.Parameters.Add(parameter);

            parameter           = new NpgsqlParameter("dbobject", NpgsqlTypes.NpgsqlDbType.Varchar);
            parameter.Value     = cy.Encrypt(dsDto.Connection.DatabaseObject);
            parameter.Direction = ParameterDirection.Input;
            Command.Parameters.Add(parameter);

            parameter           = new NpgsqlParameter("dsid", NpgsqlTypes.NpgsqlDbType.Integer);
            parameter.Value     = dsDto.DatasourceId;
            parameter.Direction = ParameterDirection.Input;
            Command.Parameters.Add(parameter);

            parameter           = new NpgsqlParameter("isactive", NpgsqlTypes.NpgsqlDbType.Boolean);
            parameter.Value     = dsDto.IsActive;
            parameter.Direction = ParameterDirection.Input;
            Command.Parameters.Add(parameter);

            StringBuilder sb = new StringBuilder();

            try
            {
                foreach (Ewav.DTO.UserDTO item in dsDto.AssociatedUsers)
                {
                    sb.Append(item.UserID);
                    sb.Append(",");
                }
            }
            catch (Exception e)
            {
                throw new Exception(e.Message);
            }

            parameter = new NpgsqlParameter("userids", NpgsqlTypes.NpgsqlDbType.Varchar);
            if (sb.ToString().Contains(","))
            {
                parameter.Value = sb.ToString().Substring(0, sb.ToString().Length - 1);
            }
            else
            {
                parameter.Value = "";
            }
            parameter.Direction = ParameterDirection.Input;
            Command.Parameters.Add(parameter);


            parameter           = new NpgsqlParameter("pnumber", NpgsqlTypes.NpgsqlDbType.Varchar);
            parameter.Value     = cy.Encrypt(dsDto.Connection.PortNumber.ToString());
            parameter.Direction = ParameterDirection.Input;
            Command.Parameters.Add(parameter);

            try
            {
                postDb.ExecuteNonQuery(Command);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
                //return false;
            }
            return(true);
        }
Esempio n. 6
0
        public bool UpdateDatasource(DTO.DatasourceDto dsDto)
        {
            SqlConnection sqlConn = new SqlConnection(this.ConnectionString);

            sqlConn.Open();

            object Formobj = null;

            if (dsDto.IsEpiInfoForm)
            {
                Formobj = ReadEWEDatasourceFormId(new DTO.EWEDatasourceDto()
                {
                    DatabaseName = dsDto.Connection.DatabaseName
                });
            }


            SqlCommand addDSCommand     = sqlConn.CreateCommand();
            SqlCommand addUserDSCommand = sqlConn.CreateCommand();

            addDSCommand.CommandType = System.Data.CommandType.StoredProcedure;

            addDSCommand.CommandText = "usp_update_datasource";

            Cryptography cy = new Cryptography();

            addDSCommand.Parameters.Add("EIWSSurveyId", (Formobj != null) ? Formobj : DBNull.Value);
            addDSCommand.Parameters.Add("DatasourceName", dsDto.DatasourceName);
            addDSCommand.Parameters.Add("DatabaseType", dsDto.Connection.DatabaseType.ToString());
            addDSCommand.Parameters.Add("PersistSecurityInfo", dsDto.Connection.PersistSecurityInfo.ToString());
            addDSCommand.Parameters.Add("InitialCatalog", cy.Encrypt(dsDto.Connection.DatabaseName));
            addDSCommand.Parameters.Add("DatasourceServerName", cy.Encrypt(dsDto.Connection.ServerName));
            addDSCommand.Parameters.Add("DatabaseUserID", cy.Encrypt(dsDto.Connection.UserId));
            addDSCommand.Parameters.Add("Password", cy.Encrypt(dsDto.Connection.Password));
            addDSCommand.Parameters.Add("DatabaseObject", cy.Encrypt(dsDto.Connection.DatabaseObject));
            addDSCommand.Parameters.Add("DatasourceID", dsDto.DatasourceId);

            addDSCommand.Parameters.Add("active", dsDto.IsActive);

            addDSCommand.Parameters.Add("pnumber", cy.Encrypt(dsDto.Connection.PortNumber));
            addDSCommand.Parameters.Add("@DatasourceUser", SqlDbType.Structured);
            addDSCommand.Parameters["@DatasourceUser"].Direction = ParameterDirection.Input;
            addDSCommand.Parameters["@DatasourceUser"].TypeName  = "DatasourceUserTableType";


            List <SqlDataRecord> sqlDrList = new List <SqlDataRecord>();

            SqlDataRecord sqdr;

            try
            {
                foreach (Ewav.DTO.UserDTO item in dsDto.AssociatedUsers)
                {
                    sqdr = new SqlDataRecord(new SqlMetaData[]
                                             { new SqlMetaData("DatasourceID", SqlDbType.Int),
                                               new SqlMetaData("UserID", SqlDbType.Int) });

                    // Set the record fields.
                    sqdr.SetInt32(0, dsDto.DatasourceId);
                    sqdr.SetInt32(1, item.UserID);

                    sqlDrList.Add(sqdr);
                }

                //// Also add the creator
                //sqdr = new SqlDataRecord(new SqlMetaData[]
                //    { new SqlMetaData("DatasourceID", SqlDbType.Int ),
                //       new SqlMetaData("UserID", SqlDbType.Int)
                //    });

                //sqdr.SetInt32(0, dsDto.DatasourceId);
                //sqdr.SetInt32(1, dsDto.CreatorID);
                //sqlDrList.Add(sqdr);


                if (dsDto.AssociatedUsers.Count == 0)
                {
                    addDSCommand.Parameters["@DatasourceUser"].Value = null;
                }
                else
                {
                    addDSCommand.Parameters["@DatasourceUser"].Value = sqlDrList;
                }
            }
            catch (Exception e)
            {
            }


            try
            {
                addDSCommand.ExecuteNonQuery();
            }
            catch (Exception ex)
            {
                //throw ex;
                return(false);
            }


            return(true);
        }