public CommandResult Delete(TInfo info) { CommandResult result; try { ParkDataContext parking = ParkDataContextFactory.CreateParking(ConnectStr); if (parking == null) { result = new CommandResult(ResultCode.CannotConnectServer, ResultCodeDecription.GetDescription(ResultCode.CannotConnectServer)); } else { DeletingItem(info, parking); parking.SubmitChanges(); result = new CommandResult(ResultCode.Successful, successMsg); } } catch (SqlException ex) { result = new CommandResult(ResultCodeResolver.GetFromSqlExceptionNumber(ex.Number), ex.Message); ExceptionPolicy.HandleException(ex, this.GetType().FullName + "." + "Delete()"); } catch (Exception ex) { result = new CommandResult(ResultCode.Fail, ex.Message); ExceptionPolicy.HandleException(ex, this.GetType().FullName + "." + "Delete()"); } return(result); }
public CommandResult Insert(TInfo info) { CommandResult result; try { ParkDataContext parking = ParkDataContextFactory.CreateParking(ConnectStr); InsertingItem(info, parking); parking.SubmitChanges(); result = new CommandResult(ResultCode.Successful, successMsg); } catch (System.Data.SqlClient.SqlException ex) { if (ex.Number == 2627) { result = new CommandResult(ResultCode.Fail, "不能插入重复ID的数据!"); } else { result = new CommandResult(ResultCode.Fail, "数据在写入数据库时发生错误!"); } ExceptionPolicy.HandleException(ex, this.GetType().Name + "." + "Insert()"); } catch (Exception ex) { result = new CommandResult(ResultCode.Fail, "数据在写入数据库时发生错误!"); ExceptionPolicy.HandleException(ex, this.GetType().Name + "." + "Insert()"); } return(result); }
public CommandResult Delete(TInfo info) { CommandResult result; try { ParkDataContext parking = ParkDataContextFactory.CreateParking(ConnectStr); DeletingItem(info, parking); parking.SubmitChanges(); result = new CommandResult(ResultCode.Successful, successMsg); } catch (Exception ex) { result = new CommandResult(ResultCode.Fail, "从数据库删除数据时发生错误!"); ExceptionPolicy.HandleException(ex, this.GetType().FullName + "." + "Delete()"); } return(result); }
public CommandResult Update(TInfo newVal, TInfo original) { CommandResult result; try { ParkDataContext parking = ParkDataContextFactory.CreateParking(ConnectStr); UpdatingItem(newVal, original, parking); parking.SubmitChanges(); result = new CommandResult(ResultCode.Successful, successMsg); } catch (Exception ex) { result = new CommandResult(ResultCode.Fail, "数据在写入数据库时发生错误!"); ExceptionPolicy.HandleException(ex, this.GetType().FullName + "." + "Update()"); } return(result); }
public CommandResult Insert(TInfo info) { CommandResult result; try { ParkDataContext parking = ParkDataContextFactory.CreateParking(ConnectStr); InsertingItem(info, parking); parking.SubmitChanges(); result = new CommandResult(ResultCode.Successful, successMsg); } catch (SqlException ex) { result = new CommandResult(ResultCodeResolver.GetFromSqlExceptionNumber(ex.Number), ex.Message); ExceptionPolicy.HandleException(ex, this.GetType().Name + "." + "Insert()"); } catch (Exception ex) { result = new CommandResult(ResultCode.Fail, ex.Message); ExceptionPolicy.HandleException(ex, this.GetType().Name + "." + "Insert()"); } return(result); }