public void DeleteRangeNullArg() { XPathNavigator nav = GetInstance("<root><foo><bar/><baz/></foo><next>child<tmp/></next>final</root>"); nav.MoveToFirstChild(); nav.MoveToFirstChild(); // <foo> nav.DeleteRange(null); }
public void DeleteRangeInvalidArg() { XPathNavigator nav = GetInstance("<root><foo><bar/><baz/></foo><next>child<tmp/></next>final</root>"); nav.MoveToFirstChild(); nav.MoveToFirstChild(); // <foo> XPathNavigator end = nav.Clone(); end.MoveToNext(); // <next> end.MoveToFirstChild(); // child nav.DeleteRange(end); }
static void XPathNavigatorMethods_DeleteRange() { // XPathNavigator.DeleteRange() //<snippet52> XmlDocument document = new XmlDocument(); document.Load("contosoBooks.xml"); XPathNavigator navigator = document.CreateNavigator(); XmlNamespaceManager manager = new XmlNamespaceManager(document.NameTable); manager.AddNamespace("bk", "http://www.contoso.com/books"); XPathNavigator first = navigator.SelectSingleNode("/bk:bookstore/bk:book[1]", manager); XPathNavigator last = navigator.SelectSingleNode("/bk:bookstore/bk:book[2]", manager); navigator.MoveTo(first); navigator.DeleteRange(last); Console.WriteLine(navigator.OuterXml); //</snippet52> }
public void DeleteRange() { XPathNavigator nav = GetInstance("<root><foo><bar/><baz/></foo><next>child<tmp/></next>final</root>"); nav.MoveToFirstChild(); nav.MoveToFirstChild(); // <foo> XPathNavigator end = nav.Clone(); end.MoveToNext(); // <next> end.MoveToNext(); // final nav.DeleteRange(end); AssertNavigator("#1", nav, XPathNodeType.Element, String.Empty, // Prefix "root", // LocalName String.Empty, // NamespaceURI "root", // Name String.Empty, // Value false, // HasAttributes false, // HasChildren false); // IsEmptyElement }
public void CTRL140_10_Clicked(object sender, ClickedEventArgs e) { XPathNavigator nav2s = this.MainDataSource.CreateNavigator(); //In the form, these fields are set from the rules of Main/myFields/ProvinceName, querying information from the Tax Calculation //list in the site contents of mercury double gstRate = Convert.ToDouble(nav2s.SelectSingleNode("/my:myFields/my:GST", NamespaceManager).Value); double pstRate = Convert.ToDouble(nav2s.SelectSingleNode("/my:myFields/my:PST", NamespaceManager).Value); double gstRebate = Convert.ToDouble(nav2s.SelectSingleNode("/my:myFields/my:GSTRebate", NamespaceManager).Value); double pstRebate = Convert.ToDouble(nav2s.SelectSingleNode("/my:myFields/my:PSTRebate", NamespaceManager).Value); //string isThereTax = nav2s.SelectSingleNode("/my:myFields/my:isThereTax", NamespaceManager).Value; //initialization of tax variables and set to default value of 0 double subtotal, valueBeforeTax, gst, pst, totalExpense, totalTaxableItems, totalNonTaxableItems; string isThereTax; subtotal = valueBeforeTax = gst = pst = totalExpense = totalTaxableItems = totalNonTaxableItems = 0; subtotal = Convert.ToDouble(nav2s.SelectSingleNode("/my:myFields/my:SubTotal", NamespaceManager).Value); //tax calculations /*if (isThereTax == "true") * { * total = Convert.ToDouble(nav2s.SelectSingleNode("/my:myFields/my:SubTotal", NamespaceManager).Value); * valueBeforeTax = total / (1 + gstRate + pstRate); * gst = valueBeforeTax * gstRate * (1 - gstRebate); * pst = valueBeforeTax * pstRate * (1 - pstRebate); * totalExpense = valueBeforeTax + gst + pst; * }*/ string pathToTable = "/my:myFields/my:LineItems"; //points and iterator node to the table of items to iterate through the rows XPathNodeIterator iterate = nav2s.Select(pathToTable, NamespaceManager); iterate.MoveNext(); //We do this as the first row is blank and not filled with fields // int numOfRows = iterate.Count; string[] arrayOfItems = new string[numOfRows]; for (int i = 1; i < iterate.Count + 1; i++) { arrayOfItems[i - 1] = nav2s.SelectSingleNode(pathToTable + "[" + i.ToString() + "]" + "/my:InputAmount", NamespaceManager).Value; isThereTax = nav2s.SelectSingleNode(pathToTable + "[" + (i).ToString() + "]" + "/my:Taxable", NamespaceManager).Value; //this checks if that line item is taxable double value = Convert.ToDouble(arrayOfItems[i - 1]); if (isThereTax == "true") { totalTaxableItems += value; } else { totalNonTaxableItems += value; } } if (totalNonTaxableItems != subtotal)//i.e. means there are tax items { valueBeforeTax = totalTaxableItems / (1 + gstRate + pstRate); gst = valueBeforeTax * gstRate * (1 - gstRebate); pst = valueBeforeTax * pstRate * (1 - pstRebate); totalExpense = valueBeforeTax + gst + pst; } for (int i = 1; i < iterate.Count + 1; i++)//this loops through each row item { //Grabs the inputed amount from the form per row item arrayOfItems[i - 1] = nav2s.SelectSingleNode(pathToTable + "[" + i.ToString() + "]" + "/my:InputAmount", NamespaceManager).Value; isThereTax = nav2s.SelectSingleNode(pathToTable + "[" + i.ToString() + "]" + "/my:Taxable", NamespaceManager).Value; //this checks if that line item is taxable double value = Convert.ToDouble(arrayOfItems[i - 1]); if (isThereTax == "false") //if no tax then inputted amount = item amount { nav2s.SelectSingleNode(pathToTable + "[" + (i).ToString() + "]" + "/my:ItemAmount", NamespaceManager).SetValue(value.ToString()); } if (isThereTax == "true")//changes item amount based on the GST and PST calculations { double finalValue = value / totalTaxableItems * totalExpense; double final = Math.Round(finalValue, 2, MidpointRounding.AwayFromZero); nav2s.SelectSingleNode(pathToTable + "[" + (i).ToString() + "]" + "/my:ItemAmount", NamespaceManager).SetValue(final.ToString()); } } //Now Fill in the TaxTable seen during Finance Review and Entry PageView string path = "/my:myFields/my:TaxTable/my:TaxItems"; // Create a navigator object to point to the root of the data source of the VP form XPathNavigator tableNav; tableNav = this.MainDataSource.CreateNavigator(); tableNav.SelectSingleNode(path, NamespaceManager); // Navigator object selects a group of nodes, specified by the path // Get the Iterator object to point to the table (group of nodes) specified by the path (currently not pointed to the first node in the set of nodes) // Object will iterate over the group of nodes XPathNodeIterator rows = tableNav.Select(path, NamespaceManager); XPathNavigator first = tableNav.SelectSingleNode("//my:myFields/my:TaxTable/my:TaxItems[2]", NamespaceManager); XPathNavigator last; // If more than one row exists, means the Calculae Tax button has been selected before therefore we need to delete the current rows and add new ones if (rows.Count > 1) { last = tableNav.SelectSingleNode("//my:myFields/my:TaxTable/my:TaxItems[2]", NamespaceManager); // Delete the current node (first) to the node specified using "last" first.DeleteRange(last); } rows.MoveNext(); //Fill in the PSTRebate Row // rows.Current causes the XPathNavigator object to point to the current node (row) and selects a node (fields) within that node/row rows.Current.SelectSingleNode("/my:myFields/my:TaxTable/my:TaxItems/my:taxName", NamespaceManager).SetValue("PST Rebate"); string pstGL = nav2s.SelectSingleNode("/my:myFields/my:PSTGLCode", NamespaceManager).Value;//grabs the PSTGL code from the Tax Calculation List rows.Current.SelectSingleNode("/my:myFields/my:TaxTable/my:TaxItems/my:GLCodeTax", NamespaceManager).SetValue(pstGL); if (totalNonTaxableItems != subtotal) { double rebatePST = Math.Round(valueBeforeTax * pstRate * pstRebate, 2, MidpointRounding.AwayFromZero); nav2s.SelectSingleNode("/my:myFields/my:PSTRebateTotal", NamespaceManager).SetValue(rebatePST.ToString()); rows.Current.SelectSingleNode("/my:myFields/my:TaxTable/my:TaxItems/my:TaxAmount", NamespaceManager).SetValue(rebatePST.ToString()); } else { nav2s.SelectSingleNode("/my:myFields/my:PSTRebateTotal", NamespaceManager).SetValue("0"); rows.Current.SelectSingleNode("/my:myFields/my:TaxTable/my:TaxItems/my:TaxAmount", NamespaceManager).SetValue("0"); } //Play around with this section // Have the iterator object point to the beginning of the table again by once again assigning a collection of nodes to the iterator rows = tableNav.Select(path, NamespaceManager); rows.MoveNext(); // Add another row by cloning the PST tax row and adding the clones row to the bottom of the table and overriding the original row with a GST row rows.Current.Clone(); rows.Current.InsertAfter(rows.Current); //repeat same process for GST Table rows.Current.SelectSingleNode("/my:myFields/my:TaxTable/my:TaxItems/my:taxName", NamespaceManager).SetValue("GST Rebate"); string gstGL = nav2s.SelectSingleNode("/my:myFields/my:GSTGLCode", NamespaceManager).Value; rows.Current.SelectSingleNode("/my:myFields/my:TaxTable/my:TaxItems/my:GLCodeTax", NamespaceManager).SetValue(gstGL); //if (isThereTax == "true") //{ double rebateGST = Math.Round(valueBeforeTax * gstRate * gstRebate, 2, MidpointRounding.AwayFromZero); rows.Current.SelectSingleNode("/my:myFields/my:TaxTable/my:TaxItems/my:TaxAmount", NamespaceManager).SetValue(rebateGST.ToString()); nav2s.SelectSingleNode("/my:myFields/my:GSTRebateTotal", NamespaceManager).SetValue(rebateGST.ToString()); //} //else //{ // rows.Current.SelectSingleNode("/my:myFields/my:TaxTable/my:TaxItems/my:TaxAmount", NamespaceManager).SetValue("0"); // nav2s.SelectSingleNode("/my:myFields/my:GSTRebateTotal", NamespaceManager).SetValue("0"); //} // Adjust the adjusted amount in the first form to ensure that the sum of the rebates + the adjusted amounts is equal to total of the inputted values if (totalNonTaxableItems != subtotal) { adjustFirstItem(); } }