New Photo Blog

To keep everything nice and tidy I’ve started a new blog for my photography ‘stuff’.

It can be found here Photos!

Not much to see at the moment but will build over the next few weeks.

Posted in Photography | Tagged , , , | Leave a comment

Insurance Claims & Nuisance Calls From Personal Accident Companies

It’s now just about a year since I had a minor accident in my car.  I was actually stationary when a small van backed into the passenger door of my car.  The impact was about equivalent to someone kicking the door.  It goes without saying that I suffered no distress or injury or, in fact, anything that I feel I need to be compensated for.

Since the accident (in fact on the very same day) I have been receiving calls from Personal Accident Companies wanting to help get me compensation for my injuries.  I would estimate that I must have had in excess of 1000 calls, tend to have a minimum of one a day, and actually had 5 last night between 19:00 and 21:00.

I’ve gone through phases of explaining exactly what happened and that I have not suffered in any way, being deliberately rude, saying I don’t live here any more, leaving the phone to one side until they hang up… and so on.

One problem seems to be that the other party made a successful claim (not sure what for) and therefore the assumption is that I will claim too.  I had one caller suggest that even though I hadn’t suffered at all I should just put a claim in (which would be approved) and that would stop companies calling me.  So making a fraudulent claim is the suggested action of one company.

One other suggested that “maybe you’ve forgotten that you were hurt, this does happen…”, so I need to “remember” being injured.

And a third just suggested that I was an idiot as I could get “free money”.

On the bright side, one of the companies I spoke to said that you have to claim within three years, so only two more years of nuisance calls to go!

It would appear that this is just a money making scheme of insurance (they sell your information on) and personal accident companies, they both take their cuts, and the costs get passed onto us in our premiums.

I would also like to take this opportunity to thank Direct Line for selling on my details.

If you think that there should be more control over these nuisance calls Which? are running a campaign here:

Which? Calling Time on Nuisance Calls & Texts

Posted in News and politics | Tagged , , , , , , , | 2 Comments

Showing Two Different Scales on Y Axis SQL Server Reporting Services (SSRS)

Long time, no post…

I was asked to create a graph showing throughput of bags on a conveyor grouped into 5 minute intervals.  One of the requirements was to show two scales on the Y axis, bags / 5 minute interval, and the equivalent value in bags / hour.  I.e. bags / 5 minutes * 12.  I thought that I would be able to use a formula to specify the axis values, however, this isn’t possible in SSRS.

What I ended up with is this:

img 1

And if you’re interested, this is how I did it:

Step 1

You need to set the start and interval for the Y axis at a value that will be suitable for your data:

Right-click on the axis, select “Vertical Axis Properties”

img 1b

I set the minimum at zero and the interval at fifty

img 1c

Step 2

Calculate your corresponding Y axis values to match the interval chosen above

As mine is Value * 12 I ended up with a list like below

50 = 600, 100 = 1200, 150 = 1800, etc.

Ensure that your list goes higher than the maximum possible value buy at least one value.

Step 3

StripLines.  If you don’t know what striplines are, they are basically horizontal lines drawn across your chart at a fixed Y value (I use these for showing targets, etc).  They have a number of properties such as width, colour, title, etc.  We are going to cheat and use these to add our additional values.

To access the striplines you need to click on the Y axis and then use the Properties window, note that striplines are not accessible via Right-clicking on the axis and selecting “Vertical Axis Properties”.

If you can’t see StripLines in the properties ensure you’re in the Chart Axis properties and not the Chart (or other section).

img 2

Click on the … next to the StripLines to open the ChartStripLine Collection Editor

The properties we are interested in are:

IntervalOffset, Title and TitleVerticalAlign

We need to add one StripLine for each value in our list we made earlier

  • IntervalOffset is the value on the Y axis where you want the StripLine to appear*.
  • Title is the equivalent value.
  • And TitleVerticalAlign just stops the Title going out of line with the value

*One thing you’ll notice is that I’ve subtracted one from the IntervalOffset value, if you don’t do this the top StripLine will not be shown, so in my chart at the top the 2400 would be missing.

img 3

As we haven’t set the Colour and thickness values for the StripLine it is invisible which is why you only see the values.

Could be a little long-winded if you had a lot of values, but worked for me!

Posted in Programming | Tagged , , , | Leave a comment

New Shop!

I have a new shop opened on Zazzle

Got lots of Computer Programming related designs, mugs, t-shirts, etc, plus items with some of my photography and some other random designs…

I will be adding a lot of new products over the next few weeks.

If you see any designs you like and would like to see them on different products, or have a specific design in mind that you can’t find, please send me an email via the Zazzle site.

Click here go to to shop!

Posted in Shopping | Tagged , , , , , | Leave a comment

Add child items to ToolStripMenuItem using C# – C Sharp

I wanted to be able to populate menu items from a database, i.e. I had a Print Document top level menu item and I wanted to be able to populate the children from the database dynamically with each available document.

The theory was this:

1. Use the MouseHover event for the main menu item
2. When the user hovers over the item, get the list of documents and add them as children
3. Add a Click event handler to process clicks on the children

