Monday, August 19, 2013

VB.NET Query to get data when Key ID is Null aka Nothing (vb.net)

Dim Query = From x In ctx.tbl_funding_capitation _ Order By x.start_dt Descending _ Select New With { _ .providerID = If((x.my_id IsNot Nothing), x.tbl_data.DATA_ID, Nothing),
 _ .provider = If((x.my_id IsNot Nothing), x.tbl_data.DATA_NAME, "")
, _ .active = x.active
 }

Thursday, August 15, 2013

What do Sender and EventArgs mean?

The sender is the control that the action is for (say OnClick, it's the button). The EventArgs are arguments that the implementor of this event may find useful. With OnClick it contains nothing good, but in some events, like say in a GridView 'SelectedIndexChanged', it will contain the new index, or some other useful data.

Programmer Productivity By Jonathan Erickson, September 26, 2009

Multitasking is good when it comes to computer programs, letting them do more with less. But when computer programmers start multitasking, productivity flies out the door.

For one thing, when programmers have to shift tasks, it takes "a really, really, really long time," says Joel Spolsky, host of the Joel On Software Web site and co-founder of Fog Creek Software. Programmers have to keep a lot of things in their heads at once, Spolsky says, and the more they remember, the more productive they are. "A programmer coding at full throttle is keeping zillions of things in their head at once," he says, "everything from names of variables, data structures, important APIs, the names of utility functions that they call a lot, even the name of the sub-directory where they store their source code."

On top of that, as applications have become more collaborative, complex, modular, and distributed, developers are having to track an increasing number of tasks and deal with more interruptions from the people with whom they're collaborating. As a result, they're multitasking more frequently and becoming less productive.

How bad is the problem? Developers spend an average of 11 minutes on one task before being interrupted to deal with another, according to Gloria Mark of the University of California at Irvine's Department of Informatics, who has spent years examining developers' work environments. It then takes them 25 minutes to return to the original task.

Keeping programmers productive in these fragmented work environments is a challenge for large software developers as well as for IT shops developing for end users. In both cases, application life-cycle management tools and processes can help. They automate steps -- such as change management, build processes, and testing -- in the development process, off-loading work from developers and cutting back on the number of interruptions they face.

Tuesday, August 13, 2013

DB Property Create --- By Rob McCrady

If you want to quickly generate a property list for a VB class from the list of columns on a DB table, this script is a way to do that quickly without a lot of typing.

Just set the value of @tablename to the name of the table you’re scripting and run the script.  Copy and Paste the resultset directly into yoru .vb file.

Note:  In this script I’m converting only varchar, int, bit, and the datetime db types into vb types.  If your table has other db types, you’ll want to add those to the CASE statement.

declare @tableName varchar(50)
set @tableName = 'tblSlotMgmt'

select
 'Public Property ' + propName + ' as ' + type
from (
select c.name as propName
, t.name
, Case t.name
      WHEN 'int' then 'integer'
      WHEN 'varchar' then 'string'
      WHEN 'datetime' then 'datetime'
      when 'smalldatetime' then 'datetime'
      when 'bit' then 'boolean'    
      else ''
  end as type
, ColOrder
FROM sysobjects o
inner join syscolumns c on c.id = o.id
inner join systypes t on c.xtype = t.xtype
where o.name = @tableName
and t.uid = 4
) d

order by ColOrder

Bound Columns -- "DataFormatString"

Important back pocket tool to have for formatting bound fields...

Reference MSDN --- http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.boundfield.dataformatstring.aspx

NoteNote
In most cases, formatting depends on the server's culture setting. The examples are for a culture setting of en-US.
Format character
Description
Example
C or c
Displays numeric values in currency format. You can specify the number of decimal places.
Format: {0:C}
123.456 -> $123.46
Format: {0:C3}
123.456 -> $123.456
D or d
Displays integer values in decimal format. You can specify the number of digits. (Although the type is referred to as "decimal", the numbers are formatted as integers.)
Format: {0:D}
1234 -> 1234
Format: {0:D6}
1234 -> 001234
E or e
Displays numeric values in scientific (exponential) format. You can specify the number of decimal places.
Format: {0:E}
1052.0329112756 -> 1.052033E+003
Format: {0:E2}
-1052.0329112756 -> -1.05e+003
F or f
Displays numeric values in fixed format. You can specify the number of decimal places.
Format: {0:F}
1234.567 -> 1234.57
Format: {0:F3}
1234.567 -> 1234.567
G or g
Displays numeric values in general format (the most compact of either fixed-point or scientific notation). You can specify the number of significant digits.
Format: {0:G}
-123.456 -> -123.456
Format: {0:G2}
-123.456 -> -120
N or n
Displays numeric values in number format (including group separators and optional negative sign). You can specify the number of decimal places.
Format: {0:N}
1234.567 -> 1,234.57
Format: {0:N4}
1234.567 -> 1,234.5670
P or p
Displays numeric values in percent format. You can specify the number of decimal places. (NOTE TO SELF --- System will perform calculation (n * 100) just provide the number.

In other words (n1 \ n2 = n3)  n3 *100 will be handled by the Format {0:P}   Note alos {0:P0} will not produce decimals values.
Format: {0:P}
1 -> 100.00%
Format: {0:P1}
.5 -> 50.0%
R or r
Displays SingleDouble, or BigInteger values in round-trip format.
Format: {0:R}
123456789.12345678 -> 123456789.12345678
X or x
Displays integer values in hexadecimal format. You can specify the number of digits.
Format: {0:X}
255 -> FF
Format: {0:x4}
255 -> 00ff

Friday, August 02, 2013

T-SQL IF Exists Table Drop and Add - SQL Server

IF EXISTS(SELECT * FROM dbo.sysobjects WHERE ID = OBJECT_ID('[dbo].[tbl_staging_services_to_summary]'))
 BEGIN
  --PRINT 'tbl_staging_services'
  DROP TABLE [dbo].[tbl_staging_services_to_summary]
  PRINT 'Table Dropped and Recreated'
 END
ELSE
 BEGIN
 PRINT 'No Table Existed - Created Completed'
 END

Thursday, August 01, 2013

Great Quote I heard today from a co-worker

Life is too short to get uptight over stuff. Not going to help a bit to do otherwise. God’s got the stuff I can’t control. If I can control it, I work on it & do my best. If I can’t, God will take care of it in his way. If someone else has control of it – no point in working myself up over it – just try to lend a helping hand.


Janet Alexander

Tuesday, July 30, 2013

SQL Server - T-SQL for setting Date

DECLARE @DayOfMonth TINYINT SET @DayOfMonth = 31
DECLARE @Month TINYINT SET @Month = 3
DECLARE @Year INTEGER SET @Year = YEAR(GETDATE()) + 1
DECLARE @NextWaiverYear AS DATETIME2


 ------------------------------------
SET @NextWaiverYear = (Select DateAdd(day, @DayOfMonth - 1,
          DateAdd(month, @Month - 1,
              DateAdd(Year, @Year-1900, 0))))

SELECT DISTINCT TblSlotWaiverYear.WaiverYrID, TblSlotWaiverYear.Description AS SlotWaiverYearDescription
FROM            TblSlotWaiverYear WHERE EndDt <= @NextWaiverYear

Monday, July 29, 2013

GET and SET - 101 Knowledge - Source - http://msdn.microsoft.com/en-us/library/w86s7x04.aspx

Using Properties (C# Programming Guide)

Visual Studio 2012
11 out of 15 rated this helpful Rate this topic
Properties combine aspects of both fields and methods. To the user of an object, a property appears to be a field, accessing the property requires the same syntax. To the implementer of a class, a property is one or two code blocks, representing a get accessor and/or a set accessor. The code block for the get accessor is executed when the property is read; the code block for the set accessor is executed when the property is assigned a new value. A property without a set accessor is considered read-only. A property without a get accessor is considered write-only. A property that has both accessors is read-write.
Unlike fields, properties are not classified as variables. Therefore, you cannot pass a property as a ref (C# Reference) or out (C# Reference) parameter.
Properties have many uses: they can validate data before allowing a change; they can transparently expose data on a class where that data is actually retrieved from some other source, such as a database; they can take an action when data is changed, such as raising an event, or changing the value of other fields.

Thursday, July 18, 2013

TFS Check Pending files

C:\Program Files (x86)\Microsoft Visual Studio 11.0>tf status /user:Domain\UserAccount /XXXXXXXXXXX;:Domain\UserAccount /collection:"http://XXXXX:808
0/tfs/MyProject
There are no pending changes. (If not files are checked out...


How do you get a co-workers workspace you ask?


Next -



DOS or CMD paging content

Type you command and add

More

10 out of 13 rated this helpful Rate this topic
Displays one screen of output at a time.

Syntax

command | more [/c] [/p] [/s] [/tn] [+n]
more [[/c] [/p] [/s] [/tn] [+n]] < [Drive:] [PathFileName
more [/c] [/p] [/s] [/tn] [+n] [files]

Parameters

[ Drive : ] [ Path FileName   Specifies the file to display.
command   Specifies a command for which you want to display the output.
/c   Clears screen before displaying page.
/p   Expands form-feed characters.
/s   Changes multiple blank lines to one blank line.
/t n   Changes tabs to the number of spaces specified by n.
+ n   Displays first file beginning at the line specified by n.
files   Specifies list of files to display. Separate file names with a space.
/?   Displays help at the command prompt.

Wednesday, July 17, 2013

Link Button Post back

The PostBackUrl property allows you to perform a cross-page post using the LinkButton control. Set the PostBackUrl property to the URL of the Web page to post to when the LinkButton control is clicked. For example, specifying Page2.aspx causes the page that contains the LinkButton control to post to Page2.aspx. If you do not specify a value for the PostBackUrl property, the page posts back to itself. (Who would have known)

Moojjoo

Monday, July 15, 2013

Debugging Console application

When you debug the application, the console window will close when
the application has finished executing, which may prevent you from
inspecting the output. You can put a breakpoint at the end of the method
for debugging. Alternatively, you can run without debugging (CTRL +
F5), in which case Visual Studio will ensure that the console window
remains open after the program has finished executing.

Reference - Programming Eneity Framework: DbContext Page 17

Reading - Programming Entity Framework: DbContext - Quote from Julie Lerman

The LINQ query looks the same as any other query that filters based on name. We then
use the Singlemethod to let Entity Framework know that we expect a single result. If
the query returns no results, or more than one result, an exception will be thrown. If
there are potentially no matches, you can use the SingleOrDefault method, which will
return  null if  no  results  are  found.  Example  2-16 shows  the  FindGreatBarrierReef
method updated to account for the fact it may not exist in the database.

If two rows are found,  Singleand  SingleOrDefault will throw an error because there is not a
single result. If you just want the first result, and aren’t concerned if there is more than
one result, you can use Firstor FirstOrDefault.

Coding 101

All code needs an event that will result in causing the code to work aka (Function/Method).  This could be a button click or the page load but always be sure to understand that your code has to have a behavior to fire your code.

It all starts with the process that puts something in motion.   If nothing can trigger, fire, or cause the the code to process then you cannot find the debug issue or even add functionality.

My 2 cents for the day.

Monday, July 08, 2013

Inserting Entities

In the YELLOW is KEY

'Insert Entity and Database
            Using Context As New qmEntities()
                Dim myServiceDefinition = New tbl_service_definitions()
                myServiceDefinition.srvc_def_desc = txtSrvDefDesc.Text.Trim()
                myServiceDefinition.eff_dt = txtsrvEffDt.SelectedDate
                myServiceDefinition.end_dt = txtsrvEndDt.SelectedDate
                myServiceDefinition.update_dt = DateTime.Now
                myServiceDefinition.update_by_id = SecurityMethods.GetLoginUserId(Session("AuthUser"))
                myServiceDefinition.create_dt = DateTime.Now
                myServiceDefinition.created_by_id = SecurityMethods.GetLoginUserId(Session("AuthUser"))
                myServiceDefinition.active = True
                Context.tbl_service_definitions.Add(myServiceDefinition)
                Context.SaveChanges()
            End Using

Friday, June 28, 2013

LINQ VB.NET CODE SNIPPET

Private Sub FillServiceCategory()
        cmbSrvCat.DataValueField = "SRVC_SUM_ID"
        cmbSrvCat.DataTextField = "SRVC_SUM_DESC"
 
        cmbSrvCat.DataSource = db.tbl_Service_Summary.OrderBy(Function(x) x.SRVC_SUM_DESC).ToList()
 
        cmbSrvCat.DataBind()
 
        cmbSrvCat.Items.Insert(0, New RadComboBoxItem(""))
    End Sub

Thursday, June 13, 2013

Mikes cheat sheet - http://www.mikesdotnetting.com/Article/46/CSharp-Regular-Expressions-Cheat-Sheet

C# Regular Expressions Cheat Sheet


Cheat sheet for C# regular expressions metacharacters, operators, quantifiers etc

Character
Description
\
Marks the next character as either a special character or escapes a literal. For example, "n" matches the character "n". "\n" matches a newline character. The sequence "\\" matches "\" and "\(" matches "(".
Note: double quotes may be escaped by doubling them: "<a href=""...>"
^Depending on whether the MultiLine option is set, matches the position before the first character in a line, or the first character in the string.
$Depending on whether the MultiLine option is set, matches the position after the last character in a line, or the last character in the string.
*Matches the preceding character zero or more times. For example, "zo*" matches either "z" or "zoo".
+Matches the preceding character one or more times. For example, "zo+" matches "zoo" but not "z".
?Matches the preceding character zero or one time. For example, "a?ve?" matches the "ve" in "never".
.Matches any single character except a newline character.
(pattern)Matches pattern and remembers the match. The matched substring can be retrieved from the resulting Matchescollection, using Item [0]...[n]. To match parentheses characters ( ), use "\(" or "\)".
(?<name>pattern)Matches pattern and gives the match a name.
(?:pattern)A non-capturing group
(?=...)A positive lookahead
(?!...)A negative lookahead
(?<=...)A positive lookbehind .
(?<!...)A negative lookbehind .
x|yMatches either x or y. For example, "z|wood" matches "z" or "wood". "(z|w)oo" matches "zoo" or "wood".
{n}n is a non-negative integer. Matches exactly n times. For example, "o{2}" does not match the "o" in "Bob," but matches the first two o's in "foooood".
{n,}n is a non-negative integer. Matches at least n times. For example, "o{2,}" does not match the "o" in "Bob" and matches all the o's in "foooood." "o{1,}" is equivalent to "o+". "o{0,}" is equivalent to "o*".
{n,m}m and n are non-negative integers. Matches at least n and at most m times. For example, "o{1,3}" matches the first three o's in "fooooood." "o{0,1}" is equivalent to "o?".
[xyz]A character set. Matches any one of the enclosed characters. For example, "[abc]" matches the "a" in "plain".
[^xyz]A negative character set. Matches any character not enclosed. For example, "[^abc]" matches the "p" in "plain".
[a-z]A range of characters. Matches any character in the specified range. For example, "[a-z]" matches any lowercase alphabetic character in the range "a" through "z".
[^m-z]A negative range characters. Matches any character not in the specified range. For example, "[m-z]" matches any character not in the range "m" through "z".
\bMatches a word boundary, that is, the position between a word and a space. For example, "er\b" matches the "er" in "never" but not the "er" in "verb".
\BMatches a non-word boundary. "ea*r\B" matches the "ear" in "never early".
\dMatches a digit character. Equivalent to [0-9].
\DMatches a non-digit character. Equivalent to [^0-9].
\fMatches a form-feed character.
\kA back-reference to a named group.
\nMatches a newline character.
\rMatches a carriage return character.
\sMatches any white space including space, tab, form-feed, etc. Equivalent to "[ \f\n\r\t\v]".
\SMatches any nonwhite space character. Equivalent to "[^ \f\n\r\t\v]".
\tMatches a tab character.
\vMatches a vertical tab character.
\wMatches any word character including underscore. Equivalent to "[A-Za-z0-9_]".
\WMatches any non-word character. Equivalent to "[^A-Za-z0-9_]".
\numMatches num, where num is a positive integer. A reference back to remembered matches. For example, "(.)\1" matches two consecutive identical characters.
\nMatches n, where n is an octal escape value. Octal escape values must be 1, 2, or 3 digits long. For example, "\11" and "\011" both match a tab character. "\0011" is the equivalent of "\001" & "1". Octal escape values must not exceed 256. If they do, only the first two digits comprise the expression. Allows ASCII codes to be used in regular expressions.
\xnMatches n, where n is a hexadecimal escape value. Hexadecimal escape values must be exactly two digits long. For example, "\x41" matches "A". "\x041" is equivalent to "\x04" & "1". Allows ASCII codes to be used in regular expressions.
\unMatches a Unicode character expressed in hexadecimal notation with exactly four numeric digits. "\u0200" matches a space character.
\AMatches the position before the first character in a string. Not affected by the MultiLine setting
\ZMatches the position after the last character of a string. Not affected by the MultiLine setting.
\GSpecifies that the matches must be consecutive, without any intervening non-matching characters.


GREAT TEST TOOL - http://myregextester.com/index.php

Saturday, June 01, 2013

Constructor Code Snippit

ctor + tab + tab

Auto Macro Code Snippet for CLASS constructor in Visual Studio

class Employee
 // Contructor
{
           public Employ()
           {
            // Default property for FirstName
            FirstName = ""  // Better than NULL which is the default


             }
}