public override bool Select(string SQL) { pErrorMsg = "No error"; pErrorCode = 0; try { SqlCeCommand command = new SqlCeCommand(SQL, DataBasePDA.Get()); RecordSet Set = new RecordSet(command.ExecuteReader()); Set.Next(); string[] fields = Set.Fileds(); Rows = new List<DataRows>(); while(!Set.Eof) { DataRows row = new DataRows(); foreach (string fieldname in fields) { row.AddField(new DataField(fieldname, Set.FieldByName(fieldname))); } Rows.Add(row); Set.Next(); } } catch(Exception ex) { pErrorMsg = ex.Message; pErrorCode = 1; throw; //return false; } return true; }
public void SaveSanitizedResults() { Sanitize(); var output = new List <string>(); if (HeaderRow != null) { output.Add(HeaderRowString); } output.AddRange(DataRows.Select(r => r.ToRowString(delimiter[0]))); File.WriteAllLines(Output_Filename, output.ToArray()); //write error file if needed if (HasErrors) { output.Clear(); if (HeaderRow != null) { output.Add(ERROR_HDR_ROW); } output.AddRange(DataRows.SelectMany(r => r.Values.Where(v => !v.IsValid) .Select(v => $"{r.Position}{delimiter[0]}{v.FieldName}{delimiter[0]}{v.OriginalValue}{delimiter[0]}{v.ErrorMsg}"))); File.WriteAllLines(Error_Filename, output.ToArray()); } }
protected virtual void ClearRenderingData() { if (HeaderPartRenderer != null) { HeaderPartRenderer.Dispose(); HeaderPartRenderer = null; } if (BodyPartRenderer != null) { BodyPartRenderer.Dispose(); BodyPartRenderer = null; } if (FooterPartRenderer != null) { FooterPartRenderer.Dispose(); FooterPartRenderer = null; } foreach (ExcelRenderer nestedRenderer in NestedRenderer) { nestedRenderer.ClearRenderingData(); } NestedRenderer.Clear(); DataRows.Clear(); RenderedRange = null; contextItems = null; cells = null; }
private static void AddDataRows( this CellCursor cursor, DataRows dataRows, ReportToWorkbookProjectionContext context, PassKind passKind) { if (dataRows == null) { return; } if (dataRows.Rows.Any()) { for (var x = 0; x < dataRows.Rows.Count; x++) { cursor.ResetColumn(); cursor.MoveDown(); if (x == 0) { cursor.AddMarker(TopLeftDataCellMarker); } if (passKind == PassKind.Formatting) { cursor.CanvassedRowRange.ApplyDataRowsFormat(dataRows.Format); } cursor.AddRow(dataRows.Rows[x], context, passKind, dataRows.Format); } cursor.AddMarker(BottomRightDataCellMarker); } }
public PDAField(DataRows row) { Name = row.FieldByName("COLUMN_NAME"); Nullable = row.FieldByName("IS_NULLABLE").ToUpper() == "YES"; DataType = row.FieldByName("DATA_TYPE"); SLen = row.FieldByNameDef("CHARACTER_MAXIMUM_LENGTH", ""); PLen = row.FieldByNameDef("NUMERIC_PRECISION", ""); DLen = row.FieldByNameDef("NUMERIC_SCALE", ""); if (SLen != "") FullDataType = DataType + "(" + SLen + ")"; else { if (PLen != "") { if (DLen != "") FullDataType = DataType + "(" + PLen + ", " + DLen + ")"; else FullDataType = DataType + "(" + PLen + ")"; } else FullDataType = DataType; } if (DataType.ToLower() == "datetime") FullDataType = DataType; List<DataRows> lst; q.Select( "SELECT a.Column_name FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE a, INFORMATION_SCHEMA.TABLE_CONSTRAINTS b WHERE (a.CONSTRAINT_NAME = b.CONSTRAINT_NAME) AND (a.TABLE_NAME = '"+ row.FieldByName("TABLE_NAME")+"') AND COLUMN_NAME='"+Name+"' ORDER BY a.TABLE_NAME"); lst = q.GetRows(); if(lst.Count>0) { IsPK = true; } }
private void treeView1_DragDrop(object sender, DragEventArgs e) { TreeNode tn = e.Data.GetData("System.Windows.Forms.TreeNode") as TreeNode; TreeViewHitTestInfo hi = treeView1.HitTest(treeView1.PointToClient(new Point(e.X, e.Y))); if (hi.Node != null && tn != null) { DataRow rSrc = tn.Tag as DataRow; DataRow rDest = hi.Node.Tag as DataRow; SqlConnection conn = new SqlConnection(@"Server=Gandalf\SQL2K;Integrated Security=true;Database=treeview"); conn.Open(); int dashpos = rSrc["TreeKey"].ToString().LastIndexOf('-'); string subSrc = (dashpos > 0 ? rSrc["TreeKey"].ToString().Substring(0, dashpos) : ""); SqlCommand cmd = new SqlCommand("update datatable set treekey = '" + rDest["TreeKey"].ToString() + "' + right(treekey, len(treekey) - len('" + subSrc + "')) where left(treekey, len('" + rSrc["TreeKey"].ToString() + "')) + '-' = '" + rSrc["TreeKey"].ToString() + "-" + "'", conn); cmd.ExecuteNonQuery(); conn.Close(); drows = new DataRows(); treeView1.Nodes.Clear(); TreeNode tnRoot = new TreeNode("Root"); treeView1.Nodes.Add(tnRoot); FillTreeView("", tnRoot); } else { MessageBox.Show("Not found"); } }
IEnumerable <CellStyle> GetAllStyles() { var header = Columns.SelectMany(x => new[] { x.HeaderStyle, x.RowStyle }); var rows = DataRows.SelectMany(x => x.ExceptNull().OfType <Cell>()).Select(x => x.Style); var groupings = Columns.Where(c => c.GroupName.HasValue()).Select(x => x.GroupingStyle); return(header.Concat(rows).Concat(groupings).Distinct(x => x.GetStyleId()).ToArray()); }
public static void Add(DataRows row) { PDAConstr c = new PDAConstr(row); foreach (PDATable table in PDATable.tables) { if (table.Name == row.FieldByNameDef("TABLE_NAME", "")) table.Constr.Add(c); } constr.Add(c); }
/// <summary> /// Get the /// </summary> /// <typeparam name="TModel"></typeparam> /// <returns></returns> public TModel FirstRow <TModel>() { if (DataRows == null) { return(typeof(TModel).IsClass ? (TModel)ReflectionUtils.Null <object>() : default(TModel)); } // select the first row return((TModel)DataRows.FirstOrDefault()); }
public static void Add(DataRows row) { PDAConstr c = new PDAConstr(row); foreach (PDATable table in PDATable.tables) { if (table.Name == row.FieldByNameDef("TABLE_NAME", "")) { table.Constr.Add(c); } } constr.Add(c); }
private void AddField(DataRows row) { foreach (PDAField field in fields) { if (field.Name == row.FieldByName("COLUMN_NAME")) { throw new Exception("Двойное поле"); } } PDAField newfield = new PDAField(row); fields.Add(newfield); }
public override void Render() { if (IsDisposed) { return; } base.Render(); toOperateOnSheetCalculation = DataRows?.SelectMany(r => r.Where(ci => ci is IFormulaCalculation)) .Select(c => (IFormulaCalculation)c).ToArray(); RenderDataOnly(); }
public void PushRowsToPowerBI(PBIRows rows, PBIAPIClient powerBiAPI = null) { if (DataRows == null) { DataRows = new List <PBIRow>(); } if (rows != null) { DataRows.AddRange(rows.Rows); } PushRowsToPowerBI(PBIJsonHelper.SerializeObject(DataRows), powerBiAPI); }
public void LoadManyAndSelectPosTest() { BridgesReader reader = new BridgesReader(); reader.query = query; Expect.Call(query.Select(SQLSelectBridgesMode.SelectPos)).Return(true); List <DataRows> rows = new List <DataRows>(); DataRows row = new DataRows(); row.AddField(new DataField("BRNAME", "Most1")); row.AddField(new DataField("KM", 12.56)); row.AddField(new DataField("NUM", "P-86")); row.AddField(new DataField("RDNAME", "Road1")); row.AddField(new DataField("ID", 10)); rows.Add(row); row = new DataRows(); row.AddField(new DataField("BRNAME", "Most2")); row.AddField(new DataField("KM", 14.45)); row.AddField(new DataField("NUM", "P-86")); row.AddField(new DataField("RDNAME", "Road1")); row.AddField(new DataField("ID", 11)); rows.Add(row); row = new DataRows(); row.AddField(new DataField("BRNAME", "Most3")); row.AddField(new DataField("KM", 14.45)); row.AddField(new DataField("NUM", "P-89")); row.AddField(new DataField("RDNAME", "Road2")); row.AddField(new DataField("ID", 12)); rows.Add(row); row = new DataRows(); row.AddField(new DataField("BRNAME", "Most4")); row.AddField(new DataField("KM", 14.45)); row.AddField(new DataField("NUM", "P-89")); row.AddField(new DataField("RDNAME", "Road2")); row.AddField(new DataField("ID", 13)); rows.Add(row); Expect.Call(query.GetRows()).Return(rows); repository.ReplayAll(); List <RoadData> records = reader.Load(BridgesReader.BrViewMode.viewPos); Assert.AreEqual("P-86 Road1", records[0].Name); Assert.AreEqual("(12,56) Most1", records[0].Bridges[0].Name); Assert.AreEqual(10, records[0].Bridges[0].IDBR); Assert.AreEqual("P-89 Road2", records[1].Name); Assert.AreEqual("(14,45) Most4", records[1].Bridges[1].Name); Assert.AreEqual(13, records[1].Bridges[1].IDBR); Assert.AreEqual(2, records[0].Bridges.Count); Assert.AreEqual(2, records[1].Bridges.Count); repository.VerifyAll(); }
public static void Add(DataRows row) { foreach (PDATable table in tables) { if(table.Name == row.FieldByName("TABLE_NAME")) { table.AddField(row); return; } } PDATable newtable = new PDATable(); newtable.Name = row.FieldByName("TABLE_NAME"); tables.Add(newtable); newtable.AddField(row); }
private void UpdateRows(List <List <string> > rows) { if (DataTable == null) { DataTable = new DataTable(); } if (rows != null) { DataTable.Rows.Clear(); DataRows.ForEach(x => DataTable.Rows.Add(x.ToArray <object>())); } DisplayTable.ItemsSource = DataTable.DefaultView; }
public void LoadTest() { List<FieldInfo> lf; FieldInfo.query = query; Expect.Call(query.Select(string.Format(FieldInfo.sql,1))).Return(true); List<DataRows> rows=new List<DataRows>(); DataRows row = new DataRows(); row.AddField(new DataField("fieldname","testvalue")); rows.Add(row); Expect.Call(query.GetRows()).Return(rows); repository.ReplayAll(); lf=FieldInfo.LoadFields(1); repository.VerifyAll(); Assert.AreEqual(1,lf.Count); Assert.AreEqual("testvalue",lf[0].fieldName); }
public static void Add(DataRows row) { foreach (PDATable table in tables) { if (table.Name == row.FieldByName("TABLE_NAME")) { table.AddField(row); return; } } PDATable newtable = new PDATable(); newtable.Name = row.FieldByName("TABLE_NAME"); tables.Add(newtable); newtable.AddField(row); }
public void LoadManyAndSelectPosTest() { BridgesReader reader = new BridgesReader(); reader.query = query; Expect.Call(query.Select(SQLSelectBridgesMode.SelectPos)).Return(true); List<DataRows> rows = new List<DataRows>(); DataRows row = new DataRows(); row.AddField(new DataField("BRNAME", "Most1")); row.AddField(new DataField("KM", 12.56)); row.AddField(new DataField("NUM", "P-86")); row.AddField(new DataField("RDNAME", "Road1")); row.AddField(new DataField("ID", 10)); rows.Add(row); row = new DataRows(); row.AddField(new DataField("BRNAME", "Most2")); row.AddField(new DataField("KM", 14.45)); row.AddField(new DataField("NUM", "P-86")); row.AddField(new DataField("RDNAME", "Road1")); row.AddField(new DataField("ID", 11)); rows.Add(row); row = new DataRows(); row.AddField(new DataField("BRNAME", "Most3")); row.AddField(new DataField("KM", 14.45)); row.AddField(new DataField("NUM", "P-89")); row.AddField(new DataField("RDNAME", "Road2")); row.AddField(new DataField("ID", 12)); rows.Add(row); row = new DataRows(); row.AddField(new DataField("BRNAME", "Most4")); row.AddField(new DataField("KM", 14.45)); row.AddField(new DataField("NUM", "P-89")); row.AddField(new DataField("RDNAME", "Road2")); row.AddField(new DataField("ID", 13)); rows.Add(row); Expect.Call(query.GetRows()).Return(rows); repository.ReplayAll(); List<RoadData> records = reader.Load(BridgesReader.BrViewMode.viewPos); Assert.AreEqual("P-86 Road1", records[0].Name); Assert.AreEqual("(12,56) Most1", records[0].Bridges[0].Name); Assert.AreEqual(10, records[0].Bridges[0].IDBR); Assert.AreEqual("P-89 Road2", records[1].Name); Assert.AreEqual("(14,45) Most4", records[1].Bridges[1].Name); Assert.AreEqual(13, records[1].Bridges[1].IDBR); Assert.AreEqual(2, records[0].Bridges.Count); Assert.AreEqual(2, records[1].Bridges.Count); repository.VerifyAll(); }
// Use this for initialization IEnumerator WaitForRequest() { string urli = "https://aca-karelia01.elisaiot.com/Thingworx/Things/LTTNS15_G3_ToinenThing/Properties/LED"; WWWForm form = new WWWForm(); DataTeksti datateksti = new DataTeksti(); DataRows datarows = new DataRows(); datateksti.LED = LED; string k = JsonUtility.ToJson(datateksti); Debug.Log("string : " + k); datarows.rows = "[" + k + "]"; //<-- string l = JsonUtility.ToJson(datarows); Debug.Log("string l : " + l); UnityWebRequest www = UnityWebRequest.Put(urli, k); string authorization = authenticate("name", "pw"); www.SetRequestHeader("Authorization", authorization); www.SetRequestHeader("postman-token", "07c850ec-0eb6-08c8-900c-246ed5cfbf6a"); www.SetRequestHeader("Cache-control", "no-cache"); www.SetRequestHeader("Content-Type", "application/json"); www.SetRequestHeader("Accept", "application/json"); yield return(www.Send()); if (www.error == null && www != null) { Debug.Log("TurnLight Complete!"); Debug.Log("Complete Responsecode: " + www.responseCode); } else { Debug.Log("WWW Error: " + www.downloadHandler.text); Debug.Log("Error Responsecode: " + www.responseCode); } if (!string.IsNullOrEmpty(www.error)) { Debug.Log(www.error); } }
public string MergePoints(string dbName, string meas, [FromBody] DataRows data, string type = "float", string minInterval = null, bool onlyChangedValues = false) { using ( MeLog.LogDebug( $"db: {dbName}, meas: {meas}, point#: {data.Rows.Count}, minInterval: {minInterval}, onlyChangedValues: {onlyChangedValues}")) { IMeasurement measurement = null; Locker.WriterLock(() => { var myDb = DbService.DbManagement.GetDb(dbName); measurement = myDb.GetOrCreateMeasurement(meas, type); }); measurement.MergeDataPoints(data.AsIDataRows(), i => onlyChangedValues ? i.ValueChanges() : i.MinimalTimeSpan(minInterval)); return("ok"); } }
/// <summary> /// Cast to the list of generic models /// </summary> /// <typeparam name="TModel"></typeparam> /// <returns></returns> public TModel[] ResultToArray <TModel>() { if (DataRows == null) { return(ReflectionUtils.Null <TModel[]>()); } if (typeof(string).IsAssignableFrom(typeof(TModel))) { StringAdapter[] adapters = DataRows.AsParallel().Cast <StringAdapter>() .ToArray(); return((TModel[])((object)adapters.ConvertToStrings())); } return(DataRows.AsParallel().Cast <TModel>() .ToArray()); }
public void ParseContents(string[] data) { if (RemoveEmptyEntries) { data = data.Where(s => !string.IsNullOrWhiteSpace(s)).ToArray(); } if (data.Count() == 0) { ErrorMsg = "Empty files cannot be processed."; return; } //Fill header and content vars string[] dataLines = null; if (HasHeader == true || IsHeader(data[0])) { HeaderRow = data[0].Split(delimiter, StringSplitOptions.None).ToArray(); dataLines = data.Skip(1).ToArray(); } else { Console.WriteLine($"No header detected in {Filename}"); dataLines = data; } int lineCount = dataLines.Count(); if (lineCount == 0) { return; } //get adder for position of row in file int adder = 1; if (HeaderRow != null) { adder++; } DataRows = Enumerable.Range(0, lineCount).Select(ind => new Row(dataLines[ind], delimiter, FieldCount, ind + adder, globalDisallowed)).ToArray(); //Add any extra data rows found, if applicable DataRows = DataRows.Concat(DataRows.SelectMany(r => r.ExtraRows)).ToArray(); }
public string WritePoints(string dbName, string meas, [FromBody] DataRows data, string type = "float", bool truncateDbToFirstElement = false) { using ( MeLog.LogDebug( $"db: {dbName}, meas: {meas}, point#: {data.Rows.Count}, trunc: {truncateDbToFirstElement}")) { IMeasurement measurement = null; Locker.WriterLock(() => { var myDb = DbService.DbManagement.GetDb(dbName); measurement = myDb.GetOrCreateMeasurement(meas, type); }); measurement.AppendDataPoints(data.AsIDataRows()); return("ok"); } }
public void LoadTest() { List <FieldInfo> lf; FieldInfo.query = query; Expect.Call(query.Select(string.Format(FieldInfo.sql, 1))).Return(true); List <DataRows> rows = new List <DataRows>(); DataRows row = new DataRows(); row.AddField(new DataField("fieldname", "testvalue")); rows.Add(row); Expect.Call(query.GetRows()).Return(rows); repository.ReplayAll(); lf = FieldInfo.LoadFields(1); repository.VerifyAll(); Assert.AreEqual(1, lf.Count); Assert.AreEqual("testvalue", lf[0].fieldName); }
public PDAField(DataRows row) { Name = row.FieldByName("COLUMN_NAME"); Nullable = row.FieldByName("IS_NULLABLE").ToUpper() == "YES"; DataType = row.FieldByName("DATA_TYPE"); SLen = row.FieldByNameDef("CHARACTER_MAXIMUM_LENGTH", ""); PLen = row.FieldByNameDef("NUMERIC_PRECISION", ""); DLen = row.FieldByNameDef("NUMERIC_SCALE", ""); if (SLen != "") { FullDataType = DataType + "(" + SLen + ")"; } else { if (PLen != "") { if (DLen != "") { FullDataType = DataType + "(" + PLen + ", " + DLen + ")"; } else { FullDataType = DataType + "(" + PLen + ")"; } } else { FullDataType = DataType; } } if (DataType.ToLower() == "datetime") { FullDataType = DataType; } List <DataRows> lst; q.Select( "SELECT a.Column_name FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE a, INFORMATION_SCHEMA.TABLE_CONSTRAINTS b WHERE (a.CONSTRAINT_NAME = b.CONSTRAINT_NAME) AND (a.TABLE_NAME = '" + row.FieldByName("TABLE_NAME") + "') AND COLUMN_NAME='" + Name + "' ORDER BY a.TABLE_NAME"); lst = q.GetRows(); if (lst.Count > 0) { IsPK = true; } }
private static TableRows BuildTableRows( int numberOfColumns) { var allHeaderRows = BuildFlatRows(numberOfColumns); var headerRows = new HeaderRows(allHeaderRows, A.Dummy <HeaderRowsFormat>()); var allFooterRows = BuildFlatRows(numberOfColumns); var footerRows = new FooterRows(allFooterRows, A.Dummy <FooterRowsFormat>()); var allDataRows = BuildDataRows(numberOfColumns); var dataRows = new DataRows(allDataRows, A.Dummy <DataRowsFormat>()); var result = new TableRows(headerRows, dataRows, footerRows, A.Dummy <RowFormat>()); return(result); }
public void Sanitize() { //Execute santize method for each field on each line and add the result to the output int maxFieldIndex = FieldCount - 1; foreach (Value v in DataRows.SelectMany(r => r.Values)) { //check for fields that don't exist if (v.FieldIndex > maxFieldIndex) { v.SanitizedValue = v.OriginalValue; v.ErrorMsg = "No field definition for this field."; continue; } //if the field does exist, apply its sanitize method FieldDefinitions[v.FieldIndex].Sanitize(v); } }
public void Copy(DataRows value) { // copy each data row children.Copy(value.children); teens.Copy(value.teens); youngs.Copy(value.youngs); adults.Copy(value.adults); seniors.Copy(value.seniors); movingIn.Copy(value.movingIn); deceased.Copy(value.deceased); // compute totals for the total data row total.eduLevel0 = children.eduLevel0 + teens.eduLevel0 + youngs.eduLevel0 + adults.eduLevel0 + seniors.eduLevel0; total.eduLevel1 = children.eduLevel1 + teens.eduLevel1 + youngs.eduLevel1 + adults.eduLevel1 + seniors.eduLevel1; total.eduLevel2 = children.eduLevel2 + teens.eduLevel2 + youngs.eduLevel2 + adults.eduLevel2 + seniors.eduLevel2; total.eduLevel3 = children.eduLevel3 + teens.eduLevel3 + youngs.eduLevel3 + adults.eduLevel3 + seniors.eduLevel3; total.movingIn = children.movingIn + teens.movingIn + youngs.movingIn + adults.movingIn + seniors.movingIn; total.deceased = children.deceased + teens.deceased + youngs.deceased + adults.deceased + seniors.deceased; }
public void LoadOneTest() { BridgesReader reader = new BridgesReader(); reader.query = query; Expect.Call(query.Select(SQLSelectBridgesMode.SelectRel)).Return(true); List<DataRows> rows = new List<DataRows>(); DataRows row = new DataRows(); row.AddField(new DataField("BRNAME", "Most1")); row.AddField(new DataField("KM", 12.56)); row.AddField(new DataField("NUM", "P-86")); row.AddField(new DataField("RDNAME", "Road")); row.AddField(new DataField("ID", 10)); rows.Add(row); Expect.Call(query.GetRows()).Return(rows); repository.ReplayAll(); List<RoadData> records = reader.Load(BridgesReader.BrViewMode.viewRel); Assert.AreEqual("P-86 Road", records[0].Name); Assert.AreEqual("(12,56) Most1", records[0].Bridges[0].Name); Assert.AreEqual(10, records[0].Bridges[0].IDBR); repository.VerifyAll(); }
protected void data_separator(string line) { Requires(line != null); string[] temp_lines = line.Split(new char[] { ',', ' ' }, StringSplitOptions.RemoveEmptyEntries); if (temp_lines.Count() > 0) { string[] input_InputAttributestring = new string[InputAttributes.Count()]; double[] input_InputAttributevalue = new double[InputAttributes.Count()]; for (int i = 0; i < InputAttributes.Count(); i++) { if (InputAttributes[i].LabelsValues.Count == 0) { double temp; string comma = System.Globalization.CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator; double.TryParse(temp_lines[i].Replace(".", comma), out temp); input_InputAttributevalue[i] = temp; input_InputAttributestring[i] = ""; } else { input_InputAttributestring[i] = temp_lines[i]; input_InputAttributevalue[i] = double.NaN; } } string class_label = temp_lines[temp_lines.Count() - 1].ToLowerInvariant(); double temp_out = double.NaN; if (OutputAttribute.LabelsValues.Count == 0) { string comma = System.Globalization.CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator; double.TryParse(class_label.Replace(".", comma), out temp_out); class_label = ""; } RowSample temp_Row_sample = new RowSample(input_InputAttributevalue, input_InputAttributestring, temp_out, class_label); DataRows.Add(temp_Row_sample); } }
static DataRowsTest() { ConstructorArgumentValidationTestScenarios .RemoveAllScenarios() .AddScenario(() => new ConstructorArgumentValidationTestScenario <DataRows> { Name = "constructor should throw ArgumentNullException when parameter 'rows' is null", ConstructionFunc = () => { var referenceObject = A.Dummy <DataRows>(); var result = new DataRows( null, referenceObject.Format); return(result); }, ExpectedExceptionType = typeof(ArgumentNullException), ExpectedExceptionMessageContains = new[] { "rows", }, }) .AddScenario(() => new ConstructorArgumentValidationTestScenario <DataRows> { Name = "constructor should throw ArgumentException when parameter 'rows' contains a null element scenario", ConstructionFunc = () => { var referenceObject = A.Dummy <DataRows>(); var result = new DataRows( new Row[0].Concat(referenceObject.Rows).Concat(new Row[] { null }).Concat(referenceObject.Rows).ToList(), referenceObject.Format); return(result); }, ExpectedExceptionType = typeof(ArgumentException), ExpectedExceptionMessageContains = new[] { "rows", "contains at least one null element", }, }); }
/// <summary> /// Get all columns from a table of a database /// </summary> /// <returns></returns> private static string[] GetAllTables(SqlConnection con, string databaseName) { string query = @"use " + databaseName + @"; SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE = 'BASE TABLE' AND TABLE_CATALOG='" + databaseName.Replace("[", "").Replace("]", "") + "'"; SqlDataReader reader = new SqlCommand(query, con).ExecuteReader(); DataRows data = new DataRows(reader, false); reader.Close(); List <string> list = new List <string>(); for (int i = 0; i < data.RowCount; i++) { list.Add(data.FindData("TABLE_NAME", i)); } return(list.ToArray()); }
private void treeView1_DragDrop(object sender, DragEventArgs e) { TreeNode tn = e.Data.GetData("System.Windows.Forms.TreeNode") as TreeNode; TreeViewHitTestInfo hi = treeView1.HitTest( treeView1.PointToClient(new Point(e.X, e.Y))); if (hi.Node != null && tn != null) { DataRows.MyRow rSrc = tn.Tag as DataRows.MyRow; DataRows.MyRow rDest = hi.Node.Tag as DataRows.MyRow; SqlConnection conn = new SqlConnection( @"Data Source=192.168.2.110;Initial Catalog=treeview;User Id=sa;Password=sa;"); conn.Open(); int dashpos = rSrc.TreeKey.LastIndexOf('.'); string subSrc = (dashpos > 0 ? rSrc.TreeKey.Substring(0, dashpos) : ""); SqlCommand cmd = new SqlCommand( "update datatable set treekey = '" + rDest.TreeKey + "' + right(treekey, len(treekey) - len('" + subSrc + "')) where left(treekey, len('" + rSrc.TreeKey + "')) + '.' = '" + rSrc.TreeKey + "." + "'", conn); cmd.ExecuteNonQuery(); conn.Close(); drows = new DataRows(); treeView1.Nodes.Clear(); TreeNode tnRoot = new TreeNode("Root"); treeView1.Nodes.Add(tnRoot); FillTreeView("", tnRoot); SortNodes(null); } else { MessageBox.Show("Not found"); } }
public void LoadOneTest() { BridgesReader reader = new BridgesReader(); reader.query = query; Expect.Call(query.Select(SQLSelectBridgesMode.SelectRel)).Return(true); List <DataRows> rows = new List <DataRows>(); DataRows row = new DataRows(); row.AddField(new DataField("BRNAME", "Most1")); row.AddField(new DataField("KM", 12.56)); row.AddField(new DataField("NUM", "P-86")); row.AddField(new DataField("RDNAME", "Road")); row.AddField(new DataField("ID", 10)); rows.Add(row); Expect.Call(query.GetRows()).Return(rows); repository.ReplayAll(); List <RoadData> records = reader.Load(BridgesReader.BrViewMode.viewRel); Assert.AreEqual("P-86 Road", records[0].Name); Assert.AreEqual("(12,56) Most1", records[0].Bridges[0].Name); Assert.AreEqual(10, records[0].Bridges[0].IDBR); repository.VerifyAll(); }
public override bool Select(string SQL) { OracleCommand command = new OracleCommand(SQL, DataBaseOracle.Get()); OracleDataReader reader; try { reader = command.ExecuteReader(); } catch(Exception) { return false; } DataRows row; Rows=new List<DataRows>(); while (reader.Read()) { row = new DataRows(); for (int i = 0; i < reader.FieldCount; i++) row.AddField(new DataField(reader.GetName(i), Convert.ToString(reader.GetValue(i)))); Rows.Add(row); } DataBaseOracle.Disconnect(); return true; }
public static void Constructor___Does_not_throw___When_all_rows_span_all_columns() { // Arrange var tableColumns = new TableColumns(Some.ReadOnlyDummies <Column>(3).ToList()); var allHeaderRows = new[] { new FlatRow( new ICell[] { A.Dummy <NotSlottedCellBase>().DeepCloneWithColumnsSpanned(null), A.Dummy <NotSlottedCellBase>().DeepCloneWithColumnsSpanned(2), }), new FlatRow( new ICell[] { A.Dummy <NotSlottedCellBase>().DeepCloneWithColumnsSpanned(2), A.Dummy <NotSlottedCellBase>().DeepCloneWithColumnsSpanned(1), }), new FlatRow( new ICell[] { A.Dummy <NotSlottedCellBase>().DeepCloneWithColumnsSpanned(3), }), new FlatRow( new ICell[] { A.Dummy <NotSlottedCellBase>().DeepCloneWithColumnsSpanned(1), A.Dummy <NotSlottedCellBase>().DeepCloneWithColumnsSpanned(null), A.Dummy <NotSlottedCellBase>().DeepCloneWithColumnsSpanned(1), }), }; var headerRows = new HeaderRows(allHeaderRows); var allDataRows = new[] { new Row(new[] { A.Dummy <NotSlottedCellBase>().DeepCloneWithColumnsSpanned(3) }), new Row( Some.ReadOnlyDummies <NotSlottedCellBase>(3).Select(_ => _.DeepCloneWithColumnsSpanned(null)).ToList(), childRows: new[] { new Row(Some.ReadOnlyDummies <NotSlottedCellBase>(3).Select(_ => _.DeepCloneWithColumnsSpanned(null)).ToList()), new Row(Some.ReadOnlyDummies <NotSlottedCellBase>(3).Select(_ => _.DeepCloneWithColumnsSpanned(null)).ToList()), new Row( new ICell[] { A.Dummy <NotSlottedCellBase>().DeepCloneWithColumnsSpanned(2), A.Dummy <NotSlottedCellBase>().DeepCloneWithColumnsSpanned(null), }), }), new Row( Some.ReadOnlyDummies <NotSlottedCellBase>(3).Select(_ => _.DeepCloneWithColumnsSpanned(null)).ToList(), childRows: new[] { new Row(Some.ReadOnlyDummies <NotSlottedCellBase>(3).Select(_ => _.DeepCloneWithColumnsSpanned(1)).ToList()), new Row( new ICell[] { A.Dummy <NotSlottedCellBase>().DeepCloneWithColumnsSpanned(1), A.Dummy <NotSlottedCellBase>().DeepCloneWithColumnsSpanned(2), }), new Row(Some.ReadOnlyDummies <NotSlottedCellBase>(1).Select(_ => _.DeepCloneWithColumnsSpanned(3)).ToList()), }), }; var dataRows = new DataRows(allDataRows); var allFooterRows = new[] { new FlatRow( new ICell[] { A.Dummy <NotSlottedCellBase>().DeepCloneWithColumnsSpanned(null), A.Dummy <NotSlottedCellBase>().DeepCloneWithColumnsSpanned(2), }), new FlatRow( new ICell[] { A.Dummy <NotSlottedCellBase>().DeepCloneWithColumnsSpanned(1), A.Dummy <NotSlottedCellBase>().DeepCloneWithColumnsSpanned(null), A.Dummy <NotSlottedCellBase>().DeepCloneWithColumnsSpanned(1), }), new FlatRow( new ICell[] { A.Dummy <NotSlottedCellBase>().DeepCloneWithColumnsSpanned(2), A.Dummy <NotSlottedCellBase>().DeepCloneWithColumnsSpanned(1), }), new FlatRow( new ICell[] { A.Dummy <NotSlottedCellBase>().DeepCloneWithColumnsSpanned(3), }), }; var footerRows = new FooterRows(allFooterRows); var tableRows = new TableRows(headerRows, dataRows, footerRows); // Act var actual = Record.Exception(() => new TreeTable(tableColumns, tableRows)); // Assert actual.AsTest().Must().BeNull(); }
private PDAConstr(DataRows row) { Name = row.FieldByNameDef("CONSTRAINT_NAME", ""); CType = row.FieldByNameDef("CONSTRAINT_TYPE", ""); }
static TreeTableTest() { ConstructorArgumentValidationTestScenarios .RemoveAllScenarios() .AddScenario(() => new ConstructorArgumentValidationTestScenario <TreeTable> { Name = "constructor should throw ArgumentNullException when parameter 'tableColumns' is null scenario", ConstructionFunc = () => { var referenceObject = A.Dummy <TreeTable>(); var result = new TreeTable( null, referenceObject.TableRows, referenceObject.Format); return(result); }, ExpectedExceptionType = typeof(ArgumentNullException), ExpectedExceptionMessageContains = new[] { "tableColumns", }, }) .AddScenario(() => new ConstructorArgumentValidationTestScenario <TreeTable> { Name = "constructor should throw ArgumentException when parameter 'tableRows' contains a header row that does not span all of the columns in tableColumns", ConstructionFunc = () => { var tableColumns = new TableColumns(Some.ReadOnlyDummies <Column>(2).ToList()); var rows = new[] { new FlatRow(Some.ReadOnlyDummies <NotSlottedCellBase>(2).Select(_ => _.DeepCloneWithColumnsSpanned(1)).ToList()), new FlatRow(Some.ReadOnlyDummies <NotSlottedCellBase>(3).ToList()), }; var headerRows = new HeaderRows(rows, null); var tableRows = new TableRows(headerRows, null); var result = new TreeTable( tableColumns, tableRows); return(result); }, ExpectedExceptionType = typeof(ArgumentException), ExpectedExceptionMessageContains = new[] { "tableRows contains a row or descendant row that does not span all 2 of the defined columns", }, }) .AddScenario(() => new ConstructorArgumentValidationTestScenario <TreeTable> { Name = "constructor should throw ArgumentException when parameter 'tableRows' contains a data row that does not span all of the columns in tableColumns", ConstructionFunc = () => { var tableColumns = new TableColumns(Some.ReadOnlyDummies <Column>(2).ToList()); var rows = new[] { new Row(Some.ReadOnlyDummies <NotSlottedCellBase>(2).Select(_ => _.DeepCloneWithColumnsSpanned(1)).ToList()), new Row( Some.ReadOnlyDummies <NotSlottedCellBase>(2).Select(_ => _.DeepCloneWithColumnsSpanned(1)).ToList(), childRows: new[] { new Row(Some.ReadOnlyDummies <NotSlottedCellBase>(2).Select(_ => _.DeepCloneWithColumnsSpanned(1)).ToList()), new Row(Some.ReadOnlyDummies <NotSlottedCellBase>(3)), new Row(Some.ReadOnlyDummies <NotSlottedCellBase>(2).Select(_ => _.DeepCloneWithColumnsSpanned(1)).ToList()), }), new Row(Some.ReadOnlyDummies <NotSlottedCellBase>(2).Select(_ => _.DeepCloneWithColumnsSpanned(1)).ToList()), }; var dataRows = new DataRows(rows, null); var tableRows = new TableRows(null, dataRows); var result = new TreeTable( tableColumns, tableRows); return(result); }, ExpectedExceptionType = typeof(ArgumentException), ExpectedExceptionMessageContains = new[] { "tableRows contains a row or descendant row that does not span all 2 of the defined columns", }, }) .AddScenario(() => new ConstructorArgumentValidationTestScenario <TreeTable> { Name = "constructor should throw ArgumentException when parameter 'footerRows' contains a footer row that does not span all of the columns in tableColumns", ConstructionFunc = () => { var tableColumns = new TableColumns(Some.ReadOnlyDummies <Column>(2).ToList()); var rows = new[] { new FlatRow(Some.ReadOnlyDummies <NotSlottedCellBase>(2).Select(_ => _.DeepCloneWithColumnsSpanned(1)).ToList()), new FlatRow(Some.ReadOnlyDummies <NotSlottedCellBase>(3).ToList()), }; var footerRows = new FooterRows(rows, null); var tableRows = new TableRows(footerRows: footerRows); var result = new TreeTable( tableColumns, tableRows); return(result); }, ExpectedExceptionType = typeof(ArgumentException), ExpectedExceptionMessageContains = new[] { "tableRows contains a row or descendant row that does not span all 2 of the defined columns", }, }) .AddScenario(() => new ConstructorArgumentValidationTestScenario <TreeTable> { Name = "constructor should throw ArgumentException when two columns have the same identifier", ConstructionFunc = () => { var tableColumns = new TableColumns(new[] { new Column("column-1"), new Column("column-2"), new Column("column-1"), }); var headerRows = new HeaderRows( new[] { new FlatRow(Some.ReadOnlyDummies <NotSlottedCellBase>(3).Select(_ => _.DeepCloneWithColumnsSpanned(1)).ToList()), new FlatRow(Some.ReadOnlyDummies <NotSlottedCellBase>(3).Select(_ => _.DeepCloneWithColumnsSpanned(1)).ToList()), }, null); var dataRows = new DataRows( new[] { new Row(Some.ReadOnlyDummies <NotSlottedCellBase>(3).Select(_ => _.DeepCloneWithColumnsSpanned(1)).ToList()), new Row( Some.ReadOnlyDummies <NotSlottedCellBase>(3).Select(_ => _.DeepCloneWithColumnsSpanned(1)).ToList(), childRows: new[] { new Row(Some.ReadOnlyDummies <NotSlottedCellBase>(3).Select(_ => _.DeepCloneWithColumnsSpanned(1)).ToList()), }), }); var tableRows = new TableRows(headerRows, dataRows); var result = new TreeTable( tableColumns, tableRows); return(result); }, ExpectedExceptionType = typeof(ArgumentException), ExpectedExceptionMessageContains = new[] { "Two or more elements (i.e. columns, rows, cells) have the same identifier.", }, }) .AddScenario(() => new ConstructorArgumentValidationTestScenario <TreeTable> { Name = "constructor should throw ArgumentException when two rows have the same identifier", ConstructionFunc = () => { var tableColumns = new TableColumns(Some.ReadOnlyDummies <Column>(3).ToList()); var headerRows = new HeaderRows( new[] { new FlatRow(Some.ReadOnlyDummies <NotSlottedCellBase>(3).Select(_ => _.DeepCloneWithColumnsSpanned(1)).ToList(), "row-1"), new FlatRow(Some.ReadOnlyDummies <NotSlottedCellBase>(3).Select(_ => _.DeepCloneWithColumnsSpanned(1)).ToList(), "row-2"), }, null); var dataRows = new DataRows( new[] { new Row(Some.ReadOnlyDummies <NotSlottedCellBase>(3).Select(_ => _.DeepCloneWithColumnsSpanned(1)).ToList(), "row-3"), new Row(Some.ReadOnlyDummies <NotSlottedCellBase>(3).Select(_ => _.DeepCloneWithColumnsSpanned(1)).ToList(), childRows: new[] { new Row(Some.ReadOnlyDummies <NotSlottedCellBase>(3).Select(_ => _.DeepCloneWithColumnsSpanned(1)).ToList(), "row-1"), }), }); var tableRows = new TableRows(headerRows, dataRows); var result = new TreeTable( tableColumns, tableRows); return(result); }, ExpectedExceptionType = typeof(ArgumentException), ExpectedExceptionMessageContains = new[] { "Two or more elements (i.e. columns, rows, cells) have the same identifier.", }, }) .AddScenario(() => new ConstructorArgumentValidationTestScenario <TreeTable> { Name = "constructor should throw ArgumentException when two cells have the same identifier", ConstructionFunc = () => { var tableColumns = new TableColumns(Some.ReadOnlyDummies <Column>(3).ToList()); var headerRows = new HeaderRows( new[] { new FlatRow( new ICell[] { A.Dummy <NotSlottedCellBase>().DeepCloneWithColumnsSpanned(1).DeepCloneWithId(null), A.Dummy <NotSlottedCellBase>().DeepCloneWithColumnsSpanned(1).DeepCloneWithId("cell-1"), A.Dummy <NotSlottedCellBase>().DeepCloneWithColumnsSpanned(1).DeepCloneWithId(null), }), new FlatRow(Some.ReadOnlyDummies <NotSlottedCellBase>(3).Select(_ => _.DeepCloneWithColumnsSpanned(1)).ToList()), }, null); var dataRows = new DataRows( new[] { new Row(Some.ReadOnlyDummies <NotSlottedCellBase>(3).Select(_ => _.DeepCloneWithColumnsSpanned(1)).ToList()), new Row( Some.ReadOnlyDummies <NotSlottedCellBase>(3).Select(_ => _.DeepCloneWithColumnsSpanned(1)).ToList(), childRows: new[] { new Row( new ICell[] { A.Dummy <NotSlottedCellBase>().DeepCloneWithColumnsSpanned(null).DeepCloneWithId(null), A.Dummy <NotSlottedCellBase>().DeepCloneWithColumnsSpanned(null).DeepCloneWithId(null), A.Dummy <NotSlottedCellBase>().DeepCloneWithColumnsSpanned(null).DeepCloneWithId("cell-1"), }), }), }); var tableRows = new TableRows(headerRows, dataRows); var result = new TreeTable( tableColumns, tableRows); return(result); }, ExpectedExceptionType = typeof(ArgumentException), ExpectedExceptionMessageContains = new[] { "Two or more elements (i.e. columns, rows, cells) have the same identifier.", }, }) .AddScenario(() => new ConstructorArgumentValidationTestScenario <TreeTable> { Name = "constructor should throw ArgumentException when a cell object is used multiple times", ConstructionFunc = () => { var tableColumns = new TableColumns(Some.ReadOnlyDummies <Column>(3).ToList()); var cell = A.Dummy <CellBase>().DeepCloneWithColumnsSpanned(1).DeepCloneWithId(null); var headerRows = new HeaderRows( new[] { new FlatRow( new ICell[] { A.Dummy <NotSlottedCellBase>().DeepCloneWithColumnsSpanned(1).DeepCloneWithId(null), cell, A.Dummy <NotSlottedCellBase>().DeepCloneWithColumnsSpanned(1).DeepCloneWithId(null), }), new FlatRow(Some.ReadOnlyDummies <NotSlottedCellBase>(3).Select(_ => _.DeepCloneWithColumnsSpanned(1)).ToList()), }, null); var dataRows = new DataRows( new[] { new Row(Some.ReadOnlyDummies <NotSlottedCellBase>(3).Select(_ => _.DeepCloneWithColumnsSpanned(1)).ToList()), new Row( Some.ReadOnlyDummies <NotSlottedCellBase>(3).Select(_ => _.DeepCloneWithColumnsSpanned(1)).ToList(), childRows: new[] { new Row( new ICell[] { A.Dummy <NotSlottedCellBase>().DeepCloneWithColumnsSpanned(null).DeepCloneWithId(null), A.Dummy <NotSlottedCellBase>().DeepCloneWithColumnsSpanned(null).DeepCloneWithId(null), cell, }), }), }); var tableRows = new TableRows(headerRows, dataRows); var result = new TreeTable( tableColumns, tableRows); return(result); }, ExpectedExceptionType = typeof(ArgumentException), ExpectedExceptionMessageContains = new[] { "One or more ICell objects are used multiple times in the tree table.", }, }); DeepCloneWithTestScenarios .RemoveAllScenarios() .AddScenario(() => new DeepCloneWithTestScenario <TreeTable> { Name = "DeepCloneWithTableColumns should deep clone object and replace TableColumns with the provided tableColumns", WithPropertyName = "TableColumns", SystemUnderTestDeepCloneWithValueFunc = () => { var systemUnderTest = A.Dummy <TreeTable>(); var referenceObject = A.Dummy <TreeTable>().ThatIs(_ => !systemUnderTest.TableColumns.IsEqualTo(_.TableColumns) && (_.TableColumns.Columns.Count == systemUnderTest.TableColumns.Columns.Count)); var result = new SystemUnderTestDeepCloneWithValue <TreeTable> { SystemUnderTest = systemUnderTest, DeepCloneWithValue = referenceObject.TableColumns, }; return(result); }, }) .AddScenario(() => new DeepCloneWithTestScenario <TreeTable> { Name = "DeepCloneWithTableRows should deep clone object and replace TableRows with the provided tableRows", WithPropertyName = "TableRows", SystemUnderTestDeepCloneWithValueFunc = () => { var systemUnderTest = A.Dummy <TreeTable>(); var referenceObject = A.Dummy <TreeTable>().ThatIs(_ => !systemUnderTest.TableRows.IsEqualTo(_.TableRows) && ((!_.TableRows.GetAllRowsInOrder().Any()) || (_.TableRows.GetAllRowsInOrder().First().GetNumberOfColumnsSpanned() == systemUnderTest.TableColumns.Columns.Count))); var result = new SystemUnderTestDeepCloneWithValue <TreeTable> { SystemUnderTest = systemUnderTest, DeepCloneWithValue = referenceObject.TableRows, }; return(result); }, }) .AddScenario(() => new DeepCloneWithTestScenario <TreeTable> { Name = "DeepCloneWithFormat should deep clone object and replace Format with the provided format", WithPropertyName = "Format", SystemUnderTestDeepCloneWithValueFunc = () => { var systemUnderTest = A.Dummy <TreeTable>(); var referenceObject = A.Dummy <TreeTable>().ThatIs(_ => !systemUnderTest.Format.IsEqualTo(_.Format)); var result = new SystemUnderTestDeepCloneWithValue <TreeTable> { SystemUnderTest = systemUnderTest, DeepCloneWithValue = referenceObject.Format, }; return(result); }, }); EquatableTestScenarios .RemoveAllScenarios() .AddScenario(() => new EquatableTestScenario <TreeTable> { Name = "Default Code Generated Scenario", ReferenceObject = ReferenceObjectForEquatableTestScenarios, ObjectsThatAreEqualToButNotTheSameAsReferenceObject = new TreeTable[] { new TreeTable( ReferenceObjectForEquatableTestScenarios.TableColumns, ReferenceObjectForEquatableTestScenarios.TableRows, ReferenceObjectForEquatableTestScenarios.Format), }, ObjectsThatAreNotEqualToReferenceObject = new TreeTable[] { new TreeTable( A.Dummy <TreeTable>().Whose(_ => !_.TableColumns.IsEqualTo(ReferenceObjectForEquatableTestScenarios.TableColumns) && (_.TableColumns.Columns.Count == ReferenceObjectForEquatableTestScenarios.TableColumns.Columns.Count)).TableColumns, ReferenceObjectForEquatableTestScenarios.TableRows, ReferenceObjectForEquatableTestScenarios.Format), new TreeTable( ReferenceObjectForEquatableTestScenarios.TableColumns, A.Dummy <TreeTable>().Whose(_ => (!_.TableRows.IsEqualTo(ReferenceObjectForEquatableTestScenarios.TableRows) && ((!_.TableRows.GetAllRowsInOrder().Any()) || (_.TableRows.GetAllRowsInOrder().First().GetNumberOfColumnsSpanned() == ReferenceObjectForEquatableTestScenarios.TableColumns.Columns.Count)))).TableRows, ReferenceObjectForEquatableTestScenarios.Format), new TreeTable( ReferenceObjectForEquatableTestScenarios.TableColumns, ReferenceObjectForEquatableTestScenarios.TableRows, A.Dummy <TreeTable>().Whose(_ => !_.Format.IsEqualTo(ReferenceObjectForEquatableTestScenarios.Format)).Format), }, ObjectsThatAreNotOfTheSameTypeAsReferenceObject = new object[] { A.Dummy <object>(), A.Dummy <string>(), A.Dummy <int>(), A.Dummy <int?>(), A.Dummy <Guid>(), }, }); }
private void AddField(DataRows row) { foreach (PDAField field in fields) { if(field.Name == row.FieldByName("COLUMN_NAME")) throw new Exception("Двойное поле"); } PDAField newfield = new PDAField(row); fields.Add(newfield); }