public void SetDefaultData(int EventID, int SchoolYear, string Category, string EventName, UDT.GroupTypes gpType)
 {
     _EventID    = EventID;
     _SchoolYear = SchoolYear;
     _Category   = Category;
     _EventName  = EventName;
     _GroupTypes = gpType;
 }
        private void btnRegLimit_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(_EventData.UID))
            {
                FISCA.Presentation.Controls.MsgBox.Show("需要新增競賽項目後才能設定。");
                return;
            }

            frmEventLimitStudent frls = new frmEventLimitStudent();
            int evID = int.Parse(_EventData.UID);

            UDT.GroupTypes gt = null;

            if (_GroupTypesDict.ContainsKey(cbxGroupType.Text))
            {
                gt = _GroupTypesDict[cbxGroupType.Text];
            }

            frls.SetDefaultData(evID, _EventData.SchoolYear, txtCategory.Text, txtName.Text, gt);
            if (frls.ShowDialog() == DialogResult.Yes)
            {
            }
        }
        private void btnSave_Click(object sender, EventArgs e)
        {
            //  檢查資料是否空白
            bool hasError = false;

            foreach (DataGridViewRow drv in dgData.Rows)
            {
                if (drv.IsNewRow)
                {
                    continue;
                }

                foreach (DataGridViewCell cell in drv.Cells)
                {
                    if (cell.ColumnIndex == colCreatedBy.Index)
                    {
                        continue;
                    }

                    if (cell.Value == null)
                    {
                        hasError = true;
                    }
                }
            }

            if (hasError)
            {
                FISCA.Presentation.Controls.MsgBox.Show("不能空白");
                return;
            }

            // 需要儲存資料
            List <UDT.GroupTypes> saveDataList = new List <UDT.GroupTypes>();
            List <UDT.GroupTypes> delDataList  = new List <UDT.GroupTypes>();
            List <string>         hasDataUID   = new List <string>();

            List <string> check_name = new List <string>();
            bool          nameErr    = false;

            // 比對取得資料與畫面資料,進行新增修改刪除動作
            foreach (DataGridViewRow drv in dgData.Rows)
            {
                if (drv.IsNewRow)
                {
                    continue;
                }

                UDT.GroupTypes data = null;

                if (drv.Tag == null)
                {
                    // 新增
                    data           = new UDT.GroupTypes();
                    data.CreatedBy = _userAccount;
                }
                else
                {
                    data = drv.Tag as UDT.GroupTypes;
                    hasDataUID.Add(data.UID);
                }

                data.Name = drv.Cells[colName.Index].Value.ToString();
                if (!check_name.Contains(data.Name))
                {
                    check_name.Add(data.Name);
                }
                else
                {
                    nameErr = true;
                }
                data.Grade = parseGrade(drv.Cells[colGrade.Index]);

                if (drv.Cells[colGender.Index].Value == null)
                {
                    data.Gender = "";
                }
                else
                {
                    if (drv.Cells[colGender.Index].Value.ToString() == "男")
                    {
                        data.Gender = "M";
                    }
                    else if (drv.Cells[colGender.Index].Value.ToString() == "女")
                    {
                        data.Gender = "F";
                    }
                    else
                    {
                        data.Gender = "";
                    }
                }

                saveDataList.Add(data);
            }

            // 檢查名稱是否重複
            if (nameErr)
            {
                FISCA.Presentation.Controls.MsgBox.Show("名稱有重複無法儲存。");
                return;
            }

            // 比對來源元件沒有 uid 需要刪除
            foreach (var sdata in _GroupTypesList)
            {
                if (!hasDataUID.Contains(sdata.UID))
                {
                    delDataList.Add(sdata);
                }
            }

            if (delDataList.Count > 0)
            {
                foreach (var data in delDataList)
                {
                    data.Deleted = true;
                    saveDataList.Add(data);
                }
            }

            try
            {
                saveDataList.SaveAll();
                FISCA.Presentation.Controls.MsgBox.Show("儲存完成");
                this.DialogResult = DialogResult.OK;
            }
            catch (Exception ex)
            {
                FISCA.Presentation.Controls.MsgBox.Show("儲存失敗," + ex.Message);
            }
        }
Beispiel #4
0
        private void btnAddPlayer_Click(object sender, EventArgs e)
        {
            string refEventID = "";


            // 檢查競賽項目
            if (_eventItemDict.ContainsKey(cbxEventItem.Text))
            {
                refEventID = _eventItemDict[cbxEventItem.Text];
            }
            else
            {
                FISCA.Presentation.Controls.MsgBox.Show("請選擇競賽項目");
                return;
            }
            UDT.Events curEvent = null;
            // 取得競賽 udt
            if (_eventDict.ContainsKey(refEventID))
            {
                curEvent = _eventDict[refEventID];
            }

            // 檢查活動報名日期與結束日期
            if (_selectedEvent.RegStartDate.HasValue && _selectedEvent.RegEndDate.HasValue)
            {
                DateTime dt = System.DateTime.Now;
                if (dt >= _selectedEvent.RegStartDate.Value && dt <= _selectedEvent.RegEndDate.Value)
                {
                    // 可報名
                }
                else
                {
                    FISCA.Presentation.Controls.MsgBox.Show("非報名期間內無法報名。");
                    return;
                }
            }
            else
            {
                FISCA.Presentation.Controls.MsgBox.Show("沒有設定報名開始日期或報名結束日期無法報名。");
                return;
            }

            int maxCount = 0;

            if (curEvent != null)
            {
                maxCount = curEvent.MaxMemberCount;
            }
            UDT.GroupTypes curGp = null;
            // 取得 group
            if (_groupDict.ContainsKey(curEvent.RefGroupTypeId.ToString()))
            {
                curGp = _groupDict[curEvent.RefGroupTypeId.ToString()];
            }

            // 檢查隊員是否超過最大人數,如果超過無法新增。

            if (dgPlayerData.Rows.Count == curEvent.MaxMemberCount)
            {
                FISCA.Presentation.Controls.MsgBox.Show("參賽人數已達最多人數" + curEvent.MaxMemberCount + "人,無法新增。");
                return;
            }

            frmRegRecordAddPlayer frrap = new frmRegRecordAddPlayer();

            if (curGp != null)
            {
                if (curGp.Grade.HasValue)
                {
                    frrap.SetGradeYearFilter(curGp.Grade.Value.ToString());
                }

                if (curGp.Gender == "M" || curGp.Gender == "F")
                {
                    frrap.SetGenderFilter(curGp.Gender);
                }
            }

            // 判斷如果是個人賽傳入 null,團體賽取得 ID 傳入
            if (_selectedEvent != null && _selectedEvent.IsTeam)
            {
                // 團體,取得畫面上所選隊伍 ID
                if (dgTeamData.SelectedRows.Count == 1)
                {
                    int tid = int.Parse(dgTeamData.SelectedRows[0].Tag.ToString());
                    frrap.SetTeamID(tid);
                    frrap.SetTeamName(dgTeamData.SelectedRows[0].Cells[colTeamName.Index].Value.ToString());
                }
                else
                {
                    FISCA.Presentation.Controls.MsgBox.Show("請選擇隊伍");
                    return;
                }
            }
            else
            {
                // 個人
                frrap.SetTeamID(null);
            }

            frrap.SetEventID(int.Parse(refEventID));

            // 設定最多人數
            maxCount = maxCount - dgPlayerData.Rows.Count;
            frrap.SetMaxCount(maxCount);

            if (frrap.ShowDialog() == DialogResult.Yes)
            {
                _bgSearch.RunWorkerAsync();
            }
        }