Ejemplo n.º 1
0
        private void button4_Click(object sender, EventArgs e)
        {
            openFileDialog1.ShowDialog();
            String    fileName = openFileDialog1.FileName;
            ExcelUtil exc      = new ExcelUtil();

            exc.Open(fileName);
            //exc.AddWorkbook();
            exc.Worksheet("Sheet1");


            Object[,] obj = exc.ReadCellByRange("A1:Y806");
            Console.WriteLine(obj.GetUpperBound(0));
            Console.WriteLine(obj.GetUpperBound(1));

            NumberToLetterUtil numUtil = new NumberToLetterUtil();

            for (int x = 1; x < obj.GetUpperBound(0); x++)
            {
                for (int y = 1; y < obj.GetUpperBound(1); y++)
                {
                    Console.WriteLine(numUtil.getLetterByNumber(y) + x + " = " + obj[x, y]);
                }
            }

            //for (int cntr = 5; cntr < 500; cntr++) {
            //    Console.WriteLine(exc.ReadCell("A" + cntr.ToString()));
            //}
        }
Ejemplo n.º 2
0
        public virtual void ImportXls(DataTable dt)
        {
            int    rowcnt   = 1;
            string keyfield = dt.Columns[0].Caption;

            Object[,] data = readCell(1, ++rowcnt, dt.Columns.Count);
            string tmp = "";

            while (data[1, 1] != null)
            {
                tmp += data[1, 1].ToString() + "{}";

                DataRow[] dr = dt.Select(keyfield + "='" + data[1, 1].ToString() + "'");
                if (dr != null && dr.Length > 0 && (!data[1, 1].ToString().Equals("-1")))
                {
                    dr[0].BeginEdit();
                    for (int i = 0; i < data.GetUpperBound(1); i++)
                    {
                        if (data[1, i + 1] != null)
                        {
                            dr[0][i] = data[1, i + 1];
                        }
                    }

                    dr[0].EndEdit();
                }
                else
                {
                    DataRow r = dt.NewRow();
                    r.BeginEdit();
                    for (int i = 0; i < data.GetUpperBound(1); i++)
                    {
                        if (data[1, i + 1] != null)
                        {
                            if (dt.Columns[i].DataType == typeof(DateTime))
                            {
                                DateTime dati;
                                String   s = data[1, i + 1].ToString();
                                // MessageBox.Show(s);
                                if (DateTime.TryParse(s, out dati))
                                {
                                    r[i] = dati;
                                }
                            }
                            else
                            {
                                r[i] = data[1, i + 1];
                            }
                        }
                    }
                    r.EndEdit();
                    dt.Rows.Add(r);
                }
                data = readCell(1, ++rowcnt, dt.Columns.Count);
            }
        }
Ejemplo n.º 3
0
 ///<summary>
 ///Creates a XArrayHelper and copies the values from an object array.
 ///</summary>
 ///<param name="array">The source array to be copied.</param>
 public void LoadRows(Object[,] array)
 {
     this.RedimXArray(new int[] { array.GetUpperBound(0), array.GetUpperBound(1) }, new int[] { array.GetLowerBound(0), array.GetLowerBound(1) });
     for (int row = array.GetLowerBound(0); row <= array.GetUpperBound(0); row++)
     {
         for (int col = array.GetLowerBound(1); col <= array.GetUpperBound(1); col++)
         {
             this.SetValue(array[row, col], row, col);
         }
     }
 }
Ejemplo n.º 4
0
        private void importSheet(PipelineContext ctx, IDatasourceSink sink, IStreamProvider elt, Worksheet sheet)
        {
            Range used      = sheet.UsedRange;
            Range usedCells = used.Cells;

            if (usedCells == null)
            {
                return;
            }

            Object[,] c = (Object[, ])used.Cells.Value2;
            if (c == null)
            {
                return;
            }

            int lo1 = c.GetLowerBound(0);
            int hi1 = c.GetUpperBound(0);
            int lo2 = c.GetLowerBound(1);
            int hi2 = c.GetUpperBound(1);

            List <String> headers = new List <string>();

            if (headersAt >= 0)
            {
                int headersRow = lo1 + headersAt;
                if (headersRow <= hi1)
                {
                    int h = 0;
                    for (int j = lo2; j <= hi2; j++)
                    {
                        for (; h < j; h++)
                        {
                            headers.Add(null);
                        }
                        headers.Add(_toString(c[headersRow, j]));
                        h++;
                    }
                }
            }

            var keys = prepareEventKeys(sheet.Name, hi2 + 1, headers);

            for (int i = lo1 + startAt; i <= hi1; i++)
            {
                for (int j = lo2; j <= hi2; j++)
                {
                    sink.HandleValue(ctx, keys[j], c[i, j]);
                }
                sink.HandleValue(ctx, keys[0], null);
                ctx.IncrementEmitted();
            }
        }
