Saturday, 3 October 2015

In GridView MouseOver Event Get Another Information based on gridview(StateName with City Name)

Design Page

css

<style type="text/css">
        body 
        {
            font-family:Arial, Tahoma;
            font-size:15px;
        }
        .grid 
        {
            width:100%;
            font:inherit;
            background-color:#FFF;
            border:solid 1px #525252;
        }
        .grid td
        {
            font:inherit;
            padding:3px 5px;
            border:solid 1px #C1C1C1;
            color:#333;
            text-align:left;
        }
        .grid th 
        {
            padding:3px;
            color:#FFF;
            background:#424242;
            border-left:solid 1px #525252;
            font:inherit;
            text-align:center;
            text-transform:uppercase;
        }       
        h3
        {
            color:#000;
            text-decoration:underline;
        }
        #divDetail 
        {
            float:left;
            font:inherit;
            font-size:13px;
            padding:2px 5px;
            width:auto;
            border:solid 2px #CCC;
            -moz-border-radius:0 7px 7px 0; -webkit-border-radius:0 7px 7px 0;
            border-radius:0 7px 7px 0;
            display:none;
            color:#333;
        }
        #divDetail p {
            font:inherit;
        }
        #divDetail a 
        {
            font:inherit;
            float:right;
            background-color:#357AE8;
            color:#FFF;
            text-decoration:none;
            border:solid 1px #2F5BB7;
            border-radius:3px; -moz-border-radius:3px; -webkit-border-radius:3px;
            padding:3px;
        }
    </style>


Script

<script type="text/javascript">       
        var iRowIndex;    // THE ROW INDEX OF THE GRIDVIEW, TO KEEP THE ROW HIGHLIGHTING
                    // WHEN THE MOUSE IS ON ANOTHER CONTROL.

        function MouseEvents(objRef, evt, desc) {

            if (evt.type == "mouseover") {

                objRef.style.cursor = 'pointer'
                objRef.style.backgroundColor = "#EEE";
                ShowDiv(desc, evt.pageY);

            }
            else {

                objRef.style.backgroundColor = "#FFF";
                iRowIndex = objRef.rowIndex;
                HideDiv();

            }
        }
        function ShowDiv(desc, pos) {

            // SHOW THE DIV WITH DESCRIPTIONS NEXT TO THE SELECTED GRIDVIEW ROW.

            document.getElementById('divDetail').style.display = 'block';
            document.getElementById('divDetail').innerHTML = desc;
            document.getElementById('divDetail').style.marginTop = pos - 25 + 'px';
        }

        function HideDiv() { document.getElementById('divDetail').style.display = 'none'; }

        function highlight(objRef, evt) {
            if (evt.type == "mouseover") {
                objRef.style.display = 'block';
                document.getElementById('gvEmployee').rows[iRowIndex].style.backgroundColor = "#EEE";
            }
            else {
                if (evt.type == "mouseout") {
                    document.getElementById('gvEmployee').rows[iRowIndex].style.backgroundColor = "#FFF";
                    objRef.style.display = 'none';
                }
            }
        }
    </script>


Design 
<div id="divGrid" style="width:auto; float:left">

            <h3>LIST OF EMPLOYEES</h3>
           
            <%--THE DATABOUND GRIDVIEW CONTROL.--%>
            <asp:GridView ID="gvEmployee" AutoGenerateColumns="False" OnRowDataBound ="gvEmployee_RowDataBound"
                CssClass="grid" GridLines="None"
                cellpadding="3" runat="server">

                <Columns>
                    <asp:BoundField DataField="StateId" HeaderText="Code" />
                    <asp:BoundField DataField="StateName" HeaderText="Name" />
                </Columns>

                <HeaderStyle BackColor="Black" ForeColor="white" />

            </asp:GridView>
        </div>
       
        <%--THE FLOATING DIV TO SHOW EMPLOYEE DETAILS.--%>
        <div runat="server" id="divDetail" onmouseover="highlight(this, event)"
            onmouseout="highlight(this, event)"></div>


Code Page

