Exemplo n.º 1
0
        protected void btnAdd_Click(object sender, EventArgs e)
        {
            if (!ProductClassManage.IsLeafNode(Convert.ToInt32(ProductClassDDL1.currentValue)))
            {
                Page.ClientScript.RegisterClientScriptBlock(this.GetType(),"err", "<script>alert('产品只能添加到子分类',请选择一个正确的分类!);</script>");
            }
            else
            {
                Product myProduct = new Product();

                myProduct.Prod_Name = this.txtName.Text;
                myProduct.Prod_Number = this.txtNumber.Text;

                if (!string.IsNullOrEmpty(this.txtPrice.Text))
                {
                    myProduct.Prod_Price = Convert.ToDecimal(this.txtPrice.Text);
                }

                myProduct.Prod_Content = CKEditor1.Text;
                myProduct.Prod_Click = 0;
                myProduct.Prod_Date = DateTime.Now;
                myProduct.IsTop = this.cbxTop.Checked;
                myProduct.IsCommend = this.cbxCommand.Checked;

                myProduct.Pc_Id = Convert.ToInt32(ProductClassDDL1.currentValue);

                if (string.IsNullOrEmpty(this.txtImage.Text) || this.txtImage.Text == "")
                {
                    string fckStr = CKEditor1.Text;
                    MatchCollection matchs = Regex.Matches(fckStr, @"<img[^src]*src=""[^http\://]*(?<src>[^""]*?)""", RegexOptions.IgnoreCase);

                    foreach (Match m in matchs)
                    {
                        myProduct.Prod_Image = m.Groups["src"].Value.ToString();
                        break;
                    }

                    if (string.IsNullOrEmpty(myProduct.Prod_Image))
                    {
                        myProduct.Prod_Image = " ";
                    }
                }
                else
                {
                    myProduct.Prod_Image = this.txtImage.Text.Trim();
                }

                if (ProductManage.Insert(myProduct))
                {
                    Response.Write("<script>alert('产品添加成功!!!');window.location.href=document.URL;</script>");
                }
                else
                {
                    this.lblError.Visible = true;
                }
            }
        }
Exemplo n.º 2
0
        public static ProductCollection GetCommend()
        {
            ProductCollection list = ProductService.GetCommend();
               int length = list.Count;
               if (length < 18)
               {
               int i = 0;
               while(i < 18 - length)
               {
                   Product product = new Product();
                   list.Add(product);

                   i++;
               }
               }

               return list;
        }
Exemplo n.º 3
0
        /// <summary>
        /// 条件查询产品
        /// </summary>
        /// <param name="prod_id">产品id</param>
        /// <returns>Product模型 包含一条产品记录</returns>
        public static Product GetItem(int prod_id)
        {
            Product myProduct = new Product();
            string sql = "select * from t_product where prod_id=?prod_id";
            MySqlParameter[] parms = { new MySqlParameter("?prod_id", MySqlDbType.Int32) };
            parms[0].Value = prod_id;
            MySqlDataReader reader = DbHelper.ExecuteDataReader(sql, parms);
            if (reader.HasRows)
            {
                if (reader.Read())
                {
                    myProduct = FillDataRecord(reader);
                }
            }

            reader.Close();

            return myProduct;
        }
Exemplo n.º 4
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                string prodId = null;
                try
                {
                    prodId = Request.QueryString["id"].ToString();
                }
                catch (Exception ex)
                {
                }

                Product myProduct = new Product();
                if (BaseCommon.ValidQueryString(prodId))
                {
                    ProductManage.Update(Convert.ToInt32(prodId));
                    myProduct = ProductManage.GetItem(Convert.ToInt32(prodId));

                    pcnav = ProductClassManage.ProductClassNav(Convert.ToInt32(myProduct.Pc_Id), pcnav);

                    Page.Title = myProduct.Prod_Name;
                    //HtmlMeta keywords = (HtmlMeta)Master.FindControl("keywords");
                    //HtmlMeta Description = (HtmlMeta)Master.FindControl("Description");

                    //keywords.Attributes["content"] = keywords.Attributes["content"] + "," + myProduct.Prod_Name;
                   // Description.Attributes["content"] = Description.Attributes["content"] + "," + myProduct.Prod_Name;

                    this.lblTitle.Text = myProduct.Prod_Name;
                    this.lblNumber.Text = myProduct.Prod_Number;
                    this.lblClick.Text = myProduct.Prod_Click.ToString();
                    this.lblContent.Text = myProduct.Prod_Content;
                    this.imgProd.ImageUrl = myProduct.Prod_Image;
                }
                else
                {
                    Response.Write("错误的链接!");
                }
            }
        }
