namespace HStation.WinFrmUI
|
{
|
public partial class CreateXhsSchemeGeneralWizardPage : DevExpress.XtraEditors.XtraUserControl, IWizardPageAsync<CreateXhsSchemeViewModel>
|
{
|
public CreateXhsSchemeGeneralWizardPage()
|
{
|
InitializeComponent();
|
this.layoutControl1.SetupLayoutControl();
|
}
|
|
/// <summary>
|
/// 状态改变事件
|
/// </summary>
|
public event Action PageStateChangedEvent;
|
|
private CreateXhsSchemeViewModel _vm = null;//操作对象
|
private bool _isCompleted = false;//是否创建完成
|
private bool _createResult = false;//创建结果
|
|
|
//绘制视图
|
private class DrawItemViewModel
|
{
|
/// <summary>
|
/// 文本
|
/// </summary>
|
public string Text { get; set; }
|
|
/// <summary>
|
/// 颜色
|
/// </summary>
|
public Color Color { get; set; }
|
|
/// <summary>
|
///
|
/// </summary>
|
/// <returns></returns>
|
public override string ToString()
|
{
|
return string.Empty;
|
}
|
}
|
|
/// <summary>
|
/// 初始化页面
|
/// </summary>
|
public async void InitialPage(CreateXhsSchemeViewModel vm)
|
{
|
if (vm == null)
|
{
|
return;
|
}
|
_vm = vm;
|
_isCompleted = false;
|
_createResult = false;
|
this.listBoxControl1.Items.Clear();
|
_createResult = await CreateXhsSchemeHelper.Create(vm, (msg, color) =>
|
{
|
var drawItem = new DrawItemViewModel
|
{
|
Text = msg,
|
Color = color
|
};
|
this.listBoxControl1.Items.Add(drawItem);
|
}, (max, current) =>
|
{
|
this.progressBarControl1.Properties.Maximum = max;
|
this.progressBarControl1.Position = current;
|
//替代方案
|
// this.progressBarControl1.Properties.Step = current;
|
// this.progressBarControl1.PerformStep();
|
});
|
_isCompleted = true;
|
if (!_createResult)
|
{
|
this.progressBarControl1.Position = 0;
|
this.itemForProgress.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never;
|
}
|
this.PageStateChangedEvent?.Invoke();
|
}
|
|
/// <summary>
|
/// 允许上一步
|
/// </summary>
|
public bool AllowPrev
|
{
|
get
|
{
|
if (!_isCompleted)
|
{
|
return false;
|
}
|
if (!_createResult)
|
{
|
return true;
|
}
|
return false;
|
}
|
}
|
|
/// <summary>
|
/// 允许下一步
|
/// </summary>
|
public bool AllowNext
|
{
|
get
|
{
|
if (_createResult)
|
{
|
return true;
|
}
|
return false;
|
}
|
}
|
|
/// <summary>
|
/// 允许取消
|
/// </summary>
|
public bool AllowCancel
|
{
|
get
|
{
|
if (!_createResult)
|
{
|
return true;
|
}
|
return false;
|
}
|
}
|
|
/// <summary>
|
/// 允许完成
|
/// </summary>
|
public bool AllowComplete
|
{
|
get
|
{
|
return false;
|
}
|
}
|
|
/// <summary>
|
/// 能否上一步
|
/// </summary>
|
/// <returns></returns>
|
public Task<bool> CanPrev()
|
{
|
return Task.Run(() => this.AllowPrev);
|
}
|
|
/// <summary>
|
/// 能否下一步
|
/// </summary>
|
public Task<bool> CanNext()
|
{
|
return Task.Run(() => this.AllowNext);
|
}
|
|
/// <summary>
|
/// 能否取消
|
/// </summary>
|
public Task<bool> CanCancel()
|
{
|
return Task.Run(() => this.AllowCancel);
|
}
|
|
/// <summary>
|
/// 能否完成
|
/// </summary>
|
public Task<bool> CanComplete()
|
{
|
return Task.Run(() => this.AllowComplete);
|
}
|
|
//绘制项
|
private void listBoxControl1_DrawItem(object sender, DevExpress.XtraEditors.ListBoxDrawItemEventArgs e)
|
{
|
// 获取当前项目的索引
|
int index = e.Index;
|
|
// 检查是否是有效的项目索引
|
if (index >= 0)
|
{
|
// 获取当前项目
|
DrawItemViewModel item = (DrawItemViewModel)listBoxControl1.Items[index];
|
|
// 设置字体和颜色
|
Font font = new Font("Arial", 15);
|
Brush brush = new SolidBrush(item.Color);
|
// 绘制文本
|
e.Graphics.DrawString(item.Text, font, brush, e.Bounds);
|
}
|
}
|
|
|
}
|
}
|