Пример #1
0
        private void SearchStudentRange()
        {
            #region 日期選擇

            dataGridView.Rows.Clear();
            _semesterProvider.SetDate(dateTimeInput1.Value);
            _students = SortClassIndex.K12Data_StudentRecord(_students);

            foreach (StudentRecord student in _students)
            {
                DataGridViewRow row = new DataGridViewRow();
                row.CreateCells(dataGridView);
                row.Cells[0].Tag = student.ID;

                row.Cells[ColumnIndex["班級"]].Value = (student.Class != null) ? student.Class.Name : "";
                row.Cells[ColumnIndex["姓名"]].Value = student.Name;
                row.Cells[ColumnIndex["學號"]].Value = student.StudentNumber;
                row.Cells[ColumnIndex["座號"]].Value = student.SeatNo.HasValue ? student.SeatNo.Value.ToString() : "";

                row.Cells[ColumnIndex["學年度"]].Value = _semesterProvider.SchoolYear;
                row.Cells[ColumnIndex["學期"]].Value  = _semesterProvider.Semester;
                row.Cells[ColumnIndex["學年度"]].Tag   = new SemesterCellInfo(_semesterProvider.SchoolYear.ToString());
                row.Cells[ColumnIndex["學期"]].Tag    = new SemesterCellInfo(_semesterProvider.Semester.ToString());
                RowTag tag = new RowTag();
                tag.Date  = dateTimeInput1.Value;
                tag.IsNew = true;
                row.Tag   = tag;

                dataGridView.Rows.Add(row);
            }
            #endregion
        }
Пример #2
0
        //儲存
        private void btnSave_Click(object sender, EventArgs e)
        {
            #region Save
            if (!IsValid())
            {
                FISCA.Presentation.Controls.MsgBox.Show("資料驗證失敗,請修正後再行儲存", "驗證失敗", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                return;
            }
            List <SHAttendanceRecord> InsertHelper = new List <SHAttendanceRecord>(); //新增
            List <SHAttendanceRecord> updateHelper = new List <SHAttendanceRecord>(); //更新
            List <string>             deleteList   = new List <string>();             //清空

            //List<string> synclist = new List<string>();

            ISemester semester = SemesterProvider.GetInstance();
            foreach (DataGridViewRow row in dataGridView.Rows)
            {
                RowTag tag = row.Tag as RowTag;
                semester.SetDate(tag.Date);

                ////log 紀錄修改後的資料 日期部分
                if (row.Cells[0].Tag is string)
                {
                    if (!LOG[row.Cells[0].Tag.ToString()].afterData.ContainsKey(tag.Date.ToShortDateString()))
                    {
                        LOG[row.Cells[0].Tag.ToString()].afterData.Add(tag.Date.ToShortDateString(), new Dictionary <string, string>());
                    }
                }
                else
                {
                    SHAttendanceRecord attRecord = row.Cells[0].Tag as SHAttendanceRecord;

                    if (!LOG[attRecord.RefStudentID].afterData.ContainsKey(tag.Date.ToShortDateString()))
                    {
                        LOG[attRecord.RefStudentID].afterData.Add(tag.Date.ToShortDateString(), new Dictionary <string, string>());
                    }
                }

                if (tag.IsNew)
                {
                    #region IsNew
                    string studentID = row.Cells[0].Tag as string;

                    SHAttendanceRecord attRecord = new SHAttendanceRecord();

                    bool hasContent = false;
                    for (int i = _startIndex; i < dataGridView.Columns.Count; i++)
                    {
                        DataGridViewCell cell = row.Cells[i];
                        if (string.IsNullOrEmpty(("" + cell.Value).Trim()))
                        {
                            continue;
                        }

                        PeriodInfo      pinfo  = dataGridView.Columns[i].Tag as PeriodInfo;
                        AbsenceCellInfo acInfo = cell.Tag as AbsenceCellInfo;
                        AbsenceInfo     ainfo  = acInfo.AbsenceInfo;

                        K12.Data.AttendancePeriod ap = new K12.Data.AttendancePeriod();
                        ap.Period      = pinfo.Name;
                        ap.AbsenceType = ainfo.Name;
                        attRecord.PeriodDetail.Add(ap);

                        hasContent = true;

                        //log 紀錄修改後的資料 缺曠明細部分
                        if (!LOG[studentID].afterData[tag.Date.ToShortDateString()].ContainsKey(pinfo.Name))
                        {
                            LOG[studentID].afterData[tag.Date.ToShortDateString()].Add(pinfo.Name, ainfo.Name);
                        }
                    }

                    if (hasContent)
                    {
                        attRecord.RefStudentID = studentID;
                        attRecord.SchoolYear   = int.Parse("" + row.Cells[ColumnIndex["學年度"]].Value);
                        attRecord.Semester     = int.Parse("" + row.Cells[ColumnIndex["學期"]].Value);
                        attRecord.OccurDate    = DateTime.Parse(tag.Date.ToShortDateString());
                        InsertHelper.Add(attRecord);
                    }

                    #endregion
                }
                else // 若是原本就有紀錄的
                {
                    #region 是舊的

                    SHAttendanceRecord attRecord = row.Cells[0].Tag as SHAttendanceRecord;
                    attRecord.PeriodDetail.Clear(); //清空

                    bool hasContent = false;
                    for (int i = _startIndex; i < dataGridView.Columns.Count; i++)
                    {
                        DataGridViewCell cell = row.Cells[i];
                        if (string.IsNullOrEmpty(("" + cell.Value).Trim()))
                        {
                            continue;
                        }

                        PeriodInfo      pinfo  = dataGridView.Columns[i].Tag as PeriodInfo;
                        AbsenceCellInfo acInfo = cell.Tag as AbsenceCellInfo;
                        AbsenceInfo     ainfo  = acInfo.AbsenceInfo;

                        K12.Data.AttendancePeriod ap = new K12.Data.AttendancePeriod();
                        ap.Period      = pinfo.Name;
                        ap.AbsenceType = ainfo.Name;
                        attRecord.PeriodDetail.Add(ap);

                        hasContent = true;

                        //log 紀錄修改後的資料 缺曠明細部分
                        if (!LOG[attRecord.RefStudentID].afterData[tag.Date.ToShortDateString()].ContainsKey(pinfo.Name))
                        {
                            LOG[attRecord.RefStudentID].afterData[tag.Date.ToShortDateString()].Add(pinfo.Name, ainfo.Name);
                        }
                    }

                    if (hasContent)
                    {
                        attRecord.SchoolYear = int.Parse("" + row.Cells[ColumnIndex["學年度"]].Value);
                        attRecord.Semester   = int.Parse("" + row.Cells[ColumnIndex["學期"]].Value);
                        updateHelper.Add(attRecord);
                    }
                    else
                    {
                        deleteList.Add(tag.Key);

                        //log 紀錄被刪除的資料
                        LOG[attRecord.RefStudentID].afterData.Remove(tag.Date.ToShortDateString());
                        LOG[attRecord.RefStudentID].deleteData.Add(tag.Date.ToShortDateString());
                    }
                    #endregion
                }
            }

            #region InsertHelper
            if (InsertHelper.Count > 0)
            {
                try
                {
                    SHAttendance.Insert(InsertHelper);
                }
                catch (Exception ex)
                {
                    FISCA.Presentation.Controls.MsgBox.Show("缺曠紀錄新增失敗 : " + ex.Message, "新增失敗", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }


                //log 寫入log
                foreach (string each in LOG.Keys)
                {
                    foreach (string date in LOG[each].afterData.Keys)
                    {
                        if (!LOG[each].beforeData.ContainsKey(date) && LOG[each].afterData[date].Count > 0)
                        {
                            StringBuilder desc = new StringBuilder("");
                            desc.AppendLine("學生「" + K12.Data.Student.SelectByID(each).Name + "」");
                            desc.AppendLine("日期「" + date + "」");
                            foreach (string period in LOG[each].afterData[date].Keys)
                            {
                                desc.AppendLine("節次「" + period + "」設為「" + LOG[each].afterData[date][period] + "」");
                            }
                            ApplicationLog.Log("學務系統.缺曠資料", "批次新增缺曠資料", "student", each, desc.ToString());
                            //Log部份
                            //CurrentUser.Instance.AppLog.Write(EntityType.Student, EntityAction.Insert, _student.ID, desc.ToString(), this.Text, "");
                        }
                    }
                }
            }
            #endregion

            #region updateHelper
            if (updateHelper.Count > 0)
            {
                try
                {
                    SHAttendance.Update(updateHelper);
                }
                catch (Exception ex)
                {
                    FISCA.Presentation.Controls.MsgBox.Show("缺曠紀錄更新失敗 : " + ex.Message, "更新失敗", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }

                //log 寫入log
                foreach (string each in LOG.Keys)
                {
                    foreach (string date in LOG[each].afterData.Keys)
                    {
                        if (LOG[each].beforeData.ContainsKey(date) && LOG[each].afterData[date].Count > 0)
                        {
                            bool          dirty = false;
                            StringBuilder desc  = new StringBuilder("");
                            desc.AppendLine("學生「" + K12.Data.Student.SelectByID(each).Name + "」 ");
                            desc.AppendLine("日期「" + date + "」 ");
                            foreach (string period in LOG[each].beforeData[date].Keys)
                            {
                                if (!LOG[each].afterData[date].ContainsKey(period))
                                {
                                    LOG[each].afterData[date].Add(period, "");
                                }
                            }
                            foreach (string period in LOG[each].afterData[date].Keys)
                            {
                                if (LOG[each].beforeData[date].ContainsKey(period))
                                {
                                    if (LOG[each].beforeData[date][period] != LOG[each].afterData[date][period])
                                    {
                                        dirty = true;
                                        desc.AppendLine("節次「" + period + "」由「" + LOG[each].beforeData[date][period] + "」變更為「" + LOG[each].afterData[date][period] + "」");
                                    }
                                }
                                else
                                {
                                    dirty = true;
                                    desc.AppendLine("節次「" + period + "」由「」變更為「" + LOG[each].afterData[date][period] + "」 ");
                                }
                            }
                            if (dirty)
                            {
                                //Log部份
                                ApplicationLog.Log("學務系統.缺曠資料", "批次修改缺曠資料", "student", each, desc.ToString());
                                //CurrentUser.Instance.AppLog.Write(EntityType.Student, EntityAction.Update, _student.ID, desc.ToString(), this.Text, "");
                            }
                        }
                    }
                }
            }
            #endregion

            #region deleteList
            if (deleteList.Count > 0)
            {
                try
                {
                    SHAttendance.Delete(deleteList);
                }
                catch (Exception ex)
                {
                    FISCA.Presentation.Controls.MsgBox.Show("缺曠紀錄刪除失敗 : " + ex.Message, "刪除失敗", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }

                //log 寫入被刪除的資料的log
                foreach (string each in LOG.Keys)
                {
                    StringBuilder desc = new StringBuilder("");
                    desc.AppendLine("學生「" + K12.Data.Student.SelectByID(each).Name + "」");
                    foreach (string date in LOG[each].deleteData)
                    {
                        desc.AppendLine("刪除「" + date + "」缺曠紀錄 ");
                    }

                    //Log部份
                    ApplicationLog.Log("學務系統.缺曠資料", "批次刪除缺曠資料", "student", each, desc.ToString());
                    //CurrentUser.Instance.AppLog.Write(EntityType.Student, EntityAction.Delete, _student.ID, desc.ToString(), this.Text, "");
                }
            }
            #endregion

            //觸發變更事件
            //Attendance.Instance.SyncDataBackground(_studentList);

            FISCA.Presentation.Controls.MsgBox.Show("儲存缺曠資料成功!", "完成", MessageBoxButtons.OK, MessageBoxIcon.Information);
            this.Close();
            #endregion
        }
Пример #3
0
        private void SearchDateRange()
        {
            #region 日期選擇
            DateTime start = dateTimeInput1.Value;
            DateTime end   = dateTimeInput2.Value;

            dataGridView.Rows.Clear();

            TimeSpan ts = dateTimeInput2.Value - dateTimeInput1.Value;
            if (ts.Days > 1500)
            {
                FISCA.Presentation.Controls.MsgBox.Show("您選取了" + ts.Days.ToString() + "天\n由於選取日期區間過長,請重新設定日期!");
                _currentStartDate = dateTimeInput1.Value = DateTime.Today;
                _currentEndDate   = dateTimeInput2.Value = DateTime.Today;
                return;
            }

            List <SHStudentRecord> CatchStudentList = SHStudent.SelectByIDs(_studentList);

            CatchStudentList = SortClassIndex.SHSchoolData_SHStudentRecord(CatchStudentList);

            bool ColorTrue = true;
            foreach (SHStudentRecord each in CatchStudentList)
            {
                DateTime date = start;
                if (ColorTrue)
                {
                    ColorTrue = false;
                }
                else
                {
                    ColorTrue = true;
                }

                while (date.CompareTo(end) <= 0)
                {
                    if (!nowWeekDay.Contains(date.DayOfWeek)) //這裡
                    {
                        date = date.AddDays(1);
                        continue;
                    }
                    string dateValue = date.ToShortDateString();

                    DataGridViewRow row = new DataGridViewRow();
                    row.CreateCells(dataGridView);
                    if (ColorTrue)
                    {
                        SetDataGridViewColor(row, ColorTrue);
                    }
                    else
                    {
                        SetDataGridViewColor(row, ColorTrue);
                    }
                    RowTag tag = new RowTag();
                    tag.Date         = date;
                    tag.IsNew        = true;
                    row.Tag          = tag;     //RowTag
                    row.Cells[0].Tag = each.ID; //系統編號

                    row.Cells[ColumnIndex["班級"]].Value = each.Class != null ? each.Class.Name : "";
                    row.Cells[ColumnIndex["座號"]].Value = each.SeatNo.HasValue ? each.SeatNo.Value.ToString() : "";
                    row.Cells[ColumnIndex["姓名"]].Value = each.Name;
                    row.Cells[ColumnIndex["學號"]].Value = each.StudentNumber;

                    row.Cells[ColumnIndex["日期"]].Value = dateValue;
                    row.Cells[ColumnIndex["星期"]].Value = GetDayOfWeekInChinese(date.DayOfWeek);
                    _semesterProvider.SetDate(date);
                    row.Cells[ColumnIndex["學年度"]].Value = _semesterProvider.SchoolYear.ToString();
                    row.Cells[ColumnIndex["學期"]].Value  = _semesterProvider.Semester.ToString();
                    date = date.AddDays(1);

                    dataGridView.Rows.Add(row);
                }
            }
            #endregion
        }