예제 #1
0
        public static void SetValor(Documento parte, string campo, int repeticion, string valor)
        {
            var param = (from DocumentoValor v in parte.Parametros
                         where v.Parametro.Nombre == campo &&
                         v.Repeticion == repeticion
                         select v).ToList();

            var val = param.Count > 0 ? param[0] : null;

            if (val == null)
            {
                var par = from TipoDocumentoParametro p in parte.TipoDocumento.Parametros
                          where p.Nombre == campo
                          select p;

                val = new DocumentoValor
                {
                    Documento  = parte,
                    Parametro  = par.ToList()[0],
                    Repeticion = ((short)repeticion)
                };

                parte.Parametros.Add(val);
            }

            val.Valor = valor;
        }
예제 #2
0
        protected override void SetInt32Value(Control ctl, DocumentoValor valor, int repeticion)
        {
            if (valor.Parametro.Nombre == ParteCampos.EstadoControl)
            {
                estado = Convert.ToInt32(valor.Valor);
                var label = ctl as Label;
                if (label != null)
                {
                    switch (valor.Valor)
                    {
                    case "1": label.Text = "Controlado"; break;

                    case "2": label.Text = "Verificado"; break;

                    default: label.Text = "Sin Controlar"; break;
                    }
                }
            }
            else if (valor.Parametro.Nombre == ParteCampos.TipoServicio)
            {
                var cb = (ctl as DropDownList);
                int i;
                if (cb != null && int.TryParse(valor.Valor, out i))
                {
                    cb.SelectedValue = valor.Valor;
                }
            }
            else
            {
                base.SetInt32Value(ctl, valor, repeticion);
            }
        }
예제 #3
0
        protected virtual void SetParameterValue(DocumentoValor val)
        {
            var id = (val.Parametro.Repeticion != 1)
                         ? TipoDocumentoHelper.GetControlName(val.Parametro, val.Repeticion)
                         : TipoDocumentoHelper.GetControlName(val.Parametro);

            SetParameterValue(val.Parametro.TipoDato, id, val.Valor);
        }
예제 #4
0
        protected virtual void SetBooleanValue(Control ctl, DocumentoValor valor, int repeticion)
        {
            var checkbox = (ctl as CheckBox);

            if (checkbox == null)
            {
                return;
            }
            checkbox.Checked = valor.Valor == "true";
        }
예제 #5
0
        protected virtual void SetStringValue(Control ctl, DocumentoValor valor, int repeticion)
        {
            var textbox = (ctl as TextBox);

            if (textbox == null)
            {
                return;
            }
            textbox.Text = valor.Valor;
        }
예제 #6
0
        protected virtual void SetDateTimeValue(Control ctl, DocumentoValor valor, int repeticion)
        {
            var d       = Convert.ToDateTime(valor.Valor, CultureInfo.InvariantCulture);
            var textbox = (ctl as TextBox);

            if (textbox == null)
            {
                return;
            }
            textbox.Text = d.ToDisplayDateTime().ToString("dd/MM/yyyy HH:mm");
        }
예제 #7
0
 protected override void SetDateTimeValue(Control ctl, DocumentoValor valor, int repeticion)
 {
     if (valor.Parametro.Nombre == "Hs Salida Al Pozo" ||
         valor.Parametro.Nombre == "Hs Llegada Al Pozo" ||
         valor.Parametro.Nombre == "Hs Salida Del Pozo" ||
         valor.Parametro.Nombre == "Hs Llegada Del Pozo")
     {
         var d       = Convert.ToDateTime(valor.Valor, CultureInfo.InvariantCulture);
         var textbox = (ctl as TextBox);
         if (textbox != null)
         {
             textbox.Text = d.ToDisplayDateTime().ToString("HH:mm");
         }
     }
     else
     {
         base.SetDateTimeValue(ctl, valor, repeticion);
     }
 }
예제 #8
0
 protected override void SetParameterValue(DocumentoValor val)
 {
     if (val.Parametro.Nombre == CamposCombustible.Actividad)
     {
         var id = (val.Parametro.Repeticion != 1)
                  ? TipoDocumentoHelper.GetControlName(val.Parametro, val.Repeticion)
                  : TipoDocumentoHelper.GetControlName(val.Parametro);
         var control = GetControlFromView(id);
         if (control == null)
         {
             return;
         }
         SetDropDownValue(control, val.Valor);
     }
     else
     {
         base.SetParameterValue(val);
     }
 }
