private void btnQuery_Click(object sender, System.EventArgs e)
        {
            CEWSI.ObjectSetType objResponse = null;

            // Perform the requested query
            try
            {
                // Set up a connection to the web service.
                // Fill in the security headers...
                CEWSI.FNCEWS40PortTypeClient objBinding = WSIUtil.ConfigureBinding(MainForm.User,
                                                                                   MainForm.Domain, MainForm.Password, MainForm.URL);

                // Create a search object
                // Set up the scope for the query
                // Set up the SQL for the search
                CEWSI.RepositorySearch objSearch      = new CEWSI.RepositorySearch();
                CEWSI.ObjectStoreScope objSearchScope = new CEWSI.ObjectStoreScope();
                objSearchScope.objectStore = MainForm.Library;
                objSearch.SearchScope      = objSearchScope;
                objSearch.SearchSQL        = "SELECT SymbolicName, Id, IsHidden, IsSystemOwned, This FROM ClassDefinition ";
                objSearch.SearchSQL        = objSearch.SearchSQL + " WHERE AllowsSubclasses=TRUE";

                if (txtName.Text != "")
                {
                    objSearch.SearchSQL = objSearch.SearchSQL + " AND SymbolicName LIKE '" + txtName.Text + "%'";
                }
                if (!chkIncludeSystem.Checked)
                {
                    objSearch.SearchSQL = objSearch.SearchSQL + " AND IsSystemOwned=FALSE";
                }
                if (!chkIncludeHidden.Checked)
                {
                    objSearch.SearchSQL = objSearch.SearchSQL + " AND IsHidden=FALSE";
                }

                // Execute the search
                objResponse = objBinding.ExecuteSearch(WSIUtil.GetLocalization(), objSearch);
            }
            catch (System.Net.WebException ex)
            {
                MessageBox.Show("An exception occurred while querying: [" + ex.Message + "]");
                return;
            }
            catch (Exception allEx)
            {
                MessageBox.Show("An exception occurred: [" + allEx.Message + "]");
                return;
            }

            // Sanity check the results data
            long lColumnCount = 0;
            long lRowCount    = 0;
            long i;

            if (objResponse == null || objResponse.Object == null)
            {
                MessageBox.Show("The query completed successfully but the results were null!");
                return;
            }
            if (objResponse.Object.Length < 1)
            {
                MessageBox.Show("No results were found for this query.");
                return;
            }
            lColumnCount = objResponse.Object[0].Property.Length;
            if (lColumnCount < 5)
            {
                MessageBox.Show("The query succeeded, but the results are missing requested data");
                return;
            }

            // Query was successful; display a list of result rows
            // First create a data table that has one column for each property
            System.Data.DataColumn dtCol;
            System.Data.DataRow    dtRow;
            CEWSI.PropertyType     prop;

            g_Classes = objResponse.Object;
            lRowCount = g_Classes.Length;
            System.Data.DataTable dtblResults = new System.Data.DataTable("Results");

            // Name
            dtCol              = new System.Data.DataColumn("Name");
            dtCol.DataType     = System.Type.GetType("System.String");
            dtCol.DefaultValue = "";
            dtblResults.Columns.Add(dtCol);

            // Class
            dtCol              = new System.Data.DataColumn("Class");
            dtCol.DataType     = System.Type.GetType("System.String");
            dtCol.DefaultValue = "";
            dtblResults.Columns.Add(dtCol);

            // IsSystem
            dtCol              = new System.Data.DataColumn("IsSystem");
            dtCol.DataType     = System.Type.GetType("System.String");
            dtCol.DefaultValue = "";
            dtblResults.Columns.Add(dtCol);

            // IsHidden
            dtCol              = new System.Data.DataColumn("IsHidden");
            dtCol.DataType     = System.Type.GetType("System.String");
            dtCol.DefaultValue = "";
            dtblResults.Columns.Add(dtCol);

            // Populate the rows
            CEWSI.ObjectReference objRef;
            for (i = 0; i < lRowCount; i++)
            {
                dtRow             = dtblResults.NewRow();
                prop              = g_Classes[i].Property[0];
                dtRow["Name"]     = IdmObjectType.getPropertyValue(prop);
                prop              = g_Classes[i].Property[4];
                objRef            = (CEWSI.ObjectReference)((CEWSI.SingletonObject)prop).Value;
                dtRow["Class"]    = objRef.classId;
                prop              = g_Classes[i].Property[3];
                dtRow["IsSystem"] = IdmObjectType.getPropertyValue(prop);
                prop              = g_Classes[i].Property[2];
                dtRow["IsHidden"] = IdmObjectType.getPropertyValue(prop);

                dtblResults.Rows.Add(dtRow);
            }
            dgrdResults.PreferredColumnWidth = 140;
            dgrdResults.DataSource           = dtblResults;
            dgrdResults.Show();
            btnCreateSubclass.Enabled = true;
            return;
        }
