cusadd.aspx.cs

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

CS
84
字号
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 cusadd : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            SqlConnection conn = db.createconn();
            conn.Open();
            SqlCommand cmd = new SqlCommand("select * from shopmaster", conn);
            SqlDataReader dr = cmd.ExecuteReader();
            this.DropDownList1.DataSource = dr;
            this.DropDownList1.DataTextField = "s_lei";
            this.DropDownList1.DataValueField = "s_id";
            this.DropDownList1.DataBind();
            dr.Close();
        }
    }
    protected void btntijiao_Click(object sender, EventArgs e)
    { 
        SqlConnection conn = db.createconn();
        conn.Open();
        string cname = txtCm.Text;
        string cq = DropDownList1.SelectedValue;
        string cjie = txtCjie.Text;
        string pjie = txtPjie.Text;
        string ren = txtRen.Text;
        string ctel = txtCtel.Text;
        string cfax = txtCfax.Text;
        string cpho = txtCphone.Text;
        string cmail = txtCmail.Text;
        string curl = txtCurl.Text;
        if (cname == "")
        {
            Response.Write("<script>alert('厂家名不能为空!');history.go(-1);</script>");
        }
        else
        {
            string fullFileName = this.File2.PostedFile.FileName;
            string fileName = fullFileName.Substring(fullFileName.LastIndexOf("\\") + 1);
            string type = fullFileName.Substring(fullFileName.LastIndexOf(".") + 1);

            if (fileName == "")
            {
                SqlCommand cmd = new SqlCommand("insert into custom(s_id,name,introduce,product,ren,phone,tel,fax,email,url)" + "values('" + cq + "','" + cname + "','" + cjie + "','" + pjie + "','" + ren + "','" + ctel + "','" + cfax + "','" + cfax + "','" + cmail + "','" + curl + "')", conn);
                cmd.ExecuteNonQuery();
                Response.Redirect("default.aspx");
            }
            else
            {
                if (type == "jpg" || type == "bmp" || type == "gif")
                {
                    this.File2.PostedFile.SaveAs(Server.MapPath("logo") + "\\" + fileName);



                    SqlCommand cmd = new SqlCommand("insert into custom(s_id,name,pic,introduce,product,ren,phone,tel,fax,email,url)" + "values('" + cq + "','" + cname + "','" + fileName + "','" + cjie + "','" + pjie + "','" + ren + "','" + ctel + "','" + cfax + "','" + cfax + "','" + cmail + "','" + curl + "')", conn);



                    cmd.ExecuteNonQuery();

                    Response.Redirect("default.aspx");
                }
                else
                {
                    Response.Write("<script language='javascript'>alert('图片格式不对');</script>");
                }
            }
        }
    }
}

⌨️ 快捷键说明

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