예제 #9
0
        public override object Parse(int empresa, int linea, IData data)
        {
            var documento = GetDocumento(empresa, linea, data);

            if (data.Operation == (int)Operation.Delete)
            {
                return(documento);
            }

            if (documento.Id == 0)
            {
                documento.Empresa = DaoFactory.EmpresaDAO.FindById(empresa);
                documento.Linea   = linea > 0 ? DaoFactory.LineaDAO.FindById(linea) : null;
                documento.Estado  = Documento.Estados.Abierto;
            }

            documento.Descripcion = data.AsString(Properties.Documento.Descripcion, 64);

            var gmt = data.AsInt32(Properties.Documento.Gmt) ?? 0;

            var fecha = data.AsDateTime(Properties.Documento.Fecha, gmt);

            if (!fecha.HasValue)
            {
                ThrowProperty("Fecha");
            }
            documento.Fecha = fecha.Value;

            var presentacion = data.AsDateTime(Properties.Documento.FechaPresentacion, gmt);

            if (documento.TipoDocumento.RequerirPresentacion && !presentacion.HasValue && !documento.Presentacion.HasValue)
            {
                ThrowProperty("FechaPresentacion");
            }
            if (presentacion.HasValue)
            {
                documento.Presentacion = presentacion.Value;
            }

            var vencimiento = data.AsDateTime(Properties.Documento.FechaVencimiento, gmt);

            if (documento.TipoDocumento.RequerirVencimiento && !vencimiento.HasValue && !documento.Vencimiento.HasValue)
            {
                ThrowProperty("FechaVencimiento");
            }
            if (vencimiento.HasValue)
            {
                documento.Vencimiento = vencimiento.Value;
            }

            var cierre = data.AsDateTime(Properties.Documento.FechaCierre, gmt);

            if (cierre.HasValue)
            {
                documento.FechaCierre = cierre.Value;
                documento.Estado      = Documento.Estados.Cerrado;
            }
            if (documento.TipoDocumento.AplicarATransportista)
            {
                var codigoTransportista = data.AsString(Properties.Documento.Transportista, 32);
                if (codigoTransportista != null)
                {
                    var transportista = DaoFactory.TransportistaDAO.FindByCodigo(empresa, linea, codigoTransportista);
                    documento.Transportista = transportista;
                }
                if (documento.Transportista == null)
                {
                    ThrowProperty("Transportista");
                }
            }
            if (documento.TipoDocumento.AplicarAVehiculo)
            {
                var interno = data.AsString(Properties.Documento.Vehiculo, 32);
                if (interno != null)
                {
                    var vehiculo = DaoFactory.CocheDAO.FindByInterno(new[] { empresa }, new[] { linea }, interno);
                    if (vehiculo != null && documento.TipoDocumento.AplicarATransportista)
                    {
                        if (vehiculo.Transportista != documento.Transportista)
                        {
                            ThrowMessage("El vehículo {0} no pertenece al transportista {1}", vehiculo.Interno, documento.Transportista.Descripcion);
                        }
                    }


                    documento.Vehiculo = vehiculo;
                }
                if (documento.Vehiculo == null)
                {
                    ThrowProperty("Vehiculo");
                }
            }
            if (documento.TipoDocumento.AplicarAEmpleado)
            {
                var legajo = data.AsString(Properties.Documento.Empleado, 32);
                if (legajo != null)
                {
                    var empleado = DaoFactory.EmpleadoDAO.FindByLegajo(empresa, linea, legajo);
                    documento.Empleado = empleado;
                }
                if (documento.Empleado == null)
                {
                    ThrowProperty("Empleado");
                }
            }
            if (documento.TipoDocumento.AplicarAEquipo)
            {
                var codigoEquipo = data.AsString(Properties.Documento.Equipo, 32);
                if (codigoEquipo != null)
                {
                    var equipo = DaoFactory.EquipoDAO.FindByCodigo(empresa, linea, codigoEquipo);
                    documento.Equipo = equipo;
                }
                if (documento.Equipo == null)
                {
                    ThrowProperty("Equipo");
                }
            }

            var custom = data.GetCustomFields();

            if (custom.Any())
            {
                var parametrosTipo = documento.TipoDocumento.Parametros.Cast <TipoDocumentoParametro>().ToList();
                var parametrosDoc  = documento.Parametros.Cast <DocumentoValor>().ToList();
                foreach (var par in custom)
                {
                    var   repIdx  = par.Key.IndexOf("]");
                    var   parName = repIdx < 0 ? par.Key : par.Key.Substring(repIdx + 1).Trim();
                    short repNo;
                    if (repIdx < 0 || !short.TryParse(par.Key.Substring(1, repIdx - 1), out repNo))
                    {
                        repNo = 0;
                    }
                    var tipoPar = parametrosTipo.FirstOrDefault(x => x.Nombre == parName);
                    if (tipoPar == null)
                    {
                        continue;
                    }
                    var valor = parametrosDoc.FirstOrDefault(x => x.Parametro.Id == tipoPar.Id && (tipoPar.Repeticion <= 1 || repNo == x.Repeticion));
                    if (valor == null)
                    {
                        valor = new DocumentoValor {
                            Documento = documento, Parametro = tipoPar, Repeticion = repNo
                        };
                        parametrosDoc.Add(valor);
                    }


                    var valorFinal = GetValue(empresa, linea, valor, par.Value);
                    if (valorFinal != null)
                    {
                        valor.Valor = valorFinal;
                    }
                    if (string.IsNullOrEmpty(valor.Valor) && !string.IsNullOrEmpty(valor.Parametro.Default))
                    {
                        valor.Valor = valor.Parametro.Default;
                    }
                    if (valor.Parametro.Obligatorio && string.IsNullOrEmpty(valor.Valor))
                    {
                        ThrowProperty(valor.Parametro.Nombre);
                    }
                }
                documento.Parametros.Clear();
                foreach (var p in parametrosDoc)
                {
                    documento.Parametros.Add(p);
                }
            }

            return(documento);
        }
