Tuesday, 18 July 2017

Google LogIn

https://developers.google.com/identity/sign-in/web/sign-in

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html>
  <head>
<script src="https://apis.google.com/js/platform.js" async defer></script>
<meta name="google-signin-client_id" content="YOUR_CLIENT_ID.apps.googleusercontent.com">

</head>

  <body>
<div id="res"></div>
  <div class="g-signin2" data-onsuccess="onSignIn"></div>
<script>
       function onSignIn(googleUser) {
        var profile = googleUser.getBasicProfile();
        console.log('ID: ' + profile.getId()); // Do not send to your backend! Use an ID token instead.
        console.log('Name: ' + profile.getName());
        console.log('Image URL: ' + profile.getImageUrl());
        console.log('Email: ' + profile.getEmail()); // This is null if the 'email' scope is not present.
    }
</script>

<a href="#" onclick="signOut();">Sign out</a>
<script>
    function signOut() {
        var auth2 = gapi.auth2.getAuthInstance();
        auth2.signOut().then(function () {
            console.log('User signed out.');
        });
    }
</script>
  </body>
</html>

Wednesday, 12 July 2017

Implement UserName and Password Remember Me functionality using CheckBox ASP.Net

<form id="form1" runat="server">
    UserName:
    <asp:TextBox ID="txtUserName" runat="server"></asp:TextBox><br />
    Password:
    <asp:TextBox ID="txtPassword" TextMode="Password" runat="server"></asp:TextBox><br />
    Remember me:
    <asp:CheckBox ID="chkRememberMe" runat="server" /><br />
    <asp:Button ID="btnLogin" runat="server" Text="Login" OnClick="Login_Click" />
    </form>
=================================================================

protected void Login_Click(object sender, EventArgs e)
{
    if (chkRememberMe.Checked)
    {
        Response.Cookies["UserName"].Expires = DateTime.Now.AddDays(30);
        Response.Cookies["Password"].Expires = DateTime.Now.AddDays(30);
    }
    else
    {
        Response.Cookies["UserName"].Expires = DateTime.Now.AddDays(-1);
        Response.Cookies["Password"].Expires = DateTime.Now.AddDays(-1);
 
    }
    Response.Cookies["UserName"].Value = txtUserName.Text.Trim();
    Response.Cookies["Password"].Value = txtPassword.Text.Trim();
}

===================================================================
protected void Page_Load(object sender, EventArgs e)
{
    if (!IsPostBack)
    {
        if (Request.Cookies["UserName"] != null && Request.Cookies["Password"] != null)
        {
            txtUserName.Text = Request.Cookies["UserName"].Value;
            txtPassword.Attributes["value"] = Request.Cookies["Password"].Value;
        }
    }
}

Tuesday, 11 July 2017

Determine if page was from redirect of loaded directly

If(Page.PreviousPage !=null && Page.PreviousPage.Request.Url == "Your Previous Page's Url")
{
     .......
}

Bind Data in DropDown in Gride View

//DropDown
DropDownList D_grade = (DropDownList)Grid_studenthealth.Rows[i].FindControl("drpGrade");

public void Grid_studenthealth_OnRowDataBound(object sender, GridViewRowEventArgs e)
    {
        dt = Bind_Disiplan_Grade();
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            DropDownList DDL_Grade = (DropDownList)e.Row.FindControl("drpGrade");
            Label di_Grade = (Label)e.Row.FindControl("grid_Grade");

            DDL_Grade.DataSource = dt;
            DDL_Grade.DataTextField = "grade";//grade Column Name
            DDL_Grade.DataValueField = "grade";
            DDL_Grade.DataBind();
            DDL_Grade.Items.Insert(0, new ListItem("--Select Grade--", "0"));//Add New Item
            DDL_Grade.SelectedValue = di_Grade.Text.Trim();
         
        }

Saturday, 8 July 2017

Generate QRCode

http://www.aspdotnet-suresh.com/2017/04/aspnet-generate-and-read-qr-code-in-web-application-using-csharp-vbnet.html

install  zxing.net c# library

PM> Install-Package ZXing.Net -Version 0.15.0

