public void add(MainPagePicModel mainpagepic) { SqlConnection cn = null; SqlTransaction tc = null; try { cn = DbHelperSQL.getConnection(); tc = DbHelperSQL.startTransaction(cn); //执行新增写进数据库 mainpagepicDal.add(cn, tc, mainpagepic); DbHelperSQL.commitTransaction(tc); } catch (Exception dalEx) { DbHelperSQL.rollBackTransaction(tc); throw new MakeException(ExpSort.数据库, dalEx.Message); } finally { DbHelperSQL.closeConnection(cn); } }
public bool add(SqlConnection cn, SqlTransaction tc, MainPagePicModel model) { return DbHelperSQL.insertModel<MainPagePicModel>(model, "MainPagePic", cn, tc); }
public bool update(SqlConnection cn, SqlTransaction tc, MainPagePicModel model) { return DbHelperSQL.updateModel<MainPagePicModel>(model, "MainPagePic", "Evenid", model.Evenid.ToString(), "'", cn, tc); }
protected void UpPicCmd_Click(object sender, EventArgs e) { string name = FileUpload1.FileName; if ((name.Trim() == "")) { this.Label1.Text = "请选择要上传的文件"; return; } else { this.Label1.Text = ""; } string type = name.Substring(name.LastIndexOf(".")); // if (type != ".jpg") // { // this.Label1.Text = "请上传jpg格式文件"; // return; // } // string fileName = DateTime.Now.GetHashCode().ToString(); string imageName = Guid.NewGuid().ToString(); string path = Server.MapPath(Helper.ImagePath) + imageName + type; string wpath = Helper.ImagePath + imageName + type; if (FileUpload1.PostedFile.ContentType.Substring(0, 5) == "image") { if (FileUpload1.PostedFile.ContentLength > Helper.ImageLimit) { this.Label1.Text = Helper.ImageLimitWraning; return; } try { FileUpload1.SaveAs(path); //压缩图片,覆盖原图 Helper.ImageMakeSmaller(wpath); var img = new MainPagePicModel(); img.SchoolNo = ImgType; img.ImgPath = imageName + type; img.SortNo = Convert.ToInt32(ReqSortNo); _mainPagePicEbi.add(img); this.Image1.ImageUrl = wpath + "?" + MakeRandom(); Script.RunJS(Page, "SuccessCallBack", "SuccessCallBack();"); } catch { Script.alertMsg("发生错误", Page); } // imgBytes = SetImgToByte(path); // Session["PhotoImage"] = imgBytes; } else { this.Label1.Text = "请上传图片格式文件"; return; } }