using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace 電子文書回覧監視ツール {
    public partial class soundcontrol : Form {
        public soundcontrol(Folder folder) {
            InitializeComponent();
            instance = this;
            soundcontrol.folder = folder;
            method1 = new System.Threading.ThreadStart(thread1);
            int0();
        }
        static Folder folder;
        static soundcontrol instance;
        static System.Threading.ThreadStart method1;
        static Label[] lbls;
        static TrackBar[] bars;
        static System.Threading.Thread th;

        private void int0(){
            //テーブル化
            lbls = new Label[] { this.lbl_1, this.lbl_2, this.lbl_3, this.lbl_4, this.lbl_5, this.lbl_6 };
            bars = new TrackBar[] { this.trackBar1, this.trackBar2, this.trackBar3, this.trackBar4, this.trackBar5, this.trackBar6 };
            //復元
            if(soundcontrol.folder.form1.getLoadData("beepSounds") != null){
                for(int i = 0; i < bars.Length; i++) {
                    bars[i].Value = Int32.Parse( soundcontrol.folder.form1.getLoadData("beepSounds").Rows[0][i].ToString());
                }
            }
            
            for(int i = 0; i < bars.Length; i++) {
                lbls[i].Text = bars[i].Value.ToString();
            }
        }

        //終了時に呼ばれる
        static public DataTable getSaveTable() {
            DataTable dt = new DataTable("beepSounds");
            for(int i = 0; i < lbls.Length; i++) {
                dt.Columns.Add();
            }
            dt.Rows.Add(lbls[0].Text,lbls[1].Text,lbls[2].Text,lbls[3].Text,lbls[4].Text,lbls[5].Text);
            return dt;
        }
        
        static public void beep() {
            th = new System.Threading.Thread(new System.Threading.ThreadStart(soundcontrol.method1));
            th.Start();
        }
        
        private void soundcontrol_Load(object sender, EventArgs e) {

        }


        private void trackBar_Scroll(object sender, EventArgs e) {
            for(int i = 0; i < bars.Length; i++){
                if(bars[i].Equals(sender)){
                    lbls[i].Text = ((TrackBar)sender).Value.ToString();
                }
            }
        }


        private void btn戻る_Click(object sender, EventArgs e) {
            this.Hide();
        }

        private void btnテスト_Click(object sender, EventArgs e) {
            
            th = new System.Threading.Thread(new System.Threading.ThreadStart(soundcontrol.method1));
            th.Start();
        }

        static private void thread1() {
            Console.Beep(int.Parse(lbls[0].Text.ToString()), int.Parse(lbls[3].Text.ToString()));
            Console.Beep(int.Parse(lbls[1].Text.ToString()), int.Parse(lbls[4].Text.ToString()));
            Console.Beep(int.Parse(lbls[2].Text.ToString()), int.Parse(lbls[5].Text.ToString()));
        }
    }
}