text:
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
using Business;
using Business.Data.Laboratorio;
using NHibernate;
using NHibernate.Expression;
using System.Drawing;
using MathParser;

using Business.Data;

namespace WebLab.Resultados
{
    public partial class ResultadoHTEdit : System.Web.UI.Page
    {

        protected void Page_PreInit(object sender, EventArgs e)
        {

             if (Session["idUsuario"] != null)
                {
                ArmarEncabezado();

                }
             else
                 Response.Redirect("../FinSesion.aspx", false);

        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                if (Session["idUsuario"] != null)
                {
                    Inicializar();

                }
                else
                    Response.Redirect("../FinSesion.aspx", false);
            }

        }

        private void Inicializar()
        {
            HojaTrabajo oRegistro = new HojaTrabajo();
            oRegistro = (HojaTrabajo)oRegistro.Get(typeof(HojaTrabajo), int.Parse(Request["idHojaTrabajo"].ToString()));
            lblArea.Text = oRegistro.IdArea.Nombre + " - " + oRegistro.Codigo; chkFormula.Visible = false;
            Usuario oUser = new Usuario();
            oUser = (Usuario)oUser.Get(typeof(Usuario), int.Parse(Session["idUsuario"].ToString()));
            //lnkControl.Text = "Marcar hoja como controlada por " + oUser.Nombre + " " + oUser.Apellido;
            switch  (Request["Operacion"].ToString())
            {
                case "Control":{
                lblTitulo.Text = "CONTROL DE HOJA DE TRABAJO";
                pnlControl.Visible = true; }break;
                case "Carga":
                    {
                        lblTitulo.Text = "CARGA DE RESULTADOS";
                        pnlControl.Visible = false;
                    } break;
                case "Valida":
                    {
                        lblTitulo.Text = "VALIDACION DE RESULTADOS";
                        lblTitulo.CssClass = "mytituloRojo2";
                        btnGuardar.Text = "Validar y Salir";
                        btnGuardarParcial.Text = "Validar";
                        btnValidarPendiente.Visible = true;
                        btnValidarPendienteySalir.Visible = true;
                        pnlControl.Visible = true;
                    } break;
            }
        }

        private void ArmarEncabezado()
        {

           // Configuracion oCon = new Configuracion(); oCon = (Configuracion)oCon.Get(typeof(Configuracion), 1);

             HojaTrabajo oRegistro = new HojaTrabajo();
             oRegistro = (HojaTrabajo)oRegistro.Get(typeof(HojaTrabajo),int.Parse( Request["idHojaTrabajo"].ToString()));

            string m_strSQL  =@" SELECT CHT.textoImprimir,CHT.idItem FROM dbo.LAB_DetalleHojaTrabajo AS CHT
            where CHT.idHojaTrabajo=" + Request["idHojaTrabajo"].ToString() +" order by CHT.idDETALLEHojaTrabajo";

                 DataSet Ds = new DataSet();
                 SqlConnection conn = (SqlConnection)NHibernateHttpModule.CurrentSession.Connection;
                 SqlDataAdapter adapter = new SqlDataAdapter();
                 adapter.SelectCommand = new SqlCommand(m_strSQL, conn);
                 adapter.Fill(Ds);

                 //tContenido0.Controls.Add(objRow0);
                 if (Ds.Tables[0].Rows.Count > 0)
                 {

                     TableRow objRow = new TableRow();
                     for (int i = 0; i < Ds.Tables[0].Rows.Count; i++)
                     {
                         string m_iditem = Ds.Tables[0].Rows[i].ItemArray[1].ToString();
                         Item oItem = new Item(); oItem = (Item)oItem.Get(typeof(Item), int.Parse(m_iditem));

                         string s_tipoREsultado= oItem.IdTipoResultado.ToString();
                         string s_nombre =oItem.Nombre;
                        // maximoAnchoTabla += 1;
                         TableCell objCell = new TableCell();
                         Label lbl0 = new Label();
                         switch (s_tipoREsultado)
                         {
                             case "1":
                                 { lbl0.Width = Unit.Pixel(80); objCell.Width = Unit.Pixel(80); } break;
                             case "2":
                                 { lbl0.Width = Unit.Pixel(100); objCell.Width = Unit.Pixel(100); } break;
                             default:
                                 { lbl0.Width = Unit.Pixel(150); objCell.Width = Unit.Pixel(150); } break;
                         }
                         //objCell.Text = Ds.Tables[0].Rows[i].ItemArray[0].ToString().Substring(0, CalcularLargo(Ds.Tables[0].Rows[i].ItemArray[0].ToString().Length));
                         lbl0.Text = Ds.Tables[0].Rows[i].ItemArray[0].ToString().Substring(0, CalcularLargo(Ds.Tables[0].Rows[i].ItemArray[0].ToString().Length));
                         lbl0.Font.Size = FontUnit.Point(8);
                         lbl0.Font.Bold = true;
                         lbl0.ToolTip = s_nombre;
                         //dt.Columns.Add(nombre_Columna);
                         Master.FindControl("ContentPlaceHolder1").FindControl("PanelEncabezado").Controls.Add(lbl0);
                         objCell.Controls.Add(lbl0);
                         objCell.BackColor = Color.WhiteSmoke;

                         objCell.HorizontalAlign = HorizontalAlign.Center;
                         objCell.Height = Unit.Pixel(25);

                         objRow.Cells.Add(objCell);
                         tEncabezado.Controls.Add(objRow);
                         //tContenido.Controls.Add(objRow);

                     }
                     Master.FindControl("ContentPlaceHolder1").FindControl("PanelEncabezado").Controls.Add(tEncabezado);
                     ArmarTabla(oRegistro);

                 }

                 else
                 {
                     PanelEncabezado.Visible = false;
                     tEncabezado.Visible = false;
                     PanelPrimeraColumna.Visible=false;
                     tContenido0.Visible = false;
                     Panel1.Visible = false;
                     tContenido.Visible = false;
                     lblMensaje.Text = "No se encontraron protocolos para los filtros ingresados";
                     lblMensaje.Visible = true;
                     btnGuardar.Visible = false;
                     chkFormula.Visible = false;
                 }

        }

        private int CalcularLargo(int p)
        {
            if (p >20) return 20;
            else return p;
        }

