Ejemplo n.º 1
0
    protected void Button1_Click(object sender, EventArgs e)
    {
        //1.判断是否选择文件
        if (FileUpload1.HasFile)
        {
            //2.是否选择图片
            string strtype = FileUpload1.PostedFile.ContentType;
            if (strtype == "image/jpeg")
            {
                //3.上传图片到服务器的指定文件
                string filename = DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString() + DateTime.Now.Day.ToString() + DateTime.Now.Hour.ToString() + DateTime.Now.Minute.ToString() + DateTime.Now.Second.ToString();
                string imgurl = "img/"+ filename +".jpg";
                FileUpload1.SaveAs(Server.MapPath(imgurl));
                Image1.ImageUrl = imgurl;

                //4.将头像的地址保存到对应用户的数据表记录中
                string strsql = string.Format("update member set head='{0}' where LoginName='{1}'",imgurl,Session["username"]);
                if (DbManger.ExceSQL(strsql))
                    Response.Write("<script>alert('头像更新成功!')</script>");
            }
            else
            {
                Response.Write("<script>alert('请选择图片类文件')<script");
            }
        }
        else
        {
            Response.Write("<script>alert('请选择文件')<script");
        }
    }
Ejemplo n.º 2
0
        protected void btnLogin_Click(object sender, EventArgs e)
        {
            #region 用户登录处理
            string check = Request.Cookies["checkcode"].Value.ToString();
            if (check == txtCheckcode.Text)
            {
                #region 使用数据访问类来完成登陆
                string        strsql = string.Format("select * from admin where admin_name='{0}' and admin_pwd='{1}'", txtAccount.Text, txtPassword.Text);
                SqlDataReader dr     = DbManger.ExceRead(strsql);
                if (dr.Read())
                {
                    int admin_id = Int32.Parse(dr["admin_id"].ToString());
                    Session.Timeout       = 20;
                    Session["admin_id"]   = admin_id;
                    Session["admin_name"] = txtAccount.Text;
                    Session["admin_pwd"]  = txtPassword.Text;
                    Response.Write("<script>alert('" + Session["admin_name"].ToString() + "用户登录成功!')</script>");
                    Response.Redirect("index.aspx");
                }
                else
                {
                    Response.Write("<script>alert('用户名密码不正确!')</script>");
                }

                dr.Close();
                #endregion
            }
            else
            {
                Response.Write("<script>alert('验证码不正确')</script>");
            }


            #endregion
        }
Ejemplo n.º 3
0
 protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
 {
     //
     if (Session["userid"] != null || Session["userid"].ToString() != "")
     {
         //
         string    strsql = string.Format("select * from cart where Memberid={0} and Merid={1}", Session["userid"], Request.QueryString["id"]);
         DataSet   ds     = DbManger.GetDataSet(strsql, "cart");
         DataTable dt     = ds.Tables["cart"];
         if (dt.Rows.Count > 0)
         {
             //
             int num = Int32.Parse(dt.Rows[0]["Amount"].ToString()) + Int32.Parse(txt_Num.Text);
             strsql = string.Format("update cart set Amount={0} where Memberid={1} and Merid={2}", num, Session["userid"], Request.QueryString["id"]);
             if (DbManger.ExceSQL(strsql))
             {
                 Page.ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('更新数量成功!')</script>", true);
             }
         }
         else
         {
             float price = float.Parse(DetailsView1.Rows[4].Cells[1].Text.Substring(6));
             strsql = string.Format("insert into cart values({0},{1},{2},{3})", Session["userid"], Request.QueryString["id"], Int32.Parse(txt_Num.Text), price);
             if (DbManger.ExceSQL(strsql))
             {
                 Page.ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('添加商品成功!')</script>", true);
             }
         }
     }
     else
     {
         Response.Redirect("Login.aspx");
     }
 }
