Friday, July 19, 2013

list to Datatable C#

 ListtoDataTableConverter Class

public class ListtoDataTableConverter
    {
        public DataTable ToDataTable<T>(List<T> items)
        {
            DataTable dataTable = new DataTable(typeof(T).Name);
            //Get all the properties
            PropertyInfo[] Props = typeof(T).GetProperties(BindingFlags.Public |BindingFlags.Instance);
            foreach (PropertyInfo prop in Props)
            {
                //Setting column names as Property names
                dataTable.Columns.Add(prop.Name);
            }
             foreach (T item in items)
            {
                var values = new object[Props.Length];
                for (int i = 0; i < Props.Length; i++)
                {
                    //inserting property values to datatable rows
                    values[i] = Props[i].GetValue(item, null);
                }
                dataTable.Rows.Add(values);
            }
             //put a breakpoint here and check datatable
            return dataTable;
        }
    }

How to use Method

ListtoDataTableConverter converter = new ListtoDataTableConverter();
       DataTable dt = converter.ToDataTable(name of list); 
 

Thursday, July 18, 2013

Count Word Without space C#

Count  Word Without Space

public static int ContWordWithOutSpace(string value)
    {
        //Content Length-Content Description

        int length = 0;
        value = value.Trim();
        string value1 = CollapseSpaces(value);
        char[] lineDelimiters = { ' ', '\n', '\r' };
        string[] arr = value1.Split(lineDelimiters);
        length = arr.Length;
        int lgth = value.Length;
        return length;
    }

Insert, Update, Change Staus Stored Procedure


CREATE proc [dbo].[ProcSMOproject]     
(     
@ProjectID int, 
@ProjectTitle varchar (100), 
@ProjectDesc text, 
@UserID int, 
@Language varchar(50), 
@Status tinyint, 
@Action int  
)     
as     
     
begin     
SET NOCOUNT OFF     
--sp_help SMOProjectMaster 
--Action 1 - Insert 
if(@Action = 1) --insert 
 begin 
 insert into SMOProjectMaster(ProjectTitle,ProjectDesc,UserID,[Language],CreateDate,Status) 
 values(@ProjectTitle,@ProjectDesc,@UserID,@Language,getdate(),@Status) 
 end 
 
if(@Action = 2) --update 
 begin 
 update SMOProjectMaster set ProjectTitle=@ProjectTitle,ProjectDesc=@ProjectDesc,UserID=@UserID,[Language]=@Language, ModifiedDate = getdate() 
 where ProjectID=@ProjectID 
 end 
 
if(@Action = 3) --change status 
 begin 
 update SMOProjectMaster set status=@status , ModifiedDate = getdate() where ProjectID=@ProjectID 
 end 
end


How to Use Stored procedure, here i m using Sql parameter to pass values to stored procedre Example not the correct values i m passing


SqlParameter[] prmSEOContent = new SqlParameter[7];
prmSEOContent[0] = new SqlParameter("@UserId", 0);
prmSEOContent[1] = new SqlParameter("@FirstName", txtfname.Text.ToString().Trim().Replace("'", "''"));
prmSEOContent[2] = new SqlParameter("@Lastname", txtlname.Text.ToString().Trim().Replace("'", "''"));
prmSEOContent[3] = new SqlParameter("@UserEmail", txtemail.Text.ToString().Trim());
prmSEOContent[4] = new SqlParameter("@RoleID", Int32.Parse(ddlrole.SelectedItem.Value.ToString().Trim()));
prmSEOContent[5] = new SqlParameter("@status", "1");
prmSEOContent[6] = new SqlParameter("@action", 1);

int i = SqlHelper.ExecuteNonQuery(ConfigurationManager.ConnectionStrings["ConnectionString"].ToString().Trim(), CommandType.StoredProcedure, "User", prmSEOContent);
            if (i > 0)
            {
                lblmessage.Text = "User Added successfully. Default Password: 12345 ";
                FillGrid(10, 1);
                txtfname.Text = "";
                txtlname.Text = "";
                txtemail.Text = "";
               
                //Done
            }
            else
            {
                lblmessage.Text = "Please try again leter!";
            }



Wednesday, July 17, 2013

ServerSide Validation Class

Server Side Validation Class Class Name= validate.cs


using System;
using System.Collections.Generic;
using System.Text.RegularExpressions;