        private void ArmarTabla(HojaTrabajo oRegistro)
        {
            //try
            //{

                ///Llena la tabla con los datos
                DataSet Ds = new DataSet();
                SqlConnection conn = (SqlConnection)NHibernateHttpModule.CurrentSession.Connection;
                SqlCommand cmd = new SqlCommand();
                cmd.CommandType = CommandType.StoredProcedure;

                string s_idHoja = Request["idHojaTrabajo"].ToString();
                Configuracion oCon = new Configuracion(); oCon = (Configuracion)oCon.Get(typeof(Configuracion), 1);

                if (oRegistro != null)
                {

            //        int tipo_HojaTrabajo = oRegistro.Formato;

                    //int columna_Control = 0;
                    //if (tipo_HojaTrabajo == 0)// formato prtocolo:filas - determinacion:columna
                    //{
                    //    cmd.CommandText = "LAB_TablaCruzada";
                    //    //columna_Control = 4;
                    //}
                    //else
                    //{/// sin uso este store
                    //    cmd.CommandText = "LAB_TablaCruzada2";
                    //    //columna_Control = 5;
                    //}
                    cmd.CommandText = "LAB_TablaCruzada";
                    cmd.Parameters.Add("@ListaProtocolos", SqlDbType.NVarChar);
                    cmd.Parameters["@ListaProtocolos"].Value = Session["Parametros"].ToString();
                    cmd.Parameters.Add("@IdHojaTrabajo", SqlDbType.NVarChar);
                    cmd.Parameters["@IdHojaTrabajo"].Value = oRegistro.IdHojaTrabajo.ToString(); // Request["idHojaTrabajo"].ToString();

                    cmd.Connection = conn;

                    SqlDataAdapter da = new SqlDataAdapter(cmd);

                    da.Fill(Ds);

                    //GridView1.DataSource = Ds;
                    //GridView1.DataBind();
                   //string validado = "0";
                    bool controlado = false;
                    for (int j = 0; j < Ds.Tables[0].Rows.Count; j++)
                    {

                        string m_nroprotocolo = "";
                        TableRow objRow = new TableRow();
                        //objRow.Height = Unit.Pixel(50);
                        for (int i = 0; i < Ds.Tables[0].Columns.Count; i++)
                        {
                            TableCell objCell = new TableCell();

                            if (i == 0) ///numero del protocolo o nombre del analisis segun sea el caso
                            {
                                TableRow objRow0 = new TableRow();
                              //  objRow0.Height = Unit.Pixel(40);
                                m_nroprotocolo = Ds.Tables[0].Rows[j].ItemArray[i].ToString();

                                Label lbl0 = new Label();
                                lbl0.Text = m_nroprotocolo;
                                lbl0.ID = m_nroprotocolo;
                                lbl0.ToolTip = "Haga clic aquí para ver más información del protocolo";
                                lbl0.Font.Size = FontUnit.Point(8);
                                lbl0.Font.Bold = true;
                                string s_idProtocolo = Ds.Tables[0].Rows[j].ItemArray[1].ToString();

                                lbl0.Attributes.Add("onClick", "javascript: protocoloView (" + s_idProtocolo + "); return false");
                                objCell.Height = Unit.Pixel(40);
                                objCell.BackColor = Color.WhiteSmoke;

                                if (true)// formato prtocolo:filas - determinacion:columna
                                {
                                    if (Request["Operacion"] != "Carga")
                                         {
                                    controlado = estaControladoProtocolo(Ds.Tables[0].Rows[j].ItemArray[1].ToString(), s_idHoja, Request["Operacion"].ToString());
                                    if (controlado)
                                    {///agrega tilde
                                        //Label oLblEstado = new Label();
                                        if (Request["Operacion"] == "Control")
                                        {
                                            objCell.BackColor = Color.LightGreen;
                                            //lbl0.ForeColor = Color.Green;
                                            lbl0.Font.Bold = true;
                                            lbl0.ToolTip = "Controlado";
                                            //oLblEstado.Text = "C";

                                        //oLblEstado.ForeColor = Color.Green;
                                        }
                                        if (Request["Operacion"] == "Valida")
                                        {
                                            objCell.BackColor = Color.LightBlue;
                                            //lbl0.ForeColor = Color.Blue;
                                            lbl0.Font.Bold = true;
                                            lbl0.ToolTip = "Validado";
                                            //oLblEstado.Text = "V";

                                            //oLblEstado.ForeColor = Color.Blue;
                                        }

                                    }

                                    //PanelPrimeraColumna.Width = Unit.Pixel(105);
                                    //tContenido0.Width = Unit.Pixel(105);
                                         }

                                }

                                Master.FindControl("ContentPlaceHolder1").FindControl("PanelPrimeraColumna").Controls.Add(lbl0);
                                objCell.Controls.Add(lbl0);

                                ////////////////////
                                if ((Request["idServicio"].ToString() == "4") && (Request["Operacion"].ToString() == "Valida")) //Pesquisa
                                {
                                    Protocolo oP = new Protocolo();
                                    oP = (Protocolo)oP.Get(typeof(Protocolo), int.Parse(s_idProtocolo));
                                    SolicitudScreening oSolicitud = new SolicitudScreening();
                                    oSolicitud = (Business.Data.Laboratorio.SolicitudScreening)oSolicitud.Get(typeof(Business.Data.Laboratorio.SolicitudScreening), "IdProtocolo", oP);
                                    if (oSolicitud != null)
                                    {
                                        int i_alarmas = oSolicitud.GetCantidadAlarmas();
                                        ImageButton imgPesquisa = new ImageButton();
                                        //imgPesquisa.TabIndex = short.Parse("500");
                                        imgPesquisa.ImageUrl = "~/App_Themes/default/images/pendiente.png";
                                        imgPesquisa.ToolTip = "Tiene " + i_alarmas.ToString() + " alarmas";
                                        imgPesquisa.Attributes.Add("onClick", "javascript: protocoloView (" + s_idProtocolo + "); return false");
                                        if (i_alarmas > 0) imgPesquisa.Visible = true; else imgPesquisa.Visible = false;
                                        Master.FindControl("ContentPlaceHolder1").FindControl("PanelPrimeraColumna").Controls.Add(imgPesquisa);
                                        objCell.Controls.Add(imgPesquisa);
                                    }
                                }

                                //////////////////

                                objRow0.Cells.Add(objCell);

                                if (Request["control"] != null)
                                {
                                    ////FUNCION DE CONTROL
                                    TableCell objCellControl = new TableCell();
                                    //objCellControl.Width=                                    Unit.Pixel(60);

                                    CheckBox chk1 = new CheckBox();
                                    chk1.ID = "chkc" + Ds.Tables[0].Rows[j].ItemArray[1].ToString();
                                    Master.FindControl("ContentPlaceHolder1").FindControl("PanelPrimeraColumna").Controls.Add(chk1);
                                    objCellControl.BackColor = Color.Beige;
                                    objCellControl.Controls.Add(chk1);
                                    objRow0.Cells.Add(objCellControl);

                                }
                                tContenido0.Controls.Add(objRow0);
                                Master.FindControl("ContentPlaceHolder1").FindControl("PanelPrimeraColumna").Controls.Add(tContenido0);
                            }

                            if (i >= 3)
                            {

                                string m_iditem = Ds.Tables[0].Columns[i].ToString();
                                string m_idprotocolo = Ds.Tables[0].Rows[j].ItemArray[0].ToString();
                                //if (tipo_HojaTrabajo == 0)// formato prtocolo:filas - determinacion:columna
                                //{
                                    m_iditem = Ds.Tables[0].Columns[i].ToString();
                                    m_idprotocolo = Ds.Tables[0].Rows[j].ItemArray[1].ToString();
                                    //m_idprotocolo = Ds.Tables[0].Rows[j].ItemArray[0].ToString();
                                //}
                                //else
                                //{
                                //    m_iditem = Ds.Tables[0].Rows[j].ItemArray[1].ToString();
                                //    m_idprotocolo = Ds.Tables[0].Columns[i].ToString();
                                //}

                                string m_valoritem = Ds.Tables[0].Rows[j].ItemArray[i].ToString();
                                string m_idControl = m_idprotocolo + "_" + m_iditem;

                                Item oItem = new Item();
                                oItem = (Item)oItem.Get(typeof(Item), int.Parse(m_iditem));
                                Label oLblXXX = new Label();
                                oLblXXX.Text = "";
                                if (oItem.IdTipoResultado == 1)
                                { objCell.Width = Unit.Pixel(80); oLblXXX.Width = Unit.Pixel(80); }
                                if (oItem.IdTipoResultado == 2)
                                { objCell.Width = Unit.Pixel(100);  oLblXXX.Width= Unit.Pixel(100);}
                                if (oItem.IdTipoResultado > 2)
                                { objCell.Width = Unit.Pixel(150); oLblXXX.Width = Unit.Pixel(150); }

                                objCell.Controls.Add(oLblXXX);

                                if (m_valoritem != "")
                                {

                                    string nombrePractica =  oItem.Nombre;
                                    Protocolo oP = new Protocolo();
                                    oP = (Protocolo)oP.Get(typeof(Protocolo), int.Parse(m_idprotocolo));
                                    DetalleProtocolo oDet = new DetalleProtocolo();
                                    oDet = (DetalleProtocolo)oDet.Get(typeof(DetalleProtocolo), "IdSubItem", oItem, "IdProtocolo", oP);
                                    //objCell.Height = Unit.Pixel(40);

                                    ///Antes de mostrar el control verifica  si está derivado
                                    if (oItem.IdEfectorDerivacion != oItem.IdEfector) //es derivado
                                    {
                                        Label lblDerivacion = new Label();
                                        lblDerivacion.Text = "Derivado";// +oItem.IdEfectorDerivacion.Nombre; /// Ds.Tables[0].Rows[i].ItemArray[1].ToString();
                                        lblDerivacion.Font.Italic = true;
                                        lblDerivacion.Font.Size = FontUnit.Point(8);
                                        lblDerivacion.ForeColor = Color.Red;
                                        objCell.Controls.Add(lblDerivacion);
                                        //objCell.Controls.Add(lblDerivacion);
                                    }
                                    else
                                    {//No es derivado

                                        switch (oItem.IdTipoResultado)
                                        {
                                            case 1: ///numerico
                                                {
                                                    Utility oUtil = new Utility();
                                                    TextBox txt1 = new TextBox();
                                                    txt1.ID = m_idControl;

                                                    decimal aux = decimal.Parse( m_valoritem);
                                                    string formato = oUtil.Formato(oItem.FormatoDecimal.ToString());
                                                    decimal x = decimal.Parse(aux.ToString(formato));

                                                    //decimal x = decimal.Parse(m_valoritem);
                                                    txt1.Text = x.ToString(System.Globalization.CultureInfo.InvariantCulture);
                                                    txt1.Width = Unit.Pixel(70);
                                                    txt1.CssClass = "myTexto";

                                                    txt1.Attributes.Add("onkeypress", "javascript:return Enter(this, event)");

                                                    if (oDet.ConResultado ==false)//no tiene resultado
                                                    {
                                                        if (oItem.ResultadoDefecto != "")
                                                            txt1.Text = oItem.ResultadoDefecto;
                                                        else
                                                            txt1.Text = "";
                                                    }

                                                    if (oDet.IdUsuarioValida > 0) // validado
                                                        txt1.BackColor = Color.LightBlue;
                                                    else
                                                        if (oDet.IdUsuarioControl > 0) // controlado
                                                            txt1.BackColor = Color.LightGreen;

                                                    if (Request["Operacion"] == "Control") // control
                                                        {
                                                    if (oDet.IdUsuarioValida > 0)
                                                        txt1.Enabled = false;
                                                        }
                                                    if (Request["Operacion"] == "Carga") // control
                                                    {
                                                        if (oDet.IdUsuarioControl > 0)
                                                            txt1.Enabled = false;
                                                        else
                                                        {
                                                            if (oDet.IdUsuarioValida > 0)
                                                                txt1.Enabled = false;
                                                        }
                                                    }
                                                    //else
                                                    //{
                                                    //    if ((Request["control"] == null) && (oDet.IdUsuarioControl > 0)) // carga
                                                    //    {
                                                    //        txt1.Enabled = false;
                                                    //    }
                                                    //}

                                                    ///Se agrega un validador de solo numeros
                                                    RegularExpressionValidator oValidaNumero = new RegularExpressionValidator();
                                                    oValidaNumero.ValidationExpression = ExpresionFormato(oItem.FormatoDecimal);
                                                    oValidaNumero.ControlToValidate = txt1.ID;
                                                    oValidaNumero.Width = Unit.Pixel(1);
                                                    oValidaNumero.Text = "*";
                                                    oValidaNumero.ValidationGroup = "0";
                                                    txt1.ToolTip = txt1.Text;

                                                    Master.FindControl("ContentPlaceHolder1").FindControl("Panel1").Controls.Add(txt1);
                                                    objCell.Controls.Add(txt1);

                                                    Master.FindControl("ContentPlaceHolder1").FindControl("Panel1").Controls.Add(oValidaNumero);
                                                    //objCell.Controls.AddAt(0,oValidaNumero);
                                                    objCell.Controls.Add(oValidaNumero);

                                                    objCell.Width = Unit.Pixel(80);
                                                }
                                                break;
                                            case 2: //texto
                                                {
                                                    TextBox txt1 = new TextBox();
                                                    txt1.ID = m_idControl;
                                                    txt1.CssClass = "myTexto";
                                                    txt1.Width = Unit.Pixel(90);
                                                    txt1.TextMode = TextBoxMode.MultiLine;
                                                    txt1.Rows = 1;
                                                    txt1.MaxLength = 200;

                                                    if (oDet != null)
                                                    {
                                                        if (oDet.ConResultado == false)
                                                        {
                                                            if (oItem.ResultadoDefecto != "")
                                                                txt1.Text = oItem.ResultadoDefecto;
                                                            else
                                                                txt1.Text = "";
                                                        }
                                                        else
                                                        {
                                                            string resNum = oDet.ResultadoNum.ToString();
                                                            if ((oDet.ResultadoCar == "") && (oDet.Enviado == 2) && (oDet.IdUsuarioValida==0) && (oDet.IdUsuarioResultado==0)) // automatico
                                                            {
                                                                if (resNum != "") txt1.Text = resNum.Substring(0, resNum.Length - 2).Replace(",", ".");
                                                            }
                                                            else
                                                            txt1.Text = oDet.ResultadoCar;
                                                        }
                                                    }

                                                    if (oDet.IdUsuarioValida > 0) // validado
                                                        txt1.BackColor = Color.LightBlue;
                                                    else
                                                        if (oDet.IdUsuarioControl > 0) // controlado
                                                            txt1.BackColor = Color.LightGreen;

                                                    if (Request["Operacion"] == "Control") // control
                                                    {
                                                        if (oDet.IdUsuarioValida > 0)
                                                            txt1.Enabled = false;
                                                    }
                                                    if (Request["Operacion"] == "Carga") // control
                                                    {
                                                        if (oDet.IdUsuarioControl > 0)
                                                            txt1.Enabled = false;
                                                        else
                                                        {
                                                            if (oDet.IdUsuarioValida > 0)
                                                                txt1.Enabled = false;
                                                        }
                                                    }

                                                    txt1.ToolTip = txt1.Text;
                                                    objCell.Controls.Add(txt1);
                                                    objCell.Width = Unit.Pixel(100);

                                                } // fin case 2
                                                break;
                                            case 3: //Lista predefinida
                                                {

                                                    //Verifica si la determinacion tiene una lista predeterminada de resultados
                                                    ISession m_session = NHibernateHttpModule.CurrentSession;
                                                    ICriteria crit = m_session.CreateCriteria(typeof(ResultadoItem));
                                                    crit.Add(Expression.Eq("IdItem", oItem));
                                                    crit.Add(Expression.Eq("Baja", false));

                                                    ///Si tiene resultados predeterminados muestra un combo
                                                    IList resultados = crit.List();
                                                    if (resultados.Count > 0)
                                                    {
                                                        DropDownList ddl1 = new DropDownList();
                                                        //ddl1.Font.Size = FontUnit.Point(7);
                                                        ListItem ItemSeleccion = new ListItem();
                                                        ItemSeleccion.Value = "0";
                                                        ItemSeleccion.Text = "";

                                                        ddl1.ToolTip = nombrePractica;
                                                        ddl1.Items.Add(ItemSeleccion);
                                                        foreach (ResultadoItem oResultado in resultados)
                                                        {
                                                            ListItem Item = new ListItem();
                                                            Item.Value = oResultado.IdResultadoItem.ToString();
                                                            Item.Text = oResultado.Resultado;

                                                            ddl1.ID = m_idControl;
                                                            ddl1.Items.Add(Item);
                                                            //ddl1.SelectedItem.Text = Ds.Tables[0].Rows[i].ItemArray[4].ToString();
                                                            ddl1.SelectedIndexChanged += new EventHandler(ddl1_SelectedIndexChanged);

                                                        }

                                                        if (oDet != null)
                                                        {
                                                            if (oDet.ConResultado == false) // sin resultado
                                                            {
                                                                if (oItem.ResultadoDefecto != "")
                                                                    ddl1.SelectedValue = oItem.IdResultadoPorDefecto.ToString();
                                                                else
                                                                    ddl1.SelectedValue= "0";
                                                            }
                                                            else

                                                                ddl1.SelectedItem.Text = oDet.ResultadoCar;
                                                        }

                                                        if (oDet.IdUsuarioValida > 0) // validado
                                                            ddl1.BackColor = Color.LightBlue;
                                                        else
                                                            if (oDet.IdUsuarioControl > 0) // controlado
                                                                ddl1.BackColor = Color.LightGreen;

                                                        if (Request["Operacion"] == "Control") // control
                                                        {
                                                            if (oDet.IdUsuarioValida > 0)
                                                                ddl1.Enabled = false;
                                                        }
                                                        if (Request["Operacion"] == "Carga") // control
                                                        {
                                                            if (oDet.IdUsuarioControl > 0)
                                                                ddl1.Enabled = false;
                                                            else
                                                            {
                                                                if (oDet.IdUsuarioValida > 0)
                                                                    ddl1.Enabled = false;
                                                            }
                                                        }

                                                        ddl1.Width = Unit.Pixel(150);
                                                        objCell.Controls.Add(ddl1);
                                                        objCell.Width = Unit.Pixel(150);
                                                    }
                                                }
                                                break;
                                            case 4: //Lista predefinida con seleccion multiple (sin seleccion multiple...jiji)
                                                {

                                                    //Verifica si la determinacion tiene una lista predeterminada de resultados
                                                    ISession m_session = NHibernateHttpModule.CurrentSession;
                                                    ICriteria crit = m_session.CreateCriteria(typeof(ResultadoItem));
                                                    crit.Add(Expression.Eq("IdItem", oItem));
                                                    crit.Add(Expression.Eq("Baja", false));

                                                    ///Si tiene resultados predeterminados muestra un combo
                                                    IList resultados = crit.List();
                                                    if (resultados.Count > 0)
                                                    {
                                                        DropDownList ddl1 = new DropDownList();
                                                        //ddl1.Font.Size = FontUnit.Point(7);
                                                        ListItem ItemSeleccion = new ListItem();
                                                        ItemSeleccion.Value = "0";
                                                        ItemSeleccion.Text = "";

                                                        ddl1.ToolTip = nombrePractica;
                                                        ddl1.Items.Add(ItemSeleccion);
                                                        foreach (ResultadoItem oResultado in resultados)
                                                        {
                                                            ListItem Item = new ListItem();
                                                            Item.Value = oResultado.IdResultadoItem.ToString();
                                                            Item.Text = oResultado.Resultado;

                                                            ddl1.ID = m_idControl;

                                                            ddl1.Items.Add(Item);
                                                            //ddl1.SelectedItem.Text = Ds.Tables[0].Rows[i].ItemArray[4].ToString();
                                                            ddl1.SelectedIndexChanged += new EventHandler(ddl1_SelectedIndexChanged);

                                                        }

                                                        if (oDet != null)
                                                        {
                                                            if (oDet.ConResultado == false) // sin resultado
                                                            {
                                                                if (oItem.ResultadoDefecto != "")
                                                                    ddl1.SelectedValue = oItem.IdResultadoPorDefecto.ToString();
                                                                else
                                                                    ddl1.SelectedValue = "0";
                                                            }
                                                            else

                                                                ddl1.SelectedItem.Text = oDet.ResultadoCar;
                                                        }

                                                        if (oDet.IdUsuarioValida > 0) // validado
                                                            ddl1.BackColor = Color.LightBlue;
                                                        else
                                                            if (oDet.IdUsuarioControl > 0) // controlado
                                                                ddl1.BackColor = Color.LightGreen;

                                                        if (Request["Operacion"] == "Control") // control
                                                        {
                                                            if (oDet.IdUsuarioValida > 0)
                                                                ddl1.Enabled = false;
                                                        }
                                                        if (Request["Operacion"] == "Carga") // control
                                                        {
                                                            if (oDet.IdUsuarioControl > 0)
                                                                ddl1.Enabled = false;
                                                            else
                                                            {
                                                                if (oDet.IdUsuarioValida > 0)
                                                                    ddl1.Enabled = false;
                                                            }
                                                        }

                                                        ddl1.Width= Unit.Pixel(150);
                                                        objCell.Controls.Add(ddl1);
                                                        objCell.Width = Unit.Pixel(150);
                                                    }
                                                }
                                                break;

                                        }
                                    }

                                }

                                objCell.Height = Unit.Pixel(40);
                                objRow.Cells.Add(objCell);
                            }
                        }
                        tContenido.Controls.Add(objRow);
                    }
                    Master.FindControl("ContentPlaceHolder1").FindControl("Panel1").Controls.Add(tContenido);
                }

        }

