Silverlight

 

If you haven’t heard, and are a developer, then go look , its got to be big, someone was heard to say that Microsoft has rebooted the web!’

I will be putting up some stuff, once I come up for air, as with the "Orcas" beta one release and the silverlight bits, there is a lot to absorb, but its all good, oh and while I am talking about the new beta Orcas, Development Express have released new update to Code Rush with is totally compatible with the new Orcas release.

Posted in Silverlight | Leave a comment

Tag Cloud

 

This post is actually for my benefit, I want to try out using a tag cloud on a web page I am playing with at the moment, mainly to see how the data will look.

This looked a good article to get an idea of the html I would need

http://24ways.org/2006/marking-up-a-tag-cloud

I will possibly blog about the experience in the future.

Posted in Code | Leave a comment

I am Alive

 

Ok so its been a while, and no one noticed, but I am still alive, and have loads of things to blog about, which I hope to do over the next few weeks, I have installed a few new programs, and chosen a launcher for my Vista laptop, so things have been busy.

Most of my time has been taken by non computer things at the moment, mostly the garden, and having the yearly cleanouts of the house, it always amass me how much stuff you can gather which is never used, worn or viewed, so the charity shops are having a great time at the moment.

The Launcher I have chosen for my laptop turns out to be the Enso launcher, even though its not yet officially available for vista, and at first it didn’t click with me, it has some features that I really like, after reading the blogs and emailing the designers I discovered that Enso actually uses your favorites folder so I can type go http://blah and Enso opens the my browser and off it goes, I can close tabs and programs from its commands etc, so it has a lot of power, as it turns out its a bit like Code Rush, I have had it for over a year, and I am still only using about 10% of its power, I think that I will still be learning things about Enso for may months, but it has turned out to be very intuitive to use.

Talking of Enso I had a load of problems with our firewall at work, and the support team at Enso were great, when you think how cheep this program actually is to buy, there support beats the pants of most people, they are there and helpful, and within hours had my computer working a treat.

What made me decide to go with this launcher then, to put it simply it was Enso Words this product so changed my life, for me spelling is a real pain, and being able to simply check a word in any application simply changed the way I work, I now don’t worry so much, and when I am unsure I simply highlight the word I want to check (even in Visual Studio, when the word is part of a camel cased variable name or command) and hit caps lock type sp, release caps lock and the word is checked, alternatives given in a new window, and I am able to check the definition of the word as well so I can ensure that I have actually got the correct word in the first place.  It was so great, I decided that the Launcher must have hidden talents, the price ensured that I would get good value for money, so I went for it, and I have not been sorry.

I would suggest that everyone had a go at these products, they are simple to install, and use, although I have found that it takes time to retrain the hands not to go for the mouse every time I want to close or minimize a window and moving between windows.

this post was a prime example of how things have changed, I wasn’t sure of the word amass, so a quick highlight, holding down caps lock and typing de ensured that I was using the correct word, and the launcher is just a good, try them out, and let us know how you get along, they are a new way of working, which is simple and very quick.

 

Posted in Computers and Internet | Leave a comment

Real Test Driven Development – Thinking of Money 16

so finally we are working on the delete function, when a user clicks on on delete check box’s in the grid, and then clicks update button, the selected items should be deleted. writing a test for this is difficult, as we need to fill the grid with the correct items, this means setting it up correctly in code.

After much playing around, it dawned on me that I have the settings on the main form, and all I had to do was create the form within the code, then I can access the filled grid and test the delete, at least that’s the theory.

