TF53010: Error converting data type bigint to int

Posted by Unknown On Tuesday, September 1, 2015 0 comments
Problem:

When you try to create or update a work item in Team Foundation Server, and you get the following error message

Exception Message: Error converting data type bigint to int. (type SqlException)
SQL Exception Class: 16
SQL Exception Number: 8114
SQL Exception Procedure: prc_iCounterGetNext
SQL Exception Line Number: 0
SQL Exception Server: testtfs
SQL Exception State: 2
SQL Error(s):

Solution
  1. Go to TFS Project Collection database (Tfs_DefaultCollection by default)
  2. Change value WIT_WorkItemWatermark in table tbl_counter to any integer value that is not exceed maxInt32.

C#: Is numeric

Posted by Unknown On Friday, July 31, 2015 0 comments
C# code

Regex.IsMatch(ddlCustomer.SelectedValue, @"^\d+$")


JavaScript: client side event on RadioButtonList

Posted by Unknown On Thursday, July 16, 2015 0 comments
ASP.NET Code

       <asp:RadioButtonList runat="server" ID="radReportType" onchange="displayReportType();" RepeatDirection="Horizontal">
           <asp:ListItem Text="Shipment" Value="Fruit" Selected="True">
           <asp:ListItem Text="Customer" Value="Vegetable">
           <asp:ListItem Text="Carrier" Value="Meat">
       </asp:RadioButtonList>

jQuery

   var radio = $("[id*=radFruits] input:checked");
   var value = radio.val();

JQuery: Get Selected Value from RadioButtonList

Posted by Unknown On Wednesday, July 15, 2015 0 comments
Asp.net Code

  <asp:RadioButtonList ID="radFruits" runat="server">
     <asp:ListItem Text="Mango" Value="1" />
     <asp:ListItem Text="Apple" Selected="True" Value="2" />
     <asp:ListItem Text="Banana" Value="3" />
     <asp:ListItem Text="Guava" Value="4" />
  </asp:RadioButtonList>

JQuery

   var radio = $("[id*=radFruits] input:checked");
   var value = radio.val();

C#: Get text between two strings

Posted by Unknown On Friday, July 10, 2015 0 comments
String between two Strings

string input = "Exemple of value between two string FirstString text I want to keep SecondString end of my string";
var match = Regex.Match(input, @"FirstString (.+?) SecondString ").Groups[1].Value;
All Number between two Strings

string input = "Exemple of value between two string FirstString 1234 I want to keep SecondString end of my string";
var match = Regex.Match(input, @"FirstString (\d*) SecondString ").Groups[1].Value;

Customize JQuery UI DatePicker: Add today button

Posted by Unknown On Friday, February 27, 2015 0 comments
NOTE: javascript code my run inside (function ($) { JavaScript }});

Problem: I want to customize the JQuery datepicker (in this case, I want to add "Today" button) with minimum effort and keep all the existing JQuery behavior.

Solution: write JQuery plugin

  1. Create afterShow event
  2. Create your own datepicker function, and call the JQuery UI datepicker function
  3. Create option that is exactly the same as JQuery Option

Create afterShow event


    $.datepicker._updateDatepicker_original = $.datepicker._updateDatepicker;
    $.datepicker._updateDatepicker = function (inst) {        
        $.datepicker._updateDatepicker_original(inst);
        var afterShow = this._get(inst, 'afterShow');
        if (afterShow)
            afterShow.apply((inst.input ? inst.input[0] : null));  // trigger custom callback
    }

Create datepicker function


   $.fn.MyDatePicker = function (optionObject) {
        var option = GetOption(optionObject);
        $(this).datepicker(
            {
                dateFormat: option.dateFormat,
                changeMonth: option.changeMonth,
                changeYear: option.changeYear,
                afterShow: function () {
                    if (option.showTodayButton) {
                        $("#ui-datepicker-div").append("<div><input type='button' id='butToday' value='Today' /></div>");
                        var textbox = $(this);
                        $("#butToday").click(function () {
                            textbox.val($.datepicker.formatDate(option.dateFormat, new Date()));
                            textbox.datepicker("hide");
                            textbox.blur();
                        });
                    }
                }
            }
        );

    };

