Exemple #1
0
        public static void RemoveOtherSheets()
        {
            List <ExcelInter.Worksheet> toDelete = new List <ExcelInter.Worksheet>();

            foreach (ExcelInter.Worksheet sh in Globals.ThisWorkbook.Worksheets)
            {
                if (!Globals.SheetNames.OriginalSheetNames.Contains(sh.Name))
                {
                    toDelete.Add(sh);
                }
            }


            if (AlertBoxes.SureDeleteAllSheetAlert() == System.Windows.Forms.DialogResult.Yes)
            {
                Globals.ThisWorkbook.Application.DisplayAlerts = false;
                toDelete.ForEach(sh => sh.Delete());
                Globals.ThisWorkbook.Application.DisplayAlerts = true;
            }
        }
Exemple #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);
        }