|
5 | 5 | using System.IO; |
6 | 6 | using System.Text; |
7 | 7 | using System.Windows.Forms; |
| 8 | +using Newtonsoft.Json; |
| 9 | +using Newtonsoft.Json.Linq; |
8 | 10 |
|
9 | 11 | namespace TEAM |
10 | 12 | { |
@@ -3236,5 +3238,78 @@ private void FormModelMetadata_SizeChanged(object sender, EventArgs e) |
3236 | 3238 | { |
3237 | 3239 | GridAutoLayout(); |
3238 | 3240 | } |
| 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 | + } |
3239 | 3314 | } |
3240 | 3315 | } |
0 commit comments