예제 #10
0
 protected virtual void SetEquipoValue(Control ctl, DocumentoValor valor, int repeticion)
 {
     equipo = Convert.ToInt32(valor.Valor);
 }
예제 #11
0
 protected virtual void SetCentroCostosValue(Control ctl, DocumentoValor valor, int repeticion)
 {
     centrocostos = Convert.ToInt32(valor.Valor);
 }
예제 #12
0
 protected virtual void SetChoferValue(Control ctl, DocumentoValor valor, int repeticion)
 {
 }
예제 #13
0
 protected virtual void SetAseguradoraValue(Control ctl, DocumentoValor valor, int repeticion)
 {
     aseguradora = Convert.ToInt32(valor.Valor);
 }
예제 #14
0
        protected virtual DocumentoValor GetDocValue(TipoDocumentoParametro par, short repeticion)
        {
            var val = new DocumentoValor();

            val.Parametro  = par;
            val.Repeticion = repeticion;

            var id = par.Nombre.Replace(' ', '_');

            if (par.Repeticion != 1)
            {
                id += repeticion;
            }

            var ctl = view.DocumentContainer.FindControl(id);

            if (ctl == null)
            {
                return(null);
            }

            switch (par.TipoDato.ToLower())
            {
            case TipoParametroDocumento.Integer:
                var ival = (ctl as TextBox).Text;
                if (!par.Obligatorio && string.IsNullOrEmpty(ival))
                {
                    return(null);
                }

                int i;
                if (!int.TryParse(ival, out i))
                {
                    throw new ApplicationException("El campo " + par.Nombre + " debe ser un numerico entero");
                }
                val.Valor = i.ToString();
                break;

            case TipoParametroDocumento.Float:
                var fval = (ctl as TextBox).Text;
                if (!par.Obligatorio && string.IsNullOrEmpty(fval))
                {
                    break;
                }
                fval = fval.Replace(',', '.');
                double f;
                if (!double.TryParse(fval, NumberStyles.Any, CultureInfo.InvariantCulture, out f))
                {
                    throw new ApplicationException("El campo " + par.Nombre + " debe ser un numerico decimal");
                }
                val.Valor = f.ToString(CultureInfo.InvariantCulture);
                break;

            case TipoParametroDocumento.String:
                var sval = (ctl as TextBox).Text;

                if (string.IsNullOrEmpty(sval))
                {
                    if (par.Obligatorio)
                    {
                        throw new ApplicationException("El campo " + par.Nombre + " no puede estar vacio");
                    }
                    else
                    {
                        break;
                    }
                }
                val.Valor = sval;
                break;

            case TipoParametroDocumento.Barcode:
                var svalcode = (ctl as TextBox).Text;

                if (string.IsNullOrEmpty(svalcode))
                {
                    if (par.Obligatorio)
                    {
                        throw new ApplicationException("El campo " + par.Nombre + " no puede estar vacio");
                    }
                    else
                    {
                        break;
                    }
                }
                val.Valor = svalcode;
                break;

            case TipoParametroDocumento.DateTime:
                var dval = (ctl as TextBox).Text;
                if (!par.Obligatorio && string.IsNullOrEmpty(dval))
                {
                    break;
                }
                DateTime d;
                if (!DateTime.TryParse(dval, new CultureInfo("es-AR"), DateTimeStyles.None, out d))
                {
                    throw new ApplicationException("El campo " + par.Nombre + " debe ser una fecha valida");
                }
                val.Valor = d.ToDataBaseDateTime().ToString(CultureInfo.InvariantCulture);
                break;

            case TipoParametroDocumento.Boolean:
                val.Valor = (ctl as CheckBox).Checked ? "true" : "false";
                break;

            case TipoParametroDocumento.Coche:
                var md = (ctl as MovilDropDownList);
                if (md.SelectedIndex < 0)
                {
                    if (par.Obligatorio)
                    {
                        throw new ApplicationException("Debe seleccionar un valor para el campo " + par.Nombre);
                    }
                    else
                    {
                        break;
                    }
                }
                val.Valor = md.SelectedValue;
                break;

            case TipoParametroDocumento.Chofer:
                /*MovilDropDownList md = (ctl as MovilDropDownList);
                 * if (md.SelectedIndex < 0)
                 *  if (par.Obligatorio)
                 *      throw new ApplicationException("Debe seleccionar un valor para el campo " + par.Nombre);
                 *  else
                 *      break;
                 * val.Valor = md.SelectedValue;*/
                break;

            case TipoParametroDocumento.Aseguradora:
                var ase = (ctl as TransportistaDropDownList);
                if (ase.SelectedIndex < 0)
                {
                    if (par.Obligatorio)
                    {
                        throw new ApplicationException("Debe seleccionar un valor para el campo " + par.Nombre);
                    }
                    else
                    {
                        break;
                    }
                }
                val.Valor = ase.SelectedValue;
                break;

            case TipoParametroDocumento.Equipo:
                var eq = (ctl as EquipoDropDownList);
                if (eq.SelectedIndex < 0)
                {
                    if (par.Obligatorio)
                    {
                        throw new ApplicationException("Debe seleccionar un valor para el campo " + par.Nombre);
                    }
                    else
                    {
                        break;
                    }
                }
                val.Valor = eq.SelectedValue;
                break;

            case TipoParametroDocumento.CentroCostos:
                var cc = (ctl as CentroDeCostosDropDownList);
                if (cc.SelectedIndex < 0)
                {
                    if (par.Obligatorio)
                    {
                        throw new ApplicationException("Debe seleccionar un valor para el campo " + par.Nombre);
                    }
                    else
                    {
                        break;
                    }
                }
                val.Valor = cc.SelectedValue;
                break;
            }

            return(val);
        }
