/// <summary> /// 當按鈕被按下 /// </summary> void item1_Click(object sender, EventArgs e) { ButtonX item1 = (ButtonX)sender; CLUBRecord cr = (CLUBRecord)item1.Tag; //int count = 0; //foreach (DataGridViewRow row in dataGridViewX1.SelectedRows) //{ // StudentJoinRow scjRow = (StudentJoinRow)row.DataBoundItem; // if (scjRow.SCJoinList.Count > 1) // { // count++; // } //} //if (count != 0) // MsgBox.Show("有重覆參與社團之學生「" + count + "」名\n無法設定為「" + cr.ClubName + "」"); foreach (DataGridViewRow row in dataGridViewX1.SelectedRows) { StudentJoinRow scjRow = (StudentJoinRow)row.DataBoundItem; if (scjRow.SCJoinList.Count > 1) { continue; } scjRow.ChangeCLUB(cr); ((DataGridViewColorBallTextCell)row.Cells[7]).Color = _ClubColorList[((CLUBRecord)item1.Tag).UID]; ((DataGridViewColorBallTextCell)row.Cells[7]).Value = _ClubNameList[((CLUBRecord)item1.Tag).UID]; } CountStudents(); }
/// <summary> /// 選擇變更時 /// </summary> private void dataGridViewX1_SelectionChanged(object sender, EventArgs e) { foreach (DataGridViewRow row in dataGridViewX1.SelectedRows) { StudentJoinRow scjRow = (StudentJoinRow)row.DataBoundItem; if (scjRow.SCJoinList.Count > 1) { row.Selected = false; return; } } labelX1.Text = "選取「" + dataGridViewX1.SelectedRows.Count + "」人"; }
private int SortCLUBRecord(StudentJoinRow x, StudentJoinRow y) { //課程名稱 string ax = x.CurrentClubName.PadLeft(20, '0'); ax += x.GradeYear.PadLeft(2, '0'); ax += x.ClassName.PadLeft(8, '0'); ax += x.SeatNo.PadLeft(3, '0'); string ay = y.CurrentClubName.PadLeft(20, '0'); ay += y.GradeYear.PadLeft(2, '0'); ay += y.ClassName.PadLeft(8, '0'); ay += y.SeatNo.PadLeft(3, '0'); return(ax.CompareTo(ay)); }
void BGW_FormLoad_DoWork(object sender, DoWorkEventArgs e) { //社團 new_ClubDic = GetSplitOBJ.GetClubRecord(); //學生參與記錄 new_SCJoinDic = GetSplitOBJ.GetSCJoin(); Dictionary <string, List <SCJoin> > new_StudentBySCJoin = new Dictionary <string, List <SCJoin> >(); foreach (SCJoin each in new_SCJoinDic.Values) { if (!new_StudentBySCJoin.ContainsKey(each.RefStudentID)) { new_StudentBySCJoin.Add(each.RefStudentID, new List <SCJoin>()); } new_StudentBySCJoin[each.RefStudentID].Add(each); } //學生參與記錄 //new_StudentIDBySCJoin = GetSplitOBJ.GetSCJoin(); //由SCJoin 取得不重覆的學生ID List <string> StudentIDList = GetSplitOBJ.GetStudentIDList(new_SCJoinDic.Values.ToList()); //取得班級相關資訊清單 new_ClassDic = GetSplitOBJ.GetClassRecord(StudentIDList); //取得學生StudentRecord studentRecordList = Student.SelectByIDs(StudentIDList); //依據學生建立資料行 Rowlist.Clear(); foreach (StudentRecord studentRec in studentRecordList) { if (tool.CheckStatus(studentRec)) { StudentJoinRow newJoinRow = new StudentJoinRow(); newJoinRow.Ref_Student_Id = studentRec.ID; newJoinRow.Name = studentRec.Name; newJoinRow.SeatNo = studentRec.SeatNo.HasValue ? studentRec.SeatNo.Value.ToString() : ""; newJoinRow.StudentNumber = studentRec.StudentNumber; newJoinRow.Gender = studentRec.Gender; //填入學生班級/年級資訊 if (studentRec.RefClassID != null) { if (new_ClassDic.ContainsKey(studentRec.RefClassID)) { newJoinRow.GradeYear = new_ClassDic[studentRec.RefClassID].gradeyear; newJoinRow.ClassName = new_ClassDic[studentRec.RefClassID].classname; } } //取得社員參與記錄 if (new_StudentBySCJoin.ContainsKey(studentRec.ID)) { newJoinRow.SCJoinList = new_StudentBySCJoin[studentRec.ID]; } //取得目前社團資料 if (newJoinRow.SCJoinList.Count == 1) { newJoinRow.CurrentClubRecord = new_ClubDic[newJoinRow.SCJoinList[0].RefClubID]; } Rowlist.Add(newJoinRow); } } Rowlist.Sort(SortCLUBRecord); }
void BGW_FormLoad_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) { btnSave.Enabled = true; if (e.Cancelled) { MsgBox.Show("背景作業已取消..."); } else { if (e.Error == null) { _ClubNameList.Clear(); _ClubColorList.Clear(); ButtonCount = 0; //加入Button this.flowLayoutPanel1.Controls.Clear(); foreach (CLUBRecord each in new_ClubDic.Values) { ButtonX item1 = SetBotton(each); this.flowLayoutPanel1.Controls.Add(item1); //加入到Panel裡面 } dataGridViewX1.AutoGenerateColumns = false; dataGridViewX1.DataSource = new BindingList <StudentJoinRow>(Rowlist); foreach (DataGridViewRow row in dataGridViewX1.Rows) { StudentJoinRow scjRow = (StudentJoinRow)row.DataBoundItem; if (scjRow.SCJoinList.Count > 1) { row.ReadOnly = true; foreach (DataGridViewCell cell in row.Cells) { cell.Style.BackColor = Color.Gray; } } else if (scjRow.SCJoinList.Count == 1) { ((DataGridViewColorBallTextCell)row.Cells[7]).Color = _ClubColorList[scjRow.CurrentClubRecord.UID]; ((DataGridViewColorBallTextCell)row.Cells[7]).Value = _ClubNameList[scjRow.CurrentClubRecord.UID]; ((DataGridViewColorBallTextCell)row.Cells[6]).Color = _ClubColorList[scjRow.CurrentClubRecord.UID]; ((DataGridViewColorBallTextCell)row.Cells[6]).Value = _ClubNameList[scjRow.CurrentClubRecord.UID]; } } #region 資料 //DataGridViewRow row = new DataGridViewRow(); //row.CreateCells(dataGridViewX1); //row.Cells[0].Tag = studentRec; //Cell0 - 儲存StudentRecord //string cr = studentRec.RefClassID; //if (ClassDic.ContainsKey(cr)) //{ // //年級 // row.Cells[0].Value = ClassDic[cr].gradeyear; // //班級 // row.Cells[1].Value = ClassDic[cr].classname; //} ////座號 //row.Cells[2].Value = studentRec.SeatNo.HasValue ? studentRec.SeatNo.Value.ToString() : ""; ////學號 //row.Cells[3].Value = studentRec.StudentNumber; ////性別 //row.Cells[4].Value = studentRec.Gender; ////姓名 //row.Cells[5].Value = studentRec.Name; ////"Count 大於 1"表示此學生重覆參與社團 //row.Cells[6].Value = _StudentAttenCourses[studentRec.ID].Count == 1 ? _ClubNameList[_StudentAttenCourses[studentRec.ID][0].ClubID] : "重覆參與社團"; //row.Cells[7].Value = _StudentAttenCourses[studentRec.ID].Count == 1 ? _ClubNameList[_StudentAttenCourses[studentRec.ID][0].ClubID] : "重覆參與社團"; //int newRowIndex = dataGridViewX1.Rows.Add(row); ////"Count==1"表示此學生重覆參與社團 //if (_StudentAttenCourses[studentRec.ID].Count == 1) //{ // dataGridViewX1.Rows[newRowIndex].Tag = _StudentAttenCourses[studentRec.ID][0]; // ((DataGridViewColorBallTextCell)dataGridViewX1.Rows[newRowIndex].Cells[6]).Color = _CourseColor[_StudentAttenCourses[studentRec.ID][0].CourseID]; // ((DataGridViewColorBallTextCell)dataGridViewX1.Rows[newRowIndex].Cells[7]).Color = _CourseColor[_StudentAttenCourses[studentRec.ID][0].CourseID]; //} //else //{ // //1.顏色為Gray // //2.整Row欄位皆為"唯讀" // dataGridViewX1.Rows[newRowIndex].ReadOnly = true; // foreach (DataGridViewCell cell in dataGridViewX1.Rows[newRowIndex].Cells) // { // cell.Style.BackColor = Color.Gray; // } //} #endregion dataGridViewX1_SelectionChanged(null, null); dataGridViewX1_Sorted(null, null); CountStudents(); } else { MsgBox.Show("取得資料發生錯誤...\n" + e.Error.Message); } } }