Net Code Monkey
Code for the primates

Alex Is Born!!

August 4, 2007 01:13 by jmcneely

Alexander Bryant McNeely has been born!! 2 months early and kicking.

3 lbs 3 ounces

17" long

2:41 pm Aug 3rd, 2007

 

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Tags:
Categories:
Actions: E-mail | Permalink | Comments (1) | Comment RSSRSS comment feed

Winfrom Databinding

July 30, 2007 03:28 by jmcneely

    I have been wondering how to correctly handle databinding in .Net 2.0 or using WPF and .Net 3.5.   I want to work with good OO code.  That is almost impossible to do using ADO.Net.  I have tried to use MS's wizards to create data access, and I have seen what maintaining that code feels like after a few iterations.  Bad, Bad Juju!!  So what to do?  how is the best way to handle good databinding between objects?

    Enter MS Object Datasource.  I found this unusable when 2.0 first came out.  I spent a few days playing with it, and I couldn't get it to work correctly.  It also didn't help that the existing code base was fighting me so much(see previous article).  I have reciently revisited the Object Data Source reciently, and I have found it suitable, but i have some questions about how to make this work in WPF, and if WPF is the right way to go designing a new app because of WPF's lack of a datagridview.  In 3.5 WPF just has a grid control out of the box.  I will be playing with it this week to see how it works.

     So here is the basic setup.  First create your objects that will be bound.  Lets say you have a customer support program.  You have Customers, Items(that belong to customers) of different types(Computers, Fax Machines, Printers), Tickets that belong to customers and relate to Items, Etc.  Each of these become Classes in good OOP structure.  So in .Net how do you get Data Binding to work?  Properties, lots and lots of properties.  Seems easier in .Net 3.5 with simple properties being automatic.  Once you have your properties setup, build your solution, and use the Wizard to link up your object to your form.  Seems simple enough, for simple examples.  There are a few tricks still.  You need to setup events for each property for when the value changes, so your form can refresh what it is displaying.  This of course depends on whether you want the object to control when the data changes, or the form. 

 

Easy, right?  I think it could be easier, but this is only half the problem. 

 

Next post, I will talk about how to fill your objects with data.

 

 


Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Tags:
Categories:
Actions: E-mail | Permalink | Comments (0) | Comment RSSRSS comment feed

Time for a change

July 22, 2007 10:31 by jmcneely

I am currently trying to decide how to tackle a very large project at work.  I am in charge of a large program that while it currently works, I don't feel that it handles the user’s needs well enough.  It is a large single form VB.Net project that is written very functionally.  It doesn't have any real OO structure at all.  I have worked with it for two years, and I have finally had it.  I decided that I cannot band aid this program anymore and it is time for a rewrite.  Now here is the question.  I am looking at .Net 3.5 and WPF, Is it worth waiting for VS 2008 before I rewrite the program.  Also is it worth staying with VB?  How should I handle the CRUD aspects of my program?  I have to use the existing database because it is used for other programs read only of course(not my idea  Smile).  So what to do?  Well let me tell you what I figured was my best solution:

 

Jay's Solution to Rewriting a large program:

 

    1.  Users: As I said I don't think the current program handles the users as well as it should.  So I am going to meet with the main users next week to talk about what is good/bad about the existing program, and discuss what the current program doesn’t' do that it should.  Of course documentation at this point is Key!

 

    2. When to start:  Well there is no time like the present.  Right now I am in the middle of a major cycle, so my time is limited, but I think this project is important enough to add to the stack.  I do think that WPF is worth using because of the style it adds to existing programs, and I am hopeful that it will upgrade well to 3.5.  I do have issues installing .Net 3.0 onto client machines because of all of the problems I have heard from my friends who do IT support for other companies that use 3.0.

    Also as long as I use good OOP upgrades from this point shouldn't be that big of a deal.  I can just upgrade my UI, or my Business logic depending on what 3.5 offers. 

 

    3. VB or not to VB:  Other people in my organization have talked about making the move from VB to C#.  I learned .Net on C#, so I am all for it.  I think VB is a second class citizen in the .Net world.  All of the examples on the web are in C#.  C# gets all of the cool features well before VB.  Look at generics.  I think C# is the answer, and I can write my business logic in C# for now, and if we decide to stay in VB, then I can change as necessary.  It is better to ask forgiveness than permission.

 

    4.  DAL:    I hate writing CRUD.  Let me say that again.  I hate writing Crud.  I have found Object binding to be very useful for the UI.  I am going to play with something like subsonic or active record to see if I can speed up my CRUD development.  Otherwise code generation using Code Rush will have to be used to keep my sanity.  

 