예제 #15
0
 protected virtual void SetCocheValue(Control ctl, DocumentoValor valor, int repeticion)
 {
     coche = Convert.ToInt32(valor.Valor);
 }
예제 #16
0
 public OrderDocumentoValor(string o, DocumentoValor v)
 {
     Orden = o;
     Valor = v;
 }
예제 #17
0
        public string GetValue(int empresa, int linea, DocumentoValor detalle, string valor)
        {
            var tipoDato = detalle.Parametro.TipoDato.ToLower();

            switch (tipoDato)
            {
            case TipoParametroDocumento.Integer:
                int intValue;
                return(int.TryParse(valor, out intValue) ? intValue.ToString(CultureInfo.InvariantCulture) : null);

            case TipoParametroDocumento.Float:
                float floatValue;
                return(float.TryParse(valor.Replace(',', '.'), NumberStyles.Any, CultureInfo.InvariantCulture, out floatValue) ? floatValue.ToString(CultureInfo.InvariantCulture) : null);

            case TipoParametroDocumento.String:
                return(valor);

            case TipoParametroDocumento.Barcode:
                return(valor);

            case TipoParametroDocumento.DateTime:
                DateTime dateTimeValue;
                return(DateTime.TryParse(valor, new CultureInfo("es-AR"), DateTimeStyles.None, out dateTimeValue) ? dateTimeValue.ToString(CultureInfo.InvariantCulture) : null);

            case TipoParametroDocumento.Boolean:
                bool boolValue;
                return(bool.TryParse(valor, out boolValue) ? (boolValue ? "true" : "false") : null);

            case TipoParametroDocumento.Coche:
                var vehiculo = DaoFactory.CocheDAO.FindByInterno(new[] { empresa }, new[] { linea }, valor);
                return(vehiculo == null ? null : vehiculo.Id.ToString(CultureInfo.InvariantCulture));

            case TipoParametroDocumento.Chofer:
                var empleado = DaoFactory.EmpleadoDAO.FindByLegajo(empresa, linea, valor);
                return(empleado == null ? null : empleado.Id.ToString(CultureInfo.InvariantCulture));

            case TipoParametroDocumento.Aseguradora:
                var transportista = DaoFactory.TransportistaDAO.FindByCodigo(empresa, linea, valor);
                return(transportista == null ? null : transportista.Id.ToString(CultureInfo.InvariantCulture));

            case TipoParametroDocumento.Equipo:
                var equipo = DaoFactory.EquipoDAO.FindByCodigo(empresa, linea, valor);
                return(equipo == null ? null : equipo.Id.ToString(CultureInfo.InvariantCulture));

            case TipoParametroDocumento.Cliente:
                var cliente = DaoFactory.ClienteDAO.FindByCode(new[] { empresa }, new[] { linea }, valor);
                return(cliente == null ? null : cliente.Id.ToString(CultureInfo.InvariantCulture));

            case TipoParametroDocumento.Tanque:
                var tanque = DaoFactory.TanqueDAO.FindByCode(valor);
                return(tanque == null ? null : tanque.Id.ToString(CultureInfo.InvariantCulture));

            case TipoParametroDocumento.CentroCostos:
                var centroCosto = DaoFactory.CentroDeCostosDAO.FindByCodigo(empresa, linea, valor);
                return(centroCosto == null ? null : centroCosto.Id.ToString(CultureInfo.InvariantCulture));

            case TipoParametroDocumento.Image:
                return(null);
            }

            return(null);
        }
