Brian's Blog

items I see across my tribes

SQL Server default Values for columns

February 08
by briancarter 8. February 2010 08:57

Running backend jobs, set the
CreatedBy to user_name()
CreatedOn to getdate()

Front-end – pass in CreatedBy

Categories: Development

C# data type Refresher with Financial Issue

February 07
by briancarter 7. February 2010 11:03

We all need a refresher on the basics.  I’ve covered data types before, but the hierarchy below sums it up in a clear diagram:

The C# type hierarchy.

 

At the leafs, the float vs Integral is clearly shown.  Integrals (Integer) are viewed as subset of the real numbers, they are numbers that can be written without a fractional or decimal component. For example, 65, 7, and −756 are integers; 1.6 and 1½ are not integers. The set of all integers is often denoted by a boldface Z.

The C# standard only lists double and float as floating points available (those being the C# shorthand for System.Double and System.Single), but strictly speaking the decimal type (shorthand for System.Decimal) is also a floating point type.

The decimal type is just another form of floating point number - but unlike float and double, the base used is 10.  Compared to floating-point types, the decimal type has more precision and a smaller range, which makes it appropriate for financial and monetary calculations.

image

 

Financial Issue Testing

Let’s review financial situations. Say we are using floats to track the money. 

123,456.78 + 123.45 = $123,580.2  --> should calculate to $123,580.23

What happen – float only can support 7 digits, so C# converted number to 123456.8 + 123.45 – since last digit is 5 or less – it rounded down.  If the number would of ended in a 6 or above – it would of rounded up.  Lost $0.03 – do this to many times in your shopping cart and it will add up.

Do you have financial reports for month/year end? 

float x1 = float.Parse("1234567890.12");  //1.234568E+9
x1.ToString();  //"1.234568E+09"

oops… off by over $110 bucks.  Use decimal type for financial fields.

 

Stress testing float – double - decimal

--------- Show limits of float  ----------------

123.4567
float = 123.4567, double = 123.4567, decimal = 123.4567

123.45678
float = 123.4568, double = 123.45678, decimal = 123.45678

--------- Show limits of double  ----------------

123.456789012345
float = 123.4568, double = 123.456789012345, decimal = 123.456789012345

123.4567890123456
float = 123.4568, double = 123.456789012346,
decimal = 123.4567890123456

--------- Show limits of decimal  ----------------

123.45678901234567890123456789
float = 123.4568, double = 123.456789012346, decimal = 123.45678901234567890123456789

123.456789012345678901234567899
float = 123.4568, double = 123.456789012346, decimal = 123.45678901234567890123456790

Categories: Development

INSERT INTO for SQL 08

January 23
by briancarter 23. January 2010 08:46

In SQL Server 2008, a new insert feature is available which will make inserting of values easier. 

How do you insert multiple rows in SQL with using only one SELECT statement:

 

SQL Server 2008 Method of Row Construction:
INSERT INTO MyTable (FirstCol, SecondCol)
VALUES ('First',1),
('Second',2),
('Third',3),
('Fourth',4),
('Fifth',5)

Previous method 1:
INSERT INTO MyTable (FirstCol, SecondCol)
VALUES ('First',1);
INSERT INTO MyTable (FirstCol, SecondCol)
VALUES ('Second',2);
INSERT INTO MyTable (FirstCol, SecondCol)
VALUES ('Third',3);
INSERT INTO MyTable (FirstCol, SecondCol)
VALUES ('Fourth',4);
INSERT INTO MyTable (FirstCol, SecondCol)
VALUES ('Fifth',5);
GO


Previous method 2:
INSERT INTO MyTable (FirstCol, SecondCol)
SELECT 'First' ,1
UNION ALL
SELECT 'Second' ,2
UNION ALL
SELECT 'Third' ,3
UNION ALL
SELECT 'Fourth' ,4
UNION ALL
SELECT 'Fifth' ,5
GO

Using SQL Server 2000, no problem.  Get a test db on SQL Server 2008 – do your updates – then use a tool to script out the inserts.  I use SSMS Tools Pack: http://www.ssmstoolspack.com/

Categories: Development

Refresher: SQL Server 2000 Limitations

January 20
by briancarter 20. January 2010 17:30

Limitations of SQL Server 2000

·         Varchar 8,000 characters

·         NVarchar 4,000 characters

·         Row max characters = 8,000 for all columns, NVarchar count for 2 each char

 

(This is not an issue with SQL 2005 & 2008 - limit is 2GB.)

 

Categories: Development

Adding jQuery to BE.N

January 17
by briancarter 17. January 2010 16:57

image

Getting into jQuery – it would be nice to have jQuery items on my blog site. 


In this post, I show how to add it along with some things to watch out for.

I tried adding the jQuery JS file reference to the admin section – settings page: “HTML head section” and “Tracking script” areas without success.  I then tried the site.master, in the themes directory, which would only load the script once per page.  The jQuery script likes to sit right above the </head> section.  

