private void CompletarValores(string k)
 {
   co_tg_mandantes obj = new bf_tg_mandantes().GetData(Convert.ToInt32(k));
   txt_ma_mandante.Text = obj.ma_mandante;
   txt_ma_descripcion.Text = obj.ma_descripcion;
   txt_ma_rut.Text = obj.ma_rut.FormatRut();
   cmb_id_persona.SeleccionarOpcion(obj.id_persona.id.ToString());
 }
    public void OnReadData_st_grilla(object sender, StoreReadDataEventArgs e)
    {
      try
      {


        int start = e.Start;
        int limit = NumInt.Init(e.Parameters.GetParameter("limit").Value);
        limit = limit == 0 ? e.Limit : limit;
        int page = (start / limit) + 1;

        co_tg_mandantes_no Nomina = new co_tg_mandantes_no();

        Nomina.Pagina = page;
        Nomina.RegistrosPorPaginas = e.Limit;
        Nomina.ColumnaOrden = e.Sort[0].Property;
        Nomina.OrdenColumna =
          (FwpServerControls.FwpDataGridDataBound.Orden)
          Enum.Parse(typeof(FwpServerControls.FwpDataGridDataBound.Orden), e.Sort[0].Direction.ToString(), true);


        IList<object> lista = new List<object>();

        AgregarFiltros_st_grilla(ref Nomina);

        Nomina<co_tg_mandantes_no> data = new bf_tg_mandantes().GetNomina(Nomina);

        foreach (co_tg_mandantes_no n in data.DataSource)
        {
          lista.Add(
              new
              {
                id_mandante = n.id_mandante,
                ma_mandante = n.ma_mandante,
                ma_descripcion = n.ma_descripcion,
                ma_rut= Validacion.FormatRut(n.ma_rut),
                id_persona = n.id_persona,
                pe_nombrecompleto = n.pe_nombrecompleto
              });
        }

        st_grilla.DataSource = lista;
        (st_grilla.Proxy[0] as PageProxy).Total = data.Registros;
        st_grilla.DataBind();
      }
      catch (Exception ex)
      {
        Mensajes.Error(ex.Message);

      }
    }
 private int BuscarMandante(string man, ref string mensaje)
 {
   if (!string.IsNullOrEmpty(man))
   {
     co_tg_mandantes mandante = new bf_tg_mandantes().GetData(new co_tg_mandantes { ma_mandante = man }).FirstOrDefault();
     if (mandante != null)
     {
       if (mandante.id != 0)
       {
         return mandante.id;
       }
       else { mensaje += "Mandante \"" + man + "\" no Existe."; }
     }
     else { mensaje += "Mandante \"" + man + "\" no Existe."; }
   }
   else { mensaje += "Mandante \"" + man + "\" no Existe."; }
   return 0;
 }
    public void click_btn_guardar(object sender, DirectEventArgs e)
    {
      try
      {

        string Tmensaje = ErrorText.REGISTRO_INGRESADO;

        co_tg_mandantes obj = new co_tg_mandantes();
        if (hid_id.Text != "0")
        {
          obj = new bf_tg_mandantes().GetData(Convert.ToInt32(hid_id.Text));
          Tmensaje = ErrorText.REGISTRO_MODIFICADO;
        }
        obj.ma_mandante = txt_ma_mandante.Text;
        obj.ma_descripcion = txt_ma_descripcion.Text;
        obj.ma_rut = txt_ma_rut.Text.Trim().ClearRut();
        int res_cmb_id_persona;
        if (Int32.TryParse(cmb_id_persona.SelectedItem.Value, out res_cmb_id_persona) && cmb_id_persona.SelectedItem.Value != cmb_id_persona.SelectedItem.Text)
        {
          obj.id_persona.id = Convert.ToInt32(res_cmb_id_persona);
        }

        if (hid_id.Text == "0")
        {
          panelCenter.Reset();
        }

        obj = new bf_tg_mandantes().Save(obj);
        new ConexionPlgOnline(Constantes.CONEXION_ONLINE).GrabaMandantePlgOnline(obj);
        new ConexionPlgOnline(Constantes.CONEXION_PROPIEDADES).GrabaMandantePlgOnline(obj);
        Mensajes.Show("Mensaje", Tmensaje, MessageBox.Icon.INFO);
      }
      catch (Exception ex)
      {
        Mensajes.Error(ex.Message);
      }
    }
    protected void TxtMaRut_Blur(object sender, DirectEventArgs e)
    {
      try
      {
        if (txt_ma_rut.Text.Length > 0)
        {
          if (txt_ma_rut.Text.Trim().ClearRut().ValidateRut())
          {
            txt_ma_rut.Text = txt_ma_rut.Text.Trim().ClearRut().FormatRut();
            co_tg_mandantes mandante = new bf_tg_mandantes().GetData(new co_tg_mandantes { ma_rut = txt_ma_rut.Text.Trim().ClearRut() }).FirstOrDefault();
            if (mandante != null)
            {
              if (mandante.id != 0 && hid_id.Text.ValidaEntero("id_mandante") != 0)
              {
                if (hid_id.Text.ValidaEntero("id_mandante") == mandante.id_mandante)
                {

                }
                else
                {
                  Mensajes.Error("El Rut Ingresado ya se encuentra asociado a otro Mandante.");
                  txt_ma_rut.Text = "";
                  txt_ma_rut.Focus();
                }
              }
              else
              {
                Mensajes.Error("El Rut Ingresado ya se encuentra asociado a otro Mandante.");
                txt_ma_rut.Text = "";
                txt_ma_rut.Focus();
              }

            }
          }
          else
          {
            Mensajes.Error("El Rut Ingresado es Invalido.");
            txt_ma_rut.Text = "";
            txt_ma_rut.Focus();
          }
        }
      }
      catch (Exception ex)
      {
        Mensajes.Error(ex.Message);
      }
    }