// =====================================================================================
        /// <summary>
        /// This class updates the fields on formfield table using field list, RecordUid and usercommon name.
        /// </summary>
        /// <param name="FormRecord">EvForm object</param>
        /// <returns>EvEventCodes: an event code for updating fields</returns>
        /// <remarks>
        /// This method consists of the following steps:
        ///
        /// 1. Iterate through the formfields object.
        ///
        /// 2. If Guid is empty, add new field.
        ///
        /// 3. Return the event code for updating items.
        /// </remarks>
        // -------------------------------------------------------------------------------------
        public EvEventCodes UpdateFields(
            EdRecord FormRecord)
        {
            this.LogMethod("UpdateFields method ");
            this.LogDebug("RecordFieldList.Count: " + FormRecord.Fields.Count);
            this.LogDebug("SubmitRecord: " + FormRecord.State);
            //
            // Initialize the method debug log and the return event code.
            //
            List <SqlParameter> ParmList           = new List <SqlParameter> ( );
            StringBuilder       SqlUpdateStatement = new StringBuilder( );

            //
            // Define the record Guid value for the update queies
            //
            SqlParameter prm = new SqlParameter(EdRecordValues.PARM_RECORD_GUID, SqlDbType.UniqueIdentifier);

            prm.Value = FormRecord.Guid;
            ParmList.Add(prm);

            //
            // Delete the sections
            //
            SqlUpdateStatement.AppendLine("DELETE FROM ED_RECORD_VALUES "
                                          + "WHERE " + EdRecordValues.DB_RECORD_GUID + "= " + EdRecordValues.PARM_RECORD_GUID + ";  \r\n\r\n");

            //
            // Iterate through the formfields object.
            //
            foreach (EdRecordField field in FormRecord.Fields)
            {
                if (field == null)
                {
                    //this.LogDebugValue ( "FIELD NULL" );
                    continue;
                }

                //
                // If the field guid is empty create a new one.
                //
                if (field.Guid == Guid.Empty)
                {
                    field.Guid = Guid.NewGuid( );
                }
                this.LogDebug("field.FormFieldGuid: " + field.FieldGuid);
                this.LogDebug("field.Guid: " + field.Guid);

                //
                // Create the list of update queries and parameters.
                //
                this.GenerateUpdateQueryStatements(
                    SqlUpdateStatement,
                    ParmList,
                    field);

                this._ValueCount++;
            }//END FormField Update Iteration.

            this.LogDebug(SqlUpdateStatement.ToString( ));

            //
            // Convert the list to an array of SqlPararmeters.
            //
            SqlParameter [] parms = new SqlParameter [ParmList.Count];

            for (int i = 0; i < ParmList.Count; i++)
            {
                parms [i] = ParmList [i];
            }

            this.LogDebug(EvSqlMethods.getParameterSqlText(parms));

            //
            // Execute the update command.
            //
            try
            {
                if (EvSqlMethods.QueryUpdate(SqlUpdateStatement.ToString( ), parms) == 0)
                {
                    return(EvEventCodes.Database_Record_Update_Error);
                }
            }
            catch (Exception Ex)
            {
                this.LogDebug(Evado.Model.EvStatics.getException(Ex));
            }

            return(EvEventCodes.Ok);
        }//END UpdateFields method
