Beispiel #1
0
        private void ExportXlsFile()
        {
            if (dataGrid.ColumnCount > 0)
            {
                using (var fileDialog = new SaveFileDialog())
                {
                    //openFileDialog.InitialDirectory = @"%HOMEPATH%";
                    fileDialog.Filter           = Resources.xlsfile_dialogextension;
                    fileDialog.FilterIndex      = 1;
                    fileDialog.RestoreDirectory = true;

                    if (fileDialog.ShowDialog() == DialogResult.OK)
                    {
                        // Save the contents of the dataGrid into the chosen file
                        if (ImpExpUtilities.ExportXLS(dataGrid.DataSource as DataTable, fileDialog.FileName))
                        {
                            MessageBox.Show(Resources.saveCurrent_success + fileDialog.FileName, Resources.success, MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                        }
                        else
                        {
                            MessageBox.Show(Resources.saveCSV_fail_msg, Resources.fail, MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }
                    }
                }
            }
            else
            {
                MessageBox.Show(Resources.saveEmptyTable_fail_msg, Resources.fail, MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }
Beispiel #2
0
        private void ExportFile()
        {
            if (dataGrid.ColumnCount > 0)
            {
                using (var fileDialog = new SaveFileDialog())
                {
                    fileDialog.Filter           = Resources.supportedFiles_extension;
                    fileDialog.FilterIndex      = 1;
                    fileDialog.RestoreDirectory = true;

                    if (fileDialog.ShowDialog() == DialogResult.OK)
                    {
                        var fileSuccessfullyExported = false;
                        switch (Path.GetExtension(fileDialog.FileName)?.ToLower())
                        {
                        // Export the file depending on the chosen extension, !Export -> if export fails, return instead is to display err msg only
                        case ".xml":
                            fileSuccessfullyExported = ImpExpUtilities.ExportXML(dataGrid.DataSource as DataTable, fileDialog.FileName);
                            break;

                        case ".xlsx":
                            fileSuccessfullyExported = ImpExpUtilities.ExportXLS(dataGrid.DataSource as DataTable, fileDialog.FileName);
                            break;

                        case ".csv":
                            fileSuccessfullyExported = ImpExpUtilities.ExportCSV(dataGrid, fileDialog.FileName);
                            break;
                        }

                        if (fileSuccessfullyExported)
                        {
                            currentOpenDocumentPath = fileDialog.FileName;
                            this.Text = Resources.title + '[' + Path.GetFileName(currentOpenDocumentPath) + ']'; // Change the Forms title to currentOpenDoc #10
                            MessageBox.Show(Resources.saveCurrent_success + currentOpenDocumentPath, Resources.success, MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                        }
                        else
                        {
                            MessageBox.Show(string.Format(Resources.saveFile_fail_msg, fileDialog.FileName), Resources.fail, MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }
                    }
                }
            }
            else
            {
                MessageBox.Show(Resources.saveEmptyTable_fail_msg, Resources.fail, MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }
Beispiel #3
0
        private void SaveFile()
        {
            if (currentOpenDocumentPath != String.Empty)
            {
                if (!readOnly.Checked && !newDocument)
                {
                    var fileSuccessfullyExported = false;
                    switch (Path.GetExtension(currentOpenDocumentPath)?.ToLower())
                    {
                    // Save the file depending on the chosen extension, !Export -> if export fails, return instead is to display err msg only
                    case ".xml":
                        fileSuccessfullyExported = ImpExpUtilities.ExportXML(dataGrid.DataSource as DataTable, currentOpenDocumentPath);
                        break;

                    case ".xlsx":
                        fileSuccessfullyExported = ImpExpUtilities.ExportXLS(dataGrid.DataSource as DataTable, currentOpenDocumentPath);
                        break;

                    case ".csv":
                        fileSuccessfullyExported = ImpExpUtilities.ExportCSV(dataGrid, currentOpenDocumentPath);
                        break;
                    }
                    if (fileSuccessfullyExported)
                    {
                        MessageBox.Show(Resources.saveCurrent_success + currentOpenDocumentPath, Resources.success, MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                    }
                    else
                    {
                        MessageBox.Show(string.Format(Resources.saveFile_fail_msg, currentOpenDocumentPath), Resources.fail, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
                else if (readOnly.Checked && !newDocument)
                {
                    MessageBox.Show(Resources.saveXml_fail_msg, Resources.fail, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
            }
            else if (newDocument || currentOpenDocumentPath?.Length == 0)
            {
                ExportFile();
            }
        }