void _dgv_KeyUp(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Delete) { foreach (DataGridViewCell cell in _dgv.SelectedCells) { IExamCell ic = cell.Tag as IExamCell; if (ic == null) { continue; } cell.Value = ""; ic.SetValue(""); CellEdited(cell, ic); } } //else if (e.KeyCode == Keys.Control | e.KeyCode == Keys.V) //{ // string value = Clipboard.GetText(); // string[] rowValues = value.Split('\n'); // XmlDocument doc = new XmlDocument(); // XmlElement root = doc.CreateElement("RootElement"); // foreach (string rowValue in rowValues) // { // XmlElement rowElement = doc.CreateElement(""); // } //} }
void _dgv_CellEndEdit(object sender, DataGridViewCellEventArgs e) { DataGridViewRow row = _dgv.Rows[e.RowIndex]; DataGridViewCell cell = row.Cells[e.ColumnIndex]; IExamCell icell = cell.Tag as IExamCell; CellEdited(cell, icell); }
public void Fill() { _dgv.Columns.Clear(); _dgv.Rows.Clear(); foreach (ColumnSetting setting in _provider.ColumnHeader.Columns) { int columnIndex = _dgv.Columns.Add(setting.ColumnName, setting.ColumnName); DataGridViewColumn col = _dgv.Columns[columnIndex]; col.Width = setting.ColumnWidth; col.Tag = setting; } try { foreach (RowEntity row in _provider.Rows.Entities) { int rowIndex = _dgv.Rows.Add(); DataGridViewRow currentRow = _dgv.Rows[rowIndex]; currentRow.Tag = row.StudentID; foreach (DataGridViewColumn column in _dgv.Columns) { ICell valueCell = row.Cells[column.Name]; string value = valueCell.GetValue(); DataGridViewCell currentCell = currentRow.Cells[column.Name]; currentCell.Value = value; currentCell.Tag = valueCell; if (valueCell is StudentCell) { column.Frozen = true; column.ReadOnly = true; } else { IExamCell examCell = valueCell as IExamCell; if (!string.IsNullOrEmpty(value)) { examCell.Standard.Judge(currentCell); } } } } } catch (Exception exception) { MsgBox.Show("資料設定錯誤:" + exception.Message); } ResetDisplayColumn(_displayColumns); }
public bool IsDirty() { foreach (DataGridViewRow row in _dgv.Rows) { foreach (DataGridViewCell cell in row.Cells) { IExamCell ic = cell.Tag as IExamCell; if (ic == null) { continue; } if (ic.IsDirty) { return(true); } } } return(false); }
public void ResetValue() { foreach (DataGridViewRow row in _dgv.Rows) { foreach (DataGridViewCell cell in row.Cells) { cell.Style.BackColor = Color.White; cell.Style.ForeColor = Color.Black; cell.ToolTipText = ""; IExamCell ic = cell.Tag as IExamCell; if (ic != null) { ic.Reset(); cell.Value = ic.GetValue(); ic.Standard.Judge(cell); } } } }
private void CellEdited(DataGridViewCell cell, IExamCell icell) { DataGridViewCellStyle style = cell.DataGridView.Rows[cell.RowIndex].Cells[0].Style; Color defaultBackColor = style.BackColor; Color defaultForeColor = style.ForeColor; cell.Style.BackColor = defaultBackColor; cell.Style.ForeColor = defaultForeColor; cell.ToolTipText = ""; string value = cell.Value == null ? "" : cell.Value.ToString().Trim(); cell.Value = value; if (icell != null) { icell.SetValue(value); if (icell.IsValid()) { icell.Standard.Judge(cell); if (icell.IsDirty) { cell.Style.BackColor = Color.Yellow; cell.ToolTipText = "此欄位值已變更,其原值為『" + icell.DefaultValue + "』"; } } else { cell.Style.BackColor = Color.Red; cell.Style.ForeColor = defaultForeColor; cell.ToolTipText = "錯誤!!此欄位必須為數字"; } } if (DirtyChanged != null) { DirtyChanged.Invoke(this, new DirtyChangedEventArgs(IsDirty())); } }
public override void Save() { // 產生新增成績 Request int insertStudentCount = 0; int updateStudentCount = 0; int deleteStudentCount = 0; int usCount = 0; DSXmlHelper insertHelper = new DSXmlHelper("Request"); DSXmlHelper updateHelper = new DSXmlHelper("Request"); DSXmlHelper deleteHelper = new DSXmlHelper("Request"); DSXmlHelper usHelper = new DSXmlHelper("Request"); insertHelper.AddElement("ScoreSheetList"); updateHelper.AddElement("ScoreSheetList"); deleteHelper.AddElement("ScoreSheet"); foreach (DataGridViewRow row in dataGridView1.Rows) { string attendid = row.Tag.ToString(); foreach (DataGridViewCell cell in row.Cells) { IExamCell ic = cell.Tag as IExamCell; if (ic == null) { continue; } ColumnSetting setting = dataGridView1.Columns[cell.ColumnIndex].Tag as ColumnSetting; string examid = setting.Key; if (ic is ScoreExamCell && ic.IsDirty) { usCount++; usHelper.AddElement("Attend"); usHelper.AddElement("Attend", "Score", ic.GetValue()); usHelper.AddElement("Attend", "ID", attendid); } else if (string.IsNullOrEmpty(ic.Key) && ic.IsDirty) { insertStudentCount++; insertHelper.AddElement("ScoreSheetList", "ScoreSheet"); insertHelper.AddElement("ScoreSheetList/ScoreSheet", "ExamID", examid); insertHelper.AddElement("ScoreSheetList/ScoreSheet", "AttendID", attendid); insertHelper.AddElement("ScoreSheetList/ScoreSheet", "Score", ic.GetValue()); } else if (!string.IsNullOrEmpty(ic.Key) && ic.IsDirty && !string.IsNullOrEmpty(ic.GetValue())) { updateStudentCount++; updateHelper.AddElement("ScoreSheetList", "ScoreSheet"); updateHelper.AddElement("ScoreSheetList/ScoreSheet", "Score", ic.GetValue()); updateHelper.AddElement("ScoreSheetList/ScoreSheet", "ID", ic.Key); } else if (!string.IsNullOrEmpty(ic.Key) && ic.IsDirty && string.IsNullOrEmpty(ic.GetValue())) { deleteStudentCount++; deleteHelper.AddElement("ScoreSheet", "ID", ic.Key); } } } if (insertStudentCount > 0) { EditCourse.InsertSCEScore(new DSRequest(insertHelper)); } if (updateStudentCount > 0) { EditCourse.UpdateSCEScore(new DSRequest(updateHelper)); } if (deleteStudentCount > 0) { EditCourse.DeleteSCEScore(new DSRequest(deleteHelper)); } if (usCount > 0) { EditCourse.UpdateAttend(usHelper); } SaveButtonVisible = false; LoadContent(RunningID); }