Ejemplo n.º 4
0
    protected void Button1_Click(object sender, EventArgs e)
    {
        //更新订单表
        Random rnd     = new Random();
        int    num     = rnd.Next(100, 1000);
        string orderid = DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString() + DateTime.Now.Day.ToString() + DateTime.Now.Hour.ToString() + DateTime.Now.Minute + num.ToString();
        //获取联系地址编号
        int contactid = Int32.Parse(RadioButtonList1.SelectedValue);
        //.下单时间
        string orderdate = DateTime.Now.ToString();

        //订单总价
        float total = float.Parse(lblTotal.Text);

        //配置SQL
        string strsql = string.Format("insert into orders values('{0}',{1},{2},{3},0,'{4}','','','')", orderid, Session["userid"].ToString(), contactid, total, orderdate);

        //更新orders表
        if (DbManger.ExceSQL(strsql))
        {
            //更新订单详情表
            for (int i = 0; i < Repeater1.Items.Count; i++)
            {
                int   merid  = Int32.Parse((Repeater1.Items[i].FindControl("lblId") as Label).Text);
                float price  = float.Parse((Repeater1.Items[i].FindControl("lblPrice") as Label).Text.Substring(1));
                int   amount = Int32.Parse((Repeater1.Items[i].FindControl("lblAmount") as Label).Text);
                strsql = string.Format("insert into orderDetail values('{0}',{1},{2},{3})", orderid, merid, price, amount);
                DbManger.ExceSQL(strsql);
            }
            Response.Write("<script>alert('订单生成');window.location.href='myhome/myallorder.aspx'</script>");
        }
    }
Ejemplo n.º 5
0
    //删除商品
    protected void DataList1_DeleteCommand(object source, DataListCommandEventArgs e)
    {
        string strsql = string.Format("delete from cart where CartId{0}", DataList1.DataKeys[e.Item.ItemIndex].ToString());

        if (DbManger.ExceSQL(strsql))
        {
            Response.Write("<script>alert('删除成功!')</script>");
            DataList1.DataBind();
        }
    }
Ejemplo n.º 6
0
    protected void Page_Load(object sender, EventArgs e)
    {
        //1.判断是否有用户
        if (Session["userid"] != null && Session["userid"].ToString() != "")
        {
            if (!IsPostBack)
            {
                string strsql = string.Format("select * from member where id = '{0}'", Session["userid"].ToString());

                SqlDataReader dr = DbManger.ExceRead(strsql);
                if (dr.Read())
                {
                    txtUser.Text     = dr["LoginName"].ToString();
                    txtPassword.Text = dr["LoginPwd"].ToString();

                    if (dr["Sex"].ToString() == "男")
                    {
                        radlSex.SelectedIndex = 0;
                    }
                    else if (dr["Sex"].ToString() == "女")
                    {
                        radlSex.SelectedIndex = 1;
                    }
                    txtBirth.Text = dr["Birth"].ToString();

                    switch (dr["Eduation"].ToString())
                    {
                    case "大专": dropEducation.SelectedIndex = 0; break;

                    case "本科": dropEducation.SelectedIndex = 1; break;

                    case "硕士": dropEducation.SelectedIndex = 2; break;

                    case "博士": dropEducation.SelectedIndex = 3; break;

                    default: dropEducation.SelectedIndex = 0; break;
                    }
                    txtAddress.Text = dr["Address"].ToString();
                    txtCall.Text    = dr["Phone"].ToString();
                    txtEmail.Text   = dr["Email"].ToString();
                    txtZip.Text     = dr["Zip"].ToString();
                    Image1.ImageUrl = dr["head"].ToString();
                }
            }
        }
        else
        {
            Response.Redirect("Login.aspx");
        }
    }
