Example #1
0
        //增加、删除地址
        protected void Repeater1_ItemCommand(object source, RepeaterCommandEventArgs e)
        {
            DataTable dt        = Session["UserTable"] as DataTable;
            int       i         = Convert.ToInt32(dt.Rows[0]["UserRecID"]);
            string    AdressNum = "select AddressName from Address where UserRecID=" + i;
            DataSet   AdressN   = DataBase.RunDataSet(AdressNum);

            if (e.CommandName.Equals("del"))
            {
                if (AdressN.Tables[0].Rows.Count > 1)
                {
                    string mycon = "delete from Address where AddressName='" + e.CommandArgument + "'";
                    int    k     = DataBase.ExecuteNonQuery(mycon);
                    if (k > 0)
                    {
                        MessageTxt.Value = "删除成功!";
                    }
                    Response.Redirect("UserCenter.aspx");
                }
                else
                {
                    MessageTxt.Value = "必须要有一个地址!删除失败!";
                }
            }
            if (e.CommandName == "insert")
            {
                TextBox tbx = (TextBox)e.Item.FindControl("UserAdressAdd");
                if (tbx.Text != "")
                {
                    if (AdressN.Tables[0].Rows.Count < 3)
                    {
                        for (int k = 0; k < AdressN.Tables[0].Rows.Count; k++)
                        {
                            if (tbx.Text != AdressN.Tables[0].Rows[k]["AddressName"].ToString())
                            {
                                string    sql        = "select * from Address where 0=1";
                                DataSet   AdressForm = DataBase.RunDataSet(sql);
                                DataTable AdresTable = new DataTable();
                                AdresTable = AdressForm.Tables[0];
                                DataRow dr = AdresTable.NewRow();
                                dr["AddressRecID"]     = 0;
                                dr["UserRecID"]        = i;
                                dr["AddressName"]      = tbx.Text;
                                dr["IsUsuallyAddress"] = 1;
                                AdresTable.Rows.Add(dr);
                                int p = DataBase.update("Address", "AddressRecID", AdresTable);
                                if (p > 0)
                                {
                                    MessageTxt.Value = "增添成功!";
                                    tbx.Text         = "";
                                }
                                Response.Redirect("UserCenter.aspx");
                            }
                            else
                            {
                                MessageTxt.Value = "此地址已存在!请重新输入!";
                                tbx.Text         = "";
                            }
                        }
                    }
                    else
                    {
                        MessageTxt.Value = "地址不能超过三个!添加失败!";
                        tbx.Text         = "";
                    }
                }
                else
                {
                    MessageTxt.Value = "不能增添地址,请重新输入地址!";
                }
            }
        }