        private string ExpresionFormato(int p)
        {
            string expresionControlDecimales = "[-+]?\\d*\\.?\\,?\\d{0,2}";
            switch (p)
            {
                case 0:
                    {
                        expresionControlDecimales = "[-+]?\\d*";
                    }
                    break;
                case 1:
                    {
                        expresionControlDecimales = "[-+]?\\d*\\.?\\,?\\d{0,1}";

                    } break;
                case 2:
                    {
                        expresionControlDecimales = "[-+]?\\d*\\.?\\,?\\d{0,2}";

                    } break;
                case 3:
                    {
                        expresionControlDecimales = "[-+]?\\d*\\.?\\,?\\d{0,3}";

                    } break;
                case 4:
                    {
                        expresionControlDecimales = "[-+]?\\d*\\.?\\,?\\d{0,4}";

                    } break;
            }
            return expresionControlDecimales;
        }

        void ddl1_SelectedIndexChanged(object sender, EventArgs e)
        {
            DropDownList ddl1 = (DropDownList)sender;
        }

        protected void btnGuardar_Click(object sender, EventArgs e)
        {
            if (Page.IsValid)
            {
                Guardar(true);
                ////Guardar y Salir
                if (Request["control"] != null) // muestra la misma pantalla con los valores controlados y la marca de control.
                    if (Request["Operacion"].ToString()=="Control")
                    Response.Redirect("../ControlResultados/ControlPlanilla.aspx?tipo=ht&idArea=" + Request["idArea"].ToString() + "&idHojaTrabajo=" + Request["idHojaTrabajo"].ToString() + "&control=1", false);
                    else
                        Response.Redirect("ResultadoBusqueda.aspx?idServicio=" + Request["idServicio"].ToString() + "&Operacion=Valida&modo=Normal", false);
                else /// redirecciona a los filtros de busqueda nuevamente.
                    Response.Redirect("ResultadoBusqueda.aspx?idServicio=" + Request["idServicio"].ToString() + "&Operacion=Carga&modo=Normal", false);
                //    Response.Redirect("ResultadoHTEdit.aspx?Parametros=" + Request["Parametros"] + "&idArea=" + Request["idArea"].ToString() + "&idHojaTrabajo=" + Request["idHojaTrabajo"].ToString() , false);

            }
        }

