Example #1
0
        public SaveMenu(String data, Window parentWindow)
            : base("Save Menu", 10, 45, 60, 20, parentWindow)
        {
            Text = data;

            fileSelect = new FileSelect(12, 47, FileInfo.Path, "fileSelect", this);

            var openLabel = new Label("Name", 26, 47, "openLabel", this);

            openTxtBox = new TextBox(26, 53, FileInfo.Filename, "openTxtBox", this)
            {
                Selectable = true
            };

            saveBtn          = new Button(28, 48, "Save", "loadBtn", this);
            saveBtn.Action   = delegate() { SaveFile(); };
            cancelBtn        = new Button(28, 56, "Cancel", "cancelBtn", this);
            cancelBtn.Action = delegate() { ExitWindow(); };

            Inputs.Add(fileSelect);
            Inputs.Add(openLabel);
            Inputs.Add(openTxtBox);
            Inputs.Add(saveBtn);
            Inputs.Add(cancelBtn);

            CurrentlySelected = saveBtn;

            Draw();
            MainLoop();
        }
Example #2
0
        public override void BuildLayout(SingleContainer editorContainer, IAssetManager assetManager)
        {
            this.m_FileSelect = new FileSelect {
                Path = this.m_Asset.SourcePath
            };
            this.m_FileSelect.Changed += (sender, e) =>
            {
                this.m_Asset.SourcePath = this.m_FileSelect.Path;
                using (var stream = new StreamReader(this.m_Asset.SourcePath, Encoding.UTF8))
                {
                    this.m_Asset.Value = stream.ReadToEnd();
                }
                assetManager.Save(this.m_Asset);
            };

            var form = new Form();

            form.AddControl("Source File:", this.m_FileSelect);

            var vertContainer = new VerticalContainer();

            vertContainer.AddChild(form, "*");

            editorContainer.SetChild(vertContainer);
        }
Example #3
0
        public override void BuildLayout(SingleContainer editorContainer, IAssetManager assetManager)
        {
            this.m_FileSelect          = new FileSelect();
            this.m_FileSelect.Changed += (sender, e) =>
            {
                using (var stream = new FileStream(this.m_FileSelect.Path, FileMode.Open))
                {
                    using (var reader = new BinaryReader(stream))
                    {
                        this.m_Asset.RawData = reader.ReadBytes((int)stream.Length);
                    }
                }
                assetManager.Recompile(this.m_Asset);
                assetManager.Save(this.m_Asset);
            };

            var form = new Form();

            form.AddControl("Source File:", this.m_FileSelect);

            //var textureViewer = new TextureViewer();
            //textureViewer.Texture = this.m_Asset;

            var vertContainer = new VerticalContainer();

            vertContainer.AddChild(form, "*");
            //vertContainer.AddChild(textureViewer, "400");

            editorContainer.SetChild(vertContainer);
        }
