Translate

Saturday 31 January 2015

Alert Msg In C#

  string msg = InsertEmployee(1,txtName.Text);

 ScriptManager.RegisterStartupScript(this,this.GetType(),"", "alert('" + msg + "');window.location.href=('Default.aspx');", true);




ScriptManager.RegisterStartupScript(this, this.GetType(), "alertmessage", "javascript:alert('Please Enter Data')", true);



----------------------
 Page.ClientScript.RegisterStartupScript(this.GetType(), "", "alert('Insufficient Access Previlage');window.location.href=('LogiPage.aspx');", true);

ClientScript.RegisterStartupScript(GetType(), "alert", "alert('" + msg + "');window.location.href='InsertPage.aspx';", true);
------------------------

 ScriptManager.RegisterStartupScript(this, this.GetType(), "", "alert('" + msg + "');", true);     
                 //ScriptManager.RegisterStartupScript(this, this.GetType(), "", "alert('" + msg + "');window.location.href=('Default.aspx');", true);     
                ScriptManager.RegisterStartupScript(this,this.GetType(),"","alert('ddddddddd');", true);  

Saturday 24 January 2015

Google Map Current Loacatation

Copy the Code And Past in Aspx Page and Run You Find the Current Locatation
------------------------------------------------------------------


<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default3.aspx.cs" Inherits="Default3" %>

<!DOCTYPE html>
<html>
    <head>
        <script src="http://maps.google.com/maps/api/js?sensor=false">
        </script>
        <script>
            if (navigator.geolocation) {
                navigator.geolocation.getCurrentPosition(showCurrentLocation);
            }
            else {
                alert("Geolocation API not supported.");
            }

            function showCurrentLocation(position) {
                var latitude = position.coords.latitude;
                var longitude = position.coords.longitude;
                var coords = new google.maps.LatLng(latitude, longitude);

                var mapOptions = {
                    zoom: 15,
                    center: coords,
                    mapTypeControl: true,
                    mapTypeId: google.maps.MapTypeId.ROADMAP
                };

                //create the map, and place it in the HTML map div
                map = new google.maps.Map(
                document.getElementById("mapPlaceholder"), mapOptions
                );

                //place the initial marker
                var marker = new google.maps.Marker({
                    position: coords,
                    map: map,
                    title: "Current location!"
                });
            }
        </script>
    </head>
    <style>
    #mapPlaceholder {
        height: 400px;
        width: 700px;
    </style>
    <body>
        <div>
        <h2>HTML5 Show Location on GoogleMap Sample</h2>
        <div id="mapPlaceholder"></div>
        </div>
    </body>
</html>

Wednesday 21 January 2015

Split Sting

  string SplitString = "Hello Pabitra !123456! City IS :bhubaneswar";
        string Name = SplitString.Split('!')[1];
        string City = SplitString.Split(':')[1];
         Response.Write(Name);
         Response.Write(City);

Saturday 10 January 2015

Send Mail in c# through gmail

using System.Configuration;
using System.Net;
using System.IO;
using System.Net;
using System.Net.Mail;
using System.Net.Mime;
----------------
 protected void btnSendMail1_Click(object sender, EventArgs e)
      {
          string ToWhomYouMail = "pabitrakiims@gmail.com";//Send to mail
          string Subject = "Test Mail";
          string mailbody = "<html><body><div>Dear Sir ,Good Morning</div></body></html>";
          bool m = send_mail(ToWhomYouMail, Subject, mailbody);
          if (m)
          {
              ScriptManager.RegisterStartupScript(this, this.GetType(), "", "alert('Mail Send Sucessfully !');", true);
          }
          else
          {
              ScriptManager.RegisterStartupScript(this, this.GetType(), "", "alert('An Error Occurs !');", true);
          }
      }



 public bool send_mail(string ToMail,string subject,string body)
       {
           bool k = false;
           try
           {
               MailMessage msg = new MailMessage("pabitra.best28@gmail.com", ToMail);
               msg.To.Add(ToMail);
            msg.Subject = subject;
            msg.Body = body;
            msg.IsBodyHtml = true;
            AlternateView view;
            SmtpClient client;
            msg.IsBodyHtml = true;
            client = new SmtpClient();
            client.Host = "smtp.gmail.com";
            client.Port = 587;
            client.Credentials = new System.Net.NetworkCredential("pabitra.best28@gmail.com", "password@123");
            client.EnableSsl = true; //Gmail works on Server Secured Layer
            client.Send(msg);
            k = true;
            //return k;
        }catch(Exception ex)
        {
            k = false;
        }
        return k;
     
    }

Friday 9 January 2015

Tuesday 6 January 2015

stored procedures in entity framework c#


