Exemple #1
0
 private void dataGridViewX1_KeyDown(object sender, KeyEventArgs e)
 {
     //當使用者鍵入的是Del 或是 空白鍵
     if (e.KeyData == Keys.Delete || e.KeyData == Keys.Space)
     {
         foreach (DataGridViewCell cell in dataGridViewX1.SelectedCells)
         {
             if (cell.ColumnIndex > 3)
             {
                 StudRepeatObj obj = (StudRepeatObj)cell.OwningRow.DataBoundItem;
                 obj.Change = true;
                 if (obj._SCJionDIc.ContainsKey(cell.ColumnIndex))
                 {
                     SCJoin scj = obj._SCJionDIc[cell.ColumnIndex];
                     if (!obj._RemoveList.Contains(scj))
                     {
                         obj._RemoveList.Add(scj);
                     }
                 }
                 cell.Style.BackColor = Color.DarkGray;
                 cell.Style.ForeColor = Color.Red;
             }
         }
     }
 }
        private void btnSave_Click(object sender, EventArgs e)
        {
            //將指定好的學生
            //建立社團參與記錄
            //並加入該社團內

            btnSave.Enabled = false;

            List <SCJoin> SCJoinList = new List <SCJoin>();

            sb_log = new StringBuilder();
            sb_log.AppendLine(string.Format("「{0}」學年度 第「{1}」學期 未選社團學生分發:", seting_school_year, seting_school_semester));

            foreach (DataGridViewRow row in dataGridViewX1.Rows)
            {
                if (row.Cells[colSelectClub.Index].Tag != null)
                {
                    StudRecord sr = (StudRecord)row.Tag;
                    CLUBRecord cr = (CLUBRecord)row.Cells[colSelectClub.Index].Tag;

                    SCJoin sc = new SCJoin();
                    sc.RefClubID    = cr.UID;
                    sc.RefStudentID = sr.id;
                    SCJoinList.Add(sc);

                    sb_log.AppendLine(string.Format("班級「{0}」學生「{1}」社團指定為「{2}」", sr.class_name, sr.name, cr.ClubName));
                }
            }

            BGWSave.RunWorkerAsync(SCJoinList);
        }
Exemple #3
0
        /// <summary>
        ///
        /// </summary>
        public Log_Result(List <string> list, SCJoin sch)
        {
            _OldItemDic = new Dictionary <string, string>();
            _NewItemDic = new Dictionary <string, string>();
            IsChange    = false;
            _sch        = sch;
            foreach (string each in list)
            {
                _OldItemDic.Add(each, "");
                _NewItemDic.Add(each, "");
            }

            if (!string.IsNullOrEmpty(sch.Score))
            {
                XmlElement xml = DSXmlHelper.LoadXml(sch.Score);

                foreach (XmlElement each in xml.SelectNodes("Item"))
                {
                    string name  = each.GetAttribute("Name");
                    string Score = each.GetAttribute("Score");
                    if (_OldItemDic.ContainsKey(name))
                    {
                        _OldItemDic[name] = Score;
                        _NewItemDic[name] = Score;
                    }
                }
            }
        }
        private string GetLogString(SCJoin scj)
        {
            StringBuilder log = new StringBuilder();

            log.AppendLine(string.Format("社團編號「{0}」學生編號「{1}」", scj.RefClubID, scj.RefStudentID));

            return("");
        }
Exemple #5
0
 /// <summary>
 /// 取得調整後的"社團參與記錄"
 /// 如果未調整,則回傳null
 /// </summary>
 public SCJoin GetChange()
 {
     if (HasChanged)
     {
         SCJoin scj = GetSCJoin();
         scj.RefClubID = AdjustClubRecord.UID;
         return(scj);
     }
     else
     {
         return(null);
     }
 }
        /// <summary>
        /// 排序 參與學生 清單
        /// </summary>
        private int SortSCJ(SCJoin scj1, SCJoin scj2)
        {
            StudentRecord sr1 = studentDic[scj1.RefStudentID];
            StudentRecord sr2 = studentDic[scj2.RefStudentID];

            string stringStudent1 = (string.IsNullOrEmpty(sr1.RefClassID) ? "" : sr1.Class.Name).PadLeft(10);
            string stringStudent2 = (string.IsNullOrEmpty(sr2.RefClassID) ? "" : sr2.Class.Name).PadLeft(10);

            stringStudent1 += (sr1.SeatNo.HasValue ? sr1.SeatNo.Value.ToString() : "").PadLeft(10);
            stringStudent2 += (sr2.SeatNo.HasValue ? sr2.SeatNo.Value.ToString() : "").PadLeft(10);

            stringStudent1 += sr1.Name;
            stringStudent2 += sr2.Name;

            return(stringStudent1.CompareTo(stringStudent2));
        }
        /// <summary>
        /// 將選擇學生加入待處理
        /// </summary>
        private void toolStripMenuItem2_Click(object sender, EventArgs e)
        {
            List <string> list = new List <string>();

            foreach (ListViewItem each in listViewEx1.SelectedItems)
            {
                if (each.Tag == null)
                {
                    continue;
                }

                SCJoin stud = (SCJoin)each.Tag;
                list.Add(stud.RefStudentID);
            }
            K12.Presentation.NLDPanels.Student.AddToTemp(list);
        }
        /// <summary>
        /// 取得新的參與學生清單
        /// </summary>
        public List <SCJoin> GetNewSCJoinList()
        {
            List <SCJoin> list = new List <SCJoin>();

            if (_new_Club != null && _scj.Count != 0)
            {
                foreach (SCJoin each in _scj)
                {
                    SCJoin scj = new SCJoin();
                    scj.RefStudentID = each.RefStudentID;
                    scj.RefClubID    = _new_Club.UID;
                    scj.Lock         = each.Lock; //鎖定
                    list.Add(scj);
                }
            }
            return(list);
        }
Exemple #9
0
        public void RunInsert(SCJoin scj)
        {
            if (tool._StudentDic.ContainsKey(scj.RefStudentID))
            {
                //社團
                CLUBRecord cr = tool._ClubDic[scj.RefClubID];
                //學生
                StudentRecord sr = tool._StudentDic[scj.RefStudentID];

                ResultScoreRecord rsr = new ResultScoreRecord();
                rsr.SchoolYear = cr.SchoolYear;
                rsr.Semester   = cr.Semester;

                rsr.RefClubID    = cr.UID;  //社團ID
                rsr.RefStudentID = sr.ID;   //學生ID
                rsr.RefSCJoinID  = scj.UID; //參與記錄ID

                rsr.ClubName = cr.ClubName;

                rsr.ClubLevel = cr.Level; //社團評等


                if (!string.IsNullOrEmpty(scj.Score))
                {
                    rsr.ResultScore = tool.GetDecimalValue(scj); //成績
                }

                #region 幹部
                if (CadreDic.ContainsKey(cr.UID))
                {
                    if (CadreDic[cr.UID]._Cadre1.ContainsKey(sr.ID))
                    {
                        rsr.CadreName = CadreDic[cr.UID]._Cadre1[sr.ID];
                    }
                    else
                    {
                        rsr.CadreName = "";
                    }
                }
                #endregion

                InsertScoreList.Add(rsr);
            }
        }
        private void parseData(List <IRowStream> Rows, List <SCJoin> listInsertSCJoin, List <SCJoin> listUpdateSCJoin)
        {
            // 每一筆社團參於學生資料
            foreach (IRowStream row in Rows)
            {
                // 確認社團參與學生資料是新增或修改
                string schoolYear    = row.GetValue("學年度");
                string semester      = row.GetValue("學期");
                string clubName      = row.GetValue("社團名稱");
                string studentNumber = row.GetValue("學號");
                string studentName   = this._dicStudentNameByStudentNumber[studentNumber];
                string key           = string.Format("{0}_{1}_{2}_{3}", schoolYear, semester, clubName, studentNumber);
                string clubKey       = string.Format("{0}_{1}_{2}", schoolYear, semester, clubName);
                string newClubName   = this._dicClubDataByID[this._dicClubIDByKey[clubKey]].ClubName;

                if (this._dicSCJoinByKey.ContainsKey(key)) // 更新
                {
                    SCJoin scj = this._dicSCJoinByKey[key];

                    // log資料
                    string originClubName = this._dicClubDataByID[scj.RefClubID].ClubName;
                    string log            = string.Format("「{0}」學生「{1}」學年度「{2}」學期原參與社團「{3}」變更為「{4}」", studentName, schoolYear, semester, originClubName, newClubName);
                    this._listUpdateLog.Add(log);

                    // 更新資料
                    scj.RefClubID    = this._dicClubIDByKey[clubKey];
                    scj.RefStudentID = this._dicStudentIDByStudentNumber[studentNumber];
                    listUpdateSCJoin.Add(scj);
                }
                else // 新增
                {
                    // log資料
                    string log = string.Format("「{0}」學生「{1}」學年度「{2}」學期參與社團「{3}」", studentName, schoolYear, semester, newClubName);
                    this._listInsertLog.Add(log);

                    // 新增資料
                    SCJoin scj = new SCJoin();
                    scj.RefClubID    = this._dicClubIDByKey[clubKey];
                    scj.RefStudentID = this._dicStudentIDByStudentNumber[studentNumber];
                    listInsertSCJoin.Add(scj);
                }
            }
        }
