Tuesday, 20 November 2012

In Text Only Numeric Value is inter&&In Text Only Char Are inter Value

<head runat="server">

  <script type="text/javascript">
        function FilterInput (event) {
            var keyCode = ('which' in event) ? event.which : event.keyCode;

            isNumeric = (keyCode >= 48 && keyCode <= 57) ||
                        (keyCode >= 96  && keyCode <= 105 );
            modifiers = (event.altKey || event.ctrlKey || event.shiftKey);
            return !isNumeric || modifiers;
        }
    </script>

 <script type="text/javascript">

        function isNumeric(keyCode)
        {
           // return ((keyCode >= 48 && keyCode <= 57) || keyCode == 8)
            return (((keyCode >= 48 && keyCode <= 57)||(keyCode >= 96
&& keyCode <= 105) ) || keyCode == 8)
        }
    </script>
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <h2>In Text Only Numeric Value is inter</h2>
      <asp:TextBox ID="TextBox1"   onkeydown = "return
isNumeric(event.keyCode);"     autocomplete="off" runat="server"
MaxLength="3"></asp:TextBox>
  <h2>In Text Only Char Are inter Value </h2>
       <asp:TextBox ID="TextBox2" onkeydown="return FilterInput
(event)" runat="server"></asp:TextBox>
    </div>
    </form>

</body>

Thursday, 15 November 2012

Web Config/ interface IService/class Service

web Config:

    <appSettings>
        <add key="connectionxyz" value="Initial Catalog=Test;server=con-23EC9119BAD;integrated security  =true"/>
    </appSettings>


 IService:-

using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Web;
using System.Text;
using System.Data;
using System.Data.SqlClient;
// NOTE: You can use the "Rename" command on the "Refactor" menu to change the interface name "IService" in both code and config file together.
[ServiceContract]
public interface IService
{
    [OperationContract]
    DataSet getAllDataForUserList1();
    [OperationContract]
    DataSet GetDatabyRecid(int i);
    [OperationContract]
    long AddNewRecord(DataSet ds);
    [OperationContract]
    long UpdateRecords(DataSet ds1, long i);
    [OperationContract]
    long DeletetripRecord(int i);
    [OperationContract]
    DataSet GetAllCountry();
   
}

// Use a data contract as illustrated in the sample below to add composite types to service operations.
[DataContract]
public class CompositeType
{
    //bool boolValue = true;
    //string stringValue = "Hello ";

    //[DataMember]
    ////public bool BoolValue
    //{
    //    get { return boolValue; }
    //    set { boolValue = value; }
    //}

    //[DataMember]
    //public string StringValue
    //{
    //    get { return stringValue; }
    //    set { stringValue = value; }
    //}
}

Service:-

using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Web;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using System.Transactions;


// NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "Service" in code, svc and config file together.
public class Service : IService

{
    string cnnstr = System.Configuration.ConfigurationManager.AppSettings["connectionxyz"];
    SqlConnection CNN = new SqlConnection();
    public Service()
    {
        CNN.ConnectionString = cnnstr;
    }

    public DataSet GetAllCountry()

    {

        DataSet dsGlobal = new DataSet();
        try
        {
            SqlDataAdapter adapGlobal = new SqlDataAdapter();
            SqlCommand cmd = new SqlCommand();
            try
            {
                if (CNN.State == ConnectionState.Closed)
                    CNN.Open();
            }
            catch (Exception ex)
            {
                CNN.Close();
            }
            if (CNN.State == ConnectionState.Closed)
                CNN.Open();
            cmd.Connection = CNN;
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.Clear();
            cmd.CommandText = "GetCountryName";
            adapGlobal.SelectCommand = cmd;
            adapGlobal.Fill(dsGlobal);
        }
        catch (Exception ex)
        {
        }
        finally
        {
            CNN.Close();

        }

        return dsGlobal;

    }

   public  DataSet getAllDataForUserList1()
    {
        DataSet dsGlobal = new DataSet();
        try
        {
            SqlDataAdapter adapGlobal = new SqlDataAdapter();
            SqlCommand cmd = new SqlCommand();
            try
            {
                if (CNN.State == ConnectionState.Closed)
                    CNN.Open();
            }
            catch (Exception ex)
            {
                CNN.Close();
            }
            if (CNN.State == ConnectionState.Closed)
                CNN.Open();
            cmd.Connection = CNN;
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.Clear();
            cmd.CommandText = "jktveiwdata1";
            adapGlobal.SelectCommand = cmd;
            adapGlobal.Fill(dsGlobal);
        }
        catch (Exception ex)
        {
        }
        finally
        {
            CNN.Close();

        }

        return dsGlobal;

    }

