public void Initialize()
        {
            //BSSIDリストの読み込み
            using (var reader = new StreamReader(Environment.CurrentDirectory + "\\bssid_db.txt"))
            {
                string line = "";
                while ((line = reader.ReadLine()) != null)
                {
                    string[] csv = line.Split(',');
                    ShareData.bssids.Add(csv[1]);
                    //Console.WriteLine(csv[1]);
                }
            }

            //部屋番号の読み込み
            using (var reader = new StreamReader(Environment.CurrentDirectory + "\\room_db.txt"))
            {
                string line = "";
                while ((line = reader.ReadLine()) != null)
                {
                    string[] csv  = line.Split(',');
                    Room     room = new Room();
                    room.setNum(csv[0]);
                    room.setRoomName(csv[1]);
                    ShareData.rooms.Add(room);
                    //Console.WriteLine(csv[1]);
                }
            }

            //時間割の読み込み
            using (var reader = new StreamReader(Environment.CurrentDirectory + "\\時間割.txt"))
            {
                string line = "";
                while ((line = reader.ReadLine()) != null)
                {
                    string[]  csv       = line.Split(',');
                    TimeTable timeTable = new TimeTable();
                    timeTable.setName(csv[0]);
                    timeTable.setTime(DateTime.Parse(csv[1]), DateTime.Parse(csv[2]));
                    timeTable.setUnipaName(csv[3]);
                    ShareData.timeTables.Add(timeTable);
                    //Console.WriteLine(csv[0]);
                }
            }
        }
Example #2
0
        private void button1_Click(object sender, EventArgs e)
        {
            //ここからサーバー通信
            WebRequest  req = WebRequest.Create(url + "user_id=" + textBox1.Text + "&password="******"UTF-8"));
                String       result = reader.ReadToEnd();
                if (result.Contains("エラー"))
                {
                    MessageBox.Show("入力内容が違います!\nそれかUNIPAメンテナンス",
                                    "エラー",
                                    MessageBoxButtons.OK,
                                    MessageBoxIcon.Error);
                }
                //エラーでないなら時間割取得成功!JSONが返ってきているはず
                else
                {
                    var json = (dynamic)JsonConvert.DeserializeObject(result);
                    int num  = 0;
                    //string[] dayofWeek = new string[] { "sun", "mon", "tue", "wed", "thu", "fri", "sat" };
                    //曜日ずつforeach
                    foreach (var day in json)
                    {
                        //Console.WriteLine(day.ToString());
                        foreach (var time in day)
                        {
                            //時限ずつforeach
                            foreach (var element in time)
                            {
                                string TimeName = element["TimeName"];
                                string Name     = element["Name"];

                                TimeClass timeClass = new TimeClass();
                                TimeClass unipa     = new TimeClass();
                                timeClass.setType(1);
                                //TimeTableの特定
                                for (int i = 0; i < ShareData.timeTables.Count; i++)
                                {
                                    TimeTable timeTable = ShareData.timeTables[i];
                                    //もし"J1限"といった文字列が同じだったら
                                    if (TimeName == timeTable.getUnipaName())
                                    {
                                        unipa.setTimeTable(TimeName);
                                        unipa.setBeginTime(timeTable.getBeginTime());
                                        unipa.setEndTime(timeTable.getEndTime());
                                        Console.WriteLine(TimeName + "を登録");
                                        break;
                                    }
                                }


                                //もしないときこうなります
                                if (UserData.scheduleClasses.Count == 0)
                                {
                                    ScheduleClass schedule = new ScheduleClass();

                                    schedule.setName(Name);
                                    timeClass.setTimeTable(TimeName);
                                    timeClass.setBeginTime(unipa.getBeginTime());
                                    timeClass.setEndTime(unipa.getEndTime());
                                    timeClass.setOneDay(true, num);
                                    schedule.addTime(timeClass);
                                    UserData.scheduleClasses.Add(schedule);
                                    Console.WriteLine("はじめましての追加" + schedule.getName() + ShareData.dayofWeek[num]);
                                    //新規フォルダ作成
                                    System.IO.DirectoryInfo di = System.IO.Directory.CreateDirectory(Environment.CurrentDirectory + "\\" + schedule.getName());
                                    continue;
                                }
                                //すでにスケジュールが入っている場合
                                else
                                {
                                    for (int i = 0; i < UserData.scheduleClasses.Count; i++)
                                    {
                                        ScheduleClass schedule = UserData.scheduleClasses[i];
                                        if (Name == schedule.getName())
                                        {
                                            //開始時間と終了時間が同じなら曜日のみ追加
                                            for (int j = 0; j < schedule.TimeSize(); j++)
                                            {
                                                timeClass = schedule.getTime(j);
                                                //時限が同じだったら"J1限"といった文字列が同じだったらということ
                                                if (timeClass.getTimeTable() == TimeName)
                                                {
                                                    //曜日の登録
                                                    timeClass.setOneDay(true, num);
                                                    UserData.scheduleClasses[i].renewTime(timeClass, j);
                                                    Console.WriteLine("おきかえました" + UserData.scheduleClasses[i].getName() + ShareData.dayofWeek[num]);
                                                    break;
                                                }
                                                else if (j == schedule.TimeSize() - 1)
                                                {
                                                    TimeClass newTime = new TimeClass();
                                                    newTime.setTimeTable(TimeName);
                                                    newTime.setOneDay(true, num);
                                                    newTime.setBeginTime(unipa.getBeginTime());
                                                    newTime.setEndTime(unipa.getEndTime());
                                                    UserData.scheduleClasses[i].addTime(newTime);
                                                    Console.WriteLine(schedule.getName() + "のタイムを追加");
                                                }
                                            }
                                            break;
                                        }
                                        //その授業のスケジュールが追加されていない場合
                                        else if (i == UserData.scheduleClasses.Count - 1)
                                        {
                                            Console.WriteLine("スケジュールの新規追加");
                                            ScheduleClass newSchedule = new ScheduleClass();
                                            TimeClass     newTime     = new TimeClass();
                                            newSchedule.setName(Name);
                                            newTime.setOneDay(true, num);
                                            newTime.setTimeTable(TimeName);
                                            newTime.setBeginTime(unipa.getBeginTime());
                                            newTime.setEndTime(unipa.getEndTime());
                                            newSchedule.addTime(newTime);
                                            UserData.scheduleClasses.Add(newSchedule);
                                            System.IO.DirectoryInfo di = System.IO.Directory.CreateDirectory(Environment.CurrentDirectory + "\\" + newSchedule.getName());
                                        }
                                    }
                                }
                            }
                        }
                        num++;
                    }
                    //最後にできたという表示をしてウィンドウを閉じる
                    DialogResult message = MessageBox.Show("UNIPAから時間割を追加しました!",
                                                           "正常終了",
                                                           MessageBoxButtons.OK,
                                                           MessageBoxIcon.Information);
                    if (message == DialogResult.Yes)
                    {
                        this.Close();
                    }
                }
                stm.Close();
            }
            rsp.Close();
        }