Tuesday, 31 May 2016

Integrate share with facebook,linkedin,twitter,google plus

No comments
HTML

<body>

    <nav>      
        <ul class="clearfix">

            <li>
                <ul>

             
                    <li><a href="javascript:void(0)" id="shareFB"><span class="fontawesome-facebook"></span></a></li>

                    <li><a id="shareTwit" href="http://twitter.com/share"><span class="fontawesome-twitter"></span></a></li>

                    <li><a id="googleLink"><span class="fontawesome-google-plus"></span></a></li>


                    <li>
                        <a id="shareLink" href="#">
                            <span class="fontawesome-linkedin"></span>
                        </a>
                    </li>

                    <li>
                        <a id="mailLink" href="#">
                            <span class="fontawesome-envelope"></span>
                        </a>
                    </li>
                </ul>

            </li>

        </ul>
    </nav>

</body>


JAVASCRIPT

<script src="http://ajax.aspnetcdn.com/ajax/jquery/jquery-1.5.1.js">
</script>
<script src="https://connect.facebook.net/en_US/all.js">
</script>
<script type="text/javascript">
    var url = document.URL;
    var message = 'Healthcare for free';
    $(document).ready(function () {

        FB.init({
            appId: '247708942243803'
        });
        $('#shareFB').click(function (e) {
            e.preventDefault();
            FB.ui(
            {
                method: 'share',
                name: message,
                href: url,
                caption: message,
                description: message,
                message: '',

            });
        });
    });
</script>

<script>
    <!--Twitter-->
    $('#shareTwit').click(function (event) {
        var width = 575,
            height = 400,
            left = ($(window).width() - width) / 2,
            top = ($(window).height() - height) / 2,
            url = this.href,
            opts = 'status=1' +
                     ',width=' + width +
                     ',height=' + height +
                     ',top=' + top +
                     ',left=' + left;

        window.open(url, 'twitter', opts);

        return false;
    });



    //Google Plus

    $('#googleLink').click(function () {
        $('#googleLink').attr('href', 'https://plus.google.com/share?url=' + url + '');
        window.open(this.href, '', 'menubar=no,toolbar=no,resizable=yes,scrollbars=yes,height=600,width=600');
        return false;
    });

    //linkedIn


    $('#shareLink').click(function () {
        $('#shareLink').attr('href', 'http://www.linkedin.com/shareArticle?mini=true&url=' + url + '&title=' + message + '&source=' + message + '');
        window.open(this.href, '', 'menubar=no,toolbar=no,resizable=yes,scrollbars=yes,height=600,width=600'); return false;
    });

    //Email

    $('#mailLink').click(function () {
        $('#mailLink').attr('href', 'mailto:?body=' + url + '&subject=' + message + '');

    });

    //Share with friends

    $('.ShareWithFreinds').click(function () {
        ShowDialog('#DivShareWithFreinds', 'Article Share with Freinds');
    });

</script>


CSS


Reset css -   http://meyerweb.com/eric/tools/css/reset/ 



<style type="text/css">
    @charset "utf-8";
    @import url('css/api.css');
    @import url('css/reset.css');

    [class*="fontawesome-"]:before {
        font-family: 'FontAwesome', sans-serif;
    }


    a {
        text-decoration: none;
    }

    .float-left {
        float: left;
    }

    .float-right {
        float: right;
    }

    .clearfix {
        *zoom: 1;
    }

        .clearfix:before, .clearfix:after {
            display: table;
            content: "";
        }

        .clearfix:after {
            clear: both;
        }


    /* ---------- NAVIGATION ---------- */

    nav {
            float: right;
    margin-top: -18px;
    position: fixed;
    margin-left: -17px;
    }

        nav ul {
            background-color: #505664;
            border-radius: 5px;
            -moz-border-radius: 5px;
            -webkit-border-radius: 5px;
            display: inline-table;
            position: relative;
        }

            nav ul li {
                float: left;
            }

                nav ul li a {
                    color: #6daeb0;
                    display: block;
                    height: 45px;
                    line-height: 45px;
                    text-align: center;
                    width: 60px;
                }

                    nav ul li a:hover {
                        color: #fff;
                    }

                nav ul li ul {
                    background-color: #6daeb0;
                    margin-top: 20px;
                    padding: 5px 0;
                    position: absolute;
                }

                    nav ul li ul:before {
                        background-color: #6daeb0;
                        content: "";
                        display: block;
                        height: 8px;
                        left: 26px; /* (nav ul li a { width: 60px; } / 2) - (nav ul li ul:before { width: 8px; } / 2) */
                        position: absolute;
                        top: -4px;
                        transform: rotate(45deg);
                        -ms-transform: rotate(45deg);
                        -moz-transform: rotate(45deg);
                        -webkit-transform: rotate(45deg);
                        width: 8px;
                        z-index: 1000;
                    }

                    nav ul li ul li {
                        float: none;
                    }

                        nav ul li ul li a {
                            color: #fff;
                        }

                            nav ul li ul li a:hover {
                                background-color: #5d9799;
                            }

