This repository was archived by the owner on Dec 5, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFormSaveFileDialog.cs
More file actions
166 lines (158 loc) · 6.19 KB
/
FormSaveFileDialog.cs
File metadata and controls
166 lines (158 loc) · 6.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
using CodeForger.CodeForgerDBDataSetTableAdapters;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using static System.Net.Mime.MediaTypeNames;
namespace CodeForger
{
public partial class FormSaveFileDialog : Form
{
private string contentsGlobal;
public FormSaveFileDialog(string contents)
{
InitializeComponent();
contentsGlobal = contents;
comboBoxFileType.SelectedIndex = 0;
}
private void buttonSave_Click(object sender, EventArgs e)
{
if (radioButtonSaveDBFile.Checked)
{
CodeTableTableAdapter codeTableTA = new CodeTableTableAdapter();
string filetype = "";
switch (comboBoxFileType.SelectedIndex)
{
case 0:
filetype = "Text";
break;
case 1:
filetype = "Pseudocode";
break;
case 2:
filetype = "LISP";
break;
case 3:
filetype = "Brainfuck";
break;
case 4:
filetype = "C";
break;
case 5:
filetype = "C++";
break;
}
if (filetype == "")
{
MessageBox.Show("Please select a file type", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
codeTableTA.Insert(contentsGlobal, filetype, DateTime.Now, Properties.Settings.Default.AccountLogin, textBoxTitle.Text);
Properties.Settings.Default.OpenFileTitle = textBoxTitle.Text;
Properties.Settings.Default.OpenFilePath = null;
Properties.Settings.Default.OpenFileIsExternal = "0";
this.Close();
}
else
{
SaveFileDialog sfd = new SaveFileDialog();
sfd.Title = "Save File";
//if (comboBoxFileType.SelectedIndex == 0)
sfd.Filter = "Text files (*.txt)|*.txt|Pseudocode files (*.psc)|*.psc|LISP files (*.lsp)|*.lsp|Brainfuck files (*.bf)|*.bf|C files (*.c)|*.c|C++ files (*.cpp)|*.cpp|All files (*.*)|*.*";
switch (sfd.FilterIndex)
{
case 0:
sfd.FileName = "untitled.txt";
break;
case 1:
sfd.FileName = "untitled.psc";
break;
case 2:
sfd.FileName = "untitled.lsp";
break;
case 3:
sfd.FileName = "untitled.bf";
break;
case 4:
sfd.FileName = "untitled.c";
break;
case 5:
sfd.FileName = "untitled.cpp";
break;
}
if (sfd.ShowDialog() == DialogResult.OK)
{
using (FileStream fs = File.Create(sfd.FileName))
{
byte[] bytes = Encoding.UTF8.GetBytes(contentsGlobal);
fs.Write(bytes, 0, bytes.Length);
}
Properties.Settings.Default.OpenFileTitle = Path.GetFileName(sfd.FileName);
Properties.Settings.Default.OpenFilePath = sfd.FileName;
Properties.Settings.Default.OpenFileIsExternal = "1";
switch (Path.GetExtension(sfd.FileName))
{
case ".txt":
Properties.Settings.Default.OpenFileType = "Text";
break;
case ".psc":
Properties.Settings.Default.OpenFileType = "Pseudocode";
break;
case ".lsp":
Properties.Settings.Default.OpenFileType = "LISP";
break;
case ".bf":
Properties.Settings.Default.OpenFileType = "Brainfuck";
break;
case ".c":
Properties.Settings.Default.OpenFileType = "C";
break;
case ".cpp":
Properties.Settings.Default.OpenFileType = "C++";
break;
}
this.Close();
}
}
}
private void radioButtonSaveExtFile_CheckedChanged(object sender, EventArgs e)
{
if (radioButtonSaveExtFile.Checked)
{
label2.Enabled = false;
label2.Visible = false;
textBoxTitle.Enabled = false;
textBoxTitle.Visible = false;
comboBoxFileType.Enabled = false;
comboBoxFileType.Visible = false;
}
else
{
label2.Enabled = true;
label2.Visible = true;
textBoxTitle.Enabled = true;
textBoxTitle.Visible = true;
comboBoxFileType.Enabled = true;
comboBoxFileType.Visible = true;
}
}
private void FormSaveFileDialog_Load(object sender, EventArgs e)
{
if (Properties.Settings.Default.AccountLogin == -1)
{
radioButtonSaveDBFile.Enabled = false;
radioButtonSaveDBFile.Checked = false;
radioButtonSaveExtFile.Checked = true;
}
this.Location = new Point(
(Screen.PrimaryScreen.WorkingArea.Width - this.Width) / 2,
(Screen.PrimaryScreen.WorkingArea.Height - this.Height) / 2);
}
}
}