copy options


    function default_options() {
        this.showTodayButton = false;
        this.dateFormat = "mm/dd/yy",
        this.changeYear = false,
        this.changeMonth = false
    } 

   function GetOption(option) {

        var opt = new default_options();
        if (option != null) {
            if (option.showTodayButton != null)
                opt.showTodayButton = option.showTodayButton;

            if (option.dateFormat != null)
                opt.dateFormat = option.dateFormat;

            if (option.changeMonth != null)
                opt.changeMonth = option.changeMonth;

            if (option.changeYear != null)
                opt.changeYear = option.changeYear;
        }
        return opt;
    }

----------------------------------------------------------

Complete Code


(function ($) {

    function default_options() {
        this.showTodayButton = false;
        this.dateFormat = "mm/dd/yy",
        this.changeYear = false,
        this.changeMonth = false
    }   

    function GetOption(option) {

        var opt = new default_options();
        if (option != null) {
            if (option.showTodayButton != null)
                opt.showTodayButton = option.showTodayButton;

            if (option.dateFormat != null)
                opt.dateFormat = option.dateFormat;

            if (option.changeMonth != null)
                opt.changeMonth = option.changeMonth;

            if (option.changeYear != null)
                opt.changeYear = option.changeYear;
        }
        return opt;
    }

    $.datepicker._updateDatepicker_original = $.datepicker._updateDatepicker;
    $.datepicker._updateDatepicker = function (inst) {        
        $.datepicker._updateDatepicker_original(inst);
        var afterShow = this._get(inst, 'afterShow');
        if (afterShow)
            afterShow.apply((inst.input ? inst.input[0] : null));  // trigger custom callback
    }

    $.fn.MyDatePicker = function (optionObject) {
        var option = GetOption(optionObject);
        $(this).datepicker(
            {
                dateFormat: option.dateFormat,
                changeMonth: option.changeMonth,
                changeYear: option.changeYear,
                afterShow: function () {
                    if (option.showTodayButton) {
                        $("#ui-datepicker-div").append("<div><input type='button' id='butToday' value='Today' /></div>");
                        var textbox = $(this);
                        $("#butToday").click(function () {
                            textbox.val($.datepicker.formatDate(option.dateFormat, new Date()));
                            textbox.datepicker("hide");
                            textbox.blur();
                        });
                    }
                }
            }
        );

    };
}(jQuery));


<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
    <link rel="stylesheet" href="//code.jquery.com/ui/1.11.3/themes/smoothness/jquery-ui.css">
    <script src="//code.jquery.com/jquery-1.10.2.js"></script>
    <script src="//code.jquery.com/ui/1.11.3/jquery-ui.js"></script>
    <script src="Scripts/MyDatePicker.js"></script>    

    <script type="text/javascript">

        $(function () {
            $("#dtpTest").MyDatePicker({                
                changeYear: true,
                changeMonth:true
            });            
        });

        $(function () {
            $("#dtpTest2").MyDatePicker({
                showTodayButton: true                
            });
        });

    </script>
</head>
<body>
    <input type="text" id="dtpTest" />    
    <input type="text" id="dtpTest2" />    
</body>
</html>

Fixed: PostBackUrl not working with OnClientClick

Posted by Unknown On Thursday, January 22, 2015 0 comments
Problem: I want to post data from login.aspx using postbackurl property in Asp.net Button. But I want to validate it first before sending data. But when I use postbackurl together with onclientclick function, It does nothing.

Solutions: Write JavaScript code instead of call JavaScript function.

ASP.NET Page
<asp:Button OnClientClick="if(!validateLogin()) return false;" 
     PostBackUrl="~/Account/authentication.aspx" Text="Sign in" runat="server" ID="butLogin" />

Asp.net POST Form Data to Another Page

Posted by Unknown On 0 comments
Problem: I have a login form written in Asp.net code. I want to post my username and password to authentication.aspx page to verify this user, but I cannot use action link in form because it is used by other button too.

Solutions: use postbackurl property in Asp.net Button.

ASP.NET Page
<asp:Button OnClientClick="if(!validateLogin()) return false;" 
     PostBackUrl="~/Account/authentication.aspx" Text="Sign in" runat="server" ID="butLogin" />

Note: if you want to validate the form before posting data, you need to do the same way ask I do. It won't work if you use:
OnClientClick="return validateLogin();"

