예제 #1
0
        private void ButtonLoadFromXml_Click(object sender, EventArgs e)
        {
            this.valutCoursesTable.Visible = false;
            this.valutCoursesTable.Controls.Clear();

            this.openFileDialog1 = new OpenFileDialog()
            {
                InitialDirectory = filePath,
                Title = "Browse Bin file",
                CheckFileExists = true,
                CheckPathExists = true,
                DefaultExt = "xml",
                Filter = "xml file (*.xml)|*.xml",
                FilterIndex = 2,
                RestoreDirectory = true,
                ShowReadOnly = true
            };

            XmlSerializer xmlSer = new XmlSerializer(typeof(ValutCoursesList));

            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                Stream stream = File.Open(openFileDialog1.FileName, FileMode.Open);

                try
                {
                    valutCourses = (ValutCoursesList)xmlSer.Deserialize(stream);
                }
                catch (SecurityException ex)
                {
                    MessageBox.Show($"Security error!\n\nError message: {ex.Message}\n\nDetails: \n\n{ex.StackTrace}");
                }

                stream.Close();
                this.valutCoursesTable = Executor.DrawTableLayoutPanel(valutCourses, this.labelProccessing.Location);
                this.labelProccessing.Visible = false;
                this.valutCoursesTable.CellPaint += DynamicTable_CellPaint;
                this.valutCoursesTable.Visible = true;
                Controls.Add(this.valutCoursesTable);
            }
        }
예제 #2
0
        private void ButtonDownloadCourses_Click(object sender, EventArgs e)
        {
            this.timer.Start();
            valutCourses = new ValutCoursesList();
            WebClient client = new WebClient();
            string site = string.Empty;
            site = Executor.DownloadSite(client);

            this.valutCourses.ExtractValutCourses(site);

            Point labelProccessingPosition = this.labelProccessing.Location;
            this.valutCoursesTable = new TableLayoutPanel();
            this.valutCoursesTable = Executor.DrawTableLayoutPanel(this.valutCourses, labelProccessingPosition);
            string asd = this.valutCoursesTable.ToString();

            this.timer.Stop();
            this.labelProccessing.Visible = false;
            this.valutCoursesTable.CellPaint += DynamicTable_CellPaint;
            this.valutCoursesTable.Visible = true;
            Controls.Add(this.valutCoursesTable);
        }
예제 #3
0
        internal static TableLayoutPanel DrawTableLayoutPanel(ValutCoursesList valutCourses, Point location)
        {
            TableLayoutPanel panel = new TableLayoutPanel
            {
                Location    = new Point(location.X, location.Y + 25),
                Name        = "TableLayoutPanelValutCourses",
                RowCount    = valutCourses.Count + 1,
                ColumnCount = valutCourses.ElementsCount,
                Font        = new Font("Microsoft Sans Serif", 10),
                AutoSize    = true
            };

            panel.RowStyles.Add(new RowStyle(SizeType.AutoSize));

            panel.ColumnStyles.Add(new ColumnStyle(SizeType.AutoSize));
            panel.Controls.Add(new Label()
            {
                Text = "Name", AutoSize = true, TextAlign = ContentAlignment.MiddleLeft
            }, 0, 0);

            panel.ColumnStyles.Add(new ColumnStyle(SizeType.AutoSize));
            panel.Controls.Add(new Label()
            {
                Text = "Code", TextAlign = ContentAlignment.MiddleCenter
            }, 1, 0);

            panel.ColumnStyles.Add(new ColumnStyle(SizeType.AutoSize));
            panel.Controls.Add(new Label()
            {
                Text = "Units count", TextAlign = ContentAlignment.MiddleRight
            }, 2, 0);

            panel.ColumnStyles.Add(new ColumnStyle(SizeType.AutoSize));
            panel.Controls.Add(new Label()
            {
                Text = "Leva", TextAlign = ContentAlignment.MiddleRight
            }, 3, 0);

            panel.ColumnStyles.Add(new ColumnStyle(SizeType.AutoSize));
            panel.Controls.Add(new Label()
            {
                Text = "Reverse course", TextAlign = ContentAlignment.MiddleRight
            }, 4, 0);

            for (int i = 0; i < valutCourses.Count; i++)
            {
                ValutCourse courseInfo = valutCourses.GetValutCourse(i);
                panel.Controls.Add(new Label()
                {
                    Text = courseInfo.Country, AutoSize = true, TextAlign = ContentAlignment.MiddleLeft
                }, 0, i + 1);
                panel.Controls.Add(new Label()
                {
                    Text = courseInfo.CountryCode, TextAlign = ContentAlignment.MiddleCenter
                }, 1, i + 1);
                panel.Controls.Add(new Label()
                {
                    Text = courseInfo.UnitsCount, TextAlign = ContentAlignment.MiddleRight
                }, 2, i + 1);
                panel.Controls.Add(new Label()
                {
                    Text = courseInfo.UnitRate, TextAlign = ContentAlignment.MiddleRight
                }, 3, i + 1);
                panel.Controls.Add(new Label()
                {
                    Text = courseInfo.ReversedUnitRate, TextAlign = ContentAlignment.MiddleRight
                }, 4, i + 1);
            }

            return(panel);
        }