Ejemplo n.º 1
0
        /// <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")));
                        }
                    }
                }
            }
        }
Ejemplo n.º 2
0
        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);
                }
            }
        }
Ejemplo n.º 3
0
        internal static bool fillEmployeeInfoSection(XMenuSection sec, Guid EmployeeID, XStorageConnection cn)
        {
            using (XDbCommand cmd = cn.CreateCommand(
                       "SELECT " +
                       "	emp.EMail, emp.Phone, emp.PhoneExt, p.Name AS PositionName, o.Home "+
                       "FROM Employee emp " +
                       "	LEFT JOIN Position p ON emp.Position = p.ObjectID "+
                       "	JOIN Organization o ON emp.Organization = o.ObjectID "+
                       "WHERE emp.ObjectID = @ObjectID"
                       ))
            {
                cmd.Parameters.Add("ObjectID", DbType.Guid, ParameterDirection.Input, false, EmployeeID);
                bool   bIsHome;
                string sEMail        = null;
                string sPhone        = null;
                string sPhoneExt     = null;
                string sPositionName = null;
                using (IXDataReader reader = cmd.ExecuteXReader())
                {
                    if (reader.Read())
                    {
                        bIsHome = reader.GetBoolean(reader.GetOrdinal("Home"));
                        if (!reader.IsDBNull(reader.GetOrdinal("EMail")))
                        {
                            sEMail = reader.GetString(reader.GetOrdinal("EMail"));
                        }
                        if (!reader.IsDBNull(reader.GetOrdinal("Phone")))
                        {
                            sPhone = reader.GetString(reader.GetOrdinal("Phone"));
                        }
                        if (!reader.IsDBNull(reader.GetOrdinal("PhoneExt")))
                        {
                            sPhoneExt = reader.GetString(reader.GetOrdinal("PhoneExt"));
                        }
                        if (!reader.IsDBNull(reader.GetOrdinal("PositionName")))
                        {
                            sPositionName = reader.GetString(reader.GetOrdinal("PositionName"));
                        }

                        sec.Items.AddInfoItem("EMail", sEMail);
                        if (bIsHome && sPhoneExt != null)
                        {
                            sec.Items.AddInfoItem("Внутренний телефон", sPhoneExt);
                        }
                        else
                        {
                            sec.Items.AddInfoItem("Телефон",
                                                  (sPhone != null && sPhone.Length > 0 ? sPhone : "") +
                                                  (sPhoneExt != null && sPhoneExt.Length > 0 ? "(" + sPhoneExt + ")" : "")
                                                  );
                        }
                        if (sPositionName != null)
                        {
                            sec.Items.AddInfoItem("Должность", sPositionName);
                        }
                        return(true);
                    }
                }
                return(false);
            }
        }