private void SaveFileShowDialog() { if (SaveAsFileDialog.ShowDialog() == DialogResult.OK) { string sourceFamilyNameBefore = SourceFamily.Name; SourceFamily.Name = Path.GetFileNameWithoutExtension( SaveAsFileDialog.FileName ); new FamilySerializeHelper(SaveAsFileDialog.FileName).Save(SourceFamily); if (FileFullName == null) { SourceFamily.Name = Path.GetFileNameWithoutExtension( SaveAsFileDialog.FileName ); } else { SourceFamily.Name = sourceFamilyNameBefore; } UnsavedChanges = false; UpdateUI(); } ; }
private void FileMenuItemNewOnClick(object sender, EventArgs e) { if (HandleUnsavedChanges() && SaveAsFileDialog.ShowDialog() == DialogResult.OK) { SourceFamily = new Family( Path.GetFileNameWithoutExtension(SaveAsFileDialog.FileName) ); new FamilySerializeHelper(SaveAsFileDialog.FileName).Save(SourceFamily); FileFullName = SaveAsFileDialog.FileName; UnsavedChanges = false; UpdateUI(); UpdateUIMembersListBox(); } ; }
private void saveAsToolStripMenuItem_Click(object sender, EventArgs e) { if (SaveAsFileDialog.ShowDialog() == DialogResult.OK) { String FNGSaveFileName = SaveAsFileDialog.FileName.ToString(); if (FNGSaveFileName != "") { FileStream FNGFileStream, NewFNGFileStream; BinaryReader FNGFile; BinaryWriter newFNGFile; Log("SATEditor : Saving to " + FNGSaveFileName); try { FNGFileStream = File.Open(FNGFileName, FileMode.Open); NewFNGFileStream = File.Open(FNGSaveFileName, FileMode.OpenOrCreate, FileAccess.ReadWrite); FNGFile = new BinaryReader(FNGFileStream); newFNGFile = new BinaryWriter(NewFNGFileStream); // Create a copy File.Copy(FNGFileName, FNGSaveFileName, true); // Write new values from list view foreach (ListViewItem item in SATEditorList.Items) { newFNGFile.BaseStream.Position = int.Parse(item.SubItems[1].Text, System.Globalization.NumberStyles.AllowHexSpecifier); newFNGFile.Write(int.Parse(item.SubItems[4].Text)); // blue newFNGFile.Write(int.Parse(item.SubItems[3].Text)); // green newFNGFile.Write(int.Parse(item.SubItems[2].Text)); // red newFNGFile.Write(int.Parse(item.SubItems[5].Text)); // alpha } Log("SATEditor : Saved " + FNGSaveFileName); FNGChanged = false; FNGFile.Close(); newFNGFile.Close(); } catch (Exception ex) { MessageBox.Show("File could not be saved.", "SATEditor", MessageBoxButtons.OK); Log("SATEditor : File could not be saved." + " " + "Exception: " + ex.ToString()); return; } } } }
/// <summary> /// Сохраняет исходные данные и результаты (если они имеются) в файл. /// </summary> private void SaveAsMenuItem_Click(object sender, EventArgs e) { SaveAsFileDialog.Filter = "Текстовый файл|*.txt"; if (SaveAsFileDialog.ShowDialog() == DialogResult.Cancel) { return; } string filename = SaveAsFileDialog.FileName; try { using (StreamWriter sw = new StreamWriter(filename, false, Encoding.Default)) { sw.WriteLine("Интервал от {0} до {1}", RangeFrom, RangeTo); sw.WriteLine("Количество разбиений: {0}", StepNumber); sw.WriteLine("Начальное условие: {0}", InitialCondition); sw.WriteLine(); sw.WriteLine("Сопротивление резистора: {0}", Resistance); sw.WriteLine("Ёмкость: {0}", Capacity.ToString()); sw.WriteLine("Напряжение: {0}", Voltage); sw.WriteLine(); if (Data.t != null && Data.q != null) { string tText, qText; for (int i = 0; i < Data.t.Length; i++) { tText = string.Format("t[{0}] = {1:f8}", i, Data.t[i]); qText = string.Format("q[{0}] = {1}", i, Data.q[i]); sw.WriteLine(string.Format("{0,-30} {1,-30}", tText, qText)); } } } } catch { MessageBox.Show("Ошибка при сохранении данных", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } }