コード例 #1
0
ファイル: Form1.cs プロジェクト: xkenia/liveresults
 private void button2_Click(object sender, EventArgs e)
 {
     OpenFileDialog ofd = new OpenFileDialog();
     if (ofd.ShowDialog(this) == DialogResult.OK)
     {
         BinaryFormatter bf = new BinaryFormatter();
         FileStream fs = File.OpenRead(ofd.FileName);
         replayEvent = (Event)bf.Deserialize(fs);
         fs.Close();
         lblInfo.Text = "ID: " + replayEvent.CompId + "\r\n" + "Name: " + replayEvent.CompName + "\r\n" + "Start: " + replayEvent.Results.Min(x => x.changed).ToString("yyyy-MM-hh HH:mm:ss") + "\r\n" + "End: " + replayEvent.Results.Max(x => x.changed).ToString("yyyy-MM-hh HH:mm:ss");
     }
 }
コード例 #2
0
ファイル: Form1.cs プロジェクト: xkenia/liveresults
        private void button1_Click(object sender, EventArgs args)
        {
            SaveFileDialog sfd = new SaveFileDialog();
            if (sfd.ShowDialog(this) == DialogResult.OK)
            {
                BinaryFormatter bf = new BinaryFormatter();
                List<Runner> runners = new List<Runner>();
                Event e = new Event();
                List<Result> results = new List<Result>();
                List<RadioControl> radious = new List<RadioControl>();

                MySql.Data.MySqlClient.MySqlConnection conn = new MySql.Data.MySqlClient.MySqlConnection("");
                conn.Open();
                MySql.Data.MySqlClient.MySqlCommand cmd = conn.CreateCommand();
                cmd.CommandText = "select * from runners where tavid=" + textBox1.Text;
                IDataReader reader = cmd.ExecuteReader();

                while (reader.Read())
                {
                    runners.Add(new Runner()
                    {
                        Name = reader["name"] as string,
                        Class = reader["class"] as string,
                        club = reader["club"] as string,
                        dbId = Convert.ToInt32(reader["dbid"])

                    });
                }
                e.Runners = runners.ToArray();
                reader.Close();

                cmd.CommandText = "select * from results where tavid=" + textBox1.Text;
                reader = cmd.ExecuteReader();

                while (reader.Read())
                {
                    results.Add(new Result()
                    {
                        control = Convert.ToInt32(reader["control"]),
                        status = Convert.ToInt32(reader["status"]),
                        time = Convert.ToInt32(reader["time"]),
                        changed = Convert.ToDateTime(reader["changed"]),
                        dbId = Convert.ToInt32(reader["dbid"])

                    });
                }
                e.Results = results.ToArray();
                reader.Close();

                cmd.CommandText = "select * from splitcontrols where tavid=" + textBox1.Text;
                reader = cmd.ExecuteReader();

                while (reader.Read())
                {
                    radious.Add(new RadioControl()
                    {
                        classname = reader["classname"] as string,
                         code = Convert.ToInt32(reader["code"]),
                          corder = Convert.ToInt32(reader["corder"]),
                           name = reader["name"] as string
                    });
                }
                e.RadioControls = radious.ToArray();
                reader.Close();

                cmd.CommandText = "select * from login where tavid=" + textBox1.Text;
                reader = cmd.ExecuteReader();

                if (reader.Read())
                {
                    e.CompDate = Convert.ToDateTime(reader["compDate"]);
                    e.CompId = Convert.ToInt32(textBox1.Text);
                    e.CompName = reader["compname"] as string;
                    e.organizer = reader["organizer"] as string;
                    e.Public = Convert.ToBoolean(reader["public"]);

                }
                reader.Close();

                FileStream fs = File.Create(sfd.FileName);
                bf.Serialize(fs, e);
                fs.Close();
                conn.Close();
            }
        }