Пример #1
0
 public static void PostTask(this Form form, Action <IWaitDialog> action)
 {
     if (action == null)
     {
         return;
     }
     using (WaitDialog dlg = new WaitDialog()){
         dlg.Closing += delegate(object sender, CancelEventArgs e) {
             if (!dlg.CanClose)
             {
                 form.Info(R.TipStopTask);
                 e.Cancel = true;
             }
         };
         dlg.Shown += delegate {
             Thread thread = new Thread(() =>
             {
                 action(dlg);
                 dlg.CanClose = true;
                 dlg.CloseDialog();
             });
             thread.IsBackground = true;
             thread.Start();
         };
         dlg.ShowDialog();
     }
 }
Пример #2
0
        private void WriteDataToExcel(List <ObjectItemTypeDefinationModel> selectedData)
        {
            var _filePath = string.Empty;

            Microsoft.Win32.SaveFileDialog dlg = new Microsoft.Win32.SaveFileDialog();
            dlg.FileName   = "Document";                        // Default file name
            dlg.DefaultExt = ".xlsx";                           // Default file extension
            dlg.Filter     = "Excel Files|*.xls;*.xlsx;*.xlsm"; // Filter files by extension

            // Show save file dialog box
            Nullable <bool> result = dlg.ShowDialog();

            // Process save file dialog box results
            if (result == true)
            {
                // Save document
                _filePath = dlg.FileName;
            }
            if (!String.IsNullOrEmpty(_filePath))
            {
                try {
                    using (SpreadsheetDocument spreadsheetDocument = SpreadsheetDocument.Create(_filePath, SpreadsheetDocumentType.Workbook))
                    {
                        // Add a WorkbookPart to the document.
                        WorkbookPart workbookpart = spreadsheetDocument.AddWorkbookPart();
                        workbookpart.Workbook = new Workbook();
                        //workbookpart.Workbook.Save();
                        using (WaitDialog wait = myApplication.Dialogs.CreateWaitDialog())
                        {
                            wait.ShowDialogAsync(500, "Please wait...", AnimationType.FileMove);


                            foreach (var obj in selectedData)
                            {
                                foreach (var child in obj.FolderChildren)
                                {
                                    if (child.FolderChildren.Count == 0)
                                    {
                                        _sheetname = child.Name;
                                        var newSheet = CreateNewWorkSheet(spreadsheetDocument, _sheetname);
                                        AddrowsToNewWorkSheet(child, spreadsheetDocument, _sheetname);
                                    }
                                    else
                                    {
                                        foreach (var StackChild in child.FolderChildren)
                                        {
                                            _sheetname = StackChild.Name;
                                            var newSheet = CreateNewWorkSheet(spreadsheetDocument, _sheetname);
                                            AddrowsToNewWorkSheet(StackChild, spreadsheetDocument, _sheetname);
                                            wait.UpdateDialog(_i, _sheetname + " " + ": Exported");
                                        }
                                    }

                                    wait.UpdateDialog(_i, _sheetname + " " + "Exported");
                                }
                                wait.UpdateDialog(_i, "Next Type Defination Folder");
                            }
                            wait.UpdateDialog(500, "Almost there");
                            wait.CloseDialog();
                            System.Windows.MessageBox.Show("Successfully Exported All Selected Data");
                        }

                        // Close the document.
                        spreadsheetDocument.Close();
                    }
                }
                catch { System.Windows.MessageBox.Show("Close all excel files"); }
            }
            else
            {
                System.Windows.MessageBox.Show("File Path Invalid");
            }
        }