   public DataSet GetDatabyRecid(int ik)
   {
       DataSet ds = new DataSet();
       SqlCommand cmd = new SqlCommand();
       SqlDataAdapter da = new SqlDataAdapter();
       try
       {
           cmd.Connection = CNN;
           cmd.CommandType = CommandType.StoredProcedure;
           cmd.CommandText = "GetRecordsByRecId";
           cmd.Parameters.AddWithValue("@RecId", ik);
           da = new SqlDataAdapter(cmd);
           da.Fill(ds);
           if (ds.Tables.Count > 0)
           {
               return ds;

           }

       }
       catch (Exception ex)
       {
           CNN.Close();
           return ds;
       }
       return ds;

   }

   public long AddNewRecord(DataSet ds)
   {
       SqlTransaction SQLT = null;
       int recId = 0;
       bool Berror = false;
       SqlCommand CMD = new SqlCommand();
       try
       {
           try
           {
               if (CNN.State == ConnectionState.Closed)
                   CNN.Open();
           }
           catch (Exception ex)
           {
               throw ex;
           }
           finally
           {
           }
           SQLT = CNN.BeginTransaction();
           CMD.Transaction = SQLT;
           CMD.Connection = CNN;
           DataTable dttripstart = new DataTable();
           dttripstart = ds.Tables[0];
           CMD.CommandType = CommandType.StoredProcedure;
           CMD.CommandText = "SaveAddressRecord1";
           CMD.Parameters.Clear();
           CMD.Parameters.AddWithValue("@title", dttripstart.Rows[0]["Title"]);
           CMD.Parameters.AddWithValue("@Firstname", dttripstart.Rows[0]["Firstname"]);
           CMD.Parameters.AddWithValue("@Middlename", dttripstart.Rows[0]["Middlename"]);
           SqlParameter SQLPar = new SqlParameter();
           SQLPar = CMD.Parameters.Add("RETURN_VALUE", SqlDbType.BigInt);
           SQLPar.Direction = ParameterDirection.ReturnValue;

           recId = CMD.ExecuteNonQuery();
           //int i = (int)CMD.Parameters["RETURN_VALUE"].Value;
           if (recId == 0)
           {
               Berror = true;

           }

           if (Berror == true)
           {
               CMD.Transaction.Rollback();
               return 0;
           }
           else
           {
               CMD.Transaction.Commit();

           }

       }
       catch (Exception ex)
       {
       }
       finally
       {
           if (CNN.State != ConnectionState.Closed)
               CNN.Close();
       }
       return recId;
  
  
   }
   public long UpdateRecords(DataSet ds1, long i)
   {
       SqlTransaction SQLT = null;
       long recId = 0;
       bool Berror = false;
       SqlCommand CMD = new SqlCommand();
       try
       {
           try
           {
               if (CNN.State == ConnectionState.Closed)
                   CNN.Open();
           }
           catch (Exception ex)
           {
               throw ex;
           }
           finally
           {
           }
           SQLT = CNN.BeginTransaction();
           CMD.Transaction = SQLT;
           CMD.Connection = CNN;
           DataTable dttripstart = new DataTable();
           dttripstart = ds1.Tables[0];
           CMD.CommandType = CommandType.StoredProcedure;
           CMD.CommandText = "updaterecord23";
           CMD.Parameters.Clear();
           CMD.Parameters.AddWithValue("@id", i);
           CMD.Parameters.AddWithValue("@title", dttripstart.Rows[0]["Title"]);
           CMD.Parameters.AddWithValue("@Firstname", dttripstart.Rows[0]["Firstname"]);
           CMD.Parameters.AddWithValue("@Middlename", dttripstart.Rows[0]["Middlename"]);
           SqlParameter SQLPar = new SqlParameter();
           SQLPar = CMD.Parameters.Add("RETURN_VALUE", SqlDbType.BigInt);
           SQLPar.Direction = ParameterDirection.ReturnValue;
           recId = CMD.ExecuteNonQuery();
           //int i = (int)CMD.Parameters["RETURN_VALUE"].Value;
           if (recId == 0)
           {
               Berror = true;

           }

           if (Berror == true)
           {
               CMD.Transaction.Rollback();
               return 0;
           }
           else
           {
               CMD.Transaction.Commit();

           }

       }
       catch (Exception ex)
       {
       }
       finally
       {
           if (CNN.State != ConnectionState.Closed)
               CNN.Close();
       }
       return recId;
   }