</style>
read more

Monday, 30 May 2016

Validating Signup form in mvc

No comments
CustomerModel.cs

  public class CustomerModel
    {
        public int UserId { get; set; }
        [StringLength(50)]
        [Required(ErrorMessage="Please enter user name")]
        public string UserName { get; set; }

        [DataType(DataType.Password)]
        [StringLength(100)]
        [Required(ErrorMessage = "Please enter password")]
        public string Password { get; set; }
        [DataType(DataType.Password)]                      
        [System.ComponentModel.DataAnnotations.Compare("Password", ErrorMessage = "Password does not match , please re-enter password")]
        public string RetypePassword { get; set; }


        [Required(ErrorMessage = "Please select security question")]
        public int SecurityQuestionId { get; set; }
        [Required(ErrorMessage = "Please enter security answer")]

        [StringLength(50)]
        public string SecurityQueAnswer { get; set; }
        [StringLength(50)]
        [Required(ErrorMessage = "Please enter first name")]
        [RegularExpression(@"^[a-zA-Z]+[ a-zA-Z-_]*$", ErrorMessage = "Invalid first name , no special characters or numbers allowed")]
        public string FirstName { get; set; }
        [StringLength(50)]
        [RegularExpression(@"^[a-zA-Z]+[ a-zA-Z-_]*$", ErrorMessage = "Invalid last name , no special characters or numbers allowed")]
        [Required(ErrorMessage = "Please enter last name")]
        public string LastName { get; set; }
        [StringLength(200)]
        [EmailAddress(ErrorMessage = "Invalid email address , enter valid email address")]
        [Required(ErrorMessage = "Please enter email")]
        public string Email { get; set; }
        [StringLength(50)]
        [System.ComponentModel.DataAnnotations.Compare("Email",ErrorMessage="Email address does not match , please re-enter email")]
        public string RetypeEmail { get; set; }

        [Required(ErrorMessage = "Please select gender")]
        public string Gender { get; set; }
        [StringLength(40)]
        [RegularExpression(@"^[a-zA-Z]+[ a-zA-Z-_]*$", ErrorMessage = "Invalid company name , no special characters or numbers allowed")]
        [Required(ErrorMessage = "Please enter company name")]
        public string CompanyName { get; set; }
        [StringLength(50)]
        [Required(ErrorMessage = "Please enter address")]
        public string Address1 { get; set; }
        [StringLength(50)]
        public string Address2 { get; set; }
        [Required(ErrorMessage = "Please select country")]
        public int CountryId { get; set; }
        [Required(ErrorMessage = "Please select state")]
        public string StateId { get; set; }
        [StringLength(50)]
        [RegularExpression(@"^[a-zA-Z]+[ a-zA-Z-_]*$", ErrorMessage = "Invalid city name , no special characters or numbers allowed")]
        [Required(ErrorMessage = "Please enter city")]
        public string City { get; set; }

        [StringLength(50)]
        [RegularExpression("^[a-zA-Z0-9]*$", ErrorMessage = "Invalid zipcode")]
        [Required(ErrorMessage = "Please enter zipcode")]
        public string ZipCode { get; set; }
   
        [StringLength(15)]
        [Required(ErrorMessage = "Please enter phone no.")]
        [RegularExpression("([1-9][0-9]*)", ErrorMessage = "Invalid phone no.")]
        public string PhoneNo { get; set; }

        [StringLength(20)]
        [RegularExpression("([1-9][0-9]*)", ErrorMessage = "Invalid Fax")]
        public string Fax { get; set; }

        [StringLength(10)]
        public string Status { get; set; }
        public decimal CreditLimit { get; set; }

        public string ActivationToken { get; set; }
     
                     
        public IEnumerable<SelectListItem> SecurityQuestionList { get; set; }
        public IEnumerable<SelectListItem> CountryList { get; set; }
        public IEnumerable<SelectListItem> StateList { get; set; }
    }