Ejemplo n.º 7
0
 //修改购买商品数量
 protected void DataList1_ItemCommand(object source, DataListCommandEventArgs e)
 {
     if (e.CommandName == "operNum")
     {
         TextBox txtNum = e.Item.FindControl("txt_num") as TextBox;
         int     num    = Int32.Parse(txtNum.Text);
         int     cartid = Int32.Parse(DataList1.DataKeys[e.Item.ItemIndex].ToString());
         string  strsql = string.Format("update cart set Amount={0} where CartId={1}", num, cartid);
         if (DbManger.ExceSQL(strsql))
         {
             Page.ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('修改成功!')</script>", true);
             DataList1.DataBind();
         }
     }
 }
Ejemplo n.º 8
0
    protected void btnLogin_Click(object sender, EventArgs e)
    {
        #region 用户登录处理
        string check = Request.Cookies["checkcode"].Value.ToString();
        if (check == txtCheckcode.Text)
        {
            #region 使用数据访问类来完成登陆
            string        strsql = string.Format("select * from member where LoginName='{0}' and LoginPwd='{1}'", txtAccount.Text, txtPassword.Text);
            SqlDataReader dr     = DbManger.ExceRead(strsql);;
            if (dr.Read())
            {
                int userid = Int32.Parse(dr["Id"].ToString());
                Session.Timeout   = 20;
                Session["userid"] = userid;

                Session["username"] = txtAccount.Text;
                Response.Write("<script>alert('" + Session["username"].ToString() + "用户登录成功!')</script>");

                string sql = string.Format("update member set LoginTimes=LoginTimes+1 where Id={0}", userid);

                if (DbManger.ExceSQL(sql))
                {
                    Response.Write("<script>alert('更新成功!')</script>");
                    //Response.Redirect("myhome/UpdatePic.aspx");
                    Response.Redirect("Product.aspx");
                }
                else
                {
                    Response.Write("<script>alert('不成功!')</script>");
                }
            }
            else
            {
                Response.Write("<script>alert('用户名密码不正确!')</script>");
            }

            dr.Close();
            #endregion
        }
        else
        {
            Response.Write("<script>alert('验证码不正确')</script>");
        }


        #endregion
    }
Ejemplo n.º 9
0
    protected void Repeater1_ItemCommand(object source, RepeaterCommandEventArgs e)
    {
        if (e.CommandName == "oper")
        {
            string     orderid  = ((Label)e.Item.FindControl("lblOrderid")).Text;
            LinkButton btn      = ((LinkButton)e.Item.FindControl("lbtnOper"));
            string     strsql   = "";
            string     operdate = DateTime.Now.ToString();
            switch (btn.Text.Trim())
            {
            case "付款":
                strsql = string.Format("update orders set status=1,paydate='{0}' where OrderId='{1}'", operdate, orderid);
                if (DbManger.ExceSQL(strsql))
                {
                    RegisterClientScriptBlock("01", "<script>alert('已经付款,等待发货')</script>");
                }
                break;

            case "提醒发货":
                RegisterClientScriptBlock("01", "<script>alert('已经提醒卖家')</script>");
                break;

            case "确认发货":
                strsql = string.Format("update orders set status=3,ReceiptDate='{0}' where OrderId='{1}'", operdate, orderid);
                if (DbManger.ExceSQL(strsql))
                {
                    RegisterClientScriptBlock("01", "<script>alert('交易完成')</script>");
                }
                break;

            case "评价":
                Response.Redirect("evaluation.aspx?orderid=" + orderid);
                break;
            }
        }
    }
