//Сгенерировать таблицу по данному ряду public void Generate(TablsList dataTabls, //Список таблиц с данными для генерации DaoRec rec, //Рекордсет генерируемой таблицы DaoRec subrec) //Рекордсет генерируемой подтаблицы { if (!Keeper.ErrMess.IsEmpty()) { return; } IEnumerable <SubRows> rows = Rule == null ? new SubRows[] { null } : ((NodeRTabl)Rule).SelectRows(dataTabls, null); foreach (var row in rows) { rec.AddNew(); int id = rec.GetInt(Table.IdField); GenerateFields(row, rec); rec.Update(); if (subrec != null) { foreach (var subRowGen in SubRows) { IEnumerable <SubRows> subRows = subRowGen.RuleString.IsEmpty() ? new [] { row } : (((INodeRTabl)subRowGen.Rule).SelectRows(dataTabls, row)); foreach (var subRow in subRows) { subrec.AddNew(); subrec.Put(subRowGen.Table.ParentIdField, id); subRowGen.GenerateFields(subRow, subrec); subrec.Update(); } } } } }
//Запись значения в рекордсет клона protected void PutCloneRec(IReadMean mom, //Значение DaoRec rec, //Рекордсет bool isCutTable, //Запись в таблицу срезов DateTime d) //Время среза { rec.AddNew(); rec.Put("SignalId", IdInClone); if (isCutTable) { rec.Put("CutTime", d); } rec.Put("Time", mom.Time); if (mom.Error != null) { rec.Put("ErrNum", mom.Error.Number); } if (DataType.IsReal()) { rec.Put("RealValue", mom.Real); } else if (DataType == DataType.String) { rec.Put("StrValue", mom.String); } else if (DataType == DataType.Time) { rec.Put("TimeValue", mom.Date); } rec.Update(); }
//Запись в рекордсет public void ToRecordset(DaoRec rec, int objectId) { rec.AddNew(); rec.Put("ObjectId", objectId); rec.Put("CodeProp", Code); rec.Put("DataType", DataType.ToRussian()); rec.Put("Mean", Mean.String); rec.Update(); }
//Запись в рекордсет public void ToRecordset(DaoRec rec, int objectId, string objectCode) { rec.AddNew(); rec.Put("ObjectId", objectId); rec.Put("FullCode", objectCode + "." + Code); rec.Put("CodeSignal", Code); rec.Put("NameSignal", Name); rec.Put("DataType", DataType.ToRussian()); rec.Put("SignalType", SignalType); rec.Put("InfOut", InfOut); rec.Put("InfProp", InfProp); rec.Put("InitialSignals", InitialSignals); rec.Put("Formula", Formula); rec.Update(); }
//Запись объекта в рекорсеты вместе с сигналами и свойствами public void ToRecordsets(DaoRec recObjects, DaoRec recSignals, DaoRec recProps) { recObjects.AddNew(); recObjects.Put("CodeObject", Code); recObjects.Put("NameObject", Name); recObjects.Put("InfObject", InfObject); int id = recObjects.GetInt("ObjectId"); recObjects.Update(); foreach (var prop in UsedProps.Values) { prop.ToRecordset(recProps, id); } foreach (var sig in UsedSignals) { sig.ToRecordset(recSignals, id, Code); } }
public void RecWrite() { using (var rec = new DaoRec(CopyDb("Write"), "Tabl")) { rec.Read(); rec.Put("IntField", 11); rec.Put("RealField", 1.6); rec.Put("StringField1", "Большой текст"); rec.Put("StringField2", "TextTextTextTextTextText", true); rec.Put("BoolField", false); rec.Put("TimeField", new DateTime(2016, 07, 02)); Assert.AreEqual(11, rec.GetInt("IntField")); Assert.AreEqual(1.6, rec.GetDouble("RealField")); Assert.AreEqual("Большой текст", rec.GetString("StringField1")); Assert.AreEqual("TextTextTe", rec.GetString("StringField2")); Assert.AreEqual(new DateTime(2016, 07, 02), rec.GetTime("TimeField")); Assert.IsFalse(rec.GetBool("BoolField")); Assert.AreEqual(1, rec.GetInt("Id")); rec.Update(); rec.MoveFirst(); Assert.AreEqual(11, rec.GetInt("IntField")); Assert.AreEqual(1.6, rec.GetDouble("RealField")); Assert.AreEqual("Большой текст", rec.GetString("StringField1")); Assert.AreEqual("TextTextTe", rec.GetString("StringField2")); Assert.AreEqual(new DateTime(2016, 07, 02), rec.GetTime("TimeField")); Assert.IsFalse(rec.GetBool("BoolField")); Assert.AreEqual(1, rec.GetInt("Id")); rec.Put(1, 11); rec.Put(2, 1.6); rec.Put(3, "Большой текст"); rec.Put(4, "TextTextTextTextTextText", true); rec.Put(5, false); rec.Put(6, new DateTime(2016, 07, 02)); Assert.AreEqual(11, rec.GetInt("IntField")); Assert.AreEqual(1.6, rec.GetDouble("RealField")); Assert.AreEqual("Большой текст", rec.GetString("StringField1")); Assert.AreEqual("TextTextTe", rec.GetString("StringField2")); Assert.AreEqual(new DateTime(2016, 07, 02), rec.GetTime("TimeField")); Assert.IsFalse(rec.GetBool("BoolField")); Assert.AreEqual(1, rec.GetInt("Id")); rec.Read(); rec.Put("IntField", (int?)null); rec.Put("RealField", (double?)null); rec.Put("StringField1", (string)null); rec.Put("StringField2", "Text", true); rec.Put("BoolField", (bool?)false); rec.Put("TimeField", (DateTime?)null); Assert.AreEqual(null, rec.GetIntNull("IntField")); Assert.AreEqual(0, rec.GetDouble("RealField")); Assert.AreEqual("", rec.GetString("StringField1", "")); Assert.AreEqual("Text", rec.GetString("StringField2")); Assert.AreEqual(false, rec.GetBoolNull("BoolField")); Assert.AreEqual(2, rec.GetInt("Id")); rec.Read(); rec.MovePrevious(); Assert.AreEqual(0, rec.GetInt("IntField")); Assert.AreEqual(null, rec.GetDoubleNull("RealField")); Assert.AreEqual(null, rec.GetString("StringField1")); Assert.AreEqual("Text", rec.GetString("StringField2")); Assert.AreEqual(null, rec.GetTimeNull("TimeField")); Assert.AreEqual(false, rec.GetBool("BoolField")); Assert.AreEqual(2, rec.GetIntNull("Id")); rec.Put(1, (int?)null); rec.Put(2, (double?)null); rec.Put(3, (string)null); rec.Put(4, "Text", true); rec.Put(5, (bool?)false); rec.Put(6, (DateTime?)null); Assert.AreEqual(null, rec.GetIntNull("IntField")); Assert.AreEqual(0, rec.GetDouble("RealField")); Assert.AreEqual("", rec.GetString("StringField1", "")); Assert.AreEqual("Text", rec.GetString("StringField2")); Assert.AreEqual(false, rec.GetBoolNull("BoolField")); Assert.AreEqual(2, rec.GetInt("Id")); Assert.AreEqual(5, rec.RecordCount); Assert.IsTrue(rec.MoveLast()); rec.Delete(); Assert.AreEqual(4, rec.RecordCount); Assert.IsTrue(rec.MoveLast()); Assert.AreEqual(40, rec.GetInt("IntField")); Assert.AreEqual(4.5, rec.GetDouble("RealField")); Assert.AreEqual("Большой текст 4", rec.GetString("StringField1")); Assert.IsTrue(rec.MoveLast()); Assert.IsFalse(rec.MoveNext()); Assert.IsTrue(rec.EOF); rec.AddNew(); rec.Put("IntField", 60); rec.Put("RealField", 6.6); rec.Put("StringField1", "Большой текст 6"); rec.Put("StringField2", "Text6", true); rec.Put("BoolField", true); rec.Put("TimeField", new DateTime(2016, 07, 06)); Assert.AreEqual(60, rec.GetInt("IntField")); Assert.AreEqual(6.6, rec.GetDouble("RealField")); Assert.AreEqual("Большой текст 6", rec.GetString("StringField1")); Assert.AreEqual("Text6", rec.GetString("StringField2")); Assert.AreEqual(new DateTime(2016, 07, 06), rec.GetTime("TimeField")); Assert.IsTrue(rec.GetBool("BoolField")); Assert.AreEqual(6, rec.GetInt("Id")); Assert.IsTrue(rec.MoveFirst()); Assert.IsTrue(rec.MoveLast()); Assert.AreEqual(60, rec.GetInt("IntField")); Assert.AreEqual(6.6, rec.GetDouble("RealField")); Assert.AreEqual("Большой текст 6", rec.GetString("StringField1")); Assert.AreEqual("Text6", rec.GetString("StringField2")); Assert.AreEqual(new DateTime(2016, 07, 06), rec.GetTime("TimeField")); Assert.IsTrue(rec.GetBool("BoolField")); Assert.AreEqual(6, rec.GetInt("Id")); Assert.AreEqual(5, rec.RecordCount); Assert.IsTrue(rec.HasRows); } }