public static IdentifiedObject CreateEntity(long globalId)
        {
            short type = ModelCodeHelper.ExtractTypeFromGlobalId(globalId);

            IdentifiedObject io = null;

            switch ((DMSType)type)
            {
            case DMSType.ANALOG:
                io = new Analog(globalId);
                break;

            case DMSType.DISCRETE:
                io = new Discrete(globalId);
                break;

            case DMSType.GENERATOR:
                io = new Generator(globalId);
                break;

            case DMSType.SUBSTATION:
                io = new Substation(globalId);
                break;

            case DMSType.BATTERY_STORAGE:
                io = new BatteryStorage(globalId);
                break;

            case DMSType.GEOGRAFICAL_REGION:
                io = new GeographicalRegion(globalId);
                break;

            default:
                string message = String.Format("Failed to create entity because specified type ({0}) is not supported.", type);
                CommonTrace.WriteTrace(CommonTrace.TraceError, message);
                throw new Exception(message);
            }

            return(io);
        }
        private void dgStorage_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            tableType tt = (tableType)dgStorage.SelectedItem;
            BatteryStorage storage = new BatteryStorage();
               if(tt!=null) storage = toStorage((tableType)dgStorage.SelectedItem);
            try
            {
                bsID.Text = storage.ID.ToString();
                if (tt != null) cbType.SelectedItem = tt.type;
                else cbType.SelectedIndex = 0;
                btStor.Text = storage.storageNumber.ToString();
                if (tt != null)
                {
                    if (calendar.SelectedDate == null)
                    {
                        cbPeriod.SelectedItem = cbi2;
                    }
                    else
                    {
                        cbPeriod.SelectedItem = cbi4;
                    }
                }
                changePeriodsView();
            }
            catch (Exception)
            {

            }
        }