private void btnSaveAll_Click(object sender, EventArgs e) { if (tcCodes.TabPages == null) { MessageBox.Show("请先生成代码!"); return; } FolderBrowserDialog dlg = new FolderBrowserDialog(); if (dlg.ShowDialog() == DialogResult.OK) { foreach (TabPage page in tcCodes.TabPages) { ICSharpCode.TextEditor.TextEditorControl txtEditor = page.Controls[0] as ICSharpCode.TextEditor.TextEditorControl; if (txtEditor != null) { Model.CodeLayer.CodeLayers layer = (Model.CodeLayer.CodeLayers)txtEditor.Tag; Model.CodeLayer codeLayer = new Model.CodeLayer(layer); string filePath = dlg.SelectedPath + "\\" + codeLayer.Folder; string fileName = string.Format(codeLayer.FileName, table.Name); if (!Directory.Exists(filePath)) { Directory.CreateDirectory(filePath); } CodeUtility.FileStream.WriteFile(filePath + "\\" + fileName, txtEditor.Text); } } } }
private void btnSaveCurrentTab_Click(object sender, EventArgs e) { if (tcCodes.SelectedTab == null) { MessageBox.Show("请先生成代码!"); return; } ICSharpCode.TextEditor.TextEditorControl txtEditor = tcCodes.SelectedTab.Controls[0] as ICSharpCode.TextEditor.TextEditorControl; if (txtEditor != null) { Model.CodeLayer.CodeLayers layer = (Model.CodeLayer.CodeLayers)txtEditor.Tag; Model.CodeLayer codeLayer = new Model.CodeLayer(layer); SaveFileDialog dlg = new SaveFileDialog(); dlg.AddExtension = true; dlg.FileName = string.Format(codeLayer.FileName, table.Name); dlg.Filter = string.Format(".{0}|*.{0}", codeLayer.FileExt); if (dlg.ShowDialog() == DialogResult.OK) { CodeUtility.FileStream.WriteFile(dlg.FileName, txtEditor.Text); } } }