Tuesday, October 22, 2013

Skip Non Business Days when Adding Days in Datetime in C#

public static DateTime AddWorkdays(DateTime originalDate, int workDays, bool transtype, bool daysSkip)
        {
            DateTime tmpDate = originalDate;
            if (transtype && !daysSkip) // Check Days Condition Checking for Saturdays and Sundays
            {
                while (workDays > 0)
                {
                    tmpDate = tmpDate.AddDays(1);
                    if (tmpDate.DayOfWeek < DayOfWeek.Saturday &&
                        tmpDate.DayOfWeek > DayOfWeek.Sunday)
                        workDays--;
                }
            }
            if (!transtype && daysSkip) // Card Days Condition Checking for only Sundays
            {
                while (workDays > 0)
                {
                    tmpDate = tmpDate.AddDays(1);
                    if (tmpDate.DayOfWeek > DayOfWeek.Sunday)
                        workDays--;
                }
            }
            if (!transtype && !daysSkip) // Card
            {
                tmpDate = AddWorkdays(tmpDate, workDays, false, true);
            }
            return tmpDate;
        }

Friday, September 20, 2013

Query to Find Column From All Tables of Database


SELECT t.name AS table_name,
SCHEMA_NAME(schema_id) AS schema_name,
c.name AS column_name
FROM sys.tables AS t
INNER JOIN sys.columns c ON t.OBJECT_ID = c.OBJECT_ID
WHERE c.name LIKE '%ColumnName%'
ORDER BY schema_name, table_name;

Tuesday, September 3, 2013

How to change the Change/Assign Dropdown/Radio Button Values in Jquery Mobile




Method #1 ( DropDown )

var countrySetValue = $("#deliveryMethod");
$('#deliveryMethod').val('-1');
countrySetValue.selectmenu("refresh", true);

Method #2 ( DropDown )

$("#deliveryMethod").selectmenu("refresh", true);


Method #1 ( Radio Button )


$('input[name=PaymentType]').removeAttr('checked').checkboxradio("refresh");

Saturday, April 27, 2013

How to execute Sql Script using Command prompt




E:\>sqlcmd -ddbname –S.\SqlExpress -Usa -PWelcome123 -iScript.sql

The above command script for Sql Server login authentication

1    1)      You have to copy the Sql Script file to any drive. Here I have used E drive.
2    2)      In the command prompt you have to select the drive where you have copied the script file.
3    3)      Before execute the script you have to create the new database.  Here I have created dbname as Database name.
4    4)      dbname  is the Database name.
5    5)      .\SqlExpress  is the Sql server instance name.
6    6)      sa is the username of the Sql Server.
7    7)      Welcome123 is the password of the Sql Server.
8    8)      Script.sql is the Script file.

Monday, April 8, 2013

Jquery Inline form validation how to disable submit button

jQuery("#formname").validationEngine('attach', {
            onValidationComplete: function (form, status) {
                if (status == true) {
                    $('#Btname').attr('disabled', true);
                    return true;
                }
            }
        });

jQuery("#formname").validationEngine('attach', {
                onValidationComplete: function (form, status) {
                    if (status == true) {
                        $('#Btname').attr('disabled', true);
                        return true;
                    }
                }
            });

Monday, April 1, 2013

How to convert string to TitleCase



public static String TitleCaseString(String s)
{
   if (s == null) return s;
   String[] words = s.Split(' ');
   for (int i = 0; i < words.Length; i++)
   {
     if (words[i].Length == 0) continue;
     Char firstChar = Char.ToUpper(words[i][0]);
     String rest = "";
     if (words[i].Length > 1)
     {
      rest = words[i].Substring(1).ToLower();
     }
     words[i] = firstChar + rest;
   }
    return String.Join(" ", words);
}