protected void Page_Load(object sender, EventArgs e)
        {
            string constr = ConfigurationManager.ConnectionStrings["DBConnection"].ConnectionString;           
            SqlConnection con = new SqlConnection(constr);
            SqlDataAdapter da = new SqlDataAdapter("select StateId, StateName from StateMaster", con);
            DataTable dt = new DataTable();
            da.Fill(dt);

            gvEmployee.DataSource = dt;
            gvEmployee.DataBind();
        }


        protected void gvEmployee_RowDataBound(object sender, System.Web.UI.WebControls.GridViewRowEventArgs e)
        {
            // BIND DATA WITH EACH ROW.
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                String sDetails = System.String.Empty;
                sDetails = "<span><h3>OTHER DETAILS</h3></span>";

                string constr = ConfigurationManager.ConnectionStrings["DBConnection"].ConnectionString;
                using (SqlConnection con = new SqlConnection(constr))
                {
                    using (SqlCommand cmd = new SqlCommand("select * from CityMaster WHERE StateId = " +
                            DataBinder.Eval(e.Row.DataItem, "StateId").ToString()))
                    {
                        SqlDataAdapter sda = new SqlDataAdapter();
                        try
                        {
                            cmd.Connection = con;
                            con.Open();
                            sda.SelectCommand = cmd;

                            DataTable dt = new DataTable();
                            sda.Fill(dt);

                            if (dt.Rows.Count > 0)
                            {
                                sDetails = sDetails + "<p><strong>City Code: </strong>" +
                                    dt.Rows[0]["CityCode"] + "</p>";
                                sDetails = sDetails + "<p><strong>City Name: </strong>" +
                                    dt.Rows[0]["CityName"] + "</p>";

                                // BIND MOUSE EVENT (TO CALL JAVASCRIPT FUNCTION), WITH EACH ROW OF THE GRID.
                                e.Row.Attributes.Add("onmouseover", "MouseEvents(this, event, '" + sDetails + "')");
                                e.Row.Attributes.Add("onmouseout", "MouseEvents(this, event, '" +
                                    DataBinder.Eval(e.Row.DataItem, "StateId").ToString() + "')");
                            }

                        }
                        catch (Exception ex)
                        {
                        }
                    }
                }
            }
        }


OUTPUT
 


Monday, 19 May 2014

How to Clear All Stored Procedure in Particular DataBase

USE myDatabase //Database Name

GOdeclare @procName sysname declare someCursor cursor for select name from sysobjects where type = 'P' and objectproperty(id, 'IsMSShipped') = 0open someCursor fetch next from someCursor into @procName while @@FETCH_STATUS = while @@FETCH_STATUS = while @@FETCH_STATUS = 0begin exec('drop proc ' + @procName) fetch next from someCursor into @procName endclose someCursor deallocate someCursor go

Saturday, 17 May 2014

Text box has to allow only characters in Asp.Net


In Text box Design Coding:

<asp:TextBox ID="txtAffwith" runat="server" BackColor="White" onkeypress="return isNameKey(event)"
                    Font-Names="Verdana" Font-Size="9pt" Height="18px" Width="190px"
                                MaxLength="50"></asp:TextBox>


Text box has to allow only characters:

function isNameKey(evt) {
        var charCode = (evt.which) ? evt.which : event.keyCode
        if ((charCode <= 93 && charCode >= 65) || (charCode <= 122 && charCode >= 97){
            return true;
        }
        else {
            return false;
        }
    }


Text box has to allow only characters with Space:

function isNameKey(evt) {
        var charCode = (evt.which) ? evt.which : event.keyCode
        if ((charCode <= 93 && charCode >= 65) || (charCode <= 122 && charCode >= 97) || (charCode == 32) ){
            return true;
        }
        else {
            return false;
        }
    }

Text box has to allow only numbers:


function isNumberKey1(evt) {
        var charCode = (evt.which) ? evt.which : event.keyCode
        if (charCode < 48 || charCode > 57) {
            return false;
        }
        else {
            return true;
        }
    }



Text box has to allow only numbers with dots:


function isNumberKey(evt) {
        var charCode = (evt.which) ? evt.which : event.keyCode
        if (charCode != 46 && (charCode < 48 || charCode > 57)) {
            return false;
        }
        else {
            return true;
        }
    }


jQuery - Allow Alphanumeric (Alphabets & Numbers)

 Characters in Textbox using JavaScript


<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>jQuery Allow only alphanumeric characters in textbox</title>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.8.2.js"></script>
<script type="text/javascript">
$(function () {
$('#txtNumeric').keydown(function (e) {
if (e.shiftKey || e.ctrlKey || e.altKey) {
e.preventDefault();
else {
var key = e.keyCode;
if (!((key == 8) || (key == 32) || (key == 46) || (key >= 35 && key <= 40) || (key >= 65 && key <= 90) || (key >= 48 && key <= 57) || (key >= 96 && key <= 105))) {
e.preventDefault();
}
}
});
});
</script>
</head>
<body>
<div>
<b>Enter Text:</b><input type="text" id="txtNumeric" />
</div>
</body>
</html>






Friday, 9 May 2014

In School Attendance Report For Month Wise

Design Page



Default.aspx.cs

int GetDaysInMonth(int month, int year)
    {
        if (month < 1 || month > 12)
        {
            throw new System.ArgumentOutOfRangeException("month", month, "month mustbe between 1 and 12");
        }
        if (1 == month || 3 == month || 5 == month || 7 == month || 8 == month || 10 == month || 12 == month)
        {
            return 31;
        }
        else if (2 == month)
        {
            if (0 == (year % 4))
            {
                if (0 == (year % 400))
                {
                    return 29;
                }
                else if (0 == (year % 100))
                {
                    return 28;
                }
                return 29;
            }
            return 28;
        }
        return 30;
    }

protected void btnReport_Click(object sender, EventArgs e)
    {
        string bno = DrpBatchNo.SelectedValue.ToString().Trim();
        string icode = DrpInsName.SelectedValue.ToString().Trim();

        string year21 = txtYear.Text.ToString().Trim();
        string month21 = DrpMonth.SelectedValue.ToString().Trim();

        int year = 0;
        if (year21 != "")
        {
            year = Convert.ToInt32(year21);
        }
        int month = 0;
        if (month21 != "")
        {
            month = Convert.ToInt32(month21);
        }

        if (year21.Length == 4)
        {
            if ((bno != "All" || bno != "") && (icode != "All" || icode != ""))
            {

               //Check No Of Days
                int days = GetDaysInMonth(Convert.ToInt32(DrpMonth.SelectedValue), Convert.ToInt32(txtYear.Text.ToString().Trim()));

                //Create a DataTable
                DataTable myDT = new DataTable();
                for (int i = 1; i <= days; i++)
                {
                    if (i == 1)
                    {                        
                        DataColumn id2 = new DataColumn("id");
                        //Create a First column Name
                        id2.ColumnName = "Member Code";
                        id2.MaxLength = 60; 
                        myDT.Columns.Add(id2);

                        DataColumn id1 = new DataColumn("id");
                        //Create a First Second Name
                        id1.ColumnName = "Member Name";
                        id1.MaxLength = 60; 
                        myDT.Columns.Add(id1);
                    }
                    
                    // loop end after i < = days 
                    DataColumn id = new DataColumn("id");
                    // i is a day 1 column until end of days
                    id.ColumnName = i.ToString("#00");
                    id.MaxLength = 4; 
                    myDT.Columns.Add(id);
                }

                for (int i = 1; i <= 1; i++)
                {                    
                    // This Datatable is used to select all members from member table  
                    DataTable dt = TRN.RGetAttendance(bno);
                    if (dt.Rows.Count > 0)
                    {
                        for (int j = 0; j < dt.Rows.Count; j++)
                        {
                            DataRow dr = myDT.NewRow();

                            string name = dt.Rows[j][1].ToString();
                            string mcode = dt.Rows[j][0].ToString();
                            
                            // single Member code until end of month days
                            for (int ii = 0; ii <= days + 1; ii++)
                            {
                                if (ii == 0)
                                {
                                    dr[ii] = mcode;
                                }
                                if (ii == 1)
                                {
                                    dr[ii] = name;
                                }
                                else if (ii > 1)
                                {
                                    string attdate = (ii - 1).ToString("#00") + "/" + month.ToString("#00") + "/" +                                                                         year.ToString("#0000");
                                    string day1 = attdate.Substring(0, 2);
                                    string month1 = attdate.Substring(3, 2);
                                    string year1 = attdate.Substring(6, 4);
                                    int day11 = 0;
                                    int month11 = 0;
                                    int year11 = 0;
                                    if (day1 != "" && month1 != "" && year1 != "")
                                    {
                                        day11 = Convert.ToInt32(day1);
                                        month11 = Convert.ToInt32(month1);
                                        year11 = Convert.ToInt32(year1);
                                        attdate = datetimeconvert(year11, month11, day11);
                                    }

                                    // This Datatable is used to select a data from member code 
                                    DataTable dt1 = TRN.RGetAttendance1(mcode, attdate);

                                    if (dt1.Rows.Count > 0)
                                    {
                                        string status = dt1.Rows[0][3].ToString();
                                        dr[ii] = status;
                                    }
                                }
                            }
                            // add a name, code, no of days present or absent
                            myDT.Rows.Add(dr);
                        }
                    }
                }
                //Bind All rows in Gridview
                GrdAttendance.DataSource = myDT;
                GrdAttendance.DataBind();
            }
            else
            {
                ScriptManager.RegisterStartupScript(this, typeof(Page), "Alert", "<script>alert('" + "Select Valid Institute and Batch Name" + "');</script>", false);
            }
        }
        else
        {
            ScriptManager.RegisterStartupScript(this, typeof(Page), "Alert", "<script>alert('" + "Enter a Valid Year" + "');</script>", false);
        }
    }


public static string datetimeconvert(int a, int b, int c)
    {
        string ye2 = Convert.ToString(a);
        string mo2 = Convert.ToString(b);
        string da2 = Convert.ToString(c);

        if (mo2.Length == 1)
        {
            mo2 = "0" + mo2;
        }
        if (da2.Length == 1)
        {
            da2 = "0" + da2;
        }

        string[] allStr = new String[] { mo2, da2, ye2 };
        string datetime = String.Join("/", allStr);

        return datetime;
    }

Table

CREATE TABLE [dbo].[attendance_dtl](
[attend_date] [smalldatetime] NULL,
[attend_time] [varchar](20) NULL,
[attend_membercode] [varchar](25) NULL,
[attend_status] [char](1) NULL,
[attend_batchno] [varchar](20) NULL,
[attend_institute_code] [int] NULL
) 

Stored Procedure in Sql

CREATE PROCEDURE [dbo].[Sp_RGetAttendance] 
@bno varchar(100)
AS      
BEGIN 

Select trainee_dtl.trainee_membercode, trainee_dtl.trainee_membername from trainee_dtl
where trainee_dtl.trainee_course_batchno = @bno 
END


CREATE PROCEDURE [dbo].[Sp_RGetAttendance1] 
@mcode varchar(100),
@attdate smalldatetime
AS      
BEGIN 

Select tnpvp_attendance_dtl.*  from attendance_dtl
      where attendance_dtl.attend_membercode = @mcode and attendance_dtl.attend_date = @attdate 
END

Output





Example of XML with XSLT

In Books.xml

<?xml version="1.0"?>
<Books>
      <Book>
             <Title>Beginning XML</Title>
             <Author>John</Author>
     </Book>
     <Book>
            <Title>Mastering XML</Title>
            <Author>Peter</Author>
     </Book>
</Books>

In Books.xml

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">   
   <xsl:template match="Books"> 
           <HTML>
           <BODY>
           <TABLE>
             <TR>
               <TD>Title</TD>
               <TD>Author</TD>
             </TR>
             <xsl:for-each select="Book">
               <TR>
                 <TD><xsl:value-of select="Title"/></TD>
                 <TD><xsl:value-of select="Author"/></TD>
               </TR>
             </xsl:for-each>
           </TABLE>     
           </BODY>
     </HTML>    
  </xsl:template>     
</xsl:stylesheet>

In Default.aspx Page

Add Xml icon From the toolbox

In Default.aspx.cs Page

//coding type 1
        string xmlPath = Server.MapPath("Books.xml");
        string xsltPath = Server.MapPath("Books.xslt");        

        XmlReader objXMlReader = XmlReader.Create(xmlPath);
        XslCompiledTransform objXSLCompTransform =
                                  new XslCompiledTransform();
        objXSLCompTransform.Load(xsltPath);

        StringBuilder objStrBuil = new StringBuilder();
        TextWriter objTextWri = new StringWriter(objStrBuil);

        objXSLCompTransform.Transform(objXMlReader, null, objTextWri);

        Literal1.Text = objStrBuil.ToString();
        objXMlReader.Close();

                            (Or)

//coding type 2
      Xml1.DocumentSource = Request.QueryString[0];
      Xml1.TransformSource = Request.QueryString[1];


Output For Coding Type1




Output For Coding Type2






Friday, 21 March 2014

How to Display without using Crystal Report(Windows Print)



  1. Select a Print Document, Print Preview Dialog, Print Dialog(all selected) under Printing Tools in   Toolbox.
  2. In Print Button
               //Create a PrintDocument object
                 PrintDocument pd = new PrintDocument();
                ////Add print-page event handler
                pd.PrintPage += new PrintPageEventHandler(pd_PrintPage);
                //Set Document property of PrintPreviewDialog
                
                printPreviewDialog1.Document = pd;

                ((Form)printPreviewDialog1).WindowState = FormWindowState.Maximized;

                DialogResult dr = printPreviewDialog1.ShowDialog();

    3. public void pd_PrintPage(object sender, PrintPageEventArgs e)
        {
            SqlConnection con = new SqlConnection(conn);
            con.Open();

            Font font = new Font("Microsoft Sans Serif", 14F,
                                System.Drawing.FontStyle.Bold,
                                System.Drawing.GraphicsUnit.Point,
                                ((byte)(0)));

            Font font2 = new Font("Microsoft Sans Serif", 14F,
                          System.Drawing.FontStyle.Regular,
                          System.Drawing.GraphicsUnit.Point,
                             ((byte)(0)));
            Graphics g = e.Graphics;

            string vouno = txtCDNo.Text.ToString().Trim();
            string transdate = dtpDate.Value.ToString().Trim();
            transdate = transdate.Substring(0, 10);
            string recname = txtCSName.Text.ToString().Trim();
            string amount = txtAmount.Text.ToString().Trim();
            double amt = 0;
            if (amount != "")
            {
                amt = Convert.ToDouble(amount);
            }
            string narr1 = txtNarration.Text.ToString().Trim();
            string narr2 = txtNarration2.Text.ToString().Trim();

            string custoname = "";
            string addres1 = "";
            string addres2 = "";
            string addres3 = "";
            string city = "";
            string pincode = "";  

            if (radioCredit.Checked == true)
            {
                g.DrawString("CREDIT NOTE", font, System.Drawing.Brushes.Black, 50, 25);

                string find = "select * from IBS_CUSTOMER_MST where Cust_Id = '" + cid + "'";
                SqlCommand findquery = new SqlCommand(find, con);
                SqlDataReader dr = findquery.ExecuteReader();
                if (dr.Read())
                {
                    custoname = dr["Cust_Name"].ToString();
                    addres1 = dr["Cust_Add1"].ToString();
                    addres2 = dr["Cust_Add2"].ToString();
                    addres3 = dr["Cust_Add3"].ToString();
                    city = dr["Cust_City"].ToString();
                    pincode = dr["Cust_Pin"].ToString();
                }
                dr.Close();
            }
            else
            {
                g.DrawString("DEBIT NOTE", font, System.Drawing.Brushes.Black, 50, 25);

                string find = "select * from IBS_SUPPLIER_MST where Sup_Id = '" + cid + "'";
                SqlCommand findquery = new SqlCommand(find, con);
                SqlDataReader dr = findquery.ExecuteReader();
                if (dr.Read())
                {
                    custoname = dr["Sup_Name"].ToString();
                    addres1 = dr["Sup_Add1"].ToString();
                    addres2 = dr["Sup_Add2"].ToString();
                    addres3 = dr["Sup_Add3"].ToString();
                    city = dr["Sup_City"].ToString();
                    pincode = dr["Sup_Pin"].ToString();
                }
                dr.Close();
            }

            g.DrawString("Ledger Name", font, System.Drawing.Brushes.Black, 0, 75);
            g.DrawString("Address", font, System.Drawing.Brushes.Black, 0, 125);

            g.DrawString("Voucher No", font, System.Drawing.Brushes.Black, 450, 75);
            g.DrawString("Date", font, System.Drawing.Brushes.Black, 450, 125);

            g.DrawString("S.No", font, System.Drawing.Brushes.Black, 30, 230);
            g.DrawString("Descripation", font, System.Drawing.Brushes.Black, 90, 230);
            g.DrawString("Amount", font, System.Drawing.Brushes.Black, 400, 230);
            //g.DrawString("Address", font, System.Drawing.Brushes.Black, 300, 300);        

            int place = 150;

            g.DrawString(custoname, font2, System.Drawing.Brushes.Black, place, 75);
            g.DrawString(addres1, font2, System.Drawing.Brushes.Black, place, 125);
            g.DrawString(addres2, font2, System.Drawing.Brushes.Black, place, 145);
            g.DrawString(addres3, font2, System.Drawing.Brushes.Black, place, 165);
            g.DrawString(city, font2, System.Drawing.Brushes.Black, place, 185);
            g.DrawString(pincode, font2, System.Drawing.Brushes.Black, place, 205);

            g.DrawString(vouno, font2, System.Drawing.Brushes.Black, place + 450, 75);
            g.DrawString(transdate, font2, System.Drawing.Brushes.Black, place + 450, 125);

            g.DrawString(vouno, font2, System.Drawing.Brushes.Black, 30, 270);
            g.DrawString(narr1, font2, System.Drawing.Brushes.Black, 90, 270);
            g.DrawString(narr2, font2, System.Drawing.Brushes.Black, 90, 290);
            g.DrawString(amt.ToString("#0.00"), font2, System.Drawing.Brushes.Black, 400, 270);


            e.HasMorePages = false;  
        }

  4. Output Page