How to set a Value in a column in a repeating table Programatically C# - InfoPath Dev
in

InfoPath Dev

Use our Google Custom Search for best site search results.

How to set a Value in a column in a repeating table Programatically C#

Last post 05-29-2013 08:42 AM by j0rt3g4. 2 replies.
Page 1 of 1 (3 items)
Sort Posts: Previous Next
  • 05-29-2013 06:18 AM

    • j0rt3g4
    • Not Ranked
      Male
    • Joined on 05-29-2013
    • Venezuela
    • Posts 2

    How to set a Value in a column in a repeating table Programatically C#

    Hello there
    I've got this code but it has 2 problems:
    1. The double value gets and "Only numeric fields are allowed"
    2. I can't find the way to repeat calculate throught all rows in the table...
    Heres the code:
    public void cambios(){
    //Navegacion entre campos
    XPathNavigator navform = this.CreateNavigator(); //navegador de formulario
    XmlNamespaceManager SpaceManager = this.NamespaceManager; //manejador de espacio de nombres
    XPathNavigator inicio = navform.SelectSingleNode("/my:myFields/my:Vacaciones/my:Detalle/my:Inicio", SpaceManager);
    XPathNavigator culminacion = navform.SelectSingleNode("/my:myFields/my:Vacaciones/my:Detalle/my:Culminacion", SpaceManager);
    XPathNavigator Tiempo = navform.SelectSingleNode("/my:myFields/my:Vacaciones/my:Detalle/my:Tiempo", SpaceManager);
    XPathNavigator Dias = navform.SelectSingleNode("/my:myFields/my:Vacaciones/my:Detalle/my:Dias", SpaceManager);
    DeleteNil(inicio);
    DeleteNil(culminacion);
    DeleteNil(Tiempo);
    DeleteNil(Dias);
    int SWcombos = Tiempo.ValueAsInt; //el valor del combo segun selección
    DateTime di = new DateTime();
    DateTime df = new DateTime();
    string ConvDias; //Conversion Dias
    if ((string.IsNullOrEmpty(inicio.Value) || (string.IsNullOrEmpty(culminacion.Value))))
    {
    // MessageBox.Show(" Los campos de Inicio y Culminación deben tener fechas válidas para realizar el cálculo ");
    // return;
    }
    else
    {
    di = inicio.ValueAsDateTime;
    df = culminacion.ValueAsDateTime;
    }
    //public int ExcluyeFeriados(DateTime start, DateTime end, int dias)
    double dias = ExcluyeFeriados(di, df);
    if (dias
    {
    MessageBox.Show("La fecha de inicio no puede estar ANTES de la fecha de Culminación");
    Dias.SetValue("0");
    return;
    }
    switch (SWcombos)
    {
    case 1:
    //calcular los dias
    //MessageBox.Show("Hice 1");
    ConvDias = Convert.ToString(dias);
    Dias.SetValue(ConvDias );
    break;
    case 2: //caso 2 y 3 son el mismo, medios días, o tarde o mañana
    case 3:
    dias *= 0.5; //son medios dias)
    ConvDias = Convert.ToString(dias);
    //calcular dias y mult por la mitad (porque son medios días) --->Caso Mañanas
    //MessageBox.Show("Hice 2 y 3");
    Dias.SetValue(ConvDias);
    break;
    default:
    //No es un número valido dar error y salir
    MessageBox.Show("No tiene un valor válido, favor contacte al departamento de sistemas a email");
    Dias.SetValue("0");
    break;
    }
    }
    Thanks in advance......
    ___________________________________
    Jose Ortega
    Bacherlor in Computational Physics
    Senior Consultant
    MCSE Server Infraestructure / Messaging
    MCPIT - Enterprise Messaging Administrator Exchange 2010
    Filed under: , , ,
  • 05-29-2013 07:40 AM In reply to

    Re: How to set a Value in a column in a repeating table Programatically C#

     You'll want to look into XPathNodeIterator - I'm guessing Detalle is your repeating group - get those and iterate through with a foreach.

    I think your validation error may be that your value is using a comma for the decimal separator? I think XML will find that invalid - http://www.w3.org/TR/xmlschema-2/#decimal

    You can set the control to display with a comma instead of a ".", but you'll need to set the field with a value with a "."

    Looks like Decimal.TryParse can take an IFormatProvider? That may be worth a shot... http://msdn.microsoft.com/en-us/library/ew0seb73.aspx

     

    Hilary Stoupa

  • 05-29-2013 08:42 AM In reply to

    • j0rt3g4
    • Not Ranked
      Male
    • Joined on 05-29-2013
    • Venezuela
    • Posts 2

    Re: How to set a Value in a column in a repeating table Programatically C#

    Thanks you very much for your reply

     Yes, Detalle is the repeating group.

    I didn't have Thought about that error validation with the "," instead of a "."

    But I changed the calculated value with a Textbox and it executed correctly. I don't think I should  add the nil attribute again.

    This should be my first time using the XpathNodeIterator and I have no idea how to use it, Can i have a clue how to use this XPathNodeIterator?

    I will let you know if it's Works

     

    ___________________________________
    Jose Ortega
    Bacherlor in Computational Physics
    Senior Consultant
    MCSE Server Infraestructure / Messaging
    MCPIT - Enterprise Messaging Administrator Exchange 2010
Page 1 of 1 (3 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.