Exemplo n.º 5
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (!string.IsNullOrEmpty(Request.QueryString["id"]))
                {
                    myProduct = ProductManage.GetItem(Convert.ToInt32(Request.QueryString["id"]));

                    if (string.IsNullOrEmpty(myProduct.Prod_Name))
                    {
                        Response.Write("<script language=JavaScript>alert('错误的链接!');document.location.href='ProductMgmt.aspx'</script>");
                    }
                    else
                    {
                        this.ProductClassDDL1.LoadTree();
                        this.ProductClassDDL1.InnerDropDownListTree.Items.FindByValue(myProduct.Pc_Id.ToString()).Selected = true;

                        this.tbxName.Text = myProduct.Prod_Name;
                        this.tbxNumber.Text = myProduct.Prod_Number;
                        this.tbxPrice.Text = string.Format("{0:N2}", myProduct.Prod_Price);
                        this.tbxImage.Text = myProduct.Prod_Image;
                        CKEditor1.Text = myProduct.Prod_Content;
                        this.cbxTop.Checked = myProduct.IsTop;
                        this.cbxCommend.Checked = myProduct.IsCommend;
                        Page.Title = myProduct.Prod_Name;
                    }

                }
                else
                {
                    Response.Write("<script language=JavaScript>alert('错误的链接!');document.location.href='ProductMgmt.aspx'</script>");
                }

            }

            CKFinder.FileBrowser _FileBrowser = new CKFinder.FileBrowser();
            _FileBrowser.BasePath = "";
            _FileBrowser.SetupCKEditor(CKEditor1);
        }
Exemplo n.º 6
0
        private static Product FillDataRecord(IDataRecord myDataRecord)
        {
            Product myProduct = new Product();

            myProduct.Prod_Id = myDataRecord.GetInt32(myDataRecord.GetOrdinal("prod_id"));
            myProduct.Prod_Name = myDataRecord.GetString(myDataRecord.GetOrdinal("prod_name"));
            myProduct.Prod_Content = myDataRecord.GetString(myDataRecord.GetOrdinal("prod_content"));
            myProduct.Prod_Date = myDataRecord.GetDateTime(myDataRecord.GetOrdinal("prod_date"));
            myProduct.Pc_Id = myDataRecord.GetInt32(myDataRecord.GetOrdinal("pc_id"));

            if (!myDataRecord.IsDBNull(myDataRecord.GetOrdinal("prod_number")))
            {
                myProduct.Prod_Number = myDataRecord.GetString(myDataRecord.GetOrdinal("prod_number"));
            }
            if (!myDataRecord.IsDBNull(myDataRecord.GetOrdinal("prod_price")))
            {
                myProduct.Prod_Price = myDataRecord.GetDecimal(myDataRecord.GetOrdinal("prod_price"));
            }
            if (!myDataRecord.IsDBNull(myDataRecord.GetOrdinal("prod_image")))
            {
                myProduct.Prod_Image = myDataRecord.GetString(myDataRecord.GetOrdinal("prod_image"));
            }
            if (!myDataRecord.IsDBNull(myDataRecord.GetOrdinal("prod_click")))
            {
                myProduct.Prod_Click = myDataRecord.GetInt32(myDataRecord.GetOrdinal("prod_click"));
            }
            if (!myDataRecord.IsDBNull(myDataRecord.GetOrdinal("istop")))
            {
                myProduct.IsTop = myDataRecord.GetBoolean(myDataRecord.GetOrdinal("istop"));
            }
            if (!myDataRecord.IsDBNull(myDataRecord.GetOrdinal("iscommend")))
            {
                myProduct.IsCommend = myDataRecord.GetBoolean(myDataRecord.GetOrdinal("iscommend"));
            }

            return myProduct;
        }
