Exemplo n.º 1
0
        /// <summary>
        /// Compare with oid fields
        /// </summary>
        /// <param name="instance1">Instance 1</param>
        /// <param name="instance2">Instance 2</param>
        /// <returns>0 if equals, -1 if instance1 is minor, 1 if instance2 is mayor</returns>
        public override int CompareUnionOID(ONInstance instance1, ONInstance instance2)
        {
            // Null Management
            if ((instance1 == null) && (instance2 == null))
            {
                return(0);
            }
            else if (instance1 == null)
            {
                return(-1);
            }
            else if (instance2 == null)
            {
                return(1);
            }

            AdministradorInstance lInstance1 = instance1 as AdministradorInstance;
            AdministradorInstance lInstance2 = instance2 as AdministradorInstance;

            int lCompare = 0;

            // id_Administrador(Asc)
            lCompare = lInstance1.Id_AdministradorAttr.CompareTo(lInstance2.Id_AdministradorAttr);
            if (lCompare != 0)
            {
                return(lCompare);
            }

            return(0);
        }
Exemplo n.º 2
0
        public override bool FilterInMemory(ONInstance instance)
        {
            AdministradorInstance lInstance = instance as AdministradorInstance;

            // SQL Optimized

            return(true);
        }
Exemplo n.º 3
0
        ///<summary> This method adds the order criteria to the SQL statement </summary>
        ///<param name = "onSql"> This parameter represents the SQL component </param>
        ///<param name = "comparer"> This parameter has all the information refering to the order criteria to add to SQL statement</param>
        /// <param name="startRowOid">This parameter has the OID necessary to start the search</param>
        /// <param name="blockSize">This parameter represents the number of instances to be returned</param>
        protected override void AddOrderCriteria(ONSqlSelect onSql, ONOrderCriteria comparer, ONOid startRowOid, int blockSize, ONPath initialPath)
        {
            //Initilizate StartRow
            AdministradorInstance lInstance = null;

            if (startRowOid != null)
            {
                lInstance     = new AdministradorInstance(OnContext);
                lInstance.Oid = startRowOid as AdministradorOid;
            }

            //Default OrderCriteria
            if (comparer == null)
            {
                string lAlias = onSql.GetAlias("Administrador", initialPath);
                if (lInstance != null)
                {
                    onSql.AddOrderBy(lAlias, CtesBD.FLD_ADMINISTRADOR_ID_ADMINISTRADOR, OrderByTypeEnumerator.Asc, lInstance.Oid.Id_AdministradorAttr);
                }
                else
                {
                    onSql.AddOrderBy(lAlias, CtesBD.FLD_ADMINISTRADOR_ID_ADMINISTRADOR, OrderByTypeEnumerator.Asc, null);
                }
                return;
            }

            //Add OrderCriteria
            bool lUseStartRow = (!comparer.InMemory);

            foreach (ONOrderCriteriaItem lOrderCriteriaItem in comparer.OrderCriteriaSqlItem)
            {
                ONPath lPath = new ONPath(lOrderCriteriaItem.OnPath);
                if ((lInstance != null) && (lUseStartRow))
                {
                    ONSimpleType lAttrStartRow = null;

                    if (lPath.Path == "")
                    {
                        lAttrStartRow = lInstance[lOrderCriteriaItem.Attribute] as ONSimpleType;
                    }
                    else
                    {
                        ONCollection lCollection = (lInstance[lPath.Path] as ONCollection);
                        if ((lCollection != null) && (lCollection.Count > 0))
                        {
                            lAttrStartRow = lCollection[0][lOrderCriteriaItem.Attribute] as ONSimpleType;
                        }
                    }
                    onSql.AddOrderBy(AdministradorData.AddPath(onSql, JoinType.LeftJoin, lOrderCriteriaItem.Facet, lPath, null, lOrderCriteriaItem.DomainArgument, false), lOrderCriteriaItem.Attribute, lOrderCriteriaItem.Type, lAttrStartRow);
                    lUseStartRow = (lAttrStartRow != null);
                }
                else
                {
                    onSql.AddOrderBy(AdministradorData.AddPath(onSql, JoinType.LeftJoin, lOrderCriteriaItem.Facet, lPath, null, lOrderCriteriaItem.DomainArgument, false), lOrderCriteriaItem.Attribute, lOrderCriteriaItem.Type, null);
                }
            }
            return;
        }
