示例#1
0
 //调度线程导出数据到Excel
 private void DataToExcel(object objFn)
 {
     if (objFn == null)
     {
         return;
     }
     try
     {
         setCtrlEnableValue(false);//禁止控件
         //启动Timer更新进度条的状态
         ProgressManager pm = new ProgressManager(this.pbLoadData);
         pm.Start();//开始进度条
         string fileName = objFn.ToString();
         Dictionary <string, string> dicPropTitle = new Dictionary <string, string>();
         DataTable dt = null;
         rwLockLpt.AcquireReaderLock(CHECKINTERVAL);//请求读锁
         try
         {
             dicPropTitle.Add("SerNumber", "计:" + this.listPrdctTest.Count);
             dicPropTitle.Add("PrdctNumber", "品号");  //品号
             dicPropTitle.Add("TreatType", "处理类型");  //处理类型
             dicPropTitle.Add("WeDuration", "白锈时长"); //白锈时长
             dicPropTitle.Add("ReDuration", "红锈时长");
             dicPropTitle.Add("StartTime", "开始时间");
             dicPropTitle.Add("WeLossTime", "白锈LOSS");
             dicPropTitle.Add("ReLossTime", "红锈LOSS");
             dicPropTitle.Add("WeEndTime", "白锈结束时间");
             dicPropTitle.Add("ReEndTime", "红锈结束时间");
             dicPropTitle.Add("WeTestResult", "白锈结果");
             dicPropTitle.Add("ReTestResult", "红锈结果");
             dicPropTitle.Add("Remark", "备注");
             dt = Dongle.Utilities.CommonUtils.ListToDataTable(this.listPrdctTest, "盐雾试验历史数据", dicPropTitle);
         }
         finally
         {
             rwLockLpt.ReleaseReaderLock();//释放读锁
         }
         if (dt == null || dt.Rows.Count == 0)
         {
             System.Windows.MessageBox.Show("转化后的数据为空!", "系统提示", MessageBoxButton.OK, MessageBoxImage.Warning);
             return;
         }
         DataSet ds = new DataSet("盐雾试验历史数据");
         ds.Tables.Add(dt);
         string mess = string.Empty;
         //bool result = DataImportExport.ExportExcel.DataToExcel(fileName, ds, ref mess);
         bool result = Dongle.Utilities.DataImportExport.DataToExcel(fileName, ds, ref mess);
         pm.Stop();                //停止进度条
         setCtrlEnableValue(true); //恢复控件
         this.Dispatcher.BeginInvoke((Action)(() =>
         {
             if (result)
             {
                 System.Windows.MessageBox.Show("导出已完成!", "系统提示", MessageBoxButton.OK, MessageBoxImage.Information);
             }
             else if (!string.IsNullOrEmpty(mess))
             {
                 System.Windows.MessageBox.Show(mess, "系统提示", MessageBoxButton.OK, MessageBoxImage.Warning);
             }
         }));
     }
     catch (Exception ex)
     {
         Logger.Error(MethodBase.GetCurrentMethod(), "导出数据过程出现错误:" + ex.Message);
     }
 }