protected void LinkButton1_Click(object sender, EventArgs e) { AdminUser adminUser = Session["SuperAdminUserSession"] as AdminUser; if (Request.QueryString["p"] != null) { NCPEP.Model.T_BidPlacard model = new NCPEP.Model.T_BidPlacard(); model.BidPlacardContent = this.txtBidPlacardContent.Value; model.BidPlacardTitle = this.txtBidPlacardTitle.Value; model.FK_BidId = int.Parse(Request.QueryString["p"]); model.Publisher = adminUser.AdminName; if (this.FileUpload1.HasFile) { string strtype = System.IO.Path.GetExtension(FileUpload1.FileName).ToLower();//ToLower转化为小写 if (strtype == ".jpg" || strtype == ".gif" || strtype == ".jpeg" || strtype == ".png" || strtype == ".pdf") { //获得上传文件的大小 int filesize = FileUpload1.PostedFile.ContentLength; if (filesize > 1024 * 1024 * 25) { MessageBox.Show(this, "你上传的文件太大!"); return; } else { model.fujianname = FileUpload1.FileName; string strname = Guid.NewGuid().ToString("N") + System.IO.Path.GetExtension(FileUpload1.FileName); model.fujian = strname; string strpath = Server.MapPath("~/Super/Scan/bcrfujian/" + model.FK_BidId + ""); if (!System.IO.Directory.Exists(strpath)) { System.IO.Directory.CreateDirectory(strpath); } FileUpload1.SaveAs(strpath + "/" + strname); } } } NCPEP.Bll.T_BidPlacard bll = new NCPEP.Bll.T_BidPlacard(); if (bll.Add(model) > 0) { MessageBox.Show(this, "添加成功"); //Response.Write("<script> function closeParent(){ window.parent.closeIframe(); }</script>"); this.LinkButton1.Visible = false; } } }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(NCPEP.Model.T_BidPlacard model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update T_BidPlacard set "); strSql.Append("FK_BidId=@FK_BidId,"); strSql.Append("BidPlacardTitle=@BidPlacardTitle,"); strSql.Append("BidPlacardContent=@BidPlacardContent,"); strSql.Append("Publisher=@Publisher,"); strSql.Append("ReleaseTime=@ReleaseTime,"); strSql.Append("fujian=@fujian,"); strSql.Append("fujianname=@fujianname"); strSql.Append(" where Id=@Id"); SqlParameter[] parameters = { new SqlParameter("@FK_BidId", SqlDbType.Int, 4), new SqlParameter("@BidPlacardTitle", SqlDbType.NVarChar, 50), new SqlParameter("@BidPlacardContent", SqlDbType.NVarChar, 500), new SqlParameter("@Publisher", SqlDbType.NVarChar, 50), new SqlParameter("@ReleaseTime", SqlDbType.DateTime), new SqlParameter("@fujian", SqlDbType.VarChar, 500), new SqlParameter("@fujianname", SqlDbType.VarChar, 50), new SqlParameter("@Id", SqlDbType.Int, 4) }; parameters[0].Value = model.FK_BidId; parameters[1].Value = model.BidPlacardTitle; parameters[2].Value = model.BidPlacardContent; parameters[3].Value = model.Publisher; parameters[4].Value = model.ReleaseTime; parameters[5].Value = model.fujian; parameters[6].Value = model.fujianname; parameters[7].Value = model.Id; int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
protected void LinkButton2_Click(object sender, EventArgs e) { if (!string.IsNullOrEmpty(this.hidid.Value)) { NCPEP.Bll.T_BidPlacard bll = new NCPEP.Bll.T_BidPlacard(); NCPEP.Model.T_BidPlacard model = new NCPEP.Model.T_BidPlacard(); model = bll.GetModel(int.Parse(this.hidid.Value)); model.BidPlacardTitle = this.txtBidPlacardTitle.Value; model.BidPlacardContent = this.txtBidPlacardContent.Value; if (this.FileUpload1.HasFile) { string strtype = System.IO.Path.GetExtension(FileUpload1.FileName).ToLower();//ToLower转化为小写 if (strtype == ".jpg" || strtype == ".gif" || strtype == ".jpeg" || strtype == ".png" || strtype == ".pdf") { //获得上传文件的大小 int filesize = FileUpload1.PostedFile.ContentLength; if (filesize > 1024 * 1024 * 25) { MessageBox.Show(this, "你上传的文件太大!"); return; } else { model.fujianname = FileUpload1.FileName; string strname = Guid.NewGuid().ToString("N") + System.IO.Path.GetExtension(FileUpload1.FileName); model.fujian = strname; string strpath = Server.MapPath("~/Super/Scan/bcrfujian/" + model.FK_BidId + ""); if (!System.IO.Directory.Exists(strpath)) { System.IO.Directory.CreateDirectory(strpath); } FileUpload1.SaveAs(strpath + "/" + strname); } } } if (bll.Update(model)) { MessageBox.Show(this, "修改成功"); } } }
/// <summary> /// 得到一个对象实体 /// </summary> public NCPEP.Model.T_BidPlacard DataRowToModel(DataRow row) { NCPEP.Model.T_BidPlacard model = new NCPEP.Model.T_BidPlacard(); if (row != null) { if (row["Id"] != null && row["Id"].ToString() != "") { model.Id = int.Parse(row["Id"].ToString()); } if (row["FK_BidId"] != null && row["FK_BidId"].ToString() != "") { model.FK_BidId = int.Parse(row["FK_BidId"].ToString()); } if (row["BidPlacardTitle"] != null) { model.BidPlacardTitle = row["BidPlacardTitle"].ToString(); } if (row["BidPlacardContent"] != null) { model.BidPlacardContent = row["BidPlacardContent"].ToString(); } if (row["Publisher"] != null) { model.Publisher = row["Publisher"].ToString(); } if (row["ReleaseTime"] != null && row["ReleaseTime"].ToString() != "") { model.ReleaseTime = DateTime.Parse(row["ReleaseTime"].ToString()); } if (row["fujian"] != null) { model.fujian = row["fujian"].ToString(); } if (row["fujianname"] != null) { model.fujianname = row["fujianname"].ToString(); } } return(model); }
/// <summary> /// 增加一条数据 /// </summary> public int Add(NCPEP.Model.T_BidPlacard model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into T_BidPlacard("); strSql.Append("FK_BidId,BidPlacardTitle,BidPlacardContent,Publisher,ReleaseTime,fujian,fujianname)"); strSql.Append(" values ("); strSql.Append("@FK_BidId,@BidPlacardTitle,@BidPlacardContent,@Publisher,@ReleaseTime,@fujian,@fujianname)"); strSql.Append(";select @@IDENTITY"); SqlParameter[] parameters = { new SqlParameter("@FK_BidId", SqlDbType.Int, 4), new SqlParameter("@BidPlacardTitle", SqlDbType.NVarChar, 50), new SqlParameter("@BidPlacardContent", SqlDbType.NVarChar, 500), new SqlParameter("@Publisher", SqlDbType.NVarChar, 50), new SqlParameter("@ReleaseTime", SqlDbType.DateTime), new SqlParameter("@fujian", SqlDbType.VarChar, 500), new SqlParameter("@fujianname", SqlDbType.VarChar, 50) }; parameters[0].Value = model.FK_BidId; parameters[1].Value = model.BidPlacardTitle; parameters[2].Value = model.BidPlacardContent; parameters[3].Value = model.Publisher; parameters[4].Value = model.ReleaseTime; parameters[5].Value = model.fujian; parameters[6].Value = model.fujianname; object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters); if (obj == null) { return(0); } else { return(Convert.ToInt32(obj)); } }
/// <summary> /// 得到一个对象实体 /// </summary> public NCPEP.Model.T_BidPlacard GetModel(int Id) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 Id,FK_BidId,BidPlacardTitle,BidPlacardContent,Publisher,ReleaseTime,fujian,fujianname from T_BidPlacard "); strSql.Append(" where Id=@Id"); SqlParameter[] parameters = { new SqlParameter("@Id", SqlDbType.Int, 4) }; parameters[0].Value = Id; NCPEP.Model.T_BidPlacard model = new NCPEP.Model.T_BidPlacard(); DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { return(DataRowToModel(ds.Tables[0].Rows[0])); } else { return(null); } }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(NCPEP.Model.T_BidPlacard model) { return(dal.Update(model)); }
/// <summary> /// 增加一条数据 /// </summary> public int Add(NCPEP.Model.T_BidPlacard model) { return(dal.Add(model)); }