Exemplo n.º 7
0
        /// <summary>
        /// 修改产品
        /// </summary>
        /// <param name="myProduct">产品模型</param>
        /// <returns>返回<c>true</c>修改成功,或<c>false</c>修改失败.</returns>
        public static bool Update(Product myProduct)
        {
            int result = 0;
            string sql = @"update t_product
                          set
                                prod_name = ?prod_name,
                                prod_number = ?prod_number,
                                prod_price = ?prod_price,
                                prod_image = ?Prod_image,
                                prod_content = ?prod_content,
                                prod_date = ?prod_date,
                                istop = ?istop,
                                iscommend = ?iscommend,
                                pc_id = ?pc_id
                            WHERE
                                prod_id = ?prod_id";
            MySqlParameter[] parms = {
                                        new MySqlParameter("@prod_name",MySqlDbType.VarChar),
                                        new MySqlParameter("@prod_number",MySqlDbType.VarChar),
                                        new MySqlParameter("@prod_price",MySqlDbType.Decimal),
                                        new MySqlParameter("@prod_image",MySqlDbType.VarChar),
                                        new MySqlParameter("@prod_content",MySqlDbType.Text),
                                        new MySqlParameter("@prod_date",MySqlDbType.Date),
                                        new MySqlParameter("@istop",MySqlDbType.Bit),
                                        new MySqlParameter("@iscommend",MySqlDbType.Bit),
                                        new MySqlParameter("@pc_id",MySqlDbType.Int32),
                                        new MySqlParameter("@prod_id",MySqlDbType.Int32)
                                     };

            parms[0].Value = myProduct.Prod_Name;
            parms[1].Value = myProduct.Prod_Number;
            parms[2].Value = myProduct.Prod_Price;
            parms[3].Value = myProduct.Prod_Image;
            parms[4].Value = myProduct.Prod_Content;
            parms[5].Value = myProduct.Prod_Date;
            parms[6].Value = myProduct.IsTop;
            parms[7].Value = myProduct.IsCommend;
            parms[8].Value = myProduct.Pc_Id;
            parms[9].Value = myProduct.Prod_Id;

            result = DbHelper.ExecuteNonQuery(sql, parms);

            return result > 0;
        }
Exemplo n.º 8
0
        /// <summary>
        /// 插入产品记录
        /// </summary>
        /// <param name="myProduct">myProduct 模型</param>
        /// <returns>返回<c>true</c>插入成功,或<c>false</c>插入失败.</returns>
        public static bool Insert(Product myProduct)
        {
            int result = 0;
            string sql = @"insert into t_product(
                                                    prod_name,
                                                    prod_number,
                                                    prod_price,
                                                    prod_image,
                                                    prod_content,
                                                    prod_date,
                                                    prod_click,
                                                    istop,
                                                    iscommend,
                                                    pc_id
                                                )
                                                values
                                                (
                                                    ?prod_name,
                                                    ?prod_number,
                                                    ?prod_price,
                                                    ?prod_image,
                                                    ?prod_content,
                                                    ?prod_date,
                                                    ?prod_click,
                                                    ?istop,
                                                    ?iscommend,
                                                    ?pc_id
                                                )";
            MySqlParameter[] parms = {
                                        new MySqlParameter("?prod_name",MySqlDbType.VarChar),
                                        new MySqlParameter("?prod_number",MySqlDbType.VarChar),
                                        new MySqlParameter("?prod_price",MySqlDbType.Decimal),
                                        new MySqlParameter("?prod_image",MySqlDbType.VarChar),
                                        new MySqlParameter("?prod_content",MySqlDbType.Text),
                                        new MySqlParameter("?prod_date",MySqlDbType.Date),
                                        new MySqlParameter("?prod_click",MySqlDbType.Int32),
                                        new MySqlParameter("?istop",MySqlDbType.Bit),
                                        new MySqlParameter("?iscommend",MySqlDbType.Bit),
                                        new MySqlParameter("?pc_id",MySqlDbType.Int32),
                                     };
            parms[0].Value = myProduct.Prod_Name;
            parms[1].Value = myProduct.Prod_Number;
            parms[2].Value = myProduct.Prod_Price;
            parms[3].Value = myProduct.Prod_Image;
            parms[4].Value = myProduct.Prod_Content;
            parms[5].Value = myProduct.Prod_Date;
            parms[6].Value = myProduct.Prod_Click;
            parms[7].Value = myProduct.IsTop;
            parms[8].Value = myProduct.IsCommend;
            parms[9].Value = myProduct.Pc_Id;

            result = DbHelper.ExecuteNonQuery(sql, parms);

            return result > 0;
        }
Exemplo n.º 9
0
 public static bool Insert(Product myProduct)
 {
     if(!string.IsNullOrEmpty(myProduct.Prod_Name)
         && !string.IsNullOrEmpty(myProduct.Prod_Content)
         && myProduct.Pc_Id > 0)
     {
         myProduct.Prod_Date = DateTime.Now;
         return ProductService.Insert(myProduct);
     }
     else
     {
         return false;
     }
 }