예제 #18
0
        private void SetDocValue(DocumentoValor val, short repeticion)
        {
            var par = val.Parametro;

            var id = par.Nombre.Replace(' ', '_');

            if (par.Repeticion != 1)
            {
                id += repeticion;
            }

            var ctl = view.DocumentContainer.FindControl(id);

            if (ctl == null)
            {
                return;
            }
            switch (par.TipoDato.ToLower())
            {
            case TipoParametroDocumento.Integer:
                SetInt32Value(ctl, val, repeticion);
                break;

            case TipoParametroDocumento.Float:
                SetFloatValue(ctl, val, repeticion);
                break;

            case TipoParametroDocumento.String:
                SetStringValue(ctl, val, repeticion);
                break;

            case TipoParametroDocumento.Barcode:
                SetStringValue(ctl, val, repeticion);
                break;

            case TipoParametroDocumento.DateTime:
                SetDateTimeValue(ctl, val, repeticion);
                break;

            case TipoParametroDocumento.Boolean:
                SetBooleanValue(ctl, val, repeticion);
                break;

            case TipoParametroDocumento.Coche:
                SetCocheValue(ctl, val, repeticion);
                break;

            case TipoParametroDocumento.Chofer:
                SetChoferValue(ctl, val, repeticion);
                break;

            case TipoParametroDocumento.Aseguradora:
                SetAseguradoraValue(ctl, val, repeticion);
                break;

            case TipoParametroDocumento.Equipo:
                SetEquipoValue(ctl, val, repeticion);
                break;

            case TipoParametroDocumento.CentroCostos:
                SetCentroCostosValue(ctl, val, repeticion);
                break;
            }
        }