   public long DeletetripRecord(int ik1)
   {

       SqlTransaction SQLT = null;

       int recId = 0;
       bool Berror = false;
       SqlCommand CMD = new SqlCommand();
       try
       {
          try
           {
               if (CNN.State == ConnectionState.Closed)
                   CNN.Open();
           }
           catch (Exception ex)
           {
               throw ex;

           }
           finally
           {
           }
     
           SQLT = CNN.BeginTransaction();
           CMD.Transaction = SQLT;
           CMD.Connection = CNN;
      
           CMD.CommandType = CommandType.StoredProcedure;
           CMD.CommandText = "DelEeg11";
           CMD.Parameters.Clear();
           CMD.Parameters.AddWithValue("@RecId", ik1);
         
           SqlParameter SQLPar = new SqlParameter();
           SQLPar = CMD.Parameters.Add("RETURN_VALUE", SqlDbType.BigInt);
           SQLPar.Direction = ParameterDirection.ReturnValue;

           recId = CMD.ExecuteNonQuery();
           int i = (int)CMD.Parameters["RETURN_VALUE"].Value;
           if (i == 0)
           {
               Berror = true;

           }

           if (Berror == true)
           {
               CMD.Transaction.Rollback();
               return 0;
           }
           else
           {
               CMD.Transaction.Commit();

           }

       }
       catch (Exception ex)
       {
       }
       finally
       {
           if (CNN.State != ConnectionState.Closed)
               CNN.Close();
       }
       return recId;


   }


    //public string GetData(int value)

    //{
    //    return string.Format("You entered: {0}", value);
    //}

    //public CompositeType GetDataUsingDataContract(CompositeType composite)
    //{
    //    if (composite == null)
    //    {
    //        throw new ArgumentNullException("composite");
    //    }
    //    if (composite.BoolValue)
    //    {
    //        composite.StringValue += "Suffix";
    //    }
    //    return composite;
    //}
}


Monday, 12 November 2012

Simple Page Coding Cs.Page

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

<!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 runat="server">
    <title></title>
    <style type="text/css">
        .style1
        {
            width: 100%;
        }
        .style2
        {
            width: 239px;
        }
        .style3
        {
            width: 187px;
        }
    </style>
</head>
<body>
    <form id="form1" runat="server">
    <div>
  
        <table class="style1">
            <tr>
                <td class="style2">
                    Title</td>
                <td class="style3">
                    <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
                </td>
                <td>
                    <br />
                    <br />
                </td>
            </tr>
            <tr>
                <td class="style2">
                    Firstname
                </td>
                <td class="style3">
                    <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
                </td>
                <td>
                    &nbsp;</td>
            </tr>
            <tr>
                <td class="style2">
                    Middlename</td>
                <td class="style3">
                    <asp:TextBox ID="TextBox3" runat="server"></asp:TextBox>
                </td>
                <td>
                    &nbsp;</td>
            </tr>
            <tr>
                <td class="style2">
                    <asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Save" />
                </td>
                <td class="style3">
                    <asp:Button ID="Button2" runat="server"
                        Text="Modified" onclick="Button2_Click" />
                    <asp:Button ID="Button3" runat="server" Text="Deleted"
                        onclick="Button3_Click" />
                    <asp:Button ID="Button4" runat="server" Text="Cancel" />
                </td>
                <td>
                    &nbsp;</td>
            </tr>
            <tr>
                <td class="style2">
                    &nbsp;</td>
                <td class="style3">
                    <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns =false
                        CellPadding="4" ForeColor="#333333"
                        GridLines="None" Height="90px"
                     Width="332px" >
                        <AlternatingRowStyle BackColor="White" />
                        <FooterStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
                        <HeaderStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
                        <PagerStyle BackColor="#FFCC66" ForeColor="#333333" HorizontalAlign="Center" />
                        <RowStyle BackColor="#FFFBD6" ForeColor="#333333" />
                        <SelectedRowStyle BackColor="#FFCC66" Font-Bold="True" ForeColor="Navy" />
                        <SortedAscendingCellStyle BackColor="#FDF5AC" />
                        <SortedAscendingHeaderStyle BackColor="#4D0000" />
                        <SortedDescendingCellStyle BackColor="#FCF6C0" />
                        <SortedDescendingHeaderStyle BackColor="#820000" />
                         <Columns>
                          <asp:BoundField  DataField="Id" HeaderText="Id"/>
                          <asp:BoundField  DataField="Title" HeaderText="Title"/>
                          <%--<asp:BoundField  DataField="Firstname" HeaderText="Firstname"/>--%>
                          <asp:BoundField  DataField="MiddleName" HeaderText="MiddleName"/>
                          <asp:HyperLinkField DataNavigateUrlFields="ID" DataNavigateUrlFormatString="Empmaster.aspx?id={0}"
                                    DataTextField="Firstname" HeaderText="First name" />
                          </Columns>

                    </asp:GridView>
                </td>
                <td>
                    &nbsp;</td>
            </tr>
        </table>
  
    </div>
    </form>
</body>
</html>





************************************************


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.Data.SqlClient;



