Пример #1
0
        private void AddALayers_Click(object sender, RoutedEventArgs e)
        {
            if (DocumentsListBox.SelectedItems != null)
            {
                DS_Layers     dS_Layers   = new DS_Layers();
                List <string> ExistLayers = new List <string>();

                int i = 0;

                foreach (var item in DocumentsListBox.SelectedItems)
                {
                    string itemName        = (item as LayerField).Code;
                    string itemDescription = (item as LayerField).Description;
                    dS_Layers.CreateAndAssignALayer(itemName, itemDescription);

                    if (dS_Layers.IfLayerCreated == true)
                    {
                        i++;
                    }
                    else
                    {
                        ExistLayers.Add(itemName);
                    }
                }
                if (i != 0)
                {
                    MessageBox.Show($"{i} layers have been created successfully!\n");

                    if (ExistLayers.Count != 0)
                    {
                        Log log = new Log();
                        log.OutputExistingLayerList(ExistLayers, "layers list");
                    }
                }
                else
                {
                    MessageBox.Show("Selected layers names alredy exist in current document.");
                }
            }
            else
            {
                MessageBox.Show("Chose item at first.");
            }
        }
        private void CreateLayer_Click(object sender, RoutedEventArgs e)
        {
            if (IfLayerCodeFormatCorrect() == false)
            {
                MessageBox.Show("Error ocured! \nFields 1 and 2 are mandatory fields!");
                return;
            }

            string delimiter = "-";
            string LayerCode = LayerCodesList.Aggregate((i, j) => i + delimiter + j);

            string[] NewLayerDescriptionsList = new string[10];
            NewLayerDescriptionsList = LayerDescriptionsList.Where(c => c != null & c != "").ToArray();
            string LayerDescription = NewLayerDescriptionsList.Aggregate((i, j) => i + delimiter + j);

            if (IfNewNameExistInDB(LayerCode) == true)
            {
                MessageBox.Show("This layer alredy exist in DB.\nEnter another name.");
                return;
            }

            InsertOneDoc(LayerCode, LayerDescription);
            DS_Layers dS_Layers = new DS_Layers();

            dS_Layers.CreateAndAssignALayer(LayerCode, LayerDescription);

            //Check if layer added to layers list
            if (dS_Layers.IfLayerCreated == true)
            {
                MessageBox.Show("Layer\n'" + LayerCode + "'\nhas been added to DB and layers list succefully!");
            }
            else
            {
                MessageBox.Show("Layer\n'" + LayerCode + "'\nhas been added to DB succefully!\n It already exist in layers list.");
            }


            //EmptyFields();
        }