DateDiff Code in Repeating field help - InfoPath Dev
in

InfoPath Dev

DateDiff Code in Repeating field help

Last post 03-06-2012 08:36 AM by BrunoAdv. 1 replies.
Page 1 of 1 (2 items)
Sort Posts: Previous Next
  • 03-05-2012 12:00 PM

    DateDiff Code in Repeating field help

    Hello,

     I have a form i am using to Datediff 2 time fields, and it needs to be a repeating table. The code i am using works with the first set of repeating tables but not once i add rows it does not continue to work. how can i make this work in a repeating table? Thank you.

    Here is the Code.

            {
                XPathNavigator mdsNav = MainDataSource.CreateNavigator();
                XPathNavigator root = MainDataSource.CreateNavigator();

                DateTime sst = mdsNav.SelectSingleNode("/my:myFields/my:Employee-Classification/my:Hours-Scheduled/my:Sun-Start",NamespaceManager).ValueAsDateTime;
                DateTime set = mdsNav.SelectSingleNode("/my:myFields/my:Employee-Classification/my:Hours-Scheduled/my:Sun-End", NamespaceManager).ValueAsDateTime;

                TimeSpan diff = set.Subtract(sst);

                XPathNavigator nodeNav = mdsNav.SelectSingleNode("/my:myFields/my:Employee-Classification/my:Hours-Scheduled/my:Sun-Total", NamespaceManager);


                nodeNav.SetValue(diff.Hours.ToString() + ":" + diff.Minutes.ToString());

                string Time = root.SelectSingleNode("/my:myFields/my:Employee-Classification/my:Hours-Scheduled/my:Sun-Total", NamespaceManager).Value;

                string[] Temp = Time.Split(':');

                root.SelectSingleNode("/my:myFields/my:Employee-Classification/my:Hours-Scheduled/my:Sun-Total", NamespaceManager).SetValue((int.Parse(Temp[0]) + (double.Parse(Temp[1]) / 60)).ToString("#.##"));


            }
  • 03-06-2012 08:36 AM In reply to

    Re: DateDiff Code in Repeating field help

    I figured out how to make it work, Figured i would share the code. If anything looks out of place or wrong please let me know.

    if (e.Operation == XmlOperation.ValueChange)

    {

    //retrieve the values for the start and end Times

    string W1SaturdayTimeInValue = e.Site.Value;

    string W1SaturdayTimeOutValue = e.Site.SelectSingleNode("../my:W1SaturdayTimeIn", NamespaceManager).Value;

    if (!String.IsNullOrEmpty(W1SaturdayTimeInValue) &&

    !

    string.IsNullOrEmpty(W1SaturdayTimeOutValue))

    {

    DateTime W1SaturdayTimeIn = e.Site.SelectSingleNode("../my:W1SaturdayTimeIn", NamespaceManager).ValueAsDateTime;

    DateTime W1SaturdayTimeOut = e.Site.SelectSingleNode("../my:W1SaturdayTimeOut", NamespaceManager).ValueAsDateTime;

    //retrieve the Totals field

    XPathNavigator nodeNav = e.Site.SelectSingleNode("../my:W1-S-Total", NamespaceManager);

    if (nodeNav.MoveToAttribute("nil", NamespaceManager.LookupNamespace("xsi")))

    nodeNav.DeleteSelf();

    //Retrieve and display Time Difference

    TimeSpan diff = W1SaturdayTimeOut.Subtract(W1SaturdayTimeIn);

    nodeNav.SetValue(diff.Hours.ToString() +

    ":" + diff.Minutes.ToString());

    string time = e.Site.SelectSingleNode("../my:W1-S-Total", NamespaceManager).Value;

    string[] Temp = time.Split(':');

    e.Site.SelectSingleNode(

    "../my:W1-S-Total", NamespaceManager).SetValue((int.Parse(Temp[0]) + (double.Parse(Temp[1]) / 60)).ToString("#.##"));

Page 1 of 1 (2 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.