public partial class Empmaster : System.Web.UI.Page
{
    public int id;
    Runtype run = new Runtype();

   protected void Page_Load(object sender, EventArgs e)
    {
       
    
        if (!Page.IsPostBack)
        {
            GetDataItem();
            id = Convert.ToInt32(Page.Request.QueryString["id"]);


            if (id > 0)
            {
                DataSet Ds = new DataSet();
                Ds = run.GetDataByRecid(id);
                TextBox1.Text = Ds.Tables[0].Rows[0]["Title"].ToString();
                TextBox2.Text = Ds.Tables[0].Rows[0]["Firstname"].ToString();
                TextBox3.Text = Ds.Tables[0].Rows[0]["MiddleName"].ToString();
            }

          
        }



    }
   public void GetDataItem()
   {
      try
       {
           DataSet ds = new DataSet();
           ds = run.GetData();
           GridView1.DataSource = ds;
           GridView1 .DataBind();



       }
       catch (Exception ex)
       {



       }
   }
    protected void Button1_Click(object sender, EventArgs e)
    {
        putdata();
        Savedata(run.dtrip);
    }


    public void putdata()
    {
        run.intitable();
        run.dtrip.Rows[0]["Title"]=TextBox1.Text;
        run.dtrip.Rows[0]["Firstname"] = TextBox2.Text;
        run.dtrip.Rows[0]["Middlename"] = TextBox3.Text;
    }

      public void Savedata(DataTable dt )
    {
        DataSet Ds = new DataSet();
        Ds.Tables.Add(dt);
        run.SaveRecords(Ds);
    }


      protected void Button2_Click(object sender, EventArgs e)
      {
          id = Convert.ToInt16(Page.Request.QueryString["id"]);
          if (id > 0)
          {
              putdata();
              Updatedata(run.dtrip,id);
              GetDataItem();
          }
 
        

      }

      public void Updatedata(DataTable dt, int id11)
      {
          DataSet Ds = new DataSet();
          Ds.Tables.Add(dt);
          run.UpdateRecords(Ds, id11);
      }

      protected void Button3_Click(object sender, EventArgs e)
      {
          id = Convert.ToInt16(Page.Request.QueryString["id"]);
         long iwq;
          iwq = run.DeleteRecords(id);
          if (iwq == 2)


          {
              ScriptManager.RegisterStartupScript(this, this.GetType(), "Success", "alert('Your Records should be deleted !');", true);
              GetDataItem();


          }




      }
}