Exemplo n.º 4
0
        ///<summary>
        /// This method builds the SQL statment to delete the instance in database
        ///</summary>
        ///<param name = instance>
        ///This parameter represents the instance to be deleted in the database
        ///</param>
        public override void UpdateDeleted(ONInstance instance)
        {
            AdministradorInstance lInstance = instance as AdministradorInstance;

            ONSqlDelete lOnSql = new ONSqlDelete();

            lOnSql.AddFrom(CtesBD.TBL_ADMINISTRADOR);
            lOnSql.AddWhere(CtesBD.FLD_ADMINISTRADOR_ID_ADMINISTRADOR, lInstance.Oid.Id_AdministradorAttr);
            Execute(lOnSql);
        }
Exemplo n.º 5
0
        public AdministradorInstance Create_instanceServ(ONInt p_atrid_AdministradorArg, ONString p_passwordArg)
        {
            // Create new context
            using (ONServiceContext lOnContext = new ONServiceContext(OnContext))
            {
                // Call Executive
                AdministradorExecutive lExecutive = new AdministradorExecutive();
                lExecutive.OnContext = lOnContext;
                lExecutive.Instance  = Instance;
                Instance             = lExecutive.Create_instanceServ(p_atrid_AdministradorArg, p_passwordArg);
            }

            return(Instance);
        }
Exemplo n.º 6
0
        /// <summary>This method builds the SQL statement to insert the instance in database</summary>
        /// <param name="instance">This parameter represents the instance to be inserted in the database</param>
        public override void UpdateAdded(ONInstance instance)
        {
            AdministradorInstance lInstance = instance as AdministradorInstance;

            ONSqlInsert lOnSql = new ONSqlInsert();

            lOnSql.AddInto(CtesBD.TBL_ADMINISTRADOR);
            // Field 'id_Administrador'
            lOnSql.AddValue(CtesBD.FLD_ADMINISTRADOR_ID_ADMINISTRADOR, lInstance.Oid.Id_AdministradorAttr);
            // Field 'PassWord'
            lOnSql.AddValue(CtesBD.FLD_ADMINISTRADOR_PASSWORD, lInstance.PassWordAttr);
            lOnSql.AddValue(CtesBD.FLD_ADMINISTRADOR_ESTADOOBJ, lInstance.StateObj);
            lOnSql.AddValue(CtesBD.FLD_ADMINISTRADOR_FUM, new ONDateTime(DateTime.Now));
            Execute(lOnSql);
        }
Exemplo n.º 7
0
        /// <summary>
        /// Load the data retrieved from the Data Base to components of the application
        /// </summary>
        /// <param name="onContext">This parameter has the current context</param>
        /// <param name="columns">This parameter has the data collected from the database</param>
        /// <param name="index">This parameter has the position of the first data to fix in the application</param>
        public static AdministradorInstance LoadFacet(ONContext onContext, ONDisplaySet displaySet, object[] columns, ref int index)
        {
            AdministradorInstance lInstance = new AdministradorInstance(onContext);

            lInstance.Oid = new AdministradorOid();

            // Field 'id_Administrador'
            lInstance.Oid.Id_AdministradorAttr = new ONInt(Convert.ToInt32(columns[index++]));
            // Field 'PassWord'
            lInstance.PassWordAttr = new ONString(((string)columns[index++]).TrimEnd());
            lInstance.StateObj     = new ONString(((string)columns[index++]).TrimEnd());
            lInstance.Lmd          = new ONDateTime((DateTime)columns[index++]);

            lInstance.Modified = false;
            return(lInstance);
        }
