void dt_ColumnChanged(object sender, DataColumnChangeEventArgs e) { if (!ColumnTable.ContainsKey(e.Column)) { return; } if (!RowTable.ContainsKey(e.Row)) { return; } int?newValue = null; int nv = 0; if (int.TryParse(e.ProposedValue.ToString(), out nv)) { newValue = nv; } if (newValue.HasValue) { if (newValue > GameService.MaxValue(Stage, RowTable[e.Row]) || newValue < GameService.MinValue(Stage, RowTable[e.Row])) { newValue = null; } } if (!newValue.HasValue) { e.Row.SetColumnError(e.Column, "Неправильное значение"); } else { e.Row.SetColumnError(e.Column, ""); } var c = ColumnTable[e.Column]; var gameResult = GameService.DbContext.GameResultSet.First(f => f.Game.Stage.Id == Stage.Id && f.Referee.Id == c.Id && f.Game.Team.Id == CurrentTeam.Id); var value = gameResult.Values.FirstOrDefault(f => f.Type == RowTable[e.Row]); if (value == null) { GameService.DbContext.GameResultValueSet.Add(new GameResultValue() { GameResult = gameResult, Type = RowTable[e.Row], Value = newValue }); } else { value.Value = newValue; } }
public void FillData() { foreach (string kind in _rows.Keys) { foreach (string key in _rows[kind].Records.Keys) { if (!RowTable.ContainsKey(kind)) { continue; } if (!ColTable.ContainsKey(key)) { continue; } int rowIndex = RowTable[kind]; int colIndex = ColTable[key]; if (kind == "獎勵" || kind == "懲罰") { if (_rows[kind].Records[key].StudentCount > 0) { _worksheet.Cells[rowIndex, colIndex].PutValue(_rows[kind].Records[key].StudentCount); } } else { if (_rows[kind].Records[key].StudentCount > 0) { _worksheet.Cells[rowIndex, colIndex].PutValue(_rows[kind].Records[key].StudentCount); } if (_rows[kind].Records[key].Times > 0) { _worksheet.Cells[rowIndex + 1, colIndex].PutValue(_rows[kind].Records[key].Times); } } } } //填入學校代碼 _worksheet.Cells[4, 0].PutValue(SmartSchool.Customization.Data.SystemInformation.SchoolCode); //填入報表標題 _worksheet.Cells[2, 0].PutValue("高中高職學校學生獎懲人數—" + _name); //填入學年度學期 _worksheet.Cells[3, 2].PutValue("中華民國 " + _school_year + " 學年 第 " + _semester + " 學期"); }