public CResult<bool> UpdatePeoplePic(PeoplePic peoplePic) { if (peoplePic.PicID <= 0) { return new CResult<bool>(false, ErrorCode.ParameterError); } var oldPic = GetPeoplePicByID(peoplePic.PicID).Data; if (oldPic == null) { return new CResult<bool>(false, ErrorCode.DataNotExist); } if (!peoplePic.PicPath.Contains(Path.GetFileName(oldPic.PicPath))) { var projectDir = Path.GetDirectoryName(Path.GetDirectoryName(Application.StartupPath)); var newName = Guid.NewGuid() + Path.GetExtension(peoplePic.PicPath); var savePth = Path.Combine(SystemInfo.UploadPeoplePicFolder, oldPic.PeopleID.ToString(), newName); var desPath = Path.Combine(projectDir, savePth); File.Copy(peoplePic.PicPath, desPath); peoplePic.PicPath = savePth; } else { peoplePic.PicPath = oldPic.PicPath; } var result = new PeoplePicDAL().UpdatePeoplePic(peoplePic); if (result) { return new CResult<bool>(true); } else { return new CResult<bool>(false, ErrorCode.SaveDataFailed); } }
private void btnSave_Click(object sender, EventArgs e) { if (string.IsNullOrWhiteSpace(this.txtPicPath.Text) || !File.Exists(this.openFileDialog1.FileName)) { MessageBox.Show("请选择文件!"); return; } var pic = new PeoplePic(); pic.PicTitle = this.txtPicTitle.Text; pic.PicPath = this.openFileDialog1.FileName; var bll = new PeoplePicBLL(); CResult<bool> result = new CResult<bool>(false); if (this._isEdit) { pic.PicID = this._currentPicID.Value; result = bll.UpdatePeoplePic(pic); } else { pic.PeopleID = this._peopleID.Value; result = bll.InsertPeoplePic(pic); } MessageHelper.ShowSaveDbResultMessage(result); if (result.Code == 0) { this.Dispose(); if (callbackEvent != null) { callbackEvent.Invoke(); } } }
public List<PeoplePic> GetPeoplePicList(int peopleID) { string sqlText = string.Format(@"select PicID, PicTitle, PicPath from {0} where PeopleID=@PeopleID" , _PeoplePicTableName); var paras = new OleDbParameter[1]; paras[0] = new OleDbParameter("PeopleID", peopleID); var table = new OLESqlHelper().GetTable(sqlText, paras); var PeoplePicList = new List<PeoplePic>(); foreach (DataRow row in table.Rows) { var PeoplePic = new PeoplePic() { PicID = (int)row["PicID"], PicTitle = row["PicTitle"].ToString(), PicPath = row["PicPath"].ToString(), }; PeoplePicList.Add(PeoplePic); } return PeoplePicList; }
public PeoplePic GetPeoplePicByID(int PicID) { using (var connection = new OleDbConnection(ConfigManagement.AccessConStr)) { string sqlText = string.Format(@"select PicID, PeopleID, PicTitle, PicPath from {0} where PicID=@PicID", _PeoplePicTableName); var paras = new OleDbParameter[1]; paras[0] = new OleDbParameter("PicID", PicID); var reader = new OLESqlHelper().GetReader(sqlText, connection, paras); if (reader.Read()) { int i = 0; var PeoplePic = new PeoplePic(); PeoplePic.PicID = reader.GetInt32(i++); PeoplePic.PeopleID = reader.GetInt32(i++); PeoplePic.PicTitle = reader.GetString(i++); PeoplePic.PicPath = reader.GetString(i++); return PeoplePic; } else { return null; } } }
public bool InsertPeoplePic(PeoplePic PeoplePic) { string sqlText = string.Format(@"insert into {0}( PeopleID, PicTitle, PicPath ) values( @PeopleID, @PicTitle, @PicPath )", _PeoplePicTableName); var paras = new OleDbParameter[3]; paras[0] = new OleDbParameter("PeopleID", PeoplePic.PeopleID); paras[1] = new OleDbParameter("PicTitle", PeoplePic.PicTitle); paras[2] = new OleDbParameter("PicPath", PeoplePic.PicPath); var result = new OLESqlHelper().ExecuteNoneQuery(sqlText, paras); return result; }
public CResult<bool> InsertPeoplePic(PeoplePic peoplePic) { if (peoplePic.PeopleID <= 0) { return new CResult<bool>(false, ErrorCode.ParameterError); } var projectDir = Path.GetDirectoryName(Path.GetDirectoryName(Application.StartupPath)); var newName = Guid.NewGuid() + Path.GetExtension(peoplePic.PicPath); var savePth = Path.Combine(SystemInfo.UploadPeoplePicFolder, peoplePic.PeopleID.ToString(), newName); var desPath = Path.Combine(projectDir, savePth); if (!Directory.Exists(Path.GetDirectoryName(desPath))) { Directory.CreateDirectory(Path.GetDirectoryName(desPath)); } File.Copy(peoplePic.PicPath, desPath); peoplePic.PicPath = savePth; var result = new PeoplePicDAL().InsertPeoplePic(peoplePic); if (result) { return new CResult<bool>(true); } else { return new CResult<bool>(false, ErrorCode.DataNotExist); } }
public bool UpdatePeoplePic(PeoplePic PeoplePic) { string sqlText = string.Format(@"update {0} set PicTitle=@PicTitle, PicPath=@PicPath where PicID=@PicID", _PeoplePicTableName); var paras = new OleDbParameter[3]; paras[0] = new OleDbParameter("PicTitle", PeoplePic.PicTitle); paras[1] = new OleDbParameter("PicPath", PeoplePic.PicPath); paras[2] = new OleDbParameter("PicID", PeoplePic.PicID); var result = new OLESqlHelper().ExecuteNoneQuery(sqlText, paras); return result; }