Exemplo n.º 8
0
        public static string RetrieveInstances(ONSqlSelect onSql, ONDisplaySet displaySet, ONPath onPath, ONContext onContext)
        {
            string       lAlias    = onSql.CreateAlias(CtesBD.TBL_ADMINISTRADOR, onPath, "Administrador");
            ONDisplaySet lSourceDS = null;

            if (displaySet != null)
            {
                lSourceDS = new ONDisplaySet(displaySet);
                displaySet.Clear();
            }
            if (displaySet == null)
            {
                onSql.AddSelect(lAlias + "." + CtesBD.FLD_ADMINISTRADOR_ID_ADMINISTRADOR + ", " + lAlias + "." + CtesBD.FLD_ADMINISTRADOR_PASSWORD + ", " + lAlias + "." + CtesBD.FLD_ADMINISTRADOR_ESTADOOBJ + ", " + lAlias + "." + CtesBD.FLD_ADMINISTRADOR_FUM);
            }
            else
            {
                displaySet.Add(new ONDisplaySetItem(CtesBD.FLD_ADMINISTRADOR_ID_ADMINISTRADOR));
                onSql.AddSelect(lAlias + "." + CtesBD.FLD_ADMINISTRADOR_ID_ADMINISTRADOR);

                displaySet.Add(new ONDisplaySetItem(CtesBD.FLD_ADMINISTRADOR_PASSWORD));
                onSql.AddSelect(lAlias + "." + CtesBD.FLD_ADMINISTRADOR_PASSWORD);

                displaySet.Add(new ONDisplaySetItem(CtesBD.FLD_ADMINISTRADOR_ESTADOOBJ));
                onSql.AddSelect(lAlias + "." + CtesBD.FLD_ADMINISTRADOR_ESTADOOBJ);

                displaySet.Add(new ONDisplaySetItem(CtesBD.FLD_ADMINISTRADOR_FUM));
                onSql.AddSelect(lAlias + "." + CtesBD.FLD_ADMINISTRADOR_FUM);
            }


            // Related attributes
            if (displaySet != null)
            {
                foreach (ONDisplaySetItem lDisplaySetItem in lSourceDS)
                {
                    if ((lDisplaySetItem.Path.IndexOf(".") > 0) && (lDisplaySetItem.InData) && (!lDisplaySetItem.HasHV))
                    {
                        displaySet.Add(lDisplaySetItem);

                        string lPath      = lDisplaySetItem.Path.Substring(0, lDisplaySetItem.Path.LastIndexOf("."));
                        string lFacetName = AdministradorInstance.GetTargetClass(onContext, typeof(AdministradorInstance), new ONPath(lDisplaySetItem.Path));
                        onSql.AddSelect(AddPath(onSql, JoinType.LeftJoin, lFacetName, new ONPath(lPath), onPath, "", false) + "." + ONInstance.GetFieldNameOfAttribute(typeof(AdministradorInstance), new ONPath(lDisplaySetItem.Path)));
                    }
                }
            }
            return(lAlias);
        }
Exemplo n.º 9
0
        internal AdministradorInstance Create_instanceServ(ONInt p_atrid_AdministradorArg, ONString p_passwordArg)
        {
            if (Instance != null)
            {
                ONFilterList onfilt = new ONFilterList();
                onfilt.Add("QueryByOid", new QueryByOidFilter(Instance.Oid));
                Instance.Find(onfilt);
            }
            // Execute service
            AdministradorAction lAction = new AdministradorAction(OnContext);

            lAction.Instance = new AdministradorInstance(OnContext);
            Instance         = lAction.Create_instanceServ(p_atrid_AdministradorArg, p_passwordArg);

            OnContext.OperationStack.Pop();
            OnContext.OperationStack.Push(Instance);

            return(Instance);
        }
Exemplo n.º 10
0
        protected override ONInstance InhGetInstance(ONContext onContext, ONFilterList onFilterList)
        {
            // Add oid filter to the list
            ONFilterList lOnFilterList = new ONFilterList(onFilterList);

            lOnFilterList.Add("QueryByOid", new QueryByOidFilter(this));

            // Search Instance
            ONInstance lInstance = new AdministradorInstance(onContext);

            lInstance.Oid = this;
            lInstance     = lInstance.Find(lOnFilterList);
            if (lInstance == null)
            {
                lInstance = new AdministradorInstance(onContext);
            }

            return(lInstance);
        }
