/// <summary> /// 获取可用的排序号 /// </summary> /// <param name="userID">用户ID</param> /// <returns></returns> public int GetMaxSort(string userID) { ExceptionHelper.TrueThrow <ArgumentNullException>(null == userID, "userID"); WhereSqlClauseBuilder builder = new WhereSqlClauseBuilder(); builder.AppendItem("USER_ID", DeluxeIdentity.CurrentUser.ID); builder.AppendTenantCode(typeof(TaskCategory)); int result = 0; string strSQL = string.Format("SELECT MAX(INNER_SORT_ID) AS NUM FROM WF.USER_TASK_CATEGORY WHERE {0}", builder.ToSqlString(TSqlBuilder.Instance)); object num = DbHelper.RunSqlReturnScalar(strSQL, ConnectionDefine.DBConnectionName); if (num.ToString() != string.Empty) { result = (int)num; //当排序号以达到最大值999时,仍返回最大值 if (result < 999) { result++; } } return(result); }
protected override int InnerUpdate(MaterialContent data, Dictionary <string, object> context, string[] ignoreProperties) { int result = 0; ORMappingItemCollection mappings = GetMappingInfo(context); string sql = string.Format("SELECT COUNT(*) FROM {0} WHERE {1}", mappings.TableName, ORMapping.GetWhereSqlClauseBuilderByPrimaryKey(data, mappings).ToSqlString(TSqlBuilder.Instance)); result = (int)DbHelper.RunSqlReturnScalar(sql, GetConnectionName()); if (result > 0) { Stream stream = null; if (context.ContainsKey("Stream")) { stream = (Stream)context["Stream"]; } if (stream == null) { result = base.InnerUpdate(data, context, ignoreProperties); } else { result = InnerUpdateWithStream(data, stream, context); } } return(result); }
/// <summary> /// 从数据库中加载 /// </summary> /// <param name="userID"></param> /// <returns></returns> private static UserRecentDataCategory LoadFromDB(string userID, string category) { userID.CheckStringIsNullOrEmpty("userID"); category.CheckStringIsNullOrEmpty("category"); string sql = string.Format("SELECT DATA FROM USER_RECENT_DATA WHERE USER_ID = {0} AND CATEGORY = {1}", TSqlBuilder.Instance.CheckQuotationMark(userID, true), TSqlBuilder.Instance.CheckQuotationMark(category, true) ); UserRecentDataCategory result = null; string settings = (string)DbHelper.RunSqlReturnScalar(sql, ConnectionDefine.UserRelativeInfoConnectionName); if (settings.IsNotEmpty()) { XElementFormatter formatter = new XElementFormatter(); formatter.OutputShortType = false; XElement root = XElement.Parse(settings); result = (UserRecentDataCategory)formatter.Deserialize(root); } return(result); }
/// <summary> /// 添加一行数据,并返回新主键 /// </summary> /// <param name="data"></param> /// <returns></returns> public int InsertData(UserOperationLog data) { ORMappingItemCollection mappings = ORMapping.GetMappingInfo <UserOperationLog>(); string sql = ORMapping.GetInsertSql(data, mappings, TSqlBuilder.Instance); decimal result = (decimal)DbHelper.RunSqlReturnScalar(string.Format("{0} \n SELECT @@IDENTITY", sql), this.GetConnectionName()); return(decimal.ToInt32(result)); }
public void Insert(UploadFileHistory history) { ExceptionHelper.FalseThrow <ArgumentNullException>(history != null, "history"); string sql = ORMapping.GetInsertSql(history, TSqlBuilder.Instance) + TSqlBuilder.Instance.DBStatementSeperator + "SELECT SCOPE_IDENTITY()"; decimal identity = (decimal)DbHelper.RunSqlReturnScalar(sql, AppLogSettings.GetConfig().ConnectionName); history.ID = Decimal.ToInt32(identity); }
public JobType GetJobType(string jobid) { WhereSqlClauseBuilder builder = new WhereSqlClauseBuilder(); builder.AppendItem("JOB_ID", jobid); string sql = string.Format(@"SELECT JOB_TYPE FROM WF.JOBS WHERE {0}", builder.ToSqlString(TSqlBuilder.Instance)); object obj = DbHelper.RunSqlReturnScalar(sql, ConnectionDefine.DBConnectionName); return((JobType)Enum.Parse(typeof(JobType), obj.ToString())); }
/// <summary> /// 是否存在且没有归档 /// </summary> /// <param name="resourceID"></param> /// <returns></returns> public bool ExistsAndNotArchived(string resourceID) { resourceID.CheckStringIsNullOrEmpty("resourceID"); WhereSqlClauseBuilder builder = new WhereSqlClauseBuilder(); builder.AppendItem("RESOURCE_ID", resourceID); builder.AppendTenantCode(typeof(AppCommonInfo)); string sql = string.Format("SELECT ARCHIVE_STATUS FROM WF.APPLICATIONS_COMMON_INFO WHERE {0}", builder.ToSqlString(TSqlBuilder.Instance)); object result = DbHelper.RunSqlReturnScalar(sql, GetConnectionName()); return(result != null && result.ToString() != "1"); }
public void UpdatePhoneNumber(PhoneNumber obj) { if (obj.ID.IsNullOrEmpty()) { obj.ID = Guid.NewGuid().ToString(); } if (obj.Changed) { string sql = VersionPhoneNumberUpdateSqlBuilder.Instance.ToUpdateSql(obj, GetMappingInfo(null)); using (TransactionScope scope = TransactionScopeFactory.Create()) { DateTime dt = (DateTime)DbHelper.RunSqlReturnScalar(sql, GetConnectionName()); DBTimePointActionContext.Current.TimePoint.IsMinValue(() => DBTimePointActionContext.Current.TimePoint = dt); scope.Complete(); } } }
/// <summary> /// 从数据库中加载 /// </summary> /// <param name="userID"></param> /// <returns></returns> private static UserSettings LoadFromDB(string userID) { string sql = string.Format("SELECT SETTINGS FROM USER_SETTINGS WHERE USER_ID = {0}", TSqlBuilder.Instance.CheckQuotationMark(userID, true)); UserSettings result = null; string settings = (string)DbHelper.RunSqlReturnScalar(sql, ConnectionDefine.UserRelativeInfoConnectionName); if (settings.IsNotEmpty()) { XElementFormatter formatter = new XElementFormatter(); formatter.OutputShortType = false; XElement root = XElement.Parse(settings); result = (UserSettings)formatter.Deserialize(root); } return(result); }