Update your site.master:  Add in jQuery.js.

image

 

The next issue – collisions with BE.N’s script.  Appears they both use $.  To resolve this, add: $j = jQuery.noConflict();  -> to all your jQuery scripts where you reference $.  Now user “j$” instead of “$”.  I know it’s a pain – but the value of BE.N out weights it.

 Below is an example showing how to user jQuery.  The code, get it here, shows calling events and calling a custom function (for left padding). 

jQuery Example

Associate click event and Creating jQuery functions


 

Thank You for listening.

jQuery_example_date.zip (616.00 bytes)

Categories:

jQuery 1.4

January 17
by briancarter 17. January 2010 12:25

image Just incase you missed it,
jQuery 1.4 was released with significant speed improvements, bug fixes and of API changes.

Follow along with the “14 days of jQuery”.  The site will release a new announcement of new features each day.

The news of the jQuery release hasn’t gone unnoticed.  Check out some of the links below. 

Stay tuned.  I’m working on a jQuery cheat sheet.

jQuery 1.4 Released: The 15 New Features you Must Know | Nettuts+ – jQuery 1.4 was recently released. This wasn’t simply a maintenance release as some had speculated; there are many new features, enhancements and performance improvements included in 1.4! This post covers the new features and …

Ajaxian » jQuery 1.4 is released – The incredibly popular jQuery library has released jQuery 1.4 on a new website that will celebrate 14 days of jQuery. There are a lot of new features, and as usual performance gains are showcased. Easy Setter Functions: For a while now, …

jQuery 1.4 Resources For Developers | W3Avenue – jQuery 1.4 include several changes and new additions to the framework. W3Avenue has compiled a list of resources for jQuery developers that will help you get up to speed with some of these new features and changes.

jQuery: » jQuery 1.4 Released – This is just a short post to say that jQuery 1.4 has just been released and all CatchMyFame plugins are compatible. All demos have been updated to use the new 1.4 version. If you encounter any issues, please let me know. […] …

jQuery 1.4 and Malformed JSON « Katz Got Your Tongue? – If you have server-side JSON that can’t be quickly fixed in the transition to jQuery 1.4, you can use the compatibility plugin, which tries to patch a number of small incompatibilities, or you can use this workaround: …

jQuery Snippets & jQuery 1.4: What’s your opinion? « John Sheehan … – jQuery 1.4 was released today and jQuery founder John Resig said in a webcast that 1.4.x would be shipping with Visual Studio 2010. The jQuery Snippets for VS 2010 project I released in December currently has support for jQuery 1.3.2. …

making games, making webs.: Jquery 1.4 – Another quality jquery release… jquery 1.4. Some very handy changes, my favourite probably being able to use functions to set values. In short, some of the changes are: setting values with functions; html5 form support …

jQuery 1.4 is released | Programming Blog – The incredibly popular jQuery library has released jQuery 1.4 on a new website that will celebrate 14 days of jQuery. There are a lot of new features, and as.

jQuery 1.4 performance improvements | The Bright Lines – Yesterday jQuery 1.4 was released. They celebrate it with a special website: jquery14.com. There are a lot new features, but what I definitely like is the performance that improves with every release. Here are a few graphics from that …

jQuery UI 1.7.2 not ready for jQuery 1.4? | SKFox – jQuery UI 1.7.2 not ready for jQuery 1.4? There seems to be a bug when you use them together.

JQuery 1.4 (JavaScript library) is now out – Twitter conversation – JQuery 1.4 (JavaScript library) is now out code.google.com and @khanali says it’s “just simply GREAT!” – Scobleizer (Robert Scoble) Twitter conversation.

JQuery 1.4, YUI: JSON ParseError – Quotes Required … – Someone just sent me a message asking me to update my imBannerRotater plugin because they were receiving a parseerrormessage with JQuery 1.4. I tested the.

Categories: Development

Writing is Thinking

January 11
by briancarter 11. January 2010 07:52

Blogging, tweets, journaling, writing and what it takes to make me effective.  Until I was into my doctoral studies, writing was something I did after thinking.  My thoughts were kept in my mental diary and pieces were delivered for whichever requirement I had to meet.  Call it a school project, work project, or something for family/friends.

Part of understanding comes from writing.  “Writing is thinking”.  I’ve found that writing is thinking; let go – forget punctuation and grammar – and just keep the pen, pencil, or keyboard moving.  Something worthwhile may surface and don’t throw out what is written – since I’ve been writing papers and blogging, the worthwhile items surface over time. 

At first, I would have a set time when I would write.  Now, my typical procedure is free-write; reflecting on an idea/thought as quickly as possible to keep the cognitive development flowing. 

So find a safe place to journal.  I like using my blog.  I have public pages and private pages which are searchable.  My public pages have increased my level of engagement with others and has made a difference in my learning.

Thank You for listening.

Categories: Tribes