        protected void btnValidarPendienteySalir_Click(object sender, EventArgs e)
        {
            if (Page.IsValid)
            {
                Guardar(false);
                ////Guardar y Salir
                if (Request["control"] != null) // muestra la misma pantalla con los valores controlados y la marca de control.
                    if (Request["Operacion"].ToString() == "Control")
                        Response.Redirect("../ControlResultados/ControlPlanilla.aspx?tipo=ht&idArea=" + Request["idArea"].ToString() + "&idHojaTrabajo=" + Request["idHojaTrabajo"].ToString() + "&control=1", false);
                    else
                        Response.Redirect("ResultadoBusqueda.aspx?idServicio=" + Request["idServicio"].ToString() + "&Operacion=Valida&modo=Normal", false);
                else /// redirecciona a los filtros de busqueda nuevamente.
                    Response.Redirect("ResultadoBusqueda.aspx?idServicio=" + Request["idServicio"].ToString() + "&Operacion=Carga&modo=Normal", false);
                //    Response.Redirect("ResultadoHTEdit.aspx?Parametros=" + Request["Parametros"] + "&idArea=" + Request["idArea"].ToString() + "&idHojaTrabajo=" + Request["idHojaTrabajo"].ToString() , false);

            }
        }

        private void Guardar( bool todo)
        {
            //string m_id = "";

            //Label lbl;
            TextBox txt;
            DropDownList ddl;

            if (Page.Master != null)
            {
                foreach (Control control in Page.Master.Controls)
                {
                    if (control is HtmlForm)
                    {
                        foreach (Control controlform in control.Controls)
                        {
                            if (controlform is ContentPlaceHolder)
                            {
                                foreach (Control control1 in controlform.Controls)
                                {
                                    if (control1 is Panel)
                                        foreach (Control control2 in control1.Controls)
                                        {
                                            if (control2 is Table)
                                                foreach (Control control3 in control2.Controls)
                                                {

                                                    if (control3 is TableRow)
                                                        foreach (Control control4 in control3.Controls)
                                                        {

                                                            if (control4 is TableCell)
                                                                foreach (Control control5 in control4.Controls)
                                                                {
                                                                    if (control5 is TextBox)
                                                                    {
                                                                        txt = (TextBox)control5;
                                                                        if (txt.Enabled) GuardarResultado(txt.ID, txt.Text, todo);

                                                                    }

                                                                    if (control5 is DropDownList)
                                                                    {
                                                                        ddl = (DropDownList)control5;
                                                                        if (ddl.Enabled) GuardarResultado(ddl.ID, ddl.SelectedItem.Text, todo);
                                                                    }
                                                                }
                                                        }
                                                }
                                        }
                                }
                            }
                        }
                    }
                }
            }

        }

        private void GuardarResultado(string m_idControl, string valorItem, bool todo)
        {
         //   bool b_guardar = true;
            string aux = m_idControl;
            string[] arr = aux.Split(("_").ToCharArray());

            string id_Protocolo = arr[0].ToString();
            string m_idItem = arr[1].ToString();

            //Usuario oUser = new Usuario();
            Protocolo oProtocolo = new Protocolo();
            oProtocolo = (Protocolo)oProtocolo.Get(typeof(Protocolo), int.Parse(id_Protocolo));
            //oProtocolo.CalcularFormulas();
     //       oProtocolo.CalcularFormulas(Request["Operacion"].ToString(), int.Parse(Session["idUsuario"].ToString()));

            //if (oProtocolo.Estado == 0)
            //{
            //    if (oProtocolo.EnProceso())
            //    {
            //        oProtocolo.Estado = 1;//en proceso
            //       // oProtocolo.ActualizarResultados(Request["Operacion"].ToString(), int.Parse(Session["idUsuario"].ToString()));
            //    }
            //}

            if (valorItem != "")
            {

                string s_unidadMedida = ""; //string s_metodo = "";
                Item oItem = new Item();
                oItem = (Item)oItem.Get(typeof(Item), int.Parse(m_idItem));
                if (oItem.IdUnidadMedida>0)
                {
                    UnidadMedida  oUnidad = new UnidadMedida();
                    oUnidad= (UnidadMedida)oUnidad.Get(typeof(UnidadMedida),oItem.IdUnidadMedida);
                    if (oUnidad!=null)  s_unidadMedida= oUnidad.Nombre;
                }

                int tiporesultado = oItem.IdTipoResultado;

                ISession m_session = NHibernateHttpModule.CurrentSession;
                ICriteria crit = m_session.CreateCriteria(typeof(DetalleProtocolo));
                crit.Add(Expression.Eq("IdSubItem", oItem));
                crit.Add(Expression.Eq("IdProtocolo", oProtocolo));
                if (!todo) crit.Add(Expression.Eq("IdUsuarioValida", 0));
                //crit.Add(Expression.Eq("IdEfector", oProtocolo.IdEfector));

                IList detalle = crit.List();
                if (detalle.Count > 0)
                {
                    foreach (DetalleProtocolo oDetalle in detalle)
                    {
                        string valorReferencia = oDetalle.CalcularValoresReferencia();
                        oDetalle.ValorReferencia = valorReferencia;
                        switch (tiporesultado)
                        {
                            case 1:// numerico
                                if (valorItem != "")
                                {
                                    oDetalle.UnidadMedida = s_unidadMedida;
                                    oDetalle.ResultadoNum = decimal.Parse(valorItem, System.Globalization.CultureInfo.InvariantCulture);
                                    oDetalle.FormatoValida = oItem.FormatoDecimal;
                                    oDetalle.ConResultado = true;
                                }
                                else
                                {
                                    oDetalle.ResultadoNum = 0;
                                    oDetalle.ConResultado = false;
                                }
                                break;
                            default:
                                {
                                    oDetalle.UnidadMedida = s_unidadMedida;
                                    oDetalle.ResultadoCar = valorItem;
                                    oDetalle.ConResultado = true;
                                } break;

                        }

                        if (Request["control"] ==null) //no es control
                        {
                            if (oDetalle.ConResultado)
                            {
                                oDetalle.IdUsuarioResultado = int.Parse(Session["idUsuario"].ToString());
                                oDetalle.FechaResultado = DateTime.Now;
                            }

                            oDetalle.Save();
                            if (oDetalle.ConResultado) oDetalle.GrabarAuditoriaDetalleProtocolo("Alta", int.Parse(Session["idUsuario"].ToString()));

                        }
                        if (Request["control"] != null) // es control
                        {

                            HojaTrabajo oRegistro = new HojaTrabajo();
                            oRegistro = (HojaTrabajo)oRegistro.Get(typeof(HojaTrabajo), int.Parse(Request["idHojaTrabajo"].ToString()));
                            int tipo_HojaTrabajo = oRegistro.Formato;
                            string s_pivot = "";
                            if (tipo_HojaTrabajo == 0)  //por protocolo
                            { s_pivot = id_Protocolo; }
                            else
                            { s_pivot = m_idItem; }

                            if (oDetalle.ConResultado)
                            {
                                if (estaTildado(s_pivot))
                                {
                                    if (!oDetalle.ConResultado)
                                    {
                                        oDetalle.ConResultado = true;
                                        oDetalle.IdUsuarioResultado = int.Parse(Session["idUsuario"].ToString());
                                        oDetalle.FechaResultado = DateTime.Now;
                                        oDetalle.Save();
                                    }
                                    if (Request["Operacion"].ToString() == "Valida")   //Validacion
                                    {
                                        if (oDetalle.ConResultado)
                                        {
                                            oDetalle.IdUsuarioValida = int.Parse(Session["idUsuarioValida"].ToString());
                                            oDetalle.FechaValida = DateTime.Now;

                                            oDetalle.Save();
                                            if (oDetalle.ConResultado) oDetalle.GrabarAuditoriaDetalleProtocolo(Request["Operacion"].ToString(), int.Parse(Session["idUsuarioValida"].ToString()));
                                        }
                                    }
                                    if (Request["Operacion"].ToString() == "Control")   //Control
                                    {
                                        oDetalle.IdUsuarioControl = int.Parse(Session["idUsuario"].ToString());
                                        oDetalle.FechaControl = DateTime.Now;
                                        oDetalle.Save();
                                        oDetalle.GrabarAuditoriaDetalleProtocolo("Control", int.Parse(Session["idUsuario"].ToString()));
                                    }
                                }
                            }
                        }
                    }

                if (Request["Operacion"].ToString() != "Valida")
                {
                    if (oProtocolo.Estado == 0)
                    {
                        if (oProtocolo.EnProceso())
                        {
                            oProtocolo.Estado = 1;//en proceso
                            // oProtocolo.ActualizarResultados(Request["Operacion"].ToString(), int.Parse(Session["idUsuario"].ToString()));
                        }
                    }
                }
                else //Validacion
                {
                    if (oProtocolo.ValidadoTotal(Request["Operacion"].ToString(), int.Parse(Session["idUsuario"].ToString())))
                        oProtocolo.Estado = 2;  //validado total (cerrado);
                    else
                        oProtocolo.Estado = 1;
                }
                oProtocolo.Save();
                }
            }

        }
        protected void lnkMarcarControl_Click(object sender, EventArgs e)
        {
          //  Marcar(true);
        }

