Exemple #1
0
        ///<summary>Updates the in memory dictionary with any changes made to the current locationID for each clinic before showing the next one.</summary>
        private void SaveClinicCurProgramPropertiesToDict()
        {
            //First check if Headquarters (default) is selected.
            if (_clinicNumCur == 0)
            {
                //Headquarters is selected so only update the location ID (might have changed) on all other location ID properties that match the "old" location ID of HQ.
                if (_dictLocationIDs.ContainsKey(_clinicNumCur))
                {
                    //Get the location ID so that we correctly update all program properties with a matching location ID.
                    string locationIdOld = _dictLocationIDs[_clinicNumCur].PropertyValue;
                    foreach (KeyValuePair <long, ProgramProperty> item in _dictLocationIDs)
                    {
                        ProgramProperty ppCur = item.Value;
                        if (ppCur.PropertyValue == locationIdOld)
                        {
                            ppCur.PropertyValue = textLocationID.Text;
                        }
                    }
                }
                return;                //No other clinic specific changes could have been made, we need to return.
            }
            //Update or Insert clinic specific properties into memory
            ProgramProperty ppLocationID = new ProgramProperty();

            if (_dictLocationIDs.ContainsKey(_clinicNumCur))
            {
                ppLocationID = _dictLocationIDs[_clinicNumCur]; //Override the database's property with what is in memory.
            }
            else                                                //Get default programproperty from db.
            {
                ppLocationID = ProgramProperties.GetListForProgramAndClinicWithDefault(_progCur.ProgramNum, _clinicNumCur)
                               .FirstOrDefault(x => x.PropertyDesc == Podium.PropertyDescs.LocationID);
            }
            if (ppLocationID.ClinicNum == 0)           //No program property for current clinic, since _clinicNumCur!=0
            {
                ProgramProperty ppLocationIDNew = ppLocationID.Copy();
                ppLocationIDNew.ProgramPropertyNum = 0;
                ppLocationIDNew.ClinicNum          = _clinicNumCur;
                ppLocationIDNew.PropertyValue      = textLocationID.Text;
                if (!_dictLocationIDs.ContainsKey(_clinicNumCur))                 //Should always happen
                {
                    _dictLocationIDs.Add(_clinicNumCur, ppLocationIDNew);
                }
                return;
            }
            //At this point we know that the clinicnum isn't 0 and the database has a property for that clinicnum.
            if (_dictLocationIDs.ContainsKey(_clinicNumCur))             //Should always happen
            {
                ppLocationID.PropertyValue      = textLocationID.Text;
                _dictLocationIDs[_clinicNumCur] = ppLocationID;
            }
            else
            {
                _dictLocationIDs.Add(_clinicNumCur, ppLocationID);               //Should never happen.
            }
        }
        ///<summary>Opens a form where the user can select an option from a combo box for a program poperty.</summary>
        ///<param name="listValuesForDb">The value that should be stored in the db for the corresponding display item that is selected. This list should
        ///have the same number of items as listForDisplay.</param>
        ///<param name="listForDisplay">The value that will be displayed to the user in the combo box. This list should have the same number of items
        ///as listValuesForDb.</param>
        private void ShowComboBoxForProgramProperty(ProgramProperty programProperty, List <string> listValuesForDb, List <string> listForDisplay
                                                    , string prompt)
        {
            ProgramProperty programPropertyOld = programProperty.Copy();
            InputBox        inputBox           = new InputBox(prompt, listForDisplay, listValuesForDb.FindIndex(x => x == programProperty.PropertyValue));

            inputBox.ShowDialog();
            if (inputBox.DialogResult != DialogResult.OK || inputBox.SelectedIndex == -1 ||
                listValuesForDb[inputBox.SelectedIndex] == programPropertyOld.PropertyValue)
            {
                return;
            }
            programProperty.PropertyValue = listValuesForDb[inputBox.SelectedIndex];
            ProgramProperties.Update(programProperty, programPropertyOld);
            ProgramProperties.RefreshCache();
            FillGrid();
        }