Example #1
0
        public Favorite Obtener(int id)
        {
            CustomerManager   customerManager   = new CustomerManager();
            SpecialistManager specialistManager = new SpecialistManager();

            Favorite      spe = null;
            SqlConnection con = new SqlConnection(Resource.CadenaConexion);

            con.Open();
            string     sql = "Select Id,Hidden,CustomerId,SpecialistId from Favorites where Id = @idFavorite";
            SqlCommand cmd = new SqlCommand(sql, con);

            cmd.Parameters.Add("@idFavorite", System.Data.SqlDbType.NVarChar).Value = id;
            SqlDataReader reader =
                cmd.ExecuteReader(System.Data.CommandBehavior.CloseConnection);

            if (reader.Read())
            {
                spe               = new Favorite();
                spe.id            = reader.GetInt32(0);
                spe.hidden        = reader.GetBoolean(1);
                spe.customer.id   = reader.GetInt32(2);
                spe.specialist.id = reader.GetInt32(3);
            }
            reader.Close();
            if (con.State == System.Data.ConnectionState.Open)
            {
                con.Close();
            }
            return(spe);
        }
Example #2
0
        public Favorite Insertar(Favorite spe)
        {
            Favorite      result = null;
            SqlConnection con    = new SqlConnection(Resource.CadenaConexion);

            con.Open();
            try
            {
                string sql = "Insert into Favorites(Hidden,CustomerId,SpecialistId) output INSERTED.Id values(@hidden,@customer,@specialist)";

                SqlCommand cmd = new SqlCommand(sql, con);
                cmd.Parameters.Add("@hidden", System.Data.SqlDbType.Int).Value     = spe.hidden;
                cmd.Parameters.Add("@customer", System.Data.SqlDbType.Int).Value   = spe.customer.id;
                cmd.Parameters.Add("@specialist", System.Data.SqlDbType.Int).Value = spe.specialist.id;
                int modified = (int)cmd.ExecuteScalar();
                if (modified != 0)
                {
                    CustomerManager   customerManager   = new CustomerManager();
                    SpecialistManager specialistManager = new SpecialistManager();
                    result            = Obtener(modified);
                    result.customer   = customerManager.Obtener(result.customer.id);
                    result.specialist = specialistManager.Obtener(result.specialist.id);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                result = null;
            }
            if (con.State == System.Data.ConnectionState.Open)
            {
                con.Close();
            }
            return(result);
        }
Example #3
0
        public SpecialistTag Obtener(int id)
        {
            TagManager        tagmanager        = new TagManager();
            SpecialistManager specialistManager = new SpecialistManager();

            SpecialistTag spe = null;
            SqlConnection con = new SqlConnection(Resource.CadenaConexion);

            con.Open();
            string     sql = "Select Id,TagId,specialistid from SpecialistTags where Id = @idSpectags";
            SqlCommand cmd = new SqlCommand(sql, con);

            cmd.Parameters.Add("@idSpectags", System.Data.SqlDbType.NVarChar).Value = id;
            SqlDataReader reader =
                cmd.ExecuteReader(System.Data.CommandBehavior.CloseConnection);

            if (reader.Read())
            {
                spe            = new SpecialistTag();
                spe.id         = reader.GetInt32(0);
                spe.tag        = tagmanager.Obtener(reader.GetInt32(1));
                spe.specialist = specialistManager.Obtener(reader.GetInt32(2));
            }
            reader.Close();
            if (con.State == System.Data.ConnectionState.Open)
            {
                con.Close();
            }
            return(spe);
        }
Example #4
0
        public List <SpecialistTag> Obtener()
        {
            SqlConnection con = new SqlConnection(Resource.CadenaConexion);

            con.Open();
            List <SpecialistTag> lista = new List <SpecialistTag>();

            try
            {
                TagManager        tagmanager        = new TagManager();
                SpecialistManager specialistManager = new SpecialistManager();

                string        sql    = "Select Id,TagId,specialistid from SpecialistTags";
                SqlCommand    cmd    = new SqlCommand(sql, con);
                SqlDataReader reader = cmd.ExecuteReader(System.Data.CommandBehavior.CloseConnection);
                while (reader.Read())
                {
                    SpecialistTag spe = new SpecialistTag();
                    spe.id         = reader.GetInt32(0);
                    spe.tag        = tagmanager.Obtener(reader.GetInt32(1));
                    spe.specialist = specialistManager.Obtener(reader.GetInt32(2));
                    lista.Add(spe);
                }
                reader.Close();
            }
            catch (Exception e)
            {
                System.Console.WriteLine(e);
            }
            if (con.State == System.Data.ConnectionState.Open)
            {
                con.Close();
            }
            return(lista);
        }
Example #5
0
        public List <Quotation> Quotations(int id, int problemid)
        {
            SqlConnection con = new SqlConnection(Resource.CadenaConexion);

            con.Open();
            List <Quotation> lista = new List <Quotation>();

            try
            {
                SpecialistManager specialistManager = new SpecialistManager();
                ProblemManager    problemmanager    = new ProblemManager();

                string sql = "Select qu.Id,ProblemId,qu.specialistid,qu.Description,qu.Price," +
                             "qu.EstimatedTime,qu.IncludesMaterials,qu.State,qu.StartDate," +
                             "qu.FinishDate,qu.FinalPrice,qu.SpecialistRate,qu.SpecialistComment," +
                             "qu.CustomerRate,qu.CustomerComment from Quotations qu " +
                             "join Problems pro on pro.Id = qu.ProblemId " +
                             "where pro.customerid = @id and ProblemId = @problemid";

                SqlCommand cmd = new SqlCommand(sql, con);
                cmd.Parameters.Add("@problemid", System.Data.SqlDbType.NVarChar).Value = problemid;
                cmd.Parameters.Add("@id", System.Data.SqlDbType.NVarChar).Value        = id;
                SqlDataReader reader = cmd.ExecuteReader(System.Data.CommandBehavior.CloseConnection);
                while (reader.Read())
                {
                    Quotation spe = new Quotation();
                    spe.id                = reader.GetInt32(0);
                    spe.problem           = problemmanager.Obtener(reader.GetInt32(1));
                    spe.specialist        = specialistManager.Obtener(reader.GetInt32(2));
                    spe.description       = reader.GetString(3);
                    spe.price             = reader.GetDecimal(4);
                    spe.estimatedTime     = reader.GetByte(5);
                    spe.includesMaterial  = reader.GetBoolean(6);
                    spe.state             = reader.GetByte(7);
                    spe.startDate         = reader.GetDateTime(8);
                    spe.finishDate        = reader.GetDateTime(9);
                    spe.finalPrice        = reader.GetDecimal(10);
                    spe.specialistRate    = reader.GetDecimal(11);
                    spe.specialistComment = reader.GetString(12);
                    spe.customerRate      = reader.GetDecimal(13);
                    spe.customerComment   = reader.GetString(14);
                    lista.Add(spe);
                }
                reader.Close();
            }
            catch (Exception e)
            {
                System.Console.WriteLine(e);
            }
            if (con.State == System.Data.ConnectionState.Open)
            {
                con.Close();
            }
            return(lista);
        }
Example #6
0
        public Quotation Insertar(Quotation spe)
        {
            Quotation     result = null;
            SqlConnection con    = new SqlConnection(Resource.CadenaConexion);

            con.Open();
            try
            {
                string sql = "Insert into Quotations(ProblemId,SpecialistId,Description,Price,EstimatedTime" +
                             ",IncludesMaterials,State,StartDate,FinishDate,FinalPrice,SpecialistRate,SpecialistComment" +
                             ",CustomerRate,CustomerComment) output INSERTED.Id values(@problemid,@specialistid,@description" +
                             ",@price,@estimatedtime,@includesmaterials,@state,@startdate,@finishdate,@finalprice" +
                             ",@specialistrate,@specialistcomment,@customerrate,@customercomment)";

                SqlCommand cmd = new SqlCommand(sql, con);
                cmd.Parameters.Add("@problemid", System.Data.SqlDbType.Int).Value             = spe.problem.id;
                cmd.Parameters.Add("@specialistid", System.Data.SqlDbType.Int).Value          = spe.specialist.id;
                cmd.Parameters.Add("@description", System.Data.SqlDbType.VarChar).Value       = spe.description;
                cmd.Parameters.Add("@price", System.Data.SqlDbType.Decimal).Value             = spe.price;
                cmd.Parameters.Add("@estimatedtime", System.Data.SqlDbType.Bit).Value         = spe.estimatedTime;
                cmd.Parameters.Add("@includesmaterials", System.Data.SqlDbType.Bit).Value     = spe.includesMaterial;
                cmd.Parameters.Add("@state", System.Data.SqlDbType.Bit).Value                 = spe.state;
                cmd.Parameters.Add("@startdate", System.Data.SqlDbType.DateTime).Value        = spe.startDate;
                cmd.Parameters.Add("@finishdate", System.Data.SqlDbType.DateTime).Value       = spe.finishDate;
                cmd.Parameters.Add("@finalprice", System.Data.SqlDbType.Decimal).Value        = spe.finalPrice;
                cmd.Parameters.Add("@specialistrate", System.Data.SqlDbType.Decimal).Value    = spe.specialistRate;
                cmd.Parameters.Add("@specialistcomment", System.Data.SqlDbType.VarChar).Value = spe.specialistComment;
                cmd.Parameters.Add("@customerrate", System.Data.SqlDbType.Decimal).Value      = spe.customerRate;
                cmd.Parameters.Add("@customercomment", System.Data.SqlDbType.VarChar).Value   = spe.customerComment;
                int modified = (int)cmd.ExecuteScalar();
                if (modified != 0)
                {
                    ProblemManager    problemManager    = new ProblemManager();
                    SpecialistManager specialistManager = new SpecialistManager();

                    result            = Obtener(modified);
                    result.specialist = specialistManager.Obtener(result.specialist.id);
                    result.problem    = problemManager.Obtener(result.problem.id);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                result = null;
            }
            if (con.State == System.Data.ConnectionState.Open)
            {
                con.Close();
            }
            return(result);
        }
Example #7
0
        public Quotation Obtener(int id)
        {
            Quotation     spe = null;
            SqlConnection con = new SqlConnection(Resource.CadenaConexion);

            con.Open();
            string sql = "select Id,ProblemId,SpecialistId,Description," +
                         "Price,EstimatedTime,IncludesMaterials,State," +
                         "StartDate,FinishDate,FinalPrice,SpecialistRate," +
                         "SpecialistComment,CustomerRate,CustomerComment from Quotations where Id = @quotation";

            SqlCommand cmd = new SqlCommand(sql, con);

            cmd.Parameters.Add("@quotation", System.Data.SqlDbType.NVarChar).Value = id;
            SqlDataReader reader =
                cmd.ExecuteReader(System.Data.CommandBehavior.CloseConnection);

            if (reader.Read())
            {
                ProblemManager    problemManager    = new ProblemManager();
                SpecialistManager specialistManager = new SpecialistManager();

                spe                   = new Quotation();
                spe.id                = reader.GetInt32(0);
                spe.problem           = problemManager.Obtener(reader.GetInt32(1));
                spe.specialist        = specialistManager.Obtener(reader.GetInt32(2));
                spe.description       = reader.GetString(3);
                spe.price             = reader.GetDecimal(4);
                spe.estimatedTime     = reader.GetByte(5);
                spe.includesMaterial  = reader.GetBoolean(6);
                spe.state             = reader.GetByte(7);
                spe.startDate         = reader.GetDateTime(8);
                spe.finishDate        = reader.GetDateTime(9);
                spe.finalPrice        = reader.GetDecimal(10);
                spe.specialistRate    = reader.GetDecimal(11);
                spe.specialistComment = reader.GetString(12);
                spe.customerRate      = reader.GetDecimal(13);
                spe.customerComment   = reader.GetString(14);
            }
            reader.Close();
            if (con.State == System.Data.ConnectionState.Open)
            {
                con.Close();
            }
            return(spe);
        }
Example #8
0
        public List <Favorite> Obtener()
        {
            SqlConnection con = new SqlConnection(Resource.CadenaConexion);

            con.Open();
            List <Favorite> lista = new List <Favorite>();

            try
            {
                CustomerManager   customerManager   = new CustomerManager();
                SpecialistManager specialistManager = new SpecialistManager();

                string        sql    = "Select Id,Hidden,CustomerId,SpecialistId from Favorites";
                SqlCommand    cmd    = new SqlCommand(sql, con);
                SqlDataReader reader = cmd.ExecuteReader(System.Data.CommandBehavior.CloseConnection);
                while (reader.Read())
                {
                    Favorite spe = new Favorite();
                    spe.id            = reader.GetInt32(0);
                    spe.hidden        = reader.GetBoolean(1);
                    spe.customer.id   = reader.GetInt32(2);
                    spe.specialist.id = reader.GetInt32(3);
                    lista.Add(spe);
                }
                reader.Close();
            }
            catch (Exception e)
            {
                System.Console.WriteLine(e);
            }
            if (con.State == System.Data.ConnectionState.Open)
            {
                con.Close();
            }
            return(lista);
        }
Example #9
0
        public List <Favorite> Favorite(int id)
        {
            SqlConnection con = new SqlConnection(Resource.CadenaConexion);

            con.Open();
            List <Favorite> lista = new List <Favorite>();

            try
            {
                SpecialistManager specialistManager = new SpecialistManager();

                string     sql = "Select Id,Hidden,customerid,specialistid from Favorites where customerid = @idClient";
                SqlCommand cmd = new SqlCommand(sql, con);
                cmd.Parameters.Add("@idClient", System.Data.SqlDbType.NVarChar).Value = id;
                SqlDataReader reader = cmd.ExecuteReader(System.Data.CommandBehavior.CloseConnection);
                while (reader.Read())
                {
                    Favorite spe = new Favorite();
                    spe.id          = reader.GetInt32(0);
                    spe.hidden      = reader.GetBoolean(1);
                    spe.customer.id = reader.GetInt32(2);
                    spe.specialist  = specialistManager.Obtener(reader.GetInt32(3));
                    lista.Add(spe);
                }
                reader.Close();
            }
            catch (Exception e)
            {
                System.Console.WriteLine(e);
            }
            if (con.State == System.Data.ConnectionState.Open)
            {
                con.Close();
            }
            return(lista);
        }