Ejemplo n.º 1
0
        public void dg_OnItemCommand(object sender, DataGridCommandEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item)
            {
                if (e.CommandName == "recommand")
                {
                    int productID = int.Parse(this.dg.DataKeys[e.Item.ItemIndex].ToString());

                    string redirectUrl = "ProductRecommandUpdate.aspx?productID=" + productID.ToString() + "&productRecommandID=0&operateType=" + Convert.ToInt32(UserAction.Create).ToString();

                    this.Response.Redirect(redirectUrl);
                }
                if (e.CommandName == "delete")
                {
                    int productID = int.Parse(this.dg.DataKeys[e.Item.ItemIndex].ToString());

                    using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["MSSqlServer"].ConnectionString))
                    {
                        string commString = "delete from ProductRecommand where ProductRawID=" + productID.ToString();
                        using (SqlCommand comm = new SqlCommand())
                        {
                            comm.CommandText = commString;
                            comm.Connection = conn;
                            conn.Open();

                            try
                            {
                                comm.ExecuteNonQuery();
                            }
                            catch
                            {

                            }
                        }
                    }

                    Product product = InfoAdmin.GetProductByProductID(productID.ToString());

                    //tag逻辑

                    if (product.ProductTagIDs != string.Empty)
                    {
                        string[] tempTagC = product.ProductTagIDs.Split(",".ToCharArray());
                        for (int k = 0; k < tempTagC.Length; k++)
                        {
                            ProductTag hst = new ProductTag();
                            using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["MSSqlServer"].ConnectionString))
                            {
                                string commString = "select * from ProductTag where ProductTagID=" + tempTagC[k];
                                using (SqlCommand comm = new SqlCommand())
                                {
                                    comm.CommandText = commString;
                                    comm.Connection = conn;
                                    conn.Open();
                                    using (SqlDataReader sdr = comm.ExecuteReader())
                                    {
                                        if (sdr.Read())
                                        {
                                            try
                                            {
                                                hst.TagID = int.Parse(sdr["ProductTagID"].ToString());
                                                hst.TagName = sdr["ProductTagName"].ToString();
                                                hst.ProductIDs = sdr["ProductIDs"].ToString();
                                            }
                                            catch
                                            { }
                                        }
                                    }
                                }
                            }
                            string[] tempProductIDC = hst.ProductIDs.Split(",".ToCharArray());
                            string ProductIDs = "";

                            int tempNum = 0;
                            for (int i = 0; i < tempProductIDC.Length; i++)
                            {
                                if (tempProductIDC[i] != product.ProductID.ToString())
                                {
                                    tempNum++;
                                    if (tempNum == 1)
                                    {
                                        ProductIDs = tempProductIDC[i];
                                    }
                                    else
                                    {
                                        ProductIDs += "," + tempProductIDC[i];
                                    }
                                }
                            }
                            using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["MSSqlServer"].ConnectionString))
                            {
                                string commString = "update ProductTag set ProductIDs='" + ProductIDs + "' where ProductTagID=" + hst.TagID.ToString();
                                using (SqlCommand comm = new SqlCommand())
                                {
                                    comm.CommandText = commString;
                                    comm.Connection = conn;
                                    conn.Open();
                                    try
                                    {
                                        comm.ExecuteNonQuery();
                                    }
                                    catch
                                    { }
                                }
                            }
                        }
                    }

                    //

                    if (InfoAdmin.DeleteProduct(productID))
                    {
                        StringHelper.AlertInfo("删除成功", this.Page);
                        this.Response.Redirect("ProductAdmin.aspx");
                    }
                    else
                    {
                        StringHelper.AlertInfo("删除失败", this.Page);
                    }
                }
            }
        }
Ejemplo n.º 2
0
        private void bindBaseInfo()
        {
            string id = Request["id"];
            Product product = InfoAdmin.GetProductByProductID(id);
            //TAG逻辑
            if (product.ProductTagIDs != string.Empty)
            {
                string[] tempTagC = product.ProductTagIDs.Split(",".ToCharArray());
                for (int k = 0; k < tempTagC.Length; k++)
                {
                    ProductTag hst = new ProductTag();
                    using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["MSSqlServer"].ConnectionString))
                    {
                        string commString = "select * from ProductTag where ProductTagID=" + tempTagC[k];
                        using (SqlCommand comm = new SqlCommand())
                        {
                            comm.CommandText = commString;
                            comm.Connection = conn;
                            conn.Open();
                            using (SqlDataReader sdr = comm.ExecuteReader())
                            {
                                if (sdr.Read())
                                {
                                    try
                                    {
                                        hst.TagID = int.Parse(sdr["ProductTagID"].ToString());
                                        hst.TagName = sdr["ProductTagName"].ToString();
                                        hst.ProductIDs = sdr["ProductIDs"].ToString();
                                    }
                                    catch
                                    { }
                                }
                            }
                        }
                    }

                    if (k == 0)
                    {
                        this.txtProductTag.Text = hst.TagName;
                    }
                    else
                    {
                        this.txtProductTag.Text += "," + hst.TagName;
                    }
                }
            }
            //
            txtCompany.Text = product.ProductCompany;
            txtCompanyDescription.Text = product.ProductCompanyDescription;
            txtProductDescription.Text = product.ProductDescription;
            txtProductDiscount.Text = product.ProductDiscount;
            txtProductName.Text = product.ProductName;
            txtProductPrice.Text = product.ProductPrice;
            txtProductRawPrice.Text = product.ProductRawPrice;
            ViewState["ProductInfo"] = product;
        }