Document inside C# Code

January 10
by briancarter 10. January 2010 17:55

I’ve tried; tried to keep documentation updated in a Word doc or in HTML content site.  It just takes too much time and doco is the last thing I update when in a time pinch (all the time).

So here is what I did on my last project.  Focused on keeping the API documentation in the code.  It was still too much typing.

I found a tool that will generate the headers for the XML comments.  Download and install Ghost Doc.  Select the class, enum, or method – press CTRL-SHIFT-D … the comments are generated.  It does a good job reading the code and adding in a good description along with parameters.

GhostDoc: http://submain.com/products/ghostdoc.aspx

Now that your code has commnets – how do you pull it all together into a nice website.  Website because docs will die on the vine and no one will have access. 

Get CodeDoc.  CodeDoc is a free, shared-source tool from Dwell.Net that helps you generate a documentation set for your C# class libraries. CodeDoc converts XML comments into documentation topics, and lets you add "overview" topics. The output from CodeDoc is browser-based documentation browser with a table of contents and index. The documentation browser works either online (on a Web site) or offline (on a hard disk).

CodeDoc: http://www.dwell.net/

There is an associated Console app that runs to generate a doc folder with all the pages.  You will need to update the CodeDoc.xml so the tool knows where to pull and push everything.  Overview.htm, Sourcefiles.htm, SourceOverview.htm required updating for display messages when on the first few pages.

Run the Console app:

codedoc C:\@Code\iESP.WebServices\iESP.Webservices.Web\CodeDoc.xml

image

Documentation is generated.  Minimum steps to keep your API documented.  Really helps when working with partners or 3rd parties that use your web services.  Saved me some time.

Categories: Development, Architecture

Using the web.config File

January 07
by briancarter 7. January 2010 06:29

The customErrors element of the web.config file is the last line of defense against an unhandled error. If you have other error handlers in place, like the Application_Error of Page_Error subs, these will get called first. Provided they don't do a Response.Redirect or a Server.ClearError, you should be brought to the page(s) defined in the web.config. In the web.config file, you can handle specific error codes (500, 404, etc), or you can use one page to handle all errors. This is a major difference between this method and the others (although you can emulate this by doing various Response.Redirects using the other methods). Open up your web.config file. The customErrors section uses this format:

<customErrors defaultRedirect="url" mode="On|Off|RemoteOnly">
   <error statusCode="statuscode" redirect="url"/>
</customErrors>
Here is some important information about the "mode" attribute:

"On" specifies that custom errors are enabled. If no defaultRedirect is specified, users see a generic error.

"Off" specifies that custom errors are disabled. This allows display of detailed errors.

"RemoteOnly" specifies that custom errors are shown only to remote clients, and ASP.NET errors are shown to the local host. This is the default.

By default, the section looks like this when you create a Web application.

<customErrors mode="RemoteOnly" />
This will show a generic page to users. To redirect it to one of your own pages, you would change it to this:
<customErrors mode="On" defaultRedirect="error.aspx" />

Now all errors that occur will be brought to the error.aspx page. 

To handle specific errors, and redirect to the error page for everything else you can specify the error code you want specially handled like so:

<customErrors mode="On" defaultRedirect="error.aspx">
    <error statusCode="500" redirect="error500.aspx?code=500"/>
    <error statusCode="404" redirect="filenotfound.aspx"/>
    <error statusCode="403" redirect="authorizationfailed.aspx"/>
</customErrors> 
There is a problem here with this solution. Once the redirect is done, your error information is no longer available on the redirected page. This is because IIS (via the .net framework) performs a plain old GET request to the error page and does not do a "Server.Transfer" like the built-in IIS error handling does.

The only information available to you at this time is the URL that caused this error to be raised. This is located on the querystring as "aspxerrorpath": http://localhost/ErrorHandling/error500.aspx?aspxerrorpath=/ErrorHandling/WebForm1.aspx. The only places this information is available is the two methods described above.

Another important part of all deployments.

Categories: Development

What Matters Now

December 14
by briancarter 14. December 2009 08:40

Newauthors

With a new year approaching, it’s good to reflect and get motivated.  Do you need some words of advice, some items that will help you focus, and some energy to turn things around? 

Seth along with 70 big thinkers have shared their ideas in a free ebook to help you head into the new year.  It’s free, download it here and visit Seth’s write-up here.  Need some fresh reading for the holidays, Here’s a lens with all the links to books by the authors.

Happy Holidays.

[local copy of “What Matters Now”]  

Categories: Tribes


 Questions or Feedback, my contact information is located on my About page.


The opinions, thoughts, and comments made in these blog posts are solely my own (unless otherwise stated). They do not reflect the opinions, thoughts or practices of my employer, my universities, my family, or anyone else. Also, I retain the right to change my mind about anything I publish here without having to go back and edit posts that occurred in the past. 

These are my opinions, or just as likely, someone else's opinions that I leveraged for my own.