        protected void lnkDesmarcarControl_Click(object sender, EventArgs e)
        {
          //  Marcar(false );
        }
        private bool estaTildado(string m_id)
        {
            string nombre_control =  "chkc" + m_id;

            Control control1 = Master.FindControl("ContentPlaceHolder1").FindControl("Panel1").FindControl(nombre_control);
            CheckBox chk = (CheckBox)control1;
            if (chk != null)
            {
                if (chk.Checked) return true;
                else return false;
            }
            else
                return false;
        }

        protected void cvValidaControles_ServerValidate(object source, ServerValidateEventArgs args)
        {
            if (ValidaControles())
                args.IsValid = true;
            else
                args.IsValid = false;
        }

        protected void lnkRegresar_Click(object sender, EventArgs e)
        {
            if (Request["control"]!=null)

                  if (Request["Operacion"].ToString()=="Control")
                    Response.Redirect("../ControlResultados/ControlPlanilla.aspx?tipo=ht&idArea=" + Request["idArea"].ToString() + "&idHojaTrabajo=" + Request["idHojaTrabajo"].ToString() + "&control=1", false);
                    else
                        Response.Redirect("ResultadoBusqueda.aspx?idServicio=" + Request["idServicio"].ToString() + "&Operacion=Valida&modo=Normal", false);
                 //Response.Redirect("../ControlResultados/ControlPlanilla.aspx?tipo=ht", false);
            else

                Response.Redirect("ResultadoBusqueda.aspx?idServicio=" + Request["idServicio"].ToString() + "&Operacion=Carga&modo=Normal", false);
        }

        private bool ValidaControles()
        {
            bool valida = true;
        //    string m_id = "";

          //  Label lbl;
            TextBox txt;
         //   DropDownList ddl;

            if (Page.Master != null)
            {
                foreach (Control control in Page.Master.Controls)
                {
                    if (control is HtmlForm)
                    {
                        foreach (Control controlform in control.Controls)
                        {
                            if (controlform is ContentPlaceHolder)
                            {
                                foreach (Control control1 in controlform.Controls)
                                {
                                    if (control1 is Panel)
                                        foreach (Control control2 in control1.Controls)
                                        {
                                            if (control2 is Table)
                                                foreach (Control control3 in control2.Controls)
                                                {

                                                    if (control3 is TableRow)
                                                        foreach (Control control4 in control3.Controls)
                                                        {

                                                            if (control4 is TableCell)
                                                                foreach (Control control5 in control4.Controls)
                                                                {
                                                                    if (control5 is TextBox)
                                                                    {
                                                                        txt = (TextBox)control5;
                                                                        if (txt.Enabled)
                                                                        {

                                                                            valida = ValidarValor(txt.ID, txt.Text);

                                                                            if (!valida) { return false; }
                                                                        }
                                                                    }

                                                                }
                                                        }
                                                }
                                        }
                                }
                            }
                        }
                    }
                }
            }
            return valida;

        }

        private bool ValidarValor(string m_idControl, string valorItem)
        {
            string aux = m_idControl;
            string[] arr = aux.Split(("_").ToCharArray());

            string id_Protocolo = arr[0].ToString();
            string m_idItem = arr[1].ToString();

            bool control = true;

            Item oItem= new Item();
            oItem= (Item)oItem.Get(typeof(Item), int.Parse( m_idItem));

            if ((oItem.Multiplicador > 1) && (valorItem != ""))
            {
               valorItem= AplicarMultiplicador(m_idControl, oItem);
            }

            if (!oItem.VerificaValoresMinimosMaximos(valorItem))
            { cvValidaControles.ErrorMessage = "Error de validación en " + oItem.Nombre; control = false; return control; }

            return control;
        }

        private string AplicarMultiplicador(string m_idControl,   Item oItem)
        {
            string aux = m_idControl;
            string[] arr = aux.Split(("_").ToCharArray());

            string id_Protocolo = arr[0].ToString();
        //    string m_idItem = arr[1].ToString();
            string valorItem = "0";

            Protocolo oProtocolo = new Protocolo();
            oProtocolo = (Protocolo)oProtocolo.Get(typeof(Protocolo), int.Parse(id_Protocolo));

            ISession m_session = NHibernateHttpModule.CurrentSession;

            ICriteria crit2 = m_session.CreateCriteria(typeof(DetalleProtocolo));
            crit2.Add(Expression.Eq("IdSubItem", oItem));
            crit2.Add(Expression.Eq("IdProtocolo", oProtocolo));
//            crit2.Add(Expression.Eq("IdEfector", oProtocolo.IdEfector));

            IList detalleProtocolo = crit2.List();
            if (detalleProtocolo.Count > 0)
            {
                foreach (DetalleProtocolo oDetalle in detalleProtocolo)
                {
                    decimal valorActual = Math.Round(oDetalle.ResultadoNum, oDetalle.IdSubItem.FormatoDecimal);
                    valorItem =valorActual.ToString(System.Globalization.CultureInfo.InvariantCulture) ;
                    Control control1 = Master.FindControl("ContentPlaceHolder1").FindControl("Panel1").FindControl(m_idControl);
                    TextBox txt = txt = (TextBox)control1;
                    if (txt != null)
                    {
                        if (txt.Text != valorActual.ToString(System.Globalization.CultureInfo.InvariantCulture))  // si no tiene resultados
                            {
                            decimal resultadoNumerico = decimal.Parse(txt.Text, System.Globalization.CultureInfo.InvariantCulture) * oDetalle.IdSubItem.Multiplicador;
                            txt.Text = resultadoNumerico.ToString(System.Globalization.CultureInfo.InvariantCulture);
                            valorItem = txt.Text;
                            }
                    }
                }
            }
            return valorItem;

        }

        private bool VerificaValoresMinimosMaximos(Item oItem)
        {
            bool devolver = true;
            try
            {
                if (oItem.IdTipoResultado == 1) //solo para los numericos
                {
                    decimal m_minimo = oItem.ValorMinimo;
                    decimal m_maximo = oItem.ValorMaximo;
                    if ((m_minimo != -1) && (m_maximo != -1))  //si tiene valores minimos y maximos predefinidos
                    {

                        Control control1 = Master.FindControl("ContentPlaceHolder1").FindControl("Panel1").FindControl(oItem.IdItem.ToString());
                        TextBox txt = txt = (TextBox)control1;
                        decimal valor = decimal.Parse(txt.Text);
                        if (valor < m_minimo)
                            devolver = false;
                        if (valor > m_maximo)
                            devolver = false;
                    }
                }
            }
            catch { devolver = false; }

            return devolver;
        }

        private bool estaControladoProtocolo(string m_idprotocolo, string m_idhoja, string operacion)
        {
            bool controlado = true;

            Protocolo oProtocolo = new Protocolo();
            oProtocolo = (Protocolo)oProtocolo.Get(typeof(Protocolo), int.Parse(m_idprotocolo));

            HojaTrabajo oHojaTrabajo = new HojaTrabajo();
            oHojaTrabajo = (HojaTrabajo)oHojaTrabajo.Get(typeof(HojaTrabajo), int.Parse(m_idhoja));

            ISession m_session = NHibernateHttpModule.CurrentSession;

            ICriteria crit = m_session.CreateCriteria(typeof(DetalleHojaTrabajo));
            crit.Add(Expression.Eq("IdHojaTrabajo", oHojaTrabajo));

            IList detalle = crit.List();
            if (detalle.Count > 0)
            {
                foreach (DetalleHojaTrabajo oDetalle in detalle)
                {

                    /////////////
                    ICriteria crit2 = m_session.CreateCriteria(typeof(DetalleProtocolo));
                    crit2.Add(Expression.Eq("IdSubItem", oDetalle.IdItem));
                    crit2.Add(Expression.Eq("IdProtocolo", oProtocolo));
                    crit2.Add(Expression.Eq("IdEfector", oProtocolo.IdEfector));

                    IList detalleProtocolo = crit2.List();
                    if (detalleProtocolo.Count > 0)
                    {
                        foreach (DetalleProtocolo oDetalleProtocolo in detalleProtocolo)
                        {
                            if (operacion=="Control"){
                                if (oDetalleProtocolo.IdUsuarioControl == 0)
                                {
                                    controlado = false;
                                    break;
                                }
                            }
                            if (operacion == "Valida")
                            {
                                if (oDetalleProtocolo.IdUsuarioValida == 0)
                                {
                                    controlado = false;
                                    break;
                                }
                            }

                        }
                    }
                    /////
                    if (!controlado) break;

                }
            }

            return controlado;
        }

