Exemplo n.º 1
0
        private async void btnCheckin_Click(object sender, RoutedEventArgs e)
        {
            string selected = (string)this.checkinComboBox.SelectedValue;

            try
            {
                if (!selected.Trim().Equals(""))
                {
                    officer selectedOfficer = this.officers.Where(p => p.officer_id.Equals(selected)).First();

                    checkin_history tmpHistory = new checkin_history();
                    tmpHistory.officer_id   = selected;
                    tmpHistory.officer_name = selectedOfficer.officer_name;
                    tmpHistory.term         = MainWindow.term;
                    tmpHistory.insert_date  = DateTime.Now;

                    using (check_dorm_newEntities db = new check_dorm_newEntities())
                    {
                        db.checkin_history.Add(tmpHistory);
                        db.SaveChanges();
                        this.checkedOfficers.Add(selectedOfficer);
                        this.checkinDataGrid.ItemsSource = null;
                        this.checkinDataGrid.ItemsSource = this.checkedOfficers;
                    }

                    await this.ShowMessageAsync("", "签到成功!");
                }
            }
            catch (Exception exp) { }
        }
Exemplo n.º 2
0
        /// <summary>
        /// 加载计时器,查询一些基本的数据
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void mainWindow_Loaded(object sender, RoutedEventArgs e)
        {
            this.db              = new check_dorm_newEntities();
            this.timer1          = new System.Windows.Threading.DispatcherTimer();
            this.timer1.Tick    += new EventHandler(OnTimer1Event);
            this.timer1.Interval = TimeSpan.FromSeconds(1.0 / 200);

            this.timer2          = new System.Windows.Threading.DispatcherTimer();
            this.timer2.Tick    += new EventHandler(OnTimer2Event);
            this.timer2.Interval = TimeSpan.FromSeconds(1);

            this.myDorms = this.db.dorm.ToList();  // 把宿舍信息拿出来缓存着,减少数据库的读取,
                                                   // 同时激活数据库连接,加速后续读取历史信息的速度
            this.allDorms     = this.myDorms.Select(p => p.dorm_name).ToList();
            this.allFloors    = this.InitFloors();
            this.myHistories  = this.db.history.ToList();
            this.newHistories = new List <history>();
            this.dormsShow1   = new ObservableCollection <Result>();
            this.dormsShow2   = new ObservableCollection <Result>();
            this.dormsShow3   = new ObservableCollection <Result>();

            term = getTerm();

            if (myHistories.Count == 0)
            {
                this.checkId = 1;
            }
            else
            {
                this.lastestTerm = myHistories.Last().term;
                this.checkId     = myHistories.Last().check_id;

                if (term.Equals(this.lastestTerm))
                {
                    if (this.checkId == checkTimes)
                    {
                        this.btnStartSampling.IsEnabled = false;
                        this.samplingDormLabel.Content  = "本学期";
                        this.samplingFloorLabel.Content = "抽选次数已满";
                    }
                    else
                    {
                        this.checkId++;
                    }
                }
                else
                {
                    this.checkId = 1;
                }
            }

            this.checkIdText.Text = "第 " + checkId + " 次抽选";
            this.rd = new Random();
        }
Exemplo n.º 3
0
        private void CheckinWindow_Loaded(object sender, RoutedEventArgs e)
        {
            using (check_dorm_newEntities db = new check_dorm_newEntities())
            {
                List <officer> tmp = db.officer.ToList();
                this.departments = new HashSet <string>();
                foreach (var tmpOfficer in tmp)
                {
                    this.departments.Add(tmpOfficer.officer_department);
                }

                this.checkinDepartment.ItemsSource = this.departments;
                this.checkedOfficers = new ObservableCollection <officer>();
            }
        }
Exemplo n.º 4
0
        private void checkinDepartment_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            string selected_department = (string)this.checkinDepartment.SelectedValue;

            try
            {
                if (!selected_department.Trim().Equals(""))
                {
                    using (check_dorm_newEntities db = new check_dorm_newEntities())
                    {
                        this.officers = new ObservableCollection <officer>(db.officer.Where(p => p.officer_department.Equals(selected_department)).ToList());
                        this.checkinComboBox.ItemsSource = this.officers;
                    }
                }
            }
            catch (Exception exp) { }
        }