read more

Friday, 27 May 2016

Call function if clicked except perticular class or id

No comments
$(document).click(function (e) {
    if (!$(e.target).is('.addSig')) {
        if ($('.tblSig').css('display') == 'none')
            $('.tblSig').show('slow')
        else
            $('.tblSig').hide('slow')
    }
    else {
        $('.tblSig').hide('slow')
    }
});
read more

Thursday, 19 May 2016

Codding standards

No comments
TEXT to be align left
Date to be align center
Numeric to be align right
PascalCase for class and method name
camelCase for argument and variable

for more Click here


read more

Tuesday, 17 May 2016

drop all tables and sp in sql

No comments
DECLARE @sql NVARCHAR(max)=''

SELECT @sql += ' Drop table [' + TABLE_SCHEMA + '].['+ TABLE_NAME + ']'
FROM   INFORMATION_SCHEMA.TABLES
WHERE  TABLE_TYPE = 'BASE TABLE'

Exec Sp_executesql @sql 
read more

Sunday, 15 May 2016

Open page in new page and Print div - javascript

No comments


 //Print label

    function PrintLabel(inId) {
        var printLabelContent = "<html><head><title> &nbsp;</title></head><body><label style='font-family:\"Free 3 of 9\"' id='barcodeCode'>" + inId + "</label></br><label style='font-family:\"Arial\"' id='barcodeCodeId'>" + inId + "</label>" + '</body></html>';
        var thePopup = window.open('', "Customer Listing", "menubar=0,location=0,height=700,width=700");            
        thePopup.document.body.innerHTML = printLabelContent;
        var css = '@@page {size: auto;margin: 0; }',
        head = thePopup.document.head || thePopup.document.getElementsByTagName('head')[0],
        style = thePopup.document.createElement('style');
        style.type = 'text/css';
        if (style.styleSheet) {
            style.styleSheet.cssText = css;
        } else {
            style.appendChild(document.createTextNode(css));
        }
        head.appendChild(style);      
        thePopup.document.getElementById('barcodeCode').style.zoom = "10.0";      
        thePopup.print();
        return false;
    }
read more

Thursday, 12 May 2016

Execute SP in MVC with repository pattern

No comments
 var result = contactsRepository.ExecWithStoreProcedure("Search @CompanyName,@CountryName,@StateName,@CityName,@AddressType,@zip,@OrderId",
                new SqlParameter("CompanyName", System.Data.SqlDbType.VarChar)
                {
                    Value = string.IsNullOrEmpty(companyName) ? string.Empty : companyName
                },
                new SqlParameter("CountryName", System.Data.SqlDbType.VarChar)
                {
                    Value = string.IsNullOrEmpty(countryName) ? string.Empty : countryName
                },
                new SqlParameter("StateName", System.Data.SqlDbType.VarChar)
                {
                    Value = string.IsNullOrEmpty(stateName) ? string.Empty : stateName
                },
                new SqlParameter("CityName", System.Data.SqlDbType.VarChar)
                {
                    Value = string.IsNullOrEmpty(cityName) ? string.Empty : cityName
                },
                new SqlParameter("AddressType", System.Data.SqlDbType.VarChar)
                {
                    Value = string.IsNullOrEmpty(hdfAddressType) ? string.Empty : hdfAddressType
                },
                new SqlParameter("zip", System.Data.SqlDbType.VarChar)
                {
                    Value = string.IsNullOrEmpty(zip) ? string.Empty : zip
                },
                new SqlParameter("OrderId", System.Data.SqlDbType.VarChar)
                {
                    Value = string.IsNullOrEmpty(orderId) ? string.Empty : orderId
                }
                ).ToList();

read more

SP to search in form