Exemple #2
0
        public static EcmQueryResult QueryDocument(DocumentModel doc, string query, int maxRow = 100)
        {
            EcmQueryResult ret = new EcmQueryResult();

            CEWSI.ObjectSetType objResponse = null;

            // Perform the requested query
            try
            {
                if (doc.IsUseCert == 1)
                {
                    Addcert(doc.EcmUrl);
                }
                // Set up a connection to the web service.
                // Fill in the security headers...
                CEWSI.FNCEWS40PortTypeClient objBinding = WSIUtil.ConfigureBinding(doc.EcmUser, doc.EcmDomain, doc.EcmPassword, doc.EcmUrl);

                // Create a search object
                // Set up the scope for the query
                // Set up the SQL for the search
                CEWSI.RepositorySearch objSearch      = new CEWSI.RepositorySearch();
                CEWSI.ObjectStoreScope objSearchScope = new CEWSI.ObjectStoreScope();
                objSearchScope.objectStore     = doc.ObjectStore;
                objSearch.SearchScope          = objSearchScope;
                objSearch.SearchSQL            = query;
                objSearch.maxElements          = maxRow;
                objSearch.maxElementsSpecified = true;

                // Execute the search
                objResponse = objBinding.ExecuteSearch(WSIUtil.GetLocalization(), objSearch);
            }
            catch (System.Net.WebException ex)
            {
                ret.ErrorCode = -1;
                ret.ErrorMsg  = "An exception occurred while querying: [" + ex.Message + "]\n" + ex.ToString();
                return(ret);
            }
            catch (Exception allEx)
            {
                ret.ErrorCode = -1;
                ret.ErrorMsg  = "An exception occurred: [" + allEx.Message + "]\n" + allEx.ToString();
                return(ret);
            }

            // Sanity check the results data
            long lColumnCount = 0;
            long lRowCount    = 0;
            long i;

            if (objResponse == null || objResponse.Object == null)
            {
                ret.ErrorCode = 1;
                ret.ErrorMsg  = "The query completed successfully but the results were null";
                return(ret);
            }
            if (objResponse.Object.Length < 1)
            {
                ret.ErrorCode = 1;
                ret.ErrorMsg  = "No results were found for this query - exiting";
                return(ret);
            }
            lColumnCount = objResponse.Object[0].Property.Length;
            if (lColumnCount < 1)
            {
                ret.ErrorCode = 1;
                ret.ErrorMsg  = "The query succeeded, but the results contain no properties - exiting";
                return(ret);
            }

            /*
             *          if( lColumnCount > 12 )
             *          {
             *                  MessageBox.Show("The result set has more than 12 columns.  Only the first 12 columns will be displayed");
             *                  lColumnCount = 12;
             *          }
             */

            // Query was successful; display a list of result rows
            // First create a data table that has one column for each property in the
            //  returned data
            System.Data.DataColumn dtCol;
            System.Data.DataRow    dtRow;
            CEWSI.PropertyType     prop;

            CEWSI.ObjectValue[] objObjects = objResponse.Object;
            lRowCount = objObjects.Length;
            System.Data.DataTable dtblResults = new System.Data.DataTable("Results");
            for (i = 0; i < lColumnCount; i++)
            {
                dtCol              = new System.Data.DataColumn(objObjects[0].Property[i].propertyId);
                dtCol.DataType     = System.Type.GetType("System.String");
                dtCol.DefaultValue = "";
                dtblResults.Columns.Add(dtCol);
            }

            // Populate the rows
            for (i = 0; i < lRowCount; i++)
            {
                dtRow = dtblResults.NewRow();
                for (long iCol = 0; iCol < lColumnCount; iCol++)
                {
                    prop = objObjects[i].Property[iCol];
                    dtRow[prop.propertyId] = IdmObjectType.getPropertyValue(prop);
                }
                dtblResults.Rows.Add(dtRow);
            }
            ret.Result    = dtblResults;
            ret.ErrorCode = 1;
            ret.ErrorMsg  = "Success";
            return(ret);
        }
        private void btnQuery_Click(object sender, System.EventArgs e)
        {
            CEWSI.ObjectSetType objResponse = null;

            // Perform the requested query
            try
            {
                // Set up a connection to the web service.
                // Fill in the security headers...
                CEWSI.FNCEWS40PortTypeClient objBinding = WSIUtil.ConfigureBinding(MainForm.User,
                                                                                   MainForm.Domain, MainForm.Password, MainForm.URL);

                // Create a search object
                // Set up the scope for the query
                // Set up the SQL for the search
                CEWSI.RepositorySearch objSearch      = new CEWSI.RepositorySearch();
                CEWSI.ObjectStoreScope objSearchScope = new CEWSI.ObjectStoreScope();
                objSearchScope.objectStore = MainForm.Library;
                objSearch.SearchScope      = objSearchScope;
                objSearch.SearchSQL        = "SELECT ";
                if (txtSelect.Text == "")
                {
                    objSearch.SearchSQL = objSearch.SearchSQL + "*";
                }
                else
                {
                    objSearch.SearchSQL = objSearch.SearchSQL + txtSelect.Text;
                }
                objSearch.SearchSQL = objSearch.SearchSQL + " FROM " + txtFrom.Text;
                if (txtWhere.Text != "")
                {
                    objSearch.SearchSQL = objSearch.SearchSQL + " WHERE " + txtWhere.Text;
                }
                if (txtMaxRows.Text != "")
                {
                    Int32 iRows = System.Int32.Parse(txtMaxRows.Text);
                    objSearch.maxElements          = iRows;
                    objSearch.maxElementsSpecified = true;
                }

                // Execute the search
                objResponse = objBinding.ExecuteSearch(WSIUtil.GetLocalization(), objSearch);
            }
            catch (System.Net.WebException ex)
            {
                MessageBox.Show("An exception occurred while querying: [" + ex.Message + "]");
                return;
            }
            catch (Exception allEx)
            {
                MessageBox.Show("An exception occurred: [" + allEx.Message + "]");
                return;
            }

            // Sanity check the results data
            long lColumnCount = 0;
            long lRowCount    = 0;
            long i;

            if (objResponse == null || objResponse.Object == null)
            {
                MessageBox.Show("The query completed successfully but the results were null!");
                return;
            }
            if (objResponse.Object.Length < 1)
            {
                MessageBox.Show("No results were found for this query - exiting.");
                return;
            }
            lColumnCount = objResponse.Object[0].Property.Length;
            if (lColumnCount < 1)
            {
                MessageBox.Show("The query succeeded, but the results contain no properties - exiting");
                return;
            }

            /*
             * if( lColumnCount > 12 )
             * {
             *      MessageBox.Show("The result set has more than 12 columns.  Only the first 12 columns will be displayed");
             *      lColumnCount = 12;
             * }
             */

            // Query was successful; display a list of result rows
            // First create a data table that has one column for each property in the
            //  returned data
            System.Data.DataColumn dtCol;
            System.Data.DataRow    dtRow;
            CEWSI.PropertyType     prop;

            CEWSI.ObjectValue[] objObjects = objResponse.Object;
            lRowCount = objObjects.Length;
            System.Data.DataTable dtblResults = new System.Data.DataTable("Results");
            for (i = 0; i < lColumnCount; i++)
            {
                dtCol              = new System.Data.DataColumn(objObjects[0].Property[i].propertyId);
                dtCol.DataType     = System.Type.GetType("System.String");
                dtCol.DefaultValue = "";
                dtblResults.Columns.Add(dtCol);
            }

            // Populate the rows
            for (i = 0; i < lRowCount; i++)
            {
                dtRow = dtblResults.NewRow();
                for (long iCol = 0; iCol < lColumnCount; iCol++)
                {
                    prop = objObjects[i].Property[iCol];
                    dtRow[prop.propertyId] = IdmObjectType.getPropertyValue(prop);
                }
                dtblResults.Rows.Add(dtRow);
            }
            dgrdResults.DataSource = dtblResults;
            dgrdResults.Show();
            return;
        }