Exemple #11
0
        void Save_BGW_DoWork(object sender, DoWorkEventArgs e)
        {
            List <SCJoin> UpdataList = new List <SCJoin>();

            foreach (StudentJoinRow row in Rowlist)
            {
                if (row.HasChanged)
                {
                    SCJoin scj = row.GetChange();
                    if (scj != null)
                    {
                        UpdataList.Add(scj);
                    }
                }
            }

            //_AccessHelper.InsertValues(InasertList);
            _AccessHelper.UpdateValues(UpdataList);
        }
Exemple #12
0
        private void 移除選擇學生ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            List <SCJoin> scjList = new List <SCJoin>();
            List <string> list    = new List <string>();

            foreach (ListViewItem item in listViewEx1.SelectedItems)
            {
                SCJoin scj = (SCJoin)item.Tag;
                scj.Lock = false;
                scjList.Add(scj);

                list.Add(scj.RefStudentID);

                foreach (ListViewItem.ListViewSubItem each in item.SubItems)
                {
                    each.BackColor = Color.White;
                }
                item.SubItems[7].Text = " ";
            }
            tool._A.UpdateValues(scjList);

            LockStudent("解除鎖定選社", list);
        }
Exemple #13
0
        private void 鎖定學生選社ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            List <SCJoin> scjList = new List <SCJoin>();
            List <string> list    = new List <string>();

            foreach (ListViewItem item in listViewEx1.SelectedItems)
            {
                SCJoin scj = (SCJoin)item.Tag;
                scj.Lock = true;
                scjList.Add(scj);

                list.Add(scj.RefStudentID);

                foreach (ListViewItem.ListViewSubItem each in item.SubItems)
                {
                    each.BackColor = Color.GreenYellow;
                }
                item.SubItems[7].Text = "是";
            }
            tool._A.UpdateValues(scjList);

            //Log
            LockStudent("鎖定學生選社", list);
        }
Exemple #14
0
        private void dataGridViewX1_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            DataGridViewCell cell = dataGridViewX1.CurrentCell;

            if (cell == null)
            {
                return;
            }

            if (cell.ColumnIndex <= 3)
            {
                return;
            }

            StudRepeatObj obj = (StudRepeatObj)cell.OwningRow.DataBoundItem;

            if (obj._SCJionDIc.ContainsKey(cell.ColumnIndex))
            {
                SCJoin scj = obj._SCJionDIc[cell.ColumnIndex];

                if (!obj._RemoveList.Contains(scj))
                {
                    obj.Change = true;
                    obj._RemoveList.Add(scj);
                    cell.Style.BackColor = Color.DarkGray;
                    cell.Style.ForeColor = Color.Red;
                }
                else
                {
                    obj.Change = false;
                    obj._RemoveList.Remove(scj);
                    cell.Style.BackColor = Color.White;
                    cell.Style.ForeColor = Color.Black;
                }
            }
        }
        //void dataGridViewX1_DataError(object sender, DataGridViewDataErrorEventArgs e)
        //{
        //    MsgBox.Show("輸入資料錯誤!!");
        //    e.Cancel = false;
        //}

        void BGW_FormLoad_DoWork(object sender, DoWorkEventArgs e)
        {
            StringBuilder sb_3 = new StringBuilder();

            GetPoint = new 成績取得器();
            GetPoint.SetWeightProportion();
            GetPoint.GetSCJoinByClubIDList(ClubAdmin.Instance.SelectedSource);

            #region 社團老師資訊

            List <string> teacherIDList = new List <string>();
            foreach (CLUBRecord club in GetPoint._ClubDic.Values)
            {
                if (!string.IsNullOrEmpty(club.RefTeacherID))
                {
                    if (!teacherIDList.Contains(club.RefTeacherID))
                    {
                        teacherIDList.Add(club.RefTeacherID);
                    }
                }
            }

            List <TeacherRecord> TeacherList = Teacher.SelectByIDs(teacherIDList);
            Dictionary <string, TeacherRecord> ClubTeacherDic = new Dictionary <string, TeacherRecord>();
            foreach (TeacherRecord each in TeacherList)
            {
                if (!ClubTeacherDic.ContainsKey(each.ID))
                {
                    ClubTeacherDic.Add(each.ID, each);
                }
            }

            #endregion

            #region 取得班級資料

            //從學生Record內取得班級ID,再取得班級Record
            ClassDic = GetClassDic();

            #endregion

            RowList.Clear();

            _logDic = new Dictionary <string, Log_Result>();

            //取得社團參與記錄
            foreach (List <SCJoin> each in GetPoint._SCJoinDic.Values)
            {
                if (each.Count == 1)
                {
                    #region 只有一筆資料
                    SCJoin sch = each[0];

                    SCJoinRow scjRow = new SCJoinRow();
                    scjRow.SCJ = sch;
                    //學生
                    if (GetPoint._StudentDic.ContainsKey(sch.RefStudentID))
                    {
                        scjRow.student = GetPoint._StudentDic[sch.RefStudentID];

                        //社團
                        if (GetPoint._ClubDic.ContainsKey(sch.RefClubID))
                        {
                            scjRow.club = GetPoint._ClubDic[sch.RefClubID];

                            if (ClubTeacherDic.ContainsKey(GetPoint._ClubDic[sch.RefClubID].RefTeacherID))
                            {
                                scjRow.teacher = ClubTeacherDic[GetPoint._ClubDic[sch.RefClubID].RefTeacherID];
                            }
                        }

                        if (GetPoint._RSRDic.ContainsKey(sch.UID))
                        {
                            scjRow.RSR = GetPoint._RSRDic[sch.UID];
                        }

                        RowList.Add(scjRow);
                    }
                    #endregion
                }
                else if (each.Count >= 1)
                {
                    #region  兩筆資料
                    //錯誤訊息
                    StudentRecord sr = Student.SelectByID(each[0].RefStudentID);
                    sb_3.AppendLine("學生[" + sr.Name + "]有2筆以上社團記錄");

                    SCJoin    sch    = each[0];
                    SCJoinRow scjRow = new SCJoinRow();
                    scjRow.SCJ = sch;
                    //學生
                    if (GetPoint._StudentDic.ContainsKey(sch.RefStudentID))
                    {
                        scjRow.student = GetPoint._StudentDic[sch.RefStudentID];

                        //社團
                        if (GetPoint._ClubDic.ContainsKey(sch.RefClubID))
                        {
                            scjRow.club = GetPoint._ClubDic[sch.RefClubID];

                            if (ClubTeacherDic.ContainsKey(GetPoint._ClubDic[sch.RefClubID].RefTeacherID))
                            {
                                scjRow.teacher = ClubTeacherDic[GetPoint._ClubDic[sch.RefClubID].RefTeacherID];
                            }
                        }

                        if (GetPoint._RSRDic.ContainsKey(sch.UID))
                        {
                            scjRow.RSR = GetPoint._RSRDic[sch.UID];
                        }

                        RowList.Add(scjRow);
                    }
                    #endregion
                }
                else
                {
                    //沒有記錄繼續
                }
            }

            if (!string.IsNullOrEmpty(sb_3.ToString()))
            {
                MsgBox.Show(sb_3.ToString());
            }
        }
        public ImportSCJoinData()
        {
            this.CustomValidate = (Rows, Messages) =>
            {
                CustomValidator(Rows, Messages);
            };

            #region 取得社團學生參與紀錄
            {
                List <SCJoin> listSCJoin = this._access.Select <SCJoin>();

                //2019/9/4 - 增加判斷,學號不為空值
                string    sql = @"
SELECT
    scj.uid
    , scj.ref_club_id
    , scj.ref_student_id
    , club.school_year
    , club.semester
    , club.club_name
    , student.student_number
FROM
    $k12.scjoin.universal AS scj
    LEFT OUTER JOIN $k12.clubrecord.universal AS club
        ON club.uid = scj.ref_club_id::BIGINT
    LEFT OUTER JOIN student 
        ON student.id = scj.ref_student_id::BIGINT
where student.student_number is not null
";
                DataTable dt  = this._qh.Select(sql);

                foreach (DataRow row in dt.Rows)
                {
                    // 社團學生參與紀錄整理
                    SCJoin scj = listSCJoin.Where(x => x.UID == "" + row["uid"]).First();
                    string key = string.Format("{0}_{1}_{2}_{3}", "" + row["school_year"], "" + row["semester"], "" + row["club_name"], "" + row["student_number"]);

                    //2019/9/4 - Dylan修正增加判斷,避免加入重複資料
                    //(tip:為何資料會重複,也是要確認的問題)
                    if (!_dicSCJoinByKey.ContainsKey(key))
                    {
                        this._dicSCJoinByKey.Add(key, scj);
                    }

                    // 學生編號整理
                }
            }
            #endregion

            #region 取得社團資料
            {
                List <CLUBRecord> listClubRecord = this._access.Select <CLUBRecord>();
                foreach (CLUBRecord cr in listClubRecord)
                {
                    // 社團編號整理
                    string clubKey = string.Format("{0}_{1}_{2}", cr.SchoolYear, cr.Semester, cr.ClubName);

                    //2019/9/4 - Dylan修正增加判斷,避免加入重複資料
                    if (!_dicClubIDByKey.ContainsKey(clubKey))
                    {
                        this._dicClubIDByKey.Add(clubKey, cr.UID);
                    }

                    if (!_dicClubDataByID.ContainsKey(cr.UID))
                    {
                        this._dicClubDataByID.Add(cr.UID, cr);
                    }
                }
            }
            #endregion

            #region 取得學生資料
            {
                string    sql = @"
SELECT
    id
    , name
    , student_number
FROM
    student
WHERE
    status IN(1,2)
    AND student_number IS NOT NULL
";
                DataTable dt  = this._qh.Select(sql);
                foreach (DataRow row in dt.Rows)
                {
                    //2019/9/4 - Dylan修正增加判斷,避免加入重複資料
                    string student_number = "" + row["student_number"];
                    if (!_dicStudentIDByStudentNumber.ContainsKey(student_number))
                    {
                        this._dicStudentIDByStudentNumber.Add(student_number, "" + row["id"]);
                    }

                    if (!_dicStudentNameByStudentNumber.ContainsKey(student_number))
                    {
                        this._dicStudentNameByStudentNumber.Add(student_number, "" + row["name"]);
                    }
                }
            }
            #endregion
        }
