Пример #1
0
        protected void Button4_Click(object sender, EventArgs e)
        {
            SqlConnection conn = null;
            SqlDataReader dr = null;

            try
            {
                ReviewRepository pr = new ReviewRepository();
                ReviewableRepository rr = new ReviewableRepository();
                UserRepository ur = new UserRepository();

                conn = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["DataServices"].ConnectionString);
                conn.Open();

                SqlCommand cmd = new SqlCommand("SELECT * from vCurrentProductReviews", conn);

                dr = cmd.ExecuteReader();
                while (dr.Read())
                {
                    ReviewData prod = new ReviewData();
                    //prod.name = dr.GetString(4);
                    //if (dr.GetValue(5) != DBNull.Value)
                    //    prod.description = dr.GetString(5);
                    if (dr.GetValue(6) != DBNull.Value)
                        prod.createdDate = dr.GetDateTime(6);
                    if (dr.GetValue(7) != DBNull.Value)
                        prod.lastModified = dr.GetDateTime(7);
                    if (dr.GetValue(8) != DBNull.Value)
                        prod.text = dr.GetString(8);
                    if (dr.GetValue(9) != DBNull.Value)
                        prod.rating = dr.GetDouble(9);
                    if (dr.GetValue(10) != DBNull.Value)
                    {
                        prod.userName = dr.GetString(10);
                        prod.user = ur.GetByName(prod.userName).id;
                    }
                    if (dr.GetValue(14) != DBNull.Value)
                        prod.fBFeedPostId = dr.GetString(14);
                    if (dr.GetValue(15) != DBNull.Value)
                        prod.fBTimelinePostId = dr.GetString(15);

                    if (dr.GetValue(4) != DBNull.Value)
                    {
                        ReviewableData x = rr.GetByName(dr.GetString(4), Guid.Empty).First();
                        prod.parentReviewableId = x.id;
                        prod.parentName = x.name;

                        //prod.outsideCode = x.outsideCode;
                        //prod.outsideCodeType = x.outsideCodeType;
                        //prod.issuerCountryCode = x.issuerCountryCode;
                        //prod.issuerCountry = x.issuerCountry;
                        //prod.providedByBizId = x.parentReviewableId;
                        //prod.providedByBizName = x.parentName;

                    }
                    prod.reviewableType = "product";

                    pr.Add(prod);

                }
                dr.Close();
            }
            finally
            {
                if (conn != null)
                {
                    conn.Close();
                }
            }
        }
Пример #2
0
        protected void Button3_Click(object sender, EventArgs e)
        {
            SqlConnection conn = null;
            SqlDataReader dr = null;

            try
            {
                ReviewableRepository pr = new ReviewableRepository();

                conn = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["DataServices"].ConnectionString);
                conn.Open();

                SqlCommand cmd = new SqlCommand("GetProductsByName", conn);
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.AddWithValue("@name", "");
                cmd.Parameters.AddWithValue("@userId", 1);

                dr = cmd.ExecuteReader();
                while (dr.Read())
                {
                    ReviewableData prod = new ReviewableData();
                    prod.name = dr.GetString(1);
                    if (dr.GetValue(2) != DBNull.Value)
                        prod.description = dr.GetString(2);
                    if (dr.GetValue(3) != DBNull.Value && dr.GetString(3).Trim().Length != 0)
                        prod.outsideCode = dr.GetString(3);
                    if (dr.GetValue(4) != DBNull.Value && dr.GetString(4).Trim() != "None")
                        prod.outsideCodeType = dr.GetString(4).Trim();
                    if (dr.GetValue(5) != DBNull.Value)
                        prod.issuerCountryCode = "en_us"; // dr.GetString(5);
                    if (dr.GetValue(6) != DBNull.Value)
                        prod.issuerCountry = dr.GetString(6);
                    //if (dr.GetValue(7) != DBNull.Value)
                        //prod.manufacturerid = dr.GetString(7);
                    //if (dr.GetValue(8) != DBNull.Value)
                        //prod.modelNum = dr.GetString(8);

                    if (dr.GetValue(10) != DBNull.Value)
                    {
                        ReviewableData biz = pr.GetByName(dr.GetString(10), Guid.Empty).First();
                        prod.parentReviewableId = biz.id;
                        prod.parentName = biz.name;
                    }
                    prod.reviewableType = "product";
                    prod.images = new string[0];
                    prod.createdDate = DateTime.UtcNow;
                    pr.Add(prod, Guid.Empty);

                }
                dr.Close();

                IEnumerable<ReviewableData> prods = pr.Get();
                foreach (ReviewableData prod in prods)
                {
                    SqlDataReader dr2 = null;
                    string query = @"SELECT top 1 i.uid, i.data, i.fileType, lkift.FileTypeName as imageTypeName, p.Name, 2 as Type, i.dateCreated FROM Image i
                        INNER JOIN lk_Image_FileType lkift on lkift.id = i.fileType
                        INNER JOIN Product_Image pi on i.uid = pi.ImageId
                        INNER JOIN Product p on p.id = pi.ProductId
                        WHERE p.name = '" + prod.name + "' ORDER by i.dateCreated DESC";
                    SqlCommand cmd2 = new SqlCommand(query, conn);

                    dr2 = cmd2.ExecuteReader();
                    while (dr2.Read())
                    {
                        ImageData l = new ImageData();
                        Guid newId = Guid.NewGuid(); //.GenerateNewId();
                        l.id = newId;
                        Object data = dr2.GetValue(1);
                        l.data = (byte[])data;

                        l.fileType = dr2.GetString(3);
                        l.category = "tile";
                        l.description = dr2.GetValue(4).ToString();
                        l.type = dr2.GetInt32(5);
                        l.dateCreated = dr2.GetDateTime(6);

                        pr.AddImage(l, prod.id);

                    }
                    dr2.Close();

                }
            }
            finally
            {
                if (conn != null)
                {
                    conn.Close();
                }
            }
        }