Exemple #1
0
        private void NotCollectedView_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
        {
            DataGridView dc = (DataGridView)sender;

            NotCollectedData ncd = Configuration.NotCollectedList[e.RowIndex];

            for (int i = 0; i < dc.Columns.Count; i++)
            {
                if (dc.Rows[e.RowIndex].Cells[i].Visible)
                {
                    DataGridViewCellStyle cellstyle = dc.Rows[e.RowIndex].Cells[i].Style;

                    int amount = ncd.Amount;

                    if (amount == 0)
                    {
                        cellstyle.BackColor = System.Drawing.Color.LimeGreen;
                        cellstyle.ForeColor = System.Drawing.Color.Black;
                    }
                    else
                    {
                        cellstyle.BackColor = System.Drawing.Color.WhiteSmoke;
                        cellstyle.ForeColor = System.Drawing.Color.Black;
                    }
                }
            }
        }
        private static void Main()
        {
            LoadOption();

            Configuration.ResourceList.CollectionChanged += ResourceListAll_CollectionChanged;
            Configuration.UnlockedList.CollectionChanged += UnlockedDictionary_CollectionChanged;

            /* Read the resources list from an csv file.
             * This was created by pasting the content (of the resource tables)
             * of 'http://tinyrails.wikia.com/wiki/Resources'
             * to an table calculation program and exported it as an csv file. */

            /* this list contains all resources and their location */
            Csv.ReadResourceFile(FilePathResource);

            /* This list contains the cities and their resources given. */
            Csv.ReadCollectedFile(FilePathCollected);

            /* This list contains the unlocked regions. */
            Csv.ReadUnlockFile(FilePathUnlocked);

            /* Now build the Unlocked Region List and react on changing items */
            foreach (var item in Configuration.ResourceList)
            {
                bool found = false;

                foreach (var inner in Configuration.UnlockedList)
                {
                    if (item.Region == inner.Region)
                    {
                        found = true;
                    }
                }

                if (!found)
                {
                    Configuration.UnlockedList.Add(new UnlockedData()
                    {
                        Region = item.Region, Unlocked = item.Unlocked
                    });
                }

                /* fill the not collected list */
                bool colfound = false;
                foreach (var inner in Configuration.NotCollectedList)
                {
                    if (inner.Resource == item.Resource)
                    {
                        colfound      = true;
                        inner.Amount += item.Amount - item.Collected;
                    }
                }
                if (!colfound)
                {
                    NotCollectedData ncd = new NotCollectedData()
                    {
                        Resource = item.Resource, Amount = item.Amount - item.Collected
                    };
                    Configuration.NotCollectedList.Add(ncd);
                }
            }

            /* now react on changes of the unlocked data */
            foreach (UnlockedData ud in Configuration.UnlockedList)
            {
                ud.PropertyChanged += Unlocked_PropertyChanged;

                /* and set the unlocked features of the resources list */
                foreach (var item in Configuration.ResourceList)
                {
                    if (item.Region == ud.Region)
                    {
                        item.Unlocked = ud.Unlocked;
                    }
                }
            }

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            MainWindow         = new MainForm();
            MainWindow.OnSave += Save;
            Application.Run(MainWindow);

            SaveOption();

            switch (Configuration.SaveOption)
            {
            case ESaveOption.Auto:
                break;

            case ESaveOption.Manual:
            case ESaveOption.OnClose:
                Save();
                break;

            default:
                break;
            }
        }