Exemple #17
0
        private void ClearStudent()
        {
            DialogResult dr = FISCA.Presentation.Controls.MsgBox.Show("是否移除選取的學生?", MessageBoxButtons.YesNo, MessageBoxDefaultButton.Button2);

            if (dr == DialogResult.No)
            {
                return;
            }

            //取得選擇學生的修課記錄
            List <SCJoin> list = new List <SCJoin>();

            foreach (ListViewItem each in listViewEx1.SelectedItems)
            {
                SCJoin stud = (SCJoin)each.Tag;
                list.Add(stud);
            }

            //Log
            StringBuilder sb_Log = new StringBuilder();

            sb_Log.AppendLine(string.Format("已移除「{0}」名社團學生:(學年度「{1}」學期「{2}」社團「{3}」)", list.Count.ToString(), _CLUBRecord.SchoolYear.ToString(), _CLUBRecord.Semester.ToString(), _CLUBRecord.ClubName));

            List <string> StudentIDList = new List <string>();
            List <string> ClubIDList    = new List <string>();

            foreach (SCJoin each in list)
            {
                if (!StudentIDList.Contains(each.RefStudentID))
                {
                    StudentIDList.Add(each.RefStudentID);
                    //移除社團學生Log
                    if (!string.IsNullOrEmpty(GetLogMessage(each.RefStudentID)))
                    {
                        sb_Log.AppendLine(GetLogMessage(each.RefStudentID));
                    }
                }

                if (!ClubIDList.Contains(each.RefClubID))
                {
                    ClubIDList.Add(each.RefClubID);
                }
            }

            Dictionary <string, CadresRecord> CadresDic = GetCadreList(StudentIDList, ClubIDList);

            //1.判斷該學生是否為本社社長
            //2.副社長
            //3.指導老師所指定的其他社團幹部
            //以上均需清除

            bool CheckIsCadre = false;

            StringBuilder sb_Message = new StringBuilder();

            sb_Message.AppendLine("移除清單中包含擔任幹部記錄!!");

            foreach (string each in StudentIDList)
            {
                //社長
                if (_CLUBRecord.President == each)
                {
                    CheckIsCadre = true;
                    if (scMAG.StudentDic.ContainsKey(each))
                    {
                        sb_Message.AppendLine("社長:" + scMAG.StudentDic[each].Name);
                    }
                }
                //副社長
                if (_CLUBRecord.VicePresident == each)
                {
                    CheckIsCadre = true;
                    if (scMAG.StudentDic.ContainsKey(each))
                    {
                        sb_Message.AppendLine("副社長:" + scMAG.StudentDic[each].Name);
                    }
                }
                //其他幹部資料
                if (CadresDic.ContainsKey(each))
                {
                    CheckIsCadre = true;
                    if (scMAG.StudentDic.ContainsKey(CadresDic[each].RefStudentID))
                    {
                        sb_Message.AppendLine(CadresDic[each].CadreName + ":" + scMAG.StudentDic[CadresDic[each].RefStudentID].Name);
                    }
                }
            }
            sb_Message.AppendLine("");
            sb_Message.AppendLine("請確認操作:");
            sb_Message.AppendLine("[是]移除學生,清除幹部記錄");
            sb_Message.AppendLine("[否]中止所有操作");

            if (CheckIsCadre) //如果有學生是擔任幹部
            {
                DialogResult dr1 = FISCA.Presentation.Controls.MsgBox.Show(sb_Message.ToString(), MessageBoxButtons.YesNo, MessageBoxDefaultButton.Button2);

                if (dr1 == DialogResult.Yes)
                {
                    foreach (string each in StudentIDList)
                    {
                        //社長
                        if (_CLUBRecord.President == each)
                        {
                            _CLUBRecord.President = "";
                        }
                        //副社長
                        if (_CLUBRecord.VicePresident == each)
                        {
                            _CLUBRecord.VicePresident = "";
                        }
                    }
                    //如果是社長副社長,就要更新一下資料
                    List <CLUBRecord> UpdataCLUBList = new List <CLUBRecord>()
                    {
                        _CLUBRecord
                    };
                    tool._A.UpdateValues(UpdataCLUBList);

                    //刪除社團幹部
                    tool._A.DeletedValues(CadresDic.Values.ToList());
                }
                else
                {
                    return;
                }
            }

            try
            {
                tool._A.DeletedValues(list);
            }
            catch (Exception ex)
            {
                FISCA.Presentation.Controls.MsgBox.Show("移除學生失敗\n" + ex.Message);
                SmartSchool.ErrorReporting.ReportingService.ReportException(ex);
                return;
            }

            FISCA.LogAgent.ApplicationLog.Log("社團", "移除社團學生", sb_Log.ToString());
            ClubEvents.RaiseAssnChanged();
        }
