Пример #1
0
        public SaveFileResponse SaveFile(string title, byte[] content, string filter = "All files|*.*", string defaultFile = "")
        {
            var openFileDialog = new System.Windows.Forms.SaveFileDialog();

            openFileDialog.Filter   = filter;
            openFileDialog.Title    = title;
            openFileDialog.FileName = defaultFile;



            if (openFileDialog.ShowDialog() == System.Windows.Forms.DialogResult.Cancel)
            {
                return(new SaveFileResponse());
            }

            using (var stream = openFileDialog.OpenFile())
            {
                foreach (var b in content)
                {
                    stream.WriteByte(b);
                }
            }

            return(new SaveFileResponse(openFileDialog.FileName));
        }
Пример #2
0
        public void SaveSettingsProfile()
        {
            var dialog = new System.Windows.Forms.SaveFileDialog()
            {
                DefaultExt       = "xml",
                FileName         = "3DVRegistryProfile",
                Filter           = "xml files (*.xml)|*.xml",
                InitialDirectory =
                    Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments),
                                 "config.xml"),
            };

            if (dialog.ShowDialog() != DialogBoxResult.OK)
            {
                return;
            }
            try
            {
                var xml = new XmlSerializer(typeof(List <SettingsProfileEntry>));
                using (Stream output = dialog.OpenFile())
                    xml.Serialize(output, new SettingsProfile(_viewModelRegistryKeys.Values).KeySettings);
            }
            catch (Exception)
            {
                MessageBox.Show("Your profile could not be saved.",
                                "Profile Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
Пример #3
0
        private void toCSV(string[][] table)
        {
            var sfd = new System.Windows.Forms.SaveFileDialog();

            if (sfd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                var f = sfd.OpenFile();
                for (int r = 0; r < table.Length; r++)
                {
                    var sb = new StringBuilder();
                    for (int c = 0; c < table[r].Length; c++)
                    {
                        string cell = table[r][c];
                        sb.Append("\"");
                        sb.Append(cell);
                        sb.Append("\"");
                        if (c < table[r].Length - 1)
                        {
                            sb.Append(",");
                        }
                        else
                        {
                            sb.Append("\n");
                        }
                    }
                    var b = Encoding.ASCII.GetBytes(sb.ToString());
                    f.Write(b, 0, b.Length);
                }

                f.Close();
            }
        }
 private void SaveAsSingleFile(object sender, RoutedEventArgs e)
 {
     System.Windows.Forms.SaveFileDialog dialog = new System.Windows.Forms.SaveFileDialog {
         OverwritePrompt = true
     };
     if (!string.IsNullOrWhiteSpace(SqlSaveDirectory))
     {
         dialog.InitialDirectory = SqlSaveDirectory;
     }
     else
     {
         dialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
     }
     dialog.DefaultExt = ".sql";
     dialog.Filter     = "SQL Script (*.sql)|*.sql|All Files (*.*)|*.*";
     if (dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
     {
         StatusText = string.Format("Saving {0}...", dialog.FileName);
         StreamWriter sw = new StreamWriter(dialog.OpenFile());
         foreach (string sql in GeneratedSqlScript.Values)
         {
             sw.Write(sql);
         }
         sw.Close();
         sw.Dispose();
         FileInfo fileInfo = new FileInfo(dialog.FileName);
         SqlSaveDirectory = fileInfo.DirectoryName;
         SettingsManager.SetString("SqlSaveDirectory", SqlSaveDirectory);
         StatusText = string.Format("Saved {0}", dialog.FileName);
     }
 }
Пример #5
0
        public async Task exportGIF(GameState state)
        {
            //start generating the gif while they file dialog is open
            Transition.StartTransition(state.screen, videoFrames.Length, "Saving Gif");
            var task = Task.Run(genGIF);

            System.Windows.Forms.SaveFileDialog saveFileDialog = new System.Windows.Forms.SaveFileDialog();
            saveFileDialog.Filter           = "gifs (*.gif)|*.gif";
            saveFileDialog.FilterIndex      = 0;
            saveFileDialog.RestoreDirectory = false;
            Stream fileStream;

            if (saveFileDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                if ((fileStream = saveFileDialog.OpenFile()) != null)
                {
                    state.screen = Screen.GIF_EXPORTING;
                    var gifStream = await task;
                    Transition.SetProgress(videoFrames.Length / 2);
                    gifStream.Position = 0;
                    gifStream.CopyTo(fileStream);
                    fileStream.Close();
                    gifStream.Close();
                    Transition.SetProgress(videoFrames.Length);
                }
            }
        }
        void link_Click(object sender, RoutedEventArgs e)
        {
            Hyperlink link = sender as Hyperlink;
            RuleFile  file = link.DataContext as RuleFile;

            if (file.FILEPATH == null || file.FILEPATH.Length == 0)
            {
                MessageBox.Show("没找到附件内容");
                return;
            }
            System.Windows.Forms.SaveFileDialog dialog = new System.Windows.Forms.SaveFileDialog();
            dialog.FileName   = file.FILENAME;
            dialog.DefaultExt = file.FILETYPE;
            System.Windows.Forms.DialogResult dialogResult = dialog.ShowDialog();
            if (dialogResult == System.Windows.Forms.DialogResult.OK || dialogResult == System.Windows.Forms.DialogResult.Yes)
            {
                byte[] result = file.FILEPATH;
                try
                {
                    using (Stream stream = dialog.OpenFile())
                    {
                        stream.Write(result, 0, result.Length);
                        stream.Close();
                        MessageBox.Show("导出成功");
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message.ToString());
                }
            }
        }
Пример #7
0
        private void buCreate_Click(object sender, RoutedEventArgs e)
        {
            string result = "";

            switch (cbReportType.SelectedIndex)
            {
            case 0: if (lbTurns.SelectedItem != null)
                {
                    result = CreateReport0();
                }
                else
                {
                    MessageBox.Show("Выберите направление");
                } break;

            case 1: try { int.Parse(tbWindowId.Text); result = CreateReport1(); } catch (Exception ex) { MessageBox.Show(ex.Message); } break;
            }
            if (result != "")
            {
                System.Windows.Forms.SaveFileDialog sfd = new System.Windows.Forms.SaveFileDialog();
                sfd.InitialDirectory = InitialDirectory;
                sfd.Filter           = "Report for Excel|*.xml";
                if (sfd.ShowDialog() == System.Windows.Forms.DialogResult.OK && sfd.FileName != "")
                {
                    System.IO.StreamWriter w = new System.IO.StreamWriter(sfd.OpenFile(), Encoding.UTF8);
                    w.Write(result);
                    w.Close();
                    PropertiesFile props = new PropertiesFile(AppDomain.CurrentDomain.BaseDirectory + "properties.properties");
                    props.set("InitialDirectory", System.IO.Path.GetFullPath(sfd.FileName));
                    props.Save();
                }
            }
        }
Пример #8
0
        private void Export_Click(object sender, RoutedEventArgs e)
        {
            var options = new ExcelExportingOptions();

            options.ExcelVersion = ExcelVersion.Excel2013;
            var excelEngine = datagrid.ExportToExcel(datagrid.View, options);
            var workbook    = excelEngine.Excel.Workbooks[0];

            System.Windows.Forms.SaveFileDialog sfd = new System.Windows.Forms.SaveFileDialog
            {
                FilterIndex = 2,
                Filter      = "Excel 97 to 2003 Files(*.xls)|*.xls|Excel 2007 to 2010 Files(*.xlsx)|*.xlsx|Excel 2013 File(*.xlsx)|*.xlsx"
            };
            sfd.FileName = "Annuaire";
            if (sfd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                using (Stream stream = sfd.OpenFile())
                {
                    if (sfd.FilterIndex == 1)
                    {
                        workbook.Version = ExcelVersion.Excel97to2003;
                    }
                    else if (sfd.FilterIndex == 2)
                    {
                        workbook.Version = ExcelVersion.Excel2010;
                    }
                    else
                    {
                        workbook.Version = ExcelVersion.Excel2013;
                    }
                    workbook.SaveAs(stream);
                }
            }
        }
        protected void ExportaExcel()
        {
            string extension = "xls";

            System.Windows.Forms.SaveFileDialog saveFileDialog1 = new System.Windows.Forms.SaveFileDialog()
            {
                DefaultExt  = extension,
                Filter      = String.Format("{1} files (*.{0})|*.{0}|Excell Files (*.xls)|*.xls", extension, "Excel"),
                FilterIndex = 2,
                Title       = "Selecione o local onde deseja exportar."
            };


            var dialogRes = saveFileDialog1.ShowDialog();

            if (dialogRes == System.Windows.Forms.DialogResult.OK)
            {
                using (Stream stream = saveFileDialog1.OpenFile())
                {
                    Telerik.Windows.Controls.GridViewExportOptions exp = new Telerik.Windows.Controls.GridViewExportOptions();
                    exp.ShowColumnFooters = true;
                    exp.ShowColumnHeaders = true;
                    exp.ShowGroupFooters  = true;

                    this.Export(stream, exp);
                }
            }
        }
        private void TsmiSaveIconAs_Click(object sender, EventArgs e)
        {
            Bitmap ico = GetFirstClockIcon();

            if (ico != null)
            {
                System.Windows.Forms.SaveFileDialog fd = Utils.GetImageSaveChooser();

                // TODO: pass MainWindow somehow to ShowDialog:
                if (fd.ShowDialog(/*MainWindow*/) == System.Windows.Forms.DialogResult.OK &&
                    fd.FileName != "")
                {
                    var fs = (FileStream)fd.OpenFile();

                    // TODO: use a method for this switch-case, method inside a new subclass of SaveFileDialog
                    // corresponding to Utils.GetImageSaveChooser.
                    switch (fd.FilterIndex)
                    {
                    case 1:
                        ico.Save(fs, ImageFormat.Jpeg);
                        break;

                    case 2:
                        ico.Save(fs, ImageFormat.Bmp);
                        break;

                    case 3:
                        ico.Save(fs, ImageFormat.Gif);
                        break;

                    case 4:
                        ico.Save(fs, ImageFormat.Emf);
                        break;

                    case 5:
                        // Made transparent on load of DataFile:
                        //ico.MakeTransparent(Color.Empty);
                        using (Icon ico2 = Utils.IconFromImage(ico))
                        {
                            ico2.Save(fs);
                        }
                        break;

                    case 6:
                        ico.Save(fs, ImageFormat.Png);
                        break;

                    case 7:
                        ico.Save(fs, ImageFormat.Tiff);
                        break;
                    }

                    fs.Close();
                }
            }
        }
        protected void ExportaPDF()
        {
            var document = CreateDocument(this, null);

            if (document != null)
            {
                document.LayoutMode = DocumentLayoutMode.Paged;
                document.Measure(RadDocument.MAX_DOCUMENT_SIZE);
                document.Arrange(new RectangleF(PointF.Empty, document.DesiredSize));

                IDocumentFormatProvider provider = new PdfFormatProvider();

                var dialog = new System.Windows.Forms.SaveFileDialog();
                dialog.DefaultExt = "*.pdf";
                dialog.Filter     = "Adobe PDF Document (*.pdf)|*.pdf";

                var dialogRes = dialog.ShowDialog();

                if (dialogRes == System.Windows.Forms.DialogResult.OK)
                {
                    using (var output = dialog.OpenFile())
                    {
                        provider.Export(document, output);
                    }
                }
            }


            //string extension = "pdf";

            //System.Windows.Forms.SaveFileDialog saveFileDialog1 = new System.Windows.Forms.SaveFileDialog()
            //{
            //    DefaultExt = extension,
            //    Filter = String.Format("{1} files (*.{0})|*.{0}|Pdf files (*.pdf)|*.pdf", extension, "Pdf"),
            //    FilterIndex = 2,
            //    Title = "Selecione o local onde deseja exportar."
            //};



            //if (saveFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            //{
            //    using (Stream stream = saveFileDialog1.OpenFile())
            //    {
            //        Telerik.Windows.Controls.GridViewExportOptions exp = new Telerik.Windows.Controls.GridViewExportOptions();
            //        exp.ShowColumnFooters = true;
            //        exp.ShowColumnHeaders = true;
            //        exp.ShowGroupFooters = true;

            //        this.Export(stream, exp);
            //    }
            //}
        }
Пример #12
0
        /// <summary>
        /// Encodes data into .level file
        /// </summary>
        public static void SaveFile(MouseState evt, UIElement elm)
        {
            // encode spawnPoint
            string newFile = $"{level.spawnPoint}\n";

            // encode events
            newFile += $"events:\n";
            for (int i = 0; i < level.EventTriggers.Count; i++)
            {
                newFile += $"{level.EventTriggers[i]}\n";
            }

            // encode enemies
            newFile += $"enemies:\n";
            for (int i = 0; i < level.Enemies.Count; i++)
            {
                newFile += $"{level.Enemies[i]}\n";
            }

            // encode texturemap
            newFile += $"map:\n{Path.GetFileName(textureMap.filePath)}\n";

            // encode tilemap
            for (int y = 0; y < level.height; y++)
            {
                for (int x = 0; x < level.width; x++)
                {
                    newFile += level.tiles[x, y].TileID;
                }
                newFile += "\n";
            }

            Stream fileStream;

            // Configure save file dialog
            System.Windows.Forms.SaveFileDialog saveFileDialog1 = new System.Windows.Forms.SaveFileDialog
            {
                Filter = "level files (*.level)|*.level",
                RestoreDirectory = true
            };

            // Open save file dialog
            if (saveFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                if ((fileStream = saveFileDialog1.OpenFile()) != null)
                {
                    // save file
                    using var sr = new StreamWriter(fileStream);
                    sr.WriteLine(newFile.Trim());
                }
            }
        }
Пример #13
0
        private void mnuFileSave_Click(object sender, EventArgs e)
        {
            this.gameTimer.IsEnabled = false;
            var folderBrowserDialog = new System.Windows.Forms.SaveFileDialog();

            System.Windows.Forms.DialogResult res = folderBrowserDialog.ShowDialog();
            if (res == System.Windows.Forms.DialogResult.OK)
            {
                Boolean create = true;
                string  txt    = "";
                Stream  stream;
                txt += this.playerName + "\n";
                txt += this.classic + "\n";
                txt += this.score.Content + "\n";
                txt += this.totalCompletedRows + "\n";
                if (folderBrowserDialog.CheckFileExists)
                {
                    MessageBoxResult result = MessageBox.Show("The save file for " + folderBrowserDialog.FileName + ".txt already exists. \nWould you like to Overwrite the save file with this one?", "Overwrite", MessageBoxButton.YesNo);
                    if (result == MessageBoxResult.No)
                    {
                        create = false;
                    }
                }
                try
                {
                    if (create)
                    {
                        for (int x = 0; x < 18; x++)
                        {
                            for (int y = 0; y < 10; y++)
                            {
                                txt += gameBoard[x, y] + "\n";
                            }
                        }
                        stream = folderBrowserDialog.OpenFile();
                        using (StreamWriter sw = new StreamWriter(stream))
                        {
                            sw.WriteLine(txt);
                        }
                    }
                }
                catch (Exception err)
                {
                    MessageBox.Show("Unable to Save file.");
                }
            }
            this.gameTimer.IsEnabled = true;
        }
Пример #14
0
        private void ExportAction_Execute(object sender, SimpleActionExecuteEventArgs e)
        {
            var dialog = new System.Windows.Forms.SaveFileDialog()
            {
                DefaultExt = ".xml",
                Filter     = fileFilter
            };

            if (dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                using (var file = dialog.OpenFile())
                {
                    InvoiceXmlIxporter.Export(file, View.ObjectSpace, (Invoice)e.CurrentObject);
                }
            }
        }
Пример #15
0
        private void mnuSaveXaml_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                var dlg = new System.Windows.Forms.SaveFileDialog();
                if (dlg.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {
                    IO.Stream fstream = dlg.OpenFile();

                    markup.XamlWriter.Save(mainCanvas, fstream);
                }
            }
            catch (Exception ex)
            {
                log.Log(mko.Log.RC.CreateError(ex.Message));
            }
        }
Пример #16
0
        public void SavePlayer()
        {
            System.Windows.Forms.SaveFileDialog dlg = new System.Windows.Forms.SaveFileDialog();
            Stream myStream;

            dlg.Filter = "He Dies At The End (.hdate) | *.hdate";


            if (dlg.ShowDialog() == System.Windows.Forms.DialogResult.OK == true)
            {
                if ((myStream = dlg.OpenFile()) != null)
                {
                    IFormatter formatter = new BinaryFormatter();
                    formatter.Serialize(myStream, p1);
                    myStream.Close();
                }
            }
        }
Пример #17
0
        private void save_Click(object sender, RoutedEventArgs e)
        {
            // Save the results of the last test
            System.Windows.Forms.SaveFileDialog dialog = new System.Windows.Forms.SaveFileDialog();

            dialog.Filter           = "txt files (*.txt)|*.txt|All files (*.*)|*.*";
            dialog.FilterIndex      = 0;
            dialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);

            if (dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                StreamWriter sw = new StreamWriter(dialog.OpenFile());
                foreach (var r in state.Reports)
                {
                    sw.WriteLine(r);
                }
                sw.Close();
            }
        }
Пример #18
0
 private void BtnSave_Click(object sender, RoutedEventArgs e)
 {
     using (System.Windows.Forms.SaveFileDialog sfd = new System.Windows.Forms.SaveFileDialog
     {
         FileName = "pipeline",
         Filter = Properties.strings.FileFilter,
         InitialDirectory =
             Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments),
         DefaultExt = "json",
     })
     {
         if (sfd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
         {
             using Stream fileStream = sfd.OpenFile();
             using var streamWriter  = new StreamWriter(fileStream);
             streamWriter.Write(JsonConvert.SerializeObject(this.Pipeline.GetDefinition(), Formatting.Indented));
         }
     }
 }
Пример #19
0
        private void SaveAs(object sender, RoutedEventArgs e)
        {
            Stream myStream;
            var    sfd = new System.Windows.Forms.SaveFileDialog();

            sfd.FileName         = Title;
            sfd.DefaultExt       = "rtf";
            sfd.Filter           = "RTF 文件 (*.rtf))|*.rtf";
            sfd.RestoreDirectory = false;
            if (sfd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                if ((myStream = sfd.OpenFile()) != null)
                {
                    TextRange documentTextRange = new TextRange(RichTextBox.Document.ContentStart, RichTextBox.Document.ContentEnd);
                    documentTextRange.Save(myStream, DataFormats.Rtf);
                    myStream.Close();
                }
            }
        }
Пример #20
0
        private void Save_Img(object sender, RoutedEventArgs e)
        {
            System.Windows.Forms.SaveFileDialog saveDialog = new System.Windows.Forms.SaveFileDialog();
            if (animated)
            {
                saveDialog.Filter = "Image (*.gif)|*.gif|All files (*.*)|*.*";
            }
            else
            {
                saveDialog.Filter = "Image (*.bmp)|*.bmp|All files (*.*)|*.*";
            }

            saveDialog.FilterIndex      = 1;
            saveDialog.RestoreDirectory = true;

            if (saveDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                memoryStream.WriteTo(saveDialog.OpenFile());
            }
        }
Пример #21
0
        private async void Button_Click(object sender, RoutedEventArgs e)
        {
            System.Windows.Forms.SaveFileDialog save_dialog = new System.Windows.Forms.SaveFileDialog();
            save_dialog.Filter           = String.Format("{0} file (*{0})|*{0}|All files (*.*)|*.*", System.IO.Path.GetExtension(_fileAdress));
            save_dialog.FilterIndex      = 1;
            save_dialog.RestoreDirectory = true;
            if (save_dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                RaiseDownloadStartedEvent();
                IsDownloading = true;
                await Task.Run(() =>
                {
                    using (var stream = save_dialog.OpenFile())
                    {
                        byte[] buffer;
                        try
                        {
                            while ((buffer = _server.DownloadData(_fileAdress, 5000)) != null)
                            {
                                stream.Write(buffer, 0, buffer.Length);
                            }
                        }
                        catch (FaultException <ExceptionType> fault)
                        {
                            if (fault.Detail == ExceptionType.ErrorDuringDataTransfer)
                            {
                                System.Windows.Forms.MessageBox.Show("Error accured during downloading. Please, try again");
                            }
                            if (fault.Detail == ExceptionType.FileNotFound)
                            {
                                System.Windows.Forms.MessageBox.Show("File Not Found on server. Incorrect data link");
                            }
                        }
                    }
                });

                RaiseDownloadEndedEvent();
                IsDownloading = false;
            }
        }
        private void ExportCanvas(object sender, EventArgs e)
        {
            // Displays a SaveFileDialog so the user can save the Image
            // assigned to Button2.
            System.Windows.Forms.SaveFileDialog saveFileDialog1 = new System.Windows.Forms.SaveFileDialog();
            saveFileDialog1.Filter = "PNG Image|*.png";
            saveFileDialog1.Title  = "Save your canvas";
            saveFileDialog1.ShowDialog();

            // If the file name is not an empty string open it for saving.
            if (saveFileDialog1.FileName != "")
            {
                // Saves the Image via a FileStream created by the OpenFile method.
                System.IO.FileStream fs =
                    (System.IO.FileStream)saveFileDialog1.OpenFile();

                surfaceDessin.GetCanvas().Save(fs,
                                               System.Drawing.Imaging.ImageFormat.Png);

                fs.Close();
            }
        }
        private void btnExport_Click(object sender, RoutedEventArgs e)
        {
            System.Windows.Forms.SaveFileDialog saveFileDialog = new System.Windows.Forms.SaveFileDialog();
            string name = (string)((TabItem)tabAnalyzer.SelectedItem).Header;

            saveFileDialog.FileName = name + ".md";
            System.Windows.Forms.DialogResult result = saveFileDialog.ShowDialog();
            if (result == System.Windows.Forms.DialogResult.OK)
            {
                using (System.IO.FileStream fs = (System.IO.FileStream)saveFileDialog.OpenFile())
                    using (System.IO.StreamWriter sw = new StreamWriter(fs))
                    {
                        switch (tabAnalyzer.SelectedIndex)
                        {
                        case 0:
                            sw.Write(ExportCampaign(isAdventure: false));
                            break;

                        case 1:
                            sw.Write(ExportCampaign(isAdventure: true));
                            break;

                        case 3:
                            sw.Write(ExportMissingItems());
                            break;

                        case 4:
                            sw.Write(ExportCredits());
                            break;

                        default:
                            throw new Exception("Tab does not exist");
                        }
                    }
            }
        }
Пример #24
0
        protected override void Update(GameTime gameTime)
        {
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
            {
                Exit();
            }

            x += -1 * Utility.UserInput.getXAxis();
            y += -1 * Utility.UserInput.getYAxis();

            transform = Matrix.CreateTranslation(x, y, 0);

            var MouseX = Mouse.GetState().X;
            var MouseY = Mouse.GetState().Y;

            var mousePosition = new Vector2(MouseX, MouseY);

            cursor.Update(Mouse.GetState().Position.ToVector2());


            Console.WriteLine(paused);


            if (delay < gameTime.TotalGameTime.TotalSeconds)
            {
                if (Keyboard.GetState().IsKeyDown(Keys.Back))
                {
                    if (paused)
                    {
                        paused = false;
                    }
                    else
                    {
                        paused = true;
                    }

                    delay = gameTime.TotalGameTime.TotalSeconds + .25;
                }

                Console.WriteLine(paused);

                if (!paused)
                {
                    if (Keyboard.GetState().IsKeyDown(Keys.LeftShift))
                    {
                        expansionSpeed = 5;
                    }
                    if (Keyboard.GetState().IsKeyUp(Keys.LeftShift))
                    {
                        expansionSpeed = 1;
                    }
                    if (Keyboard.GetState().IsKeyDown(Keys.W))
                    {
                        var width   = cursor._Texture.Width + (1 * expansionSpeed);
                        var height  = cursor._Texture.Height;
                        var texture = TextureGen.CreateTexture(width, height, cursor._Color);
                        cursor.Update(texture);
                    }
                    if (Keyboard.GetState().IsKeyDown(Keys.Q))
                    {
                        Console.WriteLine(cursor._Texture.Width);
                        if (cursor._Texture.Width > 5)
                        {
                            var width   = cursor._Texture.Width - (1 * expansionSpeed);
                            var height  = cursor._Texture.Height;
                            var texture = TextureGen.CreateTexture(width, height, cursor._Color);
                            cursor.Update(texture);
                        }
                    }
                    if (Keyboard.GetState().IsKeyDown(Keys.P))
                    {
                        var width   = cursor._Texture.Width;
                        var height  = cursor._Texture.Height + (1 * expansionSpeed);
                        var texture = TextureGen.CreateTexture(width, height, cursor._Color);
                        cursor.Update(texture);
                    }
                    if (Keyboard.GetState().IsKeyDown(Keys.O))
                    {
                        if (cursor._Texture.Height > 5)
                        {
                            var width   = cursor._Texture.Width;
                            var height  = cursor._Texture.Height - (1 * expansionSpeed);
                            var texture = TextureGen.CreateTexture(width, height, cursor._Color);
                            cursor.Update(texture);
                        }
                    }


                    if (Mouse.GetState().LeftButton == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Enter))
                    {
                        level.AddTile(cursor);
                        delay = gameTime.TotalGameTime.TotalSeconds + .25;
                    }

                    if (Mouse.GetState().RightButton == ButtonState.Pressed)
                    {
                        List <Tile> Delete = new List <Tile>();
                        foreach (var block in level.GetList())
                        {
                            if (cursor._Rectangle.Intersects(block._Rectangle))
                            {
                                Delete.Add(block);
                            }
                        }
                        foreach (var block in Delete)
                        {
                            level.Delete(block);
                        }
                        Delete.Clear();

                        delay = gameTime.TotalGameTime.TotalSeconds + .25;
                    }

                    if (Keyboard.GetState().IsKeyDown(Keys.T))
                    {
                        if (tCount <= 0)
                        {
                            tCount = Tiles.Length - 1;
                        }
                        else
                        {
                            tCount--;
                        }

                        cursor = Tiles[tCount];

                        delay = gameTime.TotalGameTime.TotalSeconds + .25;
                    }

                    if (Keyboard.GetState().IsKeyDown(Keys.L))
                    {
                        System.Windows.Forms.OpenFileDialog oDialogue = new System.Windows.Forms.OpenFileDialog();

                        oDialogue.Filter           = "Data Files (*.dat) | *.dat ";
                        oDialogue.RestoreDirectory = true;

                        if (oDialogue.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                        {
                            var stream = oDialogue.OpenFile();
                            var data   = SerializerUtility.DataManagementXML.Load(stream);

                            if (data.Count > 0)
                            {
                                level = LevelGenerator.GenerateLevel(data[0], GraphicsDevice);
                            }
                        }
                    }

                    if (Keyboard.GetState().IsKeyDown(Keys.S))
                    {
                        System.Windows.Forms.SaveFileDialog sDialogue = new System.Windows.Forms.SaveFileDialog();

                        sDialogue.Filter           = "Data Files (*.dat) | *.dat ";
                        sDialogue.RestoreDirectory = true;

                        if (sDialogue.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                        {
                            var fileStream = sDialogue.OpenFile();
                            SerializerUtility.DataManagementXML.Save(fileStream, level.GenerateBlueprint());
                        }
                    }

                    if (Keyboard.GetState().IsKeyDown(Keys.Delete))
                    {
                        level.Delete();
                    }
                }
            }


            base.Update(gameTime);
        }
Пример #25
0
        /// <summary>
        /// 将DataTable中数据写入到CSV文件中
        /// </summary>
        /// <param name="dt">提供保存数据的DataTable</param>
        /// <param name="fileName">CSV的文件路径</param>
        public static void SaveCSV(DataTable dt, string fileName)
        {
            System.Windows.Forms.SaveFileDialog saveFileDialog = new System.Windows.Forms.SaveFileDialog();
            saveFileDialog.Filter           = "Csv文件(*.csv)|*.csv";
            saveFileDialog.FilterIndex      = 0;
            saveFileDialog.RestoreDirectory = true;
            saveFileDialog.CreatePrompt     = true;
            saveFileDialog.Title            = "导出Csv文件到";
            saveFileDialog.FileName         = fileName;

            System.Windows.Forms.DialogResult result = saveFileDialog.ShowDialog();
            if (result == System.Windows.Forms.DialogResult.Cancel)
            {
                //Program.logger.LogInfo("文件\"{0}\"取消保存", fileName);
                return;
            }
            Stream myStream;

            myStream = saveFileDialog.OpenFile();
            StreamWriter sw   = new StreamWriter(myStream, System.Text.Encoding.UTF8);
            string       data = "";

            try
            {
                DataView dataView = dt.DefaultView;
                dataView.Sort = string.Format("{0} asc,{1} asc", CommonUtils.heads[0], CommonUtils.heads[1]);
                dt            = dataView.ToTable();
                //dt.DefaultView.Sort = string.Format("{0} asc,{1} asc", CommonUtils.heads[0], CommonUtils.heads[1]);
                //写出列名称
                for (int i = 0; i < dt.Columns.Count; i++)
                {
                    data += dt.Columns[i].ColumnName.ToString();
                    if (i < dt.Columns.Count - 1)
                    {
                        data += ",";
                    }
                }
                sw.WriteLine(data);
                //写出各行数据
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    data = "";
                    for (int j = 0; j < dt.Columns.Count; j++)
                    {
                        string str = dt.Rows[i][j].ToString();
                        str = str.Replace("\"", "\"\"");              //替换英文冒号 英文冒号需要换成两个冒号
                        if (str.Contains(',') || str.Contains('"') ||
                            str.Contains('\r') || str.Contains('\n')) //含逗号 冒号 换行符的需要放到引号中
                        {
                            str = string.Format("\"{0}\"", str);
                        }

                        data += str;
                        if (j < dt.Columns.Count - 1)
                        {
                            data += ",";
                        }
                    }
                    sw.WriteLine(data);
                }
                sw.Close();
                myStream.Close();
                //Program.logger.LogInfo("文件\"{0}\"保存成功", fileName);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
            finally
            {
                sw.Close();
                myStream.Close();
            }
        }
Пример #26
0
 private void CommandBinding_Executed_1(object sender, ExecutedRoutedEventArgs e)
 {
     System.Windows.Forms.SaveFileDialog saveDialog = new System.Windows.Forms.SaveFileDialog();
     saveDialog.AddExtension = true;
     saveDialog.DefaultExt = ".zac";
     if (saveDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
     {
         try
         {
             Stream myStream = null;
             if ((myStream = saveDialog.OpenFile()) != null)
             {
                 saveControl.save(myStream, GameBoard);
             }
         }
         catch (Exception ex)
         {
             System.Windows.MessageBox.Show(ex.Message);
         }
     }
 }
Пример #27
0
        //public System.Data.DataTable ReadExcel()
        //{
        //    System.Data.DataTable dt = new System.Data.DataTable();

        //    StreamReader sr = new StreamReader(txtSource);
        //    DataRow dr;
        //    int dtCount = dt.Columns.Count;
        //    string input;
        //    int i = 0;
        //    while ((input = sr.ReadLine()) != null)
        //    {

        //        try
        //        {
        //            string[] stringRows = input.Split(new char[] { '\t' });
        //            dr = dt.NewRow();
        //            for (int a = 0; a < dtCount; a++)
        //            {
        //                string dataType = dt.Columns[a].DataType.ToString();
        //                if (stringRows[a] == "" && (dataType == "System.Int32" || dataType == "System.Int64"))
        //                {
        //                    stringRows[a] = "0";
        //                }
        //                dr[a] = Convert.ChangeType(stringRows[a], dt.Columns[a].DataType);

        //            }
        //            dt.Rows.Add(dr);
        //        }
        //        catch (Exception ex)
        //        {
        //            Console.WriteLine(ex.ToString());
        //        }
        //        i++;
        //    }
        //    return dt;
        //}

        //if no choose folder>看起來沒有問題
        //if error
        //chk header right or not.>看起來沒有問題
        //chk date>看起來沒有問題.
        public string ExportExcel(string Title, System.Data.DataTable dt, System.Windows.Forms.SaveFileDialog saveFileDialog)
        {
            //SaveFileDialog saveFileDialog = new SaveFileDialog();
            saveFileDialog.Filter           = "Execl files (*.xls)|*.xls";
            saveFileDialog.FilterIndex      = 0;
            saveFileDialog.RestoreDirectory = true;
            saveFileDialog.CreatePrompt     = false;
            saveFileDialog.Title            = Title;
            saveFileDialog.FileName         = System.DateTime.Now.ToString("yyyyMMdd");
            saveFileDialog.ShowDialog();
            //如果按下取消,那就會拿到沒有path的filename,所以只要判斷有沒有:,如果沒有,回傳-1,表示按下取消
            if (saveFileDialog.FileName.IndexOf(":") < 0)
            {
                return("");
            }

            //字串流
            System.IO.Stream       myStream = null;
            System.IO.StreamWriter sw       = null;
            string ColumnTitle = "";

            try
            {
                myStream = saveFileDialog.OpenFile();
            }
            catch (Exception ex)
            {
                return(ex.Message);
            }
            //你要寫哪個流,把它放進去.
            sw = new System.IO.StreamWriter(myStream, System.Text.Encoding.UTF8);
            try
            {
                //寫標題
                for (int i = 0; i <= dt.Columns.Count - 1; i++)
                {
                    if (i > 0)
                    {
                        ColumnTitle += ",";// Constants.vbTab;
                    }
                    ColumnTitle += dt.Columns[i].Caption;
                }
                sw.WriteLine(ColumnTitle);
                //寫內容
                for (int j = 0; j <= dt.Rows.Count - 1; j++)
                {
                    string columnValue = "";
                    for (int k = 0; k <= dt.Columns.Count - 1; k++)
                    {
                        if (k > 0)
                        {
                            columnValue += ",";// Constants.vbTab;
                        }
                        //日期處理
                        if (dt.Rows[j][k].GetType().ToString().ToUpper() == "SYSTEM.DATETIME")
                        {
                            try
                            {
                                columnValue += System.DateTime.Parse(dt.Rows[j][k].ToString());
                            }
                            catch
                            {
                                columnValue += "";
                            }
                        }
                        else
                        {
                            columnValue += dt.Rows[j][k].ToString();
                        }
                    }
                    sw.WriteLine(columnValue);
                }
                sw.Close();
                myStream.Close();
                return(saveFileDialog.FileName + "檔案匯出完成");
            }
            catch (Exception ex)
            {
                return(ex.ToString());
            }
            finally
            {
                sw.Close();
                myStream.Close();
            }
        }
Пример #28
0
        public void SavePlayer()
        {
            System.Windows.Forms.SaveFileDialog dlg = new System.Windows.Forms.SaveFileDialog();
            Stream myStream;
            dlg.Filter = "He Dies At The End (.hdate) | *.hdate";
            

            if(dlg.ShowDialog() == System.Windows.Forms.DialogResult.OK == true)
                if ((myStream = dlg.OpenFile()) != null)
                {
                    IFormatter formatter = new BinaryFormatter();
                    formatter.Serialize(myStream, p1);
                    myStream.Close();
                }
        }
Пример #29
0
        private void ClickSave(object sender, EventArgs e)
        {
            string hash = hashes[fileHistory.SelectedIndex];
              string text = LoadFile(hash);

              if (text == null) {
            MessageBox.Show(this, "The file was deleted in this revision.", "Deleted");
            return;
              }

              var dialog = new System.Windows.Forms.SaveFileDialog();
              dialog.FileName = this.filename;
              dialog.Filter = "All files (*.*)|*.*";
              dialog.FilterIndex = 0;
              dialog.InitialDirectory = ProjectMonitor.GetProjectDirectory(project);
              if (dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK) {
            var file = dialog.OpenFile();
            byte[] bytes = Encoding.Default.GetBytes(text);
            file.Write(bytes, 0, bytes.Length);
            file.Close();
              }
        }
Пример #30
0
        public void SaveMap()
        {
            System.Windows.Forms.SaveFileDialog openFileDialog1 = new System.Windows.Forms.SaveFileDialog();
            openFileDialog1.Filter = "RPG Map Files (.rpgmf)|*.rpgmf";
            System.Windows.Forms.DialogResult userClickedOK = openFileDialog1.ShowDialog();

            if (userClickedOK == System.Windows.Forms.DialogResult.OK)
            {
                // Open the selected file to read.
                System.IO.Stream fileStream = openFileDialog1.OpenFile();

                using (System.IO.StreamWriter writer = new System.IO.StreamWriter(fileStream))
                {
                    // Read the first line from the file and write it the textbox.
                    map.SaveMap(writer);
                }
                fileStream.Close();
            }
        }
Пример #31
0
        public GameState ZoomUpdate(GameTime gameTime)
        {
            if (state.zoomedPic.editEquationButton.WasLeftClicked(state.inputState))
            {
                state.screen = Screen.EDIT;
                state.zoomedPic.textBox.cursorPos = new Point(0, 0);
                state.zoomedPic.textBox.SetActive(true);
                return(state);
            }


            if (state.zoomedPic.playButton.WasLeftClicked(state.inputState))
            {
                state.zoomedPic.GenVideo(state, Settings.VIDEO_WIDTH_LOW, Settings.VIDEO_HEIGHT_LOW);
            }

            if (state.zoomedPic.playHDButton.WasLeftClicked(state.inputState))
            {
                state.zoomedPic.GenVideo(state, Settings.VIDEO_WIDTH_HI, Settings.VIDEO_HEIGHT_HI);
            }

            if (state.zoomedPic.exportGIFButton.WasLeftClicked(state.inputState))
            {
                _ = state.zoomedPic.exportGIF(state);
            }
            if (state.zoomedPic.exportPNGButton.WasLeftClicked(state.inputState))
            {
                var pic   = state.zoomedPic;
                var store = new FrameStore(1, pic.bigImage.Width, pic.bigImage.Height);
                store.PushFrame(pic.bigImage);

                Stream myStream;
                System.Windows.Forms.SaveFileDialog saveFileDialog1 = new System.Windows.Forms.SaveFileDialog();

                saveFileDialog1.Filter           = "png images (*.png)|*.png";
                saveFileDialog1.FilterIndex      = 0;
                saveFileDialog1.RestoreDirectory = false;

                if (saveFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {
                    if ((myStream = saveFileDialog1.OpenFile()) != null)
                    {
                        store.ExportFrame(myStream, 0);
                        myStream.Close();
                    }
                }
            }

            if (state.zoomedPic.WasRightClicked(state.inputState) || TextUtils.IsKey(Keys.Escape, state.inputState))
            {
                state.zoomedPic.imageCancellationSource.Cancel();
                state.zoomedPic.imageCancellationSource = new CancellationTokenSource();
                state.screen           = Screen.CHOOSE;
                state.zoomedPic.zoomed = false;
                state.zoomedPic        = null;
                LayoutUI();
                return(state);
            }



            return(state);
        }
Пример #32
0
        private void ExportProxysExec()
        {
            Stream myStream;
            System.Windows.Forms.SaveFileDialog saveFileDialog = new System.Windows.Forms.SaveFileDialog();

            saveFileDialog.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*";
            saveFileDialog.FilterIndex = 2;
            saveFileDialog.RestoreDirectory = true;
            saveFileDialog.FileName = "proxys.txt";

            if (saveFileDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                if ((myStream = saveFileDialog.OpenFile()) != null)
                {
                    StreamWriter writer = new StreamWriter(myStream);

                    foreach (ProxyServer proxy in option.Proxys)
                        writer.WriteLine(proxy.Server);

                    writer.Close();
                    myStream.Close();
                }
            }

        }