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.IO; using System.Collections.Generic; using System.Data.SqlClient; public partial class SysAdmin_UpdateGoods : System.Web.UI.Page { public static List FileList = new List(); public static string Mp3; public static string Pdf; public static string soft; public static string jpg; public static string BookName; public static string pid; public DataSet ds = new DataSet(); SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["con"].ConnectionString.ToString()); /// /// /// /// /// protected void Page_Load(object sender, EventArgs e) { pid = Request.QueryString["pid"].ToString();//获取商品编号 c if (!IsPostBack) { BindPic(); #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 BindList(); } } public void BindList() { #region 绑定数据 string select = "select * from v3_merchandises as tab1 left join v3_m_category as tab2 on tab1.cid =tab2.id left join v3_Pic_path as tab3 on tab1.pid = tab3.pid where tab3.show<>0 and tab1.pid =" + pid; ds = new common().ExcuteReader(select); this.txtnamecn.Text = ds.Tables[0].Rows[0][3].ToString(); this.txtNameEn.Text = ds.Tables[0].Rows[0][4].ToString(); this.txtguige.Text = ds.Tables[0].Rows[0][23].ToString(); this.txtzhekoujia.Text = ds.Tables[0].Rows[0][7].ToString(); this.txtmarketrmb.Text = ds.Tables[0].Rows[0][5].ToString(); this.txtmarketus.Text = ds.Tables[0].Rows[0][6].ToString(); this.txtviprmb.Text = ds.Tables[0].Rows[0][7].ToString(); this.txtvipus.Text = ds.Tables[0].Rows[0][8].ToString(); string parentid = new common().ExcuteReader("select ParentId from v3_m_category where id = " + ds.Tables[0].Rows[0][2].ToString().Trim()).Tables[0].Rows[0][0].ToString().Trim(); if (!IsPostBack) { this.DDLTypeBig.SelectedIndex = this.DDLTypeBig.Items.IndexOf(DDLTypeBig.Items.FindByValue(parentid)); string TypeSmall = "select * from v3_m_category where ParentId= " + this.DDLTypeBig.SelectedItem.Value; DataSet dsList = new common().ExcuteReader(TypeSmall); if (dsList.Tables[0].Rows.Count != 0) { DDLTypeSmall.DataSource = dsList.Tables[0].DefaultView; DDLTypeSmall.DataTextField = "name_cn"; DDLTypeSmall.DataValueField = "ID"; DDLTypeSmall.DataBind(); this.DDLTypeSmall.SelectedIndex = this.DDLTypeSmall.Items.IndexOf(DDLTypeSmall.Items.FindByValue(ds.Tables[0].Rows[0][2].ToString().Trim())); } else { DDLTypeSmall.Items.Clear(); DDLTypeSmall.Items.Add(new ListItem("此项暂无,请在类别中添加", "0")); } } this.txtchubanshe.Text = ds.Tables[0].Rows[0][25].ToString(); this.txtchubanshijian.Text = ds.Tables[0].Rows[0][26].ToString(); this.txtisbn.Text = ds.Tables[0].Rows[0][27].ToString(); this.txtmulu.Value = ds.Tables[0].Rows[0][24].ToString(); this.txtdesccn.Value = ds.Tables[0].Rows[0][11].ToString(); this.txtdescen.Value = ds.Tables[0].Rows[0][12].ToString(); Mp3 = ds.Tables[0].Rows[0][15].ToString(); soft = ds.Tables[0].Rows[0][13].ToString(); Pdf = ds.Tables[0].Rows[0][14].ToString(); jpg = ds.Tables[0].Rows[0][40].ToString(); #endregion } #region DDL public void BindDDl() { string TypeBig = "select * from v3_m_category where ParentId =0 and visiable = 1 or visiable =3"; 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 绑定列表图片 以及datalist的事件 public void BindPic() { string sqlstr = "select * from v3_Pic_path where pid =" + Request.QueryString["pid"].ToString() + " and show<>1"; this.DataList1.DataSource = new common().ExcuteReader(sqlstr); this.DataList1.DataBind(); } protected void DataList1_ItemCommand(object source, DataListCommandEventArgs e) { if (e.CommandName == "del") { string sqlstr = "delete from v3_Pic_path where id = " + e.CommandArgument; if (new common().ExcuteNoneQuery(sqlstr, null)) { Methods1.Methods1.Alert(this, "删除成功!!"); BindPic(); } else { Methods1.Methods1.Alert(this, "删除失败!!"); BindPic(); } } } #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("~/SysAdmin/Resource/MP3/" + strName)) { Methods1.Methods1.Alert(this, "上传失败,文件夹中已有一个同名项,请重命名后重新上传!"); } else { if (File.Exists(Server.MapPath("Resource/MP3/" + Mp3))) { File.Delete(Server.MapPath("Resource/MP3/" + Mp3)); } string str = Server.MapPath(@"~/SysAdmin/Resource/MP3/") + strName; FileUpload1.PostedFile.SaveAs(str); Mp3 = strName; string sqlstr = " update v3_merchandises set url_mp3 = '"+Mp3+"' where pid ='"+ pid +"'"; if (new common().ExcuteNoneQuery(sqlstr, null)) { Methods1.Methods1.Alert(this, "上传成功!"); } else { Methods1.Methods1.Alert(this, "上传失败!"); } BindList(); } } } 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("Resource/Soft/" + soft))) { File.Delete(Server.MapPath("Resource/Soft/" + soft)); } string str = Server.MapPath("~/SysAdmin/Resource/Soft/") + strName; FileUpload3.PostedFile.SaveAs(str); soft = strName; string sqlstr = " update v3_merchandises set url_software = '" + soft + "' where pid ='" + pid + "'"; if (new common().ExcuteNoneQuery(sqlstr,null)) { Methods1.Methods1.Alert(this, "上传成功!"); } else { Methods1.Methods1.Alert(this, "上传失败 !"); } BindList(); } } 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("Resource/PDF/" + Pdf))) { File.Delete(Server.MapPath("Resource/PDF/" + Pdf)); } string str = Server.MapPath("~/SysAdmin/Resource/PDF/") + strName; FileUpload2.PostedFile.SaveAs(str); Pdf = strName; string sqlstr = " update v3_merchandises set url_pdf = '" + Pdf + "' where pid ='" + pid + "'"; if (new common().ExcuteNoneQuery(sqlstr, null)) { Methods1.Methods1.Alert(this, "上传成功!"); } else { Methods1.Methods1.Alert(this, "上传失败 !"); } BindList(); } } 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"||strEx.ToLower()==".png") { 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, "上传失败,数据库中已有一个同名项,请重命名后重新上传!!!"); // } // else // { if (File.Exists(@"E:\cinowoftp\LocalUser\webs\goodsImgs\" + strName)) { Methods1.Methods1.Alert(this, "上传失败,文件夹中已有一个同名项,请重命名后重新上传!"); } else { if (File.Exists(@"E:\cinowoftp\LocalUser\webs\goodsImgs\" + jpg)) { File.Delete(@"E:\cinowoftp\LocalUser\webs\goodsImgs\"+ jpg); } string str =@"E:\cinowoftp\LocalUser\webs\goodsImgs\"+ strName; FileUpload4.PostedFile.SaveAs(str); // string str1 = @"E:\cinowoftp\LocalUser\webs\langue\SysAdmin\images\Goods\"+ strName; // FileUpload4.PostedFile.SaveAs(str1); jpg = strName; string sqlstr = " update v3_Pic_path set FileName = '" + jpg + "' where pid ='" + pid + "' and show =1"; if (new common().ExcuteNoneQuery(sqlstr, null)) { Methods1.Methods1.Alert(this, "上传成功!"); } else { Methods1.Methods1.Alert(this, "上传失败 !"); } BindList(); } //} } else { Methods1.Methods1.Alert(this, "上传的文档大小不能大于5MB!"); } } else { Methods1.Methods1.Alert(this, "只能够上传jpg格式的文档文件!"); } } else { Methods1.Methods1.Alert(this, "上传失败!位置错误!请联系管理员"); } } #endregion #region 上传列表图片 /// /// 上传列表图片 /// /// /// protected void ImageButton5_Click(object sender, ImageClickEventArgs e) { FileList.Clear(); HttpFileCollection files = HttpContext.Current.Request.Files; System.Text.StringBuilder strMsg = new System.Text.StringBuilder(); int count = 0; try { 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(@"E:\cinowoftp\LocalUser\webs\goodsImgs\"+ fileName)) { fileExtension = System.IO.Path.GetExtension(fileName); FileList.Insert(count, fileName); postedFile.SaveAs(@"E:\cinowoftp\LocalUser\webs\goodsImgs\" + fileName); //postedFile.SaveAs(@"E:\cinowoftp\LocalUser\webs\goodsImgs\" + fileName); Methods1.Methods1.Alert(this, "上传成功!"); count++; } else { Methods1.Methods1.Alert(this, "文件夹中已有重名项,请更名后重新上传!"); } } } BindPic(); } 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) { ////// 面的insert 换成update 。 string mulu = null; mulu = this.txtmulu.Value.ToString().Replace("'", "‘"); string sqlstr = " update v3_merchandises set CID=" + this.DDLTypeSmall.SelectedItem.Value + ",trade_name_cn='" + this.txtnamecn.Text.Trim() + "',trade_name_en='" + this.txtNameEn.Text.Trim() + "',market_price_rmb=" + this.txtmarketrmb.Text.Trim() + ",market_price_usd=" + this.txtmarketus.Text.Trim() + ",vip_price_rmb=" + this.txtviprmb.Text.Trim() + ",vip_price_usd=" + this.txtvipus.Text.Trim() + ",summary_cn='',summary_en=''," + "description_cn='" + this.txtdesccn.Value.Trim() + "',description_en='" + this.txtdescen.Value.Trim() + "',compositor=0,comp_en=0,publish='true',editdate='" + DateTime.Now.ToString() + "',EID=0,See_count=0,Buy_count=0,Spec='" + this.txtguige.Text.Trim() + "'," + "MULU='" + mulu + "',Chubanshe='" + this.txtchubanshe.Text.Trim() + "',Chubanshijian='" + this.txtchubanshijian.Text.Trim() + "',ISBN='" + this.txtisbn.Text.Trim() + "' where pid = " + pid; 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)"; new common().ExcuteNoneQuery(insertPic2, null); } FileList.Clear(); if (new common().ExcuteNoneQuery(sqlstr, null)) { Methods1.Methods1.Alert(this, "修改成功!!"); } BindPic(); } #region 取消和重置 protected void ImageButton7_Click(object sender, ImageClickEventArgs e) { Response.Redirect("goodList.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; } } } #endregion }