public CommandResult InsertWithPrimaryKey(CardPaymentInfo info) { CommandResult result = null; try { ParkDataContext parking = ParkDataContextFactory.CreateParking(base.ConnectStr); if (parking != null) { string cmdtext = string.Empty; cmdtext += string.Format("SET IDENTITY_INSERT CardPaymentRecord ON;"); cmdtext += info.SQLInsertWithPrimaryCmd; cmdtext += string.Format("SET IDENTITY_INSERT CardPaymentRecord OFF;"); parking.ExecuteCommand(cmdtext); result = new CommandResult(ResultCode.Successful, string.Empty); } else { result = new CommandResult(ResultCode.Fail, string.Empty); } } catch (Exception ex) { Ralid.GeneralLibrary.ExceptionHandling.ExceptionPolicy.HandleException(ex); result = new CommandResult(ResultCode.Fail, string.Empty); } return(result); }
public QueryResultList <TInfo> GetAll() { QueryResultList <TInfo> result; try { ParkDataContext parking = ParkDataContextFactory.CreateParking(ConnectStr); if (parking == null) { result = new QueryResultList <TInfo>(ResultCode.CannotConnectServer, ResultCodeDecription.GetDescription(ResultCode.CannotConnectServer), new List <TInfo>()); } else { List <TInfo> infoes = GetingAllItems(parking); result = new QueryResultList <TInfo>(ResultCode.Successful, successMsg, infoes); } } catch (SqlException ex) { result = new QueryResultList <TInfo>(ResultCodeResolver.GetFromSqlExceptionNumber(ex.Number), ex.Message, new List <TInfo>()); ExceptionPolicy.HandleException(ex, this.GetType().Name + "." + "GetAll()"); } catch (Exception ex) { result = new QueryResultList <TInfo>(ResultCode.Fail, ex.Message, new List <TInfo>()); ExceptionPolicy.HandleException(ex, this.GetType().Name + "." + "GetAll()"); } return(result); }
public QueryResultList <TInfo> GetItems(SearchCondition search) { QueryResultList <TInfo> result; try { ParkDataContext parking = ParkDataContextFactory.CreateParking(ConnectStr); List <TInfo> infoes; if (search != null) { infoes = GetingItems(parking, search); } else { infoes = GetingAllItems(parking); } result = new QueryResultList <TInfo>(ResultCode.Successful, successMsg, infoes); } catch (Exception ex) { result = new QueryResultList <TInfo>(ResultCode.Fail, "从数据库获取数据时发生错误!", new List <TInfo>()); ExceptionPolicy.HandleException(ex, this.GetType().Name + "." + "GetItems()"); } 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); 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 QueryResult <TInfo> GetByID(TID id) { QueryResult <TInfo> result; try { ParkDataContext parking = ParkDataContextFactory.CreateParking(ConnectStr); TInfo info = GetingItemByID(id, parking); if (info != null) { result = new QueryResult <TInfo>(ResultCode.Successful, successMsg, info); } else { result = new QueryResult <TInfo>(ResultCode.NoRecord, string.Empty, info); } } catch (SqlException ex) { result = new QueryResult <TInfo>(ResultCodeResolver.GetFromSqlExceptionNumber(ex.Number), ex.Message, null); ExceptionPolicy.HandleException(ex, this.GetType().Name + "." + "GetByID()"); } catch (Exception ex) { result = new QueryResult <TInfo>(ResultCode.Fail, ex.Message, null); ExceptionPolicy.HandleException(ex, this.GetType().Name + "." + "GetByID()"); } return(result); }
public void DeleteAllSnapShotBefore(DateTime shotDatetime) { ParkDataContext parking = ParkDataContextFactory.CreateParking(base.ConnectStr); string cmd = "delete SnapShot where ShotAt < '" + shotDatetime.ToString("yyyy-MM-dd") + "'"; parking.CommandTimeout = 5 * 60 * 60 * 1000; parking.ExecuteCommand(cmd); }
public void DeleteAllSnapShotBefore(DateTime shotDatetime) { try { ParkDataContext parking = ParkDataContextFactory.CreateParking(base.ConnectStr); string cmd = "delete SnapShot where ShotAt < '" + shotDatetime.ToString("yyyy-MM-dd") + "'"; parking.CommandTimeout = 5 * 60 * 60 * 1000; parking.ExecuteCommand(cmd); } catch (Exception ex) { Ralid.GeneralLibrary.ExceptionHandling.ExceptionPolicy.HandleException(ex); } }
public void DeleteAllCardEventBefore(DateTime eventDatetime) { try { ParkDataContext parking = ParkDataContextFactory.CreateParking(base.ConnectStr); if (parking != null) { string cmd = "delete CardEvent where EventDateTime < '" + eventDatetime.ToString("yyyy-MM-dd") + "'"; parking.CommandTimeout = 5 * 60 * 60 * 1000; parking.ExecuteCommand(cmd); } } catch (Exception ex) { Ralid.GeneralLibrary.ExceptionHandling.ExceptionPolicy.HandleException(ex); } }
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); }
public QueryResult <TInfo> GetByID(TID id) { QueryResult <TInfo> result; try { ParkDataContext parking = ParkDataContextFactory.CreateParking(ConnectStr); TInfo info = GetingItemByID(id, parking); if (info != null) { result = new QueryResult <TInfo>(ResultCode.Successful, successMsg, info); } else { result = new QueryResult <TInfo>(ResultCode.Fail, string.Format("没有找到ID={0}的数据!", id.ToString()), info); } } catch (Exception ex) { result = new QueryResult <TInfo>(ResultCode.Fail, "从数据库获取数据时发生错误!", null); ExceptionPolicy.HandleException(ex, this.GetType().Name + "." + "GetByID()"); } return(result); }
public UnitWork(string connStr) { _Parking = ParkDataContextFactory.CreateParking(connStr); }