public int? Create(ConnectionString entity)
        {
            using (SqlCeConnection connection = new SqlCeConnection(ConnectionString))
            {
                connection.Open();
                SqlCeCommand command = new SqlCeCommand("INSERT INTO ConnectionStrings(Type, Name, Connection) VALUES (@Type, @Name, @Connection)", connection);
                command.Parameters.AddWithValue("@Type", (int)entity.Type);
                command.Parameters.AddWithValue("@Name", entity.Name);
                command.Parameters.AddWithValue("@Connection", entity.Connection);
                command.ExecuteNonQuery();

                SqlCeCommand getId = new SqlCeCommand("SELECT @@IDENTITY AS Id", connection);
                object id = getId.ExecuteScalar();
                return id == null ? (int?)null : Convert.ToInt32(getId.ExecuteScalar());
            }
        }
        public bool HasDuplicate(ConnectionString entity)
        {
            using (SqlCeConnection connection = new SqlCeConnection(ConnectionString))
            {
                connection.Open();
                SqlCeCommand command = new SqlCeCommand(
            @"SELECT
            CASE    WHEN    EXISTS
            (
            SELECT  1
            FROM    ConnectionStrings
            WHERE   Name  =   @Name
            AND     (
                    @Id IS NULL
                OR ID    <>  @Id
            )
            )
            THEN    1
            ELSE    0
            END", connection);

                SqlCeParameter idParameter = new SqlCeParameter("@Id", System.Data.SqlDbType.Int);
                if (entity.ID.HasValue)
                    idParameter.Value = entity.ID;
                else
                    idParameter.Value = DBNull.Value;
                command.Parameters.Add(idParameter);
                command.Parameters.AddWithValue("@Name", entity.Name);
                return Convert.ToBoolean(command.ExecuteScalar());
            }
        }
Пример #3
0
        public XmlLoader(ConnectionString conString)
        {
            if (conString == null || string.IsNullOrWhiteSpace(conString.Connection))
                throw new NullReferenceException("Путь к XML-файлу со снимком БД не указан!");

            if (!File.Exists(conString.Connection))
                throw new FileNotFoundException(string.Format("Файл [{0}] со снимком БД не найден!", conString.Connection));

            _conString = conString;
        }
 public void Update(ConnectionString entity)
 {
     using (SqlCeConnection connection = new SqlCeConnection(ConnectionString))
     {
         connection.Open();
         SqlCeCommand command = new SqlCeCommand("UPDATE ConnectionStrings SET Type = @Type , Name = @Name , Connection = @Connection WHERE ID = @Id", connection);
         command.Parameters.AddWithValue("@Id", entity.ID.Value);
         command.Parameters.AddWithValue("@Type", (int)entity.Type);
         command.Parameters.AddWithValue("@Name", entity.Name);
         command.Parameters.AddWithValue("@Connection", entity.Connection);
         command.ExecuteNonQuery();
     }
 }
Пример #5
0
 //public IDbLoader Loader { get; private set; }
 //public IDbSaver Saver { get; private set; }
 public DataBase(ConnectionString conString, IDbContext context)
 {
     ConString = conString;
     Context = context;
     //Context = Loader.Context;
 }
 public void AddNewConnectionStringExecute(object o)
 {
     ConnectionString s = new ConnectionString() { Type = DataLayer.Enums.DataBaseType.SqlServer };
     EditString(s);
 }
 private void EditString(ConnectionString cString)
 {
     if (EditItem != null)
     {
         RefreshCollection(EditItem(this, new EditEventArgs() { editString = cString }));
     }
 }