📄 addpinmin.aspx.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.Data.SqlClient;
public partial class addpinmin : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
order bindleibie = new order();
this.dropleibie.DataSource = bindleibie.leibieBind();
dropleibie.DataTextField = "leibie_name";
this.dropleibie.DataBind();
order supply = new order();
dropsupply.DataSource = supply.selectsupply();
dropsupply.DataTextField = "supply_Name";
dropsupply.DataBind();
supply.selectsupply().Dispose();
dropsupply.Items.Insert(0, new ListItem("无", "无"));
}
}
protected void txtleibie_TextChanged(object sender, EventArgs e)
{
}
protected void txtpinmin_TextChanged(object sender, EventArgs e)
{
if (txtpinmin.Text.Trim() != "")
{
order checkpinmin = new order();
int i = checkpinmin.pinmincheck(txtpinmin.Text.Trim());
if (i == 0)
{
this.add.Visible = false;
this.lblcheck.Text = "品名存在";
}
else
{
this.add.Visible = true;
this.lblcheck.Text = "品名可以添加";
}
}
else
{
this.add.Visible = false;
this.lblcheck.Text = "";
}
}
protected void dropnature_SelectedIndexChanged(object sender, EventArgs e)
{
if (this.dropnature.SelectedItem.Text == "配送")
{
this.dropsupply.Visible = true;
}
else
{
this.dropsupply.Visible = false;
}
}
public static string GetUniqueString()//定义时间格试,以后改图片名用
{
//得到的文件名形如:20050922101010
return DateTime.Now.ToString("yyyyMMddhhmmss");
}
public void upimg()
{
string strname = File1.PostedFile.FileName;//获取上传文件服务器上的路径
try
{
if (strname != "")//判断是否为空
{
string filename = strname.Substring(strname.LastIndexOf("\\") + 1);//获取文件名
string fullname = strname.Substring(strname.LastIndexOf("."));
string filenewname = GetUniqueString() + fullname;//上传后图片命名
string type = filename.Substring(filename.LastIndexOf(".") + 1);//获取文件后缀
if (type == "gif" || type == "jpg" || type == "png" || type == "jpeg")//判断图片类型
{
if (File1.PostedFile.ContentLength < 1024 * 1024)//判断图片大小
{
File1.PostedFile.SaveAs(Server.MapPath("picture") + "\\" + filenewname);//保存图片
this.Image1.ImageUrl = "picture/" + filenewname;//显示图片
// Response.Write(dt);
//Response.Write(filenewname);
//插入数据库
string strpath = "picture/" + filenewname;
order add = new order();
add.addpinmin(txtpinmin.Text, dropsupply.SelectedItem.Text, txtGG.Text, dropleibie.SelectedItem.Text, dropnature.SelectedItem.Text, txtprice.Text, txtsuoxie.Text, strpath);
this.txtpinmin.Text = "";
this.txtprice.Text = "";
this.txtsuoxie.Text = "";
this.txtGG.Text = "";
this.add.Visible = false;
}
else
{
Response.Write("<script>alert('图片太大(350kb以下),请修改后在上传!');</script>");
}
//Response.Write(fullname);
}
else
{
Response.Write("<script>alert('类型错误!请选择gif/jpg/png/jpeg格试的图片!');</script>");
}
}
else
{
Response.Write("<script>alert('请选择要上传的图片!');</script>");
}
}
catch (Exception ex)
{
Response.Write("<script>alert('无法预料的错误');</script>" + ex.Message);
}
}
protected void btnenter_Click(object sender, EventArgs e)
{
if (this.txtpinmin.Text != "" && this.txtGG.Text != "" && txtsuoxie.Text != "")
{
upimg();
}
else
{
Response.Redirect("<script>alert('请填写完整!')</script>");
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -