Skip to content

Commit 5df00d3

Browse files
committed
Added two menu options on model metadata
Save model file as JSON menu option Open model file from JSON menu option
1 parent 6ccf745 commit 5df00d3

File tree

2 files changed

+97
-1
lines changed

2 files changed

+97
-1
lines changed

TEAM/Form_Model_Metadata.Designer.cs

Lines changed: 22 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

TEAM/Form_Model_Metadata.cs

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
using System.IO;
66
using System.Text;
77
using System.Windows.Forms;
8+
using Newtonsoft.Json;
9+
using Newtonsoft.Json.Linq;
810

911
namespace TEAM
1012
{
@@ -3236,5 +3238,78 @@ private void FormModelMetadata_SizeChanged(object sender, EventArgs e)
32363238
{
32373239
GridAutoLayout();
32383240
}
3241+
private DialogResult STAShowDialog(FileDialog dialog)
3242+
{
3243+
var state = new FormManageMetadata.DialogState { FileDialog = dialog };
3244+
var t = new System.Threading.Thread(state.ThreadProcShowDialog);
3245+
t.SetApartmentState(System.Threading.ApartmentState.STA);
3246+
3247+
t.Start();
3248+
t.Join();
3249+
3250+
return state.DialogResult;
3251+
}
3252+
3253+
private void saveModelMetadataFileAsJSONToolStripMenuItem_Click(object sender, EventArgs e)
3254+
{
3255+
try
3256+
{
3257+
var configurationSettings = new ConfigurationSettings();
3258+
3259+
var theDialog = new SaveFileDialog
3260+
{
3261+
Title = @"Save Model Metadata File",
3262+
Filter = @"JSON files|*.json",
3263+
InitialDirectory = configurationSettings.ConfigurationPath //Application.StartupPath + @"\Configuration\"
3264+
};
3265+
3266+
var ret = STAShowDialog(theDialog);
3267+
3268+
if (ret == DialogResult.OK)
3269+
{
3270+
try
3271+
{
3272+
var chosenFile = theDialog.FileName;
3273+
3274+
DataTable gridDataTable = (DataTable)bindingSourceTableMetadata.DataSource;
3275+
3276+
gridDataTable.TableName = "ModelMetadata";
3277+
3278+
JArray outputFileArray = new JArray();
3279+
foreach (DataRow singleRow in gridDataTable.Rows)
3280+
{
3281+
JObject individualRow = JObject.FromObject(new
3282+
{
3283+
versionAttributeHash = singleRow[0].ToString(),
3284+
versionId = singleRow[1].ToString(),
3285+
tableName = singleRow[2].ToString(),
3286+
columnName = singleRow[3].ToString(),
3287+
dataType = singleRow[4].ToString(),
3288+
characterMaximumLength = singleRow[5].ToString(),
3289+
numericPrecision = singleRow[6].ToString(),
3290+
ordinalPosition = singleRow[7].ToString(),
3291+
primaryKeyIndicator = singleRow[8].ToString(),
3292+
multiActiveIndicator = singleRow[9].ToString()
3293+
});
3294+
outputFileArray.Add(individualRow);
3295+
}
3296+
3297+
string json = JsonConvert.SerializeObject(outputFileArray, Formatting.Indented);
3298+
3299+
File.WriteAllText(chosenFile, json);
3300+
3301+
richTextBoxInformation.Text = "The model metadata file " + chosenFile + " saved successfully.";
3302+
}
3303+
catch (Exception ex)
3304+
{
3305+
MessageBox.Show(ex.ToString());
3306+
}
3307+
}
3308+
}
3309+
catch (Exception ex)
3310+
{
3311+
MessageBox.Show("A problem occure when attempting to save the file to disk. The detail error message is: " + ex.Message);
3312+
}
3313+
}
32393314
}
32403315
}

0 commit comments

Comments
 (0)