Exemple #18
0
        void BGW_DoWork(object sender, DoWorkEventArgs e)
        {
            //檢查目標學年期,是否有相同名稱之社團資料
            //如果有則移除該社團
            //並透過覆製功能進行新增動作
            _SkipList = GetExistClub();

            var copyClubList   = new List <CLUBRecord>();
            var copyClubIDList = new List <string>();


            foreach (var item in _CopyList)
            {
                //如果是重覆社團則不處理
                if (!_SkipList.Contains(item.ClubName))
                {
                    copyClubList.Add(item);
                    copyClubIDList.Add(item.UID);
                }
            }

            if (copyClubList.Count == 0)
            {
                return;
            }

            int LogSchoolYear = 90;
            int LogSemester   = 1;

            if (copyClubList.Count > 0)
            {
                LogSchoolYear = copyClubList[0].SchoolYear;
                LogSemester   = copyClubList[0].Semester;
            }

            StringBuilder sb = new StringBuilder();

            sb.AppendLine("已進行複製社團作業:");
            sb.AppendLine(string.Format("由學年度「{0}」學期「{1}」複製至學年度「{2}」學期「{3}」", LogSchoolYear.ToString(), LogSemester.ToString(), _SchoolYear.ToString(), _Semester.ToString()));
            if (_CopyOtherStudent)
            {
                sb.AppendLine("(已勾選複製學生選項)");
            }
            sb.AppendLine("");
            sb.AppendLine("新學期社團清單如下:");

            foreach (CLUBRecord each in copyClubList)
            {
                #region 複製社團基本資料

                //如果是重覆社團則不處理
                if (_SkipList.Contains(each.ClubName))
                {
                    continue;
                }

                CLUBRecord cr = new CLUBRecord();
                cr.About          = each.About;
                cr.ClubNumber     = each.ClubNumber;
                cr.ClubCategory   = each.ClubCategory;
                cr.ClubName       = each.ClubName;
                cr.DeptRestrict   = each.DeptRestrict;
                cr.GenderRestrict = each.GenderRestrict;
                cr.Grade1Limit    = each.Grade1Limit;
                cr.Grade2Limit    = each.Grade2Limit;
                cr.Grade3Limit    = each.Grade3Limit;
                cr.Limit          = each.Limit;
                cr.Location       = each.Location;
                cr.Photo1         = each.Photo1;
                cr.Photo2         = each.Photo2;
                cr.RefTeacherID   = each.RefTeacherID;
                cr.RefTeacherID2  = each.RefTeacherID2;
                cr.RefTeacherID3  = each.RefTeacherID3;
                cr.Level          = each.Level;

                if (_CopyPresidentStudent)
                {
                    //社長,副社長
                    cr.President     = each.President;
                    cr.VicePresident = each.VicePresident;
                }

                //使用者所設定之學年度學期
                cr.SchoolYear = _SchoolYear;
                cr.Semester   = _Semester;
                _NewInsertList.Add(cr);

                sb.AppendLine(string.Format("學年度「{0}」學期「{1}」社團名稱「{2}」", cr.SchoolYear.ToString(), cr.Semester.ToString(), cr.ClubName));


                #endregion
            }

            //新增之社團ID
            List <string> newIDList = new List <string>();

            try
            {
                newIDList = _AccessHelper.InsertValues(_NewInsertList);
            }
            catch (Exception ex)
            {
                SmartSchool.ErrorReporting.ReportingService.ReportException(ex);
                e.Cancel = true;
                return;
            }

            FISCA.LogAgent.ApplicationLog.Log("社團", "複製社團", sb.ToString());

            if (_CopyOtherStudent || _CopyCadresStudent || _CopyPresidentStudent)
            {
                #region 複製社團學生

                //取得社團
                List <CLUBRecord> newClubRecord = _AccessHelper.Select <CLUBRecord>(string.Format("UID in('{0}')", string.Join("','", newIDList)));

                Dictionary <string, List <CadresRecord> > studentCadreDic = new Dictionary <string, List <CadresRecord> >();

                Dictionary <string, List <SCJoin> > studentSCJDic = new Dictionary <string, List <SCJoin> >();

                //取得原有社團之學生社團記錄
                List <SCJoin> scjStudentList = _AccessHelper.Select <SCJoin>(string.Format("ref_club_id in ('{0}')", string.Join("','", copyClubIDList)));

                foreach (SCJoin each in scjStudentList)
                {
                    if (!studentSCJDic.ContainsKey(each.RefClubID))
                    {
                        studentSCJDic.Add(each.RefClubID, new List <SCJoin>());
                    }
                    studentSCJDic[each.RefClubID].Add(each);
                }

                //取得原有社團之學生幹部記錄
                List <CadresRecord> cadreStudentList = _AccessHelper.Select <CadresRecord>(string.Format("ref_club_id in ('{0}')", string.Join("','", copyClubIDList)));

                foreach (CadresRecord each in cadreStudentList)
                {
                    if (!studentCadreDic.ContainsKey(each.RefClubID))
                    {
                        studentCadreDic.Add(each.RefClubID, new List <CadresRecord>());
                    }
                    studentCadreDic[each.RefClubID].Add(each);
                }

                _InsertSCJList = new List <SCJoin>();
                List <CadresRecord> newCadresRecordList = new List <CadresRecord>();

                foreach (CLUBRecord newClubRec in newClubRecord)
                {
                    foreach (CLUBRecord copyClubRec in copyClubList)
                    {
                        if (newClubRec.ClubName == copyClubRec.ClubName)
                        {
                            if (studentSCJDic.ContainsKey(copyClubRec.UID))
                            {
                                foreach (var scjRec in studentSCJDic[copyClubRec.UID])
                                {
                                    if (_CopyPresidentStudent &&
                                        (copyClubRec.President == scjRec.RefStudentID ||
                                         copyClubRec.VicePresident == scjRec.RefStudentID))
                                    {
                                        #region 複製社長副社長
                                        SCJoin scj = new SCJoin();
                                        scj.RefStudentID = scjRec.RefStudentID;
                                        scj.RefClubID    = newClubRec.UID;

                                        //鎖定狀態 - 2021/4/15(鎖定狀態,依原鎖定狀態)
                                        if (IsNowLock)
                                        {
                                            scj.Lock = scjRec.Lock;
                                        }
                                        else
                                        {
                                            scj.Lock = true;
                                        }

                                        _InsertSCJList.Add(scj);
                                        #endregion
                                        continue;
                                    }
                                    if (_CopyCadresStudent &&
                                        studentCadreDic.ContainsKey(copyClubRec.UID))
                                    {
                                        bool match = false;
                                        #region 複製社團幹部
                                        foreach (var cadresRec in studentCadreDic[copyClubRec.UID])
                                        {
                                            if (cadresRec.RefStudentID == scjRec.RefStudentID)
                                            {
                                                CadresRecord cadre = new CadresRecord();
                                                cadre.RefStudentID = cadresRec.RefStudentID; //學生
                                                cadre.CadreName    = cadresRec.CadreName;    //幹部名稱
                                                cadre.RefClubID    = newClubRec.UID;
                                                newCadresRecordList.Add(cadre);

                                                SCJoin scj = new SCJoin();
                                                scj.RefStudentID = scjRec.RefStudentID;
                                                scj.RefClubID    = newClubRec.UID;

                                                //鎖定狀態 - 2021/4/15(鎖定狀態,依原鎖定狀態)
                                                if (IsNowLock)
                                                {
                                                    scj.Lock = scjRec.Lock;
                                                }
                                                else
                                                {
                                                    scj.Lock = true;
                                                }

                                                _InsertSCJList.Add(scj);
                                                match = true;
                                                break;
                                            }
                                        }
                                        #endregion
                                        if (match)
                                        {
                                            continue;
                                        }
                                    }

                                    if (_CopyOtherStudent)
                                    {
                                        #region 複製一般社員
                                        SCJoin scj = new SCJoin();
                                        scj.RefStudentID = scjRec.RefStudentID;
                                        scj.RefClubID    = newClubRec.UID;

                                        //鎖定狀態 - 2021/4/15(鎖定狀態,依原鎖定狀態)
                                        if (IsNowLock)
                                        {
                                            scj.Lock = scjRec.Lock;
                                        }
                                        else
                                        {
                                            scj.Lock = true;
                                        }

                                        _InsertSCJList.Add(scj);
                                        #endregion
                                        continue;
                                    }
                                }
                            }
                        }
                    }
                }


                try
                {
                    _AccessHelper.InsertValues(_InsertSCJList);
                    _AccessHelper.InsertValues(newCadresRecordList);
                }
                catch (Exception ex)
                {
                    SmartSchool.ErrorReporting.ReportingService.ReportException(ex);
                    e.Cancel = true;
                    return;
                }

                #endregion
            }
        }
        /// <summary>
        /// 計算比例成績
        /// </summary>
        public decimal GetDecimalValue(SCJoin scj)
        {
            decimal results = 0;

            if (_wp != null && !string.IsNullOrEmpty(scj.Score)) //必須有比例才能計算出成績
            {
                //暫時移除
                XmlElement dsx1 = DSXmlHelper.LoadXml(_wp.Proportion);

                XmlElement dsx2 = DSXmlHelper.LoadXml(scj.Score);

                foreach (XmlElement xml1 in dsx1.SelectNodes("Item"))
                {
                    string 比例名稱 = xml1.GetAttribute("Name");
                    string 比例   = xml1.GetAttribute("Proportion");

                    foreach (XmlElement xml2 in dsx2.SelectNodes("Item"))
                    {
                        string 成績名稱 = xml2.GetAttribute("Name");
                        string 成績   = xml2.GetAttribute("Score");

                        if (比例名稱 == 成績名稱)
                        {
                            decimal kj = 0;
                            decimal uo = 0;

                            if (decimal.TryParse(成績, out uo) && decimal.TryParse(比例, out kj))
                            {
                                results += uo * kj / 100;
                            }
                            break;
                        }
                    }
                }

                //decimal? 平時活動比例 = scj.Score;
                //decimal? 出缺率比例 = scj.ARScore;
                //decimal? 活動力及服務比例 = scj.AASScore;
                //decimal? 成品成果考驗比例 = scj.FARScore;

                //if (平時活動比例.HasValue)
                //    平時活動比例 = _wp.PA_Weight * 平時活動比例 / 100;

                //if (出缺率比例.HasValue)
                //    出缺率比例 = _wp.AR_Weight * 出缺率比例 / 100;

                //if (活動力及服務比例.HasValue)
                //    活動力及服務比例 = _wp.AAS_Weight * 活動力及服務比例 / 100;

                //if (成品成果考驗比例.HasValue)
                //    成品成果考驗比例 = _wp.FAR_Weight * 成品成果考驗比例 / 100;

                //if (平時活動比例.HasValue)
                //    results += 平時活動比例.Value;

                //if (出缺率比例.HasValue)
                //    results += 出缺率比例.Value;

                //if (活動力及服務比例.HasValue)
                //    results += 活動力及服務比例.Value;

                //if (成品成果考驗比例.HasValue)
                //    results += 成品成果考驗比例.Value;
            }

            return(results = Math.Round(results, MidpointRounding.AwayFromZero));
        }
