/// <summary> /// Constructor to create a new super-class /// </summary> /// <param name="assemblyName">The assembly name of the superClass</param> /// <param name="className">The class name of the superClass</param> /// <param name="mapping">The type of OR-Mapping to use. See /// the ORMapping enumeration for more detail.</param> /// <param name="id">In ClassTableInheritance, this determines which property /// in the child has a copy of the parent ID. Provide an empty string if in /// the code the child simply inherits the parent's ID.</param> /// <param name="discriminator">In SingleTableInheritance, this determines /// the name of the database column that stores the type name of the class /// being stored in that particular row.</param> public SuperClassDef(string assemblyName, string className, ORMapping mapping, string id, string discriminator) { _orMapping = mapping; _superClassClassDef = null; _assemblyName = assemblyName; _className = className; ID = id; Discriminator = discriminator; }
private static IClassDef LoadClassDef_WithInheritance(ORMapping orMapping) { XmlClassLoader itsLoader = new XmlClassLoader(new DtdLoader(), new DefClassFactory()); IClassDef itsClassDef = itsLoader.LoadClass(String.Format(@" <class name=""Vehicle"" assembly=""Habanero.Test.Structure"" table=""table_class_Vehicle""> <superClass class=""Entity"" assembly=""Habanero.Test.Structure"" orMapping=""{0}"" {1} /> <property name=""VehicleID"" type=""Guid"" databaseField=""field_Vehicle_ID"" /> <property name=""VehicleType"" databaseField=""field_Vehicle_Type"" /> <property name=""DateAssembled"" type=""DateTime"" databaseField=""field_Date_Assembled"" /> <property name=""OwnerID"" type=""Guid"" databaseField=""field_Owner_ID"" /> <primaryKey> <prop name=""VehicleID"" /> </primaryKey> <relationship name=""Owner"" type=""single"" relatedClass=""LegalEntity"" relatedAssembly=""Habanero.Test.Structure""> <relatedProperty property=""OwnerID"" relatedProperty=""LegalEntityID"" /> </relationship> </class> ", Enum.GetName(typeof(ORMapping), orMapping), orMapping == ORMapping.SingleTableInheritance ? "discriminator=\"EntityType\"" : "")); ClassDef.ClassDefs.Add(itsClassDef); return itsClassDef; }
internal SetLockResult(string personID, DataTable table) : base(personID) { ExceptionHelper.FalseThrow(table.Rows.Count == 2, "加锁后返回的结果集的行数必须为2,现在是{1}", table.Rows.Count); if (table.Rows[0]["LOCK_ID"] != DBNull.Value) { this.newLock = new Lock(); ORMapping.DataRowToObject(table.Rows[0], this.newLock); } if (table.Rows[1]["LOCK_ID"] != DBNull.Value) { this.originalLock = new Lock(); ORMapping.DataRowToObject(table.Rows[1], this.originalLock); } this.originalLockStatus = CalculateLockStatus(this.newLock, this.originalLock); }
public void SaveArchiveData(ArchiveBasicInfo info) { ArchiveSettings settings = ArchiveSettings.GetConfig(); ORMappingItemCollection mappings = ORMapping.GetMappingInfo <Material>().Clone(); mappings["CREATE_DATETIME"].BindingFlags |= (ClauseBindingFlags.Update | ClauseBindingFlags.Insert); ORMappingContextCache.Instance[typeof(Material)] = mappings; try { MaterialAdapter.Instance.DeleteMaterialsByResourceID(info.ResourceID); MaterialContentAdapter.Instance.Delete(b => b.AppendItem("RELATIVE_ID", info.ResourceID)); info.Context.DoAction <MaterialList>("Materials", materials => { DeltaMaterialList dml = new DeltaMaterialList(); materials.ForEach(m => { dml.Inserted.Add(m); }); MaterialAdapter.Instance.SaveDeltaMaterials(dml, false); dml.Inserted.ForEach(m => { if (m.Content != null) { MaterialContentAdapter.Instance.Update(m.Content); } }); }); } finally { ORMappingContextCache.Instance.Remove(typeof(Material)); } }
private string GetMoveSysTaskSql(SysAccomplishedTask taskCompleted, Dictionary <string, object> context) { ORMappingItemCollection mappings = GetMappingInfo(context); ORMappingItemCollection mappingsCompleted = ORMapping.GetMappingInfo <SysAccomplishedTask>(); InsertSqlClauseBuilder insertBuilder = ORMapping.GetInsertSqlClauseBuilder(taskCompleted, "EndTime", "Status", "StatusText"); string[] fields = insertBuilder.GetFields().ToArray(); string affectedFields = string.Join(",", fields); string sql = string.Format("INSERT INTO {0}({1}, END_TIME, STATUS, STATUS_TEXT) SELECT {2}, GETUTCDATE() AS END_TIME, {3} AS STATUS, {4} AS STATUS_TEXT FROM {5} WHERE TASK_GUID = {6}", mappingsCompleted.TableName, affectedFields, affectedFields, TSqlBuilder.Instance.CheckUnicodeQuotationMark(taskCompleted.Status.ToString()), TSqlBuilder.Instance.CheckUnicodeQuotationMark(taskCompleted.StatusText), mappings.TableName, TSqlBuilder.Instance.CheckUnicodeQuotationMark(taskCompleted.TaskID)); return(sql); }
private SCRelationForFullPath LoadRFPByID(string parentID) { if (parentID.IsNullOrEmpty()) { parentID = SCOrganization.RootOrganizationID; } SCRelationForFullPath result = null; if (parentID == SCOrganization.RootOrganizationID) { result = new SCRelationForFullPath(); result.ParentID = string.Empty; result.ObjectID = parentID; result.Name = SCOrganization.GetRoot().Name; result.InnerSort = 0; result.FullPath = string.Empty; result.GlobalSort = string.Empty; } else { string sql = string.Format("SELECT ParentID, R.ObjectID, SC.Name, R.ChildSchemaType, R.InnerSort, R.FullPath, R.GlobalSort FROM {0} WHERE ObjectID = {1} AND ChildSchemaType = 'Organizations'", "SC.SchemaRelationObjectsSnapshot_Current R INNER JOIN SC.SchemaObjectSnapshot_Current SC ON R.ObjectID = SC.ID", TSqlBuilder.Instance.CheckUnicodeQuotationMark(parentID)); DataTable table = DbHelper.RunSqlReturnDS(sql, this.GetConnectionName()).Tables[0]; if (table.Rows.Count > 0) { result = new SCRelationForFullPath(); ORMapping.DataRowToObject(table.Rows[0], result); } } return(result); }
/// <summary> /// 更新相关的数据。先删除某个ResouceID和ClassName下相关的数据,然后再插入集合中的数据 /// </summary> /// <typeparam name="TRelative"></typeparam> /// <param name="resourceID"></param> /// <param name="className"></param> /// <param name="dataCollection"></param> public virtual void UpdateRelativeData <TRelative>(string resourceID, string className, IEnumerable <TRelative> dataCollection) where TRelative : GenericFormRelativeData { resourceID.CheckStringIsNullOrEmpty("resourceID"); className.CheckStringIsNullOrEmpty("className"); WhereSqlClauseBuilder builder = new WhereSqlClauseBuilder(); builder.AppendItem("RESOURCE_ID", resourceID).AppendItem("CLASS", className); builder.AppendTenantCode(typeof(TRelative)); StringBuilder strB = new StringBuilder(); strB.AppendFormat("DELETE WF.GENERIC_FORM_RELATIVE_DATA WHERE {0}", builder.ToSqlString(TSqlBuilder.Instance)); int i = 0; foreach (TRelative data in dataCollection) { data.ResourceID = resourceID; data.Class = className; strB.Append(TSqlBuilder.Instance.DBStatementSeperator); InsertSqlClauseBuilder insertBuilder = ORMapping.GetInsertSqlClauseBuilder(data, "ResourceID", "Class", "SortID", "XmlContent"); data.SortID = i++; insertBuilder.AppendItem("RESOURCE_ID", resourceID).AppendItem("CLASS", className).AppendItem("SORT_ID", data.SortID); XmlDocument xdoc = XmlHelper.SerializeObjectToXml(data); data.XmlContent = xdoc.OuterXml; insertBuilder.AppendItem("XML_CONTENT", xdoc.OuterXml); strB.AppendFormat("INSERT WF.GENERIC_FORM_RELATIVE_DATA{0}", insertBuilder.ToSqlString(TSqlBuilder.Instance)); } DbHelper.RunSqlWithTransaction(strB.ToString(), GetConnectionName()); }
private string GetUpdateSql(string containerID, SCAclContainerOrMemberCollectionBase members) { return(VersionStrategyUpdateSqlHelper.ConstructUpdateSql( null, (strB, context) => { string tableName = this.GetMappingInfo().TableName; ConnectiveSqlClauseCollection connectiveBuilder = VersionStrategyQuerySqlBuilder.Instance.TimePointToBuilder(); WhereSqlClauseBuilder keyBuilder = new WhereSqlClauseBuilder(); keyBuilder.AppendItem("ContainerID", containerID); connectiveBuilder.Add(keyBuilder); strB.AppendFormat( "UPDATE {0} SET VersionEndTime = {1} WHERE {2}", tableName, "@currentTime", connectiveBuilder.ToSqlString(TSqlBuilder.Instance)); for (int i = 0; i < members.Count; i++) { SCAclItem aclitem = members[i]; aclitem.SortID = i; strB.Append(TSqlBuilder.Instance.DBStatementSeperator); aclitem.VersionEndTime = ConnectionDefine.MaxVersionEndTime; InsertSqlClauseBuilder insertBuilder = ORMapping.GetInsertSqlClauseBuilder(aclitem, this.GetMappingInfo(), "VersionStartTime"); insertBuilder.AppendItem("VersionStartTime", "@currentTime", "=", true); strB.AppendFormat("INSERT INTO {0}{1}", tableName, insertBuilder.ToSqlString(TSqlBuilder.Instance)); } })); }
public void Update(string processID, WfRelativeProcessCollection relativeProcesses) { processID.CheckStringIsNullOrEmpty("processID"); relativeProcesses.NullCheck("relativeProcesses"); WhereSqlClauseBuilder wBuilder = new WhereSqlClauseBuilder(); wBuilder.AppendItem("PROCESS_ID", processID); wBuilder.AppendTenantCodeSqlClause(typeof(WfProcessCurrentActivity)); ORMappingItemCollection mapping = ORMapping.GetMappingInfo <WfRelativeProcess>(); string sqlDelete = string.Format( "DELETE {0} WHERE {1}", mapping.TableName, wBuilder.ToSqlString(TSqlBuilder.Instance)); StringBuilder strB = new StringBuilder(); foreach (WfRelativeProcess relativeProcess in relativeProcesses) { if (strB.Length > 0) { strB.Append(TSqlBuilder.Instance.DBStatementSeperator); } strB.Append(ORMapping.GetInsertSql(relativeProcess, TSqlBuilder.Instance)); } string sql = sqlDelete; if (strB.Length > 0) { sql += TSqlBuilder.Instance.DBStatementSeperator + strB.ToString(); } DbHelper.RunSqlWithTransaction(sql, GetConnectionName()); }
/// <summary> /// 按where 条件 且返回分页 /// </summary> /// <param name="where"></param> /// <param name="rowIndex">行序号, 基于0</param> /// <param name="pageSize">分页大小</param> /// <param name="sortField">排序字段</param> /// <returns></returns> public PartlyCollection <T> GetList(WhereSqlClauseBuilder where, int rowIndex, int pageSize, string sortField = "ID") { if (where == null) { throw new ArgumentNullException("where"); } if (string.IsNullOrEmpty(sortField)) { sortField = "ID"; } QueryCondition qc = new QueryCondition( rowIndex, pageSize, " * ", ORMapping.GetTableName(typeof(T)), SqlTextHelper.SafeQuote(sortField), where.ToSqlString(TSqlBuilder.Instance) ); PartlyCollection <T> result = GetPageSplitedCollection(qc); return(result); }
/// <summary> /// 综合报表查询 /// </summary> /// <param name="SysIDs">系统ID串 , 用‘,’分割</param> /// <param name="FinYears">选择的年份,用‘,’分割</param> /// <param name="Targets">选择的指标,用‘,’分割</param> /// <param name="DataType">数据的类型 </param> /// <param name="IsMonthlyReport">是否是月报,或者指标的数据 参数:MonthlyReport ,‘’</param> /// <param name="CurrentYear">当前年</param> /// <returns></returns> public List <ComprehensiveReportVModel> GetComprehensiveReportForms(string SysIDs, string FinYears, string Targets, string DataType, string IsMonthlyReport, int CurrentYear) { string sql = "GetComprehensiveReportFormsList "; SqlParameter p1 = new SqlParameter("@SysIDs", SysIDs); SqlParameter p2 = new SqlParameter("@FinYears", FinYears); SqlParameter p3 = new SqlParameter("@Targets", Targets); SqlParameter p4 = new SqlParameter("@DataType", DataType); SqlParameter p5 = new SqlParameter("@IsMonthlyReport", IsMonthlyReport); SqlParameter p6 = new SqlParameter("@CurrentYear", CurrentYear); var ds = DbHelper.RunSPReturnDS(sql, ConnectionName, p1, p2, p3, p4, p5, p6); List <ComprehensiveReportVModel> data = new List <ComprehensiveReportVModel>(); ds.Tables[0].Rows.Cast <System.Data.DataRow>().ForEach(row => { ComprehensiveReportVModel item = new ComprehensiveReportVModel(); ORMapping.DataRowToObject(row, item); data.Add(item); }); return(data); }
/// <summary> /// 根据ID查询所有提示表 /// </summary> /// <param name="codeArray">CodeName的数组 </param> /// <param name="cultureName"> 区域</param> /// <returns>提示信息集合</returns> public TipCollection GetTips(string[] codeArray, string cultureName) { (codeArray != null).FalseThrow("提示信息列表不能为null"); InSqlClauseBuilder builder = new InSqlClauseBuilder("CODE_NAME"); builder.AppendItem(codeArray); var result = new TipCollection(); if (builder.Count > 0) { string sql = string.Format("SELECT * FROM KB.TIP WHERE ENABLE ='1' AND CULTURE='{1}' AND {0} ", builder.AppendTenantCodeSqlClause(typeof(Tip)).ToSqlString(TSqlBuilder.Instance), cultureName); DataTable table = null; DbHelper.RunSql(db => table = db.ExecuteDataSet(CommandType.Text, sql).Tables[0], ConnectionDefine.KBConnectionName); ORMapping.DataViewToCollection(result, table.DefaultView); } return(result); }
public WdOrg GetOrgByName(string orgName) { WdOrg result = null; string sqlCommand = string.Empty; sqlCommand = string.Format(@"SELECT parentUnitID ParentID,OrgID, OrgName,ShortName,[order] OrderID , FullPath FROM dbo.wd_org WHERE [orgName] ='{0}' ORDER BY [order]", SqlTextHelper.SafeQuote(orgName)); DataSet ds = DbHelper.RunSqlReturnDS(sqlCommand, ConnectionName); if (ds != null) { DataTable table = ds.Tables[0]; if (table != null && table.Rows.Count > 0) { WdOrg view = new WdOrg(); ORMapping.DataRowToObject <WdOrg>(table.Rows[0], view); result = view; } } return(result); }
public void SaveArchiveData(ArchiveBasicInfo info) { ORMappingItemCollection mappings = ORMapping.GetMappingInfo <AppCommonInfo>().Clone(); mappings["CREATE_TIME"].BindingFlags |= (ClauseBindingFlags.Update | ClauseBindingFlags.Insert); ORMappingContextCache.Instance[typeof(AppCommonInfo)] = mappings; try { info.Context.DoAction <AppCommonInfo>("AppCommonInfo", acic => { if (acic != null) { acic.Status = ArchiveStatus.Archived; AppCommonInfoAdapter.Instance.Update(acic); } }); } finally { ORMappingContextCache.Instance.Remove(typeof(AppCommonInfo)); } }
internal IList <B_MonthlyReportDetail> GetMonthlyreportdetailList(Guid systemId, int year, int month) { string sql = ORMapping.GetSelectSql <B_MonthlyReportDetail>(TSqlBuilder.Instance); sql += "WHERE " + base.NotDeleted; sql += " AND SystemID=@SystemID and FinYear=@FinYear and FinMonth=@FinMonth"; SqlParameter[] parameters = { new SqlParameter { ParameterName = "@SystemID", Value = systemId }, new SqlParameter { ParameterName = "@FinYear", Value = year }, new SqlParameter { ParameterName = "@FinMonth", Value = month } }; return(ExecuteQuery(sql, parameters)); }
public UserTaskCollection LoadUserTasks(string tableName, IConnectiveSqlClause builder) { UserTaskCollection result = new UserTaskCollection(); if (builder.IsEmpty == false) { string sql = string.Format("SELECT * FROM {0} WHERE {1}", tableName, builder.ToSqlString(TSqlBuilder.Instance)); DataTable table = DbHelper.RunSqlReturnDS(sql, GetConnectionName()).Tables[0]; foreach (DataRow row in table.Rows) { UserTask task = new UserTask(); ORMapping.DataRowToObject(row, task); result.Add(task); } } return(result); }
/// <summary> /// /// </summary> /// <param name="userID"></param> /// <returns></returns> public OpenIDBindingCollection GetBindingsByUserID(string userID) { ExceptionHelper.CheckStringIsNullOrEmpty(userID, "userID"); ORMappingItemCollection mappings = ORMapping.GetMappingInfo(typeof(OpenIDBinding)); string sql = string.Format("SELECT * FROM {0} WHERE USER_ID = {1}", mappings.TableName, TSqlBuilder.Instance.CheckUnicodeQuotationMark(userID)); OpenIDBindingCollection result = new OpenIDBindingCollection(); using (DbContext context = DbContext.GetContext(DataAdapter.DBConnectionName)) { Database db = DatabaseFactory.Create(DataAdapter.DBConnectionName); DataView view = db.ExecuteDataSet(CommandType.Text, sql).Tables[0].DefaultView; ORMapping.DataViewToCollection(result, view); } return(result); }
private UserAndContainerSnapshot GetExistedObject(SCMemberRelation mr) { UserAndContainerSnapshot condition = new UserAndContainerSnapshot(mr); WhereSqlClauseBuilder keyBuilder = ORMapping.GetWhereSqlClauseBuilderByPrimaryKey(condition, this.GetMappingInfo()); string sql = string.Format("SELECT TOP 1 {0} FROM {1} WHERE {2} ORDER BY VersionStartTime DESC", string.Join(",", ORMapping.GetSelectFieldsName(this.GetMappingInfo())), this.GetLoadingTableName(DateTime.MinValue), keyBuilder.ToSqlString(TSqlBuilder.Instance)); DataTable table = DbHelper.RunSqlReturnDS(sql, this.GetConnectionName()).Tables[0]; UserAndContainerSnapshot result = null; if (table.Rows.Count > 0) { result = new UserAndContainerSnapshot(); ORMapping.DataRowToObject(table.Rows[0], result); } return(result); }
protected override void OnBuildQueryCondition(QueryCondition qc) { qc.FromClause = "WF.PROCESS_INSTANCES (NOLOCK)"; if (qc.OrderByClause.IsNullOrEmpty()) { qc.OrderByClause = "START_TIME DESC"; } qc.SelectFields = ORMapping.GetSelectFieldsNameSql <WfProcessCurrentInfo>(); WhereSqlClauseBuilder builder = new WhereSqlClauseBuilder(); builder.AppendItem("COMMITTED", "1"); builder.AppendTenantCode(); if (qc.WhereClause.IsNotEmpty()) { qc.WhereClause += " AND "; } qc.WhereClause += builder.ToSqlString(TSqlBuilder.Instance); }
public void BulkAdd(InvalidAssigneesNotificationCollection data) { if (data.Count == 0) { return; } ORMappingItemCollection mappings = ORMapping.GetMappingInfo <InvalidAssigneesNotification>(); StringBuilder sqlStrB = new StringBuilder(); foreach (InvalidAssigneesNotification item in data) { if (sqlStrB.Length > 0) { sqlStrB.Append(TSqlBuilder.Instance.DBStatementSeperator); } sqlStrB.Append(ORMapping.GetInsertSql(item, mappings, TSqlBuilder.Instance)); } DbHelper.RunSqlWithTransaction(sqlStrB.ToString(), this.GetConnectionName()); }
/// <summary> /// A表获取数据,复制到B表 /// </summary> /// <param name="MonthlyReportID"></param> /// <returns></returns> internal List <B_MonthlyReportDetail> GetMonthlyReportDetail_ByAToB(int FinYear, int FinMonth, Guid SystemID, Guid AreaID, Guid MonthlyReportID, Guid TargetPlanID) { string sql = "GetMonthlyReportDetail_ByAToB "; SqlParameter p1 = CreateSqlParameter("@FinYear", DbType.Int32, FinYear); SqlParameter p2 = CreateSqlParameter("@FinMonth", DbType.Int32, FinMonth); SqlParameter p3 = CreateSqlParameter("@SystemID", DbType.Guid, SystemID); SqlParameter p4 = CreateSqlParameter("@AreaID", DbType.Guid, AreaID); SqlParameter p5 = CreateSqlParameter("@MonthlyReportID", DbType.Guid, MonthlyReportID); SqlParameter p6 = CreateSqlParameter("@TargetPlanID", DbType.Guid, TargetPlanID); DataSet ds = DbHelper.RunSPReturnDS(sql, ConnectionName, p1, p2, p3, p4, p5, p6); List <B_MonthlyReportDetail> data = new List <B_MonthlyReportDetail>(); ds.Tables[0].Rows.Cast <System.Data.DataRow>().ForEach(row => { B_MonthlyReportDetail item = new B_MonthlyReportDetail(); ORMapping.DataRowToObject(row, item); data.Add(item); }); return(data); }
public UserTask GetLatestUserTask(string userID) { string sql = string.Format( "SELECT TOP 1 TASK_GUID, TASK_TITLE, DELIVER_TIME,APPLICATION_NAME, URL, STATUS FROM WF.USER_TASK (NOLOCK) WHERE SEND_TO_USER = {0} ORDER BY DELIVER_TIME DESC", TSqlBuilder.Instance.CheckQuotationMark(userID, true)); UserTask task = null; using (var context = DbContext.GetContext("HB2008")) { using (var dr = DbHelper.RunSqlReturnDR(sql)) { if (dr.Read()) { task = new UserTask(); ORMapping.DataReaderToObject(dr, GetMapptingInfo(), task); } } } return(task); }
public JobBase LoadSingleDataByJobID(IConnectiveSqlClause whereClause) { JobBase result = null; if (whereClause.IsEmpty == false) { using (DbContext context = DbHelper.GetDBContext(GetConnectionName())) { using (IDataReader dr = DbHelper.RunSqlReturnDR(string.Format(SINGLEATA_JOB, whereClause.AppendTenantCodeSqlClause(typeof(JobBase)).ToSqlString(TSqlBuilder.Instance)), GetConnectionName())) { while (dr.Read()) { result = new JobBase(); ORMapping.DataReaderToObject(dr, result); break; } } } } return(result); }
internal PartlyCollection <BBizProcess> LoadList(WorkFlowFilter filter) { StringBuilder strSql = new StringBuilder(); WhereSqlClauseBuilder where = filter.ConvertToWhereBuilder(); where.AppendItem("Isdeleted", 0); where.AppendItem("ProcessType", DBNull.Value); //string sql =new VTodoWorkAndUser().TodoViewSql; QueryCondition qc = new QueryCondition( filter.RowIndex, filter.PageSize, "*", ORMapping.GetTableName(typeof(BBizProcess)), " Createtime desc", where.ToSqlString(TSqlBuilder.Instance) ); PartlyCollection <VBizProcess> tuple = GetPageSplitedCollection(qc); PartlyCollection <BBizProcess> result = new PartlyCollection <BBizProcess>(); foreach (VBizProcess vBizProcess in tuple) { result.Add(new BBizProcess { TaskID = vBizProcess.TaskID, ProcessType = vBizProcess.ProcessType, Title = vBizProcess.Title, ParentID = vBizProcess.ParentID, Status = vBizProcess.Status, IsCurrentVersion = vBizProcess.IsCurrentVersion, AlarmAction = vBizProcess.AlarmAction, AlarmPlanSplitDate = vBizProcess.AlarmPlanSplitDate }); } return(result); }
public List<AURoleDisplayItem> LoadAURoleDisplayItems(string unitID, bool normalOnly, DateTime timePoint) { string sql = @"SELECT SR.Name, SR.CodeName, SR.DisplayName, S.ID, S.SchemaRoleID, S.Status FROM SC.AURoleSnapshot S INNER JOIN SC.SchemaMembers R ON S.ID = R.MemberID AND S.SchemaType = R.MemberSchemaType INNER JOIN SC.AUSchemaRoleSnapshot SR ON SR.ID = S.SchemaRoleID WHERE"; WhereSqlClauseBuilder where = new WhereSqlClauseBuilder(); where.AppendCondition("R.ContainerID", unitID).AppendCondition("R.ContainerSchemaType", AUCommon.SchemaAdminUnit); if (normalOnly) where.NormalFor("R.Status").NormalFor("S.Status").NormalFor("SR.Status"); var timeCondition1 = VersionStrategyQuerySqlBuilder.Instance.TimePointToBuilder(timePoint, "S."); var timeCondition2 = VersionStrategyQuerySqlBuilder.Instance.TimePointToBuilder(timePoint, "SR."); var timeCondition3 = VersionStrategyQuerySqlBuilder.Instance.TimePointToBuilder(timePoint, "R."); sql += new ConnectiveSqlClauseCollection(timeCondition1, timeCondition2, timeCondition3, where).ToSqlString(TSqlBuilder.Instance); List<AURoleDisplayItem> result = new List<AURoleDisplayItem>(); AUCommon.DoDbAction(() => { using (DbContext context = DbContext.GetContext(this.GetConnectionName())) { using (IDataReader dr = DbHelper.RunSqlReturnDR(sql, this.GetConnectionName())) { while (dr.Read()) { AURoleDisplayItem item = new AURoleDisplayItem(); ORMapping.DataReaderToObject<AURoleDisplayItem>(dr, item); result.Add(item); } } } }); return result; }
/// <summary> /// 加载分支流程信息 /// </summary> /// <param name="fillAssignees"></param> /// <param name="activityID"></param> /// <param name="templateKey"></param> /// <param name="includeAborted">是否包含已经作废的流程</param> /// <returns></returns> public WfProcessCurrentInfoCollection LoadByOwnerActivityID(bool fillAssignees, string activityID, string templateKey, bool includeAborted) { activityID.NullCheck("activityID"); WfProcessCurrentInfoCollection result = new WfProcessCurrentInfoCollection(); WhereSqlClauseBuilder builder = new WhereSqlClauseBuilder(); builder.AppendItem("OWNER_ACTIVITY_ID", activityID); if (templateKey.IsNotEmpty()) { builder.AppendItem("OWNER_TEMPLATE_KEY", templateKey); } if (includeAborted == false) { builder.AppendItem("Status", WfProcessStatus.Aborted.ToString(), "<>"); } string fieldNames = ORMapping.GetSelectFieldsNameSql <WfProcessCurrentInfo>(); string sql = string.Format("SELECT {0} FROM WF.PROCESS_INSTANCES WHERE {1}", fieldNames, builder.ToSqlString(TSqlBuilder.Instance)); DataTable table = DbHelper.RunSqlReturnDS(sql, GetConnectionName()).Tables[0]; result.LoadFromDataView(table.DefaultView); if (fillAssignees) { FillAssignees(result); } return(result); }
public StringBuilder InnerUpdateSql(T data, DateTime versionTime, WhereSqlClauseBuilder SqlWhere) { StringBuilder sqlbuilder = new StringBuilder(); ORMappingItemCollection mappings = GetMappingInfo(new Dictionary <string, object>()); if (versionTime == DateTime.MinValue) { versionTime = SNTPClient.AdjustedTime; } sqlbuilder.Append("DECLARE @CURRENTTIME DATETIME"); sqlbuilder.Append(TSqlBuilder.Instance.DBStatementSeperator); sqlbuilder.AppendFormat( @" SET @CURRENTTIME = {0} {3} UPDATE {1} SET VersionEndTime = @CURRENTTIME WHERE {2}; ", TSqlBuilder.Instance.FormatDateTime(versionTime), mappings.TableName, SqlWhere.ToSqlString(TSqlBuilder.Instance), TSqlBuilder.Instance.DBStatementSeperator ); InsertSqlClauseBuilder insertBuilder = ORMapping.GetInsertSqlClauseBuilder(data, mappings, "VersionStartTime"); insertBuilder.AppendItem("VersionStartTime", "@CURRENTTIME", "=", true); string insertSql = string.Format("INSERT INTO {0} {1};", mappings.TableName, insertBuilder.ToSqlString(TSqlBuilder.Instance)); sqlbuilder.Append(TSqlBuilder.Instance.DBStatementSeperator); sqlbuilder.Append(insertSql); sqlbuilder.Append(TSqlBuilder.Instance.DBStatementSeperator); sqlbuilder.Append("SELECT @CURRENTTIME"); return(sqlbuilder); }
/// <summary> /// 根据Container来加载UserAndContainerSnapshot的信息 /// </summary> /// <param name="containerID"></param> /// <param name="timePoint"></param> /// <returns></returns> public SameContainerUserAndContainerSnapshotCollection LoadByContainerID(string containerID, DateTime timePoint) { containerID.CheckStringIsNullOrEmpty("containerID"); ConnectiveSqlClauseCollection timePointBuilder = VersionStrategyQuerySqlBuilder.Instance.TimePointToBuilder(timePoint); WhereSqlClauseBuilder whereBuilder = new WhereSqlClauseBuilder(); whereBuilder.AppendItem("ContainerID", containerID); ConnectiveSqlClauseCollection connectiveBuilder = new ConnectiveSqlClauseCollection(whereBuilder, timePointBuilder); string sql = string.Format("SELECT * FROM {0} WHERE {1}", this.GetLoadingTableName(timePoint), connectiveBuilder.ToSqlString(TSqlBuilder.Instance)); SameContainerUserAndContainerSnapshotCollection result = new SameContainerUserAndContainerSnapshotCollection(); using (DbContext context = DbContext.GetContext(this.GetConnectionName())) { using (IDataReader reader = DbHelper.RunSqlReturnDR(sql, this.GetConnectionName())) { while (reader.Read()) { UserAndContainerSnapshot item = new UserAndContainerSnapshot(); ORMapping.DataReaderToObject(reader, item); if (result.ContainsKey(item.UserID) == false) { result.Add(item); } } } } return(result); }
internal IList <MonthlyReportDetail> GetVMissDetail(Guid SystemID, int Year, int Month, Guid TargetID, bool IsSpecial) { string sql = @"SELECT * FROM ( SELECT a.*,c.CompanyName,c.NeedEvaluation,c.Sequence FROM dbo.A_MonthlyReportDetail a JOIN dbo.A_TargetPlan b ON a.TargetPlanID=b.ID INNER JOIN dbo.C_Company c ON a.SystemID = c.SystemID AND a.CompanyID = c.ID WHERE b.VersionDefault=1 and a.SystemID=@SystemID and a.TargetID=@TargetID ) aa WHERE aa.SystemID=@SystemID AND aa.TargetID=@TargetID AND aa.FinMonth=@Month AND aa.FinYear=@Year" ; if (IsSpecial == false) { sql += " AND IsMissTarget=1"; sql += " ORDER BY Sequence "; } else { sql += " AND NAccumulativeDifference<0 "; sql += " ORDER BY Sequence "; } SqlParameter pSystemID = CreateSqlParameter("@SystemID", System.Data.DbType.Guid, SystemID); SqlParameter pYear = CreateSqlParameter("@Year", System.Data.DbType.String, Year); SqlParameter pMonth = CreateSqlParameter("@Month", System.Data.DbType.String, Month); SqlParameter pTargetID = CreateSqlParameter("@TargetID", System.Data.DbType.Guid, TargetID); var ds = DbHelper.RunSqlReturnDS(sql, ConnectionName, pTargetID, pSystemID, pYear, pMonth); List <MonthlyReportDetail> data = new List <MonthlyReportDetail>(); ds.Tables[0].Rows.Cast <System.Data.DataRow>().ForEach(row => { MonthlyReportDetail item = new MonthlyReportDetail(); ORMapping.DataRowToObject(row, item); data.Add(item); }); return(data); }
private void InsertGroupUsers(WfGroupUserCollection groupUsers) { using (TransactionScope scope = TransactionScopeFactory.Create()) { foreach (WfGroupUser groupUser in groupUsers) { string ingoreUserId = "UserID"; string sql = ORMapping.GetInsertSql(groupUser, TSqlBuilder.Instance, ingoreUserId); try { DbHelper.RunSql(sql, GetConnectionName()); } catch (System.Data.SqlClient.SqlException ex) { if (ex.ErrorCode != 2627) { throw; } } } scope.Complete(); } }
public void Update(string roleID, SOARolePropertyDefinitionCollection properties) { roleID.CheckStringIsNullOrEmpty("roleID"); properties.NullCheck("properties"); StringBuilder strB = new StringBuilder(); strB.AppendFormat("DELETE WF.ROLE_PROPERTIES_DEFINITIONS WHERE {0}", roleID.ToRoleIDCriteria()); foreach (SOARolePropertyDefinition property in properties) { if (strB.Length > 0) { strB.Append(TSqlBuilder.Instance.DBStatementSeperator); } property.RoleID = roleID; strB.AppendFormat(ORMapping.GetInsertSql(property, TSqlBuilder.Instance)); } using (TransactionScope scope = TransactionScopeFactory.Create()) { DbHelper.RunSql(strB.ToString(), GetConnectionName()); scope.Complete(); } string cacheKey = roleID.ToRoleIDCacheKey(); CacheNotifyData notifyData1 = new CacheNotifyData(typeof(SOARolePropertiesDefinitionCache), cacheKey, CacheNotifyType.Invalid); CacheNotifyData notifyData2 = new CacheNotifyData(typeof(SOARolePropertiesCache), cacheKey, CacheNotifyType.Invalid); UdpCacheNotifier.Instance.SendNotifyAsync(notifyData1, notifyData2); MmfCacheNotifier.Instance.SendNotify(notifyData1, notifyData2); }
private void WriteOutputStream(SoapMessage message) { this.newStream.Position = 0; Copy(this.newStream, this.oldStream); if (AccreditSection.GetConfig().AccreditSettings.SoapRecord & message is SoapServerMessage) { if (AccreditSection.GetConfig().AccreditSettings.SoapRecordOutput) { this.newStream.Position = 0; TextReader reader = new StreamReader(this.newStream); this.soapRecorder.OutputStream = reader.ReadToEnd(); } this.soapRecorder.EndDate = DateTime.Now; if (HttpContext.Current != null) { this.soapRecorder.HostIP = HttpContext.Current.Request.UserHostAddress; } string sql = ORMapping.GetInsertSql <SoapRecorder>(this.soapRecorder, TSqlBuilder.Instance); try { OGUCommonDefine.ExecuteNonQuery(sql); } catch (DbException ex) { if (ex.Message.IndexOf("WEB_READ_LOG") > 0) { InitDatabase(sql); } //else // throw ex; } } }
/// <summary> /// Load the class data from the reader /// </summary> protected override void LoadFromReader() { _reader.Read(); _className = _reader.GetAttribute("class"); _assemblyName = _reader.GetAttribute("assembly"); _typeParameter = _reader.GetAttribute("typeParameter"); string orMappingType = _reader.GetAttribute("orMapping"); try { _orMapping = (ORMapping)Enum.Parse(typeof(ORMapping), orMappingType); } catch (Exception ex) { throw new InvalidXmlDefinitionException(String.Format( "The specified ORMapping type, '{0}', is not a valid inheritance " + "type. The valid options are ClassTableInheritance (the default), " + "SingleTableInheritance and ConcreteTableInheritance.", orMappingType), ex); } _id = _reader.GetAttribute("id"); if (!String.IsNullOrEmpty(_id) && _orMapping != ORMapping.ClassTableInheritance) { throw new InvalidXmlDefinitionException("In a superClass definition, an 'id' " + "attribute has been specified for an OR-mapping type other than " + "ClassTableInheritance."); } _discriminator = _reader.GetAttribute("discriminator"); if (!String.IsNullOrEmpty(_discriminator) && _orMapping == ORMapping.ConcreteTableInheritance) { throw new InvalidXmlDefinitionException("In a superClass definition, a 'discriminator' " + "attribute has been specified for OR-mapping type ConcreteTableInheritance"); } if (String.IsNullOrEmpty(_discriminator) && _orMapping == ORMapping.SingleTableInheritance) { throw new InvalidXmlDefinitionException("In a superClass definition, a 'discriminator' " + "attribute is missing where the SingleTableInheritance OR-mapping type has been " + "specified."); } }
///<summary> ///</summary> ///<param name="assemblyName"></param> ///<param name="className"></param> ///<param name="orMapping"></param> ///<param name="id"></param> ///<param name="discriminator"></param> ///<returns></returns> public ISuperClassDef CreateSuperClassDef(string assemblyName, string className, ORMapping orMapping, string id, string discriminator) { return new SuperClassDef(assemblyName, className, orMapping, id, discriminator); }
public void SetORMapping(ORMapping orMapping) { ORMapping = orMapping; }
/// <summary> /// Constructor to create a new super-class /// </summary> /// <param name="superClassDef">The class definition</param> /// <param name="mapping">The type of OR-Mapping to use. See /// the ORMapping enumeration for more detail.</param> public SuperClassDef(IClassDef superClassDef, ORMapping mapping) { _orMapping = mapping; MySuperClassDef = superClassDef; }
private static void LoadInheritedClassdefStructure(out IClassDef parentClassDef, out IClassDef childClassDef, out IClassDef grandchildClassDef, ORMapping orMappingType) { string inheritanceType = orMappingType.ToString(); string discriminator = ""; if (orMappingType == ORMapping.SingleTableInheritance) { discriminator = @"discriminator=""blah"""; } XmlClassLoader loader = new XmlClassLoader(new DtdLoader(), new DefClassFactory()); parentClassDef = loader.LoadClass( @"<class name=""Parent"" assembly=""Habanero.Test""> <property name=""MyBoID"" type=""Guid"" /> <property name=""FakeUCProp"" type=""string"" /> <key name=""UC_Fake""> <prop name=""FakeUCProp"" /> </key> <primaryKey> <prop name=""MyBoID"" /> </primaryKey> </class> "); childClassDef = loader.LoadClass(String.Format( @"<class name=""Child"" assembly=""Habanero.Test""> <superClass class=""Parent"" assembly=""Habanero.Test"" orMapping=""{0}"" {1} /> <property name=""Prop1"" /> <property name=""FakeUCPropChild"" type=""string"" /> <key name=""UC_FakeChild""> <prop name=""FakeUCPropChild"" /> </key> </class> ", inheritanceType, discriminator)); grandchildClassDef = loader.LoadClass(String.Format( @"<class name=""Grandchild"" assembly=""Habanero.Test""> <superClass class=""Child"" assembly=""Habanero.Test"" orMapping=""{0}"" {1} /> <property name=""Prop2"" /> <property name=""FakeUCPropGrandchild"" type=""string"" /> <key name=""UC_FakeGrandchild""> <prop name=""FakeUCPropGrandchild"" /> </key> </class> ", inheritanceType, discriminator)); ClassDef.ClassDefs.Add(parentClassDef); ClassDef.ClassDefs.Add(childClassDef); ClassDef.ClassDefs.Add(grandchildClassDef); }