private void OnContentChanged(object sender, EventArgs e) { var view = (MainUserControl)MainContentControl.Content; if (view == null) { return; } if (RightWindowCommands == null) { RightWindowCommands = view.RightWindowCommands; } else { if (_previousMainContent?.RightWindowCommands != null) { Move(RightWindowCommands.Items, _previousMainContent.RightWindowCommands.Items); } RightWindowCommands.Items.Clear(); if (view.RightWindowCommands != null) { foreach (var frameworkElement in view.RightWindowCommands.Items.OfType <FrameworkElement>()) { frameworkElement.DataContext = view.DataContext; } Move(view.RightWindowCommands.Items, RightWindowCommands.Items); } _previousMainContent = view; } }
private void windowVisibilityEvents_WindowHiding(Window window) { if (mainUserControls.ContainsKey(window)) { MainUserControl mainUserControl = mainUserControls[window]; mainUserControls.Remove(window); mainUserControl.Dispose(); } }
public MainWindow() { InitializeComponent(); #region Variables Initialization loggedIn = false; CurrentVM = new FallVM(); userVM = new UserVM(); currentLang = "Resources/ukFlagIcon.png"; CurrentUser = new user(); CurrentUser.firstname = "Guest"; main = new MainUserControl(); login = new LoginUserControl(this); report = new ReportUserControl(this); #endregion #region Preparing the Source of the Falls Listbox userControlGrid.Children.Add(main); foreach (var fall in CurrentVM.Falls) { Pushpin pushpin = new Pushpin(); pushpin.Name = "pushpin" + fall.id.ToString(); pushpin.Location = new Location(fall.x, fall.y); pushpin.Background = System.Windows.Media.Brushes.Orange; main.fallsView.Children.Add(pushpin); } main.fallsListBox.ItemsSource = CurrentVM.Falls.OrderByDescending(fall => fall.date); #endregion #region Handling the previous "Recent" Reports // We want to make sure that, if recentFalls still reports from a previous day(s), // it will be cleared before we start storing reports on it today. XElement prevFallsRoot = XElement.Load("recentFalls.xml"); if (prevFallsRoot.HasElements) { IEnumerable <XElement> prevFallsList = prevFallsRoot.Elements("Fall").ToList(); DateTime lastReport = new DateTime(0); foreach (XElement fallRep in prevFallsList) { DateTime leDate = DateTime.Now; DateTime.TryParse(fallRep.Element("Date").Value, out leDate); if (leDate.CompareTo(lastReport) > 0) { lastReport = leDate; } } if (lastReport.Day != DateTime.Now.Day || lastReport.Month != DateTime.Now.Month || lastReport.Year != DateTime.Now.Year) { // This is where we'd first save the previous days reports on a more permanent // storage on the cloud, if we wanted to do that File.WriteAllText(@"recentFalls.xml", string.Empty); } } #endregion }
/// <summary>Implements the Exec method of the IDTCommandTarget interface. This is called when the command is invoked.</summary> /// <param term='commandName'>The name of the command to execute.</param> /// <param term='executeOption'>Describes how the command should be run.</param> /// <param term='varIn'>Parameters passed from the caller to the command handler.</param> /// <param term='varOut'>Parameters passed from the command handler to the caller.</param> /// <param term='handled'>Informs the caller if the command was handled or not.</param> /// <seealso class='Exec' /> public void Exec(string commandName, vsCommandExecOption executeOption, ref object varIn, ref object varOut, ref bool handled) { handled = false; if (executeOption == vsCommandExecOption.vsCommandExecOptionDoDefault) { if (commandName == "XnaLevelEditor.Connect.XnaLevelEditor") { handled = true; try { #region Load Tool Window ClassManager.applicationObject = applicationObject; ChooseClassForm form = new ChooseClassForm(); if (form.ShowDialog() != DialogResult.OK) { return; } ClassManager classManager = new XleGenerator.ClassManager(form.ProjectName, form.ClassName, form.IsOpen); object programmableObject = null; guidString = "{A5431877-4E06-44FC-A59C-5BDE534A8F4F}";//{9FFC9D9B-1F39-4763-A2AF-66AED06C799E}"; //guidString = Guid.NewGuid().ToString("B"); Window window = windows2.CreateToolWindow2(_addInInstance, asm.Location, userControlType.FullName, "Level Editor", guidString, ref programmableObject); MainUserControl mainUserControl = (MainUserControl)programmableObject; window.IsFloating = false; window.Linkable = false; window.WindowState = vsWindowState.vsWindowStateMaximize; #endregion mainUserControl.ApplicationObject = applicationObject; mainUserControl.Window = window; mainUserControl.IsOpen = form.IsOpen; mainUserControl._ClassManager = classManager; window.Visible = true; mainUserControls.Add(window, mainUserControl); } catch (Exception ex) { MessageBox.Show(ex.Message + "\r\n" + ex.StackTrace); } return; } } }
// The external command invokes this on the end-user's request public void ShowForm() { // If we do not have a dialog yet, create and show it if (m_MyForm == null) { // A new handler to handle request posting by the dialog ExternalEventClashDetection handler = new ExternalEventClashDetection(); // External Event for the dialog to use (to post requests) ExternalEvent exEvent = ExternalEvent.Create(handler); // External execution handler to provide the needed context by revit to perform modifications on active document CleanViewHandler cleanViewHandler = new CleanViewHandler(); // External event used for clean elements on the active view ExternalEvent externalCleanEvent = ExternalEvent.Create(cleanViewHandler); // We give the objects to the new dialog; // The dialog becomes the owner responsible for disposing them, eventually. m_MyForm = new MainUserControl(exEvent, handler, externalCleanEvent); m_MyForm.Closed += MyFormClosed; m_MyForm.Show(); } }
private void AddDocContents() { _tasksQueueManager = new TasksQueueManager(); var theme = new VS2012LightTheme(); this.dockPanel.Theme = theme; this.dockPanel.DocumentStyle = DocumentStyle.DockingSdi; _queueUserControl = new QueueUserControl(_tasksQueueManager.TasksQueue); _queueUserControl.Show(this.dockPanel, DockState.DockRight); _logUserControl = new LogUserControl(); _logUserControl.Show(this.dockPanel, DockState.DockBottom); _filtersUserControl = new FiltersUserControl(); _filtersUserControl.Show(this.dockPanel, DockState.DockLeft); _filtersUserControl.OnFilterChanged += FiltersUserControlOnOnFilterChanged; _mainUserControl = new MainUserControl(); _mainUserControl.Tasks = _tasksQueueManager.TasksQueue; _mainUserControl.Show(this.dockPanel, DockState.Document); _mainUserControl.OnSynchRebinded += _mainUserControl_OnSynchRebinded; }
public void MainButton_Click(object sender, RoutedEventArgs e) { mainButton.BorderThickness = new Thickness(0, 0, 0, 2); mainButton.FontWeight = FontWeights.ExtraBold; loginButton.BorderThickness = new Thickness(0, 0, 0, 0); loginButton.FontWeight = FontWeights.Normal; reportButton.BorderThickness = new Thickness(0, 0, 0, 0); reportButton.FontWeight = FontWeights.Normal; updateButton.BorderThickness = new Thickness(0, 0, 0, 0); updateButton.FontWeight = FontWeights.Normal; userControlGrid.Children.RemoveAt(0); main = new MainUserControl(); userControlGrid.Children.Add(main); CurrentVM = new FallVM(); foreach (var fall in CurrentVM.Falls) { Pushpin pushpin = new Pushpin(); pushpin.Name = "pushpin" + fall.id.ToString(); pushpin.Location = new Location(fall.x, fall.y); pushpin.Background = System.Windows.Media.Brushes.Orange; main.fallsView.Children.Add(pushpin); } main.fallsListBox.ItemsSource = CurrentVM.Falls.OrderByDescending(fall => fall.date); }
private void MyFormClosed(object sender, EventArgs e) { m_MyForm = null; }
public Form1() { #region Serilog initial Log.Logger = new LoggerConfiguration() .WriteTo.Console() .WriteTo.File($"{AppDomain.CurrentDomain.BaseDirectory}\\log\\log-.txt", rollingInterval: RollingInterval.Day, outputTemplate: "{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz} [{Level:u3}] {Message:lj}{NewLine}{Exception}") .CreateLogger(); //宣告Serilog初始化 #endregion #region Loading initial FluentSplashScreenOptions op = new FluentSplashScreenOptions(); op.Title = "太陽能資料蒐集系統";//太陽能資料蒐集系統 帆宣自動化抄表系統 op.Subtitle = "Automatic Meter Reading System"; op.LeftFooter = "Copyright © 2021 SIN MAO Energy CO., LTD." + Environment.NewLine + "All Rights reserved."; op.LoadingIndicatorType = FluentLoadingIndicatorType.Dots; op.OpacityColor = Color.FromArgb(62, 91, 135); op.Opacity = 130; SplashScreenManager.ShowFluentSplashScreen( op, parentForm: this, useFadeIn: true, useFadeOut: true ); #endregion #region 入資料庫JSON op.RightFooter = $"載入資料庫資訊"; SplashScreenManager.Default.SendCommand(FluentSplashScreenCommand.UpdateOptions, op); SystemSetting = InitialMethod.SystemLoad(); Thread.Sleep(1000); #endregion #region 入按鈕JSON op.RightFooter = $"載入按鈕資訊"; SplashScreenManager.Default.SendCommand(FluentSplashScreenCommand.UpdateOptions, op); ButtonSetting = InitialMethod.InitialButtonLoad(); Thread.Sleep(1000); #endregion #region 入匯出報表JSON op.RightFooter = $"載入匯出報表資訊"; SplashScreenManager.Default.SendCommand(FluentSplashScreenCommand.UpdateOptions, op); XtraReportSetting = InitialMethod.InitialXtraReportLoad(); Thread.Sleep(1000); #endregion #region JSON錯誤資訊檢查 if (SystemSetting == null && ButtonSetting == null && XtraReportSetting == null) { ErrorStr = "資料庫與按鈕Json錯誤"; } else if (SystemSetting != null && ButtonSetting == null && XtraReportSetting != null) { ErrorStr = "按鈕Json錯誤"; } else if (SystemSetting == null && ButtonSetting != null && XtraReportSetting != null) { ErrorStr = "資料庫Json錯誤"; } else if (SystemSetting != null && ButtonSetting != null && XtraReportSetting == null) { ErrorStr = "匯出報表Json錯誤"; } if (ErrorStr == "") { op.RightFooter = $"載入完成"; SplashScreenManager.Default.SendCommand(FluentSplashScreenCommand.UpdateOptions, op); Thread.Sleep(1000); SplashScreenManager.CloseForm(); } else { op.RightFooter = $"{ErrorStr}"; SplashScreenManager.Default.SendCommand(FluentSplashScreenCommand.UpdateOptions, op); Thread.Sleep(5000); SplashScreenManager.CloseForm(); } #endregion InitializeComponent(); if (ErrorStr == "") { Change_Logo(); //載入Logo SettingbarButtonItem.ImageOptions.Image = imageCollection1.Images["technology"]; //設定按鈕圖 #region 建立資料庫物件 MysqlMethod = new MysqlMethod(SystemSetting); if (SystemSetting != null) { GatewayConfigs = MysqlMethod.Search_GatewayConfig(); } #endregion #region 建立通訊 if (GatewayConfigs != null) { foreach (var item in GatewayConfigs) { GatewayTypeEnum gatewayType = (GatewayTypeEnum)item.GatewayTypeEnum; switch (gatewayType) { case GatewayTypeEnum.ModbusRTU: { SerialportMasterComponent serialport = new SerialportMasterComponent(item, MysqlMethod) { MysqlMethod = MysqlMethod }; serialport.MyWorkState = true; Field4Components.Add(serialport); } break; case GatewayTypeEnum.ModbusTCP: { TCPMasterComponent TCP = new TCPMasterComponent(item, MysqlMethod) { MysqlMethod = MysqlMethod }; TCP.MyWorkState = true; Field4Components.Add(TCP); } break; } } } #endregion #region 建立按鈕物件 NavigationFrame = new NavigationFrame() { Dock = DockStyle.Fill }; NavigationFrame.Parent = ViewpanelControl; ButtonMethod = new ButtonMethod() { Form1 = this, navigationFrame = NavigationFrame }; ButtonMethod.AccordionLoad(accordionControl1, ButtonSetting); #endregion #region 建立畫面 foreach (var Componentitem in Field4Components) { foreach (var Absprotocolitem in Componentitem.ElectricAbsProtocols) { ElectricAbsProtocols.Add(Absprotocolitem); } } #region 主畫面 MainUserControl main = new MainUserControl(MysqlMethod, ElectricAbsProtocols) { Dock = DockStyle.Fill }; NavigationFrame.AddPage(main); Field4UserControls.Add(main); #endregion #region 報表畫面 ChartUserControl chart = new ChartUserControl(MysqlMethod) { Dock = DockStyle.Fill }; NavigationFrame.AddPage(chart); Field4UserControls.Add(chart); #endregion #region 月報表畫面 xtraReportUserControl = new XtraReportUserControl(MysqlMethod) { Dock = DockStyle.Fill }; NavigationFrame.AddPage(xtraReportUserControl); #endregion #endregion } timer1.Interval = 1000; timer1.Enabled = true; }