예제 #2
0
        // ==================================================================================
        /// <summary>
        /// This class updates the appliocation parameter records data object.
        /// </summary>
        /// <param name="Item">EdSelectionList object</param>
        /// <returns>EvEventCodes: an event code for update data object</returns>
        // ----------------------------------------------------------------------------------
        private EvEventCodes updateOptions(EvSelectionList Item)
        {
            this.LogMethod("updateOptions ");
            this.LogValue("ListId: {0}.", Item.ListId);
            this.LogValue("Item.Items.Count: {0}.", Item.Items.Count);
            //
            // Initialize the Sql update query string.
            //
            System.Text.StringBuilder SqlUpdateQuery = new System.Text.StringBuilder( );

            if (Item.Items.Count == 0)
            {
                this.LogValue("No options in the list");

                this.LogMethodEnd("updateOptions ");
                return(EvEventCodes.Ok);
            }

            //
            // Delete the milestone activities for this milestone.
            //
            SqlUpdateQuery.AppendLine("/** DELETE ALL OF OBJECT PARAMETERS FOR THE OBJECT **/");
            SqlUpdateQuery.AppendLine(" DELETE FROM ED_SELECTION_LIST_OPTIONS ");
            SqlUpdateQuery.AppendLine(" WHERE  (EDSL_LIST_ID = '" + Item.ListId + "') ; \r\n");

            for (int count = 0; count < Item.Items.Count; count++)
            {
                EvSelectionList.Item selectionItem = Item.Items [count];
                //
                // Skip the non selected forms
                //
                if (selectionItem == null)
                {
                    continue;
                }

                this.LogDebug("Value: {0}, Description: {1}, Category: {1} ", selectionItem.Value, selectionItem.Description, selectionItem.Category);

                SqlUpdateQuery.AppendLine("Insert Into ED_SELECTION_LIST_OPTIONS ");
                SqlUpdateQuery.AppendLine("( EDSL_LIST_ID, EDS0_NO, EDS0_VALUE, EDSO_DESCRIPTION, EDSO_CATEGORY )  ");
                SqlUpdateQuery.AppendLine("values  ");
                SqlUpdateQuery.AppendLine("('" + Item.ListId + "', ");
                SqlUpdateQuery.AppendLine(" " + selectionItem.No + ", ");
                SqlUpdateQuery.AppendLine("'" + selectionItem.Value + "', ");
                SqlUpdateQuery.AppendLine("'" + selectionItem.Description + "', ");
                SqlUpdateQuery.AppendLine(" '" + selectionItem.Category + "' ); \r\n");
            }//END form list iteration loop.


            if (EvSqlMethods.QueryUpdate(SqlUpdateQuery.ToString( ), null) == 0)
            {
                this.LogValue("Update failed");
                this.LogMethodEnd("updateOptions ");
                return(EvEventCodes.Database_Record_Update_Error);
            }

            this.LogValue("Update completed");
            //
            // Return code
            //
            this.LogMethodEnd("updateOptions ");
            return(EvEventCodes.Ok);
        }//END updateOptions class
        }//END getView method.

        #endregion

        #region Update methods

        // ==================================================================================
        /// <summary>
        /// This class updates the appliocation parameter records data object.
        /// </summary>
        /// <param name="ParameterList">list of EvObjectParameter</param>
        /// <param name="ObjectGuid">parameter's Guid identifier.</param>
        /// <returns>EvEventCodes: an event code for update data object</returns>
        /// <remarks>
        /// This method consists of the following steps:
        ///
        /// 1. Exit, if the FormId or Activity's Guid or the Old activity object's Guid is empty.
        ///
        /// 2. Generate the DB row Guid, if it does not exist.
        ///
        /// 3. Define the SQL query parameters and execute the storeprocedure for updating items.
        ///
        /// 4. Return an event code for updating items.
        ///
        /// </remarks>
        // ----------------------------------------------------------------------------------
        public EvEventCodes updateItems(List <EvObjectParameter> ParameterList, Guid ObjectGuid)
        {
            this.LogMethod("updateItems ");
            this.LogValue("ObjectGuid: " + ObjectGuid);
            this.LogValue("ParameterList count: " + ParameterList.Count);
            //
            // Initialize the Sql update query string.
            //
            System.Text.StringBuilder SqlUpdateQuery = new System.Text.StringBuilder( );

            if (ParameterList.Count == 0)
            {
                this.LogValue("No parameters in the list");

                this.LogMethodEnd("updateItems ");
                return(EvEventCodes.Ok);
            }

            //
            // Delete the milestone activities for this milestone.
            //
            SqlUpdateQuery.AppendLine("/** DELETE ALL OF OBJECT PARAMETERS FOR THE OBJECT **/");
            SqlUpdateQuery.AppendLine(" DELETE FROM EV_OBJECT_PARAMETERS ");
            SqlUpdateQuery.AppendLine(" WHERE  (OBJ_GUID = '" + ObjectGuid + "') ; \r\n");

            for (int count = 0; count < ParameterList.Count; count++)
            {
                EvObjectParameter objectParameter = ParameterList [count];
                //
                // Skip the non selected forms
                //
                if (objectParameter == null)
                {
                    continue;
                }

                objectParameter.Order = count + 1;

                //this.LogDebug ( "Name: {0}, Value: {1} >> ADDED", objectParameter.Name, objectParameter.Value );

                objectParameter.Guid = ObjectGuid;

                SqlUpdateQuery.AppendLine("Insert Into EV_OBJECT_PARAMETERS ");
                SqlUpdateQuery.AppendLine("( OBJ_GUID, OBP_ORDER, OBP_NAME, OBP_TYPE, OBP_VALUE, OBP_OPTIONS )  ");
                SqlUpdateQuery.AppendLine("values  ");
                SqlUpdateQuery.AppendLine("('" + objectParameter.Guid + "', ");
                SqlUpdateQuery.AppendLine(" " + objectParameter.Order + ", ");
                SqlUpdateQuery.AppendLine("'" + objectParameter.Name + "', ");
                SqlUpdateQuery.AppendLine("'" + objectParameter.DataType.ToString( ) + "', ");
                SqlUpdateQuery.AppendLine("'" + objectParameter.Value + "', ");
                SqlUpdateQuery.AppendLine(" '" + objectParameter.Options + "' ); \r\n");
            }//END form list iteration loop.

            //this.LogDebug ( "Sql Query: " + SqlUpdateQuery.ToString ( ) );

            if (EvSqlMethods.QueryUpdate(SqlUpdateQuery.ToString( ), null) == 0)
            {
                this.LogValue("Update failed");
                this.LogMethodEnd("updateItems ");
                return(EvEventCodes.Database_Record_Update_Error);
            }

            this.LogValue("Update completed");
            //
            // Return code
            //
            this.LogMethodEnd("updateItems ");
            return(EvEventCodes.Ok);
        }//END updateItem class
        }//END GetView method.

        #endregion

        #region FormFields Update queries

        // ==================================================================================
        /// <summary>
        /// This class update items on EV_FORM_SECTION table using retrieving form section items values.
        /// </summary>
        /// <param name="Form">EvForm: a form section object</param>
        /// <returns>EvEventCodes: an event code for updating items on formfield object</returns>
        /// <remarks>
        /// This method consists of the following steps:
        ///
        /// 1. Dekete the data for the old Guid.
        ///
        /// 2. Insert the modified data for the new Guid.
        /// </remarks>
        // ----------------------------------------------------------------------------------
        public EvEventCodes UpdateItem(EdRecord Form)
        {
            this.LogMethod("updateItem method. ");
            this.LogDebug("Section Count: " + Form.Design.FormSections.Count);

            //
            // Initialize the debug status and the local variables
            //
            StringBuilder       sbSQL_AddQuery = new StringBuilder( );
            List <SqlParameter> parmList       = new List <SqlParameter> ( );

            if (Form.Guid == Guid.Empty)
            {
                return(EvEventCodes.Identifier_Global_Unique_Identifier_Error);
            }

            //
            // if sections doe not exist exit.
            //
            if (Form.Design.FormSections.Count == 0)
            {
                return(EvEventCodes.Ok);
            }

            //
            // Delete the sections
            //
            sbSQL_AddQuery.AppendLine("DELETE FROM ED_RECORD_SECTIONS "
                                      + "WHERE " + EdRecordSections.DB_LAYOUT_GUID + " = " + EdRecordSections.PARM_FORM_GUID + ";  \r\n");

            SqlParameter prm = new SqlParameter(EdRecordSections.PARM_FORM_GUID, SqlDbType.UniqueIdentifier);

            prm.Value = Form.Guid;
            parmList.Add(prm);

            for (int count = 0; count < Form.Design.FormSections.Count; count++)
            {
                EdRecordSection section = Form.Design.FormSections [count];

                //
                // skip empty sections
                //
                if (section.Title == String.Empty)
                {
                    continue;
                }

                //
                // Set the order if 0
                //
                if (section.Order == 0)
                {
                    section.Order = count + 3;
                }

                //
                // define the section parameters.
                //
                prm       = new SqlParameter(EdRecordSections.PARM_NUMBER + "_" + count, SqlDbType.Int);
                prm.Value = section.No;
                parmList.Add(prm);

                prm       = new SqlParameter(EdRecordSections.PARM_ORDER + "_" + count, SqlDbType.Int);
                prm.Value = section.Order;
                parmList.Add(prm);

                prm       = new SqlParameter(EdRecordSections.PARM_NAME + "_" + count, SqlDbType.VarChar, 30);
                prm.Value = section.Title;
                parmList.Add(prm);

                prm       = new SqlParameter(EdRecordSections.PARM_INSTRUCTIONS + "_" + count, SqlDbType.NText);
                prm.Value = section.Instructions;
                parmList.Add(prm);

                prm       = new SqlParameter(EdRecordSections.PARM_FIELD_NAME + "_" + count, SqlDbType.NVarChar, 20);
                prm.Value = section.FieldId;
                parmList.Add(prm);

                prm       = new SqlParameter(EdRecordSections.PARM_FIELD_VALUE + "_" + count, SqlDbType.NVarChar, 50);
                prm.Value = section.FieldValue;
                parmList.Add(prm);

                prm       = new SqlParameter(EdRecordSections.PARM_ON_MATCH_VISIBLE + "_" + count, SqlDbType.Bit);
                prm.Value = section.OnMatchVisible;
                parmList.Add(prm);

                prm       = new SqlParameter(EdRecordSections.PARM_VISIBLE + "_" + count, SqlDbType.Bit);
                prm.Value = section.OnOpenVisible;
                parmList.Add(prm);

                prm       = new SqlParameter(EdRecordSections.PARM_DEFAULT_DISPLAY_ROLES + "_" + count, SqlDbType.NVarChar, 250);
                prm.Value = section.ReadAccessRoles;
                parmList.Add(prm);

                prm       = new SqlParameter(EdRecordSections.PARM_DEFAULT_EDIT_ROLES + "_" + count, SqlDbType.NVarChar, 250);
                prm.Value = section.EditAccessRoles;
                parmList.Add(prm);

                prm       = new SqlParameter(EdRecordSections.PARM_PERCENT_WIDTH + "_" + count, SqlDbType.Int);
                prm.Value = section.EditAccessRoles;
                parmList.Add(prm);

                //
                // Create the add query .
                //
                sbSQL_AddQuery.AppendLine(" INSERT INTO ED_RECORD_SECTIONS  "
                                          + "(" + EdRecordSections.DB_LAYOUT_GUID
                                          + ", " + EdRecordSections.DB_NUMBER
                                          + ", " + EdRecordSections.DB_ORDER
                                          + ", " + EdRecordSections.DB_NAME
                                          + ", " + EdRecordSections.DB_INSTRUCTIONS
                                          + ", " + EdRecordSections.DB_FIELD_NAME
                                          + ", " + EdRecordSections.DB_FIELD_VALUE
                                          + ", " + EdRecordSections.DB_ON_MATCH_VISIBLE
                                          + ", " + EdRecordSections.DB_VISIBLE
                                          + ", " + EdRecordSections.DB_DEFAULT_DISPLAY_ROLES
                                          + ", " + EdRecordSections.DB_DEFAULT_EDIT_ROLES
                                          + ", " + EdRecordSections.DB_PERCENT_WIDTH
                                          + "  )  \r\n"
                                          + "VALUES ("
                                          + "  " + EdRecordSections.PARM_FORM_GUID
                                          + ", " + EdRecordSections.PARM_NUMBER + "_" + count
                                          + ", " + EdRecordSections.PARM_ORDER + "_" + count
                                          + ", " + EdRecordSections.PARM_NAME + "_" + count
                                          + ", " + EdRecordSections.PARM_INSTRUCTIONS + "_" + count
                                          + ", " + EdRecordSections.PARM_FIELD_NAME + "_" + count
                                          + ", " + EdRecordSections.PARM_FIELD_VALUE + "_" + count
                                          + ", " + EdRecordSections.PARM_ON_MATCH_VISIBLE + "_" + count
                                          + ", " + EdRecordSections.PARM_VISIBLE + "_" + count
                                          + ", " + EdRecordSections.PARM_DEFAULT_DISPLAY_ROLES + "_" + count
                                          + ", " + EdRecordSections.PARM_DEFAULT_EDIT_ROLES + "_" + count
                                          + ", " + EdRecordSections.PARM_PERCENT_WIDTH + "_" + count + " );  \r\n");
            }

            if (parmList.Count > 1)
            {
                //
                // Convert the list to an array of SqlPararmeters.
                //
                SqlParameter [] parms = new SqlParameter [parmList.Count];

                for (int i = 0; i < parmList.Count; i++)
                {
                    parms [i] = parmList [i];
                }

                //
                // Extract the parameters
                //
                this.LogDebug(sbSQL_AddQuery.ToString( ));
                this.LogDebug(EvSqlMethods.getParameterSqlText(parms));

                //
                // Execute the update command.
                //
                try
                {
                    if (EvSqlMethods.QueryUpdate(sbSQL_AddQuery.ToString( ), parms) == 0)
                    {
                        return(EvEventCodes.Database_Record_Update_Error);
                    }
                }
                catch (Exception Ex)
                {
                    this.LogDebug(Evado.Model.EvStatics.getException(Ex));
                }
            } //END parameter list greater then 1
            return(EvEventCodes.Ok);
        }     //END UpdateItem method