So there you have it.  I am going to take the leap and start a few new projects.  I think the time has come to take the leap.  Now it is time to design!!

 

 

 


Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Tags:
Categories:
Actions: E-mail | Permalink | Comments (0) | Comment RSSRSS comment feed

Data Reader or Data View what is faster?

June 8, 2007 03:50 by jmcneely

So a coworker and I were arguing over what was better, having a dataadapter with a temporary dataset pushed to a dataview, or using a datareader.  I argued that a datareader is faster, and it seems i was wrong.  Here is my code, let me know if you find any mistakes:

 

 <code>

Imports System.Threading
Imports System.data.SqlClient

Public Class Form1
    Public ConString As String = "SomeConnectionString"
    Public SQLQuery As String = "Select Item1, Item2, Item3 from Stuff"

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim thread1 As New Thread(AddressOf RefreshDataReader)
        Dim thread2 As New Thread(AddressOf RefreshDataSet)
        thread2.Start()
        thread1.Start()
    End Sub


    Private Sub RefreshDataReader()

        If dgv1.InvokeRequired Then
            dgv1.BeginInvoke(New MethodInvoker(AddressOf RefreshDRInvoke))
        Else
            RefreshDRInvoke()
        End If


    End Sub

    Private Sub RefreshDRInvoke()

        Dim sqlcon As New SqlConnection(ConString)
        sqlcon.Open()
        Dim sqlcom As New SqlCommand(SQLQuery, sqlcon)
        Dim dr As SqlDataReader
        dr = sqlcom.ExecuteReader()
        dgv1.Columns.Clear()
        dgv1.Columns.Add("Item1", "Item1")
        dgv1.Columns.Add("Item2", "Item2")
        dgv1.Columns.Add("Item3", "Item3")
        While dr.Read
            dgv1.Rows.Add(New Object() {dr("Item1"), dr("Item2"), dr("Item3")})
        End While
        dr.Close()
        sqlcon.Close()
        dgv1.Refresh()

        MessageBox.Show("DataReader : " & Now.ToString)
    End Sub

    Private Sub RefreshDataSet()

        If dgv2.InvokeRequired Then
            dgv2.BeginInvoke(New MethodInvoker(AddressOf RefreshDSInvoke))
        Else
            RefreshDSInvoke()
        End If
      

    End Sub
    Private Sub RefreshDSInvoke()

        dgv2.DataSource = TestDAL.GETDATA(ConString, SQLQuery)
        dgv2.Refresh()

        MessageBox.Show("Data Set : " & Now.ToString)
    End Sub
End Class

 


Public Class TestDAL
    Public Shared Function GETDATA(ByVal constring As String, ByVal sqlquery As String) As DataView
        Dim DV As New DataView
        Dim ds As New DataSet
        Dim sqlcon As New SqlConnection(constring)
        sqlcon.Open()
        Dim sqlcom As New SqlCommand(sqlquery, sqlcon)
        Dim da As New SqlDataAdapter(sqlcom)
        da.Fill(ds)
        DV = ds.Tables(0).DefaultView
        Return DV
    End Function
End Class

</code> 

 

The results suprised me.  Grabing 4000 records the dataadapter and the datareader both worked about the same, but every so often the dataadapter won.  Let me know what you think.

-Jay 


Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Tags:
Categories:
Actions: E-mail | Permalink | Comments (3) | Comment RSSRSS comment feed

Welcome

June 6, 2007 13:08 by jmcneely

Hello,

Welcome to my new blog.  I will be posting daily code items that i find interesting.  Also i will be including items on my journey between the worlds of MS ( my vb and C# coding) and Linux (asterisk, ruby on rails, and other items)  Thanks for coming to my site, and let the show begin!

 

For more personal stuff ( hi mom!) check out the personal section for family and friends.


Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Tags:
Categories: BlogEngine.NET
Actions: E-mail | Permalink | Comments (0) | Comment RSSRSS comment feed

Ruby On Rails

June 6, 2007 13:03 by jmcneely

I am currently playing with Ruby On Rails using an Ubuntu box.  I have to say the tutorials out there for getting rails setup are very easy.  Here are some that I used to get my site setup: 

http://www.urbanpuddle.com/articles/2006/06/10/install-ruby-rails-on-ubuntu-dapper-drake 

http://wiki.rubyonrails.org/rails/pages/RailsOnUbuntu

I have to say, so far I am very impressed with the ruby and rails communities.  Now I just need a good IDE to work with. Smile


Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Tags:
Categories:
Actions: E-mail | Permalink | Comments (0) | Comment RSSRSS comment feed