Tuesday, 23 April 2013

xml data dum in sql Sp

 @xmlLanguage xml  

SET ARITHABORT ON

if (@Action='insertDownloadCenterDetails')
                Begin
                           insert into DownloadCenter(Title,UploadFile)values(@Title,@UploadFile)
                           set @DownloadCenterId=@@identity
                 end
                   Begin
                       DELETE FROM DownloadCenterDetails WHERE fkDownloadCenterId = @DownloadCenterId
                   end                 
      
            SELECT  
                ISNULL(cast(Colx.query('data(fkTabId)') as varchar(max)),'0') as fkTabId,
                ISNULL(cast(Colx.query('data(fkSubTabId)') as varchar(max)),'0') as fkSubTabId
                INTO #TMPLanguage1 FROM @xmlLanguage.nodes('DocumentElement/Table') AS Tabx(Colx)
                insert into DownloadCenterDetails(fkDownloadCenterId,fkTabId,fkSubTabId)
                select @DownloadCenterId,fkTabId, fkSubTabId from #TMPLanguage1
 ---------------------------------------------------------------------------------------------------------

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.IO;

public partial class Xml_DataTable_dump_SQL_SP_code : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        DataTable _dt = new DataTable();

        DataColumn col1 = new DataColumn("fkTabId");
        DataColumn col2 = new DataColumn("fkSubTabId");


        col1.DataType = System.Type.GetType("System.Int32");
        col2.DataType = System.Type.GetType("System.Int32");


        _dt.Columns.Add(col1);
        _dt.Columns.Add(col2);


        //fore each loop while for etc
        _dt.Rows.Add("", "");

        //_DownloadCenter.strxmlData = CommonFunctions.GetXMLOfDataTable(_dt);
        //_DownloadCenter.InsertDownloadCenterDetails();
        //_DownloadCenter = null;
    }
    public bool InsertDownloadCenterDetails()
    {
        bool flag = false;
        try
        {

            //obj = _accessData.GetObject();
            //obj[0] = "insertDownloadCenterDetails";
            //obj[1] = _DownloadCenterId;
            //obj[2] = _TabId;
            //obj[3] = _SubTabId;
            //obj[6] = _Title;
            //obj[7] = _UploadFile;
            //obj[12] = strxmlData;
            //flag = _accessData.executeStatement(obj);

            return flag;
        }
        catch (Exception ex)
        {
            throw (ex);
        }
    }
    public static string GetXMLOfDataTable(DataTable dtToProcess)
    {
        string strOutput = "";
        try
        {
            dtToProcess.TableName = "Table";

            StringWriter sw = new StringWriter();

            dtToProcess.WriteXml(sw);
            strOutput = sw.ToString();
        }
        catch (Exception ex)
        {
        }


        return strOutput;
    }
}

Tuesday, 16 April 2013

Menu handle by Treeview

<asp:TreeView ID="treeviwExample"  runat="server" ImageSet="Arrows">
            <HoverNodeStyle Font-Underline="True" ForeColor="#5555DD" />
            <NodeStyle Font-Names="Verdana" Font-Size="8pt" ForeColor="Black" HorizontalPadding="5px" NodeSpacing="0px" VerticalPadding="0px" />
            <ParentNodeStyle Font-Bold="False" />
            <SelectedNodeStyle Font-Underline="True" ForeColor="#5555DD" HorizontalPadding="0px" VerticalPadding="0px" />           
        </asp:TreeView>

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 Treeview_checkchanges : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            BindTreeViewControl();
        }
    }
    private void BindTreeViewControl()
    {
        try
        {
            DataSet ds = GetDataSet("Select MenuId,MenuName,ParentId from tblMenuSite where deleted=0 order by groupid desc");
            DataRow[] Rows = ds.Tables[0].Select("ParentId IS NULL"); // Get all parents nodes
            for (int i = 0; i < Rows.Length; i++)
            {
                TreeNode root = new TreeNode(Rows[i]["MenuName"].ToString(), Rows[i]["MenuId"].ToString());
                root.SelectAction = TreeNodeSelectAction.Expand;
                CreateNode(root, ds.Tables[0]);
                treeviwExample.Nodes.Add(root);
            }
        }
        catch (Exception Ex) { throw Ex; }
    }

    public void CreateNode(TreeNode node, DataTable Dt)
    {
        DataRow[] Rows = Dt.Select("ParentId =" + node.Value);
        if (Rows.Length == 0) { return; }
        for (int i = 0; i < Rows.Length; i++)
        {
            TreeNode Childnode = new TreeNode(Rows[i]["MenuName"].ToString(), Rows[i]["MenuId"].ToString());
            Childnode.SelectAction = TreeNodeSelectAction.Expand;
            node.ChildNodes.Add(Childnode);
            CreateNode(Childnode, Dt);
        }
    }
    private DataSet GetDataSet(string Query)
    {
        DataSet Ds = new DataSet();
        try
        {
            string strCon = @"Data Source=;Initial Catalog=;uid=sa;pwd=;";
            SqlConnection Con = new SqlConnection(strCon);
            SqlDataAdapter Da = new SqlDataAdapter(Query, Con);
            Da.Fill(Ds);
        }
        catch (Exception) { }
        return Ds;
    }
}

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