示例#1
0
        private void DatagridToDatatable()//переводим данные из datagrid в datatable. Далее из datatable в нашу коллекцию
        {
            DataTable dt = new DataTable();

            dt = ((DataView)MainGrid.ItemsSource).ToTable();
            List <UPI> uPIs = new List <UPI>();

            for (int i = 0; i < dt.Rows.Count; i++)
            {
                UPI pI = new UPI();
                pI.id           = dt.Rows[i][0].ToString();
                pI.name         = dt.Rows[i][1].ToString();
                pI.description  = dt.Rows[i][2].ToString();
                pI.danger       = dt.Rows[i][3].ToString();
                pI.target       = dt.Rows[i][4].ToString();
                pI.confidential = dt.Rows[i][5].ToString();
                pI.integriti    = dt.Rows[i][6].ToString();
                pI.access       = dt.Rows[i][7].ToString();
                uPIs.Add(pI);
            }

            List <UPI> rowsToDelete = new List <UPI>();

            for (int i = 0; i < uPIs.Count / 2; i++)
            {
                UPI upi = uPIs[i];
                rowsToDelete.Add(upi);
            }
            foreach (UPI upi in rowsToDelete)
            {
                uPIs.Remove(upi);
            }
            UPI.UPIs = uPIs;
        }
示例#2
0
        public static void Compare()
        {
            for (int i = 0; i < UPI.UPIs.Count; i++)
            {
                ObservableCollection <string> snewElems = new ObservableCollection <string>(); //элементы кооторые не совпадают
                ObservableCollection <string> soldElems = new ObservableCollection <string>(); //элементы кооторые не совпадают
                UPI olduPI = UPI.UPIs[i];
                UPI newupi = newUPIs[i];
                if (olduPI.id != newupi.id)
                {
                    snewElems.Add(newupi.id);
                    soldElems.Add(olduPI.id);
                    ids.Add(olduPI.id);
                }
                if (olduPI.name != newupi.name)
                {
                    snewElems.Add(newupi.name);
                    soldElems.Add(olduPI.name);
                    ids.Add(olduPI.id);
                }

                if (olduPI.description != newupi.description)
                {
                    snewElems.Add(newupi.description);
                    soldElems.Add(olduPI.description);
                    ids.Add(olduPI.id);
                }
                if (olduPI.danger != newupi.danger)
                {
                    snewElems.Add(newupi.danger);
                    soldElems.Add(olduPI.danger);
                    ids.Add(olduPI.id);
                }
                if (olduPI.target != newupi.target)
                {
                    snewElems.Add(newupi.target);
                    soldElems.Add(olduPI.target);
                    ids.Add(olduPI.id);
                }
                if (olduPI.confidential != newupi.confidential)
                {
                    snewElems.Add(newupi.confidential);
                    soldElems.Add(olduPI.confidential);
                    ids.Add(olduPI.id);
                }
                if (olduPI.integriti != newupi.integriti)
                {
                    snewElems.Add(newupi.integriti);
                    soldElems.Add(olduPI.integriti);
                    ids.Add(olduPI.id);
                }
                if (olduPI.access != newupi.access)
                {
                    snewElems.Add(newupi.access);
                    soldElems.Add(olduPI.access);
                    ids.Add(olduPI.id);
                }
                if (snewElems.Count != 0)
                {
                    newElements.Add(snewElems);
                    oldElements.Add(soldElems);
                    ids.Add(olduPI.id);
                }
            }
        }
