public NuevaCotizacionViewModel(Cotizacion cot, BuscarCotizacionViewModel m)
 {
     c = cot;
     Prov = c.Proveedor;
     model = m;
     TxtCodigo = "COT-" + (cot.IdCotizacion + 1000000).ToString();
     TxtObservacion = cot.Observacion;
     EstFecha = true;
     indicador = 2;
     LstProducto = csql.Buscar(c.IdCotizacion) as List<CotizacionxProducto>;
 }
Ejemplo n.º 2
0
        public object Buscar(params object[] filters)
        {
            List<Cotizacion> lstCotizacion = new List<Cotizacion>();
            DBConexion db = new DBConexion();
            SqlDataReader reader;

            String where = "";
            int est = 2;
            string codCotizacion = "", codProveedor = "";

            if (filters.Length >= 1 && filters.Length <= 5)
            {

                codCotizacion = Convert.ToString(filters[0]);
                codProveedor = Convert.ToString(filters[1]);
                string estado = Convert.ToString(filters[2]);
                DateTime fechaIni = Convert.ToDateTime(filters[3]);
                DateTime fechaFin = Convert.ToDateTime(filters[4]);

                if (!String.IsNullOrEmpty(codCotizacion))
                {
                    try
                    {
                        int idCot = getIDfromCOD(codCotizacion);
                        where += " and idCotizacion = '" + idCot.ToString() + "' ";
                    }
                    catch
                    {
                        MessageBox.Show("Revisar formato de código \nCodigo = COT-100000X");
                    }
                }

                if (!String.IsNullOrEmpty(codProveedor))
                {
                    int idProveedor = getIDfromCOD(codProveedor);
                    where += " and idProveedor = '" + idProveedor.ToString() + "' ";
                }

                if (!String.IsNullOrEmpty(estado))
                {
                    if (estado.Equals("ATENDIDO"))
                        est = 2;
                    if (estado.Equals("PENDIENTE"))
                        est = 1;
                    if (estado.Equals("CANCELADO"))
                        est = 0;

                    where += " and estado = '" + est + "' ";
                }

                if (fechaIni != null)
                {

                    where += " and CONVERT(DATE,'" + fechaIni.ToString("yyyy-MM-dd") + "')   <=  CONVERT(DATE,fechaFin,103) ";

                }

                if (fechaFin != null)
                {

                    where += " and CONVERT(DATE,'" + fechaFin.ToString("yyyy-MM-dd") + "')   >=  CONVERT(DATE,fechaFin,103) ";
                }

            }

            db.cmd.CommandText = "SELECT * FROM Cotizacion  WHERE   estado >= 0   " + where;
            db.cmd.CommandType = CommandType.Text;
            db.cmd.Connection = db.conn;

            try
            {
                db.conn.Open();
                reader = db.cmd.ExecuteReader();

                while (reader.Read())
                {

                    Cotizacion p = new Cotizacion();
                    p.Proveedor = new Proveedor();

                    p.IdCotizacion = Convert.ToInt32(reader["idCotizacion"].ToString());
                    p.CodCotizacion = "COT-" + (1000000 + p.IdCotizacion).ToString();
                    int idProv = Convert.ToInt32(reader["idProveedor"].ToString());
                    p.Proveedor = getPROVfromID(idProv);
                    p.FechaRespuesta = Convert.ToDateTime(reader["fechaResp"].ToString());
                    p.FechaInicio = Convert.ToDateTime(reader["fechaInicio"].ToString());
                    p.FechaFin = Convert.ToDateTime(reader["fechaFin"].ToString());
                    p.Observacion = reader["observacion"].ToString();
                    p.Estado = Convert.ToInt32(reader["estado"].ToString());

                    lstCotizacion.Add(p);
                }

                db.conn.Close();

            }
            catch (Exception e)
            {
                MessageBox.Show(e.StackTrace.ToString());
            }

            return lstCotizacion;
        }