No comments
CREATE PROCEDURE [dbo].[Search] (
@CompanyName VARCHAR(150) = NULL
,@CountryName VARCHAR(50) = NULL
,@StateName VARCHAR(50) = NULL
,@CityName VARCHAR(50) = NULL
,@AddressType VARCHAR(10) = NULL
,@zip VARCHAR(20) = NULL
,@OrderId VARCHAR(50) = NULL
)
AS
BEGIN
IF (LEN(@CountryName) = 0)
BEGIN
SET @CountryName = NULL
END
ELSE
BEGIN
SET @CountryName = '%' + @CountryName + '%'
END

IF (LEN(@OrderId) = 0)
BEGIN
SET @OrderId = NULL
END

IF (LEN(@StateName) = 0)
BEGIN
SET @StateName = NULL
END
ELSE
BEGIN
SET @StateName = '%' + @StateName + '%'
END

IF (LEN(@CityName) = 0)
BEGIN
SET @CityName = NULL
END
ELSE
BEGIN
SET @CityName = '%' + @CityName + '%'
END

IF (LEN(@CompanyName) = 0)
BEGIN
SET @CompanyName = NULL
END
ELSE
BEGIN
SET @CompanyName = '%' + @CompanyName + '%'
END

IF (LEN(@zip) = 0)
BEGIN
SET @zip = NULL
END

PRINT @AddressType
PRINT ISNULL(@AddressType, '@@@@AddressType is null')


SELECT Address1
,Address2
,City
,ZIP
,Phone
,Email
,AddressType
,cntc.CountryId
,CompanyName
,StateId
,OrderId
,CountryName
,ContactsId
,'Contact' AS TypeTable
FROM Contacts cntc WITH (NOLOCK)
INNER JOIN Country cntry WITH (NOLOCK) ON cntc.CountryId = cntry.CountryId

WHERE ISNULL(CompanyName, '') LIKE COALESCE(@CompanyName, CompanyName, '')
AND ISNULL(CountryName, '') LIKE COALESCE(@CountryName, CountryName, '')
AND ISNULL(StateId, '') LIKE COALESCE(@StateName, StateId, '')
AND ISNULL(City, '') LIKE COALESCE(@CityName, City, '')
AND ISNULL(ZIP, '') = COALESCE(@zip, ZIP, '')
 AND OrderId = coalesce(@OrderId ,OrderId,''')
END
read more

Thursday, 5 May 2016

Bind Dropdownlist to model in MVC

No comments
CSHTML - 

 @Html.DropDownListFor(m => m.drugid, Model.DrugList, "Select Drug", new { @class = "chosen-select" })


GenericSelectListItems class to bind data anywhere - 

    public class GenericSelectListItems
    {
        private static GenericSelectListItems _GenericSelectListItems = new GenericSelectListItems();
        UnitOfWork uom = new UnitOfWork();

        public GenericSelectListItems()
        {

        }

        public static GenericSelectListItems Instance
        {
            get
            {
                return _GenericSelectListItems;
            }
        }

        public List<SelectListItem> GetDrugs()
        {
            var drugRepository = uom.Repository<DrugRepository>();
            var drugDataList = drugRepository.GetAllDrugs();
            return drugDataList.Select(d => new SelectListItem
            {
                Value=d.drugid.ToString(),
                Text=d.drugname
            }).ToList();
        }

    }


Controller - 

 public class DrugsController : Controller
    {
        UnitOfWork uow = new UnitOfWork();
        public ActionResult IncomingDrugs()
        {
            DrugInModels drugInModels = new DrugInModels();
            BindDropDown(drugInModels);
            return View(drugInModels);
        }

        public void BindDropDown(DrugInModels drugInModels)
        {
            drugInModels.DrugList = GenericSelectListItems.Instance.GetDrugs();
        }
    }
read more

Tuesday, 3 May 2016

Enable live click in Jquery

No comments
to enable .live click in jquery add this function in document ready

  jQuery.fn.extend({
            live: function (event, callback) {
                if (this.selector) {
                    jQuery(document).on(event, this.selector, callback);
                }
            }
        });

full code ----

$(document).ready(function () {

        jQuery.fn.extend({
            live: function (event, callback) {
                if (this.selector) {
                    jQuery(document).on(event, this.selector, callback);
                }
            }
        });

        $('.sectionCredit').live('click', function () {        
            var $this = $(this);
            $('.sectionCredit').each(function () {
                if ($(this).hasClass('active')) {
                    $(this).removeClass('active');
                }
            });
            $this.addClass('active');
        })
    });
read more