Ejemplo n.º 10
0
    protected void btnReg_Click(object sender, EventArgs e)
    {
        string loginname = txtUser.Text;
        string loginpwd  = txtPassword.Text;
        string sex       = radlSex.SelectedValue;
        string birth     = txtBirth.Text;
        string educate   = dropEducation.SelectedValue;
        string phone     = txtCall.Text;
        string address   = txtAddress.Text;
        string zip       = txtZip.Text;
        string email     = txtEmail.Text;
        string lasttime  = DateTime.Now.ToShortDateString();
        string head      = Image1.ImageUrl;

        //2.选择图片
        if (FileUpload1.HasFile)
        {
            //3.上传图片到服务器的指定文件
            string filename = DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString() + DateTime.Now.Day.ToString() + DateTime.Now.Hour.ToString() + DateTime.Now.Minute.ToString() + DateTime.Now.Second.ToString();
            FileUpload1.SaveAs(Server.MapPath("..") + "\\img\\" + filename + ".jsp");
            if (head != null && address != "")
            {
                File.Delete(Server.MapPath("..") + "\\" + head);
                head = "img/" + filename + ".jsp";
            }


            //4.将头像的地址保存到对应用户的数据表记录中
            string strsql = string.Format("update member set LoginName='{0}',LoginPwd='{1}',sex='{2}',Birth='{3}',Eduation='{4}',phone='{5}',Address='{6}',Zip='{7}',Email='{8}',LastDate='{9}',head='{10}' where id={11}", loginname, loginpwd, sex, birth, educate, phone, address, zip, email, lasttime, head, Session["userid"].ToString());
            if (DbManger.ExceSQL(strsql))
            {
                RegisterClientScriptBlock("01", "<script>alert('用户资料修改成功!')</script>");
            }
            Response.Redirect("..\\login.aspx");
        }
    }
