Example #1
0
        /// <summary>
        /// Resequences the FieldOrders of the MetadataFields effected by the movement of a MetadataField
        /// </summary>
        /// <param name="fieldOrder">the new  order of the moved field</param>
        /// <param name="previousFieldOrder">the order of the field before it was moved</param>
        /// <param name="tableId">the id of the table of the field that was moved</param>
        /// <param name="fieldId">the id of the field that was moved</param>
        private void UpdateFieldOrders(int fieldOrder, int previousFieldOrder, int tableId, int fieldId, bool fieldSuppressed)
        {
            MetadataNewDa MNDa = new MetadataNewDa();

            int numPositionChange;

            // how many positions has the field moved up or down?
            if (previousFieldOrder == -1) // -1 means field order was previously Null
            {
                numPositionChange = -1;
            }
            else
            {
                numPositionChange = fieldOrder - previousFieldOrder;
            }


            if (numPositionChange != 0 || fieldSuppressed) // make sure field moved
            {
                DataSet ReorderRecords = MNDa.GetFieldsForReodering(tableId, fieldId, fieldOrder, numPositionChange);

                int newFieldOrder = 1;                              // field was moved up from previous position

                if (numPositionChange < 0)                          // but if the field was moved down
                {
                    newFieldOrder = fieldOrder + 1;                 //move all fields above and equal to the new field order up one position
                }
                else if (numPositionChange == 0 && fieldSuppressed) // the position wasn't changed but the field was suppressed! reorder everything under where it was
                {
                    newFieldOrder = fieldOrder;
                }

                foreach (DataRow dr in ReorderRecords.Tables[0].Rows)
                {
                    MNDa.IncreaseMetaFieldOrderNumberByOne((int)dr[BOL.MetadataField.FieldId], newFieldOrder);
                    newFieldOrder++;
                }
            }
        }