Example #4
0
        //private void AddCurrentRowStationInfo(GridViewRowInfo rowInfo, List<MesService.TestLogResultHistory> historyList,string processName,string pid,string sid)
        //{
        //    var stationInDate_burn = rowInfo.Cells[5].Value.ToString();
        //    var stationInDate_sen = rowInfo.Cells[15].Value.ToString();
        //    var stationInDate_shell = rowInfo.Cells[27].Value.ToString();
        //    var stationInDate_air = rowInfo.Cells[41].Value.ToString();
        //    var stationInDate_stent = rowInfo.Cells[46].Value.ToString();
        //    var stationInDate_product = rowInfo.Cells[55].Value.ToString();

        //    if (!string.IsNullOrEmpty(stationInDate_burn))
        //    {
        //        MesService.TestLogResultHistory history = new MesService.TestLogResultHistory();
        //        history.ProcessName = processName;
        //        history.PcbaSN = pid;
        //        history.ProductSN = sid;
        //        history.StationName = "烧录工站";
        //        history.StationInDate = stationInDate_burn;
        //        historyList.Add(history);
        //    }
        //    if (!string.IsNullOrEmpty(stationInDate_sen))
        //    {
        //        MesService.TestLogResultHistory history = new MesService.TestLogResultHistory();
        //        history.ProcessName = processName;
        //        history.PcbaSN = pid;
        //        history.ProductSN = sid;
        //        history.StationName = "灵敏度测试工站";
        //        history.StationInDate = stationInDate_sen;
        //        historyList.Add(history);
        //    }
        //    if (!string.IsNullOrEmpty(stationInDate_shell))
        //    {
        //        MesService.TestLogResultHistory history = new MesService.TestLogResultHistory();
        //        history.ProcessName = processName;
        //        history.PcbaSN = pid;
        //        history.ProductSN = sid;
        //        history.StationName = "外壳装配工站";
        //        history.StationInDate = stationInDate_shell;
        //        historyList.Add(history);
        //    }
        //    if (!string.IsNullOrEmpty(stationInDate_air))
        //    {
        //        MesService.TestLogResultHistory history = new MesService.TestLogResultHistory();
        //        history.ProcessName = processName;
        //        history.PcbaSN = pid;
        //        history.ProductSN = sid;
        //        history.StationName = "气密测试工站";
        //        history.StationInDate = stationInDate_air;
        //        historyList.Add(history);
        //    }
        //    if (!string.IsNullOrEmpty(stationInDate_stent))
        //    {
        //        MesService.TestLogResultHistory history = new MesService.TestLogResultHistory();
        //        history.ProcessName = processName;
        //        history.PcbaSN = pid;
        //        history.ProductSN = sid;
        //        history.StationName = "支架装配工站";
        //        history.StationInDate = stationInDate_stent;
        //        historyList.Add(history);
        //    }
        //    if (!string.IsNullOrEmpty(stationInDate_product))
        //    {
        //        MesService.TestLogResultHistory history = new MesService.TestLogResultHistory();
        //        history.ProcessName = processName;
        //        history.PcbaSN = pid;
        //        history.ProductSN = sid;
        //        history.StationName = "成品测试工站";
        //        history.StationInDate = stationInDate_product;
        //        historyList.Add(history);
        //    }
        //}

        #endregion

        private string ExportDesFilePath(GridViewExport.ExportFormat exportFormat)
        {
            var filter = "Excel (*.xls)|*.xls";
            var path   = "";

            if (exportFormat == GridViewExport.ExportFormat.EXCEL)
            {
                filter = "Excel (*.xls)|*.xls";
                path   = FileSelect.SaveAs(filter, "C:\\");
            }
            else if (exportFormat == GridViewExport.ExportFormat.HTML)
            {
                filter = "Html File (*.htm)|*.htm";
                path   = FileSelect.SaveAs(filter, "C:\\");
            }
            else if (exportFormat == GridViewExport.ExportFormat.PDF)
            {
                filter = "PDF file (*.pdf)|*.pdf";
                path   = FileSelect.SaveAs(filter, "C:\\");
            }
            else if (exportFormat == GridViewExport.ExportFormat.CSV)
            {
                filter = "CSV file (*.csv)|*.csv";
                path   = FileSelect.SaveAs(filter, "C:\\");
            }
            return(path);
        }
