Monday, December 30, 2013

Family, Friends and fellow Developers

Merry Christmas and Happy New Year.  Hope everyone is prosperous and joyful in the coming 2014 year. In 2013 we have have lost and gained Family and Friends.  God Bless everyone. 

Love is patient, love is kind. It does not envy, it does not boast, it is not proud. It does not dishonor others, it is not self-seeking, it is not easily angered (RBD comment - but can be), it keeps no record of wrongs. Love does not delight in evil but rejoices with the truth. It always protects, always trusts, always hopes, always perseveres.

Love never fails. But where there are prophecies, they will cease; where there are tongues, they will be stilled; where there is knowledge, it will pass away. 









Friday, December 20, 2013

ie8 textarea or textbox multiline cursor jumping

IE8 has a known bug (per connect.microsoft.com) where typing or pasting text into a TEXTAREA element will cause the textarea to scroll by itself. This is hugely annoying and shows up in many community sites, including Wikipedia. The repro is this:
  1. open the HTML below with IE8 (or use any long page on wikipedia which will exhibit the same problem until they fix it)
  2. size the browser full-screen
  3. paste a few pages of text into the TEXTAREA
  4. move the scrollbar to the middle position
  5. now type one character into the textarea
Expected: nothing happens Actual: scrolling happens on its own, and the insertion point ends up near the bottom of the textarea!
Below is repro HTML (can also see this live on the web here: http://en.wikipedia.org/w/index.php?title=Text_box&action=edit)
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" ><body>
 <div style="width: 80%">
   <textarea rows="20" cols="80" style="width:100%;" ></textarea>
 </div>
</body></html>
I know I can avoid this by forcing the website into IE7 compatibility mode, but what's the best other way to work around this bug while causing as few side-effects as possible?

THE ANSWER ----

I ended up wasting a lot of time trying to figure out the answer myself, so I figured I'd save others the trouble of answering. The trick is to use a very large value for the COLS attribute on the TEXTAREA element. Like this
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml" > 
<body> 
<div style="width: 80%"> 
<textarea rows="20" cols="5000" style="width:100%;" ></textarea> 
</div> 
</body> 
</html> 
I also saw a workaround online to use a non-percentage width and then a percentage max-width and min-width, but that was much less impactful than the other workaround above (courtesy of Ross) which seems to work on all browsers including IE6.
more details: After an hour investigating this, the problem seems to be caused by IE8's handling of a conflict between "COLS" attribute and "width" style on a textarea element. If the width CSS is wider than the default width (font width x cols), IE8 gets confused when you add text and scrolls the textarea. If, instead, the width CSS is smaller than the default width derived from the cols attribute, then all works OK.
The subtle dependence between cols and width is perhaps what makes the problem so tricky to repro, because the same exact page would break or not break depending on the ratio of cols to width. The HTML in the quesiton actually reproes the bug on a large browser window and doesn't repro on a small one!

Friday, December 13, 2013

HTML 4.01 Features Removed

Removed Elements

The following HTML 4.01 elements are removed from HTML5:
  • <acronym>
  • <applet>
  • <basefont>
  • <big>
  • <center>
  • <dir>
  • <font>
  • <frame>
  • <frameset>
  • <noframes>
  • <strike>
  • <tt>

New Cool site for Browser Compatibility

http://caniuse.com/

Hour of Code

http://code.org/  --- It is a history maker.

HTML5 --- Been using HTML since HTML and HTML 4.01 and decided to take training on www.w3schools.com

Looks like it will be a good course.


The HTML5 <!DOCTYPE>

In HTML5 there is only one <!doctype> declaration, and it is very simple:
<!DOCTYPE html>


Minimum HTML5 Document

Below is a simple HTML5 document, with the minimum of required tags:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Title of the document</title>
</head>

<body>
Content of the document......
</body>

</html>

Monday, December 09, 2013

Populate Drop Down List for ASP.NET Web Control

try
            {
                using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["connString"].ConnectionString))
                {
                    conn.Open();
                    using (SqlCommand cmd = new SqlCommand("Select *  FROM [tbl_data] ORDER BY main", conn))
                    {
                        cmd.CommandType = CommandType.Text;
                        using (SqlDataReader reader = cmd.ExecuteReader())
                        {
                            if (reader.HasRows)
                            {
                                while (reader.Read())
                                {
                                   NameAndCounty = reader["NameAndCounty"].ToString();
                                   Id = reader["Id"].ToString();
                                    ddlNameAndCounty.Items.Add(new ListItem(NameAndCounty, Id));                
                                }
                            }                          
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                return ex.Message.Trim();
            }

Thursday, December 05, 2013

SQL Server RAISERROR

RAISERROR('SQL Does not like the data',16,1)  Break down of the RAISERROR

For the most part, the same exception ranges apply: exception levels between 1 and 10 result in a warning, levels between 11 and 18 are considered normal user errors, and those above 18 are considered serious and can only be raised by members of the sysadmin fixed server role. User exceptions raised over level 20, just like those raised by SQL Server, cause the connection to break.

The state argument can be any value between 1 and 127, and has no effect on the behavior of the exception. It can be used to add additional coded information to be carried by the exception—but it’s probably just as easy to add that data to the error message itself in most cases. I generally use a value of 1 for state when raising custom exceptions.

Reference - http://dataeducation.com/blog/sql-servers-raiserror-function

Monday, December 02, 2013

Label -vs- Literal - Stack Trace

The main difference is that Literal controls just render out text, but Label controls surround it with<span> tags (Unless you use the AssociatedControlID property, in which case a Label control will render a <label> tag).
So, labels can be styled easier, but if you're just inserting text, literals are the way to go. Literal controls also have a handy property Mode which governs how the text is rendered. You can have it HTML-encoded, or rendered without any changes, or have any "unsupported markup-language elements" removed.
If you're not applying any styles (e.g. by using Label's CssClass property), it will be fine to replace Labelcontrols with Literal controls.

T-SQL WHERE statement for NULL Values

SELECT * FROM table WHERE Field IS NULL

Friday, November 08, 2013

Using HibernatingRhinosProfiler with Console Application


1) Add Reference to - C:\Program Files (x86)\EntityFramework.Profiler\HibernatingRhinos.Profiler.Appender.dll

