Beispiel #1
0
        private static void StartProtocolGenerate(DistanceGroupAmount amnt, StartTimer timer, List <string> lHeaders = null)
        {
            //all distances
            List <Distance> lDistances = База.DbList;

            //get all protocol variants
            Dictionary <DistanceLevels, List <DistanceGroupType> > lVariants = new Dictionary <DistanceLevels, List <DistanceGroupType> >();

            foreach (Distance d in lDistances)
            {
                DistanceLevels level = d.Level;
                if (!lVariants.ContainsKey(level))
                {
                    lVariants.Add(level, new List <DistanceGroupType>());
                }

                foreach (KeyValuePair <Structs.GroupIndexAmountStruct, DistanceGroup> kvPair in d.Groups)
                {
                    if (!lVariants[level].Contains(kvPair.Value.Type))
                    {
                        lVariants[level].Add(kvPair.Value.Type);
                    }
                }
            }

            //generate protocol for each distance type
            foreach (KeyValuePair <DistanceLevels, List <DistanceGroupType> > kvPair in lVariants)
            {
                foreach (DistanceGroupType type in kvPair.Value)
                {
                    Distance distance = База.GetOneDistance(amnt, kvPair.Key, type);

                    if (distance.Groups.Count > 0)
                    {
                        string nameSuffix = kvPair.Key.ToString() + "_" + EnumCasters.GroupTypeStringRepresent(type);

                        StartProtocolGenerator generator = new StartProtocolGenerator(amnt, timer);

                        if (lHeaders != null)
                        {
                            generator.LHeaders = lHeaders;
                        }

                        generator.Create(distance, suffix: nameSuffix);

                        timer.Reset();
                    }
                }
            }
        }
Beispiel #2
0
        //todo: Write data to DataBase
        internal static void ImportToBase()
        {
            // If the proccess already started then just exit
            if (inProgress)
            {
                return;
            }

            InWork(true);

            // List of distances. All new created distances and their link will be added here
            lDistances = База.DbList;

            //try-catch. Get data from list. If there is some error then show alert msg to user
            try
            {
                GetData();
            }
            catch (Exception)
            {
                throw;
            }

            //convert gotten data to models. If there is some error then show alert msg to user
            try
            {
                ConvertDataToModels();

                //if entity imported
                База.IncrementEntriesCount(nPersons);

                //methods finished successfuly
                //AlertBoxes.AlertMsg("ГОТОВО!");
            }
            catch (GroupFullException e)
            //If group is already full but user wants add new person
            {
                AlertBoxes.GroupFullAlert(e.GroupIndexAmount);
            }
            catch (InvalidFieldTypeException e)
            //If field type is incorrect. For example, in the field "group index" is written not numbers
            {
                //get the cell where the field is incorrect
                ExcelInterop.Range rng = oSheet.Range[sDataCellStart].Offset[e.IRow, e.ICol];

                //select this cell
                rng.Activate();

                //show alert message to user
                string cellName = "[строка - " + rng.Row + ", столбец - " + rng.Column + "]";
                AlertBoxes.FieldTypeAlert(requiredType: e.RequiredType, cell: cellName);
            }
            catch (GroupNotFullException e)
            //If some group is not full
            {
                AlertBoxes.GroupNotFullAlert(e.StructGroupIndex.GroupIndex, e.StructGroupIndex.Amnt);
            }
            catch (GroupAlreadyExistsException e)
            {
                AlertBoxes.GroupAlreadyExistsAlert(e.Struc, e.Group);
            }

            InWork(false);
        }