/// <summary> /// 开始拖拽 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> void OnItemStartDrag(object sender, EventArgs e) { CellRange dragRng = _owner.Excel.DecorationRange; if (dragRng == null) { _drgItem = null; return; } foreach (RptItem item in _owner.GetContainer().Items) { if (item.Row == dragRng.Row && item.Col == dragRng.Column && item.RowSpan == dragRng.RowCount && item.ColSpan == dragRng.ColumnCount) { _drgItem = item; break; } } if (_drgItem == null) { _owner.Excel.DecorationRange = null; } }
/// <summary> /// 触发报表项更新事件 /// </summary> /// <param name="p_item"></param> /// <param name="e"></param> public void OnUpdated(RptItem p_item, bool e) { if (Updated != null) { Updated(p_item, e); p_item.Data.AcceptChanges(); } }
public override void Undo(object p_args) { MoveRptItemArgs args = (MoveRptItemArgs)p_args; RptItem drgItem = args.RptItem; drgItem.Row = args.OldRow; drgItem.Col = args.OldCol; drgItem.Update(true); }
public override object Execute(object p_args) { MoveRptItemArgs args = (MoveRptItemArgs)p_args; RptItem drgItem = args.RptItem; CellEventArgs dstPos = args.DstPos; args.OldRow = drgItem.Row; args.OldCol = drgItem.Col; drgItem.Row = dstPos.Row; drgItem.Col = dstPos.Column; drgItem.Update(true); return(drgItem); }
/// <summary> /// 加载xml /// </summary> /// <param name="p_reader"></param> public virtual void ReadXml(XmlReader p_reader) { p_reader.MoveToElement(); if (p_reader.IsEmptyElement) { p_reader.Read(); return; } string name = p_reader.Name; p_reader.Read(); while (p_reader.NodeType != XmlNodeType.None) { if (p_reader.NodeType == XmlNodeType.EndElement && p_reader.Name == name) { break; } RptItem item = null; switch (p_reader.Name) { case "Text": item = new RptText(this); break; case "Table": item = new RptTable(this); break; case "Matrix": item = new RptMatrix(this); break; case "Chart": item = new RptChart(this); break; default: if (item == null) { Kit.Error(string.Format("反序列化报表模板时错误,无法识别报表项【{0}】!", p_reader.Name)); } break; } item.ReadXml(p_reader); Items.Add(item); } p_reader.Read(); }
void OnInsertMtx(object sender, Mi e) { _owner.Excel.DecorationRange = null; CellRange range = _owner.Excel.ActiveSheet.Selections[0]; var item = new RptMatrix(_owner.GetContainer()); range = new CellRange(range.Row, range.Column, 2, 2); if (RptItem.ValidEmptyRange(item.Part, range)) { Kit.Error("对象创建后与其他对象位置冲突,请确认。"); return; } _owner.Excel.ActiveSheet.SetSelection(range); _owner.Info.ExecuteCmd(RptCmds.InsertMatrix, new InsertCmdArgs(item, range)); _owner.UpdateSelection(); }
public override object Execute(object p_args) { CopyItemCmdArgs args = (CopyItemCmdArgs)p_args; RptItem item = args.Item as RptItem; CellRange range = args.Range; item.Row = range.Row; item.Col = range.Column; if (item is RptText || item is RptChart) { item.RowSpan = range.RowCount; item.ColSpan = range.ColumnCount; } item.Part.Items.Add(item); return(item); }
/// <summary> /// 加载报表项 /// </summary> /// <param name="p_item"></param> public void LoadItem(RptItem p_item) { if (p_item is RptText txt) { LoadText(txt); } else if (p_item is RptTable tbl) { LoadTable(tbl); } else if (p_item is RptMatrix mtx) { LoadMatrix(mtx); } else if (p_item is RptChart ct) { LoadChart(ct); } }
/// <summary> /// 拖放结束 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> void OnItemDropped(object sender, CellEventArgs e) { if (_drgItem == null) { _owner.Excel.DecorationRange = null; return; } if (_drgItem.TestMovIntersect(e.Row, e.Column)) { Kit.Warn("此对象移动后的位置后会与其他对象重叠,请先移动可能重叠的对象后重试。"); _drgItem = null; return; } MoveRptItemArgs moveAgs = new MoveRptItemArgs(_drgItem, e); _owner.Info.ExecuteCmd(RptCmds.MoveRptItemCmd, moveAgs); _drgItem = null; }
/// <summary> /// 报表项更新事件 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> void OnUpdated(object sender, bool e) { Invoke(() => { RptItem item = (RptItem)sender; Worksheet ws = _owner.Excel.Sheets[(int)item.Part.PartType]; if (e) { // 按原始位置清除 var row = item.Data; CellRange range = new CellRange( row.GetOriginalVal <int>("row"), row.GetOriginalVal <int>("col"), row.GetOriginalVal <int>("rowspan"), row.GetOriginalVal <int>("colspan")); ClearRange(ws, range); } LoadItem(item); // 焦点切换到末单元格,重置选择框 ws.SetActiveCell(ws.RowCount - 1, ws.ColumnCount - 1, true); _owner.Excel.DecorationRange = new CellRange(item.Row, item.Col, item.RowSpan, item.ColSpan); }); }
/// <summary> /// 删除报表项后,若为正在编辑的对象,卸载属性Form /// </summary> /// <param name="p_item"></param> internal void AfterDelItem(RptItem p_item) { if ((_tabItem.Content == null && _tabCell.Content == null) || p_item == null || _curItem == null) { return; } if (p_item == _curItem) { ClearForms(); } else { CellRange oldItemRange = new CellRange(_curItem.Row, _curItem.Col, _curItem.RowSpan, _curItem.ColSpan); CellRange delItemRange = new CellRange(p_item.Row, p_item.Col, p_item.RowSpan, p_item.ColSpan); if (delItemRange.Contains(oldItemRange)) { ClearForms(); } } }
public override void Undo(object p_args) { RptItem rptItem = ((CopyItemCmdArgs)p_args).Item; rptItem.Part.Items.Remove(rptItem); }
public DelRptItemArgs(RptItem p_rptItem) { RptItem = p_rptItem; }
public InsertCmdArgs(RptItem p_rptItem, CellRange p_range) { RptItem = p_rptItem; CellRange = p_range; }
internal void ClearForms() { _curItem = null; _tabItem.Content = null; _tabCell.Content = null; }
internal void LoadForms(RptItem p_item, CellRange p_range) { if (p_item == null || p_range == null) { return; } _curItem = p_item; if (p_item is RptText txt) { LoadCellForm(txt); _tabItem.Content = null; _tabCell.IsSelected = true; return; } if (p_item is RptTable tbl) { txt = tbl.GetText(p_range.Row, p_range.Column); LoadCellForm(txt); if (_fmTbl == null) { _fmTbl = new TableForm(Info); } TblRangeType tblRng = tbl.GetRangeType(p_range.Row, p_range.Column); _fmTbl.LoadItem(txt, tblRng == TblRangeType.Group); _tabItem.Content = _fmTbl; return; } if (p_item is RptMatrix mtx) { txt = mtx.GetText(p_range.Row, p_range.Column); LoadCellForm(txt); MtxRangeType mtxRng = mtx.GetRangeType(p_range.Row, p_range.Column); switch (mtxRng) { case MtxRangeType.Level: if (_fmMtxLevel == null) { _fmMtxLevel = new MatrixLevelForm(Info); } _fmMtxLevel.LoadItem(txt); _tabItem.Content = _fmMtxLevel; break; case MtxRangeType.Subtotal: if (_fmMtxSubtotal == null) { _fmMtxSubtotal = new MatrixSubtotalForm(Info); } _fmMtxSubtotal.LoadItem(txt); _tabItem.Content = _fmMtxSubtotal; break; case MtxRangeType.Subtitle: if (_fmMtxSubtitle == null) { _fmMtxSubtitle = new MatrixSubtitleForm(Info); } _fmMtxSubtitle.LoadItem(txt); _tabItem.Content = _fmMtxSubtitle; break; default: if (_fmMatrix == null) { _fmMatrix = new MatrixForm { Info = Info } } ; _fmMatrix.LoadItem(mtx); _tabItem.Content = _fmMatrix; break; } return; } if (p_item is RptChart chart) { if (_fmChart == null) { _fmChart = new ChartForm(Info); } _fmChart.LoadItem(chart); _tabItem.Content = _fmChart; _tabCell.Content = null; _tabItem.IsSelected = true; } }
public MoveRptItemArgs(RptItem p_rptItem, CellEventArgs p_dstPos) { RptItem = p_rptItem; DstPos = p_dstPos; }
/// <summary> /// 清除RptItem所占区域的内容及样式 /// </summary> /// <param name="p_item"></param> void ClearItem(RptItem p_item) { CellRange range = GetRptItemRange(p_item); ClearRange(_owner.Excel.Sheets[(int)p_item.Part.PartType], range); }
internal async Task <bool> Show(FrameworkElement p_target, RptText p_item) { _item = p_item; if (_dataSets.Items != null && _dataSets.Items.Count > 0) { _dataSets.Items.Clear(); } Table dataSet = p_item.Root.Data.DataSet; if (dataSet.Count > 0) { foreach (var r in dataSet) { var temp = new ComboBoxItem(); temp.Content = r.Str("name"); _dataSets.Items.Add(temp); } if (_dataSets.Items.Count == 1) { // 只一项时默认选中,并触发selectionChanged事件,加载其字段集填充显示字段Lv _dataSets.SelectedIndex = 0; } else { // 默认选中单元格所在对象的数据集 RptItem topItem = null; foreach (RptItem item in p_item.Part.Items) { if (item.Row <= p_item.Row && item.Row + item.RowSpan - 1 >= p_item.Row && item.Col <= p_item.Col && item.Col + item.ColSpan - 1 >= p_item.Col) { topItem = item; break; } } string itemDataName; if (topItem != null && topItem.Data != null && topItem.Data.Contains("tbl") && (itemDataName = topItem.Data.Str("tbl")) != "") { for (int i = 0; i < _dataSets.Items.Count; i++) { if ((_dataSets.Items[i] as ComboBoxItem).Content as string == itemDataName) { _dataSets.SelectedIndex = i; break; } } } if (_dataSets.SelectedIndex == -1) { _dataSets.SelectedIndex = 0; } } } if (!Kit.IsPhoneUI) { WinPlacement = DlgPlacement.TargetBottomLeft; PlacementTarget = p_target; ClipElement = p_target; Height = 400; Width = 300; } return(await ShowAsync()); }
public CopyItemCmdArgs(RptItem p_item, CellRange p_range) { Item = p_item; Range = p_range; }
/// <summary> /// 得到RptItem所占用的矩形区域 /// </summary> /// <param name="p_item"></param> /// <returns></returns> Dt.Cells.Data.CellRange GetRptItemRange(RptItem p_item) { return(new CellRange(p_item.Row, p_item.Col, p_item.RowSpan, p_item.ColSpan)); }
/// <summary> /// 更新选择区域 /// </summary> public void UpdateSelection() { CellRange range; Excel excel = _owner.Excel; Worksheet sheet = excel.ActiveSheet; RptItem curItem = null; RptPart container = _owner.GetContainer(); excel.DecorationRange = null; // 无选择及选择整行整列 : 返回。无选择可能是选中浮动对象造成的,现不在此处处理。 if (sheet.Selections.Count == 0 || (range = sheet.Selections[0]).Row == -1 || range.Column == -1) { _owner.ClearForms(); return; } // 三种情况,在已有对象内部、相交、空白区域 foreach (RptItem item in container.Items) { // 选择区域在报表项内 if (item.Contains(range)) { curItem = item; break; } // 相交,无操作,返回 if (range.Intersects(item.Row, item.Col, item.RowSpan, item.ColSpan)) { _owner.ClearForms(); return; } } if (curItem == null) { // 在空白区域 if (container.PartType == RptPartType.Body) { if (_menuBlank == null) { _menuBlank = new BlankAreaMenu(_owner); } ShowMenu(_menuBlank, range); } else { // 页眉页脚菜单 if (_menuHeader == null) { _menuHeader = new HeaderFooterMenu(_owner); } ShowMenu(_menuHeader, range); } _owner.ClearForms(); } else { // 在对象内部 excel.DecorationRange = new CellRange(curItem.Row, curItem.Col, curItem.RowSpan, curItem.ColSpan); _owner.LoadForms(curItem, range); } }
/// <summary> /// 判定某区域是否有控件 或 是否有指定对象之外的控件 /// </summary> /// <param name="p_part"></param> /// <param name="p_range"></param> /// <param name="p_item"></param> /// <returns></returns> public static bool ValidEmptyRange(RptPart p_part, Dt.Cells.Data.CellRange p_range, RptItem p_item = null) { if (p_part == null || p_range == null) { return(false); } if (p_item == null) { return((from item in (IEnumerable <RptItem>)p_part.Items where p_range.Intersects(item.Row, item.Col, item.RowSpan, item.ColSpan) select item).Any()); } else { return((from item in (IEnumerable <RptItem>)p_part.Items where p_item != item && p_range.Intersects(item.Row, item.Col, item.RowSpan, item.ColSpan) select item).Any()); } }