so the test ended up looking like this

        [Test]
        public void DeleteTransactions()
        {
            frmMain mainForm = new frmMain();
            DataGridView transGrid = mainForm.TransactionGrid;

            MoneyEngine.MoneyTransaction transaction = 
(MoneyEngine.MoneyTransaction)transGrid.Rows[0].DataBoundItem;
            transaction.ToDelete = true;

            // get the original count in rows, delete the first row, rebind the grid to update,
            int originalCount = transGrid.Rows.Count;
            _Controller.DeleteTransactions(transGrid);
            _Controller.BindDataGrid(transGrid);

            // and check the resulting row count.
            Assert.AreEqual(originalCount - 1, transGrid.Rows.Count);
        }

 and the delete transaction method looks like

     public void DeleteTransactions(DataGridView gridView)
        {
            bool hasDeletions = false;

            foreach (DataGridViewRow datarow in gridView.Rows)
            {
                MoneyEngine.MoneyTransaction trans = (MoneyEngine.MoneyTransaction)datarow.DataBoundItem;

                if (trans.ToDelete)
                    if (trans.Update())
                        hasDeletions = true;
            }

            if (hasDeletions)
            {
                _Engine.History.Clear();
                _Engine.LoadTransarctions();
            }
        }

I added a call to the delete transactions method in the update click method of the form, and attempted to add and delete rows from the grid as a user test, it all seams to work correctly and as I expected, all there is now is to create a rollout version using one click deployment, once I get a web site up and running a version of this will be available for those who want it. next I am off to think about the shopping version of this which will be my next project.

Before then I will have a look at the completed code and do a bit of refactoring. and tidying up ready, so when I do the shopping program I can integrate the data, also I am thinking of the mobile version and a wpf version of this.

Posted in Uncategorized | Leave a comment

Real Test Driven Development – Thinking of Money 15

next on the list  is to do the add transaction part of the update, this should simply be a case of passing the various form controls to the controller object, getting it to extract the various values and checking that we have a valid transaction, adding the transaction to the collection, and calling save.  I am hoping that because we have bound the collection to the grid, and hopefully we can insert the transaction at the beginning of the collection, that it will automatically display.

so first off we need a test.

        [Test]
        public void AddTransaction()
        {
            TextBox txtDescription = new TextBox();
            TextBox txtCategory = new TextBox();
            TextBox txtAmount = new TextBox();
            ComboBox cboType = new ComboBox();
            cboType.Items.Add("Addition");
            txtAmount.Text = "10.00";
            txtCategory.Text = "Unit Testing";
            txtDescription.Text = "Test";

            Assert.IsTrue(_Controller.UpdateTransaction(txtDescription, txtCategory, txtAmount, cboType));
        }

and this calls the controller code

    public bool UpdateTransaction(TextBox txtDescripiton, TextBox txtCategory, TextBox txtAmount, ComboBox cboType)
    {
        double amount = double.Parse(txtAmount.Text);
        if (amount==0)
            return false;

        string category = txtCategory.Text;
        string description = txtDescripiton.Text;

        txtAmount.Text = string.Empty;
        txtCategory.Text = string.Empty;
        txtDescripiton.Text = string.Empty;

        if (cboType.SelectedText == "Addition")
            return _Engine.AddTransaction(amount, category, description, System.DateTime.Now);
        else
            return _Engine.SubtractTransaction(amount, category, description, System.DateTime.Now);
    }

not the best bit of code at the moment, first we check that we have a valid amount, if not the routine exits, next we obtain the values in the text box’s, then clear them so when we return the form looks nice, lastly we simply add or delete the transaction.

it could do with some error returned, but currently we have no way of displaying this in the form. we can add it to the list of things to do in the next version, as I am sure there will be changes to the interface one users get their hands on it.

now we need to update the form so it calls this, I have refractored the controller so its now a module level variable and added a click event to the button as below

       private void btnUpdate_Click(object sender, EventArgs e)
       {
           _Controller.UpdateTransaction(txtDescription, txtCategory, txtAmount, cboType);
       }

and it didn’t work !