2) Add to Main(string[] args

public static void Main(string[] args)
        {
            HibernatingRhinos.Profiler.Appender.EntityFramework.EntityFrameworkProfiler.Initialize();

Friday, November 01, 2013

VB.NET Arrays from comma delimited String

VB Code:
  1. 'creates an array from a string that is delimited by commas
  2. Dim strArray() as string
  3. strArray = split(strText,",")
  4.  
  5. 'turns an array into a string delimited by commas
  6. Dim strText as string
  7. strText = join(strArray,",")

Monday, October 07, 2013

SQL Random Number Generator

DECLARE @Random INT;
DECLARE @RandomChar CHAR(15);
DECLARE @Upper INT;
DECLARE @Lower INT

---- This will create a random number between 1 and 999
SET @Lower = 1 ---- The lowest random number
SET @Upper = 999 ---- The highest random number
SELECT @Random = ROUND(((@Upper - @Lower -1) * RAND() + @Lower), 0)
SET @RandomChar =  (SELECT CAST(@Random AS CHAR(3)))


SET @srvc_code = 'New_Code-' + @RandomChar

Tuesday, September 24, 2013

Tuesday, September 17, 2013

Windows 7 add shortcut to Active Directory

Create a short cut and point to -  %SystemRoot%\SYSTEM32\rundll32.exe dsquery,OpenQueryWindow

Monday, September 09, 2013

Entity Container Name Gotcha

Was coding today in an application I support currently (Very large)...

Lesson learned --- When working with .edmx (Entity Framework)

1) Always ensure the project for the entity framework is a reference in your current project you need to use the entities for.

2)  When using the "Using" statement create as follows:

'Note I shortcut contact with ctx

Using ctx As New nameOfEntity()  ' Here is the key to this lesson nameOfEntity is the "Entity Container Name" listed under the properties for the .edmx model.

Very important.    Remember this one.



Thursday, August 29, 2013

Deep Thoughts from Rob Roy

Next Time you are bounced, transferred or put on hold ask the individual, "Who do I send an invoice to the company for my time".

Accounts Payable.

Time, Rate, and Description Customer Service Consulting.


Thursday, August 22, 2013

Old Data Grid --- I cannot believe I am posting this old technology, but good to know and remember

The following is VB.NET I am currently on a contract programming both VB.NET and C# at the same time.  Does not make for a dull day.  However I had the code wrong with the following and wanted to be sure I blogged about the fix.

When calling the "SelectedIndexChange" Event on an old Data Grid be sure to declare a Int32
and by the way Int32 = Integer (Same thing).

Dim an index variable to hold the index as show below then get the DataKeys(index). Be sure
to convert to and Integer....

Protected Sub dg_Mygrid_SelectedIndexChanged(sender As Object, e As EventArgs)
        
        Dim index As Int32 = dg_Mygrid.SelectedIndex
        Dim intMy_ID As Int32

        intMy_ID = Convert.ToInt32(dg_Mygrid.DataKeys(index)) 
        FillForEditing(intMy_ID)

Wednesday, August 21, 2013

jQuery Hide and Show elements

$(document).ready(function () {
            if ($('#diagGroupBtnGroup').is(':visible'))
            {
                $('#divlbServices').hide();
            }
            else
            {
            $('#divlbServices').show();
            }
        });

Tuesday, August 20, 2013

LAWS OF PROJECT MANAGEMENT

1. No major project is ever installed on time, within budget, or
with the same staff that started it. Yours will not be the
first.
2. Projects progress quickly until they become 90% complete,
then they remain at 90% complete forever.
3. One advantage offuzzy project objectives is that they let
you avoid the embarrassment of estimating the
corresponding costs.
4. When things are going well, something will go wrong.
• When things just cannot get any worse, they will.
• When things appear to be going better, you have
overlooked something.
5. If project content is allowed to change freely, the rate of
change will exceed the rate of progress.
6. No system is ever completely debugged. Attempts to debug
a system inevitably introduce new bugs that are even harder
to find.
7. A carelessly planned project will take three times longer to
complete than expected; a carefully planned project will
take only twice as long.
8. Project teams detest progress reporting because it vividly
manifests their lack of progress.

Reference: Project Planning and Implementation - Jim Keogh

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.