Exemplo n.º 5
0
        private async void btnRemoveRecord_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                if (this.management == Management.人员)
                {
                    // 删除的是人员数据
                    officer tmpOfficer = (officer)this.officeGrid.SelectedItem;
                    using (check_dorm_newEntities db = new check_dorm_newEntities())
                    {
                        MessageDialogResult result = await this.ShowMessageAsync("人员管理", "您确定要删除该行数据吗", MessageDialogStyle.AffirmativeAndNegative);

                        if (result != MessageDialogResult.Negative)
                        {
                            // 删除
                            db.officer.Remove(db.officer.Where(p => p.row_id.Equals(tmpOfficer.row_id)).First());
                            db.SaveChanges();
                            this.officers.Remove(tmpOfficer);
                            this.officeGrid.ItemsSource = null;
                            this.officeGrid.ItemsSource = this.officers;
                        }
                    }
                }
                else if (this.management == Management.楼栋)
                {
                    // 删除的是楼栋数据
                    dorm tmpDorm = (dorm)this.dormGrid.SelectedItem;
                    using (check_dorm_newEntities db = new check_dorm_newEntities())
                    {
                        MessageDialogResult result = await this.ShowMessageAsync("楼栋管理", "您确定要删除该行数据吗", MessageDialogStyle.AffirmativeAndNegative);

                        if (result != MessageDialogResult.Negative)
                        {
                            // 删除
                            db.dorm.Remove(db.dorm.Where(p => p.dorm_name.Equals(tmpDorm.dorm_name)).First());
                            db.SaveChanges();
                            this.dorms.Remove(tmpDorm);
                            this.dormGrid.ItemsSource = null;
                            this.dormGrid.ItemsSource = this.dorms;
                        }
                    }
                }
            }
            catch (Exception exp) { }
        }
Exemplo n.º 6
0
        private void dormGrid_RowEditEnding(object sender, DataGridRowEditEndingEventArgs e)
        {
            dorm tmpDorm = (dorm)e.Row.DataContext;

            if (e.EditAction == DataGridEditAction.Commit)
            {
                try
                {
                    using (check_dorm_newEntities db = new check_dorm_newEntities())
                    {
                        if (tmpDorm.row_id.Equals(0))
                        {
                            dorm newDorm = new dorm();
                            newDorm.area         = tmpDorm.area;
                            newDorm.group_id     = tmpDorm.group_id;
                            newDorm.dorm_name    = tmpDorm.dorm_name;
                            newDorm.floor_number = tmpDorm.floor_number;
                            newDorm.gender       = tmpDorm.gender;

                            db.dorm.Add(newDorm);
                            db.SaveChanges();

                            // 添加完毕以后需要重新读取数据库中新加入行的row_id用于更新内存中缓存的row_id
                            this.dorms.Where(p => p.dorm_name.Equals(newDorm.dorm_name)).First().row_id = db.dorm.Where(p => p.dorm_name.Equals(newDorm.dorm_name)).First().row_id;
                        }
                        else
                        {
                            db.dorm.Where(p => p.row_id.Equals(tmpDorm.row_id)).First().area         = tmpDorm.area;
                            db.dorm.Where(p => p.row_id.Equals(tmpDorm.row_id)).First().group_id     = tmpDorm.group_id;
                            db.dorm.Where(p => p.row_id.Equals(tmpDorm.row_id)).First().dorm_name    = tmpDorm.dorm_name;
                            db.dorm.Where(p => p.row_id.Equals(tmpDorm.row_id)).First().floor_number = tmpDorm.floor_number;
                            db.dorm.Where(p => p.row_id.Equals(tmpDorm.row_id)).First().gender       = tmpDorm.gender;
                            db.SaveChanges();
                        }
                    }
                }
                catch (Exception exp)
                {
                    e.Cancel = true;
                    (sender as DataGrid).CancelEdit(DataGridEditingUnit.Row);
                }
            }
        }