<form id="form1" runat="server">
<div>
<asp:TextBox ID="txtCode" runat="server"></asp:TextBox>
<asp:Button ID="btnGenerate" runat="server" Text="Generate QR Code" OnClick="btnGenerate_Click" />
<hr />
<asp:Image ID="imgQRCode" Width="100px" Height="100px" runat="server" Visible="false" />     <br /><br />
<asp:Button ID="btnRead" Text="Read QR Image" runat="server" OnClick="btnRead_Click" />  <br /><br />
<asp:Label ID="lblQRCode" runat="server"></asp:Label>
</div>
</form>


using System;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;

using ZXing;

namespace TestProject
{
    public partial class QrCode : System.Web.UI.Page
    {

        protected void Page_Load(object sender, EventArgs e)
        {

        }
        protected void btnGenerate_Click(object sender, EventArgs e)
        {
            GenerateCode(txtCode.Text);
        }
        protected void btnRead_Click(object sender, EventArgs e)
        {
            ReadQRCode();
        }
        // Generate QRCode
        private void GenerateCode(string name)
        {
            var writer = new BarcodeWriter();
            writer.Format = BarcodeFormat.QR_CODE;
            var result = writer.Write(name);
            string path = Server.MapPath("~/image/QRCodeImage.jpg");
            var barcodeBitmap = new Bitmap(result);




            using (MemoryStream memory = new MemoryStream())
            {
                using (FileStream fs = new FileStream(path, FileMode.Create, FileAccess.ReadWrite))
                {
                    barcodeBitmap.Save(memory, ImageFormat.Jpeg);
                    byte[] bytes = memory.ToArray();
                    fs.Write(bytes, 0, bytes.Length);
                }
            }
            imgQRCode.Visible = true;
            imgQRCode.ImageUrl = "~/image/QRCodeImage.jpg";

        }
        // Read Code from QR Image
        private void ReadQRCode()
        {
            var reader = new BarcodeReader();
            string filename = Path.Combine(Request.MapPath("~/image"), "QRCodeImage.jpg");
            // Detect and decode the barcode inside the bitmap
            var result = reader.Decode(new Bitmap(filename));
            if (result != null)
            {
                lblQRCode.Text = "QR Code: " + result.Text;
            }
        }
    }

}

Saturday, 1 July 2017

Group By Abd PIVOT in SQL




Select * from tblProduct

SalesAgent | SalesCountry| SalesAmount
Tom| UK |200
shyam| US |180
shyam |UK |260
ram| India |450
Tom |India |350
ram| US |200
Tom |US |130
shyam |India |540
shyam |UK |120
ram| UK |220
shyam |UK |420
ram |US |320
Tom |US |340
Tom |UK |660
shyam |India |430
ram |India |230
ram |India |280
Tom |UK |480
shyam |US |360
ram| UK| 140
==================Group By=====================
Select SalesCountry, SalesAgent, SUM(SalesAmount) as Total 
from tblProduct
group by SalesCountry, SalesAgent
order by SalesCountry, SalesAgent

SalesCountry| SalesAgent | Total
India |ram 960
India |shyam |970
India |Tom |350
UK| ram |360
UK |shyam |800
UK |Tom |1340
US |ram| 520
US |shyam |540

US Tom 470

===============PIVOT=================
Select SalesAgent, India, US, UK
from 
(
   Select SalesAgent, SalesCountry, SalesAmount from tblProducts
) as SourceTable
Pivot
(
 Sum(SalesAmount) for SalesCountry in (India, US, UK)
) as PivotTable

Write a in StordProcedure

CREATE PROCEDURE [dbo].[SpGropByTblProductSales]
as
BEGIN
Select SalesCountry, SalesAgent, SUM(SalesAmount) as Total
from tblProductSales
group by SalesCountry, SalesAgent
order by SalesCountry, SalesAgent
END


Result
SalesAgent India US UK
ram         960        520 360
shyam        970       540 800
Tom               350     470     1340

IIS deployment support details

  Node JS - IIS deployment support details node: http://go.microsoft.com/?linkid=9784334 IISNode: https://github.com/azure/iisnode/releases/...