示例#3
0
        public static ObservableCollection <string> stringsOut = new ObservableCollection <string>();//строки об изменении
        public static void Parse()
        {
            DataTable dt = new DataTable();

            ExcelPackage.LicenseContext = LicenseContext.NonCommercial;
            FileInfo      file      = new FileInfo(@Resourse.path);
            List <string> excelData = new List <string>();

            //read the Excel file as byte array

            byte[] bin = File.ReadAllBytes(@Resourse.path);

            //create a new Excel package in a memorystream
            MemoryStream   stream       = new MemoryStream(bin);
            ExcelPackage   excelPackage = new ExcelPackage(stream);
            ExcelWorksheet worksheet    = excelPackage.Workbook.Worksheets[0];

            foreach (var firstRowCell in worksheet.Cells[2, 1, 2, worksheet.Dimension.End.Column])
            {
                dt.Columns.Add(firstRowCell.Text);
            }


            for (int i = 3; i <= worksheet.Dimension.End.Row; i++)
            {
                var     row    = worksheet.Cells[i, 1, i, worksheet.Dimension.End.Column];
                DataRow newRow = dt.NewRow();
                //loop all cells in the row
                foreach (var cell in row)
                {
                    newRow[cell.Start.Column - 1] = cell.Text;
                }
                UPI upi = new UPI();//создаем новую запись в коллекции

                upi.id          = newRow[0].ToString();
                upi.name        = newRow[1].ToString();
                upi.description = newRow[2].ToString();
                upi.danger      = newRow[3].ToString();
                upi.target      = newRow[4].ToString();

                if (newRow[5].ToString() == "1")
                {
                    newRow[5] = "да";
                }
                else
                {
                    newRow[5] = "нет";
                }
                upi.confidential = newRow[5].ToString();
                if (newRow[6].ToString() == "1")
                {
                    newRow[6] = "да";
                }
                else
                {
                    newRow[6] = "нет";
                }
                upi.integriti = newRow[6].ToString();
                if (newRow[7].ToString() == "1")
                {
                    newRow[7] = "да";
                }
                else
                {
                    newRow[7] = "нет";
                }
                upi.access = newRow[7].ToString();
                newUPIs.Add(upi);//добавляем запись в коллекцию
            }
        }
示例#4
0
        public static List <string> columnNames = new List <string>();//для заголовка
        //public static int countOfRows;
        private static void FillDataTable()
        {
            //countOfRows = 0;
            DataTable dt = new DataTable();

            columnNames.Clear();

            ExcelPackage.LicenseContext = LicenseContext.NonCommercial;

            OpenFileDialog openFileDialog = new OpenFileDialog();

            if (openFileDialog.ShowDialog() == true)
            {
                Resourse.path = openFileDialog.FileName;
            }


            FileInfo      file      = new FileInfo(Resourse.path);
            List <string> excelData = new List <string>();

            //read the Excel file as byte array

            byte[] bin = File.ReadAllBytes(Resourse.path);

            //create a new Excel package in a memorystream
            MemoryStream   stream       = new MemoryStream(bin);
            ExcelPackage   excelPackage = new ExcelPackage(stream);
            ExcelWorksheet worksheet    = excelPackage.Workbook.Worksheets[0];

            foreach (var firstRowCell in worksheet.Cells[2, 1, 2, worksheet.Dimension.End.Column])
            {
                columnNames.Add(firstRowCell.Text);
            }

            //if(columnNames.Count != 8)
            //{
            //columnNames.RemoveAt(columnNames.Count - 1);
            //columnNames.RemoveAt(columnNames.Count - 1);
            //}
            foreach (var item in columnNames)
            {
                dt.Columns.Add(item);
            }

            for (int i = 3; i <= worksheet.Dimension.End.Row; i++)
            {
                var     row    = worksheet.Cells[i, 1, i, worksheet.Dimension.End.Column];
                DataRow newRow = dt.NewRow();
                //loop all cells in the row
                foreach (var cell in row)
                {
                    newRow[cell.Start.Column - 1] = cell.Text;
                }
                UPI upi = new UPI();//создаем новую запись в коллекции

                upi.id          = newRow[0].ToString();
                upi.name        = newRow[1].ToString();
                upi.description = newRow[2].ToString();
                upi.danger      = newRow[3].ToString();
                upi.target      = newRow[4].ToString();

                if (newRow[5].ToString() == "1")
                {
                    newRow[5] = "да";
                }
                else
                {
                    newRow[5] = "нет";
                }
                upi.confidential = newRow[5].ToString();
                if (newRow[6].ToString() == "1")
                {
                    newRow[6] = "да";
                }
                else
                {
                    newRow[6] = "нет";
                }
                upi.integriti = newRow[6].ToString();
                if (newRow[7].ToString() == "1")
                {
                    newRow[7] = "да";
                }
                else
                {
                    newRow[7] = "нет";
                }
                upi.access = newRow[7].ToString();
                dt.Rows.Add(newRow);
                UPI.UPIs.Add(upi);//добавляем запись в коллекцию
            }
            if (columnNames.Count > 8)
            {
                columnNames.RemoveAt(columnNames.Count - 1);
                columnNames.RemoveAt(columnNames.Count - 1);
            }
        }