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

📄 adduser.aspx.cs

📁 三层班级留言本源码 用VS2005写的,对于其中没有太多的技术含量, 但是还是蛮有参考价值的. 后台数据库的读写采用三层架构,没有专业的后台管理程序,所有操作都是同一个页面上进行. 如果
💻 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
{
    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)
    {
        UserInfo user = new UserInfo();
        user.UserName = this.TextBoxName.Text;
        if (this.TextBoxName.Text == user.SeleUserName())
        {
            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;
        }
        user.UserPassword = this.TextBoxPWD.Text;
        if (this.TextBoxAge.Text == null || this.TextBoxAge.Text == "")
        {
            user.UserAge = 0;
        }
        else
        {
            user.UserAge = int.Parse(this.TextBoxAge.Text);
        }
        if (this.TextBox2.Text == null || this.TextBox2.Text == "" )
        {
            user.UserQQ = 0;
        }
        else
        { 
            user.UserQQ = int.Parse(this.TextBox2.Text);
        }
        if (this.TextBox1.Text == null)
        {
            user.UserAddress = null;
        }
        else
        {
            user.UserAddress = this.TextBox1.Text;
        }
        if (this.TextBox3.Text == null)
        {
            user.UserMsn = null;
        }
        else
        {
            user.UserMsn = this.TextBox3.Text;
        }
        if (this.TextBox4.Text == null)
            user.UserEmail = null;
        else
            user.UserEmail = this.TextBox4.Text;
        if (this.TextBox5.Text == null)
            TextBox5.Text = null;
        else
            user.YserTel = this.TextBox5.Text;
        if (this.TextBox6.Text == null)
            TextBox6.Text = null;
        else
            user.UserImage = this.TextBox6.Text;

        user.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));
                user.UserLable = "~\\UPimage\\" + this.FileUpload1.FileName;
            }
            else
            {
                this.Response.Write("<script>alert('图片格式不对。');</script>");
                return;
            }
            
        }
        else
        {
            user.UserLable = "~\\images\\headpic\\" + this.DropDownList4.Text;
        }
        
        user.User();
        this.Response.Redirect("index.aspx");
    }
}

⌨️ 快捷键说明

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