currently there is no update to the database when we hit update, so I need to add that functionality, the best place was in the add and subtract transaction, I only want to update when the transaction id is zero, ie its a new transaction so I added the following method to the money engine and added a call to the function in the add and subtract functions. notice that when the transaction ID is zero, a new transaction then we want to insert it at the top of the collection, if we are loading from the database then we want to add them in order, so its a simple add to list.

     private bool StoreTransaction(MoneyTransaction trans)
        {
            if (trans.TransactionID == 0)
            {
                _History.Insert(0, trans);
                return trans.Update();
            }
            else
            {
                _History.Add(trans);
                return true;
            }
        }

        private bool AddTransaction(int transID, double amount, string category, string description, 
DateTime transactionDate)
        {
            MoneyTransaction trans = new MoneyTransaction(transID, amount, category, description, 
transactionDate, TransactionType.AdditionTransaction);
            
            _Balance += trans.TransactionAmount;

            return StoreTransaction(trans);
        }

        private bool SubtractTransaction(int transID, double amount, string category, string description, 
DateTime transactionDate)
        {
            MoneyTransaction trans = new MoneyTransaction(transID, amount, category, description, 
transactionDate, TransactionType.SubtractionTransaction);
           
            _Balance -= trans.TransactionAmount;

            return StoreTransaction(trans);
        }

 ok so now it updates to the database so when we rerun the application, the transaction is there, so now we just need to get the grid to update, I was hoping that it would happen automatically, well actually it does but the grid has to be forced to update, that turns out that its as simple as calling refresh on the grid.

so Lastly for this release I need to check the grid for deletes.

Posted in Uncategorized | Leave a comment

Real Test Driven Development – Thinking of Money 14

 

right so we now need to display the balance, this is quite simple as we have a text box that is set to read only, and the balance is available form the engine, now we could add this balance to the current data grid controller, but I think the name is wrong so I shall rename it to the MoneyEngineController, so this will control all actions on the form.

looking at the controller code we can see that the only time the data is loaded is when the grid is bound, I think I will move that command up into the constructor, so when we create the controller, the data from the database is loaded ready, this will simplify the testing of the balance display and also leaves the data grid binding command doing a single thing, binding the data grid to the data source.

so we need a simple test to ensure we display the balance, I did a bit of refactoring on the test code, and ended up with the following test class

    [TestFixture]
    public class MoneyEngineControllerTests
    {
        ThinkingOfMoney.Controller.MoneyEngineController _Controller;

        [SetUp]
        public void SetupForTest()
        {
            _Controller = new ThinkingOfMoney.Controller.MoneyEngineController();
        }

        [Test]
        public void Hook()
        {
            Assert.IsTrue(true);
        }

        [Test]
        public void Create()
        {
            Assert.IsNotNull(_Controller);
        }

        [Test]
        public void BindDataGrid()
        {
            System.Windows.Forms.DataGridView gridView = new System.Windows.Forms.DataGridView();

            _Controller.BindDataGrid(gridView);

            Assert.IsTrue(gridView.Rows.Count == 0);
        }

        [Test]
        public void BindBalance()
        {
            System.Windows.Forms.TextBox txtBalance = new System.Windows.Forms.TextBox();
            _Controller.BindBalanceTextBox(txtBalance);

            Assert.IsTrue(txtBalance.Text.Length > 0, txtBalance.Text);
        }
    }

and the following code is now making up the controller, notice that I have formatted the output string(I found the information here) , and moved the loading code to the constructor.

    class MoneyEngineController
    {
        MoneyEngine.MoneyEngine _Engine;

        /// <summary>
        /// Initializes a new instance of the DataGridController class.
        /// </summary>
        public MoneyEngineController()
        {
            _Engine = new MoneyEngine.MoneyEngine();
            _Engine.LoadTransactions();         
        }

        public void BindDataGrid(System.Windows.Forms.DataGridView gridView)
        {
            gridView.DataSource = _Engine.History;
        }

        public void BindBalanceTextBox(System.Windows.Forms.TextBox txtBalance)
        {
            txtBalance.Text = string.Format("{0:c}", _Engine.Balance);
        }
    }

ok the test passes, we need to add the call to the form code, and run the form!

