/// <summary> /// Set rows by column datas. /// </summary> internal protected virtual void SetRowsByDatas() { Rows.collection.Clear(); if (Columns.Count == 0) { return; } MochaData[] datas = new MochaData[Columns.Count]; for (int dataIndex = 0; dataIndex < Columns[0].Datas.Count; ++dataIndex) { for (int columnIndex = 0; columnIndex < Columns.Count; ++columnIndex) { MochaColumn currentColumn = Columns[columnIndex]; if (currentColumn.Datas.Count < dataIndex + 1) { datas[columnIndex] = new MochaData { dataType = currentColumn.DataType, data = MochaData.TryGetData(currentColumn.DataType, string.Empty) } } ; else { datas[columnIndex] = currentColumn.Datas[dataIndex]; } } Rows.collection.Add(new MochaRow(datas)); } }
/// <summary> /// Set rows by column datas. /// </summary> internal void SetRowsByDatas() { Rows.collection.Clear(); MochaArray <MochaData> datas = new MochaData[Columns.Count]; for (int dataIndex = 0; dataIndex < Columns[0].Datas.Count; dataIndex++) { for (int columnIndex = 0; columnIndex < Columns.Count; columnIndex++) { MochaColumn currentColumn = Columns[columnIndex]; if (currentColumn.Datas.Count < dataIndex + 1) { datas[columnIndex] = new MochaData { dataType = currentColumn.DataType, data = MochaData.TryGetData(currentColumn.DataType, "") } } ; else { datas[columnIndex] = currentColumn.Datas[dataIndex]; } } Rows.collection.Add(new MochaRow(datas)); } }
/// <summary> /// Try convert value to MochaData. /// </summary> /// <param name="value">Value.</param> /// <param name="data">Output.</param> public static bool TryParse(object value, out MochaData data) { try { data = Parse(value); return(true); } catch { } data = null; return(false); }
/// <summary> /// Create new MochaRow. /// </summary> /// <param name="datas">Datas of row.</param> public MochaRow(params object[] datas) : this() { for (int dex = 0; dex < datas.Length; dex++) { var data = datas[dex]; Datas.collection.Add( new MochaData() { dataType = MochaData.GetDataTypeFromType(data.GetType()), data = data }); } }
/// <summary> /// Set datas by row datas. /// </summary> internal void SetDatasByRows() { for (int columnIndex = 0; columnIndex < Columns.Count; columnIndex++) { //Columns[columnIndex].Datas.Changed-=Column_Changed; Columns[columnIndex].Datas.collection.Clear(); } for (int rowIndex = 0; rowIndex < Rows.Count; rowIndex++) { MochaRow currentRow = Rows[rowIndex]; if (currentRow.Datas.Count != Columns.Count) { throw new MochaException("The number of data must be equal to the number of columns!"); } for (int columnIndex = 0; columnIndex < Columns.Count; columnIndex++) { MochaColumn currentColumn = Columns[columnIndex]; if (currentColumn.DataType != MochaDataType.AutoInt) { currentColumn.Datas.collection.Add(currentRow.Datas[columnIndex]); } else { MochaData data = new MochaData { data = currentColumn.Datas.Count > 0 ? 1 + (int)currentColumn.Datas[currentColumn.Datas.MaxIndex()].Data : 1, dataType = MochaDataType.AutoInt }; currentColumn.Datas.collection.Add(data); currentRow.Datas.collection[columnIndex] = data; } } } /* * for(int columnIndex = 0; columnIndex < Columns.Count; columnIndex++) { * Columns[columnIndex].Datas.Changed+=Column_Changed; * }*/ }
/// <summary> /// Set datas by row datas. /// </summary> internal protected virtual void SetDatasByRows() { for (int columnIndex = 0; columnIndex < Columns.Count; ++columnIndex) { Columns[columnIndex].Datas.collection.Clear(); } for (int rowIndex = 0; rowIndex < Rows.Count; ++rowIndex) { MochaRow currentRow = Rows[rowIndex]; if (currentRow.Datas.Count != Columns.Count) { throw new ArgumentException("The number of data must be equal to the number of columns!"); } for (int columnIndex = 0; columnIndex < Columns.Count; ++columnIndex) { MochaColumn currentColumn = Columns[columnIndex]; if (currentColumn.DataType != MochaDataType.AutoInt) { currentColumn.Datas.collection.Add(currentRow.Datas[columnIndex]); } else { MochaData data = new MochaData { data = currentColumn.Datas.Count > 0 ? 1 + (int)currentColumn.Datas[currentColumn.Datas.Count - 1].Data : 1, dataType = MochaDataType.AutoInt }; currentColumn.Datas.collection.Add(data); currentRow.Datas.collection[columnIndex] = data; } } } }