CREATE TABLE [dbo].[Employees](
    [ID] [int] NULL,
    [Name] [varchar](100) NULL,
    [Gender] [varchar](20) NULL,
    [Salary] [int] NULL
)
insert into Employees(ID,Name,Gender,Salary)values(1,'Pabitra','Male',10000)
insert into Employees(ID,Name,Gender,Salary)values(2,'Geetanjali','Female',20000)
insert into Employees(ID,Name,Gender,Salary)values(3,'Manoranjan','Male',30000)
insert into Employees(ID,Name,Gender,Salary)values(4,'Prativa','Female',40000)
insert into Employees(ID,Name,Gender,Salary)values(5,'Aloka','Male',50000)
insert into Employees(ID,Name,Gender,Salary)values(6,'Ashrita','Female',60000)
insert into Employees(ID,Name,Gender,Salary)values(7,'Chintamani','Male',70000)
insert into Employees(ID,Name,Gender,Salary)values(8,'Nishi','Female',80000)
insert into Employees(ID,Name,Gender,Salary)values(9,'Nihar','Male',90000)
insert into Employees(ID,Name,Gender,Salary)values(10,'Pabitra','Male',100000)
insert into Employees(ID,Name,Gender,Salary)values(11,'Sankar','Male',110000)
insert into Employees(ID,Name,Gender,Salary)values(12,'Himashu','Male',110000)

Repeater Control In Asp.net

USE [DBPABITRA]
GO