and the balance displays as zero, I was expecting more than that as some of the transactions have values in, so we do have a problem somewhere, looking at the code when we load the transactions from the database then the balance is not updated, so a quick change of code here, but first a test to prove the error and fix

        [Test]
        public void BalanceAfterLoad()
        {
            _Engine.LoadTransactions();

            Assert.IsTrue(_Engine.Balance > 0, "balance should be greater than zero");
        }

and as expected it fails, so now to update the load transactions method, to get a pass, first off started by changing the load class so it would use the available add and subtract routines that add too and subtract from the balance already, but I needed to be able to add the transaction id so update would work correctly

    public bool LoadTransactions()
        {
            DBMoneyEngine database = new DBMoneyEngine();
            DataTable transactions = database.GetTransactionsInDateOrder(ref _ErrorText);

            if (transactions == null)
                return false;

            if (transactions.Rows.Count > 0)
            {
                foreach (DataRow transData in transactions.Rows)
                {
                    Int32 transID = transData["TransID"] is DBNull ? 0 : Convert.ToInt32(transData["TransID"]);
                    TransactionType transType = transData["TransType"] is DBNull ? 
TransactionType.AdditionTransaction : (int) transData["TransType"] == 0 ? 
TransactionType.AdditionTransaction : TransactionType.SubtractionTransaction;
                    DateTime transDate = transData["TransDate"] is DBNull ? DateTime.Now : 
(DateTime) transData["TransDate"];
                    string transCategory = transData["TransCategory"] is DBNull ? string.Empty : 
transData["TransCategory"].ToString();
                    string transDescription = transData["TransDescription"] is DBNull ? string.Empty : 
transData["TransDescription"].ToString();
                    double transAmount = transData["TransAmount"] is DBNull ? 0 : 
(double)transData["TransAmount"];                     

                    if (transType == TransactionType.AdditionTransaction)
                        AddTransaction(transID, transAmount, transCategory, transDescription, transDate);

                    if (transType == TransactionType.SubtractionTransaction)
                        SubtractTransaction(transID, transAmount, transCategory, transDescription, transDate);
                }
            }

            return true;
        }

 This change required that the addition and subtraction routines were overloaded with a private method that took the transaction ID, the previous methods simply handed in 0 as a transaction id.

 

        private bool AddTransaction(int transID, double amount, string category, string description, 
DateTime transactionDate)
        {
            MoneyTransaction trans = new MoneyTransaction(transID, amount, category, description, 
transactionDate, TransactionType.AdditionTransaction);
            _History.Add(trans);

            _Balance += trans.TransactionAmount;

            return true;
        }
        public bool AddTransaction(double amount, string category, string description, DateTime transactionDate)
        {
            return AddTransaction(0, amount, category, description, transactionDate);
        }
        private bool SubtractTransaction(int transID, double amount, string category, string description, 
DateTime transactionDate)
        {
            MoneyTransaction trans = new MoneyTransaction(transID, amount, category, description, 
transactionDate, TransactionType.SubtractionTransaction);
            _History.Add(trans);

            _Balance -= trans.TransactionAmount;

            return true;
        }
        public bool SubtractTransaction(double amount, string category, string description, 
DateTime transactionDate)
        {
            return SubtractTransaction(0, amount, category, description, transactionDate);
        }

A quick run of all the tests confirms that we haven’t broken anything, you will also notice form the following screen shot that I changed the order in that the data is returned, and set the formatting on the account column, so that it matches the balance.

So next is the transaction addition

Posted in Projects | Leave a comment

String Formatting in c#

One of those things that I am always forgetting the correct syntax for, here is a handy reference for string formatting in c#

Posted in Code | Leave a comment

Real Test Driven Development – Thinking of Money 13

 

OK so I have tested the binding, and made sure that what I thought might work did, transferring this to our formal code means we need a way to test it as close to the interface as possible, personally I believe for programmer unit testing it is impossible to test actually at the interface short of actually clicking on the buttons.

My current way, and I am always open to suggestions, is to use a model view controller pattern, the model in this case is the engine, the view is the form and the controller will communicate between them both, and it is here that my testing will stop, so I want zero code if possible in the form, and all the code that is usually in the form within the controller.

