Files
lserp_cs_6.0/插件库/Lskj.Control/FrmTreePicture.cs
2026-07-02 10:11:39 +00:00

113 lines
4.3 KiB
C#
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using DevExpress.XtraTreeList.Columns;
using Lskj.Business;
using Lskj.Control.Model;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace Lskj.Control
{
public partial class FrmTreePicture : BaseForm
{
// 1. 将 GridColumn 替换为 TreeListColumn
public List<TreeListColumn> PicUrlColumns;
public DataRow FocusedRow; // 保持不变(仍用于存储节点绑定的数据行)
public TreeListColumn FocusedColumn; // 聚焦列改为 TreeListColumn
public Image Picture
{
get
{
return pictureEdit.Image;
}
set
{
pictureEdit.Image = value;
}
}
public FrmTreePicture()
{
InitializeComponent();
pictureEdit.Properties.ShowMenu = false;
this.lbLeft.Click += OnBtnLeftClick;
this.lbRight.Click += OnBtnRightClick;
}
// 2. 右侧按钮点击事件(适配 TreeListColumn
private void OnBtnRightClick(object sender, EventArgs e)
{
int index = PicUrlColumns.IndexOf(FocusedColumn);
if (index >= 0 && index + 1 <= PicUrlColumns.Count - 1)
{
FocusedColumn = PicUrlColumns[index + 1];
if (FocusedColumn.Tag != null && FocusedColumn.Tag is GridColumnModel columnModel)
{
// 3. 读取图片URL(兼容 TreeList 节点绑定的 DataRow
string imageUrl = FocusedRow.Table.Columns.Contains(columnModel.FieldName)
? FocusedRow[columnModel.FieldName] + ""
: "";
if (string.IsNullOrEmpty(imageUrl))
return;
// 补全URL(保持原有逻辑)
if (!imageUrl.StartsWith("http"))
{
string oaUrl = SystemInfo.Instance.OAUrl.EndsWith("/")
? SystemInfo.Instance.OAUrl
: $"{SystemInfo.Instance.OAUrl}/";
imageUrl = $"{oaUrl}{imageUrl}";
}
// 从列模型缓存中获取图片(保持原有逻辑)
if (columnModel.LabPicUrlImages.ContainsKey(imageUrl))
{
Image image = ((KeyValuePair<Image, Image>)columnModel.LabPicUrlImages[imageUrl]).Key;
Picture = image;
}
}
}
}
// 3. 左侧按钮点击事件(适配 TreeListColumn
private void OnBtnLeftClick(object sender, EventArgs e)
{
int index = PicUrlColumns.IndexOf(FocusedColumn);
if (index >= 0 && index - 1 >= 0)
{
FocusedColumn = PicUrlColumns[index - 1];
if (FocusedColumn.Tag != null && FocusedColumn.Tag is GridColumnModel columnModel)
{
// 读取图片URL(同右侧逻辑,兼容 TreeList 数据行)
string imageUrl = FocusedRow.Table.Columns.Contains(columnModel.FieldName)
? FocusedRow[columnModel.FieldName] + ""
: "";
if (string.IsNullOrEmpty(imageUrl))
return;
// 补全URL(保持原有逻辑)
if (!imageUrl.StartsWith("http"))
{
string oaUrl = SystemInfo.Instance.OAUrl.EndsWith("/")
? SystemInfo.Instance.OAUrl
: $"{SystemInfo.Instance.OAUrl}/";
imageUrl = $"{oaUrl}{imageUrl}";
}
// 从列模型缓存中获取图片(保持原有逻辑)
if (columnModel.LabPicUrlImages.ContainsKey(imageUrl))
{
Image image = ((KeyValuePair<Image, Image>)columnModel.LabPicUrlImages[imageUrl]).Key;
Picture = image;
}
}
}
}
}
}