Ejemplo n.º 5
0
        public static T[] myArray <T>(Object[,] O)
        {
            if ((O.GetLowerBound(1) == O.GetUpperBound(1)) & (O.GetUpperBound(0) != O.GetUpperBound(1)))
            {
                List <T> l = new List <T>();
                for (int i = O.GetLowerBound(0); i <= O.GetUpperBound(0); i++)
                {
                    int firstCol = O.GetLowerBound(1);
                    l.Add((T)O[i, firstCol]);
                }
                return(l.ToArray <T>());
            }

            if ((O.GetLowerBound(0) == O.GetUpperBound(0)) & (O.GetUpperBound(0) != O.GetUpperBound(1)))
            {
                List <T> l = new List <T>();
                for (int i = O.GetLowerBound(1); i <= O.GetUpperBound(1); i++)
                {
                    int firstCol = O.GetLowerBound(0);
                    l.Add((T)O[firstCol, i]);
                }
                return(l.ToArray <T>());
            }
            return(null);
        }
Ejemplo n.º 6
0
        private void button5_Click(object sender, EventArgs e)
        {
            Demand             demand    = (Demand)propertyGrid.SelectedObject;
            NumberToLetterUtil converter = new NumberToLetterUtil();

            NumberToLetterUtil numUtil = new NumberToLetterUtil();

            if (demand.RowSequenceType == RowSequenceType.Range)
            {
                try
                {
                    ExcelUtil excel = new ExcelUtil();
                    excel.Open(demand.Path + "/" + demand.FileName);
                    excel.Worksheet(demand.WorkSheet);

                    Object[,] obj = excel.ReadCellByRange(demand.RowRangeFrom + ":" + demand.RowRangeTo);
                    for (int row = 1; row <= obj.GetUpperBound(0); row++)
                    {
                        for (int column = 1; column <= obj.GetUpperBound(1); column++)
                        {
                            Console.WriteLine(numUtil.getLetterByNumber(column) + "[" + numUtil.getNumberByLetter(numUtil.getLetterByNumber(column)) + "]" + row + " = " + obj[row, column]);
                        }
                    }
                    excel.Close();
                }
                catch (WorksheetNotFoundException wnfe)
                {
                    MessageBox.Show(null, wnfe.Message, "Error Window", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                catch (RangeInvalidException rie) {
                    MessageBox.Show(null, rie.Message, "Error Window", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            else if (demand.RowSequenceType == RowSequenceType.Collection)
            {
                try
                {
                    readDDPDemandByCollection(demand);
                }
                catch (NullReferenceException nre)
                {
                    MessageBox.Show(null, nre.Message.ToString(), "Error Window", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }


            Console.WriteLine("Success!");
            Console.WriteLine(demand.Region);
        }
Ejemplo n.º 7
0
        private SRMData SetDataThreeColumn(Object[,] dataCells, bool cumulative)
        {
            int dsize = dataCells.GetUpperBound(0) - dataCells.GetLowerBound(0) + 1;

            double[] time  = new double[dsize];
            int[]    fault = new int[dsize];
            int[]    type  = new int[dsize];
            double   prev  = 0;

            for (int i = 0, j = dataCells.GetLowerBound(0); i < dsize; i++, j++)
            {
                double tmp = System.Convert.ToDouble(dataCells[j, 1]);
                if (cumulative)
                {
                    time[i] = tmp - prev;
                    prev    = tmp;
                }
                else
                {
                    time[i] = tmp;
                }
                fault[i] = System.Convert.ToInt32(dataCells[j, 2]);
                type[i]  = System.Convert.ToInt32(dataCells[j, 3]);
            }
            SRMData fdat = new SRMData();

            fdat.SetData(time, fault, type);
            return(fdat);
        }
Ejemplo n.º 8
0
        public virtual void ImportXls(System.Data.DataTable dt)
        {
            int    rowcnt   = 1;
            string keyfield = dt.Columns[0].Caption;

            Object[,] data = readCell(1, ++rowcnt, dt.Columns.Count);
            string tmp = "";

            while (data[1, 1] != null)
            {
                tmp += data[1, 1].ToString() + "{}";

                System.Data.DataRow[] dr = dt.Select(keyfield + "='" + data[1, 1].ToString() + "'");
                if (dr != null && dr.Length > 0)
                {
                    dr[0].BeginEdit();
                    for (int i = 0; i < data.GetUpperBound(1); i++)
                    {
                        if (data[1, i + 1] != null)
                        {
                            dr[0][i] = data[1, i + 1];
                        }
                    }

                    dr[0].EndEdit();
                }
                else
                {
                    System.Data.DataRow r = dt.NewRow();
                    r.BeginEdit();
                    for (int i = 0; i < data.GetUpperBound(1); i++)
                    {
                        if (data[1, i + 1] != null)
                        {
                            r[i] = data[1, i + 1];
                        }
                    }
                    r.EndEdit();
                    dt.Rows.Add(r);
                }
                data = readCell(1, ++rowcnt, dt.Columns.Count);
            }
        }
Ejemplo n.º 9
0
        public override void ImportXls(DataTable dt)
        {
            int rowcnt = 1;

            Object[,] data = readCell(1, ++rowcnt, dt.Columns.Count);
            string tmp = "";

            while (data[1, 1] != null)
            {
                tmp += data[1, 1].ToString() + "{}";

                DataRow[] dr = dt.Select("staf_ref='" + data[1, 1].ToString() + "'");
                if (dr != null && dr.Length > 0)
                {
                    dr[0].BeginEdit();
                    for (int i = 0; i < data.GetUpperBound(1); i++)
                    {
                        if (data[1, i + 1] != null)
                        {
                            dr[0][i] = data[1, i + 1];
                        }
                    }

                    dr[0].EndEdit();
                }
                else
                {
                    DataRow r = dt.NewRow();
                    r.BeginEdit();
                    for (int i = 0; i < data.GetUpperBound(1); i++)
                    {
                        if (data[1, i + 1] != null)
                        {
                            r[i] = data[1, i + 1];
                        }
                    }
                    r.EndEdit();
                    dt.Rows.Add(r);
                }
                data = readCell(1, ++rowcnt, dt.Columns.Count);
            }
        }
Ejemplo n.º 10
0
        GetRowCount
        (
            Object [,] aoColumnValues
        )
        {
            Debug.Assert(aoColumnValues != null);
            AssertValid();

            return(aoColumnValues.GetUpperBound(0) -
                   aoColumnValues.GetLowerBound(0) + 1);
        }
Ejemplo n.º 11
0
        protected static void CheckValidIndex(Object[,] array,
                                              Int32 index1,
                                              Int32 index2,
                                              String argument1Name,
                                              String argument2Name)
        {
            if (IsNull(array) ||
                (index1 < 0) ||
                (index1 > array.GetUpperBound(0)))
            {
                throw new DataArgumentException("Invalid array index", argument1Name);
            }

            if (IsNull(array) ||
                (index2 < 0) ||
                (index2 > array.GetUpperBound(1)))
            {
                throw new DataArgumentException("Invalid array index", argument2Name);
            }
        }
Ejemplo n.º 12
0
        public string[,] GetRangeStrings()
        {
            Object[,] objects = GetRangeObjects();

            //Determine the dimensions of the array.
            long iRows;
            long iCols;

            iRows = objects.GetUpperBound(0);
            iCols = objects.GetUpperBound(1);

            var strings = new string[iRows, iCols];

            for (long rowCounter = 1; rowCounter <= iRows; rowCounter++)
            {
                for (long colCounter = 1; colCounter <= iCols; colCounter++)
                {
                    strings[rowCounter, colCounter] = objects[rowCounter, colCounter].ToString();
                }
            }

            return(strings);
        }
Ejemplo n.º 13
0
        void EvaluateWorld()
        {
            string         turinginput = "";
            lifeform       templifeform;
            turing_machine tempmachine;
            Object         tempgridobject;

            for (int x = 0; x <= gridobjects.GetUpperBound(0); x++)
            {
                for (int y = 0; y <= gridobjects.GetUpperBound(1); y++)
                {
                    if (gridobjects[x, y] is lifeform)
                    {
                        templifeform = (lifeform)gridobjects[x, y];
                        tempmachine  = templifeform.turingmachine;
                    }
                }
            }
        }
Ejemplo n.º 14
0
        private void button7_Click(object sender, EventArgs e)
        {
            Demand             demand    = (Demand)propertyGrid.SelectedObject;
            NumberToLetterUtil converter = new NumberToLetterUtil();

            demand.PscEcsData.Clear();
            demand.PscEcsData.Add(new PscEcsData()
            {
                Name = "2008", Column = "J"
            });
            demand.PscEcsData.Add(new PscEcsData()
            {
                Name = "2009", Column = "K"
            });
            demand.PscEcsData.Add(new PscEcsData()
            {
                Name = "2010", Column = "L"
            });
            demand.PscEcsData.Add(new PscEcsData()
            {
                Name = "2011", Column = "M"
            });
            demand.PscEcsData.Add(new PscEcsData()
            {
                Name = "2012", Column = "N"
            });
            demand.PscEcsData.Add(new PscEcsData()
            {
                Name = "2013", Column = "O"
            });
            demand.PscEcsData.Add(new PscEcsData()
            {
                Name = "2014", Column = "P"
            });
            demand.PscEcsData.Add(new PscEcsData()
            {
                Name = "2015", Column = "Q"
            });
            demand.PscEcsData.Add(new PscEcsData()
            {
                Name = "2016", Column = "R"
            });
            demand.PscEcsData.Add(new PscEcsData()
            {
                Name = "2017", Column = "S"
            });
            demand.PscEcsData.Add(new PscEcsData()
            {
                Name = "2018", Column = "T"
            });
            demand.PscEcsData.Add(new PscEcsData()
            {
                Name = "2019", Column = "U"
            });
            demand.PscEcsData.Add(new PscEcsData()
            {
                Name = "2020", Column = "V"
            });
            demand.PscEcsData.Add(new PscEcsData()
            {
                Name = "2021", Column = "W"
            });
            demand.PscEcsData.Add(new PscEcsData()
            {
                Name = "2022", Column = "X"
            });
            NumberToLetterUtil numUtil = new NumberToLetterUtil();

            if (demand.RowSequenceType == RowSequenceType.Range)
            {
                try
                {
                    String firstLetter = demand.RowRangeFrom.ElementAt(0).ToString();

                    ExcelUtil excel = new ExcelUtil();

                    excel.Open(demand.Path + "/" + demand.FileName);
                    excel.Worksheet(demand.WorkSheet);

                    Object[,] obj = excel.ReadCellByRange(demand.RowRangeFrom + ":" + demand.RowRangeTo);
                    for (int row = 1; row <= obj.GetUpperBound(0); row++)
                    {
                        //for (int col = 1; col <= obj.GetUpperBound(1); col++) {
                        //    if (obj[row, col] == null) {
                        //        Console.WriteLine("NUl");
                        //        continue;
                        //    }

                        //    Console.WriteLine(obj[row, col].ToString());
                        //}
                        int numberGap = Int32.Parse(numUtil.getNumberByLetter(firstLetter));

                        //Area area = new Area(obj[row, Int32.Parse(numUtil.getNumberByLetter(demand.AreaColumn)) - numberGap + 1].ToString());
                        Area area = new Area("Luzon");
                        area = (Area)areaSessionData.createIfNotExist(area);

                        Regions region = new Regions(obj[row, Int32.Parse(numUtil.getNumberByLetter(demand.RegionColumn)) - numberGap + 1].ToString(), area.areaId);
                        region = (Regions)regionSessionData.createIfNotExist(region);

                        Cooperative cooperative = new Cooperative(obj[row, Int32.Parse(numUtil.getNumberByLetter(demand.CooperativeColumn)) - numberGap + 1].ToString(), "", region.regionId);
                        cooperative = (Cooperative)cooperativeSessionData.createIfNotExist(cooperative);


                        if (obj[row, Int32.Parse(numUtil.getNumberByLetter(demand.PlantColumn)) - numberGap + 1] == null)
                        {
                            continue;
                        }
                        Plant plant = new Plant(obj[row, Int32.Parse(numUtil.getNumberByLetter(demand.PlantColumn)) - numberGap + 1].ToString(), cooperative.cooperativeId);
                        plant = (Plant)plantSessionData.createIfNotExist(plant);
                        //plant = (Plant)plantSessionData.add(plant);

                        //if (plant == null) continue;

                        Console.WriteLine("Plant: " + plant.plantId);

                        DataType dataType = new DataType(obj[row, Int32.Parse(numUtil.getNumberByLetter(demand.PscEcsKeywordColumn)) - numberGap + 1].ToString());
                        dataType = (DataType)dataTypeSessionData.createIfNotExist(dataType);

                        DataValues dataValue = new DataValues(plant.plantId, dataType.dataTypeId);
                        dataValue = (DataValues)dataValuesSessionData.createIfNotExist(dataValue);

                        foreach (PscEcsData ecsData in demand.PscEcsData)
                        {
                            object dataObect = obj[row, Int32.Parse(numUtil.getNumberByLetter(ecsData.Column)) - numberGap + 1];
                            String data      = "0";

                            if (dataObect != null)
                            {
                                data = dataObect.ToString();
                            }

                            DataContent dataContent = new DataContent(ecsData.Name, data, dataValue.dataValuesId);
                            dataContentSessionData.add(dataContent);
                        }
                    }
                    excel.Close();
                }
                catch (WorksheetNotFoundException wnfe)
                {
                    MessageBox.Show(null, wnfe.Message, "Error Window", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                catch (RangeInvalidException rie)
                {
                    MessageBox.Show(null, rie.Message, "Error Window", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                catch (IndexOutOfRangeException iore) {
                    MessageBox.Show(null, "Index not in a range.", "Error Window", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            else if (demand.RowSequenceType == RowSequenceType.Collection)
            {
                try
                {
                    excel = new ExcelUtil();

                    excel.AddWorkbook();
                    excel.Worksheet("Sheet1");

                    String cell = null;
                    String path = null;

                    foreach (String row in demand.RowCollection)
                    {
                        cell = demand.PlantColumnIndex + row;
                        path = @"='" + demand.Path + "\\[" + demand.FileName + "]" + demand.WorkSheet + "'!" + cell;
                        excel.WriteCell(1, 1, path);
                        String plantName = excel.ReadCell("A1").ToString();
                        Console.WriteLine(plantName);


                        int rowIndex = Int32.Parse(row) + 2;
                        for (int cntr = rowIndex; cntr < (rowIndex + 2); cntr++)
                        {
                            cell = demand.SupplyContractedKeywordColumn + cntr;
                            path = @"='" + demand.Path + "\\[" + demand.FileName + "]" + demand.WorkSheet + "'!" + cell;
                            excel.WriteCell(1, 1, path);
                            String data = excel.ReadCell("A1").ToString();

                            dataType = new DataType(data);
                            dataType = (DataType)dataTypeSessionData.createIfNotExist(dataType);
                            Console.WriteLine("data: " + dataType.dataTypeId);

                            Area area = new Area("Luzon");
                            area = (Area)areaSessionData.createIfNotExist(area);

                            Regions region = new Regions(demand.SupplyContractedRegion.ToString().Replace("_", " "), area.areaId);
                            region = (Regions)regionSessionData.createIfNotExist(region);

                            Cooperative cooperative = new Cooperative(demand.SupplyContractedCooperative, demand.SupplyContractedCooperativeAccronym, region.regionId);
                            cooperative = (Cooperative)cooperativeSessionData.createIfNotExist(cooperative);

                            Plant plant = new Plant(plantName, cooperative.cooperativeId);
                            plant = (Plant)plantSessionData.createIfNotExist(plant);
                            Console.WriteLine("Plant: " + plant.plantId);

                            //DataValues coopSearch = data
                            DataValues coopSearch = dataValuesSessionData.findDataValuesByPlantId(plant, dataType);
                            if (coopSearch != null)
                            {
                                dataContentSessionData.deleteByDataValueId(coopSearch.dataValuesId);
                                dataValue = coopSearch;
                            }
                            else
                            {
                                dataValue            = new DataValues();
                                dataValue.plantId    = plant.plantId;
                                dataValue.dataTypeId = dataType.dataTypeId;
                                dataValue            = (DataValues)dataValuesSessionData.add(dataValue);
                            }

                            foreach (DDPSupplyContractedData contractedData in demand.SupplyContractedData)
                            {
                                cell = contractedData.Column + cntr;
                                path = @"='" + demand.Path + "\\[" + demand.FileName + "]" + demand.WorkSheet + "'!" + cell;
                                excel.WriteCell(1, 1, path);
                                Console.WriteLine(contractedData.Name + " - " + excel.ReadCell(1, "A"));

                                dataContent              = new DataContent();
                                dataContent.header       = contractedData.Name;
                                dataContent.value        = excel.ReadCell("A1");
                                dataContent.dataValuesId = dataValue.dataValuesId;
                                dataContentSessionData.add(dataContent);
                            }
                        }
                    }

                    excel.Close();
                }
                catch (NullReferenceException nre)
                {
                    MessageBox.Show(null, nre.Message.ToString(), "Error Window", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }


            Console.WriteLine("Success!");
            Console.WriteLine(demand.Region);
        }
Ejemplo n.º 15
0
        ImportWorkbookIntoGraph
        (
            Worksheet oSourceWorksheet,
            Range oNonEmptySourceRange,
            Int32 iColumnNumberToUseForVertex1OneBased,
            Int32 iColumnNumberToUseForVertex2OneBased,
            ICollection <Int32> oEdgeColumnNumbersToImportOneBased,
            ICollection <Int32> oVertex1ColumnNumbersToImportOneBased,
            ICollection <Int32> oVertex2ColumnNumbersToImportOneBased,
            Boolean bSourceColumnsHaveHeaders
        )
        {
            Debug.Assert(oSourceWorksheet != null);
            Debug.Assert(oNonEmptySourceRange != null);
            Debug.Assert(iColumnNumberToUseForVertex1OneBased >= 1);
            Debug.Assert(iColumnNumberToUseForVertex2OneBased >= 1);
            Debug.Assert(oEdgeColumnNumbersToImportOneBased != null);
            Debug.Assert(oVertex1ColumnNumbersToImportOneBased != null);
            Debug.Assert(oVertex2ColumnNumbersToImportOneBased != null);
            AssertValid();

            String [] asWorkbookColumnNames = GetWorkbookColumnNames(
                oSourceWorksheet, oNonEmptySourceRange, bSourceColumnsHaveHeaders);

            Int32 iColumns = oNonEmptySourceRange.Columns.Count;

            Int32 iFirstNonEmptyColumnOneBased =
                oNonEmptySourceRange.Columns.Column;

            if (bSourceColumnsHaveHeaders)
            {
                // Skip the header row.

                if (oNonEmptySourceRange.Rows.Count < 2)
                {
                    OnInvalidSourceWorkbook(
                        "If the columns in the other workbook have headers, then"
                        + " there must be at least two rows.",

                        oSourceWorksheet, 1, 1
                        );
                }

                ExcelUtil.OffsetRange(ref oNonEmptySourceRange, 1, 0);

                ExcelUtil.ResizeRange(ref oNonEmptySourceRange,
                                      oNonEmptySourceRange.Rows.Count - 1, iColumns);
            }

            IGraph            oGraph    = new Graph(GraphDirectedness.Undirected);
            IVertexCollection oVertices = oGraph.Vertices;
            IEdgeCollection   oEdges    = oGraph.Edges;

            // The key is a vertex name and the value is the corresponding IVertex
            // object.

            Dictionary <String, IVertex> oVertexNameDictionary =
                new Dictionary <String, IVertex>();

            foreach (Range oSubrange in
                     ExcelRangeSplitter.SplitRange(oNonEmptySourceRange, 500))
            {
                Object [,] oSubrangeValues = ExcelUtil.GetRangeValues(oSubrange);
                Int32 iSubrangeRows = oSubrangeValues.GetUpperBound(0);

                for (Int32 iRowOneBased = 1; iRowOneBased <= iSubrangeRows;
                     iRowOneBased++)
                {
                    String sVertex1Name, sVertex2Name;

                    if (
                        !ExcelUtil.TryGetNonEmptyStringFromCell(oSubrangeValues,
                                                                iRowOneBased,
                                                                iColumnNumberToUseForVertex1OneBased -
                                                                iFirstNonEmptyColumnOneBased + 1,
                                                                out sVertex1Name)
                        ||
                        !ExcelUtil.TryGetNonEmptyStringFromCell(oSubrangeValues,
                                                                iRowOneBased,
                                                                iColumnNumberToUseForVertex2OneBased -
                                                                iFirstNonEmptyColumnOneBased + 1,
                                                                out sVertex2Name)
                        )
                    {
                        continue;
                    }

                    IVertex oVertex1 = WorksheetReaderBase.VertexNameToVertex(
                        sVertex1Name, oVertices, oVertexNameDictionary);

                    IVertex oVertex2 = WorksheetReaderBase.VertexNameToVertex(
                        sVertex2Name, oVertices, oVertexNameDictionary);

                    IEdge oEdge = oEdges.Add(oVertex1, oVertex2);

                    // Add the edge and vertex attributes.

                    AddAttributeValuesToEdgeOrVertex(asWorkbookColumnNames,
                                                     oSubrangeValues, iRowOneBased,
                                                     iFirstNonEmptyColumnOneBased,
                                                     oEdgeColumnNumbersToImportOneBased, oEdge);

                    AddAttributeValuesToEdgeOrVertex(asWorkbookColumnNames,
                                                     oSubrangeValues, iRowOneBased,
                                                     iFirstNonEmptyColumnOneBased,
                                                     oVertex1ColumnNumbersToImportOneBased, oVertex1);

                    AddAttributeValuesToEdgeOrVertex(asWorkbookColumnNames,
                                                     oSubrangeValues, iRowOneBased,
                                                     iFirstNonEmptyColumnOneBased,
                                                     oVertex2ColumnNumbersToImportOneBased, oVertex2);
                }
            }

            // Store metadata on the graph indicating the sets of keys that may be
            // present on the graph's edges and vertices.

            oGraph.SetValue(ReservedMetadataKeys.AllEdgeMetadataKeys,

                            GetColumnNamesToImport(oNonEmptySourceRange,
                                                   asWorkbookColumnNames, oEdgeColumnNumbersToImportOneBased)
                            );

            List <Int32> oVertexColumnNumbersToImportOneBased = new List <Int32>();

            oVertexColumnNumbersToImportOneBased.AddRange(
                oVertex1ColumnNumbersToImportOneBased);

            oVertexColumnNumbersToImportOneBased.AddRange(
                oVertex2ColumnNumbersToImportOneBased);

            oGraph.SetValue(ReservedMetadataKeys.AllVertexMetadataKeys,

                            GetColumnNamesToImport(oNonEmptySourceRange, asWorkbookColumnNames,
                                                   oVertexColumnNumbersToImportOneBased)
                            );

            return(oGraph);
        }
Ejemplo n.º 16
0
        AutoFillByVertexCategory
        (
            Microsoft.Office.Interop.Excel.Workbook oWorkbook,
            Microsoft.Office.Interop.Excel.ListObject oEdgeTable,
            Microsoft.Office.Interop.Excel.ListObject oVertexTable,
            String sVertexCategoryColumnName,
            Boolean bShowVertexLabels,
            String sVertexLabelColumnName
        )
        {
            Debug.Assert(oWorkbook != null);
            Debug.Assert(oEdgeTable != null);
            Debug.Assert(oVertexTable != null);
            Debug.Assert(!String.IsNullOrEmpty(sVertexCategoryColumnName));

            Debug.Assert(!bShowVertexLabels ||
                         !String.IsNullOrEmpty(sVertexLabelColumnName));

            Range oVisibleCategoryRange = null;
            Range oVisibleShapeRange    = null;
            Range oVisibleColorRange    = null;
            Range oVisibleRadiusRange   = null;;

            if (
                !ExcelUtil.TryGetVisibleTableColumnData(oVertexTable,
                                                        sVertexCategoryColumnName, out oVisibleCategoryRange)
                ||
                !ExcelUtil.TryGetVisibleTableColumnData(oVertexTable,
                                                        VertexTableColumnNames.Shape, out oVisibleShapeRange)
                ||
                !ExcelUtil.TryGetVisibleTableColumnData(oVertexTable,
                                                        VertexTableColumnNames.Color, out oVisibleColorRange)
                ||
                !ExcelUtil.TryGetVisibleTableColumnData(oVertexTable,
                                                        VertexTableColumnNames.Radius, out oVisibleRadiusRange)
                )
            {
                ErrorUtil.OnMissingColumn();
            }

            // Loop through the visible areas to create a dictionary of categories.
            // The key is a unique category name and the value is a scheme index.
            // If the category column contains three unique categories, for
            // example, the dictionary entries will look like this:
            //
            // Category A, 0
            // Category B, 1
            // Category C, 2

            Dictionary <String, Int32> oCategoryDictionary =
                new Dictionary <String, Int32>();

            Areas oCategoryAreas = oVisibleCategoryRange.Areas;
            Int32 iAreas         = oCategoryAreas.Count;
            Int32 iSchemeIndex   = 0;

            for (Int32 iArea = 1; iArea <= iAreas; iArea++)
            {
                Object [,] aoCategoryValues = ExcelUtil.GetRangeValues(
                    oCategoryAreas[iArea]);

                Int32  iRows = aoCategoryValues.GetUpperBound(0);
                String sCategory;

                for (Int32 iRow = 1; iRow <= iRows; iRow++)
                {
                    if (ExcelUtil.TryGetNonEmptyStringFromCell(aoCategoryValues,
                                                               iRow, 1, out sCategory))
                    {
                        if (!oCategoryDictionary.ContainsKey(sCategory))
                        {
                            oCategoryDictionary[sCategory] = iSchemeIndex;
                            iSchemeIndex++;
                        }
                    }
                }
            }

            // Scheme index that will be used for vertices that have an empty
            // category cell.

            Int32 SchemeIndexForNoCategory = iSchemeIndex;

            Areas oShapeAreas  = oVisibleShapeRange.Areas;
            Areas oColorAreas  = oVisibleColorRange.Areas;
            Areas oRadiusAreas = oVisibleRadiusRange.Areas;

            Debug.Assert(oShapeAreas.Count == iAreas);
            Debug.Assert(oColorAreas.Count == iAreas);
            Debug.Assert(oRadiusAreas.Count == iAreas);

            ColorConverter2 oColorConverter2 = new ColorConverter2();

            VertexShapeConverter oVertexShapeConverter =
                new VertexShapeConverter();

            // Loop through the visible areas again, this time to fill in the
            // vertex shape, color, and radius columns.

            for (Int32 iArea = 1; iArea <= iAreas; iArea++)
            {
                Object [,] aoCategoryValues = ExcelUtil.GetRangeValues(
                    oCategoryAreas[iArea]);

                Range oShapeArea  = oShapeAreas[iArea];
                Range oColorArea  = oColorAreas[iArea];
                Range oRadiusArea = oRadiusAreas[iArea];

                Object [,] aoShapeValues  = ExcelUtil.GetRangeValues(oShapeArea);
                Object [,] aoColorValues  = ExcelUtil.GetRangeValues(oColorArea);
                Object [,] aoRadiusValues = ExcelUtil.GetRangeValues(oRadiusArea);

                Int32 iRows = aoCategoryValues.GetUpperBound(0);

                Debug.Assert(aoShapeValues.GetUpperBound(0) == iRows);
                Debug.Assert(aoColorValues.GetUpperBound(0) == iRows);
                Debug.Assert(aoRadiusValues.GetUpperBound(0) == iRows);

                String sCategory;

                for (Int32 iRow = 1; iRow <= iRows; iRow++)
                {
                    if (ExcelUtil.TryGetNonEmptyStringFromCell(aoCategoryValues,
                                                               iRow, 1, out sCategory))
                    {
                        iSchemeIndex = oCategoryDictionary[sCategory];
                    }
                    else
                    {
                        iSchemeIndex = SchemeIndexForNoCategory;
                    }

                    VertexShape eShape;
                    Color       oColor;
                    Single      fRadius;

                    GetVertexCategoryScheme(iSchemeIndex, out eShape, out oColor,
                                            out fRadius);

                    aoShapeValues[iRow, 1] =
                        oVertexShapeConverter.GraphToWorkbook(eShape);

                    // Write the color in a format that is understood by
                    // ColorConverter.ConvertFromString(), which is what
                    // WorksheetReaderBase uses.

                    aoColorValues[iRow, 1] =
                        oColorConverter2.GraphToWorkbook(oColor);

                    aoRadiusValues[iRow, 1] = fRadius;
                }

                oShapeArea.set_Value(Missing.Value, aoShapeValues);
                oColorArea.set_Value(Missing.Value, aoColorValues);
                oRadiusArea.set_Value(Missing.Value, aoRadiusValues);
            }

            // Fill in other columns with constants.

            FillColumnsWithConstants(

                oVertexTable, CommonTableColumnNames.Alpha,
                AlphaConverter.MaximumAlphaWorkbook,

                oEdgeTable, EdgeTableColumnNames.Color,
                oColorConverter2.GraphToWorkbook(
                    Color.FromArgb(179, 179, 179)),

                oEdgeTable, EdgeTableColumnNames.Width, 1.0F,

                oEdgeTable, CommonTableColumnNames.Alpha,
                AlphaConverter.MaximumAlphaWorkbook
                );

            // Save the results.

            SaveVertexCategoryResults(oWorkbook, sVertexCategoryColumnName,
                                      oCategoryDictionary);
        }
Ejemplo n.º 17
0
        public int mWriteRecordSet(RecordSetMD inRecordSetMD
                                   , Object[,] r
                                   , Boolean bIncludesHeaderRow
                                   )
        {
            try {
                if (this.RecordSet.Buffer == null)
                {
                    throw new com.WDataSci.WDS.WDSException("Error, RecordSet buffer not set before WriteSet!");
                }

                DBB buf = this.RecordSet.Buffer;

                int rowstartindex = r.GetLowerBound(0);
                int nRows         = r.GetUpperBound(0) - rowstartindex + 1;
                if (bIncludesHeaderRow)
                {
                    nRows         -= 1;
                    rowstartindex += 1;
                }
                int nColumns = r.GetUpperBound(1) - r.GetLowerBound(1) + 1;

                if (nColumns != inRecordSetMD.nColumns())
                {
                    throw new com.WDataSci.WDS.WDSException("Error, Excel ListObject #columns does not match RecordSetMD #columns");
                }

                this.mWritePrepFor(inRecordSetMD, nRows);

                buf.position(0, 0, 0);


                //write leading data
                buf.PutLayerFLenString(0, "WDSD", 8, 0);
                buf.PutLayerLong(0, buf.nDBBRequiredBytes);
                buf.PutLayerLong(0, buf.nDBBLeadingBytes);
                buf.PutLayerLong(0, buf.nDBBFLenBytes);
                buf.PutLayerLong(0, buf.nDBBVLenBytes);
                buf.PutLayerLong(0, buf.nRecords);
                buf.PutLayerLong(0, buf.nRecordFLenBytes);
                buf.PutLayerLong(0, buf.nRecordVLenBytes);

                int bptr = 0;
                //bptr = (int) buf.nDBBLeadingBytes;



                int nInputColumns = inRecordSetMD.nColumns();



                for (int i = 0, ii = rowstartindex; i < nRows; i++, ii++)
                {
                    if (i > 0)
                    {
                        bptr += (int)this.RecordSet.Buffer.nRecordFLenBytes;
                    }
                    long lbptr = bptr;
                    buf.position(buf.ptr, (int)bptr, buf.vlenptr);

                    for (int j = 0, jj = r.GetLowerBound(1); j < nColumns; j++, jj++)
                    {
                        Object obj = r [ii, jj];
                        switch (inRecordSetMD.Column [j].DTyp)
                        {
                        case FieldMDEnums.eDTyp.Dbl:
                            buf.PutLayerDouble(1, obj);
                            break;

                        case FieldMDEnums.eDTyp.Lng:
                            buf.PutLayerLong(1, obj);
                            break;

                        case FieldMDEnums.eDTyp.Dte:
                            buf.PutLayerDouble(1, obj);
                            break;

                        case FieldMDEnums.eDTyp.DTm:
                            buf.PutLayerDouble(1, obj);
                            break;

                        case FieldMDEnums.eDTyp.Int:
                            buf.PutLayerInt(1, obj);
                            break;

                        case FieldMDEnums.eDTyp.Str:
                            buf.PutLayerFLenString(1, Convert.ToString(obj), (int)inRecordSetMD.Column [j].ByteMaxLength, 2);
                            break;

                        case FieldMDEnums.eDTyp.VLS:
                            buf.PutLayerVLenString(1, Convert.ToString(obj), (int)inRecordSetMD.Column [j].ByteMaxLength, 2);
                            break;

                        default:
                            throw new Exception("Hey");
                        }
                    }
                }

                return(0);
            }
            catch (Exception e) {
                throw new com.WDataSci.WDS.WDSException("Error in writing output map to DBB", e);
            }
        }
Ejemplo n.º 18
0
        public MainWindow()
        {
            CultureInfo myCIintl = new CultureInfo("ru-RU", false);

            System.Threading.Thread.CurrentThread.CurrentUICulture = myCIintl;
            System.Threading.Thread.CurrentThread.CurrentCulture   = myCIintl;

            InitializeComponent();

            connectionString = GetConnectionString();
            string sql;
            // Declares managed prototypes for unmanaged functions.
            long i, j;

            this.Visibility = Visibility.Hidden;
            this.TaskbarItemInfo.ProgressValue = 0;
            this.TaskbarItemInfo.Description   = "Загрузка начальных данных";
            this.TaskbarItemInfo.ProgressState = System.Windows.Shell.TaskbarItemProgressState.Normal;
            UserName.Text = "Пользователь " + (string)Environment.UserName;
            this.TaskbarItemInfo.ProgressValue = 0.1;
            sql            = @"SELECT ПРП.[лот], ""Лот "" & [Лоты]![Номер лота] & "" Контракт № "" & [Номер договора] & "" от "" & [Дата договора] AS Выражение1, ПРП.[all]  FROM Лоты INNER JOIN ПРП ON Лоты.Код = ПРП.[лот] WHERE (((ПРП.User)=""" + (string)Environment.UserName + @"""));";
            Object[,] rez1 = ConnectToData(connectionString, sql);
            if (rez1.Length < 1)
            {
                WinNoDost w = new WinNoDost();
                w.SetText("Пользователь " + (string)Environment.UserName + Environment.NewLine + "не имеет права работать с данным файлом." + Environment.NewLine + "Прошу сообщить руководителю департамента управления" + Environment.NewLine + "проектом об этом для включения в список.");
                w.ShowDialog();
                this.Close();
            }
            else
            {
                int   rows = rez1.GetUpperBound(0) + 1;
                int[] temp = new int[2];
                temp[0] = 2;
                temp[1] = rows + 5;
                lot_p   = (Object[, ])ResizeArray(lot_p, temp);
                Lot.Items.Clear();
                Lot.Items.IsLiveSorting = true;
                for (i = 0; i < rows; i++)
                {
                    j           = Lot.Items.Add(rez1[i, 1]);
                    lot_p[0, j] = rez1[i, 0];
                    lot_p[1, j] = rez1[i, 1];
                }
                Form1.TaskbarItemInfo.ProgressValue = 0.2;
                Object[,] rez = ConnectToData(connectionString, @"Select Настройки.Значение FROM Настройки WHERE (((Настройки.Название)=""Ставка рефенансирования""));");
                Form1.TaskbarItemInfo.ProgressValue = 0.4;
                refinans           = (double)rez[0, 0];
                Refinans_text.Text = String.Format("Ставка рефинансирования ЦБ {0:p}", refinans);
                Form1.TaskbarItemInfo.ProgressValue = 0.6;

                Form1.TaskbarItemInfo.ProgressValue = 1;
                Form1.TaskbarItemInfo.Description   = "";
                TipV.Text        = "График / РКЦ";
                Form1.Visibility = Visibility.Visible;
                initFlg          = true;

                SizeC(true, true);

                Lot.SelectedIndex = 0;// ' Вызывает Lot_SelectionChanged и соответственно ReadDBtoDG

                Form1.TaskbarItemInfo.ProgressState = System.Windows.Shell.TaskbarItemProgressState.None;
            }
        }