so to the unit tests which look like this.

   [TestFixture]
    public class DataGridControllerTests
    {
        [Test]
        public void Hook()
        {
            Assert.IsTrue(true);
        }

        [Test]
        public void Create()
        {
            Assert.IsNotNull(new ThinkingOfMoney.Controller.DataGridController());
        }

        [Test]
        public void BindDataGrid()
        {
            System.Windows.Forms.DataGridView gridView = new System.Windows.Forms.DataGridView();

            DataGridController controller = new DataGridController();
            controller.BindDataGrid(gridView);

            Assert.IsTrue(gridView.Rows.Count == 0);
        }
    }

This is our usual hook and a create, the BindDataGrid is where the interest will happen it takes our forms grid , the test then ensures we have some rows when the function returns.

The controller code looks like this

    class DataGridController
    {
        MoneyEngine.MoneyEngine _Engine;

        public DataGridController()
        {
            _Engine = new MoneyEngine.MoneyEngine();                      
        }

        public void BindDataGrid(System.Windows.Forms.DataGridView gridView)
        {
            _Engine.LoadTransactions();

            gridView.DataSource = _Engine.History;
        }
    }

The controller creates a new money engine in its constructor, providing the link to the model, so the form dosn’t actually have any direct contact with the money engine at all.

The BindDataGrid method takes a data grid view as a parameter, and loads all the transactions, then the data grid view data source property is set to the engine history collection.

Finally we have to create the loading code for the main form

    public partial class frmMain : Form
    {
        public frmMain()
        {
            InitializeComponent();

            Controller.DataGridController gridController = new ThinkingOfMoney.Controller.DataGridController();
            gridController.BindDataGrid(dgvHistory);
        }
    }

This is the bit we cant test, so it has to be as basic as possible, now we can run the project and see how the user interface fills out.

so next we need to display the balance, and be able to add and update the transactions

Posted in Projects | Leave a comment

Real Test Driven Development – Thinking of Money 12

It took a while to figure out correctly but by adding the grid to the form and opening the data grid view task, I selected the object data source

and then clicked next, ok so we want to display money engine transactions, this is important, what we are selecting on this screen is the row item we are going to display, this took me a bit of time to get my head around, it helped me to see it as defining the columns that would be displayed, first select the transaction object, which has all the properties of a transaction, and click next

press finish with money transactions selected, and you are returned to the main form, but this time the grid has all the basic column names filled out, now we need to edit the grid column names so that only the ones we are interested in are shown.

So now with this basic configuration done its back to the code.

when I was trying out this I used a new form and simply dropped the datagrid onto in, and set it up to fill the form, I wanted to quickly understand the binding technique, and what code was required to bind the collection to the form, this ended up as follows

       public Form1()
        {
            InitializeComponent();

            MoneyEngine.MoneyEngine engine = new MoneyEngine.MoneyEngine();
            engine.LoadTransactions();

            dataGridView1.DataSource = engine.History;
        }

it turned out that simply loading the money engine, and then binding the engine history, which is a collection of transactions, this automatically fills the grid, like so

having tested the theory we setup the main gird on the money form the same way, however in keeping with our wish to test as much as possible, we will move the binding code into a controller module, which we can test in the usual way, 

know I did all of this without running any unit tests, but sometimes I find its easier just to breakout a quick form and try out some quick code, especially when it involves using Visual Studio wizards.  As long as when we transfer the code into the main project, we create tests that will ensure that it works and any changes are caught things should be fine.

which we shall do next time.

Posted in Projects | Leave a comment

Program Launchers and Spell Checkers

For the last month I have been testing a new program launcher, and spell checker supplied by ENSO now they are two products, so I shall treat them totally separately

ENSO Words

I have great difficulty with spelling (just ask the people I work with), so I rely on spell checkers a lot of the time, I won’t send an email without checking the spelling, this for emails and documents wasn’t really a problem, but when it came to other things like say naming variables or commands the problem became virtually impossible, short of cutting the word out and pasting it into word there was not a lot of choice, this would totally break the flow of what I was doing, and required word to load etc.