Exemplo n.º 11
0
        /// <summary>This method builds the SQL statement to edit the instance in database</summary>
        /// <param name="instance">This parameter represents the instance to be modified in the database</param>
        public override void UpdateEdited(ONInstance instance)
        {
            AdministradorInstance lInstance = instance as AdministradorInstance;

            ONSqlUpdate lOnSql = new ONSqlUpdate();

            lOnSql.AddUpdate(CtesBD.TBL_ADMINISTRADOR);
            // Field 'id_Administrador'
            // Update not needed (OID)
            // Field 'PassWord'
            if (lInstance.PassWordAttrModified)
            {
                lOnSql.AddSet(CtesBD.FLD_ADMINISTRADOR_PASSWORD, lInstance.PassWordAttr);
            }
            lOnSql.AddSet(CtesBD.FLD_ADMINISTRADOR_ESTADOOBJ, lInstance.StateObj);
            lOnSql.AddSet(CtesBD.FLD_ADMINISTRADOR_FUM, new ONDateTime(DateTime.Now));

            lOnSql.AddWhere(CtesBD.FLD_ADMINISTRADOR_ID_ADMINISTRADOR, lInstance.Oid.Id_AdministradorAttr);
            Execute(lOnSql);
        }
Exemplo n.º 12
0
        /// <summary>
        /// Executes the SQL statment over the Data Base connected
        /// </summary>
        /// <param name="onSql">This parameter has the current SQL statment</param>
        /// <param name="onFilterList">List of filters to check</param>
        /// <param name="comparer">This parameter has all the information refering to the order criteria to add to SQL statment</param>
        /// <param name="startRowOid">This parameter has the OID necessary to start the search</param>
        /// <param name="blockSize">This parameter represents the number of instances to be returned</param>
        public override ONCollection ExecuteSql(ONSql onSql, ONFilterList onFilterList, ONDisplaySet displaySet, ONOrderCriteria orderCriteria, ONOid startRowOid, int blockSize)
        {
            AdministradorCollection lQuery = null;
            bool lWithStartRow             = (startRowOid != null).TypedValue;
            long lCount = -1;

            if (!lWithStartRow)
            {
                lCount = 0;
            }

            IDataReader     lDataReader      = null;
            ONSQLConnection lOnSQLConnection = null;

            try
            {
                lDataReader = Execute(onSql) as IDataReader;

                AdministradorInstance lInstance    = null;
                AdministradorInstance lAntInstance = null;
                if (lDataReader != null)
                {
                    object[] lColumns;
                    if (displaySet == null)
                    {
                        lColumns = new object[4];
                    }
                    else
                    {
                        lColumns = new object[displaySet.ElementsInData];
                    }

                    lQuery = new AdministradorCollection(OnContext);
                    bool lFoundStartRow = false;
                    while (lDataReader.Read())
                    {
                        lAntInstance = lInstance;

                        // Read Columns
                        lDataReader.GetValues(lColumns);

                        // Read Instance
                        int lIndex = 0;
                        lInstance = LoadFacet(OnContext, displaySet, lColumns, ref lIndex);

                        // Read related attributes
                        if (displaySet != null)
                        {
                            LoadRelated(OnContext, displaySet, lColumns, lIndex, lInstance);
                        }

                        if (lCount >= 0)                         // Add the load instance
                        {
                            if ((onFilterList == null) || (!onFilterList.InMemory))
                            {
                                // Add to the Instance list
                                lQuery.Add(lInstance);
                                lCount++;
                            }
                            else
                            {
                                ONSQLConnection lSQLConnectionOld = (ONSQLConnection)lInstance.OnContext.SqlConnection;

                                // Set another connection because it is imposible to use
                                // the same connection that is used in the DataReader
                                if (lOnSQLConnection == null)
                                {
                                    lOnSQLConnection = GetConnection();
                                }
                                lInstance.OnContext.SqlConnection = lOnSQLConnection;

                                if (onFilterList.FilterInMemory(lInstance))
                                {
                                    // Add to the Instance list
                                    lQuery.Add(lInstance);
                                    lCount++;
                                }

                                lInstance.OnContext.SqlConnection = lSQLConnectionOld;
                            }
                        }
                        else
                        {
                            if ((orderCriteria != null) && (orderCriteria.InMemory))                             // Need to load for ordering in memory after loading
                            {
                                if (lAntInstance != null)
                                {
                                    // Set another connection because it is imposible to use
                                    // the same connection that is used in the DataReader
                                    ONSQLConnection lOnSQLConnectionOld = lInstance.OnContext.SqlConnection as ONSQLConnection;
                                    if (lOnSQLConnection == null)
                                    {
                                        lOnSQLConnection = GetConnection();
                                    }
                                    lInstance.OnContext.SqlConnection = lOnSQLConnection;

                                    int lCompare = orderCriteria.CompareSql(lInstance, lAntInstance);
                                    if (lCompare != 0)
                                    {
                                        if (lFoundStartRow)
                                        {
                                            lCount = 1;
                                        }
                                        else
                                        {
                                            lQuery.Clear();
                                        }
                                    }

                                    // Restores the old connection
                                    lInstance.OnContext.SqlConnection = lOnSQLConnectionOld;
                                }

                                if ((onFilterList == null) || (!onFilterList.InMemory))
                                {
                                    // Add to the Instance list
                                    lQuery.Add(lInstance);
                                }
                                else
                                {
                                    ONSQLConnection lSQLConnectionOld = (ONSQLConnection)lInstance.OnContext.SqlConnection;

                                    // Set another connection because it is imposible to use
                                    // the same connection that is used in the DataReader
                                    if (lOnSQLConnection == null)
                                    {
                                        lOnSQLConnection = GetConnection();
                                    }
                                    lInstance.OnContext.SqlConnection = lOnSQLConnection;

                                    if (onFilterList.FilterInMemory(lInstance))
                                    {
                                        // Add to the Instance list
                                        lQuery.Add(lInstance);
                                    }
                                    else
                                    {
                                        lCount--;
                                    }

                                    lInstance.OnContext.SqlConnection = lSQLConnectionOld;
                                }

                                if (lInstance.Oid.Equals(startRowOid))
                                {
                                    lFoundStartRow = true;
                                }
                            }

                            else if (lInstance.Oid.Equals(startRowOid))                             // Search the start row
                            {
                                lCount = 0;
                            }
                        }

                        // Stop loading
                        if ((blockSize != 0) && (lCount > blockSize))
                        {
                            if (orderCriteria == null)
                            {
                                break;
                            }
                            else
                            {
                                // Set another connection because it is imposible to use
                                // the same connection that is used in the DataReader
                                ONSQLConnection lOnSQLConnectionOld = lInstance.OnContext.SqlConnection as ONSQLConnection;
                                if (lOnSQLConnection == null)
                                {
                                    lOnSQLConnection = GetConnection();
                                }
                                lInstance.OnContext.SqlConnection = lOnSQLConnection;

                                int lCompare = orderCriteria.CompareSql(lInstance, lAntInstance);

                                // Restores the old connection
                                lInstance.OnContext.SqlConnection = lOnSQLConnectionOld;

                                if (lCompare > 0)
                                {
                                    break;
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
                string ltraceItem = "Method: ExecuteSql, Component: AdministradorData";
                if (e is ONSystemException)
                {
                    ONSystemException lException = e as ONSystemException;
                    lException.addTraceInformation(ltraceItem);
                    throw lException;
                }
                throw new ONSystemException(e, ltraceItem);
            }
            finally
            {
                if (lOnSQLConnection != null)
                {
                    ONDBData.CloseConnection(lOnSQLConnection);
                }
                if (lDataReader != null)
                {
                    if (mSqlCommand != null)
                    {
                        mSqlCommand.Cancel();
                    }
                    lDataReader.Close();
                }
                Close();
                if ((onFilterList != null) && (onFilterList.InMemory) && !lWithStartRow && (lCount <= blockSize))
                {
                    lQuery.totalNumInstances = lQuery.Count;
                }
            }

            return(lQuery);
        }
Exemplo n.º 13
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="onContext">This parameter has the current context</param>
 /// <param name="instance">This parameter has the instance that exectues the service</param>
 public AdministradorServer(ONServiceContext onContext, AdministradorInstance instance) : base(onContext, instance, "Administrador")
 {
 }