public static StringCollection ConvertObject2StringCollection(Object obj0) { StringCollection result = new StringCollection(); if (obj0 is string) { result.Add((string)obj0); return(result); } else if (obj0 is double) { result.Add(System.Convert.ToString(System.Convert.ToInt32((double)obj0))); return(result); } Object[,] obj = (Object[, ])obj0; int rows = obj.GetLength(0); int cols = obj.GetLength(1); for (int i = 0; i < rows; i++) { for (int j = 0; j < cols; j++) { if (obj[i, j] is string) { result.Add((String)obj[i, j]); } else if (obj[i, j] is double) { result.Add(System.Convert.ToString(System.Convert.ToInt32((double)obj[i, j]))); } } } return(result); }
private void CreateMinesLaveriesConnexions() { Object[,] connexionsInput = configDico[Legende.CONNEXIONS]; for (int i = 1; i < connexionsInput.GetLength(0); i++) { string axeName = (string)connexionsInput[i, 1]; string mineName = (string)connexionsInput[i, 2]; string extractionName = mineName + Legende.EXTRACTION; string connexionName = (string)connexionsInput[i, 4]; Product interProduct = IntermediateProducts.GetInterProduct((string)connexionsInput[i, 3]); CapexObjectManager capexObj = objectManagerDico[connexionsInput[i, 0].ToString()]; capexObj.UpdateLaveriesDico(); Entity variableMine = capexObj.GetEntity(axeName, mineName); for (int j = 5; j < connexionsInput.GetLength(1); j++) { string laverieName = (string)connexionsInput[0, j]; if (connexionsInput[i, j].ToString() == "N") { continue; } Unit laverie = capexObj.GetLaverie(laverieName); Unit extractionUnit = variableMine.GetUnit(extractionName); capexObj.AddConnexion(connexionName, extractionUnit, laverie, (double)connexionsInput[i, j], (double)laverie.Capacity, interProduct); } } }
private void round() { int lastUsedRow = thezoneWS.Cells.Find("*", System.Reflection.Missing.Value, System.Reflection.Missing.Value, System.Reflection.Missing.Value, Excel.XlSearchOrder.xlByRows, Excel.XlSearchDirection.xlPrevious, false, System.Reflection.Missing.Value, System.Reflection.Missing.Value).Row; // Find the last real column int lastUsedColumn = thezoneWS.Cells.Find("*", System.Reflection.Missing.Value, System.Reflection.Missing.Value, System.Reflection.Missing.Value, Excel.XlSearchOrder.xlByColumns, Excel.XlSearchDirection.xlPrevious, false, System.Reflection.Missing.Value, System.Reflection.Missing.Value).Column; String valcolend = GetExcelColumnName(lastUsedColumn - 1); Excel.Range valrng = thezoneWS.Range["B4:" + valcolend + lastUsedRow.ToString()]; valrng.NumberFormat = "#,##0"; Object[,] val = valrng.Value; for (int i = 1; i < val.GetLength(0); i++) { for (int j = 1; j < val.GetLength(1); j++) { if (val[i, j] != null) { val[i, j] = Math.Round(Convert.ToDouble(val[i, j]), 0); } } } valrng.Value = val; }
static void Main(string[] args) { TestData testData = TestData.TestMaze4(); Object[,] mazeObjects = testData.MazeConstructionObjects; int numberOfRows = (mazeObjects.GetLength(0) - 1) / 2; int numberOfColumn = (mazeObjects.GetLength(1) - 1) / 2; int startingRow = testData.StartingRow; int startingColumn = testData.StartingColumn; int destinationRow = testData.DestinationRow; int destinationColumn = testData.DestinationColumn; try { Maze maze = new Maze(numberOfRows, numberOfColumn, startingRow, startingColumn, destinationRow, destinationColumn, mazeObjects); Mouse mouse = new Mouse(maze); var printer = new MazePrinter(mouse, maze); mouse.SolveMaze(); Console.WriteLine("You have succeeded!"); printer.PrintDirectionsTakenByMouseToReachDestination(); } catch (Exception e) { Console.WriteLine(e.Message); Console.WriteLine("You have failed!"); } }
public Object[,] Prifil(Object[,] mt) { // metodo prifil Object[] fil = new Object[mt.GetLength(0)]; //columna fil for (int i = 0; i < fil.GetLength(0); i++) //elmgetlengt(0) es para num de filas { int cont = 0; for (int y = 1; y < mt.GetLength(1); y++) { if (!mt[i, y].Equals("-")) { cont++; } fil[i] = cont; } } Object[] prif = new Object[mt.GetLength(0)];// columna prifil prif[0] = 1; for (int i = 1; i < prif.GetLength(0); i++) { if (Convert.ToInt16(prif[i - 1]) <= 518) { prif[i] = Convert.ToInt16(prif[i - 1]) + Convert.ToInt16(fil[i]); } else { prif[i - 1] = 0; } } Object[,] prifil = new Object[mt.GetLength(0), 3]; prifil[0, 0] = "X"; prifil[0, 1] = "Prifil"; prifil[0, 2] = "fil"; for (int i = 1; i < prifil.GetLength(0); i++) { prifil[i, 0] = i - 1; prifil[i, 1] = prif[i - 1]; prifil[i, 2] = fil[i]; } for (int i = 1; i < prifil.GetLength(0); i++) { for (int j = 1; j < prifil.GetLength(1); j++) { if (prifil[i, j] == null) { prifil[i, j] = "-"; } } } return(prifil); }
public void findCombinations() { Console.WriteLine("Suche Zahl-Alphametiken..."); //verschachtelte Schleife für die Kombinationen zweier Wörter for (int firstNumber = 1; firstNumber < numbers.GetLength(0); firstNumber++) { for (int secondNumber = 1; secondNumber < numbers.GetLength(0); secondNumber++) { if (firstNumber + secondNumber < numbers.GetLength(0)) { calculateThisString(numbers[firstNumber, 1] + "+" + numbers[secondNumber, 1] + "=" + numbers[firstNumber + secondNumber, 1]); } if (firstNumber - secondNumber > 0) { calculateThisString(numbers[firstNumber, 1] + "-" + numbers[secondNumber, 1] + "=" + numbers[firstNumber - secondNumber, 1]); } if (firstNumber / secondNumber > 0 && firstNumber % secondNumber == 0) { calculateThisString(numbers[firstNumber, 1] + "/" + numbers[secondNumber, 1] + "=" + numbers[firstNumber / secondNumber, 1]); } if (firstNumber * secondNumber < numbers.GetLength(0)) { calculateThisString(numbers[firstNumber, 1] + "*" + numbers[secondNumber, 1] + "=" + numbers[firstNumber * secondNumber, 1]); } } } }
public override string ToString() { StringBuilder builder = new StringBuilder(); builder.AppendLine($"Field Contents:"); builder.AppendLine(); for (int row = 0; row < animals.GetLength(0); row++) { for (int column = 0; column < animals.GetLength(1); column++) { if (animals[row, column] == null) { builder.Append("."); } else { builder.Append(animals[row, column].ToString()); } } builder.AppendLine(); } builder.AppendLine(); return(builder.ToString()); }
private void CreateAndUpdateLaveriesCapacities() { Object[,] capaLaverieInput = configDico[Legende.CAPALAV]; for (int i = 1; i < capaLaverieInput.GetLength(0); i++) { string axeName = (string)capaLaverieInput[i, 0]; string mineName = (string)capaLaverieInput[i, 1]; string laverieName = (string)capaLaverieInput[i, 2]; foreach (CapexObjectManager objManager in objectManagerDico.Values) { Entity variableMine = objManager.GetEntity(axeName, mineName); variableMine.AddTreatment(laverieName, TreatmentType.LAVERIE); } } for (int i = 6; i < capaLaverieInput.GetLength(1); i++) { CapexObjectManager capexObj = objectManagerDico[capaLaverieInput[0, i].ToString()]; for (int j = 1; j < capaLaverieInput.GetLength(0); j++) { Unit treatmentUnit = capexObj.GetUnit((string)capaLaverieInput[j, 0], (string)capaLaverieInput[j, 1], (string)capaLaverieInput[j, 2]); if (capaLaverieInput[j, i] == null) { capaLaverieInput[j, i] = 0.0; } treatmentUnit.Capacity = (double)capaLaverieInput[j, i]; } } }
public DataTable ArraytoDatatable(Object[,] numbers) { DataTable dt = new DataTable(); for (int i = 0; i < numbers.GetLength(0); i++) { // This array holds the row data Object[] data = new Object[numbers.GetLength(0)]; for (int j = 0; j < numbers.GetLength(0); j++) { // fill the row data data[j] = numbers[i, j]; } // Add the row to the DataTable dt.Rows.Add(data); } //for (int i = 0; i < numbers.GetLength(1); i++) //{ // dt.Columns.Add("Column" + (i + 1)); //} //for (var i = 0; i < numbers.GetLength(0); ++i) //{ // DataRow row = dt.NewRow(); // for (var j = 0; j < numbers.GetLength(1); ++j) // { // row[j] = numbers[i, j]; // } // dt.Rows.Add(row); //} return(dt); }
public DataTable Convert2DArraytoDatatableHeader(Object[,] resultHeader, Object[,] numbers) { int colCountHeader = resultHeader.GetLength(1); int rowCountHeader = resultHeader.GetLength(0); DataTable dtHeader = new DataTable(); for (int i = 1; i <= rowCountHeader; i++) { for (int j = 1; j <= colCountHeader; j++) { if (1 == i) { dtHeader.Columns.Add(resultHeader[i, j].ToString()); } } } int colCount = numbers.GetLength(1); int rowCount = numbers.GetLength(0); for (int i = 1; i <= rowCount; i++) { DataRow dr = dtHeader.NewRow(); for (int j = 1; j <= colCount; j++) { dr[j - 1] = numbers[i, j]; } dtHeader.Rows.Add(dr); } return(dtHeader); }
public DataTable Convert2DArraytoDatatable(Object[,] numbers) { DataTable dt = new DataTable(); int colCount = numbers.GetLength(1); int rowCount = numbers.GetLength(0); dt = new DataTable(); int noofrow = 1; for (int c = 1; c <= colCount; c++) { dt.Columns.Add("Column" + (c)); noofrow = 1; } for (int i = noofrow; i <= rowCount; i++) { DataRow dr = dt.NewRow(); for (int j = 1; j <= colCount; j++) { dr[j - 1] = numbers[i, j]; } dt.Rows.Add(dr); } return(dt); }
public DataTable Convert2DArraytoDatatable(Object[,] numbers) { DataTable dt = new DataTable(); int colCount = numbers.GetLength(1); int rowCount = numbers.GetLength(0); dt = new DataTable(); if (true == IsHeader) { DataRow dr = null; for (int i = 1; i <= rowCount; i++) { if (1 != i) { dr = dt.NewRow(); } for (int j = 1; j <= colCount; j++) { if (1 == i) { dt.Columns.Add(numbers[i, j].ToString()); } else { dr[j - 1] = numbers[i, j]; } } if (1 != i) { dt.Rows.Add(dr); } } } else { for (int c = 1; c <= colCount; c++) { dt.Columns.Add("Column" + (c)); } for (int i = 1; i <= rowCount; i++) { DataRow dr = dt.NewRow(); for (int j = 1; j <= colCount; j++) { dr[j - 1] = numbers[i, j]; } dt.Rows.Add(dr); } } return(dt); }
public GameSpace() { gameBoard = new Object[gameSizeX, gameSizeY]; for (int x = 0; x < gameBoard.GetLength(0); x++) { for (int y = 0; y < gameBoard.GetLength(1); y++) { gameBoard[x, y] = null; } } }
int marcaMina; //numero de minas por marcar public void InicializarPartidaTablero() { game.setmines(); marcaMina = game.Mina; for (int i = 0; i < tableroJuego.GetLength(0); i++) { for (int j = 0; j < tableroJuego.GetLength(0); j++) { tableroJuego[i, j] = "#"; } } }
public Object[,] Valor(Object[,] mt, int s) { // matriz valor Object[,] TVal = new Object[519, 3]; ArrayList Lista = new ArrayList(); // columna de valor for (int i = 1; i < mt.GetLength(0); i++) { for (int j = 1; j < mt.GetLength(1); j++) { if (!mt[i, j].Equals("-")) { Lista.Add(mt[i, j]); } } } ArrayList l; //columna de col l = new ArrayList(); { for (int i = 1; i < mt.GetLength(0); i++) { for (int j = 1; j < mt.GetLength(1); j++) { for (int x = 0; x < Lista.Count; x++) { if (mt[i, j].Equals(Lista[x])) { l.Add(mt[0, j]); break; } } } } } for (int x = 0; x < l.Count; x++) { if (l[x].Equals("C")) { l[x] = ';'; } } TVal[0, 0] = "X"; TVal[0, 1] = "valor"; TVal[0, 2] = "Col"; for (int i = 1; i < 519; i++) { TVal[i, 0] = i; TVal[i, 1] = Lista[i - 1]; TVal[i, 2] = l[i - 1]; } return(TVal); }
void ResetLevel() { for (int i = 0; i < levelObjArray.GetLength(0); i++) { for (int j = 0; j < levelObjArray.GetLength(1); j++) { Debug.Log("destroying object"); Destroy(levelObjArray[i, j]); levelIntArray[i, j] = 0; } } SetupLevel(); }
private static void OutputCSV(Object[,] data, string csvname = "test") { using (StreamWriter outfile = new StreamWriter(String.Format("C:/Temp/{0}.csv", csvname))) { for (int x = 0; x < data.GetLength(0); x++) { string content = ""; for (int y = 0; y < data.GetLength(1); y++) { content += data[x, y] + ","; } outfile.WriteLine(content); } } }
private SRMData CreateSRMFData(string datarange, bool cumulative) { try { Object[,] dataCells = IOOperation.GetInstance().Read(datarange); if (dataCells == null) { throw new InvalidDataRange(); } switch (dataCells.GetLength(1)) { case 1: return(SetDataOneColumn(dataCells, cumulative)); case 2: return(SetDataTwoColumn(dataCells, cumulative)); case 3: return(SetDataThreeColumn(dataCells, cumulative)); default: throw new WrongColumn(); } } catch { throw new InvalidDataRange(); } }
protected void Button1_Click(object sender, EventArgs e) { double a; string b, c; a = Convert.ToDouble(TextBox1.Text); b = DropDownList1.Text; c = DropDownList2.Text; int ii = 0; int jj = 0; for (int i = 1; i < array.GetLength(1); i++) { if (b.Equals((String)array[0, i])) { ii = i; } if (c.Equals((String)array[0, i])) { jj = i; } } double result; result = a * Convert.ToDouble(array[ii, jj]); TextBox2.Text = Convert.ToString(result); }
public int Get_CulCount() { var cel = ws.UsedRange; Object[,] cel1 = (Object[, ])cel.Value; return(cel1.GetLength(1)); }
public void Print(Object[,] est, RichTextBox rtb) { string s = "\n"; for (int i = 0; i < est.GetLength(0); i++) { s += " "; for (int j = 0; j < est.GetLength(1); j++) { s += est[i, j].ToString() + " "; } s += "\n"; } s += "\n"; rtb.AppendText(s); }
public ExportParams(Object[,] data, String[] exportColumnFields) : this(exportColumnFields) { if (data == null) { return; } if (data.GetLength(1) != 2) { throw new ArgumentException("参数维度应为2"); } for (int i = 0; i < data.GetLength(0); i++) { this.Parameters.Add(data[i, 0], data[i, 1]); } }
public static void LogBoard(Object[,] array, string trueChar, string falseChar) { List <string> lines = new List <string>(); for (int i = array.GetLength(1) - 1; i >= 0; i--) { List <string> cells = new List <string>(); for (int j = 0; j < array.GetLength(0); j++) { cells.Add(array[j, i] ? trueChar : falseChar); } lines.Add(string.Join(" ", cells.ToArray())); } string value = string.Join("\n", lines.ToArray()); Debug.Log(value); }
/// <summary> /// 读取EXCEL文件上的数据表 /// </summary> /// <param name="Path">EXCEL文件的路径</param> /// <param name="pageNumber">EXCEL表的页数(sheet),从1开始</param> /// <returns></returns> public static DataTable ExcelToDT(String Path, int sheetNumber, Boolean readOnly, Boolean editable) { DataTable dt = new DataTable(); object missing = System.Reflection.Missing.Value; Excel.Application excelApp = new Excel.Application(); Excel.Workbook wb = excelApp.Application.Workbooks.Open(Path, missing, readOnly, missing, missing, missing, missing, missing, missing, editable, missing, missing, missing, missing, missing); Excel.Worksheet ws = (Excel.Worksheet)wb.Worksheets.get_Item(sheetNumber); int rowsCount = ws.UsedRange.Cells.Rows.Count; int columsCount = ws.UsedRange.Cells.Columns.Count; Object[,] arry = (Object[, ])ws.UsedRange.Value2; int i = arry.GetLength(0); int j = arry.GetLength(1); dt = ConvertToDataTable(arry); return(dt); }
public ValueEval GetAreaValueEval(int firstRowIndex, int firstColumnIndex, int lastRowIndex, int lastColumnIndex, Object[,] tokens) { ValueEval[] values = new ValueEval[tokens.GetLength(0) * tokens.GetLength(1)]; int index = 0; for (int jdx = 0; jdx < tokens.GetLength(0); jdx++) { for (int idx = 0; idx < tokens.GetLength(1); idx++) { values[index++] = convertObjectEval(tokens[jdx, idx]); } } return(new CacheAreaEval(firstRowIndex, firstColumnIndex, lastRowIndex, lastColumnIndex, values)); }
public virtual void CopyValues(Object[,] values_tem) { if (values_tem != null) { if (values_tem.GetLength(0) == Values.GetLength(0) && values_tem.GetLength(1) == Values.GetLength(1)) { int row = Values.GetLength(0); int col = Values.GetLength(1); for (int x = 0; x < row; x++) { for (int y = 0; y < col; y++) { SetValue(x, y, values_tem[x, y]); } } } } }
private void StoreExcelRangeToTable(Dictionary <String, String> parameters) { if (parameters.ContainsKey("Table") && parameters.ContainsKey("SourceWorksheet") && CheckWorksheetExists(parameters["SourceWorksheet"])) { Range excelRange = null; if ((parameters.ContainsKey("RangeStart") ^ (parameters.ContainsKey("RangeStartVariable") && EngineState.VariableDictionary.ContainsKey(parameters["RangeStartVariable"]))) && (parameters.ContainsKey("RangeEnd") ^ (parameters.ContainsKey("RangeEndVariable") && EngineState.VariableDictionary.ContainsKey(parameters["RangeEndVariable"])))) { excelRange = _excelWorkbook.Sheets[parameters["SourceWorksheet"]].Range(parameters["RangeStart"] ?? EngineState.VariableDictionary["RangeStartVariable"], parameters["RangeEnd"] ?? EngineState.VariableDictionary["RangeEndVariable"]); } else { excelRange = _excelWorkbook.Sheets[parameters["SourceWorksheet"]].UsedRange; } if (excelRange != null) { using (System.Data.DataTable table = new System.Data.DataTable(parameters["Table"])) { Object[,] values = (Object[, ])excelRange.Value2; for (int i = 1; i <= values.GetLength(1); i++) { table.Columns.Add(values[1, i].ToString()); } for (int i = 2; i <= values.GetLength(0); ++i) { DataRow row = table.NewRow(); for (var j = 1; j <= values.GetLength(1); ++j) { row[j - 1] = values[i, j]; } table.Rows.Add(row); } if (EngineState.TableList.Exists((x) => { return(x.TableName == table.TableName); })) { EngineState.TableList.Remove(EngineState.TableList.Find((x) => { return(x.TableName == table.TableName); })); } table.TableName = parameters["Table"]; EngineState.TableList.Add(table); } } } }
public static bool isNotEmpty(Object[,] pArray) { bool isEmpty = false; for (int i = 0; i < pArray.GetLength(0); i++) { for (int j = 0; j < pArray.GetLength(0); j++) { if (pArray[i, j] != null) { isEmpty = true; break; } } } return(isEmpty); }
/// <summary> /// 학과정보, 학수번호, 분반 정보를 가지고 엑셀정보에서 해당 과목 정보를 가져온다. /// </summary> /// <param name="id">현재 접속중인 사용자</param> /// <param name="major">학과 이름</param> /// <param name="number">학수 번호</param> /// <param name="division">분반</param> /// <returns>엑셀에서 관심과목 담고자 하는 과목 정보</returns> public InterestLectureVO GetInterestLecture(string id, string major, string number, string division) { InterestLectureVO interest = new InterestLectureVO(); int count = 1; for (int row = 2; row <= lectureInformation.GetLength(0); row++) { if (Regex.IsMatch(lectureInformation[row, 2].ToString(), major) && lectureInformation[row, 3].Equals(number) && lectureInformation[row, 4].Equals(division)) { interest.Id = id; interest.No = lectureInformation[row, 1].ToString(); interest.Major = lectureInformation[row, 2].ToString(); interest.Number = lectureInformation[row, 3].ToString(); interest.Division = lectureInformation[row, 4].ToString(); interest.Name = lectureInformation[row, 5].ToString(); interest.Completion = lectureInformation[row, 6].ToString(); interest.Grade = lectureInformation[row, 7].ToString(); interest.Credit = lectureInformation[row, 8].ToString(); interest.Time = lectureInformation[row, 9].ToString(); if (lectureInformation[row, 10] != null) { interest.Room = lectureInformation[row, 10].ToString(); } else { interest.Room = ""; } interest.Professor = lectureInformation[row, 11].ToString(); interest.Language = lectureInformation[row, 12].ToString(); return(interest); } count++; } if (count.Equals(lectureInformation.GetLength(0))) { return(null); } else { return(interest); } }
private SqlCommand buildCommand(String query, Object[,] paramList) { SqlCommand cmd = new SqlCommand(query, connection); for (int i = 0; i < paramList.GetLength(0); ++i) { cmd.Parameters.AddWithValue(paramList[i, 0].ToString(), paramList[i, 1]); } return(cmd); }