String Array To List Or int[]

Wednesday, August 20, 2014
Convert String Array to Int array OR List<int> :

var aIDs=(r["AlertIDs"].ToString()).Split(',');
if (aIDs.Length > 0 && aIDs[0] !="" )
{
      List<int> alertIds = aIDs.Select(int.Parse).ToList();   // for convert to List<int>
    //  var alertIds = aIDs.Select(int.Parse);                         // for convert to int[]
}

Hide All TR after 5th TR of a Table by JQuery

Hide All TR after 5th TR of a Table by JQuery :

 $('#tbcompose > table:first tr:gt(5)').hide();

Submit button in MVC by Html Helper

Tuesday, June 10, 2014
In this way you can add new property with Htmlhelper :

public static MvcHtmlString Submit(this HtmlHelper helper, string name, string value, object htmlAttrib = null)
{
   var attributes = HtmlHelper.AnonymousObjectToHtmlAttributes(htmlAttrib);
   var builder = new TagBuilder("input");
   if (htmlAttrib != null)
   {
      builder.MergeAttributes(attributes);
   }
   builder.Attributes.Add("type", "submit");
   builder.Attributes.Add("value", value);
   builder.Attributes.Add("name", name);
   builder.Attributes.Add("id", name);
   builder.AddCssClass("submit");
   return new MvcHtmlString(builder.ToString(TagRenderMode.SelfClosing));
}

And you can you this like :

 @Html.Submit("submit")

Convert Int32 to Bool in C#

Wednesday, April 30, 2014
Bellow is the syntax for change Int to Bool :

bool result = Convert.ToInt32(maxLead[5]) == 1; 

Access URL details by JavaScript/JQuery

Thursday, April 24, 2014
http://www.refulz.com:8082/index.php#tab2?foo=789

Property    Result
-------------------------------------------
host        www.refulz.com:8082
hostname    www.refulz.com
port        8082
protocol    http
pathname    index.php
href        http://www.refulz.com:8082/index.php#tab2
hash        #tab2
search      ?foo=789

var x = $(location).attr('<property>');

No symbol in Textbox by JavaScripy

Tuesday, April 15, 2014
Within Script Block : 

var specialKeys = new Array();
    specialKeys.push(8); //Backspace
    specialKeys.push(9); //Tab
    specialKeys.push(46); //Delete
    specialKeys.push(36); //Home
    specialKeys.push(35); //End
    specialKeys.push(37); //Left
    specialKeys.push(39); //Right
    function IsAlphaNumeric(e) {
        var keyCode = e.keyCode == 0 ? e.charCode : e.keyCode;
        var ret = ((keyCode >= 48 && keyCode <= 57) || (keyCode >= 65 && keyCode <= 90) || (keyCode >= 97 && keyCode <= 122) || (specialKeys.indexOf(e.keyCode) != -1 && e.charCode != e.keyCode));      
        if ($('#txtCode').val().length > 7)
            ret= false;
        if (!ret)
        $("#errmsg").html("NO Symbol(s) & 8 Char").show().fadeOut("slow");
        return ret;
    }

where the HTML Like bellow :

<input id="txtCode" name="Code" class="/*easyui-validatebox*/ required form-control" required="true" style="width:100%" onkeypress="return IsAlphaNumeric(event);" ondrop="return false;" onpaste="return false;">
                    &nbsp;<span id="errmsg"></span>

--- on " onkeypress " event of that textbox that function filtered the input value & showing or inserted valied input . and it should not cross more than 8 char. 

SQL query with " IN " function with C# List

Tuesday, April 8, 2014
Here uLL is the List<BsonValue> ,because i am using MongoDB as a Database.
that's why i did convert to List<int> for compare with SQL.


string qry = "select count(*) from SendMessageHistory where SendDate> convert(varchar(10), getdate(),120) ";

                if (td != 1)
                {
                    if (td == 0)
                    {
                        qry += "and UserID=" + userID;
                    }
                    else if (td == 2)
                    {
                        AccountData dad = new AccountData();
                        var uLL = dad.GetUserByManagerID(userID);
                        List<int> ul=new List<int>();
                        foreach (var user in uLL)
                        {
                            ul.Add(Convert.ToInt32(user));
                        }
                         string types = string.Join(",", ul.ToArray());
                         qry += "and UserID In (" + types + ")";
                    }
                 
                }

Get Current Week Start & End Date by JavaScript / Jquery

Tuesday, March 25, 2014
Simple pic of code for JavaScript
<script type="text/javascript">
        $(document).ready(function () {
        var curr = new Date;                               // get current date
        var first = curr.getDate() - curr.getDay(); // First day is the day of the month - the day of the week
        var last = first + 6;                                  // last day is the first day + 6

        var firstday = new Date(curr.setDate(first)).toUTCString();
        var lastday = new Date(curr.setDate(last)).toUTCString();

        $('#startDate').datebox('setValue', firstday);    // I use Easyui Thatswhy my code is different :)
        });
    </script>

and also u can do some formation by like bellow :

var fdate = firstday.getMonth()+1 + "/" + firstday.getDate() + "/" + firstday.getFullYear();

Export To Excel ( from html table )

Thursday, February 13, 2014
Import to a Excel from a html table is very easy ,just follow this step ::

  1. In Script tag : 
var tableToExcel = (function() {

  var uri = 'data:application/vnd.ms-excel;base64,'    , template = '<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns="http://www.w3.org/TR/REC-html40"><head><!--[if gte mso 9]><xml><x:ExcelWorkbook><x:ExcelWorksheets><x:ExcelWorksheet><x:Name>{worksheet}</x:Name><x:WorksheetOptions><x:DisplayGridlines/></x:WorksheetOptions></x:ExcelWorksheet></x:ExcelWorksheets></x:ExcelWorkbook></xml><![endif]--></head><body><table>{table}</table></body></html>'    , base64 = function(s) { return window.btoa(unescape(encodeURIComponent(s))) }    , format = function(s, c) { return s.replace(/{(\w+)}/g, function(m, p) { return c[p]; }) }
  return function(table, name) {
    if (!table.nodeType) table = document.getElementById(table)
        var ctx = {worksheet: name || 'Worksheet', table: table.innerHTML}
          window.location.href = uri + base64(format(template, ctx))
          }
        })()

        2. And In Html should like :
        <input type="button" onclick="tableToExcel('testTable', 'W3C Example Table')" value="Export to Excel">
        3. And Table id should be "testTable" as per button :
        <table id="testTable"></table>

        !!_________________ Enjoy____________________!!