Drop Down Select Date Records Should Displays

        If isDropDown = False Then
                'CbDates.SelectedIndex = exIndex
                Exit Sub
            End If
            exIndex = CbDates.SelectedIndex
            isDropDown = False

            Dim n As Long
            Dim n1 As Integer
            Dim das, da1, da2 As Date
            Dim date1 As Date
            date1 = Date.Today
            Dim intTmp As Integer, intTmp1 As Integer
            Dim myDate As Date = Date.Today ''.ToString("dd-MMM-yyyy")
            Dim i As Long
            Bfrom.Enabled = False
            Bto.Enabled = False
            Select Case CbDates.SelectedItem
                Case "All"
                    FromDate = BegingIngDate ''.ToString("dd-MMM-yyyy")
                    ToDate = EndDate ''.ToString("dd-MMM-yyyy")

                Case "Today"

                    FromDate = myDate '.ToString("dd-MMM-yyyy")
                    ToDate = myDate '.ToString("dd-MMM-yyyy")
                    '---------------{END}---------------------
                Case "This Week"

                    FromDate = myDate.AddDays(-(myDate.DayOfWeek - 1))
                    ToDate = FromDate.AddDays(6)
                Case "This Week to date"

                    FromDate = myDate.AddDays(-(myDate.DayOfWeek - 1))
                    ToDate = myDate '.ToString("dd-MMM-yyyy")
                Case "This Month"
                    FromDate = myDate.AddDays(-(myDate.Day - 1)) ''.ToString("dd-MMM-yyyy")
                    ToDate = FromDate.AddMonths(1) ''.ToString("dd-MMM-yyyy")
                    ToDate = ToDate.AddDays(-1)

                Case "This Month to date"

                    FromDate = myDate.AddDays(-(myDate.Day - 1)) ''.ToString("dd-MMM-yyyy")
                    ToDate = myDate.ToString("dd-MMM-yyyy")

                Case "This Fiscal Quarter"
                    intTmp = myDate.Month
                    intTmp1 = intTmp Mod 3
                    If intTmp1 > 0 Then
                        FromDate = myDate.AddMonths(-(intTmp - 1)) ''.ToString("dd-MMM-yyyy")
                    Else
                        FromDate = myDate.AddMonths(-2) ''.ToString("dd-MMM-yyyy")
                    End If
                    FromDate = CType(FromDate.Month & "-" & 1 & "-" & FromDate.Year, Date)
                    ToDate = FromDate.AddMonths(3) ''.ToString("dd-MMM-yyyy")
                    ToDate = ToDate.AddDays(-1)

                Case "This Fiscal Quarter to date"
                    intTmp = myDate.Month
                    intTmp1 = intTmp Mod 3
                    If intTmp1 > 0 Then
                        FromDate = myDate.AddMonths(-(intTmp - 1)) ''.ToString("dd-MMM-yyyy")
                    Else
                        FromDate = myDate.AddMonths(-2) ''.ToString("dd-MMM-yyyy")
                    End If
                    FromDate = CType(FromDate.Month & "-" & 1 & "-" & FromDate.Year, Date)
                    ToDate = myDate.ToString("dd-MMM-yyyy")

                Case "This Fiscal Year"
                    FromDate = CType(1 & "-" & 1 & "-" & myDate.Year, Date)
                    ToDate = FromDate.AddYears(1) ''.ToString("dd-MMM-yyyy")
                    ToDate = ToDate.AddDays(-1)

                Case "This Fiscal  Year to date"
                    FromDate = CType(1 & "-" & 1 & "-" & myDate.Year, Date)
                    ToDate = myDate.ToString("dd-MMM-yyyy")

                Case "Yesterday"
                    FromDate = myDate.AddDays(-1)
                    ToDate = FromDate

                Case "Last Week"
                    myDate = myDate.AddDays(-7)
                    FromDate = myDate.AddDays(-(myDate.DayOfWeek - 1))
                    ToDate = FromDate.AddDays(6)

                Case "Last Week to date"
                    ToDate = myDate
                    myDate = myDate.AddDays(-7)
                    FromDate = myDate.AddDays(-(myDate.DayOfWeek - 1))

                Case "Last Month"
                    myDate = myDate.AddMonths(-1)
                    FromDate = myDate.AddDays(-(myDate.Day - 1)) ''.ToString("dd-MMM-yyyy")
                    ToDate = FromDate.AddMonths(1) ''.ToString("dd-MMM-yyyy")
                    ToDate = ToDate.AddDays(-1)

                Case "Last Month to date"
                    ToDate = myDate
                    myDate = myDate.AddMonths(-1)
                    FromDate = myDate.AddDays(-(myDate.Day - 1))

                Case "Last Fiscal Quarter"
                    myDate = myDate.AddMonths(-3)
                    intTmp = myDate.Month
                    intTmp1 = intTmp Mod 3
                    If intTmp1 > 0 Then
                        FromDate = myDate.AddMonths(-(intTmp - 1)) ''.ToString("dd-MMM-yyyy")
                    Else
                        FromDate = myDate.AddMonths(-2) ''.ToString("dd-MMM-yyyy")
                    End If
                    FromDate = CType(FromDate.Month & "-" & 1 & "-" & FromDate.Year, Date)
                    ToDate = FromDate.AddMonths(3) ''.ToString("dd-MMM-yyyy")
                    ToDate = ToDate.AddDays(-1)
                Case "Last Fiscal Quarter to date"
                    ToDate = myDate
                    myDate = myDate.AddMonths(-3)
                    intTmp = myDate.Month
                    intTmp1 = intTmp Mod 3
                    If intTmp1 > 0 Then
                        FromDate = myDate.AddMonths(-(intTmp - 1)) ''.ToString("dd-MMM-yyyy")
                    Else
                        FromDate = myDate.AddMonths(-2) ''.ToString("dd-MMM-yyyy")
                    End If
                    FromDate = CType(FromDate.Month & "-" & 1 & "-" & FromDate.Year, Date)

                Case "Last Fiscal to Year"
                    myDate = myDate.AddYears(-1)
                    FromDate = CType(1 & "-" & 1 & "-" & myDate.Year, Date)
                    ToDate = FromDate.AddYears(1) ''.ToString("dd-MMM-yyyy")
                    ToDate = ToDate.AddDays(-1)
                Case "Last Fiscal Year to date"
                    ToDate = myDate
                    myDate = myDate.AddYears(-1)
                    FromDate = CType(1 & "-" & 1 & "-" & myDate.Year, Date)

                Case "Next Week"
                    FromDate = ToDate
                    ToDate = FromDate.AddDays(7)

                Case "Next 4 Week"
                    FromDate = ToDate
                    ToDate = FromDate.AddDays(28)

                Case "Next Month"
                    FromDate = ToDate
                    ToDate = FromDate.AddMonths(1)

                Case "Next Fiscal Quarter"
                    FromDate = ToDate

                    ToDate = FromDate.AddMonths(3)
                    'TFrom.Text = FromDate.ToString("dd-MMM-yyyy")
                    'TTo.Text = ToDate.ToString("dd-MMM-yyyy")
                    'refreshDataSet()
                    'If memo = 2 Then
                    '    strlength()
                    'End If
                    'populateData()
                Case "Next Fiscal Year"
                    FromDate = ToDate
                    ToDate = FromDate.AddYears(1)
                    'TFrom.Text = FromDate.ToString("dd-MMM-yyyy")
                    'TTo.Text = ToDate.ToString("dd-MMM-yyyy")
                    'refreshDataSet()
                    'If memo = 2 Then
                    '    strlength()
                    'End If
                    'populateData()

                Case "Custom"

                    Bfrom.Enabled = True
                    Bto.Enabled = True

                    FromDate = myDate
                    ToDate = myDate
                    'TFrom.Text = FromDate.ToString("dd-MMM-yyyy")
                    'TTo.Text = ToDate.ToString("dd-MMM-yyyy")
                    'refreshDataSet()
                    'If memo = 2 Then
                    '    strlength()
                    'End If
                    'populateData()
            End Select

            TFrom.Text = FromDate.ToString("dd-MMM-yyyy")
            TTo.Text = ToDate.ToString("dd-MMM-yyyy")

                If Cmbdd1.SelectedValue <> "" Then
                refreshDataSet()
            End If
        