Exemple #20
0
        /// <summary>
        /// 傳入分配
        /// </summary>
        private bool Allocation(學生選社亂數檔 ran, int NumberIndex)
        {
            //社團選社資料
            VolunteerRecord vr = ran._record;

            XmlElement xml = XmlHelper.LoadXml(vr.Content);

            //每一個社團
            foreach (XmlElement each in xml.SelectNodes("Club"))
            {
                int index = 0;
                int.TryParse(each.GetAttribute("Index"), out index);
                //當進行第一輪志願分配時
                if (index != NumberIndex)
                {
                    continue;
                }

                string clubID    = each.GetAttribute("Ref_Club_ID");
                string StudentID = vr.RefStudentID;

                //2013/4/8號
                //需建立一個ClubCount字典
                //覆蓋 - 把本期除了鎖定學生之社團記錄清除
                //略過 - 本期的社團記錄不予更動

                //1.須檢查目前系統是否有要加入的社團(例如該社團被選社後刪除)
                //2.目前此社團是否已額滿或目前社團人數為可加入狀態
                if (!CLUBDic.ContainsKey(clubID))
                {
                    continue;
                }

                //不存在社團記錄,表示可以新增
                if (!SCJLockDic.ContainsKey(StudentID))
                {
                    #region  存在社團記錄,表示可以新增
                    SCJoin scj = new SCJoin();
                    一個社團檢查 一社團 = CLUBCheckDic[clubID];

                    if (!一社團.人數未滿)
                    {
                        if (StudentDic.ContainsKey(StudentID))
                        {
                            一名學生 一學生 = StudentDic[StudentID];
                            sb_Log.AppendLine(string.Format("序號「{0}」班級「{1}」學生「{2}」開始進行第「{3}」志願分配", ran._Index, 一學生.class_name, 一學生.student_name, NumberIndex.ToString()));
                            sb_Log.AppendLine(string.Format("分配失敗原因:社團「{0}」人數已滿", 一社團._ClubObj.ClubName));
                            sb_Log.AppendLine("");
                            return(false);
                        }
                    }

                    if (StudentDic.ContainsKey(StudentID))
                    {
                        一名學生 一學生 = StudentDic[StudentID];
                        //序號「{0}」  ran._Index
                        sb_Log.AppendLine(string.Format("序號「{0}」班級「{1}」學生「{2}」開始進行第「{3}」志願分配", ran._Index, 一學生.class_name, 一學生.student_name, NumberIndex.ToString()));

                        //你必須是本社團科別限制之學生
                        //Count大於0,表示有科別限制
                        if (一社團.DeptList.Count > 0)
                        {
                            if (!一社團.DeptList.Contains(一學生.dept_name))
                            {
                                sb_Log.AppendLine(string.Format("分配失敗原因:志願「{0}」受到科別限制「{1}」", 一社團._ClubObj.ClubName, 一學生.dept_name));
                                sb_Log.AppendLine("");
                                //本社團選社失敗
                                continue;
                            }
                        }

                        if (一社團.男女限制 == 一學生.gender || 一社團.男女限制 == GetVolunteerData.男女.限制)
                        {
                            if (一學生.grade_year == "1" || 一學生.grade_year == "7" || 一學生.grade_year == "10")
                            {
                                if (一社團.一年級未滿)
                                {
                                    scj.RefClubID    = clubID;
                                    scj.RefStudentID = StudentID;

                                    一社團._Now_ClubStudentCount++;
                                    一社團._Now_GradeYear1++;

                                    sb_Log.AppendLine(string.Format("已入選社團「{0}」", 一社團._ClubObj.ClubName));
                                    sb_Log.AppendLine("");
                                    InsertList1.Add(scj);
                                    return(true);
                                }
                                else
                                {
                                    sb_Log.AppendLine(string.Format("分配失敗原因:志願「{0}」年級「{1}」人數已滿", 一社團._ClubObj.ClubName, 一學生.grade_year));
                                    sb_Log.AppendLine("");
                                }
                            }
                            else if (一學生.grade_year == "2" || 一學生.grade_year == "8" || 一學生.grade_year == "11")
                            {
                                if (一社團.二年級未滿)
                                {
                                    scj.RefClubID    = clubID;
                                    scj.RefStudentID = StudentID;

                                    一社團._Now_ClubStudentCount++;
                                    一社團._Now_GradeYear2++;

                                    sb_Log.AppendLine(string.Format("已入選社團「{0}」", 一社團._ClubObj.ClubName));
                                    sb_Log.AppendLine("");
                                    InsertList1.Add(scj);
                                    return(true);
                                }
                                else
                                {
                                    sb_Log.AppendLine(string.Format("分配失敗原因:志願「{0}」年級「{1}」人數已滿", 一社團._ClubObj.ClubName, 一學生.grade_year));
                                    sb_Log.AppendLine("");
                                }
                            }
                            else if (一學生.grade_year == "3" || 一學生.grade_year == "9" || 一學生.grade_year == "12")
                            {
                                if (一社團.年級未滿)
                                {
                                    scj.RefClubID    = clubID;
                                    scj.RefStudentID = StudentID;

                                    一社團._Now_ClubStudentCount++;
                                    一社團._Now_GradeYear3++;

                                    sb_Log.AppendLine(string.Format("已入選社團「{0}」", 一社團._ClubObj.ClubName));
                                    sb_Log.AppendLine("");
                                    InsertList1.Add(scj);
                                    return(true);
                                }
                                else
                                {
                                    sb_Log.AppendLine(string.Format("分配失敗原因:志願「{0}」年級「{1}」人數已滿", 一社團._ClubObj.ClubName, 一學生.grade_year));
                                    sb_Log.AppendLine("");
                                }
                            }
                            else
                            {
                                sb_Log.AppendLine(string.Format("分配社團「{0}」失敗,未符合年級設定", 一社團._ClubObj.ClubName));
                                sb_Log.AppendLine("");
                            }
                        }
                        else
                        {
                            sb_Log.AppendLine(string.Format("分配社團「{0}」失敗,未符合男女限制「{1}」", 一社團._ClubObj.ClubName, 一社團.男女限制));
                            sb_Log.AppendLine("");
                        }
                    }
                    #endregion
                }
                else //已存在,要判斷是覆蓋還是略過
                {
                    #region 已存在,要判斷是覆蓋還是略過
                    //已有社團記錄時 - 覆蓋
                    if (By_V.已有社團記錄時)
                    {
                        #region 覆蓋
                        SCJoin scj_del = SCJLockDic[StudentID];

                        if (!scj_del.Lock)
                        {
                            #region 未鎖定
                            //新增一筆資料
                            SCJoin scj = new SCJoin();

                            //因為覆蓋所以 - 列入刪除
                            if (!DeleteList.Contains(scj_del))
                            {
                                DeleteList.Add(scj_del);
                            }

                            一個社團檢查 一社團 = CLUBCheckDic[clubID];
                            if (!一社團.人數未滿)
                            {
                                if (StudentDic.ContainsKey(StudentID))
                                {
                                    一名學生 一學生 = StudentDic[StudentID];
                                    sb_Log.AppendLine(string.Format("序號「{0}」班級「{1}」學生「{2}」開始進行第「{3}」志願分配", ran._Index, 一學生.class_name, 一學生.student_name, NumberIndex.ToString()));
                                    sb_Log.AppendLine(string.Format("分配失敗原因:社團「{0}」人數已滿", 一社團._ClubObj.ClubName));
                                    sb_Log.AppendLine("");
                                    return(false);
                                }
                            }

                            if (StudentDic.ContainsKey(StudentID))
                            {
                                一名學生 一學生 = StudentDic[StudentID];

                                string clubName = "";
                                if (CLUBDic.ContainsKey(scj_del.RefClubID))
                                {
                                    clubName = CLUBDic[scj_del.RefClubID].ClubName;
                                }
                                //序號「{0}」  ran._Index
                                sb_Log.AppendLine(string.Format("序號「{0}」班級「{1}」學生「{2}」開始進行第「{3}」志願分配", ran._Index, 一學生.class_name, 一學生.student_name, NumberIndex.ToString()));
                                sb_Log.AppendLine(string.Format("已是社團「{0}」參與學生,因「未被鎖定」將進行重新分配", clubName));

                                //你必須是本社團科別限制之學生
                                //Count大於0,表示有科別限制
                                if (一社團.DeptList.Count > 0)
                                {
                                    if (!一社團.DeptList.Contains(一學生.dept_name))
                                    {
                                        sb_Log.AppendLine(string.Format("社團「{0}」分配失敗!原因:志願「{1}」受到科別限制「{2}」", 一社團._ClubObj.ClubName, NumberIndex, 一學生.dept_name));
                                        sb_Log.AppendLine("");
                                        //本社團選社失敗
                                        continue;
                                    }
                                }

                                if (一社團.男女限制 == 一學生.gender || 一社團.男女限制 == GetVolunteerData.男女.限制)
                                {
                                    if (一學生.grade_year == "1" || 一學生.grade_year == "7" || 一學生.grade_year == "10")
                                    {
                                        if (一社團.一年級未滿)
                                        {
                                            scj.RefStudentID = StudentID;
                                            scj.RefClubID    = clubID;

                                            一社團._Now_ClubStudentCount++;
                                            一社團._Now_GradeYear1++;

                                            InsertList2.Add(scj);

                                            sb_Log.AppendLine(string.Format("已入選社團「{0}」", 一社團._ClubObj.ClubName));
                                            sb_Log.AppendLine("");

                                            return(true);
                                        }
                                        else
                                        {
                                            sb_Log.AppendLine(string.Format("分配失敗原因:志願「{0}」年級「{1}」人數已滿", 一社團._ClubObj.ClubName, 一學生.grade_year));
                                            sb_Log.AppendLine("");
                                        }
                                    }
                                    else if (一學生.grade_year == "2" || 一學生.grade_year == "8" || 一學生.grade_year == "11")
                                    {
                                        if (一社團.二年級未滿)
                                        {
                                            scj.RefStudentID = StudentID;
                                            scj.RefClubID    = clubID;

                                            一社團._Now_ClubStudentCount++;
                                            一社團._Now_GradeYear2++;

                                            InsertList2.Add(scj);

                                            sb_Log.AppendLine(string.Format("已入選社團「{0}」", 一社團._ClubObj.ClubName));
                                            sb_Log.AppendLine("");
                                            return(true);
                                        }
                                        else
                                        {
                                            sb_Log.AppendLine(string.Format("分配失敗原因:志願「{0}」年級「{1}」人數已滿", 一社團._ClubObj.ClubName, 一學生.grade_year));
                                            sb_Log.AppendLine("");
                                        }
                                    }
                                    else if (一學生.grade_year == "3" || 一學生.grade_year == "9" || 一學生.grade_year == "12")
                                    {
                                        if (一社團.年級未滿)
                                        {
                                            scj.RefStudentID = StudentID;
                                            scj.RefClubID    = clubID;

                                            一社團._Now_ClubStudentCount++;
                                            一社團._Now_GradeYear3++;

                                            sb_Log.AppendLine(string.Format("已入選社團「{0}」", 一社團._ClubObj.ClubName));
                                            sb_Log.AppendLine("");

                                            InsertList2.Add(scj);
                                            return(true);
                                        }
                                        else
                                        {
                                            sb_Log.AppendLine(string.Format("分配失敗原因:志願「{0}」年級「{1}」人數已滿", 一社團._ClubObj.ClubName, 一學生.grade_year));
                                            sb_Log.AppendLine("");
                                        }
                                    }
                                    else
                                    {
                                        sb_Log.AppendLine(string.Format("分配社團「{0}」失敗,未符合年級設定", 一社團._ClubObj.ClubName));
                                        sb_Log.AppendLine("");
                                    }
                                }
                                else
                                {
                                    sb_Log.AppendLine(string.Format("分配社團「{0}」失敗,未符合男女限制「{1}」", 一社團._ClubObj.ClubName, 一社團.男女限制));
                                    sb_Log.AppendLine("");
                                }
                            }
                            #endregion
                        }
                        else
                        {
                            //取得社團記錄
                            SCJoin scj = SCJLockDic[StudentID];

                            string clubName = "";
                            if (CLUBDic.ContainsKey(scj.RefClubID))
                            {
                                clubName = CLUBDic[scj_del.RefClubID].ClubName;
                            }
                            // 2018/03/08 羿均 同步code
                            //2017/9/1 - 修正Bug
                            //這是多餘的程式邏輯 - By Dylan
                            if (StudentDic.ContainsKey(StudentID))
                            {
                                一名學生 一學生 = StudentDic[StudentID];
                                //序號「{0}」  ran._Index
                                sb_Log.AppendLine(string.Format("序號「{0}」班級「{1}」學生「{2}」開始進行第「{3}」志願分配", ran._Index, 一學生.class_name, 一學生.student_name, NumberIndex.ToString()));
                                sb_Log.AppendLine(string.Format("已是社團「{0}」鎖定學生,將不變更社團", clubName));
                                sb_Log.AppendLine("");

                                return(true);
                            }
                            #region 鎖定
                            //一個社團檢查 一社團 = CLUBCheckDic[scj_del.RefClubID];

                            //if (StudentDic.ContainsKey(StudentID))
                            //{
                            //    一名學生 一學生 = StudentDic[StudentID];

                            //    if (一學生.grade_year == "1" || 一學生.grade_year == "7" || 一學生.grade_year == "10")
                            //    {
                            //        一社團._Now_ClubStudentCount++;
                            //        一社團._Now_GradeYear1++;
                            //        return true;

                            //    }
                            //    else if (一學生.grade_year == "2" || 一學生.grade_year == "8" || 一學生.grade_year == "11")
                            //    {
                            //        一社團._Now_ClubStudentCount++;
                            //        一社團._Now_GradeYear2++;
                            //        return true;

                            //    }
                            //    else if (一學生.grade_year == "3" || 一學生.grade_year == "9" || 一學生.grade_year == "12")
                            //    {
                            //        一社團._Now_ClubStudentCount++;
                            //        一社團._Now_GradeYear3++;
                            //        return true;

                            //    }
                            //}
                            #endregion
                        }
                        #endregion
                    }
                    else
                    {
                        //2017/9/1 - 修正Bug
                        //這是多餘的程式邏輯 - By Dylan
                        #region 略過
                        //取得社團記錄
                        SCJoin scj = SCJLockDic[StudentID];

                        string clubName = "";
                        if (CLUBDic.ContainsKey(scj.RefClubID))
                        {
                            clubName = CLUBDic[scj.RefClubID].ClubName;
                        }

                        if (StudentDic.ContainsKey(StudentID))
                        {
                            一名學生 一學生 = StudentDic[StudentID];

                            //序號「{0}」  ran._Index
                            sb_Log.AppendLine(string.Format("目前設定:「略過」已入選學生,序號「{0}」學生「{1}」社團「{2}」將不變更", ran._Index, 一學生.student_name, clubName));
                            sb_Log.AppendLine("");

                            return(true);

                            //if (一學生.grade_year == "1" || 一學生.grade_year == "7" || 一學生.grade_year == "10")
                            //{
                            //    一社團._Now_ClubStudentCount++;
                            //    一社團._Now_GradeYear1++;
                            //    return true;

                            //}
                            //else if (一學生.grade_year == "2" || 一學生.grade_year == "8" || 一學生.grade_year == "11")
                            //{
                            //    一社團._Now_ClubStudentCount++;
                            //    一社團._Now_GradeYear2++;
                            //    return true;

                            //}
                            //else if (一學生.grade_year == "3" || 一學生.grade_year == "9" || 一學生.grade_year == "12")
                            //{
                            //    一社團._Now_ClubStudentCount++;
                            //    一社團._Now_GradeYear3++;
                            //    return true;

                            //}
                        }
                        #endregion
                    }
                    #endregion
                }
            }
            //選社失敗
            return(false);
        }
