예제 #1
0
        protected void btnEidt_Click(object sender, EventArgs e)
        {
            int id = int.Parse(Request["id"].ToString());
            UsersDataContext lq = new UsersDataContext();
            var users           = from gt in lq.Users
                                  where gt.uID == id
                                  select gt;

            foreach (Users user in users)
            {
                user.uName     = txtuName.Text;
                user.uPwd      = txtuPwd.Text;
                user.uRealName = txtuRealName.Text;
                user.uSex      = rbluSex.SelectedValue;
                user.uAge      = Convert.ToInt16(txtuAge.Text);
                for (int i = 0; i < cbluHobby.Items.Count; i++)
                {
                    if (cbluHobby.Items[i].Selected)
                    {
                        user.uHobby += cbluHobby.Items[i].Value;
                    }
                }
                user.uEmail   = txtuEmail.Text;
                user.uQQ      = txtuQQ.Text;
                user.uPwd     = txtuPhone.Text;
                user.uImage   = imguImage.ImageUrl.Substring(imguImage.ImageUrl.LastIndexOf("/") + 1);
                user.uRegTime = System.DateTime.Now;
            }
            lq.SubmitChanges();
            Response.Redirect("UsersManager.aspx");
        }
예제 #2
0
        protected void btnAdd_Click(object sender, EventArgs e)
        {
            UsersDataContext lq   = new UsersDataContext();
            Users            user = new Users();

            user.uName     = txtuName.Text;
            user.uPwd      = txtuPwd.Text;
            user.uRealName = txtuRealName.Text;
            user.uSex      = rbluSex.SelectedValue;
            user.uAge      = Convert.ToInt16(txtuAge.Text);
            for (int i = 0; i < cbluHobby.Items.Count; i++)
            {
                if (cbluHobby.Items[i].Selected)
                {
                    user.uHobby += cbluHobby.Items[i].Value;
                }
            }
            user.uEmail   = txtuEmail.Text;
            user.uQQ      = txtuQQ.Text;
            user.uPwd     = txtuPhone.Text;
            user.uImage   = imguImage.ImageUrl.Substring(imguImage.ImageUrl.LastIndexOf("/") + 1);
            user.uRegTime = System.DateTime.Now;
            lq.Users.InsertOnSubmit(user);
            lq.SubmitChanges();
            Response.Redirect("UserManager.aspx");
        }
예제 #3
0
        /// <summary>
        /// 页面加载时将Users表中的数据显示在GridView控件中
        /// </summary>
        protected void Page_Load(object sender, EventArgs e)
        {
            UsersDataContext lq = new UsersDataContext();
            var mylq            = from gt in lq.Users select gt;

            gvUsers.DataSource = mylq;
            gvUsers.DataBind();
        }
예제 #4
0
        protected void gvUsers_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            UsersDataContext lq = new UsersDataContext();
            var users           = from gt in lq.Users
                                  where gt.uID == Convert.ToInt32(gvUsers.DataKeys[e.RowIndex].Value)
                                  select gt;

            foreach (Users user in users)
            {
                lq.Users.DeleteOnSubmit(user);
            }
            lq.SubmitChanges();
            Response.Redirect("UsersManager.aspx");
        }
예제 #5
0
 protected void Page_Load(object sender, EventArgs e)
 {
     if (Request["id"] == null)                  //判断是否有查询字符串id传递到本页
     {
         Response.Redirect("UsersManager.aspx"); //跳转到会员管理页
     }
     else
     {
         int id = int.Parse(Request["id"].ToString());
         if (!IsPostBack)
         {
             UsersDataContext lq = new UsersDataContext();
             var users           = from gt in lq.Users
                                   where gt.uID == id
                                   select gt;
             foreach (Users user in users)
             {
                 txtuName.Text     = user.uName;
                 txtuPwd.Text      = user.uPwd;
                 txtuRealName.Text = user.uRealName;
                 if (user.uSex == "女")
                 {
                     rbluSex.Items[1].Selected = true;
                 }
                 txtuAge.Text = user.uAge.ToString();
                 string[] hobbys = user.uHobby.Split(',');           //分割字符串到字符串数组
                 for (int i = 0; i < cbluHobby.Items.Count; i++)
                 {
                     for (int j = 0; j < hobbys.Length; j++)
                     {
                         if (cbluHobby.Items[i].Value == hobbys[j])
                         {
                             cbluHobby.Items[i].Selected = true;
                             break;
                         }
                     }
                 }
                 txtuEmail.Text          = user.uEmail;
                 txtuQQ.Text             = user.uQQ;
                 txtuPhone.Text          = user.uPhone;
                 ddluImage.SelectedValue = user.uImage;
                 imguImage.ImageUrl      = imguImage.ImageUrl.Substring(0, imguImage.ImageUrl.LastIndexOf("/") + 1) + user.uImage;
             }
         }
     }
 }