// Create Attribute Type/Definition /*************************************************************** © Copyright 2008 DXLScripts.com, Inc. All rights reserved *************************************************************** This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA or contact http://www.gnu.org If you make modifications or find defects please contact support@dxlscripts.com Version 1.0 GNU Release */ Module m = current if (null m) { // ack "You must run this from an existing module" halt } DB attrDB = create ("Create Attribute Definition, © Copyright 2008 DXLScripts.com - V1.0:",styleCentered | styleStandard) DBE attrNameDBE = null DBE fileNameDBE = null DBE fileSelectorDBE = null DBE createOptionsDBE = null DBE attrPropDBE = null warningBox "This DXL Modifies Attribute Definitions. You must save the module to commit the changes." string createOptions[] = {"Delete Attribute if Exist", "Delete Attribute Type if Exist"} string attrProps[] = {"Object Attribute", "Module Attribute", "Multi-Valued","Inherit Value", "Affect Change Bars", "Affect Change Dates","Generate History","Hide Definition"} void createAttr(DB) { AttrType at = find(m, get(attrNameDBE)) AttrDef ad = find(m, get(attrNameDBE)) string attrName = get(attrNameDBE) bool deleteAttr = false bool deleteType = false string createOptions[] = {"Delete Attribute if Exist", "Delete Attribute Type if Exist"} int maxCreateOptions = sizeof(createOptions) - 1 int bitmap = get(createOptionsDBE) int remain, i for i in 0:maxCreateOptions do { remain = bitmap % 2 // remainder if (remain != 0) { if (i == 0) deleteAttr = true if (i == 1) deleteType = true }else { // Options not selected. Do nothing! } bitmap = bitmap / 2 // integer division } bool objectAttr = false; modAttr = false; multiVal = false;inheritVal = false; affectBars = false; affectDates = false; genHist = false; hideDef = false string attrProps[] = {"Object Attribute", "Module Attribute", "Multi-Valued","Inherit Value", "Affect Change Bars", "Affect Change Dates","Generate History","Hide Definition"} int maxAttrOptions = sizeof(attrProps) - 1 bitmap = get(attrPropDBE) remain = 0; a = 0 for i in 0:maxAttrOptions do { remain = bitmap % 2 // remainder if (remain != 0) { if (i == 0) objectAttr = true if (i == 1) modAttr = true if (i == 2) multiVal = true if (i == 3) inheritVal = true if (i == 4) affectBars = true if (i == 5) affectDates = true if (i == 6) genHist = true if (i == 7) hideDef = true } bitmap = bitmap / 2 // integer division } if (deleteAttr == false && exists attribute(attrName)) { ack "Attribute: \"" attrName "\" exist!\n\nYour current settings do not allow this operation." halt } if ((deleteType == false or deleteAttr == false) && !null at) { ack "Attribute Type: \"" attrName "\" Exist!\n\nYour current settings do not allow this operation." halt } string err if (deleteAttr == true && !null ad) { mess = delete(ad) } if (deleteType == true && !null at) { delete(at,err) } at = find(m, get(attrNameDBE)) ad = find(m, get(attrNameDBE)) if(null at && null ad) { string s = readFile(get(fileSelectorDBE)) if (s == "") { ack "Error Opening the File. Check to see if the file exist!" halt } Stream input = read get(fileSelectorDBE) int count = 0 string in_values Skip in_ValuesSkip = createString for (input >> in_values; !end input; input >> in_values) { if (in_values == "") { continue }else { put(in_ValuesSkip, in_values, in_values) } } for in_values in in_ValuesSkip do { count++ } close input string names[count] int values[count] int i = 0 for in_values in in_ValuesSkip do { names[i] = in_values values[i] = 0 i++ } string mess = "" at = create(get(attrNameDBE), names, values, mess) if (!null mess) ack "Type type creation failed\n" delete in_ValuesSkip if (objectAttr == false && modAttr == false) { warningBox "Both Object Attribute and Module Attribute check boxes were deselected!" //- "\n\nCreating Object Attribute" int propErr = get(attrPropDBE) set(attrPropDBE, (propErr+1)) } AttrDef ad = create type attrName history genHist changeBars affectBars date affectDates inherit inheritVal multi multiVal hidden hideDef attribute attrName if (objectAttr == false && modAttr == true) { ad = modify(ad, setModule, modAttr) ad = modify(ad, setObject, objectAttr) } if (objectAttr == true && modAttr == true) { ad = modify(ad, setModule, modAttr) ad = modify(ad, setObject, objectAttr) } if (!null mess) ack ("An error occurred\t" mess) infoBox ("Attribute Created") }else { ack "An error occurred while trying to create the attribute!" } } void helpMe(DB) { infoBox (//- "Creation Options:\n" //- "Delete Attribute if Exist: Delete the attribute definition and all set values.\n" //- "Delete Attribute Type if Exist: Delete the attribute type definition.\n" //- "Attribute Name: Name of the new attribute/type to create.\n" //- "Attribute Options:\n" //- "Object Attribute: Define the attribute for the Objects (Default).\n" //- "Module Attribute: Define the attribute for the Module.\n" //- "Multi-Valued: Enable the attribute to have multiple values selected.\n" //- "Inherit Value: Enables the attribute value to be obtained from it's parent Object (Object Attributes Only).\n" //- "Affect Change Bars: If the attribute value is changed the change bar is affected.\n" //- "Affect Change Dates: If the attribute value is changed the objects change date is affected.\n" //- "Generate History: Capture the history when the attribute values change.\n" //- "Hide Definition: Definition is only visible when displaying advanced system attributes\n" //- "Input File Name: Name of input file where the attribute values are listed. One per line with a line feed after each value." //- ) } createOptionsDBE = checkBox(attrDB, "Creation Options: ", createOptions, 0) attrNameDBE = field(attrDB,"Attribute Name:","",60,false) attrPropDBE = verticalCheckBox(attrDB, "Attribute Properties: ", attrProps, 100) fileNameDBE = label(attrDB,"Input File Name:") fileSelectorDBE = fileName(attrDB, "BROWSE", "*.txt", "Input files",true) apply(attrDB, "Create Attribute",createAttr) apply(attrDB, "Help",helpMe) setSize(attrDB,640,480) realize(attrDB) show (attrDB)