Thursday, 11 April 2013

dataset clone and copy and select query and distinct use dataset table filter and date filter

 -----------------------Short code------------------------
DataTable table6 = ds.Tables[0];
                    if (table6.Rows.Count > 0)
                    {
                        table6.DefaultView.RowFilter = string.Format(CultureInfo.InvariantCulture, "EZone ='" + ds.Tables[3].Rows[i]["Zone"].ToString().Trim() + "' and eemailid='" + ds.Tables[3].Rows[i]["eemailid"].ToString().Trim() + "' and Inv_Dist_Awareness ='2' and  instdate >= #" + moreThan + "# and instdate <= #" + lessThan + "#");
                        table6 = table5.DefaultView.ToTable();
                    }
                  DataRow[] rows;
   rows = table6.Select();

-----------------------------------------------------
 DataSet tempTaskDS = new DataSet();
                DataTable tempTable = ds.Tables[0].Clone();
                foreach (DataRow row in ds.Tables[0].Select("instdate >= #" + Currentmonth_fisrt + "# and instdate <= #" + Currentmonth_last + "#"))
                {
                    tempTable.Rows.Add(row.ItemArray);
                    i++;
                }

                tempTaskDS.Tables.Add(tempTable);
--------------------------------------------------


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


public partial class Datasetclone_datasetclone : System.Web.UI.Page
{

    DataTable GetTable()
    {
        //
        // Here we create a DataTable with four columns.
        //
        DataTable table = new DataTable();
        table.Columns.Add("Dosage", typeof(int));
        table.Columns.Add("Drug", typeof(string));
        table.Columns.Add("Patient", typeof(string));
        table.Columns.Add("Date", typeof(DateTime));

        //
        // Here we add five DataRows.
        //
        table.Rows.Add(25, "Indocin", "David", DateTime.Now);
        table.Rows.Add(25, "ajit", "David", DateTime.Now);
        table.Rows.Add(50, "Enebrel", "Sam", DateTime.Now);
        table.Rows.Add(10, "Hydralazine", "Christoff", DateTime.Now);
        table.Rows.Add(21, "Combivent", "Janet", DateTime.Now);
        table.Rows.Add(100, "Dilantin", "Melanie", DateTime.Now);
        return table;
    }
    protected void Page_Load(object sender, EventArgs e)
    {

        DataTable ds = new DataTable();
        ds = GetTable();
        DataSet ds1 = new DataSet();
        ds1.Tables.Add(ds);
        _FilterAndInsert(ds1);
        //ds.Tables.Add(employees);
        //ds.Tables.Add(payCheckes);
    }
    public DataSet  _FilterAndInsert(DataSet sourceSet)
    {
         sourceSet.Tables[0].Columns.Add("ppID", typeof(string));
        ///Apply your filter clauses in Select() function parameter
        DataRow[] rows = sourceSet.Tables[0].Select("Dosage >="+25+"");
        ///Get the structure of source table
        DataTable tempTable = sourceSet.Tables[0].Clone();
        ///Add the filtered rows in temp table
        int i = 0;
        foreach (DataRow row in rows)
        {
            tempTable.Rows.Add(row.ItemArray[0], row.ItemArray[1], row.ItemArray[2], row.ItemArray[3], row.ItemArray[4] = (i+1).ToString());
            i++;
        }
        tempTable.Columns.Remove("Date"); 
        tempTable.AcceptChanges();
        ///Create new dataset
        DataSet resultSet = new DataSet();
        ///Add temp table at first index or modify this code sequence as you require
        resultSet.Tables.Add(tempTable);
        for (int index = 1; index < sourceSet.Tables.Count; index++)
        {
            ///Set the copy of source table in local instance
            DataTable tableToAdd = sourceSet.Tables[index].Copy();
            ///Remove from source to avoid any exceptions
            sourceSet.Tables.RemoveAt(index);
            ///Add the copy to result set
            resultSet.Tables.Add(tableToAdd);
        }
        ///Set the copy to source table from result set
        sourceSet = resultSet.Copy();

        //DataTable tbl;
        //DataTable tbl2 = new DataTable();
        //DataSet ds = new DataSet();
        //ds.Tables.Add(new DataTable());
        //ds.Tables[0].Columns.Add("ID", typeof(int));
        //ds.Tables[0].Columns.Add("Tour_Code", typeof(int));
        //ds.Tables[0].Columns.Add("Tour_Date", typeof(string));
        ////ds.Tables[0].Columns.Add("No_Of_Vehicle", typeof(int));
        //ds.Tables[0].Columns.Add("Vehicle", typeof(string));
        //tbl2 = ds.Tables[0].Clone();

        DataTable dt = new DataTable("pramod");
        dt.Columns.Add("Dosage", tempTable.Columns["Dosage"].DataType);

        object LastValue = null;
        foreach (DataRow dr in tempTable.Select("", "Dosage"))
        {
            if (LastValue == null || !(ColumnEqual(LastValue, dr["Dosage"])))
            {
                LastValue = dr["Dosage"];
                dt.Rows.Add(new object[] { LastValue });
            }
        }
       
        return sourceSet;
    }

    private bool ColumnEqual(object A, object B)
    {

        // Compares two values to see if they are equal. Also compares DBNULL.Value.
        // Note: If your DataTable contains object fields, then you must extend this
        // function to handle them in a meaningful way if you intend to group on them.

        if (A == DBNull.Value && B == DBNull.Value) //  both are DBNull.Value
            return true;
        if (A == DBNull.Value || B == DBNull.Value) //  only one is DBNull.Value
            return false;
        return (A.Equals(B));  // value type standard comparison
    }
}

public string _FilterAndInsert(DataSet sourceSet)
    {
        // sourceSet.Tables[0].Columns.Add("ppID", typeof(string));
        ///Apply your filter clauses in Select() function parameter
        string lessThan = DateTime.Now.Month.ToString() + "-" + DateTime.Now.Day.ToString() + "-" + DateTime.Now.Year.ToString();
        string moreThan = DateTime.Now.Month.ToString() + "-" + DateTime.Now.AddDays(-7).Day.ToString() + "-" + DateTime.Now.Year.ToString();

        DataRow[] rows = sourceSet.Tables[0].Select("instdate <= #" + lessThan + "# and instdate > #" + moreThan + "#");//+ "AND instdate >= #" + moreThan + "#");
        ///Get the structure of source table
        DataTable tempTable = sourceSet.Tables[0].Clone();
        ///Add the filtered rows in temp table
        int i = 0;
        string weeklycount = rows.Length.ToString(); ;

        return weeklycount;
    }

Monday, 8 April 2013

Monday, 18 March 2013

Add favriate

<div class="rightFavourite" id="addbtnDiv" runat="server">
    <a href="javascript:;" class="addFavourite" onclick="javascript:addToCompare();">Add to Favourite</a></div>
<asp:HiddenField ID="hdnPageUrl" runat="server" />
<asp:HiddenField ID="hdnPageTitle" runat="server" />
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

public partial class UserControls_UCaddFvrtBtn : System.Web.UI.UserControl
{
    FavouritePages.clFvrtPg objClFvrtPg = new FavouritePages.clFvrtPg();

    protected void Page_Load(object sender, EventArgs e)
    {
        hdnPageUrl.Value = HttpContext.Current.Request.Url.ToString();
        hdnPageTitle.Value = this.Page.Title.ToString();
        checkPageExits();
    }
    public void checkPageExits()
    {
        string pageUrl = HttpContext.Current.Request.Url.ToString();
        string pageTitle = this.Page.Title.ToString();

        DataTable _dtFvrtPg = objClFvrtPg.dtFavouritePages;
        if (_dtFvrtPg != null)
        {
            if (_dtFvrtPg.Rows.Count > 0)
            {
                foreach (DataRow dr in _dtFvrtPg.Rows)
                {
                    if (pageUrl == dr["PageUrl"].ToString() && pageTitle == dr["PageTitle"].ToString())
                    {
                        addbtnDiv.Attributes.Add("style", "display:none");
                    }                 
                }
            }
        }
    }
}

Tuesday, 5 March 2013

Request UrlReferrer

 if (Request.UrlReferrer == null)
            {
}


<script language="JavaScript" type="text/javascript">
    window.history.forward();
    function noBack() { window.history.forward(); }

    </script>

<body onload="noBack();" onpageshow="if (event.persisted) noBack();" onunload="">

Thursday, 28 February 2013

Replace junk charater function

public string cleanip(string str)
    {
        string str_op;
        str_op = str;
        if (str_op != "" && str_op != null)
        {
            str_op = str_op.Replace("<", "");
            str_op = str_op.Replace(">", "");
            str_op = str_op.Replace("&lt;", "");
            str_op = str_op.Replace("&gt;", "");
        }
        if (str_op != null)
        {
            if (str_op.Length >= 50)
                str_op = str_op.Remove(50);
        }
        return str_op;
    }

Monday, 25 February 2013

validation with ajax filter

  
 <asp:TextBox ID="txtMessage" runat="server" TextMode="MultiLine" autocomplete="off"  TabIndex="15"></asp:TextBox>
                                    </div>
                                    <div class="errormsg_contact">
                                        <asp:RequiredFieldValidator ID="rfvYourMessage" runat="server" ControlToValidate="txtMessage"
                                Display="Dynamic" ErrorMessage="Please enter your message" ValidationGroup="SUBMIT"
                                SetFocusOnError="true"> </asp:RequiredFieldValidator>

                                <cc1:FilteredTextBoxExtender ID="FilteredTextBoxExtender3" runat="server"
                                FilterType="Custom, Numbers, UppercaseLetters, LowercaseLetters" ValidChars=" ,./\()_" TargetControlID="txtMessage"> </cc1:FilteredTextBoxExtender>

                                        <asp:RegularExpressionValidator ID="rvtxtMessage" runat="server" ControlToValidate="txtMessage"
                                Display="Dynamic" ErrorMessage="Message contains minuman 5 maximum 1000 characters with or without space"
                                ValidationExpression="[,./\()_-a-zA-z0-9 ]{5,1000}" ValidationGroup="SUBMIT"
                                SetFocusOnError="true" />

Sunday, 17 February 2013

validation more than zero

 function fnChkNumVal(source, args) {
            //var iknum = parseInt(args.Value)
            var iknum =args.Value
            if(iknum==0)
                 args.IsValid = false;
            else
                 args.IsValid = true ; 
        }

 <asp:TextBox ID="txtNWOnlineTransAmt" MaxLength="16" runat="server" CssClass="input">

  <asp:CustomValidator ID="CustomValidator19" runat="server" ErrorMessage="Transaction amount can not be zero"
                                                    EnableClientScript="true" SetFocusOnError="true" ClientValidationFunction="fnChkNumVal"
                                                    ControlToValidate="txtNWOnlineTransAmt" ValidationGroup="Feedback" Display="None"
                                                    CssClass="commment"></asp:CustomValidator>