private void barButtonItem2_ItemClick(object sender, ItemClickEventArgs e) { //弹出加载对话框 DevExpress.Utils.WaitDialogForm waitDialog = null; new Thread((ThreadStart) delegate { waitDialog = new DevExpress.Utils.WaitDialogForm("请稍候...", "正在生成数据"); waitDialog.TopMost = false; System.Windows.Forms.Application.Run(waitDialog); }).Start(); bool flag = WriteYear1(); waitDialog.Invoke((EventHandler) delegate { waitDialog.Close(); }); if (flag) { MessageBox.Show("生成成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show("数据获取失败", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } }
private void barBtnExport_ItemClick(object sender, ItemClickEventArgs e) { SaveFileDialog saveFileDialog = new SaveFileDialog(); saveFileDialog.Title = "导出Excel"; saveFileDialog.Filter = "Excel文件(*.xlsx)|*.xlsx"; DialogResult dialogResult = saveFileDialog.ShowDialog(this); if (dialogResult == DialogResult.OK) { DevExpress.Utils.WaitDialogForm WaitExportToExcel = null; try { new Thread((ThreadStart) delegate { WaitExportToExcel = new DevExpress.Utils.WaitDialogForm("请稍候...", "正在导出排名结果"); WaitExportToExcel.TopMost = false; Application.Run(WaitExportToExcel); }).Start(); ExportToExcel toExcel = new ExportToExcel(); DataSet ds = new DataSet(); if (gridControl1.DataSource != null) { DataTable dt1 = (DataTable)gridControl1.DataSource; dt1.TableName = "车型油耗目标值"; DataTable dtc1 = dt1.Copy(); dtc1.Columns["ZBZL"].ColumnName = "整备质量/kg"; dtc1.Columns["ZWPS2"].ColumnName = "座位排数≤2/(L/100km)"; dtc1.Columns["ZWPS3"].ColumnName = "座位排数≥3/(L/100km)"; ds.Tables.Add(dtc1); } if (gridControl2.DataSource != null) { DataTable dt2 = (DataTable)gridControl2.DataSource; dt2.TableName = "新能源车型核算倍数"; DataTable dtc2 = dt2.Copy(); dtc2.Columns["YEAR"].ColumnName = "年份"; dtc2.Columns["RATIO"].ColumnName = "核算倍数"; ds.Tables.Add(dtc2); } if (gridControl3.DataSource != null) { DataTable dt3 = (DataTable)gridControl3.DataSource; dt3.TableName = "节能车核算倍数"; DataTable dtc3 = dt3.Copy(); dtc3.Columns["YEAR"].ColumnName = "年份"; dtc3.Columns["RATIO"].ColumnName = "核算倍数"; ds.Tables.Add(dtc3); } if (gridControl4.DataSource != null) { DataTable dt4 = (DataTable)gridControl4.DataSource; dt4.TableName = "企业平均燃料消耗量要求"; DataTable dtc4 = dt4.Copy(); dtc4.Columns["YEAR"].ColumnName = "年份"; dtc4.Columns["RATIO"].ColumnName = "Phase in系数"; ds.Tables.Add(dtc4); } toExcel.ToExcelSheet(ds, saveFileDialog.FileName); MessageBox.Show("导出成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } catch (Exception ex) { MessageBox.Show("导出失败,请检查!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } finally { WaitExportToExcel.Invoke((EventHandler) delegate { WaitExportToExcel.Close(); }); } } }
/// <summary> /// 导入或修改车型参数 /// </summary> /// <param name="importType"></param> protected void ImportMainData(string importType) { string operateType = string.Empty; if (importType == "IMPORT") { operateType = "导入"; } else if (importType == "UPDATE") { operateType = "修改"; } MitsUtils utils = new MitsUtils(); FolderDialog openFolder = new FolderDialog(); DevExpress.Utils.WaitDialogForm waitDialog = null; try { if (openFolder.DisplayDialog() == DialogResult.OK) { // 获取用户选择的文件夹路径 string folderPath = openFolder.Path.ToString(); // 获取folderPath下以格式为utils.CocFileName的所有文件 List <string> fileNameList = utils.GetFileName(folderPath, utils.MainFileName); if (fileNameList.Count > 0) { string fileNameMsg = string.Empty; string returnMsg = string.Empty; List <string> mainUpdateList = new List <string>(); //弹出加载提示画面 new Thread((ThreadStart) delegate { waitDialog = new DevExpress.Utils.WaitDialogForm("loading...", "系统处理中,请等待"); Application.Run(waitDialog); }).Start(); // 遍历读所有文件fileNameList foreach (string fileName in fileNameList) { fileNameMsg += Path.GetFileName(fileName) + "\r\n"; // 导入filename文件信息 returnMsg += utils.ImportMainData(fileName, folderPath, importType, mainUpdateList); } MessageForm mf = new MessageForm(returnMsg); Utils.SetFormMid(mf); mf.Text = operateType + "结果"; //关闭登录提示画面 waitDialog.Invoke((EventHandler) delegate { waitDialog.Close(); }); mf.ShowDialog(); if (importType == "IMPORT") { this.ShowMainData(); } else if (importType == "UPDATE") { this.ShowUpdatedMainData(mainUpdateList); } } else { MessageBox.Show(String.Format("目录{0}下没有文件{1}", folderPath, utils.MainFileName), "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } } } catch (Exception ex) { //关闭登录提示画面 if (waitDialog != null) { waitDialog.Invoke((EventHandler) delegate { waitDialog.Close(); }); } MessageBox.Show(String.Format("{0}失败:{1}", operateType, ex.Message), "异常", MessageBoxButtons.OK, MessageBoxIcon.Error); } }