Example #5
0
        private async Task SetExcelRelatedFieldsAsync(FileSelect excel)
        {
            Model.IsLoading = Visibility.Visible;
            try
            {
                SetSelectedFileName(excel);

                Model.SheetItems.Clear();
                Model.MonthOnlySheets.Clear();

                if (FileSelected(Model.ExcelFileName))
                {
                    await ShowAvailableSheetsAsync();
                }
                else
                {
                    Model.SheetSelectionVisibility = Visibility.Collapsed;
                }

                Model.IsLoading = Visibility.Collapsed;
            }
            catch (Exception ex)
            {
                _logService.Error("Failed to finish displaying sheets to select. ", ex);
                Model.IsLoading = Visibility.Collapsed;
                await ShowMessageDialogAsync(DialogIcon.ErrorFilled, $"Klaida, kuriant \"Excel\" lapų pasirinkimą:\n\"{ex.Message}\"");
            }
        }
        // Token: 0x0600296A RID: 10602 RVA: 0x0009E720 File Offset: 0x0009C920
        public static bool smethod_2(out Class524 selectedFile)
        {
            bool result;

            using (FileSelect fileSelect = new FileSelect())
            {
                fileSelect.InputLabelMessage = "Please enter a reference name for this capture file.";
                fileSelect.InputText         = "The ToonTown Spoofer : Joe Fish Capture Setup File Name";
                fileSelect.FileInfo          = Class110.Instance.JoeFishSettings.JoeFishCaptureSettings.Files.ToArray();
                fileSelect.Filter            = "Joe Fish Capture Setup File|*.jfc";
                fileSelect.InstallFolder     = Class291.JoeFishCaptureSettingsDirectory;
                fileSelect.FileExtension     = ".jfc";
                FileSelectBase fileSelectBase = fileSelect;
                if (Class460.eventHandler_0 == null)
                {
                    Class460.eventHandler_0 = new EventHandler <EventArgs43 <string> >(Class460.smethod_6);
                }
                fileSelectBase.InputValidating += Class460.eventHandler_0;
                if (fileSelect.ShowDialog() == DialogResult.OK)
                {
                    selectedFile = fileSelect.SelectedFileInfo;
                }
                else
                {
                    selectedFile = null;
                }
                Class110.Instance.JoeFishSettings.JoeFishCaptureSettings.Files.Clear();
                Class110.Instance.JoeFishSettings.JoeFishCaptureSettings.Files.AddRange(fileSelect.FileInfo);
                Class110.smethod_1();
                result = Class524.smethod_1(selectedFile, null);
            }
            return(result);
        }
        // Token: 0x0600296C RID: 10604 RVA: 0x0009E930 File Offset: 0x0009CB30
        public static bool smethod_4(out Class524 selectedFile)
        {
            bool result;

            using (FileSelect fileSelect = new FileSelect())
            {
                fileSelect.InputLabelMessage = "Please enter a reference name for this flora file.";
                fileSelect.InputText         = "The ToonTown Spoofer : Gardener Flora File Name";
                fileSelect.FileInfo          = Class110.Instance.GardenerFloraSettings.GardenerFloraFiles.Files.ToArray();
                fileSelect.Filter            = "Gardener Flora File|*.flora";
                fileSelect.InstallFolder     = Class291.GardenerFloraEstateSettings;
                fileSelect.FileExtension     = ".flora";
                FileSelectBase fileSelectBase = fileSelect;
                if (Class460.eventHandler_2 == null)
                {
                    Class460.eventHandler_2 = new EventHandler <EventArgs43 <string> >(Class460.smethod_8);
                }
                fileSelectBase.InputValidating += Class460.eventHandler_2;
                if (fileSelect.ShowDialog() == DialogResult.OK)
                {
                    selectedFile = fileSelect.SelectedFileInfo;
                }
                else
                {
                    selectedFile = null;
                }
                Class110.Instance.GardenerFloraSettings.GardenerFloraFiles.Files.Clear();
                Class110.Instance.GardenerFloraSettings.GardenerFloraFiles.Files.AddRange(fileSelect.FileInfo);
                Class110.smethod_1();
                result = Class524.smethod_1(selectedFile, null);
            }
            return(result);
        }
Example #8
0
        /// <summary>
        /// Opens a file dialog for the user to select the Jagex client executable
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void JagexClientSelect_Click(object sender, EventArgs e)
        {
            DialogResult result = FileSelect.ShowDialog();

            if (result == DialogResult.OK)
            {
                JagexClientLocation.Text = FileSelect.FileName;
            }
        }
        private void BtnSelectSavePath_Click(object sender, EventArgs e)
        {
            var rePath = FileSelect.GetDirectorPath();

            if (rePath != "")
            {
                this.textBox_savePath.Text = reportDir;
            }
        }
Example #10
0
        private void button1_Click(object sender, EventArgs e)
        {
            // File Select
            DialogResult FileSelectResult = FileSelect.ShowDialog();

            if (FileSelectResult == DialogResult.OK)
            {
                textBox1.Text = FileSelect.FileName;
            }
        }