Exemple #21
0
        void BGW_Save_DoWork(object sender, DoWorkEventArgs e)
        {
            BGW_Save.ReportProgress(0, "志願分配作業...");
            //已有社團參與者略過或覆蓋
            DeleteList  = new List <SCJoin>();
            InsertList1 = new List <SCJoin>();
            InsertList2 = new List <SCJoin>();


            //增加退社相關作業(2015/9/14)
            if (By_V.已有社團記錄時) //有社團記錄時,不進行退社(True覆蓋,False略過)
            {
                //進行已選學生的退社處理
                foreach (DataGridViewRow row in dataGridViewX1.SelectedRows)
                {
                    if (row.DataBoundItem is 社團志願分配的Row)
                    {
                        社團志願分配的Row 班級 = (社團志願分配的Row)row.DataBoundItem;
                        foreach (一名學生 一學生 in 班級._StudentDic.Values)
                        {
                            if (SCJLockDic.ContainsKey(一學生.student_id))
                            {
                                SCJoin scj_del = SCJLockDic[一學生.student_id];
                                if (!scj_del.Lock) //不是鎖定的學生
                                {
                                    scj_del.Deleted = true;
                                    scj_del.Save();

                                    //設定社團人數
                                    一個社團檢查 一社團 = CLUBCheckDic[scj_del.RefClubID];
                                    SetClubGradeYearCount(一社團, 一學生, false);
                                }
                            }
                        }
                    }
                }
            }


            #region 社團參與依據

            //用條件進行排序的物件
            List <學生選社亂數檔> RunList = new List <學生選社亂數檔>();

            if (By_V.社團分配優先序)
            {
                #region 使用獎懲依據
                BGW_Save.ReportProgress(10, "取得獎懲資料...");
                獎懲換算機制 m = new 獎懲換算機制();

                BGW_Save.ReportProgress(20, "取得資料模型...");
                Dictionary <string, int> StudentMeritDic = m.GetMerit(StudentList);

                BGW_Save.ReportProgress(20, "取得資料模型...");

                List <社團志願分配的Row> IsRowList = new List <社團志願分配的Row>();
                foreach (DataGridViewRow row in dataGridViewX1.SelectedRows)
                {
                    if (row.DataBoundItem is 社團志願分配的Row)
                    {
                        IsRowList.Add((社團志願分配的Row)row.DataBoundItem);
                    }
                }
                foreach (社團志願分配的Row each in IsRowList)
                {
                    foreach (VolunteerRecord vol in each._Volunteer.Values)
                    {
                        if (StudentMeritDic.ContainsKey(vol.RefStudentID))
                        {
                            學生選社亂數檔 rr = new 學生選社亂數檔(vol, StudentMeritDic[vol.RefStudentID]);
                            RunList.Add(rr);
                        }
                    }
                }
                #endregion
            }
            else
            {
                #region 使用亂數依據
                BGW_Save.ReportProgress(10, "使用亂數依據...");

                Random _r = new Random();

                BGW_Save.ReportProgress(20, "取得資料模型...");
                List <社團志願分配的Row> IsRowList = new List <社團志願分配的Row>();
                foreach (DataGridViewRow row in dataGridViewX1.SelectedRows)
                {
                    if (row.DataBoundItem is 社團志願分配的Row)
                    {
                        IsRowList.Add((社團志願分配的Row)row.DataBoundItem);
                    }
                }
                foreach (社團志願分配的Row each in IsRowList)
                {
                    foreach (VolunteerRecord vol in each._Volunteer.Values)
                    {
                        學生選社亂數檔 rr = new 學生選社亂數檔(vol, _r.Next(99999));
                        RunList.Add(rr);
                    }
                }
                #endregion
            }

            BGW_Save.ReportProgress(30, "資料排序作業...");
            RunList.Sort(SortRandom);

            int _index = 1;
            foreach (學生選社亂數檔 rr in RunList)
            {
                rr._Index = _index;
                _index++;
            }

            #endregion

            //2016/9/7 - 略過功能不需要再一次進行人數統計
            //if (!By_V.已有社團記錄時) //True為覆蓋
            //{
            //    //要略過的話
            //    //要先進行資料的檢查
            //    SetCount(RunList);
            //}

            #region 開始分配學生社團狀態(相關狀態與學生都應該已處理)

            if (By_V.已有社團記錄時)
            {
                sb_Log.AppendLine("選社設定:覆蓋");
            }
            else
            {
                sb_Log.AppendLine("選社設定:略過");
            }

            sb_Log.AppendLine("每名學生志願數:" + By_V.學生選填志願數.ToString());

            //取志願
            BGW_Save.ReportProgress(45, "志願選填作業...");
            for (int x = 1; x <= By_V.學生選填志願數; x++)
            {
                BGW_Save.ReportProgress(65, string.Format("志願選填作業...{0}", x));

                sb_Log.AppendLine("");
                sb_Log.AppendLine(string.Format("═══開始進行第「{0}」志願分配═══", x.ToString()));
                sb_Log.AppendLine("");
                Judge(RunList, x);
            }

            #endregion

            //新增資料

            if (By_V.已有社團記錄時) //覆蓋
            {
                BGW_Save.ReportProgress(77, "清除學生選社...");
                //刪除學生社團參與記錄
                tool._A.DeletedValues(DeleteList);

                //新增未選社之學生
                BGW_Save.ReportProgress(84, "新增選社記錄..1");
                tool._A.InsertValues(InsertList1);
                //新增已選社之學生
                BGW_Save.ReportProgress(88, "新增選社記錄..2");
                tool._A.InsertValues(InsertList2);
            }
            else //略過資料
            {
                BGW_Save.ReportProgress(85, "新增選社記錄..1");
                //只新增未選社之學生
                tool._A.InsertValues(InsertList1);
            }
            BGW_Save.ReportProgress(100, "選社分配完成!!");

            ApplicationLog.Log("社團志願序模組", "志願分配", sb_Log.ToString());

            VolunteerLog logForm = new VolunteerLog(sb_Log.ToString());
            logForm.ShowDialog();
        }
        void BGW_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            dataGridViewX1.Enabled = true;
            this.Text = "學生選填明細";

            if (!e.Cancelled)
            {
                if (e.Error == null)
                {
                    SetColumn();

                    #region 建立Row

                    //取得該班級的學生基本資料
                    List <一名學生> list = _VolRow._StudentDic.Values.ToList();
                    //依座號排序
                    list.Sort(SortMergeList);

                    foreach (一名學生 each in list)
                    {
                        DataGridViewRow row = new DataGridViewRow();
                        row.CreateCells(dataGridViewX1);
                        row.Cells[0].Value = each.seat_no.HasValue ? each.seat_no.Value.ToString() : ""; //座號
                        row.Cells[1].Value = each.student_name;                                          //姓名
                        row.Cells[2].Value = each.gender;                                                //姓名


                        if (_VolRow._Volunteer.ContainsKey(each.student_id))
                        {
                            #region 必須有填志願才會被填入社團資料
                            //學生基本資料
                            VolunteerRecord obj = _VolRow._Volunteer[each.student_id];

                            //ClubDic社團是從選社志願內的資料
                            //因此它為0時,就表示多數數資料都沒有填志願
                            if (ClubDic.Count != 0)
                            {
                                //取得單一學生志願序選填狀況
                                if (!string.IsNullOrEmpty(obj.Content))
                                {
                                    XmlElement Element = XmlHelper.LoadXml(obj.Content);
                                    foreach (XmlElement xml in Element.SelectNodes("Club"))
                                    {
                                        //所選填的必須只有設定之數量
                                        int ClubIndex = 0;
                                        int.TryParse(xml.GetAttribute("Index"), out ClubIndex);
                                        if (ClubIndex <= _By_V.學生選填志願數 && ClubIndex != 0)
                                        {
                                            string clubID = xml.GetAttribute("Ref_Club_ID");
                                            //是否包含此社團
                                            if (ClubDic.ContainsKey(clubID))
                                            {
                                                CLUBRecord cr = ClubDic[clubID];
                                                //+3是因為由第 3 Column起始
                                                row.Cells[ClubIndex + 2].Value    = cr.ClubName;
                                                row.Cells[ClubIndex + 2].ReadOnly = true;
                                            }
                                        }
                                    }
                                }
                            }
                            #endregion
                        }

                        if (_VolRow._SCJDic.ContainsKey(each.student_id))
                        {
                            #region 當此學生有社團參與記錄時

                            SCJoin scj = _VolRow._SCJDic[each.student_id];
                            if (_VolRow._ClubDic.ContainsKey(scj.RefClubID))
                            {
                                CLUBRecord club = _VolRow._ClubDic[scj.RefClubID];
                                row.Cells[1].Value += "(" + club.ClubName + ")";

                                if (scj.Lock)
                                {
                                    foreach (DataGridViewCell cell in row.Cells)
                                    {
                                        cell.Style.BackColor = Color.GreenYellow;
                                    }
                                }
                                else
                                {
                                    foreach (DataGridViewCell cell in row.Cells)
                                    {
                                        cell.Style.BackColor = Color.Yellow;
                                    }
                                }
                            }

                            #endregion
                        }
                        else
                        {
                            StudentIDList.Add(each.student_id);
                        }

                        dataGridViewX1.Rows.Add(row);
                    }


                    #endregion
                }
                else
                {
                    MsgBox.Show("已發生錯誤!!\n" + e.Error.Message);
                }
            }
            else
            {
                MsgBox.Show("資料取得動作已取消");
            }
        }
