- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
- 68
- 69
- 70
- 71
- 72
- 73
- 74
- 75
- 76
- 77
- 78
- 79
- 80
- 81
- 82
- 83
- 84
- 85
- 86
- 87
- 88
- 89
- 90
- 91
class Users : Data
{
public int ID { get; set; }
public string Name { get; set; }
public int PostID { get; set; }
public int SubdivID { get; set; }
public QueryType qType { get; set; }
public static QueryState qState { get; set; }
/// <summary>
/// Типы запроса для QueryBuilder
/// </summary>
public enum QueryType : int
{
Insert = 1,
Delete,
Update,
SelectUsers,
SelectUser,
SelectUsersbyName
}
/// <summary>
/// Статусы открытия формы (добавление или редактирование)
/// </summary>
public enum QueryState : int
{
Insert = 1,
Update
}
public Users()
{
ID = -1;
Name = null;
}
/// <summary>
/// Формирует запрос на основе значения переменной qType и осуществляет выборку данных
/// </summary>
public void QueryBuilder()
{
switch (qType)
{
case QueryType.SelectUsers:
{
QueryText = "Select Users.ID, Users.Name, Posts.Name, Subdivisions.Name from Users, Posts, Subdivisions Where Users.SubdivID = subdivisions.ID and Users.PostID = Posts.ID";
Select();
break;
}
case QueryType.SelectUser:
{
if (ID != -1)
{
QueryText = "Select Users.ID, Users.Name, Posts.Name, Subdivisions.Name, Posts.ID, Subdivisions.ID From Users, Posts, Subdivisions " +
" Where Users.SubdivID = subdivisions.ID and Users.PostID = Posts.ID and Users.ID = " + ID;
SelectRow();
}
else
{
MessageBox.Show("ID пользователя не найден");
}
break;
}
case QueryType.Insert:
{
QueryText = "Insert Into Users(Name, PostID, SubdivID) Values('" + Name + "', '" + PostID + "', '" + SubdivID + "')";
InsertRecord();
break;
}
case QueryType.Delete:
{
QueryText = "Delete From Users Where ID = " + ID;
DeleteRecord();
break;
}
case QueryType.Update:
{
QueryText = "Update Users set Name = '" + Name + "', PostID = '" + PostID + "', SubdivID = '" + SubdivID + "' Where ID = " + ID;
UpdateRecord();
break;
}
case QueryType.SelectUsersbyName:
{
QueryText = "Select Users.ID, Users.Name, Posts.Name, Subdivisions.Name from Users, Posts, Subdivisions " +
"Where Users.SubdivID = subdivisions.ID and Users.PostID = Posts.ID and Users.Name like " + "'%" + Name + "%'";
Select();
break;
}
}
}
DBdev 28.04.2014 14:28 # +3
Ололо, фултейбл скан дитектед.