/// <summary>
/// Summary description for validate
/// </summary>
public class validate
{
    public validate()
    {
       
    }
    public static IDictionary<string, Regex> RegexDictionary = new Dictionary<string, Regex>() {
        { "Phone", new Regex("\\d{10}")},
        { "Email", new Regex(@"^(([^<>()[\]\\.,;:\s@\""]+"
          + @"(\.[^<>()[\]\\.,;:\s@\""]+)*)|(\"".+\""))@"
          + @"((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}"
          + @"\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+"
          + @"[a-zA-Z]{2,}))$"
        )},
        { "URL", new Regex(@"(http(s)?://)?([\w-]+\.)+[\w-]+(/[\w- ;,./?%&=]*)?")},
        { "ZipCode", new Regex("^[0-9]{6}$")}
        };

    public string IsPhoneValid(string phone)
    {
        if (!RegexDictionary["Phone"].IsMatch(phone))
        {
            // Phoneno should be digits only
            return "Phoneno Must be of 10 digits only";
           
        }
        else
        {
            return "";
        }
    }
    public string IsEmailValid(string email)
   
    {
        if (!RegexDictionary["Email"].IsMatch(email))
        {
            // EmailId is invalid
            return "EmailId is invalid";
           
        }
        else
        {
            return "";
        }
    }
    public string IsURLValid(string url)
    {
        if (!RegexDictionary["URL"].IsMatch(url))
        {
            // URL is invalid
            return  "URL is invalid";
         
        }
        else
        {
            return "";
        }
    }
    public string IsZipCodeValid(string url)
    {
        if (!RegexDictionary["ZipCode"].IsMatch(url))
        {
            // ZipCode must be of 6 digit only.
           return "ZipCode must be of 6 digit only.";
           
        }
        else
        {
            return "";
        }
    }
    public string Minimuntwochar(string name)
    {
        Regex objAlphaPattern = new Regex("^[A-Za-z]{2,}$");
        if (!objAlphaPattern.IsMatch(name))
        {
            // Minimum Two Characters.
            return "Minimum Two Characters.";
        
        }
        else
        {
            return "";
        }
    }
    public string Isnullorempty(String Controlname,string name)
    {
        if (string.IsNullOrEmpty(name))
        {
            return "Please Enter " + Controlname;
        }
        else
        {
            return "";
        }
    }
    public string Compare(string controlname,string first,string second)
    {
        //Compare two field
        if (!string.IsNullOrEmpty(first))
        {
            if (first == second)
            {
                return controlname + " accepted";
            }
            else
            {
                return controlname + " do not match.";
            }
        }
        else
        {
            return controlname + " Cannot be Empty!.";
        }
    }
    public string Isnumeric(string numeric)
    {
        Regex objnumeric = new Regex("^\\d+$");
        if (!objnumeric.IsMatch(numeric))
        {
            // Minimum Two Characters.
            return "Numeric Character only.";

        }
        else
        {
            return "";
        }

    }
    public string Maxlength(string controlname,int maxlength, string controlvalue)
    {
        if (!String.IsNullOrEmpty(controlvalue))
        {
            if (controlvalue.Length!= maxlength)
            {
                return controlname + " Should not exceed the " + maxlength + " Character";
            }
            else
            {
                return "";
            }

        }
        return "Please Enter " + controlname; ;

    }

}



 Control and label

<asp:TextBox ID="txtzipcode" runat="server"></asp:TextBox><asp:Label ID="lblzip"
                        runat="server"></asp:Label>

How  To Use On Page





 validate formvalidation = new validate();
        lblzip.Text = formvalidation.IsZipCodeValid(txtzipcode.Text);
     

Tuesday, July 9, 2013

import excel data to sql server

First Create Table, it is better to name as sheet column name.
Then Copy the data  [ Ctrl + C ]
import excel data to sql server

Go to Table Right Click and select Open Table

import excel data to sql server
Now left Click
import excel data to sql server
The Area will be highlighted now right click and paste
import excel data to sql server
Happy Excel ...data is in sql now..
import excel data to sql server

Friday, July 5, 2013

Web Developer Must Know

1) php.net : For Php information php.net is the best site.

Web Developer Must Know


2) Git hub : Very powerful repository where most of the majority of source code plug-ins, frameworks and libraries.
Web Developer Must Know


3) Stackoverflow.com :  It has very big database of question answer.Most of the question are resolved here easily
Web Developer Must Know


4)  net.tutsplus.com   : It is a used for tutorial purpose here you can find the tutorial in all format that is audio, video and text.
Web Developer Must Know


5) jsfiddle.net. A very popular resource for testing JS, CSS, HTML. Here you can save the example and share the link with you friends.

Web Developer Must Know


6) fontsquirrel.com  This site made very easy to generate font face.


Web Developer Must Know

7)lipsum.com and lorempixel.com.  Two popular resources for filling and testing content. You can also generate text for different formats. The second one generates images by the subject and size.

Web Developer Must Know


8) prefixr.com This great resource is for anyone who bothers to put prefixes in their css code. It is very simple to use, just copy the code and resources will give re-generated code with prefixes.

Web Developer Must Know


9) caniuse.com This is an informative resource which contains information about certain technologies supporting browsers. It is always updated and the information is very useful for web developers who follow the trends.
Web Developer Must Know

10) css3generator.com This is a great generator for the majority of CSS3 styles. it offers a very easy and simple generator for those who do not remember the syntax.

Web Developer Must Know

DotnetNuke download free



DotnetNuke Its Free

DotNetNuke (DNN) is one of the leading Open Source web CMS apps for Microsoft ASP.NET, claiming it powers over 700,000 production websites worldwide. DNN offers a free version – the Community Edition – as well as two paid editions – Professional and Enterprise. A handy feature comparison chart is available on the DNN website.

DotnetNuke download free




Click here to download
You can also download this Community CMS from codeplex : download

Download DNN Skin : http://www.dnnskins.com

Dnn Tutorial : http://www.howiusednn.com/

Tuesday, July 2, 2013

Textbox as circle, Rectangle

 <asp:TextBox ID="myoval" runat="server"></asp:TextBox>
 <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>



Aplly CSS

<style>
    #myoval {
width: 200px;
height: 200px;

border-radius: 213px 213px 213px 213px;
}
#TextBox1
{width: 400px;
height: 200px;
    }
</style>