Enter Enso Words now in ANY application I can press caps lock and type spellcheck and any highlighted words are spell checked, if incorrectly spelt a browser like window opens and like word the incorrect spellings are highlighted and with a click of the mouse suggestions given. when I have finished checking the text, pressing caps lock again and typing done closes the window, and any corrections are copied to the highlighted text.

For the first time I am able to highlight function names and spell check them quickly and easily, names made up of two English words are easy to check as only highlighted text is spellchecked, so I can simply highlight one part of the function name.

The program has only crashed on me once, it was an unfair test to be honest as it was a complete HTML web page including tags, poor old words got a good way down before crashing out, but to my surprise it opened a browser, with a crash dump and space for me to write some text describing what I was doing, the support email came back within hours, and the problem was solved. 

I cannot say enough about the support these guys give, they are there with any problem, even as with myself just the other day when I tried out Words on my Vista machine, which I knew the web site said was not supported yet, they replied trying to help out, and promising a version for vista soon (it crashed trying to update itself, which it does by the way in the background without any prompting from the user)

And with a price tag of just $19.95 this is one program that will never be without again. its just the best solution for my spelling problem I have ever seen, and to be honest I have only just touched on its power, it also has a  thesaurus, a character count and you can find the dictionary definition for a selected word.

oh and did I say this was system wide, any program that you can select text in!

 

ENSO Launcher

Now before I start, let me say that I have been using Colibri for many months now (probably nearly a year), and it has been my defacto launcher for both my 2003 server development machine and my vista laptop, its quick to call simply hit ctr+space and start typing the name of the application you want to launch, it learns so to launch visual studio 2005 I simply have to hit the 5 key now as that is the top item in the list, all this and the only configuration I have done is to select the theme I liked for its UI.

So Enso Launcher had a great mountain to climb, I again have been using it for about a month now, and have done no configuration of the program, as even when I set shortcuts unless I use them many times I don’t remember them anyway, and the launcher has a great many commands and functions that I have never used in the month I have had it installed, other than to play with them when I first started the program.  One of the things I think is that a review should be honest, there is much functionality within programs that I will never use, (word being a prime example of the 10% rule, a user will use about 10% of an applications power most of the time)

I used this as a program launcher, now I tend to run word, visual studio 2003 or 2005, sql management studio, Internet explorer, firefox, and notepad2 along with my startup programs of outlook 2007 and sharp reader.  Now for the launcher to launch a program you have to hold down the caps lock key and type open, then a space and the name of the program you want to run, so for visual studio it would be visual studio, by which time the small list of available options would have both studios in and I could select either one, typing sql would normally display in the list sql management studio, although the position of the program within the list might vary each time.

Before I start complaining, let me say I wanted to like Launcher, it fitted well with the spell checker, both the programs mesh well together, and their is a lot of functionality available in the launcher application that I have never seen anywhere else, its just that I didn’t use it, for example given a highlighted sum it will solve it and provide the answer, go switches to windows by name, I tend to use alt + tab though, and many others for maximizing and minimizing the from window, and even closing it completely, I tend not to minimize or maximize windows, much.

So what I am about to say, is purely from the program launching point of view, and its simple Colibri is simply quicker, it takes fewer keystrokes to open a program, and application launchers for me is about the number of keystrokes it takes. the quickest I can open visual studio 2005 in Enso Launcher is to press [Caps Lock] type open and then 5 if I have set a shortcut, this is 6 keystrokes, with colbri its [control + space] 5, (after a couple of times using it) which is a best 3 keystrokes, half the amount. 

For me if ENSO needs to default to a selected command, for me this would be open, which would reduce the amount of typing I have to do to get the application running.  I early wanted to love this program and but I have to admit that at present Colibri still just wins on pure speed.

Posted in Computers and Internet | 1 Comment