/// <summary> /// 添加友情连接 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void Button1_Click(object sender, EventArgs e) { string title = txtTitle.Text.Trim(); string proDesc = this.txtTitle2.Text.Trim(); string proPrice = this.txtPrice.Text.Trim(); string unitDesc = txtUnit.Text.Trim(); string url = this.txtLinkUrl.Text.Trim(); string spic = ""; if (this.FileUpload1.PostedFile != null && FileUpload1.PostedFile.FileName != "") { if (!Directory.Exists(Server.MapPath(Global_Upload.FriendImgPath))) //判断目录是否存在 { Directory.CreateDirectory(Server.MapPath(Global_Upload.FriendImgPath)); //创建目录 } spic = DoClass.UploadFile(FileUpload1.PostedFile, Global_Upload.Imgsize, Global_Upload.ImgType, Global_Upload.FriendImgPath); if (spic == "-1") { return; } else if (spic == "0") { return; } else { ViewState["img1Name"] = spic; spic = Global_Upload.FriendImgPath + spic; ViewState["newsImg1"] = spic; lblURL1.Text = spic; } } IndexProduct item = new IndexProduct(); item.typeId = Convert.ToInt32(ddlCate.SelectedValue); item.typeName = ddlCate.SelectedItem.Text; item.proName = title; item.proDesc = proDesc; item.proPrice = 0; item.priceStr = proPrice; item.unitDesc = unitDesc; if (ViewState["newsImg1"] != null || lblURL1.Text != "") { item.imgUrl = lblURL1.Text; } else { lblError.Text = "请上传图片"; return; } item.status = 0; item.remark = url; item.addTime = DateTime.Now; item.infoType = 0; item.addUser = 0; AdminUser au = Session["loginUser"] as AdminUser; if (au != null) { item.addUser = au.id; } if (lblId.Text != "") { item.id = Convert.ToInt32(lblId.Text.Trim()); IndexProductService.Update(item); } else { int num = IndexProductService.Add(item); } pnlAdd.Visible = false; pnlList.Visible = true; LoadData(); }