.Net & SharePoint '07

Technical blog for .Net and all SharePoint 2007 related Information

About the author

Me(Prince) and my wife are B.E in I.T & C.S.E respectively.  I a certified MCPD: Web from 2007 Dec. I am Intrestes in Web Application, MOSS, EPM, etc.
Now working with Deira International School, as IT Application & Help Manager. I have started my career as "Software Developer" @  REACH Sewn Technologies and Consulting Pvt. Ltd, Bangalore India from Oct 2004 to Feb 2006, then as "Web & Intranet Developer" @ Fosroc International Ltd, Dubai from April 2006 to Sep 2009.
You can catch me on mail@jpy-tech.com or mail@princepy.com. Or on 00971 - 50 - 4284530 

Google Translate

Tag cloud

Calendar

<<  May 2012  >>
MoTuWeThFrSaSu
30123456
78910111213
14151617181920
21222324252627
28293031123
45678910

View posts in large calendar

RecentComments

Comment RSS

Google Your Location


Infopath(VSTA):Populating & Sorting Main DataSource with Datas from Secondary DataSource

Main Data Source:

where SoNFields/SoNField is populating from Secondary Data Source "AGFileEntities" which is sorted according to SortOrder

Secondary Data Source
 

 

public void FormEvents_Loading(object sender, LoadingEventArgs e)
{
    /* ** For  Sorting purpose ** */
    if (!FormState.Contains("InSwap"))
        FormState.Add("InSwap", false);
    /* ** For  Sorting purpose ** */

        XPathNavigator root = this.MainDataSource.CreateNavigator();
        XPathNodeIterator nodes;
        XPathNavigator clone;

        XPathNavigator pListRoot = this.DataSources["AGFileEntities"].CreateNavigator();
        SortList(pListRoot, "SortOrder", "/dfs:myFields/dfs:dataFields/dfs:IPS_Auto_Generated_File_Entities");
        nodes = pListRoot.Select("/dfs:myFields/dfs:dataFields/dfs:IPS_Auto_Generated_File_Entities[@Field_Type='Preliminary SoN']", this.NamespaceManager);
        clone = root.SelectSingleNode("/my:myFields/my:preliminarySoN/my:SoNFields/my:SoNField", this.NamespaceManager).Clone();
        while (nodes.MoveNext())
        {
            clone.SelectSingleNode("my:Title", this.NamespaceManager).SetValue(nodes.Current.GetAttribute("Title", "").Trim());
            clone.SelectSingleNode("my:Description", this.NamespaceManager).SetValue(nodes.Current.GetAttribute("Description", "").Trim());
            root.SelectSingleNode("/my:myFields/my:preliminarySoN/my:SoNFields", this.NamespaceManager).AppendChild(clone);
        }
        root.SelectSingleNode("/my:myFields/my:preliminarySoN/my:SoNFields/my:SoNField", this.NamespaceManager).DeleteSelf();

    }
    else
    {

    }
}

 

 

#region Sorting
private void SortList(XPathNavigator aListRoot, string sortBy, string itemsToSort)
{
    System.Globalization.CultureInfo currentThreadCulture =
        System.Threading.Thread.CurrentThread.CurrentCulture;

    int numPeople = aListRoot.Select(itemsToSort, NamespaceManager).Count;

    /* basic bubble sort implementation */
    for (int i = 1; i < numPeople; i++)  /* xpath is 1-based */
    {
        for (int j = i + 1; j <= numPeople; j++) // keep j ahead of i; we can index [numPeople]
        {
            /* swap (i,j) if i > j */
            string iValue = GetValue(aListRoot, itemsToSort + WrapAsIndexer(i) + "/@" + sortBy);//GetValue(itemsToSort + WrapAsIndexer(i) + "/dfs:" + sortBy);
            string jValue = GetValue(aListRoot, itemsToSort + WrapAsIndexer(j) + "/@" + sortBy);//GetValue(itemsToSort + WrapAsIndexer(j) + "/dfs:" + sortBy);

            /* Do we sort by number or string? */
            /*if (SortAsNumber) */
            /*{ */
            int iNum, jNum;
            if (!Int32.TryParse(iValue, out iNum) || !Int32.TryParse(jValue, out jNum))
            {
                /* Let InfoPath take care of the invalid datatype with its own validation, we'll keep sorting the rest */
                continue;
            }

            if (iNum > jNum)
            {
                Swap(aListRoot, itemsToSort + WrapAsIndexer(i), itemsToSort + WrapAsIndexer(j));
            }
            /*}*/

            /*else // SortAsString */
            /*{ */
            /*    if (String.Compare( */
            /*       iValue, jValue, true */ /*ignoreCase*//*currentThreadCulture) > 0)  */
           /*    { */
            /*        Swap(itemsToSort + WrapAsIndexer(i), itemsToSort + WrapAsIndexer(j)); */
            /*    } */
            /*} */

        } /* end inner-for */
    } /* end outer-for */
}
private string WrapAsIndexer(int intToWrap)
{ return WrapAsIndexer(intToWrap.ToString()); }
private string WrapAsIndexer(string strToWrap)
{ return "[" + strToWrap + "]"; }
private string GetValue(XPathNavigator aListRoot, string xpath)
{ return aListRoot.SelectSingleNode(xpath, NamespaceManager).Value; }
private void SetValue(XPathNavigator aListRoot, string xpath, string value)
{ aListRoot.SelectSingleNode(xpath, NamespaceManager).SetValue(value); }
private void Swap(XPathNavigator aListRoot, string xpath1, string xpath2)
{
    InSwap = true;

    try
    {
        XPathNavigator item1 = aListRoot.SelectSingleNode(xpath1, NamespaceManager);
        XPathNavigator item2 = aListRoot.SelectSingleNode(xpath2, NamespaceManager);

        XPathNavigator item1Clone = item1.Clone();
        item1.ReplaceSelf(item2);
        item2.ReplaceSelf(item1Clone);
    }
    finally /* always undo the reentrancy block at the end */
    {
        InSwap = false;
    }
}
private bool InSwap
{
    get { return (bool)FormState["InSwap"]; }
    set { FormState["InSwap"] = value; }
}
#endregion


Categories: c# | Infopath 2007 | MOSS | VSTOS | WSS
Posted by admin on Tuesday, September 23, 2008 3:04 PM
Permalink | Comments (0) | Post RSSRSS comment feed