// 新增一个内容行 // parameters: // nRowIndex 全部行的坐标 Row InsertContentLine(string strReaderType, ref int nRowIndex) { int nColIndex = 0; Row new_row = new Row(); this._rows.Insert(nRowIndex - 1, new_row); new_row.ReaderType = strReaderType; new_row.PatronPolicyCell = new PatronPolicyCell(); // row.PatronPolicyCell.TextChanged += new TextChangedEventHandler(PatronPolicyCell_TextChanged); new_row.PatronPolicyCell.CommentText = strReaderType; // 将全部日历名进行筛选,只给读者参数里面设置分馆的日历 List<string> temp = GetCarlendarNamesByLibraryCode(this._strCurrentLibraryCode, _calendarList); new_row.PatronPolicyCell.CalendarList = temp; // 0 Label label = new Label(); label.Content = strReaderType; label.HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch; label.HorizontalContentAlignment = System.Windows.HorizontalAlignment.Right; label.VerticalAlignment = System.Windows.VerticalAlignment.Stretch; label.VerticalContentAlignment = System.Windows.VerticalAlignment.Center; label.FontSize = 24; label.Foreground = new SolidColorBrush(Color.FromArgb(255, 255, 255, 255)); Grid.SetColumn(label, nColIndex++); Grid.SetRow(label, nRowIndex); this._grid.Children.Add(label); new_row.Label = label; new_row.Label.MouseDown += new MouseButtonEventHandler(Label_row_MouseDown); // 1 读者参数 Grid.SetColumn(new_row.PatronPolicyCell, nColIndex++); Grid.SetRow(new_row.PatronPolicyCell, nRowIndex); this._grid.Children.Add(new_row.PatronPolicyCell); // 其他栏 // 若干图书类型 foreach (string strBookType in this._bookTypes) { PolicyCell cell = new PolicyCell(); cell.CommentText = strReaderType + " - " + strBookType; // cell.TextChanged += new TextChangedEventHandler(cell_TextChanged); Grid.SetColumn(cell, nColIndex++); Grid.SetRow(cell, nRowIndex); this._grid.Children.Add(cell); new_row.Cells.Add(cell); } // 下面的行移动 for (int i = nRowIndex; i < this._rows.Count; i++) { Row row = this._rows[i]; Grid.SetRow(row.Label, i + 1); Grid.SetRow(row.PatronPolicyCell, i + 1); foreach (PolicyCell cell in row.Cells) { Grid.SetRow(cell, i + 1); } } nRowIndex++; if (this._inInitial == false) AddRowEvents(new_row, true); return new_row; }
// Return the row at the specified rowIndex located within // the sheet data passed in via wsData. If the row does not // exist, create it. private static Row GetRow(SheetData wsData, UInt32 rowIndex) { var row = wsData.Elements<Row>(). Where(r => r.RowIndex.Value == rowIndex).FirstOrDefault(); if (row == null) { row = new Row(); row.RowIndex = rowIndex; wsData.Append(row); } return row; }
void AddRowEvents(Row row, bool bAdd) { if (this._inInitial == true) return; // 初始化阶段暂时不要添加事件 if (bAdd == true) { // row.PatronPolicyCell.TextChanged += new TextChangedEventHandler(PatronPolicyCell_TextChanged); row.PatronPolicyCell.PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler(PatronPolicyCell_PropertyChanged); row.Label.MouseDown += new MouseButtonEventHandler(Label_row_MouseDown); } else { // row.PatronPolicyCell.TextChanged -= new TextChangedEventHandler(PatronPolicyCell_TextChanged); row.PatronPolicyCell.PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler(PatronPolicyCell_PropertyChanged); row.Label.MouseDown -= new MouseButtonEventHandler(Label_row_MouseDown); } foreach (PolicyCell cell in row.Cells) { if (bAdd == true) { cell.PropertyChanged += new PropertyChangedEventHandler(cell_PropertyChanged); //cell.TextChanged += new TextChangedEventHandler(cell_TextChanged); } else { cell.PropertyChanged -= new PropertyChangedEventHandler(cell_PropertyChanged); //cell.TextChanged -= new TextChangedEventHandler(cell_TextChanged); } } }
// Add a cell with the specified address to a row. private static DocumentFormat.OpenXml.Spreadsheet.Cell CreateCell(Row row, String address) { DocumentFormat.OpenXml.Spreadsheet.Cell cellResult; DocumentFormat.OpenXml.Spreadsheet.Cell refCell = null; // Cells must be in sequential order according to CellReference. // Determine where to insert the new cell. foreach (DocumentFormat.OpenXml.Spreadsheet.Cell cell in row.Elements<DocumentFormat.OpenXml.Spreadsheet.Cell>()) { if (string.Compare(cell.CellReference.Value, address, true) > 0) { refCell = cell; break; } } cellResult = new DocumentFormat.OpenXml.Spreadsheet.Cell(); cellResult.CellReference = address; row.InsertBefore(cellResult, refCell); return cellResult; }