Exemple #4
0
        public static bool Deletedoc(DocumentModel doc, string docId, int taskId, string userName)
        {
            EcmResult ret = new EcmResult();

            //string mimeType = "application/vnd.openxmlformats-officedocument.wordprocessingml.document";
            //bool isCheckin = false;
            if (doc.IsUseCert == 1)
            {
                Addcert(doc.EcmUrl);
            }

            CEWSI.FNCEWS40PortTypeClient objBinding = WSIUtil.ConfigureBinding(doc.EcmUser, doc.EcmDomain, doc.EcmPassword, doc.EcmUrl);

            CEWSI.ObjectStoreScope objObjectStoreScope = new CEWSI.ObjectStoreScope();
            objObjectStoreScope.objectStore = doc.ObjectStore;

            // Create RepositorySearch
            CEWSI.RepositorySearch objRepositorySearch = new CEWSI.RepositorySearch();
            objRepositorySearch.repositorySearchMode          = CEWSI.RepositorySearchModeType.Rows;
            objRepositorySearch.repositorySearchModeSpecified = true;
            objRepositorySearch.SearchScope = objObjectStoreScope;

            objRepositorySearch.SearchSQL = "SELECT [DocumentTitle],[Id],[DateLastModified],bpmCodeLarge FROM " + doc.DocumentClass + " WHERE Id='" + docId + "' AND bpmCode='" + taskId.ToString() + "' AND NguoiTao='" + userName + "' ORDER BY [DateLastModified]";


            // Invoke the ExecuteSearch operation
            CEWSI.ObjectSetType objObjectSet = objBinding.ExecuteSearch(WSIUtil.GetLocalization(), objRepositorySearch);

            // Display the Document Titles
            int hitCount = (objObjectSet.Object == null) ? 0 : objObjectSet.Object.Length;

            if (hitCount == 0)
            {
                return(true);
            }

            CEWSI.DeleteAction docUnfile = new CEWSI.DeleteAction();

            // Assign the action to the ChangeRequestType element
            CEWSI.ChangeRequestType[] objChangeRequestTypeArray = new CEWSI.ChangeRequestType[1];
            CEWSI.ChangeRequestType   objChangeRequestType      = new CEWSI.ChangeRequestType();
            objChangeRequestTypeArray[0] = objChangeRequestType;

            // Create ChangeResponseType element array
            CEWSI.ChangeResponseType[] objChangeResponseTypeArray;

            // Build ExecuteChangesRequest element and assign ChangeRequestType element array to it
            CEWSI.ExecuteChangesRequest objExecuteChangesRequest = new CEWSI.ExecuteChangesRequest();
            objExecuteChangesRequest.ChangeRequest    = objChangeRequestTypeArray;
            objExecuteChangesRequest.refresh          = true; // return a refreshed object
            objExecuteChangesRequest.refreshSpecified = true;

            objChangeRequestType.Action    = new CEWSI.ActionType[1];
            objChangeRequestType.Action[0] = (CEWSI.ActionType)docUnfile;

            // Specify the target object (Reservation object) for the actions
            objChangeRequestType.TargetSpecification             = new CEWSI.ObjectReference();
            objChangeRequestType.TargetSpecification.classId     = doc.DocumentClass;
            objChangeRequestType.TargetSpecification.objectId    = docId;
            objChangeRequestType.TargetSpecification.objectStore = doc.ObjectStore;
            objChangeRequestType.id = "1";

            // Assign ChangeRequestType element
            objChangeRequestTypeArray[0] = objChangeRequestType;

            // Build ExecuteChangesRequest element and assign ChangeRequestType element array to it
            objExecuteChangesRequest.ChangeRequest    = objChangeRequestTypeArray;
            objExecuteChangesRequest.refresh          = true; // return a refreshed object
            objExecuteChangesRequest.refreshSpecified = true;

            try
            {
                // Call ExecuteChanges operation to implement the Delete object
                objChangeResponseTypeArray = objBinding.ExecuteChanges(WSIUtil.GetLocalization(), objExecuteChangesRequest);
            }
            catch (System.Net.WebException ex)
            {
                Console.WriteLine("An exception occurred while checking out a document: [" + ex.Message + "]");
                return(false);
            }
            catch (Exception ex)
            {
                Console.WriteLine("An exception : [" + ex.Message + "]");
                return(false);
            }

            // The new document object will be returned, unless there is an error
            if (objChangeResponseTypeArray == null || objChangeResponseTypeArray.Length < 1)
            {
                Console.WriteLine("A valid object was not returned from the ExecuteChanges operation");
                return(false);
            }

            return(true);
        }