Example #11
0
        private async Task SetEipRelatedFields(FileSelect eipMode)
        {
            try
            {
                SetSelectedFileName(eipMode);
            }
            catch (Exception ex)
            {
                _logService.Error($"Failed to select eip file", ex);

                await ShowMessageDialogAsync(DialogIcon.ErrorFilled, $"Klaida, pasirenkant .eip failą:\n\"{ex.Message}\"");
            }
        }
        /// <summary>
        /// 导出数据
        /// </summary>
        /// <param name="selectIndex"></param>
        /// <param name="radGridView"></param>
        public static void ExportGridViewData(ExportFormat exportFormat, RadGridView radGridView)
        {
            if (radGridView.RowCount < 1)
            {
                MessageBox.Show("没有可以导出的数据!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            var filter = "Excel (*.xls)|*.xls";

            if (exportFormat == ExportFormat.EXCEL)
            {
                filter = "Excel (*.xls)|*.xls";
                var path = FileSelect.SaveAs(filter, "C:\\");
                if (path == "")
                {
                    return;
                }
                GridViewExport.RunExportToExcelML(path, radGridView);
            }
            else if (exportFormat == ExportFormat.HTML)
            {
                filter = "Html File (*.htm)|*.htm";
                var path = FileSelect.SaveAs(filter, "C:\\");
                if (path == "")
                {
                    return;
                }
                GridViewExport.RunExportToHTML(path, radGridView);
            }
            else if (exportFormat == ExportFormat.PDF)
            {
                filter = "PDF file (*.pdf)|*.pdf";
                var path = FileSelect.SaveAs(filter, "C:\\");
                if (path == "")
                {
                    return;
                }
                GridViewExport.RunExportToPDF(path, radGridView);
            }
            else if (exportFormat == ExportFormat.CSV)
            {
                filter = "CSV file (*.csv)|*.csv";
                var path = FileSelect.SaveAs(filter, "C:\\");
                if (path == "")
                {
                    return;
                }
                GridViewExport.RunExportToCSV(path, radGridView);
            }
        }
Example #13
0
        private void generateSQLToolStripMenuItem_Click(object sender, EventArgs e)
        {
            FileSelect SelectFile = new FileSelect();

            SelectFile.ShowDialog();

            if (SelectFile.Success)
            {
                IBMiUtils.UsingQTEMPFiles(new[] { "Q_GENSQL" });
                if (IBMi.RemoteCommand(SelectFile.getCommand()))
                {
                    OpenSource(new RemoteSource("", "QTEMP", "Q_GENSQL", "Q_GENSQL", "SQL", false));
                }
                else
                {
                    MessageBox.Show("Error generating SQL source.");
                }
            }
        }
Example #14
0
        private void SetSelectedFileName(FileSelect fileMode)
        {
            _logService.Information("Openning file select dialog with file mode filter: {Mode}", fileMode.ToString());
            switch (fileMode)
            {
            case FileSelect.Excel:
                Model.ExcelFileName = GetSelectedFile("Excel |*.xlsx") ?? UIDefault.FileNotSelected;
                _logService.Information("File selected {FileName}", Model.ExcelFileName);
                break;

            case FileSelect.Eip:
                Model.EipFileName = GetSelectedFile("Eip |*.eip") ?? UIDefault.FileNotSelected;
                _logService.Information("File selected {FileName}", Model.EipFileName);
                break;

            default:
                throw new ArgumentException($"FileSelect enum does not contain {fileMode} value");
            }
        }
Example #15
0
        public MainWindow()
            : base("Change Folder", 1, (Console.WindowWidth / 2) - ((Console.WindowWidth - 4) / 2), Console.WindowWidth - 4, Console.WindowHeight - 2, null)
        {
            var folderSelect = new FileSelect(3, 3, Console.WindowWidth - 6, Height - 6, Directory.GetCurrentDirectory(), "folderSelect", this, true);
            folderSelect.SelectFile = delegate() { Path = folderSelect.CurrentPath; changePath = true; ExitWindow(); };

            var selectBtn = new Button(PostionX + Height - 2, 3, "Select", "selectBtn", this);
            selectBtn.Action = delegate() { Path = folderSelect.CurrentPath; changePath = true; ExitWindow(); };

            var cancelBtn = new Button(PostionX + Height - 2, 12, "Cancel", "cancelBtn", this);
            cancelBtn.Action = delegate() { changePath = false; ExitWindow(); };

            Inputs.Add(folderSelect);
            Inputs.Add(selectBtn);
            Inputs.Add(cancelBtn);

            CurrentlySelected = selectBtn;

            Draw();
            MainLoop();
        }
Example #16
0
        private void generateSQLToolStripMenuItem_Click(object sender, EventArgs e)
        {
            FileSelect SelectFile = new FileSelect();

            SelectFile.ShowDialog();

            if (SelectFile.Success)
            {
                new Thread((ThreadStart) delegate {
                    IBMi.RemoteCommand(SelectFile.getCommand());
                    string resultFile = IBMiUtils.DownloadMember("QTEMP", "Q_GENSQL", "Q_GENSQL", "SQL");

                    if (resultFile != "")
                    {
                        this.Invoke((MethodInvoker) delegate
                        {
                            Editor.TheEditor.AddMemberEditor(new Member(resultFile, "QTEMP", "Q_GENSQL", "Q_GENSQL", "SQL", false), GetBoundLangType("SQL"));
                        });
                    }
                }).Start();
            }
        }
Example #17
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            OpenFileDialog m_openDialog = new OpenFileDialog();

            m_openDialog.Filter = this.Extension;
            if (m_openDialog.ShowDialog() == true)
            {
                Result                   = true;
                SelectedFileName         = m_openDialog.FileName;
                this.ButtonLabel.Content = ButtonLabelContent;
            }
            else
            {
                Result           = false;
                SelectedFileName = "";
            }

            FileSelect?.Invoke(this, new FileSelectionArgs()
            {
                isSelected = Result, FileName = SelectedFileName
            });
        }
Example #18
0
        public LoadMenu(Window parentWindow)
            : base("Load Menu", 10, 45, 60, 20, parentWindow)
        {
            fileSelect            = new FileSelect(12, 47, FileInfo.Path, "fileSelect", this, true, "txt");
            fileSelect.ChangeItem = delegate() { UpdateCurrentlySelectedFileName(); };
            fileSelect.SelectFile = delegate() { LoadFile(); };

            var openLabel = new Label("Open", 26, 47, "openLabel", this);

            openTxtBox = new TextBox(26, 53, "openTxtBox", this, 31)
            {
                Selectable = false
            };

            var fileTypes = new List <String> {
                "Text Doc (txt)", "All Files"
            };

            fileTypeDropdown            = new Dropdown(26, 86, fileTypes, "fileTypeDropdown", this, 17);
            fileTypeDropdown.OnUnselect = delegate() { UpdateFileTypeFilter(); };

            loadBtn          = new Button(28, 48, "Load", "loadBtn", this);
            loadBtn.Action   = delegate() { LoadFile(); };
            cancelBtn        = new Button(28, 56, "Cancel", "cancelBtn", this);
            cancelBtn.Action = delegate() { ExitWindow(); };

            Inputs.Add(fileSelect);
            Inputs.Add(fileTypeDropdown);
            Inputs.Add(loadBtn);
            Inputs.Add(cancelBtn);
            Inputs.Add(openLabel);
            Inputs.Add(openTxtBox);

            CurrentlySelected = fileSelect;

            Draw();
            MainLoop();
        }
Example #19
0
        public override void BuildLayout(SingleContainer editorContainer, IAssetManager assetManager)
        {
            this.m_FileSelect          = new FileSelect();
            this.m_FileSelect.Changed += (sender, e) =>
            {
                using (var reader = new StreamReader(this.m_FileSelect.Path))
                {
                    this.m_Asset.Code = reader.ReadToEnd();
                }
                assetManager.Recompile(this.m_Asset);
                assetManager.Save(this.m_Asset);
            };

            var form = new Form();

            form.AddControl("Source File:", this.m_FileSelect);

            var vertContainer = new VerticalContainer();

            vertContainer.AddChild(form, "*");

            editorContainer.SetChild(vertContainer);
        }
 private void LoadImage()
 {
     try
     {
         string filter = "Image(*.jpg;*.png;*.bmp;*.tiff;*.jepg;*.gif;)|*.jpg;*.png;*.bmp;*.tiff;*.jepg;*.gif|" +
                         "jpg(*.jpg)|*.jpg|png(*.png)|*.png|bmp(*.bmp)|*.bmp";
         FileContent fileContent = FileSelect.GetSelectFileContent(filter, "选择图片");
         if (fileContent == null)
         {
             return;
         }
         if (string.IsNullOrEmpty(fileContent.FileName))
         {
             return;
         }
         radLabel1.Text    = fileContent.FileName.Split('.')[1];
         pictureBox1.Image = Image.FromFile(fileContent.FileName);
         OpenFileImage(fileContent.FileName);
     }
     catch (System.Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }
Example #21
0
        public MainWindow()
            : base("Change Folder", 1, (Console.WindowWidth / 2) - ((Console.WindowWidth - 4) / 2), Console.WindowWidth - 4, Console.WindowHeight - 2, null)
        {
            var folderSelect = new FileSelect(3, 3, Console.WindowWidth - 6, Height - 6, Directory.GetCurrentDirectory(), "folderSelect", this, true);

            folderSelect.SelectFile = delegate() { Path = folderSelect.CurrentPath; changePath = true; ExitWindow(); };

            var selectBtn = new Button(PostionX + Height - 2, 3, "Select", "selectBtn", this);

            selectBtn.Action = delegate() { Path = folderSelect.CurrentPath; changePath = true; ExitWindow(); };

            var cancelBtn = new Button(PostionX + Height - 2, 12, "Cancel", "cancelBtn", this);

            cancelBtn.Action = delegate() { changePath = false; ExitWindow(); };

            Inputs.Add(folderSelect);
            Inputs.Add(selectBtn);
            Inputs.Add(cancelBtn);

            CurrentlySelected = selectBtn;

            Draw();
            MainLoop();
        }
Example #22
0
 private void Btn_sameSavePath_Click(object sender, EventArgs e)
 {
     this.sameOutputDirPath      = FileSelect.GetDirectorPath();
     this.lbx_sameOutputDir.Text = this.sameOutputDirPath;
 }
Example #23
0
        private void Menu_addFile_Click(object sender, EventArgs e)
        {
            FileContent fileContent = FileSelect.GetSelectFileContent("(*.*)|*.*", "选择文件");

            sourchFilePath = fileContent.FileName;
        }
    void createFileSelects()
    {
        clearFileSelects();

        string           path       = Application.persistentDataPath + "/quickData.sav";
        bool             fileExists = false;
        List <QuickData> quickDatas = new List <QuickData>();

#if !UNITY_WEBPLAYER
        fileExists = File.Exists(path);
#endif

        if (fileExists)
        {
            byte[]     bArr    = File.ReadAllBytes(path);
            string     content = Utilities.bytesToString(bArr);
            Properties prop    = new Properties(content);
            for (int i = 0; i < NUM_SAVE_FILES; i++)
            {
                QuickData qd = new QuickData();
                qd.create(
                    prop.getString("fn" + i, "-1"),
                    ((Vars.Difficulty)prop.getInt("diff" + i, 0)),
                    prop.getFloat("t" + i, -1),
                    prop.getFloat("info" + i, -1),
                    prop.getFloat("phys" + i, -1));
                quickDatas.Add(qd);
            }
        }
        else
        {
            for (int i = 0; i < NUM_SAVE_FILES; i++)
            {
                quickDatas.Add(new QuickData());
            }
        }



        for (int i = 0; i < quickDatas.Count; i++)
        {
            QuickData  qd   = quickDatas[i];
            GameObject fsGO = GameObject.Instantiate(fileSelectGameObject);
            fsGO.transform.SetParent(transform, false);
            FileSelect fs = fsGO.GetComponent <FileSelect>();
            fs.index    = i;
            fs.selected = false;
            fs.startPosition.Set(centerPos.x, centerPos.y - verticalSpacing * fs.index - fadeDistance);
            fs.GetComponent <RectTransform>().localPosition = fs.startPosition;
            fs.endPosition.Set(centerPos.x, centerPos.y - verticalSpacing * fs.index);
            fs.timeOffset = timeDiff * fs.index;
            if (qd.created)
            {
                fs.newFile = false;
                fs.setFileName(fs.index);
                fs.setPlayTime(qd.time);
                fs.setDifficulty(difficultyProperties.getString(((int)qd.difficulty) + "name"));
                fs.setInfoComplete(qd.infoPercent);
                fs.setPhysComplete(qd.physPercent);
            }
            else
            {
                fs.newFile = true;
            }
            fileSelects.Add(fs);
        }
    }
        /// <summary>
        /// 将DataTable数据导入到excel中
        /// </summary>
        /// <param name="data">要导入的数据</param>
        /// <param name="isColumnWritten">DataTable的列名是否要导入</param>
        /// <param name="sheetName">要导入的excel的sheet的名称</param>
        /// <returns>导入数据行数(包含列名那一行)</returns>
        public static int GridViewToExcel(RadGridView radGridView, string sheetName, bool isColumnWritten, bool IsIncludeFirstCol)
        {
            int    i     = 0;
            int    j     = 0;
            int    count = 0;
            ISheet sheet = null;

            var data = RadGridViewHelper.ConvertGridViewToDataTable(radGridView, IsIncludeFirstCol);

            if (null == data || data.Rows.Count <= 0)
            {
                return(0);
            }
            var fileName = FileSelect.SaveAs("Microsoft Excel files(*.xls)|*.xls", "C:\\");

            if (fileName == "")
            {
                return(0);
            }
            FileStream fs = new FileStream(fileName, FileMode.OpenOrCreate, FileAccess.ReadWrite);

            if (fileName.IndexOf(".xlsx") > 0) // 2007版本
            {
                workbook = new XSSFWorkbook();
            }
            else if (fileName.IndexOf(".xls") > 0) // 2003版本
            {
                workbook = new HSSFWorkbook();
            }

            try
            {
                if (workbook != null)
                {
                    sheet = workbook.CreateSheet(sheetName);
                }
                else
                {
                    return(-1);
                }

                if (isColumnWritten == true) //写入DataTable的列名
                {
                    IRow row = sheet.CreateRow(0);
                    for (j = 0; j < data.Columns.Count; ++j)
                    {
                        row.CreateCell(j).SetCellValue(data.Columns[j].ColumnName);
                    }
                    count = 1;
                }
                else
                {
                    count = 0;
                }

                for (i = 0; i < data.Rows.Count; ++i)
                {
                    IRow row = sheet.CreateRow(count);
                    for (j = 0; j < data.Columns.Count; ++j)
                    {
                        row.CreateCell(j).SetCellValue(data.Rows[i][j].ToString());
                    }
                    ++count;
                }
                workbook.Write(fs); //写入到excel
                RadMessageBox.SetThemeName(radGridView.ThemeName);
                DialogResult dr = RadMessageBox.Show("The data in the grid was exported successfully. Do you want to open the file?",
                                                     "Export to Excel", MessageBoxButtons.YesNo, RadMessageIcon.Question);
                if (dr == DialogResult.Yes)
                {
                    try
                    {
                        System.Diagnostics.Process.Start(fileName);
                    }
                    catch (Exception ex)
                    {
                        string message = String.Format("The file cannot be opened on your system.\nError message: {0}", ex.Message);
                        RadMessageBox.Show(message, "Open File", MessageBoxButtons.OK, RadMessageIcon.Error);
                    }
                }
                if (fs != null)
                {
                    fs.Close();
                }
                return(count);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Exception: " + ex.Message);
                return(-1);
            }
        }
Example #26
0
        public static int DataTableToExcel(DataTable data, string sheetName, bool isColumnWritten, string fileName, bool IsShowExcel)
        {
            FileStream fs       = null;
            int        i        = 0;
            int        j        = 0;
            int        count    = 0;
            ISheet     sheet    = null;
            IWorkbook  workbook = null;

            if (null == data)
            {
                return(0);
            }
            if (data.Rows.Count <= 0)
            {
                return(0);
            }
            if (fileName == "")
            {
                fileName = FileSelect.SaveAs("Microsoft Excel files(*.xls)|*.xls", "C:\\");
            }
            if (fileName == "")
            {
                return(0);
            }

            try
            {
                fs = new FileStream(fileName, FileMode.Create);
            }
            catch (Exception ex)
            {
                MessageBox.Show("创建文件失败!请检查文件是否被占用,关闭已打开文件后重试!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return(0);
            }

            try
            {
                if (Path.GetExtension(fileName) == ".xlsx") // 2007版本
                {
                    workbook = new XSSFWorkbook();
                }
                else if (Path.GetExtension(fileName) == ".xls") // 2003版本
                {
                    fs.Position = 0;
                    workbook    = new HSSFWorkbook();
                }
            }
            catch (Exception ex)
            {
                var exMessage = "";
                if (ex.Message == "" && ex.InnerException != null)
                {
                    exMessage = ex.InnerException.Message;
                }
                MessageBox.Show(exMessage, "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return(0);
            }

            if (workbook != null)
            {
                if (sheetName.Trim() == "")
                {
                    sheetName = "Sheet1";
                }
                sheet = workbook.CreateSheet(sheetName);
            }
            else
            {
                MessageBox.Show("创建Sheet失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return(-1);
            }

            if (isColumnWritten) //写入DataTable的列名
            {
                IRow row = sheet.CreateRow(0);
                for (j = 0; j < data.Columns.Count; ++j)
                {
                    row.CreateCell(j).SetCellValue(data.Columns[j].ColumnName);
                }
                count = 1;
            }
            else
            {
                count = 0;
            }
            try
            {
                for (i = 0; i < data.Rows.Count; ++i)
                {
                    IRow row = sheet.CreateRow(count);
                    for (j = 0; j < data.Columns.Count; ++j)
                    {
                        row.CreateCell(j).SetCellValue(data.Rows[i][j].ToString());
                    }
                    ++count;
                }
                workbook.Write(fs); //写入到excel
                if (IsShowExcel)
                {
                    DialogResult dr = MessageBox.Show("The data in the grid was exported successfully. Do you want to open the file?",
                                                      "Export to Excel", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                    if (dr == DialogResult.Yes)
                    {
                        if (File.Exists(fileName))
                        {
                            System.Diagnostics.Process.Start(fileName);
                        }
                    }
                }
                CloseStream(fs);
                return(count);
            }
            catch (Exception ex)
            {
                CloseStream(fs);
                MessageBox.Show(ex.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return(-1);
            }
        }
Example #27
0
 private void btnBrowse_Click(object sender, EventArgs e)
 {
     FileSelect.ShowDialog();
 }
Example #28
0
 private void Btn_dragSetPath_Click(object sender, EventArgs e)
 {
     this.dragOutpuDirpath      = FileSelect.GetDirectorPath();
     this.lbx_dragSavePath.Text = this.dragOutpuDirpath;
 }
Example #29
0
 private void Btn_sameFile1_Click(object sender, EventArgs e)
 {
     this.sameSelectFile1Path = FileSelect.GetDirectorPath();
     this.lbx_sameFile1.Text  = this.sameSelectFile1Path;
 }
Example #30
0
 private void Btn_selectImg_Click(object sender, EventArgs e)
 {
     this.currentSelectImagePath = FileSelect.GetDirectorPath();
     this.lbx_selectImg.Text     = this.currentSelectImagePath;
 }
Example #31
0
 private void Btn_exportPathImg_Click(object sender, EventArgs e)
 {
     this.exportImageDirPath     = FileSelect.GetDirectorPath();
     this.lbx_exportPathImg.Text = this.exportImageDirPath;
 }