Ejemplo n.º 11
0
    protected void btnReg_Click(object sender, EventArgs e)
    {
        #region
        //String str = "注册信息为<br/>";
        //str +="用户账号:"+ txtAccount.Text +"<br/>";
        //str += "出生年月:" + txtBirth.Text + "<br/>";
        //str += "联系地址:" + txtAddress.Text + "<br/>";
        //str += "联系电话:" + txtTel.Text + "<br/>";
        //str += "电子邮箱:" + txtEmail.Text + "<br/>";
        //str += "邮政编码:" +txtPostCode.Text + "<br/>";
        //str += "性别:" + rdolSex.SelectedValue + "<br/>";
        //str += "学历:" + ddlEdu.SelectedValue+ "<br/>";
        //String strAttention = "你关注的类型为:";
        //for (int i = 0; i < chlAttention.Items.Count;i++ )
        //{
        //    if(chlAttention.Items[i].Selected)
        //    {
        //        strAttention += chlAttention.Items[i].Text + "";
        //    }
        //}
        //str += strAttention;
        ////Response.Write(str);
        //Response.Write("<script>alert('"+str+"')</script>");
        #endregion

        #region 检测同名用户

        /**
         * //创建连接对象
         * SqlConnection con = new SqlConnection();
         * con.ConnectionString = ConfigurationManager.ConnectionStrings["ApplicationServices"].ConnectionString;
         * con.Open();
         *
         * //创建命令对象
         * SqlCommand com = new SqlCommand();
         * com.Connection = con;
         * com.CommandText = string.Format("select * from member where LoginName = '{0}'", txtAccount.Text);
         *
         * //执行命令对象,返回数据阅读器
         * SqlDataReader dr = com.ExecuteReader();
         * if (dr.HasRows)
         * {
         *  Response.Write("<script>alert('该用户已存在!')</script>");
         * }
         *
         * else
         * {
         #region 数据库连接数据库
         *  string username = txtAccount.Text;
         *  string pwd = txtPassword.Text;
         *  string sex = rdolSex.SelectedItem.ToString();
         *  string birth = txtBirth.Text;
         *  string educate = ddlEdu.SelectedItem.ToString();
         *  string address = txtAddress.Text;
         *  string tel = txtTel.Text;
         *  string zip = txtPostCode.Text;
         *  string email = txtEmail.Text;
         *  string regdate = DateTime.Now.ToShortDateString();
         *  string strSql = string.Format("insert into member values (0,'{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','',0,'')", username, pwd, sex, birth,educate,tel,address,zip,email,regdate);
         *  //创建连接对象
         *  SqlConnection cn = new SqlConnection();
         *  cn.ConnectionString = ConfigurationManager.ConnectionStrings["ApplicationServices"].ConnectionString;
         *  cn.Open();
         *
         *  //创建命令对象
         *  SqlCommand cm = new SqlCommand();
         *  cm.Connection = cn;
         *  cm.CommandText = strSql;
         *
         *  //执行命令对象,返回数据阅读器
         *  if (cm.ExecuteNonQuery() > 0)
         *  {
         *      Response.Write("<script>alert('注册成功')</script>");
         *  }
         #endregion
         * }
         #endregion
         #region dataset对象,断开式连接
         * //创建连接对象
         * SqlConnection conn = new SqlConnection();
         * conn.ConnectionString = ConfigurationManager.ConnectionStrings["ApplicationServices"].ConnectionString;
         * conn.Open();
         *
         * //创建命令对象
         * SqlCommand comm = new SqlCommand();
         * comm.Connection = conn;
         * comm.CommandText = string.Format("select * from member where LoginName = '{0}'", txtAccount.Text);
         *
         * DataSet ds= new DataSet();
         * SqlDataAdapter da = new SqlDataAdapter();
         * da.SelectCommand = comm;
         * da.Fill(ds,"member");
         * if (ds.Tables["member"].Rows.Count > 0)
         * {
         *  Response.Write("<script>alert('该用户已存在!')</script>");
         * }
         * else
         * {
         #region 数据库连接数据库
         *  string username = txtAccount.Text;
         *  string pwd = txtPassword.Text;
         *  string sex = rdolSex.SelectedItem.ToString();
         *  string birth = txtBirth.Text;
         *  string educate = ddlEdu.SelectedItem.ToString();
         *  string address = txtAddress.Text;
         *  string tel = txtTel.Text;
         *  string zip = txtPostCode.Text;
         *  string email = txtEmail.Text;
         *  string regdate = DateTime.Now.ToShortDateString();
         *  string strSql = string.Format("insert into member values (0,'{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','',0,'')", username, pwd, sex, birth, educate, tel, address, zip, email, regdate);
         *  //创建连接对象
         *  SqlConnection cn = new SqlConnection();
         *  cn.ConnectionString = ConfigurationManager.ConnectionStrings["ApplicationServices"].ConnectionString;
         *  cn.Open();
         *
         *  //创建命令对象
         *  SqlCommand cm = new SqlCommand();
         *  cm.Connection = cn;
         *  cm.CommandText = strSql;
         *
         *  //执行命令对象,返回数据阅读器
         *  if (cm.ExecuteNonQuery() > 0)
         *  {
         *      Response.Write("<script>alert('注册成功')</script>");
         *  }
         #endregion
         * }**/
        #endregion

        #region 数据操作类

        string        strsql = string.Format("select * from member where LoginName = '{0}'", txtAccount.Text);
        SqlDataReader myread = DbManger.ExceRead(strsql);
        if (myread.Read())
        {
            Response.Write("<script>alert('该用户已存在!')</script>");
        }
        else
        {
            #region 数据库连接数据库
            string username = txtAccount.Text;
            string pwd      = txtPassword.Text;
            //string sex = rdolSex.SelectedItem.ToString();
            string birth = txtBirth.Text;
            //string educate = ddlEdu.SelectedItem.ToString();
            string address = txtAddress.Text;
            string tel     = txtTel.Text;
            string zip     = txtPostCode.Text;
            string email   = txtEmail.Text;
            string regdate = DateTime.Now.ToShortDateString();
            strsql = string.Format("insert into member values (0,'{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','',0,'')", username, pwd, birth, tel, address, zip, email, regdate);


            //执行命令对象,返回数据阅读器
            if (DbManger.ExceSQL(strsql))
            {
                Response.Write("<script>alert('注册成功')</script>");
            }
            #endregion
        }
        #endregion
    }