Exemplo n.º 1
0
 /// <summary>
 /// Wczytuje używane aktualnie dane.
 /// </summary>
 /// <param name="choose">Tablica tabel, które mają zostać wybrane z bazy danych.</param>
 static void ReadDataFromDataBase(int[] choose)
 {
     DataBase = new IDataBase[choose.Length];
     int i = 0;
     foreach (var choosen in choose)
     {
         switch (choosen)
         {
             case 0:
                 DataBase[i++] = new Collectors();
                 break;
             case 1:
                 DataBase[i++] = new Customers();
                 break;
             case 2:
                 DataBase[i++] = new Areas();
                 break;
             case 3:
                 DataBase[i++] = new Addresses();
                 break;
             case 4:
                 DataBase[i++] = new Counters();
                 break;
             default:
                 DataBase[i++] = new Collectors();
                 break;
         }
     }
 }
Exemplo n.º 2
0
        /// <summary>
        /// Inicjalizuje pola rozwijanej listy. Ustawia odpowiednie szerokości kolumn.
        /// </summary>
        /// <returns>Lista zainicjowanych pól. Elementy listy zawierają długi i krótki opis danego pola.</returns>
        private List<ComboBoxItem> InitializeItems()
        {
            List<ComboBoxItem> initializedItems = new List<ComboBoxItem>();
            IDataBase dataBase = null;
            int[] shortDescriptionWords = null;

            switch (tableName)
            {
                case "Collector":
                    dataBase = new Collectors();
                    shortDescriptionWords = new int[] { 1, 2 };
                    widthsOfColumns = new int[7];
                    break;
                case "Customer":
                    dataBase = new Customers();
                    shortDescriptionWords = new int[] { 1, 2 };
                    widthsOfColumns = new int[7];
                    break;
                case "Area":
                    dataBase = new Areas();
                    shortDescriptionWords = new int[] { 1 };
                    widthsOfColumns = new int[3];
                    break;
                case "Address":
                    dataBase = new Addresses();
                    shortDescriptionWords = new int[] { 1, 2, 3 };
                    widthsOfColumns = new int[4];
                    break;
            }

            List<string[]> itemList = dataBase.itemList;
            System.Drawing.Graphics g = comboBox.CreateGraphics();
            System.Drawing.Font f = comboBox.Font;

            string[] nullList = new string[widthsOfColumns.Length];
            for (int i = 0; i < nullList.Length; i++)
            {
                nullList[i] = String.Empty;
                widthsOfColumns[i] = 0;
            }

            initializedItems.Add(new ComboBoxItem(nullList, new int[] { 0 }));
            initializedItems.ElementAt(0).formattedLongItemDescription = String.Empty;

            foreach (string[] item in itemList)
            {

                ComboBoxItem comboBoxItem = new ComboBoxItem(item, shortDescriptionWords);

                for (int j = 0; j < widthsOfColumns.Length; j++)
                {
                    int newWidth = Convert.ToInt32(g.MeasureString(comboBoxItem.fields.ElementAt(j), f).Width);
                    if (newWidth > widthsOfColumns[j])
                        widthsOfColumns[j] = newWidth;
                }

                initializedItems.Add(comboBoxItem);
            }

            return initializedItems;
        }