Sunday, 11 November 2012

How TO Find Control IN Grid Cell and Footter

 Master Page:--

    Footer:-
        GridView grv = Master.FindControl("ContentPlaceHolder2").FindControl("GridView1") as GridView;
            TextBox txtCopies = (TextBox)grv.FooterRow.FindControl("txtST");
            TextBox txtDescription = (TextBox)grv.FooterRow.FindControl("txtET");

      Cell:-
        GridView grv = Master.FindControl("ContentPlaceHolder2").FindControl("GridView1") as GridView;
        TextBox txt = (TextBox)grv.Rows[e.RowIndex].FindControl("TextBox1");
        TextBox txt2 = (TextBox)grv.Rows[e.RowIndex].FindControl("TextBox2"); 



Non   Master Page(Simple Page):--
         Cell :----

        int id  =Convert.ToInt16( GridView1.DataKeys[e.RowIndex].Values["Recid"].ToString());
        TextBox txt = (TextBox)GridView1.Rows[e.RowIndex].FindControl("TextBox1");
        TextBox txt2 = (TextBox)GridView1.Rows[e.RowIndex].FindControl("TextBox2");



         Footer :-

            TextBox txt = (TextBox)GridView1.FooterRow.FindControl("txtST");
            TextBox txt1 = (TextBox)GridView1.FooterRow.FindControl("txtET");
             intitable();
             dttrip.Rows[0]["TripStart"] = txt.Text;
             dttrip.Rows[0]["TripEnd"] = txt1.Text;

          .......................................
       public void intitable()
            {
         try
          {
             { 
                dttrip.Columns.Add("Recid");
                dttrip.Columns.Add("TripStart");
                dttrip.Columns.Add("TripEnd");
            }
                dttrip.Rows.Add(dttrip.NewRow());

            }
                catch (Exception ex)
            {

                  }
              }

Logicl Page And Dynamic Table in C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;

/// <summary>
/// Summary description for Runtype
/// </summary>
public class Runtype
{
    SPMS serv1 = new SPMS();
    public DataTable dtrip = new DataTable();
    public Runtype()

    {
        //
        // TODO: Add constructor logic here
        //
    }

    public void intitable()
    {
        try
        {
            {
                dtrip.Columns.Add("Title");
                dtrip.Columns.Add("Firstname");
                dtrip.Columns.Add("Middlename");
            }
            dtrip.Rows.Add(dtrip.NewRow());

        }
        catch (Exception ex)
        {

        }

    }

    public long SaveRecords(DataSet ds1)

    {
       long Recid=0;
        try
        {
        
            Recid = serv1.AddNewRecords(ds1);
         }
       catch (Exception ex)
        {

        }
        return Recid ;

    }

    public long UpdateRecords(DataSet ds1,int j)

    {
        long Recid = 0;
        try
        {

            Recid = serv1.UpdateRecords(ds1 ,j);


        }
        catch (Exception ex)
        {

        }
        return Recid;

    }


    public long DeleteRecords( int j)

    {
       long Recid = 0;
        try
        {

            Recid = serv1.DeletetripRecord(j);


        }
        catch (Exception ex)
        {

        }
        return Recid;

    }
    public DataSet GetData()
    {
        DataSet Ds1 = new DataSet();
        try
        {
     
            Ds1 = serv1.GetRecordTripDetail();
  
        }
        catch (Exception ex)
        {


        }
        return Ds1;

    }