C# Get only number from text string

Posted by Unknown On Monday, January 19, 2015 0 comments

Problem: I want to get only number from phone number Ex. 562-810-9631 or (562) 810 9631.

Solution: Use Regular expression

C#
var phoneNumber = Regex.Replace(phoneNumber, @"\D", String.Empty, RegexOptions.Compiled);

ASP.Net RadioButton and CheckBox css class render inside a Span Fixed

Posted by Unknown On Thursday, January 8, 2015 0 comments

Problem: when we add cssclass to asp.net checkbox control, it renders checkbox control in span tag. That not what we want.

Solution: call InputAttributes function

C#
protected override void OnPreRender(EventArgs e)
{
        if (!Page.IsPostBack)
        {
            chkMenuItem.InputAttributes.Add("class", "selectall");
        }
}

Fizz Buzz Programming Alogirthm

Posted by Unknown On Tuesday, January 6, 2015 0 comments
Surprisingly, I had been asked to implement this simple algorithm twice among my 3 interviews.

Problem:

  • Loop from 1 to 100
  • If value is divided by 3, print Fizz
  • If value is divided by 5, print Buzz
  • If value is divided by 3 & 5, print Fizz Buzz
  • Else print the value

Solution: This problem is designed to test how your code look like. Is it short and clean, not too many condition statement.

C#
        private static void FizzBuzz(int value)
        {
            string result;

            for (int i = 1; i <= value; i++)
            {
                result = null;
                if (i % 3 == 0)
                    result = "Fizz";

                if (i % 5 == 0)
                    result += "Buzz";

                Console.WriteLine(result ?? i.ToString());
            }            
        }

JavaScript Multiline Validation with Regular expression

Posted by Unknown On 0 comments

How to validate multiple line values using JavaScript and Regular Expression.
Problem: I want to validate if my textarea contains only number. But my textarea accepts multiple Number values separated by break line.
1234
6743
2934
2134

Solutions:

  1. Merge the value into single line of code by replacing the end of line character with empty string
  2. Check if the value is number using regular expression

JavaScript
function isNumber(value){
   var pattern = new RegExp("^[0-9]+$");
   value = value.replace(/\n/g,"");
   return pattern.test(value);
}

Client Size validation with ASP.NET CustomValidator

Posted by Unknown On Monday, January 5, 2015 0 comments

Using JavaScript to custom validate asp.net control.

.ASPX File & JavaScript
function ValidateAge(source, arguments){
    var pattern = new RegExp("^[0-9]{2}$");
    if (!pattern.test(arguments.Value)){
         source.errormessage ="Age must be numeric";
         arguments.IsValid = false;
    }else{
         arguments.IsValid = true;
    }
}

<asp:CustomValidator 
     id="valCustom" 
     ControlToValidate="txbAge"
     ClientValidationFunction="ValidateAge"
     OnServerValidate="ValidateAge"
     ErrorMessage="This can be set from code"
     ForeColor="red" 
     runat="server">
     ValidationGroup="valSave"
</asp:CustomValidator>

Javascript Custom Regular Expression Validation

Posted by Unknown On 0 comments
Following are example of JavaScript Validation Function and useful patterns.

JavaScript Function
function ClientValidate(str) {
    var pattern = new RegExp("^[a-zA-Z0-9]+$"); 
    return pattern.test(arguments.Value);
}
Any characters and number. No special characters.
var pattern = new RegExp("^[a-zA-Z0-9]+$");
Numeric number only
var pattern = new RegExp("^[0-9]+$");
Email Validataion
var pattern = new RegExp("^[A-Za-z0-9](([_\.\-]?[a-zA-Z0-9]+)*)@([A-Za-z0-9]+)(([\.\-]?[a-zA-Z0-9]+)*)\.([A-Za-z]{2,})$");
//ex. matinee.la@mymail.office
//ex. matinee.la@yahoo.com
Phone Number
var pattern = new RegExp("^(1\s*[-\/\.]?)?(\((\d{3})\)|(\d{3}))\s*[-\/\.]?\s*(\d{3})\s*[-\/\.]?\s*(\d{4})\s*(([xX]|[eE][xX][tT])\.?\s*(\d+))*$");