/// <summary>
 /// Class constructor
 /// </summary>
 /// <param name="dataList">Datalist</param>
 /// <param name="rm">Resource manager</param>
 public CreateIntervalWizard(FerdaSmartDataList dataList, ResourceManager rm)
 {
     //setting the ResManager resource manager and localization string
     this.resManager = rm;
     this.dataList = dataList;
     InitializeComponent();
     this.ChangeLocale(this.resManager);
     this.AddHandlers();
     //Initializing temp category
     this.currentCategory = new Category();
     currentCategory.CatType = CategoryType.Interval;
 }
        /// <summary>
        /// Class constructor
        /// </summary>
        /// <param name="dataList">Datalist to work with</param>
        /// <param name="Enumeration">Enumeration to edit</param>
        /// <param name="rm"></param>
        public EditExistingEnumeration(FerdaSmartDataList dataList, Category Enumeration, ResourceManager rm)
            : base(dataList, rm)
        {
            this.datalist = dataList;
            this.enumeration = Enumeration;
            this.ButtonSubmit.Click -= new EventHandler(Submit_Click);
            this.ButtonSubmit.Click += new EventHandler(Submit_Click_New);
            index = this.datalist.GetIndex(this.enumeration);
            this.TextBoxNewName.Text = this.enumeration.Name;
            foreach (object value in this.enumeration.Set.Values)
            {
                this.ListBoxExistingValues.Items.Add(value);
            }

            // This call is required by the Windows Form Designer.
            InitializeComponent();
        }
 /// <summary>
 /// Class constructor
 /// </summary>
 /// <param name="index">Index of category to edit</param>
 /// <param name="dataList">Datalist to work with</param>
 /// <param name="listView">Listview to display categories</param>
 /// <param name="rm">Resource manager</param>
 public EditExistingCategory(int index, FerdaSmartDataList dataList, MainListView listView, ResourceManager rm)
 {
     if (dataList.GetCategory(index).CatType == Ferda.FrontEnd.AddIns.EditCategories.CategoryType.Interval)
     {
         EditExistingInterval editedInterval = new EditExistingInterval(dataList, dataList.GetCategory(index), rm);
         listView.SuspendLayout();
         editedInterval.Name = "EditIntervalWizard";
         editedInterval.TabIndex = 2;
         editedInterval.Dock = DockStyle.Right;
         listView.splitContainer1.Panel2Collapsed = false;
         listView.splitContainer1.Panel2.Controls.Add(editedInterval);
         listView.MenuItemNew.Enabled = false;
         listView.ButtonNew.Enabled = false;
         listView.ButtonEdit.Enabled = false;
         listView.MenuItemEdit.Enabled = false;
         listView.DoubleClick -= new EventHandler(listView.EditItem);
         editedInterval.Disposed += new EventHandler(listView.ListViewReinitSize);
         listView.ResumeLayout();
         editedInterval.BringToFront();
     }
     else
     {
         EditExistingEnumeration editedEnum = new EditExistingEnumeration(dataList, dataList.GetCategory(index), rm);
         listView.SuspendLayout();
         editedEnum.Name = "EditSetWizard";
         editedEnum.TabIndex = 2;
         editedEnum.Dock = DockStyle.Right;
         listView.splitContainer1.Panel2Collapsed = false;
         listView.splitContainer1.Panel2.Controls.Add(editedEnum);
         listView.MenuItemNew.Enabled = false;
         listView.ButtonNew.Enabled = false;
         listView.ButtonEdit.Enabled = false;
         listView.MenuItemEdit.Enabled = false;
         editedEnum.Disposed += new EventHandler(listView.ListViewReinitSize);
         listView.ResumeLayout();
         editedEnum.BringToFront();
     }
 }
 /// <summary>
 /// Method to convert SmartDataList to CategoriesStruct structure.
 /// </summary>
 /// <param name="dataList"></param>
 /// <returns></returns>
 private CategoriesStruct MyIceRunOut(FerdaSmartDataList dataList)
 {
     CategoriesStruct myCategoriesStruct = new CategoriesStruct();
     myCategoriesStruct.dateTimeIntervals = new DateTimeIntervalCategorySeq();
     myCategoriesStruct.enums = new EnumCategorySeq();
     myCategoriesStruct.floatIntervals = new FloatIntervalCategorySeq();
     myCategoriesStruct.longIntervals = new LongIntervalCategorySeq();
     ArrayList tempArray = new ArrayList();
     foreach (Category multiSet in dataList.Categories)
     {
         switch (multiSet.CatType)
         {
             case CategoryType.Interval:
                 foreach (Interval interval in multiSet.GetIntervals())
                 {
                     if (interval.intervalType == IntervalType.Long)
                     {
                         LongIntervalStruct newLong = new LongIntervalStruct();
                         newLong.leftBound = interval.lowerBound;
                         newLong.rightBound = interval.upperBound;
                         if (interval.lowerBoundType == IntervalBoundType.Round)
                         {
                             newLong.leftBoundType = BoundaryEnum.Round;
                         }
                         else
                         {
                             if (interval.lowerBoundType == IntervalBoundType.Sharp)
                             {
                                 newLong.leftBoundType = BoundaryEnum.Sharp;
                             }
                             else
                             {
                                 newLong.leftBoundType = BoundaryEnum.Infinity;
                             }
                         }
                         if (interval.upperBoundType == IntervalBoundType.Round)
                         {
                             newLong.rightBoundType = BoundaryEnum.Round;
                         }
                         else
                         {
                             if (interval.upperBoundType == IntervalBoundType.Sharp)
                             {
                                 newLong.rightBoundType = BoundaryEnum.Sharp;
                             }
                             else
                             {
                                 newLong.rightBoundType = BoundaryEnum.Infinity;
                             }
                         }
                         tempArray.Add(newLong);
                     }
                     else
                     {
                         if (interval.intervalType == IntervalType.Float)
                         {
                             FloatIntervalStruct newFloat = new FloatIntervalStruct();
                             newFloat.leftBound = interval.lowerBoundFl;
                             newFloat.rightBound = interval.upperBoundFl;
                             if (interval.lowerBoundType == IntervalBoundType.Round)
                             {
                                 newFloat.leftBoundType = BoundaryEnum.Round;
                             }
                             else
                             {
                                 if (interval.lowerBoundType == IntervalBoundType.Sharp)
                                 {
                                     newFloat.leftBoundType = BoundaryEnum.Sharp;
                                 }
                                 else
                                 {
                                     newFloat.leftBoundType = BoundaryEnum.Infinity;
                                 }
                             }
                             if (interval.upperBoundType == IntervalBoundType.Round)
                             {
                                 newFloat.rightBoundType = BoundaryEnum.Round;
                             }
                             else
                             {
                                 if (interval.upperBoundType == IntervalBoundType.Sharp)
                                 {
                                     newFloat.rightBoundType = BoundaryEnum.Sharp;
                                 }
                                 else
                                 {
                                     newFloat.rightBoundType = BoundaryEnum.Infinity;
                                 }
                             }
                             tempArray.Add(newFloat);
                         }
                     }
                 }
                 if (multiSet.GetIntervalType() == IntervalType.Long)
                 {
                     myCategoriesStruct.longIntervals.Add(multiSet.Name, (LongIntervalStruct[])tempArray.ToArray(typeof(LongIntervalStruct)));
                     tempArray.Clear();
                 }
                 else
                 {
                     if (multiSet.GetIntervalType() == IntervalType.Float)
                     {
                         myCategoriesStruct.floatIntervals.Add(multiSet.Name, (FloatIntervalStruct[])tempArray.ToArray(typeof(FloatIntervalStruct)));
                         tempArray.Clear();
                     }
                 }
                 break;
             case CategoryType.Enumeration:
                 tempArray = multiSet.Set.Values;
                 String[] tempString = new String[tempArray.Count];
                 for (int i = 0; i < tempArray.Count; i++)
                 {
                     tempString[i] = tempArray[i].ToString();
                 }
                 try
                 {
                     myCategoriesStruct.enums.Add(multiSet.Name, tempString);
                 }
                 catch (System.ArgumentException)
                 {
                     throw (new System.ApplicationException());
                 }
                 tempArray.Clear();
                 break;
             default:
                 break;
         }
     }
     return myCategoriesStruct;
 }
        /// <summary>
        /// Method to initialize listview using ice structures
        /// </summary>
        /// <param name="existingCategories">Categories to fill in FerdaSmartDataList</param>
        /// <returns>FerdaSmartDataList with categories</returns>
        private FerdaSmartDataList MyIceRun(Modules.CategoriesStruct existingCategories)
        {
            //here we need to fill our data structure with data from ice
            ArrayList allValues = new ArrayList();
            if (this.distinctValues != null)
            {
                foreach (string value in this.distinctValues)
                {
                    allValues.Add(value);
                }
            }

            FerdaSmartDataList returnList = new FerdaSmartDataList(allValues, new ArrayList());
            foreach (DictionaryEntry myEnumCategorySeq in existingCategories.enums)
            {
                Category newMultiset = new Category();
                newMultiset.CatType = CategoryType.Enumeration;
                newMultiset.Name = myEnumCategorySeq.Key.ToString();
                ArrayList tempArray = new ArrayList();
                String[] StringSeq = (String[])myEnumCategorySeq.Value;
                foreach (string entry in StringSeq)
                {
                    tempArray.Add(entry);
                }
                SingleSet newSet = new SingleSet(tempArray);
                newMultiset.AddSingleSet(newSet);
                returnList.AddNewCategoryDirect(newMultiset);
            }

            foreach (DictionaryEntry myLongIntervalCategorySeq in existingCategories.longIntervals)
            {
                Category newMultiset = new Category();
                newMultiset.CatType = CategoryType.Interval;
                newMultiset.Name = myLongIntervalCategorySeq.Key.ToString();
                LongIntervalStruct[] myLongIntervalStructSeq = (LongIntervalStruct[])myLongIntervalCategorySeq.Value;
                foreach (LongIntervalStruct myLongIntervalStruct in myLongIntervalStructSeq)
                {
                    IntervalBoundType ubt, lbt;
                    if (myLongIntervalStruct.leftBoundType == BoundaryEnum.Infinity)
                    {
                        lbt = IntervalBoundType.Infinity;
                    }
                    else
                    {
                        if (myLongIntervalStruct.leftBoundType == BoundaryEnum.Round)
                        {
                            lbt = IntervalBoundType.Round;
                        }
                        else
                        {
                            lbt = IntervalBoundType.Sharp;
                        }
                    }
                    if (myLongIntervalStruct.rightBoundType == BoundaryEnum.Infinity)
                    {
                        ubt = IntervalBoundType.Infinity;
                    }
                    else
                    {
                        if (myLongIntervalStruct.rightBoundType == BoundaryEnum.Round)
                        {
                            ubt = IntervalBoundType.Round;
                        }
                        else
                        {
                            ubt = IntervalBoundType.Sharp;
                        }
                        Interval newInterval = new Interval(IntervalType.Long);
                        newInterval.lowerBound = myLongIntervalStruct.leftBound;
                        newInterval.upperBound = myLongIntervalStruct.rightBound;
                        newInterval.lowerBoundType = lbt;
                        newInterval.upperBoundType = ubt;
                        //Interval newInterval = new Interval((int)myLongIntervalStruct.leftBound, (int)myLongIntervalStruct.rightBound, lbt, ubt);
                        //  newInterval.intervalType = IntervalType.Long
                        newMultiset.AddInterval(newInterval);
                    }
                    returnList.AddNewCategoryDirect(newMultiset);
                }
            }

            foreach (DictionaryEntry myFloatIntervalCategorySeq in existingCategories.floatIntervals)
            {
                Category newMultiset = new Category();
                newMultiset.CatType = CategoryType.Interval;
                newMultiset.Name = myFloatIntervalCategorySeq.Key.ToString();
                FloatIntervalStruct[] myFloatIntervalStructSeq = (FloatIntervalStruct[])myFloatIntervalCategorySeq.Value;
                foreach (FloatIntervalStruct myFloatIntervalStruct in myFloatIntervalStructSeq)
                {
                    IntervalBoundType ubt, lbt;
                    if (myFloatIntervalStruct.leftBoundType == BoundaryEnum.Infinity)
                    {
                        lbt = IntervalBoundType.Infinity;
                    }
                    else
                    {
                        if (myFloatIntervalStruct.leftBoundType == BoundaryEnum.Round)
                        {
                            lbt = IntervalBoundType.Round;
                        }
                        else
                        {
                            lbt = IntervalBoundType.Sharp;
                        }
                    }
                    if (myFloatIntervalStruct.rightBoundType == BoundaryEnum.Infinity)
                    {
                        ubt = IntervalBoundType.Infinity;
                    }
                    else
                    {
                        if (myFloatIntervalStruct.rightBoundType == BoundaryEnum.Round)
                        {
                            ubt = IntervalBoundType.Round;
                        }
                        else
                        {
                            ubt = IntervalBoundType.Sharp;
                        }
                        Interval newInterval = new Interval(IntervalType.Float);
                        newInterval.lowerBoundFl = myFloatIntervalStruct.leftBound;
                        newInterval.upperBoundFl = myFloatIntervalStruct.rightBound;
                        newInterval.lowerBoundType = lbt;
                        newInterval.upperBoundType = ubt;
                        //     Interval newInterval = new Interval(myFloatIntervalStruct.leftBound, myFloatIntervalStruct.rightBound, lbt, ubt);
                        newMultiset.AddInterval(newInterval);
                    }
                    returnList.AddNewCategoryDirect(newMultiset);
                }
            }
            return returnList;
        }
 /// <summary>
 /// Method to display FerdaSmartDataList using a ListView component
 /// </summary>
 /// <param name="smartList">SmartDataList to display</param>
 /// <param name="form">Form to display the SmartDataList in</param>
 public void SmartDataListToListView(FerdaSmartDataList smartList, ListView listView)
 {
     foreach (Category multiSet in smartList.Categories)
     {
         ListViewItem item = new ListViewItem(multiSet.Name, 1);
         switch (multiSet.CatType)
         {
             case CategoryType.Interval:
                 item.SubItems.Add(this.resManager.GetString("TypeInterval"));
                 break;
             case CategoryType.Enumeration:
                 item.SubItems.Add(this.resManager.GetString("TypeSet"));
                 break;
             default:
                 throw new Exception("Switch branch not implemented");
         }
         item.SubItems.Add(multiSet.ToString());
         //tag contains index of the value in the array of multisets
         item.Tag = smartList.GetIndex(multiSet);
         listView.Items.Add(item);
     }
 }
 /// <summary>
 /// Contructor which creates editcategories instance and fills in the needed values
 /// </summary>
 /// <param name="localePrefs">Current locale</param>
 /// <param name="categories">Categories to edit</param>
 /// <param name="distinctValues">Distinct values for enum categories</param>
 public MainListView(string[] localePrefs, CategoriesStruct categories, string[] distinctValues, IOwnerOfAddIn ownerOfAddin)
 {
     //setting the ResManager resource manager and localization string
     string locale;
     try
     {
         locale = localePrefs[0];
         localizationString = locale;
         locale = "Ferda.FrontEnd.AddIns.EditCategories.Localization_" + locale;
         resManager = new ResourceManager(locale, Assembly.GetExecutingAssembly());
     }
     catch
     {
         this.resManager = new ResourceManager("Ferda.FrontEnd.AddIns.EditCategories.Localization_en-US",
     Assembly.GetExecutingAssembly());
         localizationString = "en-US";
     }
     this.distinctValues = distinctValues;
     this.ownerOfAdd = ownerOfAddin;
     this.path = Assembly.GetExecutingAssembly().Location;
     InitializeComponent();
     this.ChangeLocale(this.resManager);
     bigDataList = this.MyIceRun(categories);
     FillEditCategoriesListView(CategoriesListView);
     //adding a handling method for column sorting
     this.CategoriesListView.ColumnClick += new System.Windows.Forms.ColumnClickEventHandler(this.listView1_ColumnClick);
     this.LoadIcons();
     this.InitIcons();
 }
        /// <summary>
        /// Class constructor
        /// </summary>
        /// <param name="dataList">Datalist to work with</param>
        /// <param name="editedInterval">Edited interval category</param>
        /// <param name="rm">resource manager</param>
        public EditExistingInterval(FerdaSmartDataList dataList, Category editedInterval, ResourceManager rm)
            : base(dataList, rm)
        {
            this.datalist = dataList;
            this.interval = new Category();
            this.interval.CatType = CategoryType.Interval;
            this.interval.Name = editedInterval.Name;
            this.interval.Frequency = editedInterval.Frequency;
            foreach (Interval inter in editedInterval.GetIntervals())
            {
                this.interval.AddInterval(inter);
            }
            this.currentCategory = editedInterval;
            this.index = datalist.GetIndex(this.currentCategory);
            this.TextBoxCategoryName.Text = editedInterval.Name;
            Interval tempInterval = (Interval)editedInterval.GetIntervals()[0];
            switch (tempInterval.intervalType)
            {
                case IntervalType.Long:
                    this.TextBoxLeftBound.Text = tempInterval.lowerBound.ToString();
                    this.TextBoxRightBound.Text = tempInterval.upperBound.ToString();
                    break;

                case IntervalType.Float:
                    this.TextBoxLeftBound.Text = tempInterval.lowerBoundFl.ToString();
                    this.TextBoxRightBound.Text = tempInterval.upperBoundFl.ToString();
                    break;

                default:
                    throw new Exception("Switch branch not implemented");
            }

            foreach (Interval inter in editedInterval.GetIntervals())
            {
                this.ListBoxIntervals.Items.Add(inter.ToString());
                if (this.ListBoxIntervals.Items.Count > 0)
                {
                    this.ListBoxIntervals.SelectedIndex = 0;
                }
            }
            this.CheckIntervalTypesConsistency();
            this.ButtonCancel.Click -= new System.EventHandler(this.CancelButton_Click);
            this.ButtonCancel.Click += new System.EventHandler(this.ButtonNewCancel_Click);

            //initialiazing controls according to the interval
            if (tempInterval.lowerBoundType == IntervalBoundType.Infinity)
            {
                this.RadioMinusInfinity.Checked = true;
            }
            else
            {
                if (tempInterval.lowerBoundType == IntervalBoundType.Round)
                {
                    this.RadioLeftBoundRound.Checked = true;
                }
                else
                {
                    this.RadioLeftBoundSharp.Checked = true;
                }
            }

            if (tempInterval.upperBoundType == IntervalBoundType.Infinity)
            {
                this.RadioPlusInfinity.Checked = true;
            }
            else
            {
                if (tempInterval.upperBoundType == IntervalBoundType.Round)
                {
                    this.RadioRightBoundRound.Checked = true;
                }
                else
                {
                    this.RadioRightBoundSharp.Checked = true;
                }
            }
            this.datalist.RemoveCategory(index);
            InitializeComponent();
        }