예제 #1
0
        public void Delete( Contact contact )
        {
            using ( connection = factory.CreateDbConnection () )
            {
                try
                {
                    DbCommand cmd = connection.CreateCommand ();

                    cmd.CommandText = "DELETE FROM [" + TABLENAME + @"]
                                       WHERE    [Address] like @address AND
                                                [Phone] like @phone";
                    FactoryUtility.AddParameterWithValue ( cmd, "@address", contact.Address );
                    FactoryUtility.AddParameterWithValue ( cmd, "@phone", contact.Phone );
                    cmd.Connection = connection;

                    cmd.ExecuteNonQuery ();
                }
                catch ( Exception ex )
                {
                    MessageBox.Show ( ex.Message );
                }
            }
        }
예제 #2
0
        private User FormateUser( UserDTO packet, Contact contact )
        {
            return new User
            {
                Contact = contact,

                Id = packet.Id,
                ContactId=packet.ContactId,

                Login = packet.Login,
                Password = packet.Password,
                IsAdmin=packet.IsAdmin
            };
        }
예제 #3
0
        public void Save( Contact contact )
        {
            using ( connection = factory.CreateDbConnection () )
            {
                if ( isTableExists () == false )
                {
                    createTable ();
                }

                if ( isContactExists ( contact ) == false )
                {
                    insertContact ( contact );
                }
            }
        }
예제 #4
0
 private bool isContactExists( Contact contact )
 {
     try
     {
         DbCommand cmd = connection.CreateCommand ();
         cmd.CommandText = "SELECT COUNT( *) from [" + TABLENAME + @"] where
                 [Address] like @address AND
                 [Phone] like @phone";
         FactoryUtility.AddParameterWithValue ( cmd, "@address", contact.Address );
         FactoryUtility.AddParameterWithValue ( cmd, "@phone", contact.Phone );
         cmd.Connection = connection;
         int addressCount = ( int ) cmd.ExecuteScalar ();
         if ( addressCount > 0 )
         {
             contact.Id = getExistingId ( contact );
             return true;
         }
         return false;
     }
     catch ( Exception ex )
     {
         MessageBox.Show ( ex.Message );
         return true;
     }
 }
예제 #5
0
        private void insertContact( Contact contact )
        {
            try
            {
                DbCommand cmd = connection.CreateCommand ();
                cmd.CommandText = @"INSERT INTO [" + TABLENAME + @"]
                                            ( [Address], [Phone])
                                            VALUES (@country, @Phone)";
                cmd.Connection = connection;
                FactoryUtility.AddParameterWithValue ( cmd, "@country", contact.Address );
                FactoryUtility.AddParameterWithValue ( cmd, "@phone", contact.Phone );
                cmd.ExecuteNonQuery ();

                contact.Id = getLastId ();
            }
            catch ( Exception ex )
            {
                MessageBox.Show ( ex.Message );
            }
        }
예제 #6
0
 private int getExistingId( Contact contact )
 {
     try
     {
         DbCommand cmd = connection.CreateCommand ();
         cmd.CommandText = "SELECT [ID] from [" + TABLENAME + @"] where
                 [Address] like @address AND
                 [Phone] like @phone";
         FactoryUtility.AddParameterWithValue ( cmd, "@address", contact.Address );
         FactoryUtility.AddParameterWithValue ( cmd, "@phone", contact.Phone );
         cmd.Connection = connection;
         int addressID = ( int ) cmd.ExecuteScalar ();
         if ( addressID > 0 )
         {
             return addressID;
         }
         return -1;
     }
     catch ( Exception ex )
     {
         MessageBox.Show ( ex.Message );
         return -1;
     }
 }