Exemple #1
0
        /// <summary>
        /// 获取选定对应宿舍楼的抽查楼层
        /// </summary>
        /// <param name="dormsSelected"></param>
        /// <returns></returns>
        private List <string> getFloors(dorm dormSelected)
        {
            List <string>  floorsSelected = new List <string>();
            List <int>     floors         = new List <int>();
            List <history> lastHistories  = this.lastTermHistories
                                            .Where(p => p.dorm_name.Equals(dormSelected.dorm_name))
                                            .ToList();

            //Random rd = new Random();
            if (lastHistories.Count == 0)
            {
                int number = (int)dormSelected.floor_number;
                //当宿舍楼层数为奇数且不为1时,随机选择向上或向下选择
                if (number % 2 != 0)
                {
                    int next = this.rd.Next(0, 2);
                    number /= 2;
                    number += next;
                }
                else
                {
                    number /= 2;
                }

                //考虑多学期情况,应修改为如果当前学期为奇数,抽选楼层;
                //当前学期为偶数,选取上学期未选取的楼层
                for (int i = 0; i < number; i++)
                {
                    int floor = this.rd.Next(1, (int)dormSelected.floor_number + 1);
                    while (floors.Contains(floor))
                    {
                        floor = this.rd.Next(1, (int)dormSelected.floor_number + 1);
                    }
                    floors.Add(floor);
                }
            }
            else
            {
                for (int i = 1; i <= dormSelected.floor_number; i++)
                {
                    floors.Add(i);
                }

                string[]   tmp            = lastHistories[0].floor_id.Split(' ');
                List <int> lastTermFloors = new List <int>(Array.ConvertAll(tmp, int.Parse));

                floors = floors.Except(lastTermFloors).ToList();
            }

            floors.Sort();
            foreach (int floor in floors)
            {
                floorsSelected.Add(floor.ToString());
            }
            return(floorsSelected);
        }
Exemple #2
0
        private void AddNewHistory(dorm dormSelected, string floorsSelected)
        {
            history newHistory = new history();

            newHistory.term        = term;
            newHistory.area        = dormSelected.area;
            newHistory.dorm_name   = dormSelected.dorm_name;
            newHistory.check_id    = this.checkId;
            newHistory.floor_id    = floorsSelected;
            newHistory.insert_date = DateTime.Now;
            newHistories.Add(newHistory);
        }
Exemple #3
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) { }
        }
Exemple #4
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);
                }
            }
        }
Exemple #5
0
        /// <summary>
        /// 计数器委托函数,用于停止timer1并显示抽选到的宿舍及楼层
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void OnTimer2Event(object sender, EventArgs e)
        {
            if (this.isTimer1Started)
            {
                this.timer1.Stop();

                dorm firstDorm = new dorm();

                if (this.dormsGroup1.Count != 0)
                {
                    firstDorm = this.dormsGroup1.First();
                }
                else if (this.dormsGroup2.Count != 0)
                {
                    firstDorm = this.dormsGroup2.First();
                }
                else if (this.dormsGroup3.Count != 0)
                {
                    firstDorm = this.dormsGroup3.First();
                }

                List <string> floors         = this.getFloors(firstDorm);
                string        floorsSelected = "";
                string        floorsOfDorm   = "";

                for (int i = 0; i < floors.Count - 1; i++)
                {
                    floorsOfDorm   += floors[i] + "层  ";
                    floorsSelected += floors[i] + " ";
                }

                floorsOfDorm   += floors[floors.Count - 1] + "层";
                floorsSelected += floors[floors.Count - 1];

                this.samplingDormLabel.Content  = firstDorm.dorm_name;
                this.samplingFloorLabel.Content = floorsOfDorm;
                Result result = new Result();
                result.dormName     = firstDorm.dorm_name;
                result.gender       = firstDorm.gender;
                result.floorsOfDorm = floorsOfDorm;
                AddNewHistory(firstDorm, floorsSelected);

                if (this.dormsGroup1.Count != 0)
                {
                    this.dormsShow1.Add(result);
                    this.dataGridGroupOne.ItemsSource = null;
                    this.dataGridGroupOne.ItemsSource = dormsShow1;
                    this.dormsGroup1.RemoveAt(0);
                }
                else if (this.dormsGroup2.Count != 0)
                {
                    this.dormsShow2.Add(result);
                    this.dataGridGroupTwo.ItemsSource = null;
                    this.dataGridGroupTwo.ItemsSource = dormsShow2;
                    this.dormsGroup2.RemoveAt(0);
                }
                else if (this.dormsGroup3.Count != 0)
                {
                    this.dormsShow3.Add(result);
                    this.dataGridGroupThree.ItemsSource = null;
                    this.dataGridGroupThree.ItemsSource = dormsShow3;
                    this.dormsGroup3.RemoveAt(0);
                }

                if (this.dormsGroup3.Count == 0)
                {
                    this.timer2.Stop();
                    this.btnStartSampling.IsEnabled = true;
                    this.btnSaveRecord.IsEnabled    = true;
                }

                this.isTimer1Started = false;
            }
            else
            {
                this.timer1.Start();
                this.isTimer1Started = true;
            }
        }