namespace SaturnRep
{
public static class ClassSerialiaze
{
public static void SerialiazeToXml<T>(ref T inObject, string inFileName)
{
try
{
System.Xml.Serialization.XmlSerializer writer = new System.Xml.Serialization.XmlSerializer(typeof(T));
System.IO.StreamWriter file = new System.IO.StreamWriter(inFileName);
writer.Serialize(file, inObject);
file.Close();
}
catch (Exception ex) { MessageBox.Show(ex.Message); }
}
public static void DeserializationFromXml<T>(ref T inObject, string inFileName)
{
if (System.IO.File.Exists(inFileName))
{
System.Xml.Serialization.XmlSerializer reader = new System.Xml.Serialization.XmlSerializer(typeof(T));
System.IO.StreamReader file = new System.IO.StreamReader(inFileName);
inObject = (T)reader.Deserialize(file);
file.Close();
}
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using Devart.Data.SQLite;
namespace Registratura
{
public class ClassDataBase
{
#region ExecuteNonQuery
public int ExecuteNonQuery(ref ClassSetupProgram setupProgram, string sSql, int where)
{
int n = 0;
try
{
using (SQLiteConnection con = new SQLiteConnection(string.Format("Data Source={0};", setupProgram.connectionToDBString)))
{
con.Open();
using (SQLiteCommand sqlCommand = con.CreateCommand())
{
sqlCommand.CommandText = sSql;
n = sqlCommand.ExecuteNonQuery();
}
con.Close();
}
}
catch (Exception ex)
{
n = 0;
}
return n;
}
#endregion
#region Execute
protected T GetObject<T>(params object[] args)
{
return (T)Activator.CreateInstance(typeof(T), args);
}
public void Execute<T>(ref ClassSetupProgram setupProgram, string sSql, ref List<T> listResult)
{
string result="";
try
{
string databaseName = setupProgram.connectionToDBString;
SQLiteConnection con = new SQLiteConnection(string.Format("Data Source={0};", databaseName));
con.Open();
SQLiteCommand command = new SQLiteCommand(sSql, con);
SQLiteDataReader dataReader = command.ExecuteReader();
if (dataReader.HasRows)
{
while (dataReader.Read())
{
result = "";
for (int i = 0; i < dataReader.FieldCount; i++)
{
result += dataReader.GetString(i) + "!";
}
if (result.Count() > 2) result = result.Remove(result.Count() - 1);
if (result != "") listResult.Add(GetObject<T>(result));
}
}
con.Close();
}
catch (Exception ex)
{
}
}
#endregion
}
}
Питання для самоконтролю
1. Які переваги повторного використання елементів програм?
2. Які елементи можна повторно використовувати в програмах?
3. Опишіть процедуру створення шаблона форми
4. Опишіть процедуру використання шаблона форми у новому проекті.
5. Що таке зв'язана форма?
6. Що таке депозитарій Delphi?
7. Як додати та видалити шаблон форми в депозитарію?
8. Які типи заполучення форм із депозитарію ви знаєте?
9. Дайте характеристику всіх типів заполучення форм із депозитарію.
10. Як видалити шаблон форми із допозитарію?
Лекція №8
Тема: Принципи одноманітних компонентів. Делегати, їх призначення та використання.
Мета: Придбати практичні навички у обробці одноманітних компонентів. Отримати знання з конструктції делгатів та їх використання при конструюванні програмних продутів.
Перелік питань, що розглядаються на лекції:
1. Використання підпрограм в оброблювачах подій
2. Звертання до активного компонента не за ім’ям
3. Обробка групи компонентів
4. Обробка компонентів як масиву
5. Сортування даних у компонентах