private void FormDisplayFields_Load(object sender, EventArgs e) { _listOrthoChartTabs = OrthoChartTabs.GetDeepCopy(true); _listOrthoChartTabLinks = OrthoChartTabLinks.GetDeepCopy(); LoadDisplayFields(); FillComboOrthoChartTabs(); FillGrids(); }
private void butSetupTabs_Click(object sender, EventArgs e) { FormOrthoChartSetup form = new FormOrthoChartSetup(); if (form.ShowDialog() != DialogResult.OK) { return; } List <OrthoChartTabFields> listOldTabDisplayFields = _listTabDisplayFields; _listTabDisplayFields = new List <OrthoChartTabFields>(); //The tab order may have changed. Also new tabs may have been added. Tabs were not removed, because they can only be hidden not deleted. //If orthocharttabs order changed or new tabs were added, then the cache was updated in FormOrthoChartSetup in OK click. _listOrthoChartTabs = OrthoChartTabs.GetDeepCopy(true); foreach (OrthoChartTab orthoChartTab in _listOrthoChartTabs) { OrthoChartTabFields orthoChartTabFieldsOld = listOldTabDisplayFields.FirstOrDefault( x => x.OrthoChartTab != null && x.OrthoChartTab.OrthoChartTabNum == orthoChartTab.OrthoChartTabNum); OrthoChartTabFields orthoChartTabFields = new OrthoChartTabFields(); orthoChartTabFields.OrthoChartTab = orthoChartTab; if (orthoChartTabFieldsOld == null) //Either a new tab was added or a hidden tab was un-hidden. { orthoChartTabFields.ListDisplayFields = new List <DisplayField>(); List <OrthoChartTabLink> listOrthoChartTabLinks = OrthoChartTabLinks.GetWhere( x => x.OrthoChartTabNum == orthoChartTab.OrthoChartTabNum); foreach (OrthoChartTabLink orthoChartTabLink in listOrthoChartTabLinks) { orthoChartTabFields.ListDisplayFields.AddRange(_listAllDisplayFields.FindAll(x => x.DisplayFieldNum == orthoChartTabLink.DisplayFieldNum)); } } else //The tab already existed. Maintain the display field names and order within the tab, especially if the tab order changed. { orthoChartTabFields.ListDisplayFields = orthoChartTabFieldsOld.ListDisplayFields; } _listTabDisplayFields.Add(orthoChartTabFields); } //Always add the orphaned OrthoChartTabFields back because they can not be affected from the Tab Setup window. _listTabDisplayFields.AddRange(listOldTabDisplayFields.FindAll(x => x.OrthoChartTab == null)); //Refresh the combo box and the grid because there is a chance that the user was viewing a different tab than the first in the list. FillComboOrthoChartTabs(); FillGrids(); }
private void LoadDisplayFields() { OrthoChartTabs.RefreshCache(); OrthoChartTabLinks.RefreshCache(); DisplayFields.RefreshCache(); _listAllDisplayFields = DisplayFields.GetAllAvailableList(DisplayFieldCategory.OrthoChart); _listTabDisplayFields = new List <OrthoChartTabFields>(); //Add all fields that are actively associated to a tab to our class wide list of tabs and fields. for (int i = 0; i < _listOrthoChartTabs.Count; i++) { OrthoChartTabFields orthoChartTabFields = new OrthoChartTabFields(); orthoChartTabFields.OrthoChartTab = _listOrthoChartTabs[i]; orthoChartTabFields.ListDisplayFields = new List <DisplayField>(); List <OrthoChartTabLink> listOrthoChartTabLinks = _listOrthoChartTabLinks.FindAll( x => x.OrthoChartTabNum == _listOrthoChartTabs[i].OrthoChartTabNum ); listOrthoChartTabLinks.OrderBy(x => x.ItemOrder); foreach (OrthoChartTabLink orthoChartTabLink in listOrthoChartTabLinks) { orthoChartTabFields.ListDisplayFields.AddRange(_listAllDisplayFields.FindAll(x => x.DisplayFieldNum == orthoChartTabLink.DisplayFieldNum)); } _listTabDisplayFields.Add(orthoChartTabFields); } //Add a dummy OrthoChartTabFields object to the list that represents available fields that are not part of any tab. //These "display fields" were previously used at least once. A patient has info for this field, then the office removed the field from all tabs. List <DisplayField> listOrphanedFields = _listAllDisplayFields.FindAll(x => x.DisplayFieldNum == 0 || !OrthoChartTabLinks.GetExists(y => y.DisplayFieldNum == x.DisplayFieldNum)); if (listOrphanedFields != null && listOrphanedFields.Count > 0) { OrthoChartTabFields orphanedFields = new OrthoChartTabFields(); orphanedFields.OrthoChartTab = null; //These are fields not associated to any tab. Purposefully use null. orphanedFields.ListDisplayFields = new List <DisplayField>(); orphanedFields.ListDisplayFields.AddRange(listOrphanedFields); _listTabDisplayFields.Add(orphanedFields); } }
private void butOK_Click(object sender, EventArgs e) { OrthoChartTabFields orphanedTab = _listTabDisplayFields.Find(x => x.OrthoChartTab == null); //No need to do anything if nothing changed and there are no 'orphaned' display fields to delete. if (!changed && (orphanedTab != null && orphanedTab.ListDisplayFields.All(x => x.DisplayFieldNum == 0))) { DialogResult = DialogResult.OK; return; } //Get all fields associated to a tab in order to sync with the database later. List <DisplayField> listAllFields = GetAllFields(false); if (listAllFields.Count(x => x.InternalName == "Signature") > 1) { MessageBox.Show(Lan.g(this, "Only one display field can be a signature field. Fields that have the signature field checkbox checked:") + " " + string.Join(", ", listAllFields.FindAll(x => x.InternalName == "Signature").Select(x => x.Description))); return; } //Ensure all new displayfields have a primary key so that tab links can be created below. Update existing displayfields. foreach (DisplayField df in listAllFields) { if (df.DisplayFieldNum == 0) //New displayfield { DisplayFields.Insert(df); } else //Existing displayfield. { DisplayFields.Update(df); } } DataValid.SetInvalid(InvalidType.DisplayFields); //Remove tab links which no longer exist. Update tab link item order for tab links which still belong to the same tab. List <OrthoChartTabLink> listOrthoChartTabLinks = OrthoChartTabLinks.GetDeepCopy(); for (int i = listOrthoChartTabLinks.Count - 1; i >= 0; i--) { OrthoChartTabLink orthoChartTabLink = listOrthoChartTabLinks[i]; OrthoChartTabFields orthoChartTabFields = _listTabDisplayFields.FirstOrDefault( x => x.OrthoChartTab != null && x.OrthoChartTab.OrthoChartTabNum == orthoChartTabLink.OrthoChartTabNum); if (orthoChartTabFields == null) { continue; //The tab was hidden and we are going to leave the tab links alone. } DisplayField df = orthoChartTabFields.ListDisplayFields.FirstOrDefault(x => x.DisplayFieldNum == orthoChartTabLink.DisplayFieldNum); if (df == null) //The tab link no longer exists (was removed). { listOrthoChartTabLinks.RemoveAt(i); } else //The tab link still exists. Update the link with any changes. { orthoChartTabLink.ItemOrder = orthoChartTabFields.ListDisplayFields.IndexOf(df); } } //Add new tab links which were just created. foreach (OrthoChartTabFields orthoChartTabFields in _listTabDisplayFields) { //Skip "orphaned" fields that just show in the available fields list. if (orthoChartTabFields.OrthoChartTab == null) { continue; } foreach (DisplayField df in orthoChartTabFields.ListDisplayFields) { OrthoChartTabLink orthoChartTabLink = listOrthoChartTabLinks.FirstOrDefault( x => x.OrthoChartTabNum == orthoChartTabFields.OrthoChartTab.OrthoChartTabNum && x.DisplayFieldNum == df.DisplayFieldNum); if (orthoChartTabLink != null) { continue; } orthoChartTabLink = new OrthoChartTabLink(); orthoChartTabLink.ItemOrder = orthoChartTabFields.ListDisplayFields.IndexOf(df); orthoChartTabLink.OrthoChartTabNum = orthoChartTabFields.OrthoChartTab.OrthoChartTabNum; orthoChartTabLink.DisplayFieldNum = df.DisplayFieldNum; listOrthoChartTabLinks.Add(orthoChartTabLink); } } //Delete any display fields that have a valid PK and are in the "orphaned" list. //This is fine to do because the field will show back up in the available list of display fields if a patient is still using the field. //This is because we link the ortho chart display fields by their name instead of by their PK. if (orphanedTab != null) //An orphaned list actually exists. //Look for any display fields that have a valid PK (this means the user removed this field from every tab and we need to delete it). { List <DisplayField> listFieldsToDelete = orphanedTab.ListDisplayFields.FindAll(x => x.DisplayFieldNum != 0); listFieldsToDelete.ForEach(x => DisplayFields.Delete(x.DisplayFieldNum)); } OrthoChartTabLinks.Sync(listOrthoChartTabLinks, OrthoChartTabLinks.GetDeepCopy()); DataValid.SetInvalid(InvalidType.OrthoChartTabs); DialogResult = DialogResult.OK; }
///<summary>Clears the current grid and fills from datatable. Do not call unless you have saved changes to database first.</summary> private void FillGrid() { if (tabControl.SelectedIndex == -1) { return; //This happens when the tab pages are cleared (updating the selected index). } //else if(_indexInitialTab!=0) { // tabControl.SelectedIndex=_indexInitialTab; // _indexInitialTab=0; //} Cursor = Cursors.WaitCursor; //Get all the corresponding fields from the OrthoChartTabLink table that are associated to the currently selected ortho tab. OrthoChartTab orthoChartTab = _listOrthoChartTabs[tabControl.SelectedIndex]; List <DisplayField> listSelectedTabDisplayFields = OrthoChartTabLinks.GetWhere(x => x.OrthoChartTabNum == orthoChartTab.OrthoChartTabNum) //Determines the number of items that will be returned .OrderBy(x => x.ItemOrder) //Each tab is ordered based on the ortho tab link entry .Select(x => _listOrthDisplayFields.FirstOrDefault(y => y.DisplayFieldNum == x.DisplayFieldNum)) //Project all corresponding display fields in order .Where(x => x != null) //Can happen when there is an OrthoChartTabLink in the database pointing to an invalid display field. .ToList(); //Casts the projection to a list of display fields _sigColIdx = -1; //Clear out the signature column index cause it will most likely change or disappear (switching tabs) int gridMainScrollValue = gridMain.ScrollValue; gridMain.BeginUpdate(); //Set the title of the grid to the title of the currently selected ortho chart tab. This is so that medical users don't see Ortho Chart. gridMain.Title = orthoChartTab.TabName; gridMain.Columns.Clear(); ODGridColumn col; //First column will always be the date. gridMain_CellLeave() depends on this fact. col = new ODGridColumn(Lan.g(this, "Date"), 70); gridMain.Columns.Add(col); foreach (DisplayField field in listSelectedTabDisplayFields) { string columnHeader = string.IsNullOrEmpty(field.DescriptionOverride) ? field.Description : field.DescriptionOverride; if (!string.IsNullOrEmpty(field.PickList)) { List <string> listComboOptions = field.PickList.Split(new string[] { "\r\n" }, StringSplitOptions.None).ToList(); col = new ODGridColumn(columnHeader, field.ColumnWidth, listComboOptions); } else { col = new ODGridColumn(columnHeader, field.ColumnWidth, true); if (field.InternalName == "Signature") { _sigColIdx = gridMain.Columns.Count; col.TextAlign = HorizontalAlignment.Center; col.IsEditable = false; } } col.Tag = field.Description; gridMain.Columns.Add(col); } gridMain.Rows.Clear(); ODGridRow row; foreach (KeyValuePair <DateTime, List <OrthoChart> > kvPair in _dictOrthoCharts) { row = new ODGridRow(); DateTime tempDate = kvPair.Key; row.Cells.Add(tempDate.ToShortDateString()); row.Tag = tempDate; bool areAllColumnsBlank = true; foreach (DisplayField field in listSelectedTabDisplayFields) { string cellValue = ""; if (field.InternalName != "Signature") { //Find the index of the corresponding column in our table via the column title. OrthoChart chart = kvPair.Value.Find(x => x.FieldName == field.Description); if (chart != null) { cellValue = chart.FieldValue; } } if (!string.IsNullOrEmpty(field.PickList)) { List <string> listComboOptions = field.PickList.Split(new string[] { "\r\n" }, StringSplitOptions.None).ToList(); int selectedIndex = listComboOptions.FindIndex(x => x == cellValue); row.Cells.Add(cellValue, selectedIndex); } else { row.Cells.Add(cellValue); } if (cellValue != "") { areAllColumnsBlank = false; } } if (!areAllColumnsBlank || _listDatesAdded.Contains(tempDate)) { gridMain.Rows.Add(row); } CanEditRow(tempDate); } gridMain.EndUpdate(); if (gridMainScrollValue == 0) { gridMain.ScrollToEnd(); } else { gridMain.ScrollValue = gridMainScrollValue; gridMainScrollValue = 0; } //Show the signature control if a signature display field is present on any tab. _showSigBox = _listOrthDisplayFields.Any(x => x.InternalName == "Signature"); signatureBoxWrapper.Visible = _showSigBox; //Hide the signature box if this tab does not have the signature column present. if (_showSigBox) { for (int i = 0; i < gridMain.Rows.Count; i++) { DisplaySignature(i, false); } signatureBoxWrapper.ClearSignature(); signatureBoxWrapper.Enabled = false; //We don't want it to be enabled unless the user has clicked on a row. _prevRow = -1; } Cursor = Cursors.Default; }