|
|
|
|
using KGIS.Framework.Utils;
|
|
|
|
|
using KGIS.Framework.Utils.Helper;
|
|
|
|
|
using Kingo.PluginServiceInterface.Model;
|
|
|
|
|
using KUI.Windows;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Diagnostics;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading;
|
|
|
|
|
using System.Windows;
|
|
|
|
|
using System.Windows.Controls;
|
|
|
|
|
using System.Windows.Data;
|
|
|
|
|
using System.Windows.Input;
|
|
|
|
|
|
|
|
|
|
namespace Kingo.PluginServiceInterface.WizardFramework
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// WizardWindow.xaml 的交互逻辑
|
|
|
|
|
/// </summary>
|
|
|
|
|
public partial class WizardWindow : BaseWindow
|
|
|
|
|
{
|
|
|
|
|
#region 字段
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 状态标志位
|
|
|
|
|
/// </summary>
|
|
|
|
|
public enum WizardState
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 未初始化
|
|
|
|
|
/// </summary>
|
|
|
|
|
Uninitialized,
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 启动状态
|
|
|
|
|
/// </summary>
|
|
|
|
|
Start,
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 中间状态
|
|
|
|
|
/// </summary>
|
|
|
|
|
Middle,
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 结束状态
|
|
|
|
|
/// </summary>
|
|
|
|
|
End,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 向导模式
|
|
|
|
|
/// </summary>
|
|
|
|
|
public enum WizardModel
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 分步执行模式
|
|
|
|
|
/// </summary>
|
|
|
|
|
SimpleModel,
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 分步设置一键执行模式
|
|
|
|
|
/// </summary>
|
|
|
|
|
StepSettingModel,
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 一键执行模式
|
|
|
|
|
/// </summary>
|
|
|
|
|
OneKeyModel,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 记录当前步骤
|
|
|
|
|
/// </summary>
|
|
|
|
|
private int m_currentSetp;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 记录向导状态
|
|
|
|
|
/// </summary>
|
|
|
|
|
private WizardState m_state;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 记录向导模式
|
|
|
|
|
/// </summary>
|
|
|
|
|
private WizardModel m_model;
|
|
|
|
|
private ListCollectionView m_view;
|
|
|
|
|
List<IWizardFramework> m_WizardSteps = new List<IWizardFramework>();
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region 属性
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 向导状态
|
|
|
|
|
/// </summary>
|
|
|
|
|
public WizardState State
|
|
|
|
|
{
|
|
|
|
|
get { return m_state; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 向导模式
|
|
|
|
|
/// </summary>
|
|
|
|
|
public WizardModel Model
|
|
|
|
|
{
|
|
|
|
|
get { return m_model; }
|
|
|
|
|
set { m_model = value; }
|
|
|
|
|
}
|
|
|
|
|
#region
|
|
|
|
|
private string m_prefilishBtnName = "完成";
|
|
|
|
|
private bool m_isSucessFinsh = false;//在新一轮里是否成功的执行完成
|
|
|
|
|
private string m_finishBtnName = "完成";
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 根据需要改变完成按钮,执行完了名字变回“完成”
|
|
|
|
|
/// </summary>
|
|
|
|
|
public string FinishBtnName
|
|
|
|
|
{
|
|
|
|
|
get { return m_finishBtnName; }
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
m_prefilishBtnName = m_finishBtnName;
|
|
|
|
|
m_finishBtnName = value;
|
|
|
|
|
this.btnFinish.Content = m_finishBtnName;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 构造函数
|
|
|
|
|
/// </summary>
|
|
|
|
|
public WizardWindow()
|
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
m_currentSetp = -1;
|
|
|
|
|
m_state = WizardState.Uninitialized;
|
|
|
|
|
PluginArea.Children.Clear();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void Window_Loaded(object sender, RoutedEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
//ThemeManager.SetThemeName(this, "Office2013LightGray");
|
|
|
|
|
++m_currentSetp;
|
|
|
|
|
SetWizardMode();
|
|
|
|
|
SetState();
|
|
|
|
|
ButtonState();
|
|
|
|
|
lstSetpCaption.DataContext = m_WizardSteps;
|
|
|
|
|
m_view = (ListCollectionView)CollectionViewSource.GetDefaultView(lstSetpCaption.DataContext);
|
|
|
|
|
m_view.CurrentChanged += new EventHandler(view_CurrentChanged);
|
|
|
|
|
MoveNext(m_currentSetp);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void view_CurrentChanged(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
lstSetpCaption.SelectedIndex = m_view.CurrentPosition;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 添加向导步骤
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="pWF"></param>
|
|
|
|
|
public void AddStepControl(IWizardFramework pWF)
|
|
|
|
|
{
|
|
|
|
|
m_WizardSteps.Add(pWF);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
///向导模式
|
|
|
|
|
/// </summary>
|
|
|
|
|
private void SetWizardMode()
|
|
|
|
|
{
|
|
|
|
|
switch (this.m_model)
|
|
|
|
|
{
|
|
|
|
|
case WizardModel.SimpleModel:
|
|
|
|
|
this.btnExecute.Visibility = Visibility.Collapsed;
|
|
|
|
|
break;
|
|
|
|
|
case WizardModel.StepSettingModel:
|
|
|
|
|
this.btnExecute.Visibility = Visibility.Collapsed;
|
|
|
|
|
break;
|
|
|
|
|
case WizardModel.OneKeyModel:
|
|
|
|
|
this.btnMovePrevious.Visibility = Visibility.Hidden;
|
|
|
|
|
this.btnMoveNext.Visibility = Visibility.Hidden;
|
|
|
|
|
this.btnFinish.Visibility = Visibility.Hidden;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 判断PlugList列表是否为空
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
private bool IsValidate()
|
|
|
|
|
{
|
|
|
|
|
if (m_WizardSteps.Count != 0)
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#region 按钮方法
|
|
|
|
|
|
|
|
|
|
#region 添加
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 上一步
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
private void MoveToFirstView()
|
|
|
|
|
{
|
|
|
|
|
if (m_currentSetp == 0)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
--m_currentSetp;
|
|
|
|
|
SetState();
|
|
|
|
|
ButtonState();
|
|
|
|
|
if (m_currentSetp > -1 && m_currentSetp <= m_WizardSteps.Count - 1)
|
|
|
|
|
{
|
|
|
|
|
this.PluginArea.Children.Clear();
|
|
|
|
|
this.FinishBtnName = m_prefilishBtnName;
|
|
|
|
|
m_WizardSteps[m_currentSetp].Intializing();
|
|
|
|
|
this.PluginArea.Children.Add((UIElement)m_WizardSteps[0]);
|
|
|
|
|
this.lblWizardCaption.Content = m_WizardSteps[0].Caption;
|
|
|
|
|
this.txtDescription.Text = m_WizardSteps[0].Description;
|
|
|
|
|
m_currentSetp = 0;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 上一步
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
private void MovePrevious()
|
|
|
|
|
{
|
|
|
|
|
if (m_currentSetp == 0)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
--m_currentSetp;
|
|
|
|
|
SetState();
|
|
|
|
|
ButtonState();
|
|
|
|
|
//************************************************//
|
|
|
|
|
//this.MoveNext(m_currentSetp);
|
|
|
|
|
if (m_currentSetp > -1 && m_currentSetp <= m_WizardSteps.Count - 1)
|
|
|
|
|
{
|
|
|
|
|
this.PluginArea.Children.Clear();
|
|
|
|
|
//m_WizardSteps[m_currentSetp].Intializing();
|
|
|
|
|
this.PluginArea.Children.Add((UIElement)m_WizardSteps[m_currentSetp]);
|
|
|
|
|
this.lblWizardCaption.Content = m_WizardSteps[m_currentSetp].Caption;
|
|
|
|
|
this.txtDescription.Text = m_WizardSteps[m_currentSetp].Description;
|
|
|
|
|
//**************修改**********************************//
|
|
|
|
|
if (this.m_isSucessFinsh)//点击执行成功后放回,则进入下一轮执行期
|
|
|
|
|
{
|
|
|
|
|
this.FinishBtnName = m_prefilishBtnName;
|
|
|
|
|
this.m_isSucessFinsh = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
//************************************************//
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 下一步
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
private void MoveNext(int currentStep)
|
|
|
|
|
{
|
|
|
|
|
if (m_currentSetp > -1 && m_currentSetp <= m_WizardSteps.Count - 1)
|
|
|
|
|
{
|
|
|
|
|
this.PluginArea.Children.Clear();
|
|
|
|
|
m_WizardSteps[m_currentSetp].Intializing();
|
|
|
|
|
this.PluginArea.Children.Add((UIElement)m_WizardSteps[m_currentSetp]);
|
|
|
|
|
this.lblWizardCaption.Content = m_WizardSteps[m_currentSetp].Caption;
|
|
|
|
|
this.txtDescription.Text = m_WizardSteps[m_currentSetp].Description;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 取消
|
|
|
|
|
/// </summary>
|
|
|
|
|
private void Cancel()
|
|
|
|
|
{
|
|
|
|
|
System.Windows.Forms.DialogResult result = MessageHelper.ShowYesNoAndTips("是否要确实退出该向导操作?");
|
|
|
|
|
bool dResult = (result == System.Windows.Forms.DialogResult.Yes);
|
|
|
|
|
if (dResult)
|
|
|
|
|
{
|
|
|
|
|
PluginArea.Children.Clear();
|
|
|
|
|
Close();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 完成
|
|
|
|
|
/// </summary>
|
|
|
|
|
private bool Finish()
|
|
|
|
|
{
|
|
|
|
|
m_isSucessFinsh = false;
|
|
|
|
|
if (!IsValidate()) return false;
|
|
|
|
|
if (m_WizardSteps[m_currentSetp].Validating())
|
|
|
|
|
{
|
|
|
|
|
//this.Cursor = Cursors.Wait;
|
|
|
|
|
this.btnMovePrevious.IsEnabled = false;
|
|
|
|
|
this.btnFinish.IsEnabled = false;
|
|
|
|
|
this.btnExecute.IsEnabled = false;
|
|
|
|
|
if (m_WizardSteps[m_currentSetp] is IWizardFrameworkExeState)
|
|
|
|
|
{
|
|
|
|
|
(m_WizardSteps[m_currentSetp] as IWizardFrameworkExeState).ExeStateCallBacK = (p) =>
|
|
|
|
|
{
|
|
|
|
|
if (p is ExeState)
|
|
|
|
|
{
|
|
|
|
|
switch (p)
|
|
|
|
|
{
|
|
|
|
|
case ExeState.Start:
|
|
|
|
|
this.btnMovePrevious.IsEnabled = false;
|
|
|
|
|
this.btnFinish.IsEnabled = false;
|
|
|
|
|
this.btnExecute.IsEnabled = false;
|
|
|
|
|
this.btnSkip.IsEnabled = false;
|
|
|
|
|
this.btnMoveNext.IsEnabled = false;
|
|
|
|
|
this.btnCancel.IsEnabled = false;
|
|
|
|
|
break;
|
|
|
|
|
case ExeState.Fail:
|
|
|
|
|
this.btnMovePrevious.IsEnabled = true;
|
|
|
|
|
this.btnFinish.IsEnabled = true;
|
|
|
|
|
this.btnExecute.IsEnabled = true;
|
|
|
|
|
break;
|
|
|
|
|
case ExeState.Success:
|
|
|
|
|
this.btnMovePrevious.IsEnabled = true;
|
|
|
|
|
this.btnFinish.IsEnabled = true;
|
|
|
|
|
this.btnExecute.IsEnabled = true;
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
if (m_WizardSteps[m_currentSetp].Execute())
|
|
|
|
|
{
|
|
|
|
|
//this.btnMovePrevious.IsEnabled = true;
|
|
|
|
|
//this.btnFinish.IsEnabled = true;
|
|
|
|
|
//this.btnExecute.IsEnabled = true;
|
|
|
|
|
if (m_WizardSteps[m_currentSetp].IsFinalSuccess)
|
|
|
|
|
{
|
|
|
|
|
//MessageBoxResult result = MessageBox.Show("向导运行成功,是否关闭该向导", "提示", MessageBoxButton.YesNo, MessageBoxImage.Question);
|
|
|
|
|
//bool dResult = (result == MessageBoxResult.Yes);
|
|
|
|
|
//if (dResult)
|
|
|
|
|
//{
|
|
|
|
|
// PluginArea.Children.Clear();
|
|
|
|
|
// Close();
|
|
|
|
|
//}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
//MessageBoxResult result = MessageBox.Show("向导运行失败,是否继续该向导", "提示", MessageBoxButton.YesNo, MessageBoxImage.Question);
|
|
|
|
|
//bool dResult = (result == MessageBoxResult.Yes);
|
|
|
|
|
System.Windows.Forms.DialogResult result = MessageHelper.ShowYesNoAndError("向导运行失败,是否继续该向导?");
|
|
|
|
|
bool dResult = (result == System.Windows.Forms.DialogResult.Yes);
|
|
|
|
|
if (!dResult)
|
|
|
|
|
{
|
|
|
|
|
PluginArea.Children.Clear();
|
|
|
|
|
Close();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
//else
|
|
|
|
|
//{
|
|
|
|
|
// MessageBox.Show("信息不能为空,请选择!", "提示");
|
|
|
|
|
//}
|
|
|
|
|
//this.Cursor = Cursors.Arrow;
|
|
|
|
|
}
|
|
|
|
|
private bool FinishAll()
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
#region 验证最后一步是否可执行
|
|
|
|
|
var Lastitem = m_WizardSteps.FindLast(x => x.Validating());
|
|
|
|
|
//if (!Lastitem.IsFinalSuccess)
|
|
|
|
|
// return false;
|
|
|
|
|
TextBox txtlog = Lastitem.Parameter as TextBox;
|
|
|
|
|
Lastitem.Parameter = null;
|
|
|
|
|
#endregion
|
|
|
|
|
m_isSucessFinsh = false;
|
|
|
|
|
if (!IsValidate()) return false;
|
|
|
|
|
this.btnMovePrevious.IsEnabled = false;
|
|
|
|
|
this.btnFinish.IsEnabled = false;
|
|
|
|
|
this.btnExecute.IsEnabled = false;
|
|
|
|
|
IDGParameter iDGParameter = null;
|
|
|
|
|
bool isExeGPForProces = false;
|
|
|
|
|
//this.ShowLoading("正在执行请稍候...", 0, 0);
|
|
|
|
|
foreach (var item in m_WizardSteps)
|
|
|
|
|
{
|
|
|
|
|
if (item.IsSkip) continue;
|
|
|
|
|
if (item.Parameter != null)
|
|
|
|
|
{
|
|
|
|
|
if (iDGParameter == null)
|
|
|
|
|
{
|
|
|
|
|
iDGParameter = new IDGParameter();
|
|
|
|
|
iDGParameter.StrProjInfo = (item.Parameter as IDGParameter).StrProjInfo;
|
|
|
|
|
}
|
|
|
|
|
if ((item.Parameter as IDGParameter).ExeDLTB)
|
|
|
|
|
{
|
|
|
|
|
iDGParameter.ExeDLTB = true;
|
|
|
|
|
}
|
|
|
|
|
if ((item.Parameter as IDGParameter).ExeCJDCQ || (item.Parameter as IDGParameter).ExeXZQ || (item.Parameter as IDGParameter).ExeGDDB)
|
|
|
|
|
{
|
|
|
|
|
iDGParameter.ExeCJDCQ = (item.Parameter as IDGParameter).ExeCJDCQ == true;
|
|
|
|
|
iDGParameter.ExeXZQ = (item.Parameter as IDGParameter).ExeXZQ == true;
|
|
|
|
|
iDGParameter.ExeGDDB = (item.Parameter as IDGParameter).ExeGDDB == true;
|
|
|
|
|
}
|
|
|
|
|
if ((item.Parameter as IDGParameter).ExeCZC)
|
|
|
|
|
{
|
|
|
|
|
iDGParameter.ExeCZC = (item.Parameter as IDGParameter).ExeCZC == true;
|
|
|
|
|
}
|
|
|
|
|
if ((item.Parameter as IDGParameter).ExeZLHZ)
|
|
|
|
|
{
|
|
|
|
|
iDGParameter.ExeZLHZ = (item.Parameter as IDGParameter).ExeZLHZ == true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (iDGParameter != null && isExeGPForProces == false)
|
|
|
|
|
{
|
|
|
|
|
string result = ProcesHelper.Instance.ExeGPForProces(iDGParameter, txtlog);
|
|
|
|
|
if (result.Contains("Err"))
|
|
|
|
|
{
|
|
|
|
|
MessageHelper.ShowTips($"执行失败!:{result}");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
isExeGPForProces = true;
|
|
|
|
|
}
|
|
|
|
|
if (item.Execute())
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
LogAPI.Debug("执行失败");
|
|
|
|
|
MessageHelper.ShowTips("执行失败!");
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//Thread.Sleep(2000);
|
|
|
|
|
}
|
|
|
|
|
//this.CloseLoading();
|
|
|
|
|
MessageHelper.ShowTips("执行完成!");
|
|
|
|
|
this.btnMovePrevious.IsEnabled = true;
|
|
|
|
|
this.btnFinish.IsEnabled = true;
|
|
|
|
|
this.btnExecute.IsEnabled = true;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
//this.CloseLoading();
|
|
|
|
|
LogAPI.Debug("执行失败");
|
|
|
|
|
MessageHelper.ShowError(ex.Message);
|
|
|
|
|
}
|
|
|
|
|
finally
|
|
|
|
|
{
|
|
|
|
|
//this.CloseLoading();
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region 向导状态
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 设置当前向导状态
|
|
|
|
|
/// </summary>
|
|
|
|
|
protected void SetState()
|
|
|
|
|
{
|
|
|
|
|
if (m_WizardSteps.Count == 0)
|
|
|
|
|
{
|
|
|
|
|
m_state = WizardState.Uninitialized;
|
|
|
|
|
}
|
|
|
|
|
else if (m_WizardSteps.Count - 1 == m_currentSetp)
|
|
|
|
|
{
|
|
|
|
|
m_state = WizardState.End;
|
|
|
|
|
}
|
|
|
|
|
else if (m_currentSetp == 0)
|
|
|
|
|
{
|
|
|
|
|
m_state = WizardState.Start;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
m_state = WizardState.Middle;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 设置Button状态
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="btn"></param>
|
|
|
|
|
/// <param name="isEnabled"></param>
|
|
|
|
|
protected void SetButtonState(Button btn, bool isEnabled)
|
|
|
|
|
{
|
|
|
|
|
if (btn != null)
|
|
|
|
|
{
|
|
|
|
|
btn.IsEnabled = isEnabled;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 监听当前向导状态
|
|
|
|
|
/// </summary>
|
|
|
|
|
protected void ButtonState()
|
|
|
|
|
{
|
|
|
|
|
switch (this.State)
|
|
|
|
|
{
|
|
|
|
|
case WizardState.Uninitialized:
|
|
|
|
|
SetButtonState(this.btnMovePrevious, false);
|
|
|
|
|
SetButtonState(this.btnMoveNext, false);
|
|
|
|
|
SetButtonState(this.btnFinish, false);
|
|
|
|
|
SetButtonState(this.btnSkip, false);
|
|
|
|
|
SetButtonState(this.btnCancel, true);
|
|
|
|
|
break;
|
|
|
|
|
case WizardState.Start:
|
|
|
|
|
SetButtonState(this.btnMovePrevious, false);
|
|
|
|
|
SetButtonState(this.btnMoveNext, true);
|
|
|
|
|
SetButtonState(this.btnFinish, false);
|
|
|
|
|
SetButtonState(this.btnSkip, true);
|
|
|
|
|
SetButtonState(this.btnCancel, true);
|
|
|
|
|
break;
|
|
|
|
|
case WizardState.Middle:
|
|
|
|
|
SetButtonState(this.btnMovePrevious, true);
|
|
|
|
|
SetButtonState(this.btnMoveNext, true);
|
|
|
|
|
SetButtonState(this.btnSkip, true);
|
|
|
|
|
SetButtonState(this.btnFinish, false);
|
|
|
|
|
SetButtonState(this.btnCancel, true);
|
|
|
|
|
break;
|
|
|
|
|
case WizardState.End:
|
|
|
|
|
SetButtonState(this.btnMovePrevious, true);
|
|
|
|
|
SetButtonState(this.btnMoveNext, false);
|
|
|
|
|
SetButtonState(this.btnSkip, false);
|
|
|
|
|
SetButtonState(this.btnFinish, true);
|
|
|
|
|
SetButtonState(this.btnCancel, true);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
private void btnMoveNext_Click(object sender, RoutedEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (!IsValidate()) return;
|
|
|
|
|
if (m_WizardSteps[m_currentSetp].Validating())
|
|
|
|
|
{
|
|
|
|
|
this.Cursor = Cursors.Wait;
|
|
|
|
|
if (this.Model == WizardModel.SimpleModel)
|
|
|
|
|
{
|
|
|
|
|
if (m_WizardSteps[m_currentSetp].Execute())
|
|
|
|
|
{
|
|
|
|
|
++m_currentSetp;
|
|
|
|
|
SetState();
|
|
|
|
|
ButtonState();
|
|
|
|
|
this.MoveNext(m_currentSetp);
|
|
|
|
|
m_view.MoveCurrentToNext();//ListBoxItem向下移动一次
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (this.Model == WizardModel.StepSettingModel)
|
|
|
|
|
{
|
|
|
|
|
++m_currentSetp;
|
|
|
|
|
SetState();
|
|
|
|
|
ButtonState();
|
|
|
|
|
this.MoveNext(m_currentSetp);
|
|
|
|
|
m_view.MoveCurrentToNext();//ListBoxItem向下移动一次
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//else
|
|
|
|
|
//{
|
|
|
|
|
// MessageBox.Show("信息不能为空,请选择!", "提示");
|
|
|
|
|
//}
|
|
|
|
|
this.Cursor = Cursors.Arrow;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void btnMovePrevious_Click(object sender, RoutedEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
//************************************************//
|
|
|
|
|
m_WizardSteps[m_currentSetp].Back();
|
|
|
|
|
//************************************************//
|
|
|
|
|
MovePrevious();
|
|
|
|
|
m_view.MoveCurrentToPrevious();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void btnCancel_Click(object sender, RoutedEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
Cancel();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void btnFinish_Click(object sender, RoutedEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (m_isSucessFinsh)
|
|
|
|
|
{
|
|
|
|
|
Close();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
this.Cursor = Cursors.Wait;
|
|
|
|
|
switch (this.Model)
|
|
|
|
|
{
|
|
|
|
|
case WizardModel.SimpleModel:
|
|
|
|
|
if (Finish())
|
|
|
|
|
{
|
|
|
|
|
this.FinishBtnName = "完成";
|
|
|
|
|
m_isSucessFinsh = true;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case WizardModel.StepSettingModel:
|
|
|
|
|
if (Finish())//FinishAll
|
|
|
|
|
{
|
|
|
|
|
this.FinishBtnName = "完成";
|
|
|
|
|
m_isSucessFinsh = true;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case WizardModel.OneKeyModel:
|
|
|
|
|
if (Finish())
|
|
|
|
|
{
|
|
|
|
|
this.FinishBtnName = "完成";
|
|
|
|
|
m_isSucessFinsh = true;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
this.Cursor = Cursors.Arrow;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void ListBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (Model == WizardModel.OneKeyModel)
|
|
|
|
|
{
|
|
|
|
|
PluginArea.Children.Clear();
|
|
|
|
|
int index = ((ListBox)sender).SelectedIndex;
|
|
|
|
|
this.lblWizardCaption.Content = m_WizardSteps[index].Caption;
|
|
|
|
|
this.txtDescription.Text = m_WizardSteps[index].Description;
|
|
|
|
|
m_WizardSteps[index].Intializing();
|
|
|
|
|
this.PluginArea.Children.Add((UIElement)m_WizardSteps[index]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void btnExecute_Click(object sender, RoutedEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
if (ValidateAllSeteps())
|
|
|
|
|
{
|
|
|
|
|
this.btnExecute.IsEnabled = false;
|
|
|
|
|
bool ExecuteResult = ExcuteAllSteps();
|
|
|
|
|
if (ExecuteResult)
|
|
|
|
|
{
|
|
|
|
|
this.btnExecute.IsEnabled = true;
|
|
|
|
|
m_view.MoveCurrentToFirst();
|
|
|
|
|
MessageHelper.ShowTips("执行成功!");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
MessageHelper.ShowError(ex.Message);
|
|
|
|
|
}
|
|
|
|
|
this.btnExecute.IsEnabled = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private bool ValidateAllSeteps()
|
|
|
|
|
{
|
|
|
|
|
int setpCount = -1;
|
|
|
|
|
bool validateResult = false;
|
|
|
|
|
foreach (IWizardFramework wizard in m_WizardSteps)
|
|
|
|
|
{
|
|
|
|
|
++setpCount;
|
|
|
|
|
lstSetpCaption.SelectedIndex = setpCount;
|
|
|
|
|
validateResult = wizard.Validating();
|
|
|
|
|
//m_view.MoveCurrentToNext();
|
|
|
|
|
if (!validateResult)
|
|
|
|
|
{
|
|
|
|
|
//m_view.MoveCurrentToPrevious();
|
|
|
|
|
lstSetpCaption.SelectedIndex = setpCount;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return validateResult;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private bool ExcuteAllSteps()
|
|
|
|
|
{
|
|
|
|
|
int setpCount = -1;
|
|
|
|
|
bool validateReslut = false;
|
|
|
|
|
foreach (IWizardFramework wizard in m_WizardSteps)
|
|
|
|
|
{
|
|
|
|
|
++setpCount;
|
|
|
|
|
lstSetpCaption.SelectedIndex = setpCount;
|
|
|
|
|
validateReslut = wizard.Execute();
|
|
|
|
|
//m_view.MoveCurrentToNext();
|
|
|
|
|
if (!validateReslut)
|
|
|
|
|
{
|
|
|
|
|
//m_view.MoveCurrentToPrevious();
|
|
|
|
|
lstSetpCaption.SelectedIndex = setpCount;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return validateReslut;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void btnSkip_Click(object sender, RoutedEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (!IsValidate()) return;
|
|
|
|
|
m_WizardSteps[m_currentSetp].Intializing(true);
|
|
|
|
|
this.Cursor = Cursors.Wait;
|
|
|
|
|
++m_currentSetp;
|
|
|
|
|
SetState();
|
|
|
|
|
ButtonState();
|
|
|
|
|
this.MoveNext(m_currentSetp);
|
|
|
|
|
m_view.MoveCurrentToNext();
|
|
|
|
|
this.Cursor = Cursors.Arrow;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
public class ProcesHelper
|
|
|
|
|
{
|
|
|
|
|
public static ProcesHelper Instance { get; } = new ProcesHelper();
|
|
|
|
|
private ProcesHelper() { }
|
|
|
|
|
public Action<object> ProgressHandle { get; set; }
|
|
|
|
|
public string ExeGPForProces(string arg, TextBox textBox)
|
|
|
|
|
{
|
|
|
|
|
Byte[] toEncryptArray = Encoding.UTF8.GetBytes(arg);
|
|
|
|
|
string strParm = Convert.ToBase64String(toEncryptArray);
|
|
|
|
|
var psi = new ProcessStartInfo("IDGForNDBG.exe", strParm);
|
|
|
|
|
psi.UseShellExecute = false;
|
|
|
|
|
psi.CreateNoWindow = true;
|
|
|
|
|
psi.RedirectStandardError = true;
|
|
|
|
|
psi.RedirectStandardInput = true;
|
|
|
|
|
psi.RedirectStandardOutput = true;
|
|
|
|
|
var pes = Process.Start(psi);
|
|
|
|
|
var sbuffer = new StringBuilder();
|
|
|
|
|
var sout = pes.StandardOutput;
|
|
|
|
|
while (!sout.EndOfStream)
|
|
|
|
|
{
|
|
|
|
|
var line = sout.ReadLine();
|
|
|
|
|
if (String.IsNullOrEmpty(line)) continue;
|
|
|
|
|
sbuffer.AppendLine(line);
|
|
|
|
|
if (line.StartsWith("Msg:"))
|
|
|
|
|
{
|
|
|
|
|
ProgressHandle?.Invoke(line.Replace("Msg:", ""));
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
LogAPI.Debug(line);
|
|
|
|
|
}
|
|
|
|
|
if (line.StartsWith("Msg:"))
|
|
|
|
|
{
|
|
|
|
|
//textBox.Text.
|
|
|
|
|
this.UpdateMsg($"正在执行{line.Replace("Msg:", "")}...");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
pes.WaitForExit();
|
|
|
|
|
pes.Close();
|
|
|
|
|
String res = sbuffer.ToString();
|
|
|
|
|
sbuffer.Clear();
|
|
|
|
|
return res;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
string outPath = string.Empty;
|
|
|
|
|
public string ExeGPForProces(IDGParameter gPParam, TextBox textBox)
|
|
|
|
|
{
|
|
|
|
|
string result = string.Empty;
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
string strParm = SerializeAPI.SerializeToXML<IDGParameter>(gPParam);
|
|
|
|
|
result = ExeGPForProces(strParm, textBox);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
result = ex.Message;
|
|
|
|
|
Console.WriteLine(result);
|
|
|
|
|
Console.WriteLine(ex.Message);
|
|
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|