        protected void btnValidarPendiente_Click(object sender, EventArgs e)
        {
            if (Page.IsValid)
            {
                Guardar(false);
                ////Guarda y se queda en la pantalla
                if (Request["control"] != null) // muestra la misma pantalla con los valores controlados y la marca de control.
                    Response.Redirect("ResultadoHTEdit.aspx?idArea=" + Request["idArea"].ToString() + "&Operacion=" + Request["Operacion"].ToString() + "&idHojaTrabajo=" + Request["idHojaTrabajo"].ToString() + "&control=1&idServicio=" + Request["idServicio"].ToString(), false);
                else /// redirecciona a los filtros de busqueda nuevamente.
                    //    Response.Redirect("ResultadoBusqueda.aspx?idServicio=" + Request["idServicio"].ToString() + "&Operacion=Carga&modo=Normal", false);
                    Response.Redirect("ResultadoHTEdit.aspx?idArea=" + Request["idArea"].ToString() + "&Operacion=Carga&idHojaTrabajo=" + Request["idHojaTrabajo"].ToString() + "&idServicio=" + Request["idServicio"].ToString(), false);

                //Guardar();
                //////Guardar y Salir
                //if (Request["control"] != null) // muestra la misma pantalla con los valores controlados y la marca de control.
                //    if (Request["Operacion"].ToString() == "Control")
                //        Response.Redirect("../ControlResultados/ControlPlanilla.aspx?tipo=ht&idArea=" + Request["idArea"].ToString() + "&idHojaTrabajo=" + Request["idHojaTrabajo"].ToString() + "&control=1", false);
                //    else
                //        Response.Redirect("ResultadoBusqueda.aspx?idServicio=" + Request["idServicio"].ToString() + "&Operacion=Valida&modo=Normal", false);
                //else /// redirecciona a los filtros de busqueda nuevamente.
                //    Response.Redirect("ResultadoBusqueda.aspx?idServicio=" + Request["idServicio"].ToString() + "&Operacion=Carga&modo=Normal", false);
            }

        }

        protected void btnGuardarParcial_Click(object sender, EventArgs e)
        {
            if (Page.IsValid)
            {
                Guardar(true);
                ////Guarda y se queda en la pantalla
                if (Request["control"] != null) // muestra la misma pantalla con los valores controlados y la marca de control.
                    Response.Redirect("ResultadoHTEdit.aspx?idArea=" + Request["idArea"].ToString()  +"&Operacion=" + Request["Operacion"].ToString() + "&idHojaTrabajo=" + Request["idHojaTrabajo"].ToString() + "&control=1&idServicio=" + Request["idServicio"].ToString(), false);
                else /// redirecciona a los filtros de busqueda nuevamente.
                    //    Response.Redirect("ResultadoBusqueda.aspx?idServicio=" + Request["idServicio"].ToString() + "&Operacion=Carga&modo=Normal", false);
                    Response.Redirect("ResultadoHTEdit.aspx?idArea=" + Request["idArea"].ToString()  + "&Operacion=Carga&idHojaTrabajo=" + Request["idHojaTrabajo"].ToString()+"&idServicio=" + Request["idServicio"].ToString(), false);

                //Guardar();
                //////Guardar y Salir
                //if (Request["control"] != null) // muestra la misma pantalla con los valores controlados y la marca de control.
                //    if (Request["Operacion"].ToString() == "Control")
                //        Response.Redirect("../ControlResultados/ControlPlanilla.aspx?tipo=ht&idArea=" + Request["idArea"].ToString() + "&idHojaTrabajo=" + Request["idHojaTrabajo"].ToString() + "&control=1", false);
                //    else
                //        Response.Redirect("ResultadoBusqueda.aspx?idServicio=" + Request["idServicio"].ToString() + "&Operacion=Valida&modo=Normal", false);
                //else /// redirecciona a los filtros de busqueda nuevamente.
                //    Response.Redirect("ResultadoBusqueda.aspx?idServicio=" + Request["idServicio"].ToString() + "&Operacion=Carga&modo=Normal", false);
            }

        }

    }

}


text:
<?xml version="1.0" encoding="UTF-8"?>
<sbml xmlns="http://www.sbml.org/sbml/level3/version1/core" level="3" version="1">
  <model timeUnits="time">
    <listOfUnitDefinitions>
      <unitDefinition id="volume">
        <listOfUnits>
          <unit kind="litre" exponent="1" scale="0" multiplier="1"/>
        </listOfUnits>
      </unitDefinition>
      <unitDefinition id="time">
        <listOfUnits>
          <unit kind="second" exponent="1" scale="0" multiplier="1"/>
        </listOfUnits>
      </unitDefinition>
    </listOfUnitDefinitions>
    <listOfCompartments>
      <compartment id="c" spatialDimensions="3" units="volume" constant="false"/>
    </listOfCompartments>
    <listOfParameters>
      <parameter id="p" value="1" constant="false" units="dimensionless"/>
      <parameter id="p1" value="1" units="metre" constant="false"/>
      <parameter id="delta_t" value="1" units="time" constant="false"/>
    </listOfParameters>
    <listOfRules>
      <algebraicRule>
        <math xmlns="http://www.w3.org/1998/Math/MathML">
          <apply>
            <times/>
            <ci> p </ci>
            <apply>
              <csymbol encoding="text" definitionURL="http://www.sbml.org/sbml/symbols/delay"> delay </csymbol>
              <ci> p1 </ci>
              <ci> delta_t </ci>
            </apply>
          </apply>
        </math>
      </algebraicRule>
    </listOfRules>
  </model>
</sbml>

redpajama_set_name: RedPajamaGithub


text:
package org.apache.flink.table.planner.plan.nodes.exec.stream;

import org.apache.flink.table.data.RowData;
import org.apache.flink.table.planner.plan.nodes.exec.InputProperty;
import org.apache.flink.table.planner.plan.nodes.exec.common.CommonExecLookupJoin;
import org.apache.flink.table.planner.plan.utils.LookupJoinUtil;
import org.apache.flink.table.runtime.operators.join.FlinkJoinType;
import org.apache.flink.table.types.logical.RowType;

import org.apache.calcite.plan.RelOptTable;
import org.apache.calcite.rex.RexNode;
import org.apache.calcite.rex.RexProgram;

import javax.annotation.Nullable;

import java.util.Map;

/** {@link StreamExecNode} for temporal table join that implemented by lookup. */
public class StreamExecLookupJoin extends CommonExecLookupJoin implements StreamExecNode<RowData> {
    public StreamExecLookupJoin(
            FlinkJoinType joinType,
            @Nullable RexNode joinCondition,
            RelOptTable temporalTable,
            @Nullable RexProgram calcOnTemporalTable,
            Map<Integer, LookupJoinUtil.LookupKey> lookupKeys,
            InputProperty inputProperty,
            RowType outputType,
            String description) {
        super(
                joinType,
                joinCondition,
                temporalTable,
                calcOnTemporalTable,
                lookupKeys,
                inputProperty,
                outputType,
                description);
    }
}


text:
<?php $this->load->view('developer_header'); ?>

Location Capture Widget

<?php echo anchor('/', 'Home'); ?>

<?php echo anchor('/documentation/widgets/', 'Widgets'); ?>

Location Capture Widget

What is this widget?

The ANDS Location Capture Widget allows you to instantly enrich your data capture system, adding geospatial capabilities such as custom drawings and place name resolution (using the Australian Gazetteer Service and Google Maps API).

How does it work?

Simply drop the following lines of HTML into your web form. You only need to specify the name of the form field and the widget will do the rest!

					 Step 1. Drop this code somewhere in the <head></head> of your web page

<script type="text/javascript" src="//maps.google.com/maps/api/js?sensor=false&libraries=drawing&v=3"></script>
<script src='//ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.js'></script>
<script type="text/javascript" src="<?=remove_scheme(apps_url('assets/location_capture_widget/js/location_capture_widget.js'));?>"></script>
<link rel="stylesheet" type="text/css" href="<?=remove_scheme(apps_url('assets/location_capture_widget/css/location_capture_widget.css'));?>" />

					Step 2. Invoke the plugin using this code towards the bottom of the page. This example invokes the plugin on an HTML element with id mapContainer, and stores the final coordinate data in the HTML element with id coordinates:

<script type="text/javascript">
  $(document).ready(function() {
	$("#mapContainer").ands_location_widget({target:'coordinates'});
  });
</script>

Step 3. Load the web page and see the new widget appear!

Once submitted, the coordinates of the location selected will be in the form value you chose for target

Demo

Result

HTML

JS

<div id="mapContainer"></div>

$("#mapContainer").ands_location_widget({
	lonLat:"151.503462,-33.251348 150.558638,-33.039778 149.767623,-34.137978 150.844283,-34.754050 151.283736,-33.937689 151.503462,-33.251348"
});

							Developer Zone

Some basic web development knowledge may be needed to implement this widget

Software Download

<?php echo anchor(apps_url('location_capture_widget/download/'), ' Download widget sourcecode', array('class'=>'btn btn-large btn-success')) ?>

<?php echo anchor(apps_url('location_capture_widget/download/minified'), ' Download minified widget', array('class'=>'btn btn-large btn-success')) ?>

License

Apache License, Version 2.0: http://www.apache.org/licenses/LICENSE-2.0

Functions

The ANDS Location Capture widget plugin supports the following functions:

init

Initialise the plugin against a jQuery object; use a jQuery selector to define the object.

example:
$("#mapContainer").ands_location_widget('init');

googlemap

Once initialised, call the plugin on the jQuery object again to access the underlying google map object.

example:
var map = $("#mapContainer").ands_location_widget('googlemap');

Configurations

The ANDS Location Capture widget plugin's init function has the following options:

<?php
	$config = array(
		array('mode', '', 'Under normal operation, the widget opens in map view. Use this setting to open either in the search or coords dialogue. Eg
$("#mapContainer").ands_location_widget('init', {mode:'search'});
'),
		array('zoom','3','The initial zoom level of the map. Eg
$("#mapContainer").ands_location_widget('init', {zoom:7});
'),
		array('start', '133,-27','The initial map view, given as a string of "longitude, latitude". Eg
$("#mapContainer").ands_location_widget('init', {start:"130, -16"});
'),
		array('target','geoLocation', 'The HTML id attribute of the element to store the final coordinate data in. If no such element exists, it wil be created for you, and inserted immediately after the plugin element. Eg
$("#mapContainer").ands_location_widget('init', {target:'coordinate_data'});
'),
		array('lonLat','','Initial coordinate data to display on the map. Coordinates are specified as a comma-delimited string longitude, latitude. Coordinate data can be a single point, or an array of points representing a region. Regions should be closed (that is, the first and last points should be the same). Eg
$("#mapContainer").ands_location_widget('init', {lonLat:'133, -27'});
'),
		array('jumpToPoint','true','When entering "point" mode, jumpToPoint defines whether the map view should jump to the existing point, or stay at the current map view. Eg
$("#mapContainer").ands_location_widget('init', {jumpToPoint:false});
'),
		array('endpoint','services.ands.org.au/api/resolver/','The ANDS resolver service to use. Change this when you want to use your own resolver service. Eg
$("#mapContainer").ands_location_widget('init', {endpoint:'http://localhost.localdomain/myresolver/'});
'),
		array('gasset_protocol','(the current window\'s protocol)','The HTTP protocol to use for google asset (image) requests : choose http:// or https://. Eg
$("#mapContainer").ands_location_widget('init', {gasset_protocol:'https://'});
'),
	);
?>

					<colgroup>
						<col class="col-lg-2"> <col class="col-lg-2"> <col class="col-lg-8">
					</colgroup>

						Property	Defaults	Description

						<?php foreach($config as $c): ?>

							<?php echo $c[0] ?>
							<?php echo $c[1] ?>
							<?php echo $c[2] ?>

						<?php endforeach; ?>

FAQs

										I'm getting an "insecure content" warning? Can the widget run under HTTPS?

									Yes! Ensure that all the <script> and <link> tags (from Step 1 & 2) are pointing to the securely-hosted version of the resource.
		    	 	In other words, the URL starts with https:// (such as https://maps.google.com/api...).

										What service is doing the placename resolution?

									ANDS hosts a resolver proxy service that provides JSONP results based on the response from the Gazetteer service.
		    	 	An example of this script is included in the source code package. You can customise this proxy service yourself
		    	 	and change the location by passing endpoint (and optionally, protocol) options to the widget's init function.

										How can I customise the widget / not use the ANDS-hosted resources?

									Full source code for this widget is available and licensed under Apache License, Version 2.0.

<?php $this->load->view('developer_footer'); ?>


text:
using System;
using System.Windows.Forms;

using ZXing.Common;
using ZXing.Rendering;

namespace WindowsFormsDemo
{
    public partial class EncodingOptionsForm : Form
    {
        public EncodingOptions Options
        {
            get
            {
                return (EncodingOptions)propOptions.SelectedObject;
            }
            set
            {
                propOptions.SelectedObject = value;
            }
        }

        public Type Renderer
        {
            get { return (Type)cmbRenderer.SelectedItem; }
            set { cmbRenderer.SelectedItem = value; }
        }

        public EncodingOptionsForm()
        {
            InitializeComponent();

            cmbRenderer.Items.Add(typeof(BitmapRenderer));
            cmbRenderer.Items.Add(typeof(CustomBitmapRenderer));
            cmbRenderer.Items.Add(typeof(AlternateBitmapRenderer));
            cmbRenderer.SelectedItem = typeof(BitmapRenderer);
        }
    }
}


text:
{-# OPTIONS_HADDOCK hide #-}
{-# LANGUAGE MultiParamTypeClasses, FunctionalDependencies, GeneralizedNewtypeDeriving, FlexibleInstances, UndecidableInstances, DefaultSignatures, GADTs #-}
module QuickSpec.Internal.Pruning where

import QuickSpec.Internal.Type (Arity (..))
import QuickSpec.Internal.Prop
import QuickSpec.Internal.Testing
import Control.Monad.Trans.Class
import Control.Monad.IO.Class
import Control.Monad.Trans.State.Strict
import Control.Monad.Trans.Reader

class Monad m => MonadPruner term norm m | m -> term norm where
  normaliser :: m (term -> norm)
  add :: Prop term -> m Bool

  default normaliser :: (MonadTrans t, MonadPruner term norm m', m ~ t m') => m (term -> norm)
  normaliser = lift normaliser

  default add :: (MonadTrans t, MonadPruner term norm m', m ~ t m') => Prop term -> m Bool
  add = lift . add

instance MonadPruner term norm m => MonadPruner term norm (StateT s m)
instance MonadPruner term norm m => MonadPruner term norm (ReaderT r m)

normalise :: MonadPruner term norm m => term -> m norm
normalise t = do
  norm <- normaliser
  return (norm t)

newtype ReadOnlyPruner m a = ReadOnlyPruner { withReadOnlyPruner :: m a }
  deriving (Functor, Applicative, Monad, MonadIO, MonadTester testcase term)

instance MonadTrans ReadOnlyPruner where
  lift = ReadOnlyPruner

instance MonadPruner term norm m => MonadPruner term norm (ReadOnlyPruner m) where
  normaliser = ReadOnlyPruner normaliser
  add _ = return True

newtype WatchPruner term m a = WatchPruner (StateT [Prop term] m a)
  deriving (Functor, Applicative, Monad, MonadTrans, MonadIO, MonadTester testcase term)

instance MonadPruner term norm m => MonadPruner term norm (WatchPruner term m) where
  normaliser = lift normaliser
  add prop = do
    res <- lift (add prop)
    WatchPruner (modify (prop:))
    return res

watchPruner :: Monad m => WatchPruner term m a -> m (a, [Prop term])
watchPruner (WatchPruner mx) = do
  (x, props) <- runStateT mx []
  return (x, reverse props)


text:
#import <XCTest/XCTest.h>

#import "NSDictionary+HeaderSize.h"

@interface NSDictionaryHeaderSizeTest : XCTestCase

@end

@implementation NSDictionaryHeaderSizeTest

#pragma mark NSDictionaryHeaderSizeTest

- (void)testNoSizeForNonStringKeys
{
    NSDictionary *headers = @{ @(1) : @(2) };
    XCTAssertEqual(headers.byteSizeOfHeaders, 0, @"The header size in bytes should be 0 with no string keys");
}

- (void)testNoSizeForNonStringObjects
{
    NSDictionary *headers = @{ @"Authorisation" : @(1) };
    XCTAssertEqual(headers.byteSizeOfHeaders, 0, @"The header size in bytes should be 0 with no string objects");
}

- (void)testSize
{
    NSDictionary *headers = @{ @"Authorisation" : @"Basic thisismytoken" };
    XCTAssertEqual(headers.byteSizeOfHeaders, 35, @"The header size in bytes should be 35 inclusive of the \": \" barrier and \\n");
}

@end


text:
import os
import sys

from celery.result import AsyncResult

import django
from django.core.management import call_command

from eventkit_cloud.tasks import test_chain
from eventkit_cloud.celery import app

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "eventkit_cloud.settings.prod")
django.setup()

# CELERY_ALWAYS_EAGER = False

def chain_success(chain_async_result):
    """Checks that each task for the chain producing @chain_result completed successfully.
    Returns True if all tasks are successful, False otherwise.
    """
    print("Waiting on chain.ready()")
    # Make sure the chain has completed
    result = chain_async_result.get()
    msgs = []

    def traverse_chain_result(result):
        result_id, remaining_chain = result[0]
        link_result = AsyncResult(result_id)
        msgs.append("{}: {}".format(result_id, link_result.status))

        if type(remaining_chain) == list:
            remaining_links_completed = traverse_chain_result(remaining_chain)
        else:
            remaining_links_completed = []

        statuses = [link_result.status] + remaining_links_completed
        return statuses

    statuses = traverse_chain_result(result)
    if all([s == "SUCCESS" for s in statuses]):
        return True
    else:
        print("\n".join(msgs))
        return False

def test_shutdown_celery_workers_mgmt_cmd():
    """Checks that 'shutdown_celery_workers' allows previous tasks to finish, but prevents additional processing
    then stops the celery workers.
    """
    # Ensure celery container is running
    if app.control.inspect().ping() is None:
        return (100, "No worker nodes found running prior to test")

    worker_nodename = [n for n in list(app.control.inspect().ping().keys()) if "worker" in n][0]
    worker_hostname = worker_nodename.split("@")[1]

    # Fire off a number of tasks & wait for them to be picked up
    tc1 = test_chain.apply_async(kwargs={"subtask_queuename": worker_hostname}, expires=6)
    tc1.get()

    # Instruct system to finish current tasks
    call_command("finish_worker_tasks")

    # fire off more tasks
    tc2 = test_chain.apply_async(kwargs={"subtask_queuename": worker_hostname}, expires=6)

    if tc1.status != "SUCCESS":
        return (100, 'Tasks started before "finish_worker_tasks", status "{}" != "SUCCESS"'.format(tc1.status))
    if not chain_success(tc1):
        return (100, 'Tasks started before "finish_worker_tasks", did not all complete successfully')
    if tc2.status != "PENDING":
        return (100, 'Tasks started after "finish_worker_tasks", status {} != "PENDING"'.format(tc2.status))

    # Invoke shutdown_celery_workers
    call_command("shutdown_celery_workers")

    # Check that the celery workers are all stopped
    if app.control.inspect().ping() is not None:
        return (100, "Worker nodes still running after test")

    # There should be one test_chain task on the celery queue that's left after "finish_worker_tasks" call.
    n_purged_tasks = app.control.purge()
    if n_purged_tasks != 1:
        return (100, "Number of pending tasks purged, {} != 4".format(n_purged_tasks))

    return (0, "Ok")

if __name__ == "__main__":
    n_preexisting_tasks = app.control.purge()
    if n_preexisting_tasks != 0:
        return_code, msg = (100, "Found {} preexisting tasks, please clean up queue before executing this test")
    else:
        return_code, msg = test_shutdown_celery_workers_mgmt_cmd()
    print(msg)
    sys.exit(return_code)


text:
import dude from 'debug-dude'
const { log } = dude('coffea-telegram:events')

import { connection, message, command, error } from 'coffea'

const isPrivate = (evt) =>
  evt.chat && evt.chat.type === 'private'

const getChat = (evt) =>
  isPrivate(evt) ? evt.from && evt.from.id : evt.chat && evt.chat.id

const getUser = (evt) =>
  evt.from && evt.from.id

const makeForward = (dispatch) =>
  (evtName) => (evt) => dispatch({
    type: evtName,
    chat: getChat(evt),
    user: getUser(evt), // user
    text: evt.text,
    data: evt[evtName],
    raw: evt
  })

const validCommand = (me, cmd) => {
  if (cmd.length > 1) { // /command@botusername syntax was used
    // true if: bot already knows its username and it matches
    return me && cmd[1] === me.username
  }

  // global /command syntax was used
  return true
}

export default function events (bot, dispatch) {
  let me
  bot.getMe().then(
    (user) => {
      me = user
      dispatch(connection({ me }))
    }
  )

  const forward = makeForward(dispatch)

  bot.on('text', (evt) => dispatch(message({
    chat: getChat(evt), // chat
    user: getUser(evt), // user
    text: evt.text, // message
    private: isPrivate(evt), // private message or not?
    raw: evt // rest of the options
  })))

  bot.on('text', (evt) => {
    log('message event received: %o', evt)
    if (evt.text.charAt(0) === '/') { // example: /np@nowplayingbot username
      log(' |-> command detected')
      let args = evt.text.substring(1).trim().split(/\s+/) // [ 'np@nowplayingbot', 'username' ]
      let cmd = args.shift().split('@') // [ 'np', 'nowplayingbot' ]
      // args is now [ 'username' ]
      if (validCommand(me, cmd)) {
        log(' `-> valid command "%s" with args: %o', cmd[0], args)
        return dispatch(command({
          chat: getChat(evt), // chat
          user: getUser(evt), // user
          cmd: cmd[0], // cmd
          args, // args
          raw: evt // rest of the options
        }))
      } else log(' !-> wrong recipient "%s", expected "%s"', cmd[1], me.username)
    }
  })

  bot.on('audio', forward('audio'))
  bot.on('document', forward('document'))
  bot.on('photo', forward('photo'))
  bot.on('sticker', forward('sticker'))
  bot.on('video', forward('video'))
  bot.on('video_note', forward('video_note'))
  bot.on('voice', forward('voice'))
  bot.on('contact', forward('contact'))
  bot.on('location', forward('location'))
  bot.on('new_chat_members', forward('new_chat_members'))
  bot.on('left_chat_member', forward('left_chat_member'))
  bot.on('new_chat_title', forward('new_chat_title'))
  bot.on('new_chat_photo', forward('new_chat_photo'))
  bot.on('delete_chat_photo', forward('delete_chat_photo'))
  bot.on('group_chat_created', forward('group_chat_created'))
  bot.on('callback_query', forward('callback_query'))
  bot.on('inline_query', forward('inline_query'))
  bot.on('chosen_inline_result', forward('chosen_inline_result'))
  bot.on('edited_message', forward('edited_message'))
  bot.on('edited_message_text', forward('edited_message_text'))
  bot.on('edited_message_caption', forward('edited_message_caption'))
  bot.on('channel_post', forward('channel_post'))
  bot.on('edited_channel_post_text', forward('edited_channel_post_text'))
  bot.on('edited_channel_post_caption', forward('edited_channel_post_caption'))
  bot.on('shipping_query', forward('shipping_query'))
  bot.on('pre_checkout_query', forward('pre_checkout_query'))

  bot.on('error', (err) => dispatch(error({ err })))
}


text:
package org.apache.cassandra.gms;

import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.net.InetAddress;
import java.util.UUID;

import org.apache.cassandra.dht.IPartitioner;
import org.apache.cassandra.dht.Token;
import org.apache.cassandra.io.ICompactSerializer;
import org.apache.cassandra.utils.FBUtilities;

/**
 * This abstraction represents the state associated with a particular node which an
 * application wants to make available to the rest of the nodes in the cluster.
 * Whenever a piece of state needs to be disseminated to the rest of cluster wrap
 * the state in an instance of <i>ApplicationState</i> and add it to the Gossiper.
 *
 * e.g. if we want to disseminate load information for node A do the following:
 *
 *      ApplicationState loadState = new ApplicationState(<string representation of load>);
 *      Gossiper.instance.addApplicationState("LOAD STATE", loadState);
 */

public class VersionedValue implements Comparable<VersionedValue>
{
    public static final ICompactSerializer<VersionedValue> serializer = new VersionedValueSerializer();

    // this must be a char that cannot be present in any token
    public final static char DELIMITER = ',';
    public final static String DELIMITER_STR = new String(new char[] { DELIMITER });

    // values for ApplicationState.STATUS
    public final static String STATUS_BOOTSTRAPPING = "BOOT";
    public final static String STATUS_NORMAL = "NORMAL";
    public final static String STATUS_LEAVING = "LEAVING";
    public final static String STATUS_LEFT = "LEFT";
    public final static String STATUS_MOVING = "MOVING";

    public final static String REMOVING_TOKEN = "removing";
    public final static String REMOVED_TOKEN = "removed";

    public final static String HIBERNATE = "hibernate";

    // values for ApplicationState.REMOVAL_COORDINATOR
    public final static String REMOVAL_COORDINATOR = "REMOVER";

    public final int version;
    public final String value;

    private VersionedValue(String value, int version)
    {
        this.value = value;
        this.version = version;
    }

    private VersionedValue(String value)
    {
        this.value = value;
        version = VersionGenerator.getNextVersion();
    }

    public int compareTo(VersionedValue value)
    {
        return this.version - value.version;
    }

    @Override
    public String toString()
    {
        return "Value(" + value + "," + version + ")";
    }

    public static class VersionedValueFactory
    {
        IPartitioner partitioner;

        public VersionedValueFactory(IPartitioner partitioner)
        {
            this.partitioner = partitioner;
        }

        public VersionedValue bootstrapping(Token token)
        {
            return new VersionedValue(VersionedValue.STATUS_BOOTSTRAPPING + VersionedValue.DELIMITER + partitioner.getTokenFactory().toString(token));
        }

        public VersionedValue normal(Token token)
        {
            return new VersionedValue(VersionedValue.STATUS_NORMAL + VersionedValue.DELIMITER + partitioner.getTokenFactory().toString(token));
        }

        public VersionedValue load(double load)
        {
            return new VersionedValue(String.valueOf(load));
        }

        public VersionedValue migration(UUID newVersion)
        {
            return new VersionedValue(newVersion.toString());
        }

        public VersionedValue leaving(Token token)
        {
            return new VersionedValue(VersionedValue.STATUS_LEAVING + VersionedValue.DELIMITER + partitioner.getTokenFactory().toString(token));
        }

        public VersionedValue left(Token token)
        {
            return new VersionedValue(VersionedValue.STATUS_LEFT + VersionedValue.DELIMITER + partitioner.getTokenFactory().toString(token));
        }

        public VersionedValue moving(Token token)
        {
            return new VersionedValue(VersionedValue.STATUS_MOVING + VersionedValue.DELIMITER + partitioner.getTokenFactory().toString(token));
        }

        public VersionedValue removingNonlocal(Token token)
        {
            return new VersionedValue(VersionedValue.REMOVING_TOKEN + VersionedValue.DELIMITER + partitioner.getTokenFactory().toString(token));
        }

        public VersionedValue removedNonlocal(Token token)
        {
            return new VersionedValue(VersionedValue.REMOVED_TOKEN + VersionedValue.DELIMITER + partitioner.getTokenFactory().toString(token));
        }

        public VersionedValue removalCoordinator(Token token)
        {
            return new VersionedValue(VersionedValue.REMOVAL_COORDINATOR + VersionedValue.DELIMITER + partitioner.getTokenFactory().toString(token));
        }

        public VersionedValue hibernate(boolean value)
        {
            return new VersionedValue(VersionedValue.HIBERNATE + VersionedValue.DELIMITER + value);
        }

        public VersionedValue datacenter(String dcId)
        {
            return new VersionedValue(dcId);
        }

        public VersionedValue rack(String rackId)
        {
            return new VersionedValue(rackId);
        }

        public VersionedValue rpcaddress(InetAddress endpoint)
        {
            return new VersionedValue(endpoint.getHostAddress());
        }

        public VersionedValue releaseVersion()
        {
            return new VersionedValue(FBUtilities.getReleaseVersionString());
        }

        public VersionedValue internalIP(String private_ip)
        {
            return new VersionedValue(private_ip);
        }
    }

    private static class VersionedValueSerializer implements ICompactSerializer<VersionedValue>
    {
        public void serialize(VersionedValue value, DataOutputStream dos, int version) throws IOException
        {
            dos.writeUTF(value.value);
            dos.writeInt(value.version);
        }

        public VersionedValue deserialize(DataInputStream dis, int version) throws IOException
        {
            String value = dis.readUTF();
            int valVersion = dis.readInt();
            return new VersionedValue(value, valVersion);
        }
    }
}