Exemplo n.º 7
0
        private void officeGrid_RowEditEnding(object sender, DataGridRowEditEndingEventArgs e)
        {
            // 获取编辑后的数据
            officer tmpOfficer = (officer)e.Row.DataContext;

            if (e.EditAction == DataGridEditAction.Commit)
            {
                try
                {
                    using (check_dorm_newEntities db = new check_dorm_newEntities())
                    {
                        if (tmpOfficer.row_id.Equals(0))
                        {
                            // row_id == 0说明是新加入的行
                            officer newOfficer = new officer();
                            newOfficer.officer_id         = tmpOfficer.officer_id;
                            newOfficer.officer_department = tmpOfficer.officer_department;
                            newOfficer.officer_name       = tmpOfficer.officer_name;
                            newOfficer.officer_gender     = tmpOfficer.officer_gender;
                            db.officer.Add(newOfficer);
                            db.SaveChanges();

                            // 添加完毕以后需要重新读取数据库中新加入行的row_id用于更新内存中缓存的row_id
                            this.officers.Where(p => p.officer_id.Equals(newOfficer.officer_id)).First().row_id = db.officer.Where(p => p.officer_id.Equals(newOfficer.officer_id)).First().row_id;
                        }
                        else
                        {
                            // row_id != 0说明是原先存在的行,修改即可
                            db.officer.Where(p => p.row_id.Equals(tmpOfficer.row_id)).First().officer_id         = tmpOfficer.officer_id;
                            db.officer.Where(p => p.row_id.Equals(tmpOfficer.row_id)).First().officer_department = tmpOfficer.officer_department;
                            db.officer.Where(p => p.row_id.Equals(tmpOfficer.row_id)).First().officer_name       = tmpOfficer.officer_name;
                            db.officer.Where(p => p.row_id.Equals(tmpOfficer.row_id)).First().officer_gender     = tmpOfficer.officer_gender;
                            db.SaveChanges();
                        }
                    }
                }
                catch (Exception exp)
                {
                    e.Cancel = true;
                    (sender as DataGrid).CancelEdit(DataGridEditingUnit.Row);
                }
            }
        }
Exemplo n.º 8
0
 private void editorWindow_Loaded(object sender, RoutedEventArgs e)
 {
     using (check_dorm_newEntities db = new check_dorm_newEntities())
     {
         // 读取已有数据
         if (this.management == Management.人员)
         {
             this.Title = "人员管理";
             this.officeGrid.Visibility = Visibility.Visible;
             this.officers = new ObservableCollection <officer>(db.officer.ToList());
             this.officeGrid.DataContext = this.officers;
         }
         else if (this.management == Management.楼栋)
         {
             this.Title = "楼栋管理";
             this.dormGrid.Visibility = Visibility.Visible;
             this.dorms = new ObservableCollection <dorm>(db.dorm.ToList());
             this.dormGrid.DataContext = this.dorms;
         }
         else if (this.management == Management.历史)
         {
             this.Title = "历史记录查询";
             this.historyGrid.Visibility     = Visibility.Visible;
             this.btnRemoveRecord.IsEnabled  = false;
             this.btnRemoveRecord.Visibility = Visibility.Hidden;
             this.histories = new ObservableCollection <history>(db.history.ToList());
             this.historyGrid.DataContext = this.histories;
             this.statusBar.Visibility    = Visibility.Hidden;
         }
         else if (this.management == Management.签到)
         {
             this.Title = "签到记录查询";
             this.checkinGrid.Visibility     = Visibility.Visible;
             this.btnRemoveRecord.IsEnabled  = false;
             this.btnRemoveRecord.Visibility = Visibility.Hidden;
             this.checkin_histories          = new ObservableCollection <checkin_history>(db.checkin_history.ToList());
             this.checkinGrid.DataContext    = this.checkin_histories;
             this.statusBar.Visibility       = Visibility.Hidden;
         }
     }
 }