public void EncapsulationData() { EmailObj = new tblEmail(); BackupObj = new tblBackup(); BackupObj.BackupFloder = txtBackupFolder.Text.Trim(); BackupObj.BackupDatabase = txtDatabase.Text.Trim(); BackupObj.BackupServer = txtServer.Text.Trim(); BackupObj.BackupID = System.Guid.NewGuid(); EmailObj.EmailID = BackupObj.BackupID; EmailObj.SMTPHost = rtxtServerName.Text.Trim(); EmailObj.EmailFrom = rtxtFrom.Text.Trim(); EmailObj.EmailPort = Convert.ToInt16(rntxtPort.Text.Trim()); EmailObj.SMTPUsername = rtxtName.Text.Trim(); EmailObj.SMTPPassword = rtxtPwd.Text.Trim(); EmailObj.EmailSSL = ckbSSL.Checked; HttpCookie UserData = Request.Cookies.Get("UserIdCookies"); if (UserData != null) { BackupObj.BackupUser = UserData.Value; } HttpCookie UserPasswordData = Request.Cookies.Get("UserPasswordCookies"); if (UserPasswordData != null) { BackupObj.BackupPassword = UserPasswordData.Value; } }
/// <summary> /// 创建新的 tblBackup 对象。 /// </summary> /// <param name="backupID">BackupID 属性的初始值。</param> public static tblBackup CreatetblBackup(global::System.Guid backupID) { tblBackup tblBackup = new tblBackup(); tblBackup.BackupID = backupID; return tblBackup; }
/// <summary> /// 用于向 tblBackup EntitySet 添加新对象的方法,已弃用。请考虑改用关联的 ObjectSet<T> 属性的 .Add 方法。 /// </summary> public void AddTotblBackup(tblBackup tblBackup) { base.AddObject("tblBackup", tblBackup); }
/// <summary> /// 更新对象 /// </summary> /// <param name="BackupObj">需要更新的对象</param> /// <returns>返回受影响的行数</returns> public virtual string Update(tblBackup BackupObj) { tblBackup SchedulerObjUpdate;//需要跟新的对象 string strMessage = "InsertError"; int counts = 0;//影响行数标记 try { ServiceDirectDB = new ServiceDirectDBEntities(); SchedulerObjUpdate = ServiceDirectDB.tblBackup.FirstOrDefault(t => t.BackupID == BackupObj.BackupID); }catch(EntitySqlException) { throw; } catch (EntityException) { throw; } if (SchedulerObjUpdate != null)//如果为空则进行插入 { //对象进行赋值,准备更新 SchedulerObjUpdate.BackupFloder = BackupObj.BackupFloder; SchedulerObjUpdate.BackupDatabase = BackupObj.BackupDatabase; SchedulerObjUpdate.DeleteBackupOlder = BackupObj.DeleteBackupOlder; SchedulerObjUpdate.BackupServer = BackupObj.BackupServer; SchedulerObjUpdate.BackupUser = BackupObj.BackupUser; SchedulerObjUpdate.BackupPassword = BackupObj.BackupPassword; try { counts = ServiceDirectDB.SaveChanges(); } catch (EntityException) { throw; } } else { try { ServiceDirectDBEntitieAdd = new ServiceDirectDBEntities(); ServiceDirectDBEntitieAdd.tblBackup.AddObject(BackupObj); counts = ServiceDirectDBEntitieAdd.SaveChanges(); } catch (EntityException) { throw; } } if (counts > 0) { strMessage = "update success"; return strMessage; } return strMessage; }
/// <summary> /// 插入的对象 /// </summary> /// <param name="BackupObj">需要插入的对象</param> /// <returns>受影响的行数</returns> public virtual string Insert(tblBackup BackupObj) { int counts = 0;//影响行数标记 string strErrorMessage = "InsertError"; //插入数据 try { ServiceDirectDBEntitieAdd = new ServiceDirectDBEntities(); ServiceDirectDBEntitieAdd.tblBackup.AddObject(BackupObj); counts = ServiceDirectDBEntitieAdd.SaveChanges(); } catch (EntitySqlException) { throw; } if (counts>0) { return BackupObj.BackupID.ToString(); } return strErrorMessage; }