Exemple #23
0
        /// <summary>
        /// 將傳入的學生ID,加入此課程
        /// </summary>
        private void AddListViewInTemp(List <string> IsSaft)
        {
            if (IsSaft.Count != 0)
            {
                cso = new ClubStudObj();

                //Log
                StringBuilder sb_Message = new StringBuilder();

                #region 可加入的學生清單

                //排除已存在本課程的學生
                cso.CheckTempStudentInCourse(IsSaft, scMAG.SCJoin_Dic, _CLUBRecord);

                StringBuilder sb_Log = new StringBuilder();
                sb_Log.AppendLine(string.Format("加入「{0}」名社團參與學生:(學年度「{1}」學期「{2}」社團「{3}」)", cso.InsertList.Count.ToString(), _CLUBRecord.SchoolYear.ToString(), _CLUBRecord.Semester.ToString(), _CLUBRecord.ClubName));

                if (cso.ReMoveTemp.Count != 0)
                {
                    #region 是否有重覆加入本社學生 - 錯誤

                    sb_Message.AppendLine("共有" + cso.ReMoveTemp.Count + "名學生,存在本社團!!");
                    List <StudentRecord> studlist = Student.SelectByIDs(cso.ReMoveTemp);
                    studlist = SortClassIndex.K12Data_StudentRecord(studlist);
                    foreach (StudentRecord stud in studlist)
                    {
                        string class_981  = string.IsNullOrEmpty(stud.RefClassID) ? "" : stud.Class.Name;
                        string SeatNo_981 = stud.SeatNo.HasValue ? stud.SeatNo.Value.ToString() : "";
                        sb_Message.AppendLine("班級「" + class_981 + "」座號「" + SeatNo_981 + "」姓名「" + stud.Name + "」");
                    }

                    #endregion

                    MsgBox.Show(sb_Message.ToString(), "錯誤", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }

                if (cso.ReDoubleTemp.Count != 0)
                {
                    #region 重覆參與其它社團記錄 -警告

                    sb_Message.AppendLine("共有" + cso.ReDoubleTemp.Count + "筆,重覆參與其它社團記錄");


                    //取得重覆社團
                    List <CLUBRecord> cludlist = tool._A.Select <CLUBRecord>("uid in ('" + string.Join("','", cso.GetClubID()) + "')");
                    Dictionary <string, CLUBRecord> clubDic = new Dictionary <string, CLUBRecord>();
                    foreach (CLUBRecord each in cludlist)
                    {
                        if (!clubDic.ContainsKey(each.UID))
                        {
                            clubDic.Add(each.UID, each);
                        }
                    }

                    studentDic.Clear();
                    foreach (StudentRecord each in Student.SelectByIDs(cso.GetStudentID()))
                    {
                        if (!studentDic.ContainsKey(each.ID))
                        {
                            studentDic.Add(each.ID, each);
                        }
                    }
                    cso.ReDoubleTemp.Sort(SortSCJ);
                    foreach (SCJoin SCJ in cso.ReDoubleTemp)
                    {
                        StudentRecord stud = studentDic[SCJ.RefStudentID];
                        CLUBRecord    cr   = clubDic[SCJ.RefClubID];

                        string class_981  = string.IsNullOrEmpty(stud.RefClassID) ? "" : stud.Class.Name;
                        string SeatNo_981 = stud.SeatNo.HasValue ? stud.SeatNo.Value.ToString() : "";
                        sb_Message.AppendLine("班級「" + class_981 + "」座號「" + SeatNo_981 + "」姓名「" + stud.Name + "」重覆社團「" + cr.ClubName + "」");
                    }

                    #endregion

                    DialogResult dr = MsgBox.Show(sb_Message.ToString() + "\n您是否要繼續進行此作業?", "警告", MessageBoxButtons.YesNo, MessageBoxIcon.Error);
                    if (dr != DialogResult.Yes)
                    {
                        MsgBox.Show("作業已中止!!");
                        return;
                    }
                }

                if (cso.InsertList.Count != 0)
                {
                    #region InsertList

                    //取得Log學生物件
                    cso.GetLogStudent();

                    List <SCJoin> SCJoinlist = new List <SCJoin>();
                    foreach (string each in cso.InsertList)
                    {
                        SCJoin JHs = new SCJoin();
                        JHs.RefStudentID = each; //修課學生
                        JHs.RefClubID    = this.PrimaryKey;
                        SCJoinlist.Add(JHs);

                        //加入修課LOG
                        if (!string.IsNullOrEmpty(GetLogMessage(each)))
                        {
                            sb_Log.AppendLine(GetLogMessage(each));
                        }
                    }

                    try
                    {
                        tool._A.InsertValues(SCJoinlist);
                    }
                    catch (Exception ex)
                    {
                        MsgBox.Show("新增社員資料失敗\n" + ex.Message);
                        SmartSchool.ErrorReporting.ReportingService.ReportException(ex);
                        return;
                    }

                    //移出待處理
                    StringBuilder sbHelp = new StringBuilder();
                    sbHelp.AppendLine("已由待處理加入社員\n共「" + cso.InsertList.Count.ToString() + "」名學生\n");
                    MsgBox.Show(sbHelp.ToString());

                    FISCA.LogAgent.ApplicationLog.Log("社團", "加入社員", sb_Log.ToString());
                    K12.Presentation.NLDPanels.Student.RemoveFromTemp(cso.InsertList);

                    ClubEvents.RaiseAssnChanged();

                    #endregion
                }

                #endregion
            }
            else
            {
                string message = "請檢查\n1.待處理無學生\n2.學生狀態有誤(非一般生)";
                FISCA.Presentation.Controls.MsgBox.Show(message);
            }
        }