/// <summary> /// Возвращает коллекцию ключей и значений вида : "дата","норма сотрудника на дату" /// </summary> /// <param name="con"></param> /// <param name="dtStart">Дата начала периода</param> /// <param name="dtEnd">Дата окончания периода</param> /// <param name="dtEnd">Идентификатор сотрудника</param> private Dictionary <DateTime, int> GetDayRates(XStorageConnection con, DateTime dtStart, DateTime dtEnd, Guid uidUserId) { if (dtStart > dtEnd) { throw new ArgumentException("Дата начала периода должна быть меньше даты окончания периода"); } XDbCommand cmd = con.CreateCommand( "SELECT CalendarDate, Rate FROM dbo.GetEmployeeCalendar(@dtStart,@dtEnd,@EmpID) as empCal"); cmd.Parameters.Add("dtStart", DbType.Date, ParameterDirection.Input, false, dtStart); cmd.Parameters.Add("dtEnd", DbType.Date, ParameterDirection.Input, false, dtEnd); cmd.Parameters.Add("EmpID", DbType.Guid, ParameterDirection.Input, false, uidUserId); Dictionary <DateTime, int> dictDateRates = new Dictionary <DateTime, int>(); using (IXDataReader reader = cmd.ExecuteXReader()) { while (reader.Read()) { DateTime dt = reader.GetDateTime(reader.GetOrdinal("CalendarDate")); int nDateRate = reader.GetInt16(reader.GetOrdinal("Rate")); dictDateRates.Add(dt, nDateRate); } } return(dictDateRates); }
/// <summary> /// Загружает поля State, BlockDate в случае, если они еще не загружены и если они обновлялись. /// </summary> /// <param name="xobj"></param> /// <param name="bUpdatedState">Признак обновления поля State</param> /// <param name="bUpdatedBlockDate">Признак обновления поля BlockDate</param> /// <param name="context"></param> private void preloadProps(DomainObjectData xobj, bool bUpdatedState, bool bUpdateIsLocked, IXExecutionContext context) { bool bLoadState = bUpdatedState && !xobj.HasLoadedProp("State"); bool bLoadIsLocked = bUpdateIsLocked && !xobj.HasLoadedProp("IsLocked"); // если надо зачитать хотя бы одно свойство if (bLoadState || bLoadIsLocked) { XDbCommand cmd = context.Connection.CreateCommand(); StringBuilder cmdTextBuilder = new StringBuilder(); cmdTextBuilder.Append("SELECT "); if (bLoadState) { cmdTextBuilder.Append("[State]"); } if (bLoadIsLocked) { if (bLoadState) { cmdTextBuilder.Append(", "); } cmdTextBuilder.Append("[IsLocked]"); } cmdTextBuilder.Append(" FROM "); cmdTextBuilder.Append(context.Connection.GetTableQName(xobj.TypeInfo)); cmdTextBuilder.Append(" WHERE ObjectID = @ObjectID"); cmd.CommandText = cmdTextBuilder.ToString(); cmd.Parameters.Add("ObjectID", DbType.Guid, ParameterDirection.Input, false, xobj.ObjectID); using (IXDataReader reader = cmd.ExecuteXReader()) { if (reader.Read()) { if (bLoadState) { xobj.SetLoadedPropValue("State", reader.GetInt16(reader.GetOrdinal("State"))); } if (bLoadIsLocked) { xobj.SetLoadedPropValue("IsLocked", reader.GetBoolean(reader.GetOrdinal("IsLocked"))); } } } } }
private void readUserActivityTypes(ITUser user, XStorageConnection con) { XDbCommand cmd = con.CreateCommand(); cmd.CommandText = @" SELECT at.ObjectID, at.Name, at.Code, at.AccountRelated, at.FolderType, at.StartDate, at.EndDate FROM dbo.SystemUser_ActivityTypes su_at WITH (nolock) JOIN dbo.ActivityType at WITH (nolock) ON su_at.Value = at.ObjectID WHERE su_at.ObjectID = @ObjectID UNION SELECT at.ObjectID, at.Name, at.Code, at.AccountRelated, at.FolderType, at.StartDate, at.EndDate FROM dbo.SystemUser_SystemRoles su_sr WITH (nolock) JOIN dbo.SystemRole_ActivityTypes sr_at WITH (nolock) ON su_sr.Value = sr_at.ObjectID JOIN dbo.ActivityType at WITH (nolock) ON sr_at.Value = at.ObjectID WHERE su_sr.ObjectID = @ObjectID " ; cmd.Parameters.Add("ObjectID", DbType.Guid, ParameterDirection.Input, false, user.SystemUserID); using (IXDataReader reader = cmd.ExecuteXReader()) { user.ActivityTypes = new Hashtable(); while (reader.Read()) { DomainObject_ActivityType xobj = new DomainObject_ActivityType(); xobj.ObjectID = reader.GetGuid(reader.GetOrdinal("ObjectID")); xobj.Name = reader.GetString(reader.GetOrdinal("Name")); xobj.Code = reader.GetString(reader.GetOrdinal("Code")); xobj.AccountRelated = reader.GetBoolean(reader.GetOrdinal("AccountRelated")); xobj.FolderType = (FolderTypeFlags)reader.GetInt16(reader.GetOrdinal("FolderType")); xobj.StartDate = reader.GetDateTime(reader.GetOrdinal("StartDate")); if (!reader.IsDBNull(reader.GetOrdinal("EndDate"))) { xobj.EndDate = reader.GetDateTime(reader.GetOrdinal("EndDate")); } user.ActivityTypes.Add(xobj.ObjectID, xobj); } } }