    public DataSet GetCountryName()
    {
        DataSet Ds1 = new DataSet();
        try
        {

            Ds1 = serv1.GetContryMaster();

        }
        catch (Exception ex)
        {


        }
        return Ds1;

    }
    public DataSet GetDataByRecid(int ictr)
    {
        DataSet Ds1 = new DataSet();
        try
        {

            Ds1 = serv1.GetDatabyRecid( ictr);


        }
        catch (Exception ex)
        {


        }
        return Ds1;

    }

    public DataSet GetStateName(int ictr)

    {
        DataSet Ds1 = new DataSet();
        try
        {

            Ds1 = serv1.GetStateName(ictr);


        }
        catch (Exception ex)
        {


        }
        return Ds1;

    } 


}

THIS IS DATABASE (SPMS)Class

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Data.SqlClient;
using System.Transactions;

/// <summary>
/// Summary description for SPMS
/// </summary>
public class SPMS
{
    string cnnstr = System.Configuration.ConfigurationManager.AppSettings["xyzcon"];
    SqlConnection CNN = new SqlConnection();
    public SPMS()
    {
        CNN.ConnectionString = cnnstr;
    }

    public long AddNewRecords(DataSet ds)
    {
        SqlTransaction SQLT = null;
        int recId = 0;
        bool Berror = false;
        SqlCommand CMD = new SqlCommand();
        try
        {
              try
            {
                if (CNN.State == ConnectionState.Closed)
                    CNN.Open();
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
            }
            SQLT = CNN.BeginTransaction();
            CMD.Transaction = SQLT;
            CMD.Connection = CNN;
            DataTable dttripstart = new DataTable();
            dttripstart = ds.Tables[0];
            CMD.CommandType = CommandType.StoredProcedure;
            CMD.CommandText = "SaveAddressRecord1";
            CMD.Parameters.Clear();
            CMD.Parameters.AddWithValue("@title", dttripstart.Rows[0]["Title"]);
            CMD.Parameters.AddWithValue("@Firstname", dttripstart.Rows[0]["Firstname"]);
            CMD.Parameters.AddWithValue("@Middlename", dttripstart.Rows[0]["Middlename"]);
            SqlParameter SQLPar = new SqlParameter();
            SQLPar = CMD.Parameters.Add("RETURN_VALUE", SqlDbType.BigInt);
            SQLPar.Direction = ParameterDirection.ReturnValue;

            recId = CMD.ExecuteNonQuery();
           //int i = (int)CMD.Parameters["RETURN_VALUE"].Value;
            if (recId == 0)
            {
                Berror = true;

            }

            if (Berror == true)
            {
                CMD.Transaction.Rollback();
                return 0;
            }
            else
            {
                CMD.Transaction.Commit();

            }

        }
        catch (Exception ex)
        {
        }
        finally
        {
            if (CNN.State != ConnectionState.Closed)
                CNN.Close();
        }
        return recId;

    }
    public long UpdateRecords(DataSet ds,int i)

    {
        SqlTransaction SQLT = null;
        int recId = 0;
        bool Berror = false;
        SqlCommand CMD = new SqlCommand();
        try
        {
            try
            {
                if (CNN.State == ConnectionState.Closed)
                    CNN.Open();
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
            }
            SQLT = CNN.BeginTransaction();
            CMD.Transaction = SQLT;
            CMD.Connection = CNN;
            DataTable dttripstart = new DataTable();
            dttripstart = ds.Tables[0];
            CMD.CommandType = CommandType.StoredProcedure;
            CMD.CommandText = "updaterecord23";
            CMD.Parameters.Clear();
            CMD.Parameters.AddWithValue("@id", i);
            CMD.Parameters.AddWithValue("@title", dttripstart.Rows[0]["Title"]);
            CMD.Parameters.AddWithValue("@Firstname",dttripstart.Rows[0]["Firstname"]);
            CMD.Parameters.AddWithValue("@Middlename", dttripstart.Rows[0]["Middlename"]);
            SqlParameter SQLPar = new SqlParameter();
            SQLPar = CMD.Parameters.Add("RETURN_VALUE", SqlDbType.BigInt);
          SQLPar.Direction = ParameterDirection.ReturnValue;
            recId = CMD.ExecuteNonQuery();
            //int i = (int)CMD.Parameters["RETURN_VALUE"].Value;
            if (recId == 0)
            {
                Berror = true;

            }

            if (Berror == true)
            {
                CMD.Transaction.Rollback();
                return 0;
            }
            else
            {
                CMD.Transaction.Commit();

            }

        }
        catch (Exception ex)
        {
        }
        finally
        {
            if (CNN.State != ConnectionState.Closed)
                CNN.Close();
        }
        return recId;

    }

