/// <summary> /// 自組態設定集合移除所有組態設定成員 /// </summary> public override void RemoveAllProperties() { try { // Get the application configuration file. GetConfigurationFile(); // Read and display the custom section. GetPropSection(); // Remove the collection of elements from the section. if (PropSection != null) { PropSection.DBPropCollection.Clear(); PropSection.BasicPropCollection.Clear(); PropSection.DefaultPropCollection.Clear(); PropSection.UndoPropCollection.Clear(); PropSection.RedoPropCollection.Clear(); // Save the application configuration file. PropSection.SectionInformation.ForceSave = true; Config.Save(ConfigurationSaveMode.Modified); InfoLog.Log("AppConfig", "RemoveAllProperties", string.Format("Removed collection element from the custom section in the configuration file: {0}", Config.FilePath)); } else { InfoLog.Log("AppConfig", "RemoveAllProperties", "You must create the custom section first."); } } catch (ConfigurationErrorsException ex) { ErrorLog.Log("RemoveAllProperties", ex); throw ex; } }
private void Button_Bag_Y_Click(object sender, EventArgs e) { InfoLog.Log("BRSTestDataGenerator", "ChildForm", "Click <Submit> button to add a BSM data."); if (Text_Data_Number.ForeColor != Color.Black || Text_BagState.ForeColor != Color.Black || Text_CabinClass.ForeColor != Color.Black) { MessageBox.Show("You did not complete all inputs yet.", "Warning", MessageBoxButtons.OK); InfoLog.Log("BRSTestDataGenerator", "ChildForm", "Inputs in BSM panel are not completed."); return; } // 顯示異動確認之對話方塊作再次確認 InfoLog.Log("BRSTestDataGenerator", "ChildForm", "Double confirm whether to complete this BSM amendment or not."); DialogResult doubleConfirm = MessageBox.Show("Are you sure to complete this amendment?", "Confirm", MessageBoxButtons.YesNo); if (doubleConfirm == DialogResult.Yes) { // 異動確認之對話方塊選擇"Yes" InfoLog.Log("BRSTestDataGenerator", "ChildForm", "Sure to complete this BSM amendment."); if (new Regex(@"^[1-9]\d*$").IsMatch(Text_Data_Number.Text) && int.TryParse(Text_Data_Number.Text, out int int_Number_BSM) && new Regex(@"^\d*$").IsMatch(Text_BagState.Text) && int.TryParse(Text_BagState.Text, out int int_BagState_BSM) && new Regex(@"^[A-Z]{1}$").IsMatch(Text_CabinClass.Text) && new Regex(@"^\w{1,20}$").IsMatch(User)) { InfoLog.Log("BRSTestDataGenerator", "MainForm", string.Format("Start to add {0} new BSM test data for [{1}].", Text_Data_Number.Text, SelectedFlight)); if (AddNewTestBSM(int_Number_BSM, Text_CabinClass.Text, int_BagState_BSM, SelectedFlight)) { // 回復步驟記錄新增行李動作與行李所屬航班編號及新增數量 List <string> undoKeys = AppJsonConfig.AppPropertySetting.Instance().ConfigRoot.properties.AppPropSetting.Undo; int undoNo = undoKeys.Count > 0 ? int.Parse(undoKeys[^ 1].Split("|")[0].Split("_")[2]) + 1 : 1;
/// <summary> /// 自組態設定集合依標籤名稱(key)移除特定型態組態設定成員 /// </summary> /// <param name="key">標籤名稱(key)</param> /// <param name="pCollectionName">特定組態設定成員集合之名稱</param> public override void RemoveProperty(string key, string pCollectionName) { try { // Get the application configuration file. GetConfigurationFile(); // Read and display the custom section. GetPropSection(); // Remove the element from the custom section. if (PropSection != null) { // Use one of the ConfigurationCollectionElement Remove overloaded methods to remove the element from the collection based on the element's key switch (pCollectionName) { case AppPropSection.DBCollection: PropSection.DBPropCollection.Remove(PropSection.DBPropCollection[key]); break; case AppPropSection.BasicCollection: PropSection.BasicPropCollection.Remove(PropSection.BasicPropCollection[key]); break; case AppPropSection.DefaultCollection: PropSection.DefaultPropCollection.Remove(PropSection.DefaultPropCollection[key]); break; case AppPropSection.UndoCollection: PropSection.UndoPropCollection.Remove(PropSection.UndoPropCollection[key]); break; case AppPropSection.RedoCollection: PropSection.RedoPropCollection.Remove(PropSection.RedoPropCollection[key]); break; default: InfoLog.Log(string.Empty, "AppConfig", string.Format("The requested ConfigurationCollection name {0} is not found", pCollectionName)); return; } // Save the application configuration file. PropSection.SectionInformation.ForceSave = true; Config.Save(ConfigurationSaveMode.Modified); InfoLog.Log("AppConfig", "RemoveProperty", string.Format("Removed collection element from the custom section in the configuration file: {0}", Config.FilePath)); } else { InfoLog.Log("AppConfig", "RemoveProperty", "You must create the custom section first."); } } catch (ConfigurationErrorsException ex) { ErrorLog.Log("RemoveProperty", ex); throw ex; } }
/// <summary> /// 新增特定型態之組態設定成員至組態設定集合 /// </summary> /// <param name="element">特定型態之組態設定成員</param> /// <param name="pCollectionName">特定組態設定成員集合之名稱</param> public override void AddProperty(object element, string pCollectionName) { try { // Get the application configuration file. GetConfigurationFile(); // Read and display the custom section. GetPropSection(); // Add the element to the collection in the custom section. if (PropSection != null) { // Use the ConfigurationCollectionElement Add method to add the new element to the collection. switch (pCollectionName) { case AppPropSection.DBCollection: PropSection.DBPropCollection.Add((AppPropElement)element); break; case AppPropSection.BasicCollection: PropSection.BasicPropCollection.Add((AppPropElement)element); break; case AppPropSection.DefaultCollection: PropSection.DefaultPropCollection.Add((AppPropElement)element); break; case AppPropSection.UndoCollection: PropSection.UndoPropCollection.Add((AppPropElement)element); break; case AppPropSection.RedoCollection: PropSection.RedoPropCollection.Add((AppPropElement)element); break; default: Console.WriteLine("The requested ConfigurationCollection name {0} is not found", pCollectionName); return; } // Save the application configuration file. PropSection.SectionInformation.ForceSave = true; Config.Save(ConfigurationSaveMode.Modified); InfoLog.Log("AppConfig", "AddProperty", string.Format("Added collection element to the custom section in the configuration file: {0}", Config.FilePath)); } else { InfoLog.Log("AppConfig", "AddProperty", "You must create the custom section first."); } } catch (ConfigurationErrorsException ex) { ErrorLog.Log("AddProperty", ex); throw ex; } }
/// <summary> /// 建立並儲存 <c>AppPropElement</c> 組態設定檔案所需之區段 /// </summary> protected override void CreateCustomSection() { try { // Get the current configuration file. GetConfigurationFile(); // Add the custom section to the application configuration file. GetPropSection(); if (PropSection == null) { // The configuration file does not contain the custom section yet. Create it. PropSection = new AppPropSection(); Config.Sections.Add(SectionName, PropSection); } else { // The configuration file contains the custom section but its element collection is empty. Initialize the collection if (PropSection.DBPropCollection.Count == 0) { PropSection.DBPropCollection.Add(new AppPropElement()); } if (PropSection.BasicPropCollection.Count == 0) { PropSection.BasicPropCollection.Add(new AppPropElement()); } if (PropSection.DefaultPropCollection.Count == 0) { PropSection.DefaultPropCollection.Add(new AppPropElement()); } if (PropSection.UndoPropCollection.Count == 0) { PropSection.UndoPropCollection.Add(new AppPropElement()); } if (PropSection.RedoPropCollection.Count == 0) { PropSection.RedoPropCollection.Add(new AppPropElement()); } } // Save the application configuration file. PropSection.SectionInformation.ForceSave = true; bool sb = Config.HasFile; Config.Save(ConfigurationSaveMode.Modified); InfoLog.Log("AppConfig", "CreateCustomSection", string.Format("Created custom section in the application configuration file: {0}", Config.FilePath)); } catch (ConfigurationErrorsException ex) { ErrorLog.Log("CreateCustomSection", ex); throw ex; } }
private void Button_Flight_Y_Click(object sender, EventArgs e) { InfoLog.Log("BRSTestDataGenerator", "ChildForm", "Click <Submit> button to add a FIDS data."); if (Text_STD.ForeColor != Color.Black || Text_ETD.ForeColor != Color.Black || Text_DES.ForeColor != Color.Black) { MessageBox.Show("You did not complete all inputs yet.", "Warning", MessageBoxButtons.OK); InfoLog.Log("BRSTestDataGenerator", "ChildForm", "Inputs in FIDS panel are not completed."); return; } // 顯示異動確認之對話方塊作再次確認 InfoLog.Log("BRSTestDataGenerator", "ChildForm", "Double confirm whether to complete this FIDS amendment or not."); DialogResult doubleConfirm = MessageBox.Show("Are you sure to complete this amendment?", "Confirm", MessageBoxButtons.YesNo); if (doubleConfirm == DialogResult.Yes) { // 異動確認之對話方塊選擇"Yes" InfoLog.Log("BRSTestDataGenerator", "ChildForm", "Sure to complete this FIDS amendment."); if (new Regex(@"^\d{4}$").IsMatch(Text_STD.Text) && new Regex(@"^\d{4}$").IsMatch(Text_ETD.Text) && new Regex(@"^[A-Z]{3,4}$").IsMatch(Text_DES.Text) && new Regex(@"^\w{1,20}$").IsMatch(User)) { InfoLog.Log("BRSTestDataGenerator", "ChildForm", string.Format("Start to add a new FIDS test data: {0}.", TargetFlight)); FIDS2Day.Row newRow = new FIDS2Day.Row() { FLIGHT_NO = TargetFlight, DATE_TIME = App_Mode == "0" ? DateTime.ParseExact(TestDate, "yyyy-MM-dd", CultureInfo.InvariantCulture).ToString("yyyyMMdd") : DateTime.Now.ToString("yyyyMMdd"), TYPE = "D", STD = Text_STD.Text, ETD = Text_ETD.Text, ATD = string.Empty, DESTINATION = Text_DES.Text.ToUpper(), PLANE = string.Empty, STATUS = "On Time", UPD_USER = User, UPD_TIME = DateTime.Now.ToString("yyyyMMddHHmmss"), UPD_TYPE = 0 }; if (AddNewTestFIDS(newRow)) { // 回復步驟記錄新增航班動作與航班編號 List <string> undoKeys = AppJsonConfig.AppPropertySetting.Instance().ConfigRoot.properties.AppPropSetting.Undo; int undoNo = undoKeys.Count > 0 ? int.Parse(undoKeys[^ 1].Split("|")[0].Split("_")[2]) + 1 : 1;
private void MainForm_FormClosing(object sender, FormClosingEventArgs e) { // 清除回復、重複步驟記錄 //List<string> undoKeys = AppConfig.AppPropertySetting.Instance().GetCollectionPropertyNames(AppConfig.AppPropSection.UndoCollection); //undoKeys.ForEach(key => AppConfig.AppPropertySetting.Instance().RemoveProperty(key, AppConfig.AppPropSection.UndoCollection)); //AppConfig.AppPropertySetting.Instance().AddProperty(new AppConfig.AppPropElement("Undo_Base_00", "DoNotRemove"), AppConfig.AppPropSection.UndoCollection); List <string> undoKeys = AppJsonConfig.AppPropertySetting.Instance().ConfigRoot.properties.AppPropSetting.Undo; undoKeys.RemoveAll(s => !s.StartsWith("Undo_Base")); //List<string> redoKeys = AppConfig.AppPropertySetting.Instance().GetCollectionPropertyNames(AppConfig.AppPropSection.RedoCollection); //redoKeys.ForEach(key => AppConfig.AppPropertySetting.Instance().RemoveProperty(key, AppConfig.AppPropSection.RedoCollection)); //AppConfig.AppPropertySetting.Instance().AddProperty(new AppConfig.AppPropElement("Redo_Base_00", "DoNotRemove"), AppConfig.AppPropSection.RedoCollection); List <string> redoKeys = AppJsonConfig.AppPropertySetting.Instance().ConfigRoot.properties.AppPropSetting.Redo; redoKeys.RemoveAll(s => !s.StartsWith("Redo_Base")); InfoLog.Log("BRSTestDataGenerator", "MainForm", "MainForm of [BRS Test Data Generator] Closed."); }
/// <summary> /// 將標籤名稱(key)的組態設定檔區段內容之設定值變更 /// </summary> /// <param name="key">標籤名稱(key)</param> /// <param name="value">欲變更組態設定檔區段內容之設定值</param> public override void SetProperty(string key, string value) { try { // Get the application configuration file. GetConfigurationFile(); // Read and display the custom section. GetPropSection(); if (PropSection != null) { if (PropSection.DBPropCollection[key] != null) { PropSection.DBPropCollection[key].Value = value; } else if (PropSection.BasicPropCollection[key] != null) { PropSection.BasicPropCollection[key].Value = value; } else if (PropSection.DefaultPropCollection[key] != null) { PropSection.DefaultPropCollection[key].Value = value; } } // Save the application configuration file. PropSection.SectionInformation.ForceSave = true; Config.Save(ConfigurationSaveMode.Modified); InfoLog.Log("AppConfig", "SetProperty", string.Format("Saved the value for the collection element from the custom section in the configuration file: {0}", Config.FilePath)); } catch (ConfigurationErrorsException ex) { ErrorLog.Log("SetProperty", ex); throw ex; } }
private void ChildForm_AddBag_Load(object sender, EventArgs e) { InfoLog.Log("BRSTestDataGenerator", "ChildForm", "ChildForm_AddBag of [BRS Test Data Generator] initialized."); InitializeForm(); }
private void MainForm_Load(object sender, EventArgs e) { InfoLog.Log("BRSTestDataGenerator", "MainForm", "MainForm of [BRS Test Data Generator] initialized."); RefreshForm(); }