using System; using System.Collections; using System.Configuration; using System.Data; using System.Linq; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.HtmlControls; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Xml.Linq; using System.Data.SqlClient; using System.IO; using System.Collections.Generic; public partial class SysAdmin_NewGoods : System.Web.UI.Page { public static string Mp3; public static string Pdf; private static SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["con"].ConnectionString.ToString()); public static string soft; public static string BookName; public static List FileList = new List(); protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { #region DDL BindDDl(); DDLTypeSmall.Items.Add(new ListItem("请选择", "0")); DDLTypeBig.Items.Add(new ListItem("请选择", "0")); DDLTypeSmall.SelectedIndex = DDLTypeSmall.Items.IndexOf(DDLTypeSmall.Items.FindByValue("0")); DDLTypeBig.SelectedIndex = DDLTypeBig.Items.IndexOf(DDLTypeBig.Items.FindByValue("0")); #endregion } } #region DDL public void BindDDl() { string TypeBig = "select * from v3_m_category where ParentId =0"; DataSet ds = new common().ExcuteReader(TypeBig); DDLTypeBig.DataSource = ds.Tables[0].DefaultView; DDLTypeBig.DataTextField = "name_cn"; DDLTypeBig.DataValueField = "ID"; DDLTypeBig.DataBind(); } protected void DDLTypeBig_SelectedIndexChanged(object sender, EventArgs e) { if (DDLTypeBig.SelectedItem.Value != "0") { string TypeSmall = "select * from v3_m_category where ParentId= " + this.DDLTypeBig.SelectedItem.Value; DataSet ds = new common().ExcuteReader(TypeSmall); if (ds.Tables[0].Rows.Count != 0) { DDLTypeSmall.DataSource = ds.Tables[0].DefaultView; DDLTypeSmall.DataTextField = "name_cn"; DDLTypeSmall.DataValueField = "ID"; DDLTypeSmall.DataBind(); } else { DDLTypeSmall.Items.Clear(); DDLTypeSmall.Items.Add(new ListItem("此项暂无,请在类别中添加", "0")); } } else { DDLTypeSmall.Items.Clear(); DDLTypeSmall.Items.Add(new ListItem("请选择", "0")); } } #endregion #region MP3 protected void ImageButton1_Click(object sender, ImageClickEventArgs e) { string strFullName = FileUpload1.PostedFile.FileName; if (strFullName != "") { string strName = Path.GetFileName(strFullName);//文件名 string strEx = Path.GetExtension(strFullName);//文件扩展名 string strType = FileUpload1.PostedFile.ContentType; string strSize = (FileUpload1.PostedFile.ContentLength / 1024.0).ToString("n2"); string strTime = DateTime.Now.ToString("HHmmss"); if (strEx.ToLower() == ".mp3") { double size = double.Parse(strSize); if (size <= 10000) { string sqlstring = "select count(*) from v3_merchandises where url_mp3 ='" + strName + "'"; SqlCommand excom = new SqlCommand(sqlstring, con); excom.Connection.Open(); int hasrow = Convert.ToInt32(excom.ExecuteScalar()); excom.Connection.Close(); if (hasrow > 0) { Methods1.Methods1.Alert(this, "上传失败,数据库中已有一个同名项,请重命名后重新上传!!!"); } else { if (File.Exists(Server.MapPath("~/SysAdmin/Resource/MP3/") + strName)) { Methods1.Methods1.Alert(this, "上传失败,文件夹中已有一个同名项,请重命名后重新上传!"); } else { string str = Server.MapPath("~/SysAdmin/Resource/MP3/") + strName; FileUpload1.PostedFile.SaveAs(str); Mp3 = strName; Methods1.Methods1.Alert(this, "上传成功!"); } } } else { Methods1.Methods1.Alert(this, "上传的文档大小不能大于10MB!"); } } else { Methods1.Methods1.Alert(this, "只能够上传mp3格式的音频文件!"); } } else { Methods1.Methods1.Alert(this, "上传失败!位置错误!请联系管理员"); } } #endregion #region Soft protected void ImageButton2_Click(object sender, ImageClickEventArgs e) { string strFullName = FileUpload3.PostedFile.FileName; if (strFullName != "") { string strName = Path.GetFileName(strFullName);//文件名 string strEx = Path.GetExtension(strFullName);//文件扩展名 string strType = FileUpload3.PostedFile.ContentType; string strSize = (FileUpload3.PostedFile.ContentLength / 1024.0).ToString("n2"); string strTime = DateTime.Now.ToString("HHmmss"); if (strEx.ToLower() == ".rar" || strEx.ToLower() == ".zip") { double size = double.Parse(strSize); if (size <= 10000) { string sqlstring = "select count(*) from v3_merchandises where url_software ='" + strName + "'"; SqlCommand excom = new SqlCommand(sqlstring, con); excom.Connection.Open(); int hasrow = Convert.ToInt32(excom.ExecuteScalar()); excom.Connection.Close(); if (hasrow > 0) { Methods1.Methods1.Alert(this, "上传失败,数据库中已有一个同名项,请重命名后重新上传!!!"); } else { if (File.Exists(Server.MapPath("~/SysAdmin/Resource/Soft/") + strName)) { Methods1.Methods1.Alert(this, "上传失败,文件夹中已有一个同名项,请重新命名后上传!!"); } else { string str = Server.MapPath("~/SysAdmin/Resource/Soft/") + strName; FileUpload3.PostedFile.SaveAs(str); soft = strName; Methods1.Methods1.Alert(this, "上传成功!"); } } } else { Methods1.Methods1.Alert(this, "上传的文档大小不能大于10MB!"); } } else { Methods1.Methods1.Alert(this, "只能够上传RAR,zip格式的压缩文件!"); } } else { Methods1.Methods1.Alert(this, "上传失败!位置错误!请联系管理员"); } } #endregion #region PDF protected void ImageButton4_Click(object sender, ImageClickEventArgs e) { string strFullName = FileUpload2.PostedFile.FileName; if (strFullName != "") { string strName = Path.GetFileName(strFullName);//文件名 string strEx = Path.GetExtension(strFullName);//文件扩展名 string strType = FileUpload2.PostedFile.ContentType; string strSize = (FileUpload2.PostedFile.ContentLength / 1024.0).ToString("n2"); string strTime = DateTime.Now.ToString("HHmmss"); if (strEx.ToLower() == ".pdf") { double size = double.Parse(strSize); if (size <= 20000) { string sqlstring = "select count(*) from v3_merchandises where url_pdf ='" + strName + "'"; SqlCommand excom = new SqlCommand(sqlstring, con); excom.Connection.Open(); int hasrow = Convert.ToInt32(excom.ExecuteScalar()); excom.Connection.Close(); if (hasrow > 0) { Methods1.Methods1.Alert(this, "上传失败,数据库中已有一个同名项,请重命名后重新上传!!!"); } else { if (File.Exists(Server.MapPath("~/SysAdmin/Resource/PDF/") + strName)) { Methods1.Methods1.Alert(this, "上传失败,文件夹中已有一个同名项,请重新命名后上传!!"); } else { string str = Server.MapPath("~/SysAdmin/Resource/PDF/") + strName; FileUpload2.PostedFile.SaveAs(str); Pdf = strName; Methods1.Methods1.Alert(this, "上传成功!"); } } } else { Methods1.Methods1.Alert(this, "上传的文档大小不能大于20MB!"); } } else { Methods1.Methods1.Alert(this, "只能够上传pdf格式的文档文件!"); } } else { Methods1.Methods1.Alert(this, "上传失败!位置错误!请联系管理员"); } } #endregion #region 首页图地址 /// /// 首页图地址 /// /// /// protected void ImageButton3_Click(object sender, ImageClickEventArgs e) { string FileName = FileUpload4.PostedFile.FileName; if (FileName != "") { string strName = Path.GetFileName(FileName);//文件名 string strEx = Path.GetExtension(FileName);//文件扩展名 string strType = FileUpload4.PostedFile.ContentType; string strSize = (FileUpload4.PostedFile.ContentLength / 1024.0).ToString("n2"); string strTime = DateTime.Now.ToString("HHmmss"); if (strEx.ToLower() == ".jpg") { double size = double.Parse(strSize); if (size <= 5000) { string sqlstring = "select count(*) from v3_Pic_path where FileName ='" + strName + "'"; SqlCommand excom = new SqlCommand(sqlstring, con); excom.Connection.Open(); int hasrow = Convert.ToInt32(excom.ExecuteScalar()); excom.Connection.Close(); if (hasrow > 0) { Methods1.Methods1.Alert(this, "上传失败,数据库中已有一个同名项,请重命名后重新上传!!!"); BookName = null; } else { if (File.Exists( Server.MapPath("~/SysAdmin/images/Goods/") + strName)) { Methods1.Methods1.Alert(this, "上传失败,文件夹中已有一个同名项,请重命名后重新上传!"); BookName = null; } else { string str = Server.MapPath("~/SysAdmin/images/Goods/") + strName; FileUpload4.PostedFile.SaveAs(str); string str1 = @"E:\cinowoftp\LocalUser\webs\chinese\SysAdmin\images\Goods\"+ strName; FileUpload4.PostedFile.SaveAs(str1); BookName = strName; Methods1.Methods1.Alert(this, "上传成功!"); } } } else { Methods1.Methods1.Alert(this, "上传的文档大小不能大于5MB!"); BookName = null; } } else { Methods1.Methods1.Alert(this, "只能够上传jpg格式的文档文件!"); BookName = null; } } else { Methods1.Methods1.Alert(this, "上传失败!位置错误!请联系管理员"); BookName = null; } } #endregion #region 上传列表图 /// /// 上传列表图 /// /// /// protected void ImageButton5_Click1(object sender, ImageClickEventArgs e) { FileList.Clear(); HttpFileCollection files = HttpContext.Current.Request.Files; System.Text.StringBuilder strMsg = new System.Text.StringBuilder(); try { int count = 0; for (int iFile = 0; iFile < files.Count; iFile++) { HttpPostedFile postedFile = files[iFile]; string fileName, fileExtension; fileName = System.IO.Path.GetFileName(postedFile.FileName); if (fileName != "") { if (!File.Exists("images/Goods/" + fileName)) { fileExtension = System.IO.Path.GetExtension(fileName); FileList.Insert(count, fileName); count++; postedFile.SaveAs(System.Web.HttpContext.Current.Request.MapPath("images/Goods/") + fileName); //string str1 = "E:\cinowoftp\LocalUser\webs\chinese\SysAdmin\images\"+ fileName; //FileUpload4.PostedFile.SaveAs(str1); postedFile.SaveAs(@"E:\cinowoftp\LocalUser\webs\chinese\SysAdmin\images\Goods\" + fileName); Methods1.Methods1.Alert(this, "上传成功!"); } else { Methods1.Methods1.Alert(this, "文件夹中已有重名项,请更名后重新上传!"); } } } } catch (System.Exception Ex) { } #region 循环遍历listFile里面的数据 //for (int str = 0; str < FileList.Count; str++) //{ // //Methods1.Methods1.Alert(this, FileList[str].ToString()); //} #endregion } #endregion protected void ImageButton6_Click(object sender, ImageClickEventArgs e) { int pid = (GetGoodsId() + 1); string sqlstr = " insert into v3_merchandises (PID,CID,trade_name_cn,trade_name_en,market_price_rmb,market_price_usd,vip_price_rmb,vip_price_usd,summary_cn,summary_en," + "description_cn,description_en,url_software,url_pdf,url_mp3,compositor,comp_en,publish,editdate,EID,See_count,Buy_count,Spec," + "MULU,Chubanshe,Chubanshijian,ISBN) values(" + pid + "," + this.DDLTypeSmall.SelectedItem.Value + ",'" + this.txtnamecn.Text.Trim() + "','" + this.txtNameEn.Text.Trim() + "'," + this.txtmarketrmb.Text.Trim() + "," + this.txtmarketus.Text.Trim() + "," + this.txtviprmb.Text.Trim() + "," + this.txtvipus.Text.Trim() + "," + "'',' ','" + this.txtdesccn.Text.Trim() + "','" + this.txtdescen.Text.Trim() + "','" + soft + "','" + Pdf + "','" + Mp3 + "'," + "0,0,'true','" + DateTime.Now.ToString() + "',0,0,0,'" + this.txtguige.Text.Trim() + "','" + this.txtmulu.Text.Trim() + "','" + this.txtchubanshe.Text.Trim() + "','" + this.txtchubanshijian.Text.Trim() + "','" + this.txtisbn.Text.Trim() + "')"; string insertPic = "insert into v3_Pic_Path(pid,FileName,title,Show) values('" + pid + "','" + BookName + "','',1)"; if (new common().ExcuteNoneQuery(insertPic, null)) { for (int str = 0; str < FileList.Count; str++) { string insertPic2 = "insert into v3_Pic_Path(pid,FileName,title,Show) values('" + pid + "','" + FileList[str].ToString() + "','',0)"; if (new common().ExcuteNoneQuery(insertPic2, null)) { } } if (new common().ExcuteNoneQuery(sqlstr, null)) { Methods1.Methods1.Alert(this, "添加成功!!"); } } } public int GetGoodsId() { string sqlstr = "select top 1 pid from v3_merchandises order by PID desc"; try { int i = Convert.ToInt32(new common().ExcuteReader(sqlstr).Tables[0].Rows[0][0].ToString()); if (i > 1) { return i; } else { return 1; } } catch { return 1; } } protected void ImageButton7_Click(object sender, ImageClickEventArgs e) { Response.Redirect("goodslist.aspx"); } protected void ImageButton8_Click(object sender, ImageClickEventArgs e) { foreach (System.Web.UI.Control ctr in form1.Controls) { if (ctr.GetType().ToString().ToLower() == "system.web.ui.webcontrols.textbox") { ((TextBox)ctr).Text = null; } } } }