Example #1
0
        /// <summary>
        /// 添加课程到课程表
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void AddCourse_Click(object sender, RoutedEventArgs e)
        {
            //ClassInfoListBox.SelectedItems
            //ClassListBox.SelectedItem
            //ClassroomListBox.SelectedItem
            if (ClassroomListBox.SelectedItem is null || ClassListBox.SelectedItem is null || ClassInfoListBox.SelectedItem is null)
            {
                return;
            }
            Button          button        = sender as Button;
            ClassroomInfo   classroomInfo = ClassroomListBox.SelectedValue as ClassroomInfo;
            TeachingProject tp            = ClassListBox.SelectedValue as TeachingProject;

            Course course = new Course()
            {
                CourseName = tp.CourseName,
                Teacher    = tp.Teacher,
                Classroom  = classroomInfo.ClassroomNumber
            };

            foreach (var item in ClassInfoListBox.SelectedItems)
            {
                ClassInfo classInfo = (ClassInfo)item;

                if (classInfo.Timetables is null)
                {
                    classInfo.Timetables = new Dictionary <Button, Course>();
                }

                if (classInfo.Timetables.ContainsKey(button))
                {
                    if (ClassInfoListBox.SelectedItems.Count > 1)
                    {
                        MessageBox.Show("已排课", "警告");
                        return;
                    }
                    else
                    {
                        classInfo.Timetables[button] = course;//修改待定
                    }
                }
                else
                {
                    classInfo.Timetables.Add(button, course);
                }
            }

            Grid  g = button.Parent as Grid;
            Label l = g.Children[0] as Label;

            l.Content = course.CourseName + "\n" +
                        course.Classroom + "\n" +
                        course.Teacher + "\n";
        }
Example #2
0
        /// <summary>
        /// 连接数据库获取教室信息表数据
        /// </summary>
        public void ConnectDbForClassroomInfo()
        {
            // 获取数据库路径
            var path0  = Environment.CurrentDirectory;
            var path1  = path0.Substring(0, path0.LastIndexOf("\\", StringComparison.Ordinal));
            var path2  = path1.Substring(0, path1.LastIndexOf("\\", StringComparison.Ordinal));
            var dbPath = path2 + "\\DB\\course_scheduling_system.db";

            #region
            using (var conn = new SQLiteConnection())
            {
                var connsb = new SQLiteConnectionStringBuilder {
                    DataSource = dbPath
                };
                conn.ConnectionString = connsb.ToString();
                conn.Open();
                using (new SQLiteCommand(conn))
                {
                    const string sql     = "SELECT * FROM tb_classroominfo";
                    var          command = new SQLiteCommand(sql, conn);
                    var          reader  = command.ExecuteReader();
                    while (reader.Read())
                    {
                        var ci = new ClassroomInfo
                        {
                            ClassroomNumber     = reader["classroom_number"].ToString(),
                            ClassroomGalleryful = reader["classroom_galleryful"].ToString(),
                            ClassroomType       = reader["classroom_type"].ToString(),
                            DetInfo             = reader["classroom_number"] + "\t" + reader["classroom_type"]
                        };
                        _classroomInfosList.Add(ci);
                    }
                }
            }
            #endregion
        }