8,735
社区成员
发帖
与我相关
我的任务
分享
W_PBarSuper win = new W_PBarSuper(string.Format("正在读取文件:{0}……", tempATCFile.FileName), ProcessBarCategory.OpenPhoneFile, _param);
try
{
win.Owner = this._parentWindow;
win.WindowStartupLocation = WindowStartupLocation.CenterOwner;
win.ShowDialog();
}
private ProcessBarCategory _currentProcessBarCategory = ProcessBarCategory.OpenPhoneFile;
private object[] _param = null;
public W_PBarSuper(string des, ProcessBarCategory enumOP, object[] param)
{
InitializeComponent();
this.lbl_Des.Content = des;
this._currentProcessBarCategory = enumOP;
this._param = param;
this.OperateResult = false;
}
private void Window_Loaded(object sender, RoutedEventArgs e)
{
try
{
this.start();
}
catch(Exception ex)
{
Log.LogRecord(ex.ToString());
}
}
#region 进度条相关,主要是实现接口:INotifyPropertyChanged
/// <summary>
/// 记录百分比
/// </summary>
public double percent = 0;
private double finished;
/// <summary>
/// 记录获取信息时候完成度
/// </summary>
public double Finished
{
get
{
return this.finished;
}
set
{
this.finished = value;
NotifyPropertyChanged("Finished");
}
}
private string _detailDescription;
/// <summary>
/// 记录获取信息时候需要提示的文字
/// </summary>
public string DetailDescription
{
get
{
return this._detailDescription;
}
set
{
this._detailDescription = value;
NotifyPropertyChanged("DetailDescription");
}
}
public event PropertyChangedEventHandler PropertyChanged;
public void NotifyPropertyChanged(string propertyName)
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
#endregion
private void RegisterEventThis()
{
this.PropertyChanged -= new PropertyChangedEventHandler(this.This_PropertyChanged);
this.PropertyChanged += new PropertyChangedEventHandler(this.This_PropertyChanged);
}
void This_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
{
if (e.PropertyName == "Finished")
{
//this.pb_Main.Value = this._currentMTKPhone.Finished;
this.pb_Main.Dispatcher.Invoke(new Action<DependencyProperty, object>(this.pb_Main.SetValue), DispatcherPriority.Background, ProgressBar.ValueProperty, this.Finished);
//Thread initThread = new Thread(new ParameterizedThreadStart(this.InitInformation2));
//initThread.Start(this._currentMTKPhone.Finished);
}
else if (e.PropertyName == "DetailDescription")
{
//this.lbl_DesDetail.Content = this._currentMTKPhone.DetailDescription;
this.lbl_DesDetail.Dispatcher.Invoke(new Action<DependencyProperty, object>(this.lbl_DesDetail.SetValue), DispatcherPriority.Background, Label.ContentProperty, this.DetailDescription);
}
//this.Dispatcher.Invoke(new UpdateUIDelegate(this.UpdateUI), new object[] { this._currentMTKPhone.Finished, this._currentMTKPhone.DetailDescription });
}
private System.Windows.Threading.DispatcherTimer timer = new System.Windows.Threading.DispatcherTimer();
//轮循执行要执行的业务逻辑
void Refersh(object sender, EventArgs e)
{
try
{
this.StartThread();
}
catch(Exception ex)
{
//throw ex;
}
finally
{
this.stop();
this.Close();
}
}
private void StartThread()
{
switch (this._currentProcessBarCategory)
{
case ProcessBarCategory.OpenPhoneFile:
this.OpenPhoneFile(this._param[0] as ATCFile);
break;
case ProcessBarCategory.WritePhoneFile:
this.WritePhoneFile(this._param[0] as string, this._param[1] as string);
break;
default:
break;
}
}
public void start()
{
timer.Tick += Refersh;
timer.Interval = new TimeSpan(0, 0, 1);
timer.Start();
}
public void stop()
{
timer.Stop();
timer.Tick -= Refersh;
}
public bool OpenPhoneFile(ATCFile atc)
{
this.RegisterEventThis();
try
{
string phoneFullFileName = atc.FullFileName;
if (!Directory.Exists(ConstString.ATCFileTemp))
{
Directory.CreateDirectory(ConstString.ATCFileTemp);
}
string pcFullFileName = System.IO.Path.Combine(ConstString.ATCFileTemp, atc.FileName);
//fileName
if (System.IO.File.Exists(pcFullFileName))
{
System.IO.File.Delete(pcFullFileName);
}
//逻辑函数中更新你的Finished和DetailDescription
byte[] array = DataConvert.HexToByte(result);
System.IO.FileStream fs = new System.IO.FileStream(pcFullFileName, System.IO.FileMode.Create, System.IO.FileAccess.Write);
fs.Write(array, 0, array.Length);
fs.Close();
this.OperateResult = true;
}
catch (Exception ex)
{
this.OperateResult = false;
throw ex;
}
finally
{
}
return true;
}