private static bool IsPowerObject(Excel.Range range, int pO, ref PowerObjectType pOType)
 {
     if (IsPowerStation(range, pO))
     {
         pOType = PowerObjectType.PowerStation; return(true);
     }
     if (IsJunction(range, pO))
     {
         pOType = PowerObjectType.Junction; return(true);
     }
     if (IsJunction1(range, pO))
     {
         pOType = PowerObjectType.Junction1; return(true);
     }
     if (IsJunction2(range, pO))
     {
         pOType = PowerObjectType.Junction2; return(true);
     }
     if (IsJunction12(range, pO))
     {
         pOType = PowerObjectType.Junction12; return(true);
     }
     if (IsJunction22(range, pO))
     {
         pOType = PowerObjectType.Junction22; return(true);
     }
     if (IsSeparator(range, pO))
     {
         pOType = PowerObjectType.Separator; return(true);
     }
     if (IsCabin(range, pO))
     {
         pOType = PowerObjectType.Cabin; return(true);
     }
     return(false);
 }
        private static bool GetProfiles(Excel.Range range, ref List <Profile> prof, string name)
        {
            Profile p = new Profile();

            p.Name = name;
            int ind = 0;

            int n = 0;
            int m = 0;
            int o = 0;

            int s      = 0;
            int pt     = 0;
            int j      = 0;
            int sector = 0;
            int c      = 0;

            while (range.Cells[n + 1, 1].Value != null)
            {
                n++;
            }
            while (range.Cells[m + 1, 3].Value != null)
            {
                m++;
            }
            while (range.Cells[o + 1, 5].Value != null)
            {
                o++;
            }
            while (range.Cells[ind + 3, 10].Value != null)
            {
                ind++;
            }

            for (int i = 0; i < ind; i++)
            {
                if (IsStop(range, i))
                {
                    s++;
                }
                if (IsPowerStation(range, i))
                {
                    pt++;
                }
                if (IsJunction(range, i))
                {
                    j++;
                }
                if (IsJunction1(range, i))
                {
                    j++;
                }
                if (IsJunction2(range, i))
                {
                    j++;
                }
                if (IsJunction12(range, i))
                {
                    j++;
                }
                if (IsJunction22(range, i))
                {
                    j++;
                }
                if (IsSeparator(range, i))
                {
                    sector++;
                }
                if (IsCabin(range, i))
                {
                    c++;
                }
            }

            int objectsCount = s + pt + j + sector + c;

            p.Profile1   = new float[2, n - 1];
            p.Profile2   = new float[2, m - 1];
            p.Limits     = new float[2, o - 1];
            p.ObjectType = new ObjectType[objectsCount];
            if (s != 0)
            {
                p.Stations    = new Station[s];
                p.PowerObject = new PowerObject[objectsCount - s];
                p.Tracks      = new Track[objectsCount - 1];
                for (int i = 0; i < p.PowerObject.Length; i++)
                {
                    p.PowerObject[i] = new PowerObject();
                }

                for (int i = 0; i < p.Stations.Length; i++)
                {
                    p.Stations[i] = new Station();
                }
            }

            for (int i = 0; i < n - 1; i++)
            {
                p.Profile1[0, i] = float.Parse(range.Cells[i + 2, 1].Value.ToString());
                p.Profile1[1, i] = float.Parse(range.Cells[i + 2, 2].Value.ToString());
            }
            for (int i = 0; i < m - 1; i++)
            {
                p.Profile2[0, i] = float.Parse(range.Cells[i + 2, 3].Value.ToString());
                p.Profile2[1, i] = float.Parse(range.Cells[i + 2, 4].Value.ToString());
            }
            for (int i = 0; i < o - 1; i++)
            {
                p.Limits[0, i] = float.Parse(range.Cells[i + 2, 5].Value.ToString());
                p.Limits[1, i] = float.Parse(range.Cells[i + 2, 6].Value.ToString());
            }

            int sInd    = 0;
            int pObjInd = 0;

            for (int i = 0; i < objectsCount; i++)
            {
                if (range.Cells[i + 3, 9].Value != null)
                {
                    if (IsStop(range, i))
                    {
                        p.Stations[sInd] = new Station();

                        string nameStation     = range.Cells[i + 3, 10].Value.ToString();
                        float  positionStation = float.Parse(range.Cells[i + 3, 9].Value.ToString());

                        p.Stations[sInd].Name     = nameStation;
                        p.Stations[sInd].Position = positionStation;

                        sInd++;
                    }

                    PowerObjectType pOType = new PowerObjectType();
                    if (IsPowerObject(range, i, ref pOType))
                    {
                        p.PowerObject[pObjInd]      = new PowerObject();
                        p.PowerObject[pObjInd].Type = pOType;

                        string nameObj  = range.Cells[i + 3, 10].Value.ToString();
                        float  position = float.Parse(range.Cells[i + 3, 9].Value.ToString());
                        int    rCount   = int.Parse(range.Cells[i + 3, 14].Value.ToString());
                        int    wCount   = int.Parse(range.Cells[i + 3, 29].Value.ToString());

                        p.PowerObject[pObjInd].Name      = nameObj;
                        p.PowerObject[pObjInd].Position  = position;
                        p.PowerObject[pObjInd].RailCount = rCount;
                        p.PowerObject[pObjInd].WingCount = wCount;

                        //elektryka
                        if (pOType == PowerObjectType.PowerStation)
                        {
                            p.PowerObject[pObjInd].Elec.RWewA = float.Parse(range.Cells[i + 3, 17].Value.ToString());
                            p.PowerObject[pObjInd].Elec.RPA   = float.Parse(range.Cells[i + 3, 18].Value.ToString());
                            p.PowerObject[pObjInd].Elec.RZA1  = float.Parse(range.Cells[i + 3, 19].Value.ToString());
                            p.PowerObject[pObjInd].Elec.RZA2  = float.Parse(range.Cells[i + 3, 20].Value.ToString());
                            //p.PowerObject[pObjInd].Elec.RZB1 = float.Parse(range.Cells[i + 3, 21].Value.ToString());
                            //p.PowerObject[pObjInd].Elec.RZB2 = float.Parse(range.Cells[i + 3, 22].Value.ToString());
                            p.PowerObject[pObjInd].Elec.UA     = float.Parse(range.Cells[i + 3, 23].Value.ToString());
                            p.PowerObject[pObjInd].SupplyCount = int.Parse(range.Cells[i + 3, 28].Value.ToString());
                            for (int rz = 0; rz < 4; rz++)
                            {
                                try
                                {
                                    p.PowerObject[pObjInd].Elec.RZ[rz] = float.Parse(range.Cells[i + 3, 19 + rz].Value.ToString());
                                }
                                catch
                                {
                                    p.PowerObject[pObjInd].Elec.RZ[rz] = 0;
                                }
                            }
                            for (int rz = 0; rz < 8; rz++)
                            {
                                try
                                {
                                    p.PowerObject[pObjInd].Elec.RZ[rz + 4] = float.Parse(range.Cells[i + 3, 30 + rz].Value.ToString());
                                }
                                catch
                                {
                                    p.PowerObject[pObjInd].Elec.RZ[rz + 4] = 0;
                                }
                            }
                        }
                        if (pOType == PowerObjectType.Junction)
                        {
                        }
                        if (pOType == PowerObjectType.Separator)
                        {
                            float rParallel = 0;
                            if (float.Parse(range.Cells[i + 3, 18].Value.ToString()) != null)
                            {
                                rParallel = float.Parse(range.Cells[i + 3, 18].Value.ToString());
                            }
                            p.PowerObject[pObjInd].Elec.RPA = rParallel;
                        }
                        if (pOType == PowerObjectType.Cabin)
                        {
                            if (p.PowerObject[pObjInd].RailCount == 2)
                            {
                                p.PowerObject[pObjInd].Elec.RK1 = float.Parse(range.Cells[i + 3, 24].Value.ToString());
                                p.PowerObject[pObjInd].Elec.RK2 = float.Parse(range.Cells[i + 3, 25].Value.ToString());
                                p.PowerObject[pObjInd].Elec.RK3 = float.Parse(range.Cells[i + 3, 26].Value.ToString());
                                p.PowerObject[pObjInd].Elec.RK4 = float.Parse(range.Cells[i + 3, 27].Value.ToString());
                            }
                        }
                        pObjInd++;
                    }

                    if (i != 0)
                    {
                        p.Tracks[i - 1] = new Track();

                        string nameTrack   = range.Cells[i + 3, 12].Value.ToString();
                        float  lengthTrack = float.Parse(range.Cells[i + 3, 13].Value.ToString());
                        int    railCount   = int.Parse(range.Cells[i + 3, 14].Value.ToString());
                        float  rS          = float.Parse(range.Cells[i + 3, 15].Value.ToString());
                        float  rT          = float.Parse(range.Cells[i + 3, 16].Value.ToString());

                        p.Tracks[i - 1].Name        = nameTrack;
                        p.Tracks[i - 1].Length      = lengthTrack;
                        p.Tracks[i - 1].Position    = float.Parse(range.Cells[i - 1 + 3, 9].Value.ToString());
                        p.Tracks[i - 1].ProfileName = name;
                        p.Tracks[i - 1].RailCount   = railCount;

                        p.Tracks[i - 1].RS = rS;
                        p.Tracks[i - 1].RT = rT;
                    }
                }

                if (range.Cells[i + 3, 11].Value.ToString() == "st" ||
                    range.Cells[i + 3, 11].Value.ToString() == "po" ||
                    range.Cells[i + 3, 11].Value.ToString() == "podg")
                {
                    p.ObjectType[i] = ObjectType.Station;
                }
                else
                {
                    p.ObjectType[i] = ObjectType.PowerObject;
                }
            }

            prof.Add(p);
            return(true);
        }