/****** Object:  Table [dbo].[tbexecutive]    Script Date: 01/06/2015 17:47:58 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

SET ANSI_PADDING ON
GO

CREATE TABLE [dbo].[tbexecutive](
[id] [varchar](10) NULL,
[workername] [varchar](50) NULL,
[currentadd] [varchar](50) NULL
) ON [PRIMARY]

GO

SET ANSI_PADDING OFF
GO


-------------------------using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Configuration;
using System.Data.SqlClient;
public partial class RepeatearControl : System.Web.UI.Page
{  
    SqlConnection con = new SqlConnection("server=.;uid=sa;pwd=mypass;database=MyDB");
    protected void Page_Load(object sender, EventArgs e)
    {

        if (con.State == ConnectionState.Closed)
        {

            con.Open();

        }

        if (Page.IsPostBack == false)
        {

            Show_Data();

        }

    }

    protected void Repeater1_ItemCommand(object source, RepeaterCommandEventArgs e)
    {

        if (e.CommandName == "edit")
        {

            ((Label)e.Item.FindControl("Label1")).Visible = false;

            ((Label)e.Item.FindControl("Label2")).Visible = false;

            ((TextBox)e.Item.FindControl("Textbox1")).Visible = true;

            ((TextBox)e.Item.FindControl("Textbox2")).Visible = true;

            ((LinkButton)e.Item.FindControl("LinkEdit")).Visible = false;

            ((LinkButton)e.Item.FindControl("LinkDelete")).Visible = false;

            ((LinkButton)e.Item.FindControl("LinkUpdate")).Visible = true;

            ((LinkButton)e.Item.FindControl("Linkcancel")).Visible = true;

        } if (e.CommandName == "delete")
        {

            SqlCommand cmd = new SqlCommand("delete from tbexecutive where id=@id", con);

            cmd.Parameters.AddWithValue("@id", e.CommandArgument);

            cmd.ExecuteNonQuery();

            cmd.Dispose();

            Page.ClientScript.RegisterStartupScript(this.GetType(), "ch", "");

            Show_Data();

        }

        if (e.CommandName == "update")
        {

            string str1 = ((TextBox)e.Item.FindControl("TextBox1")).Text;

            string str2 = ((TextBox)e.Item.FindControl("TextBox2")).Text;

            SqlDataAdapter adp = new SqlDataAdapter("update tbexecutive set workername=@workername, currentadd=@add where id=@id", con);

            adp.SelectCommand.Parameters.AddWithValue("@workername", str1);

            adp.SelectCommand.Parameters.AddWithValue("@add", str2);

            adp.SelectCommand.Parameters.AddWithValue("@id", e.CommandArgument);

            DataSet ds = new DataSet();

            adp.Fill(ds);

            Show_Data();

            Page.ClientScript.RegisterStartupScript(this.GetType(), "ch", "");

        } if (e.CommandName == "cancel")
        {

            ((Label)e.Item.FindControl("Label1")).Visible = true;

            ((Label)e.Item.FindControl("Label2")).Visible = true;

            ((TextBox)e.Item.FindControl("TextBox1")).Visible = false;

            ((TextBox)e.Item.FindControl("TextBox2")).Visible = false;

            ((LinkButton)e.Item.FindControl("LinkEdit")).Visible = true;

            ((LinkButton)e.Item.FindControl("LinkDelete")).Visible = true;

            ((LinkButton)e.Item.FindControl("LinkUpdate")).Visible = false;

            ((LinkButton)e.Item.FindControl("Linkcancel")).Visible = false;

        }



    }

    public void Show_Data()
    {

        SqlDataAdapter adp = new SqlDataAdapter("select * from tbexecutive ORDER BY workername ASC", con);

        DataSet ds = new DataSet();

        adp.Fill(ds);

        Repeater1.DataSource = ds;

        Repeater1.DataBind();

    }

}

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="RepeatearControl.aspx.cs" Inherits="RepeatearControl" %>


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


<html xmlns="http://www.w3.org/1999/xhtml">
<head id = "Head1" runat="server">
    <title></title>
</head>
<body>
    <form id="form2" runat="server">
    <div>
   
        <asp:Repeater ID="Repeater1" runat="server"
            onitemcommand="Repeater1_ItemCommand">
            <HeaderTemplate>
           

          <table width="350"><tr
bgcolor="#FF6600"><td>Name</td><td>Address</td><td>Action</td></tr></HeaderTemplate>

           <ItemTemplate><tr><td> <asp:Label
ID="Label1" runat="server" Text='<%#Eval("workername")
%>'></asp:Label>

      <asp:TextBox ID="TextBox1" runat="server"
Text='<%#Eval("workername") %>'
Visible="false"></asp:TextBox>
        </td>
        <td>
        <asp:Label ID="Label2" runat="server" Text='<%#Eval("currentadd") %>'></asp:Label>

      <asp:TextBox ID="TextBox2" runat="server"
Text='<%#Eval("currentadd") %>'
Visible="false"></asp:TextBox>
        </td>
         <td>

      <asp:LinkButton ID="LinkEdit" runat="server"
CommandArgument='<%#Eval("id") %>'
CommandName="edit">Edit</asp:LinkButton>

          <asp:LinkButton ID="LinkDelete" runat="server"
CommandArgument='<%#Eval("id") %>'
CommandName="delete">Delete</asp:LinkButton>

          <asp:LinkButton ID="LinkUpdate" runat="server"
CommandArgument='<%#Eval("id") %>' CommandName="update"
Visible="false">Update</asp:LinkButton>

          <asp:LinkButton ID="Linkcancel" runat="server"
CommandArgument='<%#Eval("id") %>' CommandName="cancel"
Visible="false">Cancel</asp:LinkButton>
            </td>
        </tr>
           
     
       
        </ItemTemplate>
        </asp:Repeater>
   
    </div>
    </form>
</body>
</html>
---------------------------

Monday 5 January 2015

Random Number in Sql Server

Random Number in Sql Server
--------------------------

declare  @RandomNumber bigint
SELECT  @RandomNumber= CAST(RAND() *

100000000 AS bigint)
print @RandomNumber

IUD IN EntityFramework

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.Entity;
using System.Data.SqlClient;
namespace DemoEntityFrameWork
{
    public partial class Default2 : System.Web.UI.Page
    {
        DBPABITRAEntities dbcontext = new DBPABITRAEntities();
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void btnSave_Click(object sender, EventArgs e)
        {
        TBL_EMP_ENTITY ob = new TBL_EMP_ENTITY();

        try
        {
            ob.EM_ID = int.Parse(TextBox1.Text);
            ob.EM_NAME = TextBox2.Text;
            ob.EM_STATUS = "1";
            dbcontext.TBL_EMP_ENTITY.Add(ob);
            dbcontext.SaveChanges();
            TextBox1.Text = "";
            TextBox2.Text = "";
            Response.Write("<script>alert('Save Sucessfully !');</script>");
        }catch(SqlException ex)
        {
            throw ex;
        }
        catch (Exception ex)
        {
            throw ex;
        }
     
   

           
        }

        protected void Button1_Click(object sender, EventArgs e)
        {

        }

        protected void btnUpdate_Click(object sender, EventArgs e)
        {
            DBPABITRAEntities db = new DBPABITRAEntities();
            int ID=Convert.ToInt32(TextBox1.Text);
            var empQuery = from emp in db.TBL_EMP_ENTITY
                           where emp.EM_ID == ID
                           select emp;
            TBL_EMP_ENTITY ob = empQuery.Single();
            ob.EM_ID = int.Parse(TextBox1.Text);
            ob.EM_NAME = TextBox2.Text;
            ob.EM_STATUS = "1";          
          int x=  db.SaveChanges();
          Response.Write(x.ToString()+"Record Will be Updated......");
        }

        protected void btnDelete_Click(object sender, EventArgs e)
        {
            DBPABITRAEntities db = new DBPABITRAEntities();
            int ID = Convert.ToInt32(TextBox1.Text);
            //create a new object using the value of EmpId
            TBL_EMP_ENTITY objEmp = new TBL_EMP_ENTITY() { EM_ID = ID };

            //attach and delete object
            db.TBL_EMP_ENTITY.Attach(objEmp);
           
            //db.TBL_EMP_ENTITYS.DeleteObject(objEmp);

            //save changes
            db.SaveChanges();
        }
    }
}

Encryption of procedure in sql server

create PROCEDURE MyProcedure WITH ENCRYPTION AS
BEGIN
 PRINT 'This text is going to be decrypted'
END