private void CloseWidget(UserControlDashboardWidget widget, EventArgs e) { if (widget == null) { return; } Controls.Remove(widget); if (ListOpenWidgets.Count == 0) { IsInitialized = false; _actionDashboardContentsChanged?.Invoke(); if (!_isLoggingOff) { _actionDashboardClosing?.Invoke(); } _threadRefresh?.QuitSync(100); } }
///<summary>Adds a new Widget to the current Dashboard container.</summary> public bool AddWidget(SheetDef sheetDefWidget) { if (sheetDefWidget == null || !Security.IsAuthorized(Permissions.DashboardWidget, sheetDefWidget.SheetDefNum, true)) { return(false); } UserControlDashboardWidget widget = null; this.InvokeIfRequired(() => { //Trying to open a widget that is already open. if (ListOpenWidgets.Any(x => x.SheetDefWidget.SheetDefNum == sheetDefWidget.SheetDefNum)) { return; } widget = new UserControlDashboardWidget(sheetDefWidget); widget.WidgetClosed += CloseWidget; widget.RefreshClicked += UserControlDashboardWidgetRefresh_Fired; widget.Anchor = ((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)); if (!widget.IsHandleCreated) { IntPtr handle = widget.Handle; //Ensure the handle for this object is created on the Main thread. } }); if (widget != null && widget.Initialize()) { this.InvokeIfRequired(() => { widget.Location = new Point(0, 0); widget.Anchor = (System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left); Controls.Add(widget); widget.BringToFront(); }); } else //Failed to open the widget, either due to lack of permission or failure to get the widget's SheetDef. { return(false); } _actionDashboardContentsChanged?.Invoke(); return(true); }
private void butImport_Click(object sender, EventArgs e) { Cursor = Cursors.WaitCursor; OpenFileDialog openDlg = new OpenFileDialog(); string initDir = PrefC.GetString(PrefName.ExportPath); if (Directory.Exists(initDir)) { openDlg.InitialDirectory = initDir; } if (openDlg.ShowDialog() != DialogResult.OK) { Cursor = Cursors.Default; return; } try { //ImportCustomSheetDef(openDlg.FileName); SheetDef sheetdef = new SheetDef(); XmlSerializer serializer = new XmlSerializer(typeof(SheetDef)); if (openDlg.FileName != "") { if (!File.Exists(openDlg.FileName)) { throw new ApplicationException(Lan.g("FormSheetDefs", "File does not exist.")); } try { using (TextReader reader = new StreamReader(openDlg.FileName)) { sheetdef = (SheetDef)serializer.Deserialize(reader); } } catch { throw new ApplicationException(Lan.g("FormSheetDefs", "Invalid file format")); } } sheetdef.IsNew = true; //the Form that called this is not the PatientDashboard but the sheetdefs are of type PatientDashboard if (!_isOpenedFromDashboardSetup && SheetDefs.IsDashboardType(sheetdef)) { throw new ApplicationException(Lan.g("FormSheetDefs", "Sheets of type '" + sheetdef.SheetType.GetDescription() + "' cannot be imported from Sheets. Use Dashboard Setup instead.")); } //the Form that called this is the PatientDashboard but the sheetdefs are not of type PatientDashboard if (_isOpenedFromDashboardSetup && !SheetDefs.IsDashboardType(sheetdef)) { throw new ApplicationException(Lan.g("FormSheetDefs", "Sheets of type '" + sheetdef.SheetType.GetDescription() + "' cannot be imported from Dashboard Setup. Use Sheets instead.")); } List <SheetFieldDef> listUnsupportedSheetDefs = new List <SheetFieldDef>(); for (int i = sheetdef.SheetFieldDefs.Count - 1; i >= 0; i--) { SheetFieldDef fieldDef = sheetdef.SheetFieldDefs[i]; //If user is importing a Dashboard SheetDef with SheetDefFields that are not supported by Dashboards, remove them from the field list if (SheetDefs.IsDashboardType(sheetdef) && !UserControlDashboardWidget.IsSheetFieldDefSupported(fieldDef)) { listUnsupportedSheetDefs.Add(fieldDef); sheetdef.SheetFieldDefs.Remove(fieldDef); } //Users might be importing a sheet that was developed in an older version that does not support ItemColor. Default them to black if necessary. //Static text, lines, and rectangles are the only field types that support ItemColor. if (fieldDef.FieldType != SheetFieldType.StaticText && fieldDef.FieldType != SheetFieldType.Line && fieldDef.FieldType != SheetFieldType.Rectangle) { continue; } //ItemColor will be set to "Empty" if this is a sheet that was exported from a previous version that didn't support ItemColor. //Color.Empty will actually draw but will be 'invisible' to the user. For this reason, we considered this a bug and defaulted the color to black. if (fieldDef.ItemColor == Color.Empty) { fieldDef.ItemColor = Color.Black; //Old sheet behavior was to always draw these field types in black. } } if (!listUnsupportedSheetDefs.IsNullOrEmpty()) { Cursor = Cursors.Default; //If the user was importing from the Dashboard with SheetDef fields that were unsupported, use the previously saved list to //present them a message about the fields that will be lost and see if they wish to proceed. if (!MsgBox.Show("FormSheetDefs", MsgBoxButtons.YesNo, "Field(s): " + string.Join(",", listUnsupportedSheetDefs.Select(x => x.FieldName + "(" + x.FieldType + ")")) //Displays as FieldName(FeildType) + " are not supported by Patient Dashboards and will not be imported.\r\n" + "Continue?")) { return; } } if (SheetDefs.IsDashboardType(sheetdef)) { //PatImage fields use FieldName as a FK to the Patient Image definition. Since this FK may not be accurate across databases, determine //which Image Category Definition is set as PatImage SheetDefs.SetPatImageFieldNames(sheetdef); } SheetDefs.InsertOrUpdate(sheetdef, isOldSheetDuplicate: sheetdef.DateTCreated.Year < 1880); HasSheetsChanged = true; //Flag as true so we know to refresh the grid in FormSheetDefs.cs ImportedSheetDefNum = sheetdef.SheetDefNum; //Set this so when we return to FormSheetDefs.cs we can select that row. } catch (ApplicationException ex) { Cursor = Cursors.Default; MessageBox.Show(ex.Message); return; } Cursor = Cursors.Default; MsgBox.Show(this, "Imported."); }
private void UserControlDashboardWidgetRefresh_Fired(UserControlDashboardWidget sender, EventArgs e) { ODProgress.ShowAction(() => RefreshDashboard(), "Refreshing Dashboard."); }