    public  DataSet GetRecordTripDetail()
    {
        DataSet dsGlobal = new DataSet();
        try
        {
            SqlDataAdapter adapGlobal = new SqlDataAdapter();
            SqlCommand cmd = new SqlCommand();
          try
            {
                if (CNN.State == ConnectionState.Closed)
                    CNN.Open();
            }
            catch (Exception ex)
            {
                CNN.Close();

            }
            if (CNN.State == ConnectionState.Closed)
                CNN.Open();
            cmd.Connection = CNN;
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.Clear();
            cmd.CommandText = "jktveiwdata1";
            adapGlobal.SelectCommand = cmd;
            adapGlobal.Fill(dsGlobal);
        }
        catch (Exception ex)
        {
        }
        finally
        {
            CNN.Close();

        }

        return dsGlobal;


    }
    public DataSet GetContryMaster()

    {
        DataSet dsGlobal = new DataSet();
        try
        {
            SqlDataAdapter adapGlobal = new SqlDataAdapter();
            SqlCommand cmd = new SqlCommand();
            try
            {
                if (CNN.State == ConnectionState.Closed)
                    CNN.Open();
            }
            catch (Exception ex)
            {
                CNN.Close();

            }
            if (CNN.State == ConnectionState.Closed)
                CNN.Open();
            cmd.Connection = CNN;
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.Clear();
            cmd.CommandText = "GetCountryName";
            adapGlobal.SelectCommand = cmd;
            adapGlobal.Fill(dsGlobal);
        }
        catch (Exception ex)
        {
        }
        finally
        {
            CNN.Close();

        }

        return dsGlobal;


    }

    public DataSet GetDatabyRecid(int ik)
    {

        DataSet ds = new DataSet();
        SqlCommand cmd = new SqlCommand();
        SqlDataAdapter da = new SqlDataAdapter();
        try
        {
            cmd.Connection = CNN;
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.CommandText = "GetRecordsByRecId";
            cmd.Parameters.AddWithValue("@RecId", ik);
            da = new SqlDataAdapter(cmd);
            da.Fill(ds);
            if (ds.Tables.Count > 0)
            {
                return ds;

            }

        }
        catch (Exception ex)
        {
            CNN.Close();
            return ds;
        }
        return ds;

    }


    public DataSet GetStateName(int ik)

    {

        DataSet ds = new DataSet();
        SqlCommand cmd = new SqlCommand();
        SqlDataAdapter da = new SqlDataAdapter();
        try
        {
            cmd.Connection = CNN;
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.CommandText = "GetSateName";
            cmd.Parameters.AddWithValue("@Recid", ik);
            da = new SqlDataAdapter(cmd);
            da.Fill(ds);
            if (ds.Tables.Count > 0)
            {
                return ds;

            }

        }
        catch (Exception ex)
        {
            CNN.Close();
            return ds;
        }
        return ds;

    }

    public long DeletetripRecord(int ik)
    {
        SqlTransaction SQLT = null;

        int recId = 0;
        bool Berror = false;
        SqlCommand CMD = new SqlCommand();
        try
        {
            //CNN.ConnectionString = cnnstr;

            try
            {
                if (CNN.State == ConnectionState.Closed)
                    CNN.Open();
            }
            catch (Exception ex)
            {
                throw ex;

            }
            finally
            {
            }
            // CNN.Open();
            SQLT = CNN.BeginTransaction();
            CMD.Transaction = SQLT;
            CMD.Connection = CNN;
            //DataTable dttripstart = new DataTable();
            //dttripstart = ds.Tables[0];
            CMD.CommandType = CommandType.StoredProcedure;
            CMD.CommandText = "DelEeg11";
            CMD.Parameters.Clear();
            CMD.Parameters.AddWithValue("@RecId", ik);
            //CMD.Parameters.AddWithValue("@Starttrip", dttripstart.Rows[0]["TripStart"]);
            //CMD.Parameters.AddWithValue("@endtrip", dttripstart.Rows[0]["TripEnd"]);
            SqlParameter SQLPar = new SqlParameter();
            SQLPar = CMD.Parameters.Add("RETURN_VALUE", SqlDbType.BigInt);
            SQLPar.Direction = ParameterDirection.ReturnValue;

            recId = CMD.ExecuteNonQuery();
            int i = (int)CMD.Parameters["RETURN_VALUE"].Value;
            if (i == 0)
            {
                Berror = true;

            }

            if (Berror == true)
            {
                CMD.Transaction.Rollback();
                return 0;
            }
            else
            {
                CMD.Transaction.Commit();

            }

        }
        catch (Exception ex)
        {
        }
        finally
        {
            if (CNN.State != ConnectionState.Closed)
                CNN.Close();
        }
        return recId;




    }

}