/// <summary>
        /// Retorna un objeto >> orden , con informacion segun el id de la orden
        /// </summary>
        /// <param name="id_orden"></param>
        /// <returns></returns>
        public entidades.vialsur.prefectura.orden ConsultarOrdenPorId(string id_orden)
        {
            try
            {
                string consulta = "SELECT id, tipo_oden, fecha,  hora, fecha_cierre, estado, ve_vehiculo_responsable_id, per_persona_cedula, observacion, km_ingreso, km_egreso, per_persona_cedula_crea " +
                                  "FROM orden where id = @id_orden";

                SqlParameter parametro = new SqlParameter("@id_orden", SqlDbType.NChar, 10);
                parametro.Value = id_orden;

                entidades.vialsur.prefectura.orden obj_orden = new entidades.vialsur.prefectura.orden();

                SqlDataReader dr_datos = SqlHelper.ExecuteReader(_con, CommandType.Text, consulta, parametro);
                while (dr_datos.Read())
                {
                    obj_orden.id        = dr_datos["id"].ToString();
                    obj_orden.tipo_oden = int.Parse(dr_datos["tipo_oden"].ToString());
                    obj_orden.fecha     = Convert.ToDateTime(dr_datos["fecha"]);

                    if (dr_datos["fecha_cierre"] != DBNull.Value)
                    {
                        obj_orden.fecha_cierre = Convert.ToDateTime(dr_datos["fecha_cierre"]);
                    }

                    obj_orden.hora   = (TimeSpan)dr_datos["hora"];
                    obj_orden.estado = int.Parse(dr_datos["estado"].ToString());
                    obj_orden.ve_vehiculo_responsable_id = int.Parse(dr_datos["ve_vehiculo_responsable_id"].ToString());
                    obj_orden.per_persona_cedula_crea    = dr_datos["per_persona_cedula_crea"] == null ? "" : dr_datos["per_persona_cedula_crea"].ToString();
                    obj_orden.per_persona_numero_cedula  = dr_datos["per_persona_cedula"] == null ? "" : dr_datos["per_persona_cedula"].ToString();
                    obj_orden.observacion = dr_datos["observacion"].ToString();
                    int ki = 0, ke = 0;
                    int.TryParse(dr_datos["km_ingreso"].ToString(), out ki);
                    obj_orden.km_ingreso = ki;
                    int.TryParse(dr_datos["km_egreso"].ToString(), out ke);
                    obj_orden.km_egreso = ke;
                }
                return(obj_orden);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Ejemplo n.º 2
0
        private void frmOrdenesCambiarEstado_Load(object sender, EventArgs e)
        {
            try
            {
                ord = new logica.vialsur.prefectura.Catalogos.cls_logica_orden().ConsultarOrdenPorId(OrdenID);
                lbl_EstadoActual.Text = ((entidades.vialsur.prefectura.Orden_TipoEstado)ord.estado).ToString();
                uc_TipoEstadosOrdenes1.CargarDatos();

                if (((entidades.vialsur.prefectura.Orden_TipoEstado)ord.estado) == entidades.vialsur.prefectura.Orden_TipoEstado.FINALIZADO)
                {
                    toolStripButton2.Enabled       = false;
                    uc_TipoEstadosOrdenes1.Enabled = false;
                    return;
                }

                if (entidades.vialsur.prefectura.TipoUsuario.ADMINISTRADOR == (entidades.vialsur.prefectura.TipoUsuario)((int)Empleado.tipo_usuario) |
                    entidades.vialsur.prefectura.TipoUsuario.MECANICO == (entidades.vialsur.prefectura.TipoUsuario)((int)Empleado.tipo_usuario))
                {
                    toolStripButton2.Visible       = true;
                    uc_TipoEstadosOrdenes1.Enabled = true;
                }
                else
                {
                    toolStripButton2.Visible       = false;
                    uc_TipoEstadosOrdenes1.Enabled = false;
                }


                //uc_TipoEstadosOrdenes1.CargarDatos();
                //lbl_EstadoActual.Text = ((entidades.vialsur.prefectura.Orden_TipoEstado)((int)new logica.vialsur.prefectura.Catalogos.cls_logica_orden().ConsultarOrdenPorId(OrdenID).estado)).ToString();
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error: " + ex.Message);
            }
        }
        /// <summary>
        /// Inserta el registro en la tabla orden, retorna el ID de la orden
        /// </summary>
        /// <param name="_orden">Obj. Orden</param>
        /// <returns></returns>
        public string Insertar_orden(entidades.vialsur.prefectura.orden _orden, string cedula_creador = "")
        {
            try
            {
                List <SqlParameter> parameters = new List <SqlParameter>();

                #region parametros
                SqlParameter _id = new SqlParameter("@id", SqlDbType.NChar, 10);
                _id.Direction = ParameterDirection.Output;
                _id.Value     = _orden.id;
                parameters.Add(_id);

                SqlParameter _tipo_oden = new SqlParameter("@tipo_oden", SqlDbType.Int);
                _tipo_oden.Value = _orden.tipo_oden;
                parameters.Add(_tipo_oden);

                SqlParameter _fecha = new SqlParameter("@fecha", SqlDbType.Date);
                _fecha.Value = _orden.fecha;
                parameters.Add(_fecha);

                SqlParameter _hora = new SqlParameter("@hora", SqlDbType.Time);
                _hora.Value = _orden.hora;
                parameters.Add(_hora);


                SqlParameter _estado = new SqlParameter("@estado", SqlDbType.Int);
                _estado.Value = _orden.estado;
                parameters.Add(_estado);

                SqlParameter _ve_vehiculo_responsable_id = new SqlParameter("@ve_vehiculo_responsable_id", SqlDbType.Int);
                _ve_vehiculo_responsable_id.Value = _orden.ve_vehiculo_responsable_id;
                parameters.Add(_ve_vehiculo_responsable_id);

                SqlParameter _per_persona_cedula = new SqlParameter("@per_persona_cedula", SqlDbType.NChar, 10);
                _per_persona_cedula.Value = _orden.per_persona_numero_cedula;
                parameters.Add(_per_persona_cedula);

                SqlParameter _observacion = new SqlParameter("@observacion", SqlDbType.Text);
                _observacion.Value = _orden.observacion;
                parameters.Add(_observacion);

                SqlParameter _km_ingreso = new SqlParameter("@km_ingreso", SqlDbType.Int);
                _km_ingreso.Value = _orden.km_ingreso;
                parameters.Add(_km_ingreso);

                SqlParameter _km_egreso = new SqlParameter("@km_egreso", SqlDbType.Int);
                _km_egreso.Value = _orden.km_egreso;
                parameters.Add(_km_egreso);


                SqlParameter _per_persona_cedula_crea = new SqlParameter("@per_persona_cedula_crea", SqlDbType.NChar, 10);
                _per_persona_cedula_crea.Value = cedula_creador;
                parameters.Add(_per_persona_cedula_crea);

                #endregion

                SqlHelper.ExecuteNonQuery(_con, CommandType.StoredProcedure, "dbo.ORDEN_SP_INSERT", parameters.ToArray());

                return(_id.Value.ToString().Trim());

                //  int customerId = SqlHelper.ExecuteNonQuery(_con, CommandType.Text, _sql_insert, parameters.ToArray());
            }
            catch (Exception ex)
            {
                throw ex;
                //throw new Exception("No se pudo registrar los datos de la persona", ex);
            }
        }