insertcus.aspx.cs

来自「大中型酒店管理系统」· CS 代码 · 共 91 行

CS
91
字号
using System;
using System.Data;
using System.Data.SqlClient;
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;

public partial class insertcus : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            SqlConnection conn = db.createconn();
            conn.Open();
            SqlCommand cmd1 = new SqlCommand("select * from shopmaster",conn);
            SqlDataReader dr = cmd1.ExecuteReader(); 
            this.qujian.DataSource = dr;
            this.qujian.DataTextField = "s_lei";
            this.qujian.DataValueField = "s_id";
            this.qujian.DataBind();
            dr.Close();
            SqlCommand cmd2 = new SqlCommand("select * from lei",conn);
            SqlDataReader dr1 = cmd2.ExecuteReader();
            this.hao.DataSource = dr1;
            this.hao.DataTextField = "lei";
            this.hao.DataValueField = "id";
            this.hao.DataBind();
            dr1.Close();
        }
     
        
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        SqlConnection conn = db.createconn();
        conn.Open();
        string login = txtlogin.Text;
        string pwd = txtpwd.Text;
        string name = txtname.Text;
        string qj = qujian.SelectedItem.Text;
        string lx = hao.SelectedItem.Text;
        string jj = txtjj.Text;
        string pz = txtpz.Text;
        string fw = txtzongzhi.Text;
        string ci = txtci.Text;

        string ren = txtren.Text;
        string address = txtadd.Text;
        string tel = txttel.Text;
        string phone = txtphone.Text;
        string mail = txtmail.Text;
        if(login == "")
        {
            Response.Write("<script language='javascript'>alert('用户名不能为空');history.back(-1);</script>");
        }
        else
        {
            string fullFileName = this.File1.PostedFile.FileName;
            string fileName = fullFileName.Substring(fullFileName.LastIndexOf("\\")+1);
            string type = fullFileName.Substring(fullFileName.LastIndexOf(".")+1);
            if (fileName == "")
            {
                SqlCommand cmd = new SqlCommand("insert into user1(u_log,u_pwd,u_name,u_qu,u_lei,u_introduce,u_ping,u_zong,u_guang,u_ren,u_address,u_tel,u_phone,u_email)" + "values('" + login + "','" + pwd + "','" + name + "','" + qj + "','" + lx + "','" + jj + "','" + pz + "','" +fw+ "','" + ci + "','" + ren + "','" + address + "','" + tel + "','" + phone + "','" + mail + "')", conn);
                cmd.ExecuteNonQuery();
                Response.Redirect("insertcus.aspx");
            }
            else
            {
                if (type == "jpg" || type == "bmp" || type == "gif")
                {
                    this.File1.PostedFile.SaveAs(Server.MapPath("logo") + "\\" + fileName);
                    SqlCommand cmd = new SqlCommand("insert into user1(u_log,u_pwd,u_name,u_qu,u_lei,u_logo,u_introduce,u_ping,u_zong,u_guang,u_ren,u_address,u_tel,u_phone,u_email)" + "values('" + login + "','" + pwd + "','" + name + "','" + qj + "','" + lx + "','" + fileName + "','" + jj + "','" + pz + "','" + fw + "','" + ci + "','" + ren + "','" + address + "','" + tel + "','" + phone + "','" + mail + "')", conn);
                    cmd.ExecuteNonQuery();
                    Response.Redirect("insertcus.aspx");
                }
                else
                {
                    Response.Write("<script language='javascript'>alert('图片格式不对');</script>");
                }
            }
        }

    }
}

⌨️ 快捷键说明

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