Locations of visitors to this page
Onteora Software - February 2007

Onteora Software

Ken Tucker's Blog

About the author

Author Name is someone.
E-mail me Send mail

Recent posts

Recent comments

Disclaimer

The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

© Copyright 2008

Windows WorkFlow Loop

Windows WorkFlow Loop



Lets create a simple Windows Workflow that uses a loop to run some code 10 times. So first create a Visual Basic Squential Workflow Console Application. In the designer layout the workflow to look like this.



Double click on the codeActivity and add the following code


Public class Workflow1
    Inherits SequentialWorkflowActivity

    Public intLoop As Integer = 0

    Private Sub codeActivity1_ExecuteCode(ByVal sender As System.Object, ByVal e As System.EventArgs)
        intLoop += 1
        Console.WriteLine("Loop has run " & intLoop.ToString & " times")
    End Sub
End Class


When you open the Rule Condition Editor it is interesting to note the conditon needs to written in c# instead of VB


Once you run it your output should look something like this.

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Categories: WorkFlow
Posted by Ken Tucker on Wednesday, February 28, 2007 11:12 PM
Permalink | Comments (0) | Post RSSRSS comment feed

SQLCLR: Create a custom function

SQLCLR: Create a custom function



I store a persons full name in the name field of one my sql express database which I wanted to sort by the last name.  Well I could always try a query like this.

SELECT * FROM SPEAKERS ORDER BY SUBSTRING(NAME, PATINDEX('%  %', NAME), LEN(NAME) + 1 - PATINDEX('%  %', NAME))

Unfortuntely some of the names have a middle initial so this method was not fool proof.  This is where SQLCLR came to the rescue.  By creating a SQL Server Project you can create functions with VB.Net code.  So lets create a Sql Server Project and right click on the Project Name in the solution explorer.  Select Add-> User-Defined Function.    Once you add the code below you can use a query like this to sort by last name.

 

select * from Speakers order by dbo.LastWord(Name)

Imports System
Imports System.Data
Imports System.Data.SqlClient
Imports System.Data.SqlTypes
Imports Microsoft.SqlServer.Server

Partial Public Class UserDefinedFunctions
    <Microsoft.SqlServer.Server.SqlFunction()> _
    Public Shared Function LastWord(ByVal word As SqlString) As SqlString
        ' Add your code here
        Dim strWords() As String = word.ToString.Split(" "c)
        Return New SqlString(strWords(strWords.GetUpperBound(0)))
    End Function
End Class

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Categories: Sql
Posted by Ken Tucker on Monday, February 12, 2007 11:12 PM
Permalink | Comments (0) | Post RSSRSS comment feed

Draw an Icon in a DataGridViewButtonCell

Draw an Icon in a DataGridViewButtonCell



Here is a simple example on how to draw in a DataGridViewButtonCell. In this example an icon is displayed when button is pushed and the icon is made invisible when its pushed again. I am storing the if the button has been pressed in the cell's tag. I use the cellPainting event to draw the icon when needed.


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace CSButtonColumn
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            String strConn = "Server = .\\SqlExpress;Database = Pubs;Integrated Security = SSPI;";
            DataTable dt = new DataTable();
            SqlConnection conn = new SqlConnection(strConn);
            SqlDataAdapter da = new SqlDataAdapter("Select * from titles", conn);
            da.Fill(dt);
            dataGridView1.DataSource = dt;
            DataGridViewButtonColumn bc = new DataGridViewButtonColumn();
            bc.Tag = false;
            dataGridView1.Columns.Insert(0, bc);
        }

        private void dataGridView1_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
        {
            if (e.ColumnIndex == 0)
            {
                e.Value = "Repair";
                e.FormattingApplied = true;
            }
        }

        private void dataGridView1_CellPainting(object sender, DataGridViewCellPaintingEventArgs e)
        {
            if (e.ColumnIndex == 0 && e.RowIndex >= 0)
            {
                e.Paint(e.CellBounds, DataGridViewPaintParts.All);
                DataGridViewButtonCell bc = dataGridView1[0, e.RowIndex] as DataGridViewButtonCell;
                bool x;
                if (bc.Tag == null)
                {
                    x = false;
                }
                else
                {
                    x = (bool)bc.Tag;
                }
                if (x)
                {
                    Icon ico = new Icon("repair.ico");
                    e.Graphics.DrawIcon(ico, e.CellBounds.Left+3, e.CellBounds.Top+3 );
                }
                e.Handled = true;
            }
        }

        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.ColumnIndex == 0 && e.RowIndex >= 0)
            {
                DataGridViewButtonCell bc = dataGridView1[e.ColumnIndex, e.RowIndex] as DataGridViewButtonCell;
                if (bc.Tag == null)
                {
                    bc.Tag = true;
                }
                else
                {
                    bc.Tag = !(bool)bc.Tag;
                }
            }
        }
    }
}

 

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Categories: DataGridView | C#
Posted by Ken Tucker on Wednesday, February 07, 2007 11:12 PM
Permalink | Comments (0) | Post RSSRSS comment feed

I've been Tagged: Five Things You Might Not Know About Me

I've been Tagged: Five Things You Might Not Know About Me



I have been tagged by Shawn Weisfeld. Here are 5 things you might not know about me.



1) My son Ryan, brother Denis and I are all Eagle Scouts



2) I love to go camping. I have a lot of good memories backpacking upstate New York.



3) My current job is an assistant engineer onboard Sun Cruz's Surfside Princess



4) I have 4 dogs, 4 cats, and 3 birds as pets.



5) While working on ships I have visited England, Scottland, Ireland, Germany, Norway, Spain, Canada, Puerto Rico, UAE, and Bahrain.

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Categories: Archive
Posted by Ken Tucker on Tuesday, February 06, 2007 11:12 PM
Permalink | Comments (0) | Post RSSRSS comment feed