Ejemplo n.º 3
0
        protected void btnSubmit_OnClick(object sender, EventArgs e)
        {
            if (this.txtProductTag.Text.Trim() != string.Empty)
            {
                string[] tagCondition = this.txtProductTag.Text.Split(",".ToCharArray());
                this.lblRedInfo1.Visible = false;

                for (int k = 0; k < tagCondition.Length; k++)
                {
                    if (tagCondition[k] == string.Empty)
                    {
                        this.lblRedInfo1.Text = "TAG格式不正确(正确的格式&nbsp;&nbsp; 1,2,3)";
                        this.lblRedInfo1.Visible = true;
                        return;
                    }
                }
            }

            Product product = (Product)ViewState["ProductInfo"];
            //tag逻辑

            if (product.ProductTagIDs != string.Empty)
            {
                string[] tempTagC = product.ProductTagIDs.Split(",".ToCharArray());
                for (int k = 0; k < tempTagC.Length; k++)
                {
                    ProductTag hst = new ProductTag();
                    using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["MSSqlServer"].ConnectionString))
                    {
                        string commString = "select * from ProductTag where ProductTagID=" + tempTagC[k];
                        using (SqlCommand comm = new SqlCommand())
                        {
                            comm.CommandText = commString;
                            comm.Connection = conn;
                            conn.Open();
                            using (SqlDataReader sdr = comm.ExecuteReader())
                            {
                                if (sdr.Read())
                                {
                                    try
                                    {
                                        hst.TagID = int.Parse(sdr["ProductTagID"].ToString());
                                        hst.TagName = sdr["ProductTagName"].ToString();
                                        hst.ProductIDs = sdr["ProductIDs"].ToString();
                                    }
                                    catch
                                    { }
                                }
                            }
                        }
                    }
                    string[] tempProductIDC = hst.ProductIDs.Split(",".ToCharArray());
                    string ProductIDs = "";

                    int tempNum = 0;
                    for (int i = 0; i < tempProductIDC.Length; i++)
                    {
                        if (tempProductIDC[i] != product.ProductID.ToString())
                        {
                            tempNum++;
                            if (tempNum == 1)
                            {
                                ProductIDs = tempProductIDC[i];
                            }
                            else
                            {
                                ProductIDs += "," + tempProductIDC[i];
                            }
                        }
                    }
                    using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["MSSqlServer"].ConnectionString))
                    {
                        string commString = "update ProductTag set ProductIDs='" + ProductIDs + "' where ProductTagID=" + hst.TagID.ToString();
                        using (SqlCommand comm = new SqlCommand())
                        {
                            comm.CommandText = commString;
                            comm.Connection = conn;
                            conn.Open();
                            try
                            {
                                comm.ExecuteNonQuery();
                            }
                            catch
                            { }
                        }
                    }
                }
            }

            //
            product.ProductName = txtProductName.Text.Trim();
            product.ProductPrice = txtProductPrice.Text.Trim();
            product.ProductRawPrice = txtProductRawPrice.Text.Trim();
            product.ProductDiscount = txtProductDiscount.Text.Trim();
            product.ProductDescription = txtProductDescription.Text.Trim();
            product.ProductCompanyDescription = txtCompanyDescription.Text.Trim();
            product.ProductCompany = txtCompany.Text.Trim();

            //tag逻辑
            int id = product.ProductID;
            string tagIDs = "";
            string[] tagCollection = txtProductTag.Text.Split(",".ToCharArray());
            if (tagCollection[0] != string.Empty)
            {
                for (int k = 0; k < tagCollection.Length; k++)
                {
                    string tagID = "";
                    bool isExist = false;
                    ProductTag hst = new ProductTag();
                    using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["MSSqlServer"].ConnectionString))
                    {
                        string commString = "select * from ProductTag where ProductTagName='" + tagCollection[k] + "'";
                        using (SqlCommand comm = new SqlCommand())
                        {
                            comm.CommandText = commString;
                            comm.Connection = conn;
                            conn.Open();
                            using (SqlDataReader sdr = comm.ExecuteReader())
                            {
                                if (sdr.Read())
                                {
                                    try
                                    {
                                        hst.TagID = int.Parse(sdr["ProductTagID"].ToString());
                                        hst.TagName = sdr["ProductTagName"].ToString();
                                        hst.ProductIDs = sdr["ProductIDs"].ToString();
                                    }
                                    catch
                                    { }
                                }
                            }
                        }
                    }
                    if (hst.TagID == 0)
                    {
                        using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["MSSqlServer"].ConnectionString))
                        {
                            string commString = "insert ProductTag(ProductTagName,ProductIDs) values('" + tagCollection[k] + "','" + id.ToString() + "');select @@identity;";
                            using (SqlCommand comm = new SqlCommand())
                            {
                                comm.CommandText = commString;
                                comm.Connection = conn;
                                conn.Open();

                                tagID = comm.ExecuteScalar().ToString();
                            }
                        }
                    }
                    else
                    {
                        tagID = hst.TagID.ToString();
                        if (hst.ProductIDs == string.Empty)
                        {
                            using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["MSSqlServer"].ConnectionString))
                            {
                                string commString = "update ProductTag set ProductIDs='" + id.ToString() + "' where ProductTagID=" + hst.TagID.ToString();
                                using (SqlCommand comm = new SqlCommand())
                                {
                                    comm.CommandText = commString;
                                    comm.Connection = conn;
                                    conn.Open();
                                    try
                                    {
                                        comm.ExecuteNonQuery();
                                    }
                                    catch
                                    { }
                                }
                            }
                        }
                        else
                        {
                            using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["MSSqlServer"].ConnectionString))
                            {
                                string commString = "update ProductTag set ProductIDs=ProductIDs+'," + id.ToString() + "' where ProductTagID=" + hst.TagID.ToString();
                                using (SqlCommand comm = new SqlCommand())
                                {
                                    comm.CommandText = commString;
                                    comm.Connection = conn;
                                    conn.Open();
                                    try
                                    {
                                        comm.ExecuteNonQuery();
                                    }
                                    catch
                                    { }
                                }
                            }
                        }
                    }
                    if (k == 0)
                    {
                        tagIDs = tagID;
                    }
                    else
                    {
                        tagIDs += "," + tagID;
                    }
                }
            }
            product.ProductTagIDs = tagIDs;
            //

            Session["ProductInfo"] = product;
            //更新美发产品
            InfoAdmin.UpdateProduct(product);
            this.Response.Redirect("ProductAdmin.aspx");
        }
        public bool ProductTagCreateDeleteUpdate(ProductTag productTag, UserAction ua)
        {
            bool result = false;

            string commandText = string.Empty;
            switch (ua)
            {
                case UserAction.Create:
                    commandText = "insert into ProductTag(ProductTagName,ProductIDs) values('" + productTag.TagName + "','" + productTag.ProductIDs + "')";
                    break;
                case UserAction.Delete:
                    commandText = "delete from ProductTag where ProductTagID=" + productTag.TagID.ToString();
                    break;
                case UserAction.Update:
                    commandText = "update ProductTag set ProductTagName = '" + productTag.TagName + "',ProductIDs='" + productTag.ProductIDs + "' where ProductTagID=" + productTag.TagID.ToString();
                    break;
            }
            using (SqlConnection conn = new SqlConnection(DataHelper2.SqlConnectionString))
            {
                using (SqlCommand comm = new SqlCommand())
                {
                    comm.CommandText = commandText;
                    comm.Connection = conn;
                    conn.Open();
                    try
                    {
                        comm.ExecuteNonQuery();
                        result = true;
                    }
                    catch (Exception ex)
                    {
                        throw new Exception(ex.Message);
                    }

                }
            }

            return result;
        }
        public List<ProductTag> GetProductTags(int count)
        {
            List<ProductTag> list = new List<ProductTag>();

            string commText = "";
            switch (count)
            {
                case 0:
                    commText = "select * from ProductTag Order by ProductTagID desc";
                    break;
                default:
                    commText = "select top " + count.ToString() + " * from ProductTag order by ProductTagID desc";
                    break;
            }

            using (SqlConnection conn = new SqlConnection(DataHelper2.SqlConnectionString))
            {
                {
                    using (SqlCommand comm = new SqlCommand())
                    {
                        comm.Connection = conn;
                        comm.CommandText = commText;
                        conn.Open();

                        using (SqlDataReader sdr = comm.ExecuteReader())
                        {
                            while (sdr.Read())
                            {
                                ProductTag productTag = new ProductTag();

                                productTag.ProductIDs = sdr["ProductIDs"].ToString();
                                productTag.TagID = int.Parse(sdr["ProductTagID"].ToString());
                                productTag.TagName = sdr["ProductTagName"].ToString();

                                list.Add(productTag);
                            }
                        }
                    }
                }
            }

            return list;
        }
        public ProductTag GetProductTagByProductTagID(int productTagID)
        {
            ProductTag productTag = new ProductTag();

            string commText = "select * from ProductTag where ProductTagID = " + productTagID.ToString();

            using (SqlConnection conn = new SqlConnection(DataHelper2.SqlConnectionString))
            {
                {
                    using (SqlCommand comm = new SqlCommand())
                    {
                        comm.Connection = conn;
                        comm.CommandText = commText;
                        conn.Open();

                        using (SqlDataReader sdr = comm.ExecuteReader())
                        {
                            while (sdr.Read())
                            {
                                productTag.ProductIDs = sdr["ProductIDs"].ToString();
                                productTag.TagID = int.Parse(sdr["ProductTagID"].ToString());
                                productTag.TagName = sdr["ProductTagName"].ToString();
                            }
                        }
                    }
                }
            }

            return productTag;
        }