Example #1
0
        public List <Jf_Model> list()
        {
            Jf bll = new Jf();
            //DataTable dt = bll.GetList();
            List <Jf_Model> list = new List <Jf_Model>();
            Database        db   = DatabaseFactory.CreateDatabase();
            StringBuilder   sb   = new StringBuilder();

            sb.Append("select * from Jf");
            DbCommand   cmd    = db.GetSqlStringCommand(sb.ToString());
            IDataReader reader = db.ExecuteReader(cmd);

            while (reader.Read())
            {
                int    id   = reader.GetInt32(reader.GetOrdinal("ID"));
                string name = reader.GetString(reader.GetOrdinal("Name"));
                int    jf   = reader.GetInt32(reader.GetOrdinal("Jf"));
                string pt   = reader.GetString(reader.GetOrdinal("Pt"));
                string img  = reader.GetString(reader.GetOrdinal("Img"));
                list.Add(new Jf_Model
                {
                    id   = id,
                    name = name,
                    jf   = jf,
                    pt   = pt,
                    img  = img
                });
            }
            return(list);
        }
Example #2
0
        protected void Button1_Click(object sender, EventArgs e)
        {
            if (this.FileUpload1.HasFile)     //判断上传数据是否为空
            {
                //bool FileIsValid=false;
                String   fileExtension     = System.IO.Path.GetExtension(this.FileUpload1.FileName).ToLower();//获取文件类型
                String[] restrictExtension = { ".gif", ".jpg", ".bmp", ".png" };
                int      length            = txtName.Text.Trim().Length;
                int      length1           = jf.Text.Trim().Length;
                if (length != 0)
                {
                    if (length1 != 0)
                    {
                        if (restrictExtension.Contains(fileExtension) == true)
                        {
                            string filePath = "/JFimages/";
                            string fileName = filePath + CreatePasswordHash(FileUpload1.FileName, 4) + fileExtension;
                            string mappath  = Server.MapPath(fileName);
                            FileUpload1.PostedFile.SaveAs(mappath);      //转换存储到服务器上的物理路径
                            SOSOshop.Model.JF.Jf_Model mdoel = new SOSOshop.Model.JF.Jf_Model();
                            mdoel.name = this.txtName.Text.Trim();
                            mdoel.jf   = Convert.ToInt32(this.jf.Text.Trim());
                            mdoel.pt   = this.pt.Text.Trim();
                            mdoel.img  = fileName;
                            SOSOshop.BLL.JF.Jf bll = new SOSOshop.BLL.JF.Jf();
                            bll.Add(mdoel);

                            Response.Write("<script>alert('文件上传成功');window.location.href='Add.aspx';</script>");
                            //Response.Redirect("js_list.aspx");
                        }
                        else
                        {
                            Response.Write("<script>alert('请选择正确的图片格式');window.location.href='Add.aspx';</script>");
                        }
                    }
                    else
                    {
                        Response.Write("<script>alert('请输入商品积分');window.location.href='Add.aspx';</script>");
                    }
                }
                else
                {
                    Response.Write("<script>alert('请输入商品名称');window.location.href='Add.aspx';</script>");
                }
            }
            else
            {
                Response.Write("<script>alert('请选择图片')</script>");
            }
        }