Below is the MouseOver code (NB I’ve replaced the load from database code with three simple allocations to simplify the code). Notice that the property that holds the menu item children is DropDownItems.

private void MyToolStripMenuItem_MouseHover(object sender, EventArgs e)
{
    //create tsParent using sender
    ToolStripMenuItem tsParent = (ToolStripMenuItem)sender;
    

    //check to see if the children have already been created 
    //(stops them being added repeatedly if you hover more than once)

    if (tsParent.DropDownItems.Count == 0)
    {
        //define new ToolStripMenuItem to use as the new child
        ToolStripMenuItem newChild;

        //in the real case this is a loop adding items from a database
        //notice the Click event handler added to each item detailed below
        newChild= new ToolStripMenuItem();
        newChild.Text = "Added Item One";
        newChild.Tag = 1;
        newChild.Click += new EventHandler(processMeunItem);
        //add the new child to the parent DropDownItems collection
        tsParent.DropDownItems.Add(newChild);

        newChild= new ToolStripMenuItem();
        newChild.Text = "Added Item 2";
        newChild.Tag = 2;
        newChild.Click += new EventHandler(processMeunItem);
        tsParent.DropDownItems.Add(newChild);

        newChild= new ToolStripMenuItem();
        newChild.Text = "Added Item 3";
        newChild.Tag = 3;
        newChild.Click += new EventHandler(processMeunItem);
        tsParent.DropDownItems.Add(newChild);
    }
}

The code above will add three children to the menu item when you hover over it. Now we need to do something when a child is clicked:

//code runs when any of the new children are clicked
private void processMeunItem(object sender, EventArgs e)
{
    //Get the tag of the selected menu item and assign to integer selectedMenuTag
    int selectedMenuTag = Convert.ToInt32(((ToolStripMenuItem)sender).Tag);

    //do something with the selected item...
}

This will allocate the Tag of the clicked item to selectedMenuTag, you can then use it for further processing.

Posted in Programming | Tagged , , , , , , | Leave a comment

Shuffle an Array in C#

As part of a basic guessing game I wanted to be able to shuffle an array of n chars into a random order.

The method I decided to use was the following.

Create a loop to iterate n times (where n is the number of elements in the array). Randomly select one array element and add this to a new array. Replace the removed item with the last item in the array (effectively making the array one element smaller). This seemed easier than shifting all the elements along one to remove the gap (which was my first thought). The new array will hold the ‘shuffled’ items.

Pictorial example:

Shuffle Array

Shuffle Array

Here you can see each step (the selected item is shown in Red).

In code this translates to the following shuffle function:

private char[] shuffle(char[] charArray)
{
    char[] shuffledArray = new char[charArray.Length];
    int rndNo;

    Random rnd = new Random();
    for (int i = charArray.Length; i >= 1; i--)
    {
        rndNo = rnd.Next(1, i+1) - 1;
        shuffledArray[i - 1] = charArray[rndNo];
        charArray[rndNo] = charArray[i - 1];
    }
    return shuffledArray;
}

This can be called in the following way:

char[] list1 = { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M' };
char[] shuffled = shuffle((char[])list1.Clone()); 

Here the list1 array will be shuffled and returned to the shuffled array. Note that I pass a clone of the list1 array, this is because arrays are passed by reference and if I didn’t do this the list1 array would be altered which I didn’t want.

One other thing to note is that this would work for any kind of array, just by changing the array type.

I don’t know exactly how random this function is. However, I ran a loop shuffling 13 chars 1,000,000 times and had 42 duplicate outputs.

Posted in Programming | Tagged , , , , , | 3 Comments

Loading Data into a DataReader and Looping Through Records OLEDB / C#

Just a quick example of loading data into a data reader using C#. My data source is MS SQL Server in this case, although you would just need the correct OLEDB connection string to use any other data source.

//database connection string & SQL Statement to return SERVICE_LEVEL_ID and DEFINITION from a table called property.SERVICE_LEVEL
string dbConnectionString = @"Provider=SQLNCLI10;Server=(local)\SQLEXPRESS;Database=XXXXX;Uid=XXXXXX;Pwd=XXXXXXXXX;";
string dbSQL = "SELECT SERVICE_LEVEL_ID, DEFINITION FROM property.SERVICE_LEVEL"; 

//Create and open connection string
OleDbConnection dbConnection = new OleDbConnection(dbConnectionString);
dbConnection.Open();

//create a command object using the sql and the connection object
OleDbCommand dbCommand = new OleDbCommand(dbSQL, dbConnection);
dbCommand.CommandType = CommandType.Text;

//excute the command object and write the output to the datareader dr
OleDbDataReader dr = dbCommand.ExecuteReader();

//loop through all the records in the datareader
while (dr.Read())
{
    //write the DEFINITION field out to a message box
    MessageBox.Show(dr["DEFINITION"].ToString());
}

Couple of things to notice in this code are the While(dr.Read()) line. Not only does dr.Read() get the next record in the data reader, it also returns true if a record is returned or false if one isn’t. So it effectively checks for EOF (end of file) at the same time. Also the dr[“DEFINITION”].ToString() could be replaced with an index based call of dr.GetString(1). NB column indexes start at 0

Posted in Programming | Tagged , , , , , | Leave a comment