⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 adduser.aspx.cs

📁 数据配置信息 登录数据库为sa 密码123 登录界面的用户信息:shichang 密码:sc
💻 CS
字号:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.IO;
//using UserInfoLib;

public partial class AddUser : System.Web.UI.Page
{
    public string UserLable;
    protected void Page_Load(object sender, EventArgs e)
    {
        DateTime tnow = DateTime.Now;//现在时间
        ArrayList AlYear = new ArrayList();
        int i;
        for (i = 1970; i <= 2010; i++)
            AlYear.Add(i);
        ArrayList AlMonth = new ArrayList();
        for (i = 1; i <= 12; i++)
            AlMonth.Add(i);
        if (!Page.IsPostBack)
        {
            this.DropDownList4.Attributes.Add("onchange", "checkImage();");
            this.Button2.Attributes.Add("onclick", "window.close();");
            this.FileUpload1.Attributes.Add("onchange", "FileImage();");
            string[] str = Directory.GetFiles(this.Server.MapPath("images\\headpic"), "*.gif");

            for (int k = 0; k < str.Length; k++)
            {
                this.DropDownList4.Items.Add(Path.GetFileName(str[k]));
            }
            this.DropDownList4.DataBind();

            DropDownList1.DataSource = AlYear;
            DropDownList1.DataBind();//绑定年
            //选择当前年
            DropDownList1.SelectedValue = tnow.Year.ToString();
            DropDownList2.DataSource = AlMonth;
            DropDownList2.DataBind();//绑定月
            //选择当前月
            DropDownList2.SelectedValue = tnow.Month.ToString();
            int year, month;
            year = Int32.Parse(DropDownList1.SelectedValue);
            month = Int32.Parse(DropDownList2.SelectedValue);
            BindDays(year, month);//绑定天
            //选择当前日期
            DropDownList3.SelectedValue = tnow.Day.ToString();
        }

    }
    //判断闰年
    private bool CheckLeap(int year)
    {
        if ((year % 4 == 0) && (year % 100 != 0) || (year % 400 == 0))
            return true;
        else
            return false;
    }
    //绑定每月的天数
    private void BindDays(int year, int month)
    {
        int i;
        ArrayList AlDay = new ArrayList();

        switch (month)
        {
            case 1:

            case 3:
            case 5:
            case 7:
            case 8:
            case 10:
            case 12:
                for (i = 1; i <= 31; i++)
                    AlDay.Add(i);
                break;
            case 2:
                if (CheckLeap(year))
                {
                    for (i = 1; i <= 29; i++)
                        AlDay.Add(i);
                }
                else
                {
                    for (i = 1; i <= 28; i++)
                        AlDay.Add(i);
                }
                break;
            case 4:
            case 6:
            case 9:
            case 11:
                for (i = 1; i <= 30; i++)
                    AlDay.Add(i);
                break;
        }
        DropDownList3.DataSource = AlDay;
        DropDownList3.DataBind();
    }
    //选择年
    private void DropDownList1_SelectedIndexChanged(object sender, System.EventArgs e)
    {
        int year, month;
        year = Int32.Parse(DropDownList1.SelectedValue);
        month = Int32.Parse(DropDownList2.SelectedValue);
        BindDays(year, month);
    }
    //选择月
    private void DropDownList2_SelectedIndexChanged(object sender, System.EventArgs e)
    {
        int year, month;
        year = Int32.Parse(DropDownList1.SelectedValue);
        month = Int32.Parse(DropDownList2.SelectedValue);
        BindDays(year, month);
    }
    //提交注册信息
    protected void Button1_Click(object sender, EventArgs e)
    {
       
        string UserName = this.TextBoxName.Text;
        BLL.Class1 getuser = new BLL.Class1();


        string aa = this.TextBoxName.Text;
        if (this.TextBoxName.Text.Trim() == getuser.getname(aa).Trim())
        {
           this.Response.Write("<script>alert('此用户已存在,您可以使用系统自动更改过的用户名');</script>");
           this.TextBoxName.Text += "_1";
           return;
        }
        if ((this.TextBoxName.Text.Length < 4) || (this.TextBoxName.Text.Length > 20))
        {
           this.LabelName.Visible = true;
            this.LabelName.Text = "用户名长度需大于4小于20 ";
           return;
        }
         string UserPassword = this.TextBoxPWD.Text;
         int age =Convert.ToInt32(TextBoxAge.Text);
         string QQ = this.TextBox2.Text;
         string UserAddress = this.TextBox1.Text;    
         string UserMsn =this.TextBox3.Text;
         string UserEmail = this.TextBox4.Text;
         string YserTel = this.TextBox5.Text;
         string UserImage = this.TextBox6.Text;
         string UserYeah = this.DropDownList1.Text + "-" + this.DropDownList2.Text + "-" + this.DropDownList3.Text;
        if (this.FileUpload1.FileName != null && this.FileUpload1.FileName != "")
       {
           string[] FileName = this.FileUpload1.FileName.Split('.');
           string name = FileName[FileName.Length - 1].ToLower();
           if (name == "jpg" || name == "gif" || name == "bmp" || name == "jpeg")
           {

               //上传文件
               this.FileUpload1.SaveAs(this.Server.MapPath("UPimage") + "\\" + Path.GetFileName(this.FileUpload1.PostedFile.FileName));
               UserLable = "~\\UPimage\\" + this.FileUpload1.FileName;
           }
           else
           {
               this.Response.Write("<script>alert('图片格式不对。');</script>");
               return;
           }

       }else
        {
            UserLable = "~\\images\\headpic\\" + this.DropDownList4.Text;
        }

        BLL.Class1 inserregit = new BLL.Class1();

        if (inserregit.insert(this.TextBoxName.Text, UserPassword, age, UserYeah, UserAddress, QQ, UserMsn, UserEmail, YserTel, UserImage, UserLable))
        {
            Response.Write("<script>alert('恭喜你注册成功')</script>");
            this.Response.Redirect("index.aspx");
        }


       
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -