public FrmFitnessRecord(DAO.StudentFitnessRecord rec, accessType actType)
        {
            InitializeComponent();

            _studRec = Student.SelectByID(rec.StudentID);
            _fitnessRec = rec;
            _actType = actType;
            _LogTransfer = new Log.LogTransfer();

            if(_actType == accessType.Edit)
                this.TitleText = _FrmTitleEdit;
            else
                this.TitleText = _FrmTitleAdd;
        }
Ejemplo n.º 2
0
        public FrmFitnessRecord(DAO.StudentFitnessRecord rec, accessType actType)
        {
            InitializeComponent();

            _studRec     = Student.SelectByID(rec.StudentID);
            _fitnessRec  = rec;
            _actType     = actType;
            _LogTransfer = new Log.LogTransfer();

            if (_actType == accessType.Edit)
            {
                this.TitleText = _FrmTitleEdit;
            }
            else
            {
                this.TitleText = _FrmTitleAdd;
            }
        }
        public FrmFitnessRecord(DAO.StudentFitnessRecord rec, accessType actType)
        {
            InitializeComponent();

            _studRec     = Student.SelectByID(rec.StudentID);
            _fitnessRec  = rec;
            _actType     = actType;
            _LogTransfer = new Log.LogTransfer();

            if (_actType == accessType.Edit)
            {
                this.Text = _FrmTitleEdit;
                //修改模式無法變更學年度
                this.integerInput1.Enabled = false;
            }
            else
            {
                this.Text = _FrmTitleAdd;
            }
        }
        private void btnDelete_Click(object sender, EventArgs e)
        {
            if (lvFitnessList.SelectedItems.Count > 0)
            {
                DAO.StudentFitnessRecord rec = lvFitnessList.SelectedItems[0].Tag as DAO.StudentFitnessRecord;
                if (FISCA.Presentation.Controls.MsgBox.Show("請問是否確定是刪除體適能紀錄?", "刪除體適能紀錄", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) == DialogResult.Yes)
                {
                    K12.Data.StudentRecord studRec = K12.Data.Student.SelectByID(PrimaryKey);
                    string studStr = "學號:" + studRec.StudentNumber + ",姓名:" + studRec.Name + ",";

                    Log.LogTransfer LogTransfer = new Log.LogTransfer();
                    Utility.SetLogData(LogTransfer, rec);
                    LogTransfer.SaveDeleteLog("學生.體適能-刪除", "刪除", studStr, "", "student", studRec.ID);

                    DAO.StudentFitness.DeleteByRecord(rec);

                    _BGRun();
                }
            }
            else
            {
                FISCA.Presentation.Controls.MsgBox.Show("請選擇資料.");
            }
        }
        public override string Import(List<IRowStream> Rows)
        {
            _InsertRecList.Clear();
            _UpdateRecList.Clear();

            // 取得 Rows內學號, 學年度
            List<string> StudentNumberList = new List<string>();
            Dictionary<string, string> SchoolYearDic = new Dictionary<string, string>();
            foreach (IRowStream row in Rows)
            {
                string StudentNumber = Utility.GetIRowValueString(row, "學號");
                string SchoolYear = Utility.GetIRowValueString(row, "學年度");
                
                if (string.IsNullOrEmpty(StudentNumber)) continue;
                if (string.IsNullOrEmpty(SchoolYear)) continue;

                StudentNumberList.Add(StudentNumber);

                if (!SchoolYearDic.ContainsKey(SchoolYear))
                {
                    SchoolYearDic.Add(SchoolYear, "");
                }
            }

            // 透過學號去取得學生ID
            Dictionary<string, string> StudNumDict = DAO.FDQuery.GetStudenIdDictByStudentNumber(StudentNumberList);
            
            // 根據學年度, 學生ID取得體適能的資料
            List<DAO.StudentFitnessRecord> fitnessRecList = DAO.StudentFitness.SelectByStudentIDListAndSchoolYear(StudNumDict.Values.ToList<string>(), SchoolYearDic.Keys.ToList<string>());

            int totalCount = 0;
            // 判斷每一筆資料是要新增還是更新
            foreach(IRowStream row in Rows)
            {
                totalCount++;
                this.ImportProgress = totalCount;
                bool isInsert = true;   // 用來判斷此筆資料是否要新增
                DAO.StudentFitnessRecord fitnessRec = new DAO.StudentFitnessRecord();
                string StudentNumber = Utility.GetIRowValueString(row, "學號");
                int? SchoolYear = Utility.GetIRowValueInt(row, "學年度");
                DateTime? TestDate = Utility.GetIRowValueDateTime(row, "測驗日期");

                // 如果"學號"或"學年度"或"測驗日期"沒有資料, 換到下一筆
                if(string.IsNullOrEmpty(StudentNumber)) continue;
                if(!SchoolYear.HasValue) continue;
                if(!TestDate.HasValue) continue;

                // 透過學號換成學生ID
                string StudentID = "";
                if(StudNumDict.ContainsKey(StudentNumber))
                {
                    StudentID = StudNumDict[StudentNumber];
                }
                else
                {
                    // 如果無法取得學生ID, 就換到下一筆
                    continue;
                }

                // 判斷此筆資料是否已在DB
                foreach(DAO.StudentFitnessRecord rec in fitnessRecList)
                {
                    if (rec.SchoolYear == SchoolYear && rec.StudentID == StudentID && rec.TestDate == TestDate)
                    {
                        isInsert = false;
                        fitnessRec = rec;

                        break;
                    }
                }

                // 新增資料
                if(isInsert == true)
                {
                    #region 處理新增資料
                    // 學生系統編號
                    fitnessRec.StudentID = StudentID;
                    // 學年度
                    fitnessRec.SchoolYear = SchoolYear.Value;
                    // 測驗日期
                    fitnessRec.TestDate = TestDate.Value;
                    // 學校類別
                    fitnessRec.SchoolCategory = Utility.GetIRowValueString(row, "學校類別");
                    // 身高
                    fitnessRec.Height = Utility.GetIRowValueString(row, "身高");
                    // 身高常模
                    fitnessRec.HeightDegree = Utility.GetIRowValueString(row, "身高常模");
                    // 體重
                    fitnessRec.Weight = Utility.GetIRowValueString(row, "體重");
                    // 體重常模
                    fitnessRec.WeightDegree = Utility.GetIRowValueString(row, "體重常模");
                    // 坐姿體前彎
                    fitnessRec.SitAndReach = Utility.GetIRowValueString(row, "坐姿體前彎");
                    // 坐姿體前彎常模
                    fitnessRec.SitAndReachDegree = Utility.GetIRowValueString(row, "坐姿體前彎常模");
                    // 立定跳遠
                    fitnessRec.StandingLongJump = Utility.GetIRowValueString(row, "立定跳遠");
                    // 立定跳遠常模
                    fitnessRec.StandingLongJumpDegree = Utility.GetIRowValueString(row, "立定跳遠常模");
                    // 仰臥起坐
                    fitnessRec.SitUp = Utility.GetIRowValueString(row, "仰臥起坐");
                    // 仰臥起坐常模
                    fitnessRec.SitUpDegree = Utility.GetIRowValueString(row, "仰臥起坐常模");
                    // 心肺適能
                    fitnessRec.Cardiorespiratory = Utility.GetIRowValueString(row, "心肺適能");
                    // 心肺適能常模
                    fitnessRec.CardiorespiratoryDegree = Utility.GetIRowValueString(row, "心肺適能常模");
                    #endregion
                }
                // 更新資料
                else
                {
                    #region 處理更新資料
                    // "學號/座號", "學年度", "測驗日期" 無法更新

                    // 學校類別
                    if (_Option.SelectedFields.Contains("學校類別"))
                        fitnessRec.SchoolCategory = Utility.GetIRowValueString(row, "學校類別");
                    // 身高
                    if (_Option.SelectedFields.Contains("身高"))
                        fitnessRec.Height = Utility.GetIRowValueString(row, "身高");
                    // 身高常模
                    if (_Option.SelectedFields.Contains("身高常模"))
                        fitnessRec.HeightDegree = Utility.GetIRowValueString(row, "身高常模");
                    // 體重
                    if (_Option.SelectedFields.Contains("體重"))
                        fitnessRec.Weight = Utility.GetIRowValueString(row, "體重");
                    // 體重常模
                    if (_Option.SelectedFields.Contains("體重常模"))
                        fitnessRec.WeightDegree = Utility.GetIRowValueString(row, "體重常模");
                    // 坐姿體前彎
                    if (_Option.SelectedFields.Contains("坐姿體前彎"))
                        fitnessRec.SitAndReach = Utility.GetIRowValueString(row, "坐姿體前彎");
                    // 坐姿體前彎常模
                    if (_Option.SelectedFields.Contains("坐姿體前彎常模"))
                        fitnessRec.SitAndReachDegree = Utility.GetIRowValueString(row, "坐姿體前彎常模");
                    // 立定跳遠
                    if (_Option.SelectedFields.Contains("立定跳遠"))
                        fitnessRec.StandingLongJump = Utility.GetIRowValueString(row, "立定跳遠");
                    // 立定跳遠常模
                    if (_Option.SelectedFields.Contains("立定跳遠常模"))
                        fitnessRec.StandingLongJumpDegree = Utility.GetIRowValueString(row, "立定跳遠常模");
                    // 仰臥起坐
                    if (_Option.SelectedFields.Contains("仰臥起坐"))
                        fitnessRec.SitUp = Utility.GetIRowValueString(row, "仰臥起坐");
                    // 仰臥起坐常模
                    if (_Option.SelectedFields.Contains("仰臥起坐常模"))
                        fitnessRec.SitUpDegree = Utility.GetIRowValueString(row, "仰臥起坐常模");
                    // 心肺適能
                    if (_Option.SelectedFields.Contains("心肺適能"))
                        fitnessRec.Cardiorespiratory = Utility.GetIRowValueString(row, "心肺適能");
                    // 心肺適能常模
                    if (_Option.SelectedFields.Contains("心肺適能常模"))
                        fitnessRec.CardiorespiratoryDegree = Utility.GetIRowValueString(row, "心肺適能常模");
                    #endregion
                }

                if(isInsert == true)
                    _InsertRecList.Add(fitnessRec);
                else
                    _UpdateRecList.Add(fitnessRec);
            }   // end of 判斷每一筆資料是要新增還是更新


            // 執行更新或新增
            if (_InsertRecList.Count >0 )
                DAO.StudentFitness.InsertByRecordList(_InsertRecList);
            if (_UpdateRecList.Count > 0)
                DAO.StudentFitness.UpdateByRecordList(_UpdateRecList);

            // Log
            Log.LogTransfer logTransfer = new Log.LogTransfer();
            StringBuilder logData = new StringBuilder();
            int insertCnt = _InsertRecList.Count; 
            int updateCnt = _UpdateRecList.Count;
            logData.Append("總共匯入").Append((insertCnt + updateCnt)).Append("筆,");
            logData.Append("新增:").Append(insertCnt).Append("筆,");
            logData.Append("更新:").Append(updateCnt).Append("筆");
            logTransfer.SaveLog("學生.體適能-匯入", "匯入", "student", "", logData);

            return "";
        }
        public override string Import(List <IRowStream> Rows)
        {
            _InsertRecList.Clear();
            _UpdateRecList.Clear();

            // 取得 Rows內學號, 學年度
            List <string> StudentNumberList           = new List <string>();
            Dictionary <string, string> SchoolYearDic = new Dictionary <string, string>();

            foreach (IRowStream row in Rows)
            {
                string StudentNumber = Utility.GetIRowValueString(row, "學號");
                string SchoolYear    = Utility.GetIRowValueString(row, "學年度");

                if (string.IsNullOrEmpty(StudentNumber))
                {
                    continue;
                }
                if (string.IsNullOrEmpty(SchoolYear))
                {
                    continue;
                }

                StudentNumberList.Add(StudentNumber);

                if (!SchoolYearDic.ContainsKey(SchoolYear))
                {
                    SchoolYearDic.Add(SchoolYear, "");
                }
            }

            // 透過學號去取得學生ID
            Dictionary <string, string> StudNumDict = DAO.FDQuery.GetStudenIdDictByStudentNumber(StudentNumberList);

            // 根據學年度, 學生ID取得體適能的資料
            List <DAO.StudentFitnessRecord> fitnessRecList = DAO.StudentFitness.SelectByStudentIDListAndSchoolYear(StudNumDict.Values.ToList <string>(), SchoolYearDic.Keys.ToList <string>());

            int totalCount = 0;

            // 判斷每一筆資料是要新增還是更新
            foreach (IRowStream row in Rows)
            {
                totalCount++;
                this.ImportProgress = totalCount;
                bool isInsert = true;   // 用來判斷此筆資料是否要新增
                DAO.StudentFitnessRecord fitnessRec = new DAO.StudentFitnessRecord();
                string   StudentNumber = Utility.GetIRowValueString(row, "學號");
                int?     SchoolYear    = Utility.GetIRowValueInt(row, "學年度");
                DateTime?TestDate      = Utility.GetIRowValueDateTime(row, "測驗日期");

                // 如果"學號"或"學年度"或"測驗日期"沒有資料, 換到下一筆
                if (string.IsNullOrEmpty(StudentNumber))
                {
                    continue;
                }
                if (!SchoolYear.HasValue)
                {
                    continue;
                }
                if (!TestDate.HasValue)
                {
                    continue;
                }

                // 透過學號換成學生ID
                string StudentID = "";
                if (StudNumDict.ContainsKey(StudentNumber))
                {
                    StudentID = StudNumDict[StudentNumber];
                }
                else
                {
                    // 如果無法取得學生ID, 就換到下一筆
                    continue;
                }

                // 判斷此筆資料是否已在DB
                foreach (DAO.StudentFitnessRecord rec in fitnessRecList)
                {
                    if (rec.SchoolYear == SchoolYear && rec.StudentID == StudentID && rec.TestDate == TestDate)
                    {
                        isInsert   = false;
                        fitnessRec = rec;

                        break;
                    }
                }

                // 新增資料
                if (isInsert == true)
                {
                    #region 處理新增資料
                    // 學生系統編號
                    fitnessRec.StudentID = StudentID;
                    // 學年度
                    fitnessRec.SchoolYear = SchoolYear.Value;
                    // 測驗日期
                    fitnessRec.TestDate = TestDate.Value;
                    // 學校類別
                    fitnessRec.SchoolCategory = Utility.GetIRowValueString(row, "學校類別");
                    // 身高
                    fitnessRec.Height = Utility.GetIRowValueString(row, "身高");
                    // 身高常模
                    fitnessRec.HeightDegree = Utility.GetIRowValueString(row, "身高常模");
                    // 體重
                    fitnessRec.Weight = Utility.GetIRowValueString(row, "體重");
                    // 體重常模
                    fitnessRec.WeightDegree = Utility.GetIRowValueString(row, "體重常模");
                    // 坐姿體前彎
                    fitnessRec.SitAndReach = Utility.GetIRowValueString(row, "坐姿體前彎");
                    // 坐姿體前彎常模
                    fitnessRec.SitAndReachDegree = Utility.GetIRowValueString(row, "坐姿體前彎常模");
                    // 立定跳遠
                    fitnessRec.StandingLongJump = Utility.GetIRowValueString(row, "立定跳遠");
                    // 立定跳遠常模
                    fitnessRec.StandingLongJumpDegree = Utility.GetIRowValueString(row, "立定跳遠常模");
                    // 仰臥起坐
                    fitnessRec.SitUp = Utility.GetIRowValueString(row, "仰臥起坐");
                    // 仰臥起坐常模
                    fitnessRec.SitUpDegree = Utility.GetIRowValueString(row, "仰臥起坐常模");
                    // 心肺適能
                    fitnessRec.Cardiorespiratory = Utility.GetIRowValueString(row, "心肺適能");
                    // 心肺適能常模
                    fitnessRec.CardiorespiratoryDegree = Utility.GetIRowValueString(row, "心肺適能常模");
                    #endregion
                }
                // 更新資料
                else
                {
                    #region 處理更新資料
                    // "學號/座號", "學年度", "測驗日期" 無法更新

                    // 學校類別
                    if (_Option.SelectedFields.Contains("學校類別"))
                    {
                        fitnessRec.SchoolCategory = Utility.GetIRowValueString(row, "學校類別");
                    }
                    // 身高
                    if (_Option.SelectedFields.Contains("身高"))
                    {
                        fitnessRec.Height = Utility.GetIRowValueString(row, "身高");
                    }
                    // 身高常模
                    if (_Option.SelectedFields.Contains("身高常模"))
                    {
                        fitnessRec.HeightDegree = Utility.GetIRowValueString(row, "身高常模");
                    }
                    // 體重
                    if (_Option.SelectedFields.Contains("體重"))
                    {
                        fitnessRec.Weight = Utility.GetIRowValueString(row, "體重");
                    }
                    // 體重常模
                    if (_Option.SelectedFields.Contains("體重常模"))
                    {
                        fitnessRec.WeightDegree = Utility.GetIRowValueString(row, "體重常模");
                    }
                    // 坐姿體前彎
                    if (_Option.SelectedFields.Contains("坐姿體前彎"))
                    {
                        fitnessRec.SitAndReach = Utility.GetIRowValueString(row, "坐姿體前彎");
                    }
                    // 坐姿體前彎常模
                    if (_Option.SelectedFields.Contains("坐姿體前彎常模"))
                    {
                        fitnessRec.SitAndReachDegree = Utility.GetIRowValueString(row, "坐姿體前彎常模");
                    }
                    // 立定跳遠
                    if (_Option.SelectedFields.Contains("立定跳遠"))
                    {
                        fitnessRec.StandingLongJump = Utility.GetIRowValueString(row, "立定跳遠");
                    }
                    // 立定跳遠常模
                    if (_Option.SelectedFields.Contains("立定跳遠常模"))
                    {
                        fitnessRec.StandingLongJumpDegree = Utility.GetIRowValueString(row, "立定跳遠常模");
                    }
                    // 仰臥起坐
                    if (_Option.SelectedFields.Contains("仰臥起坐"))
                    {
                        fitnessRec.SitUp = Utility.GetIRowValueString(row, "仰臥起坐");
                    }
                    // 仰臥起坐常模
                    if (_Option.SelectedFields.Contains("仰臥起坐常模"))
                    {
                        fitnessRec.SitUpDegree = Utility.GetIRowValueString(row, "仰臥起坐常模");
                    }
                    // 心肺適能
                    if (_Option.SelectedFields.Contains("心肺適能"))
                    {
                        fitnessRec.Cardiorespiratory = Utility.GetIRowValueString(row, "心肺適能");
                    }
                    // 心肺適能常模
                    if (_Option.SelectedFields.Contains("心肺適能常模"))
                    {
                        fitnessRec.CardiorespiratoryDegree = Utility.GetIRowValueString(row, "心肺適能常模");
                    }
                    #endregion
                }

                if (isInsert == true)
                {
                    _InsertRecList.Add(fitnessRec);
                }
                else
                {
                    _UpdateRecList.Add(fitnessRec);
                }
            }   // end of 判斷每一筆資料是要新增還是更新


            // 執行更新或新增
            if (_InsertRecList.Count > 0)
            {
                DAO.StudentFitness.InsertByRecordList(_InsertRecList);
            }
            if (_UpdateRecList.Count > 0)
            {
                DAO.StudentFitness.UpdateByRecordList(_UpdateRecList);
            }

            // Log
            Log.LogTransfer logTransfer = new Log.LogTransfer();
            StringBuilder   logData     = new StringBuilder();
            int             insertCnt   = _InsertRecList.Count;
            int             updateCnt   = _UpdateRecList.Count;
            logData.Append("總共匯入").Append((insertCnt + updateCnt)).Append("筆,");
            logData.Append("新增:").Append(insertCnt).Append("筆,");
            logData.Append("更新:").Append(updateCnt).Append("筆");
            logTransfer.SaveLog("學生.體適能-匯入", "匯入", "student", "", logData);

            return("");
        }
        private void btnDelete_Click(object sender, EventArgs e)
        {
            if(lvFitnessList.SelectedItems.Count > 0)
            {
                DAO.StudentFitnessRecord rec = lvFitnessList.SelectedItems[0].Tag as DAO.StudentFitnessRecord;
                if (FISCA.Presentation.Controls.MsgBox.Show("請問是否確定是刪除體適能紀錄?", "刪除體適能紀錄", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) == DialogResult.Yes)
                {
                    K12.Data.StudentRecord studRec = K12.Data.Student.SelectByID(PrimaryKey);
                    string studStr = "學號:" + studRec.StudentNumber + ",姓名:" + studRec.Name + ",";

                    Log.LogTransfer LogTransfer = new Log.LogTransfer();
                    Utility.SetLogData(LogTransfer, rec);
                    LogTransfer.SaveDeleteLog("學生.體適能-刪除", "刪除", studStr, "", "student", studRec.ID);
                    
                    DAO.StudentFitness.DeleteByRecord(rec);

                    _BGRun();
                }
            }
            else
            {
                FISCA.Presentation.Controls.MsgBox.Show("請選擇資料.");
            }
        }