-
Notifications
You must be signed in to change notification settings - Fork 0
/
ChooseObj.cs
75 lines (70 loc) · 2.65 KB
/
ChooseObj.cs
1
2
3
4
5
6
7
8
9
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
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Configuration;
using System.Data.Entity;
using System.Data.Entity.Migrations;
using System.Collections.ObjectModel;
using NPLab.Data.Migrations;
using NPLab.Data;
using NPLab.Models;
namespace NPLab
{
public partial class ChooseObj : Form
{
public Home H;
public ChooseObj(Home h)
{
this.H = h;
InitializeComponent();
}
private void SearchField_TextChanged(object sender, EventArgs e)
{
Database.SetInitializer(new MigrateDatabaseToLatestVersion<NPLabDbContext, Configuration>());
var db = new NPLabDbContext();
string[] objNames = (from p in db.Object
where p.ObjectName.IndexOf(SearchField.Text.ToLower()) != -1 && p.ObjectName != null
select p.ObjectName).ToArray<string>();
ListObjects.Items.Clear();
ListObjects.Items.AddRange(objNames);
}
private void ChooseObj_Load(object sender, EventArgs e)
{
Database.SetInitializer(new MigrateDatabaseToLatestVersion<NPLabDbContext, Configuration>());
var db = new NPLabDbContext();
string[] objNames = (from p in db.Object
where p.ObjectName.Length > 0 && p.ObjectName != null
select p.ObjectName).ToArray<string>();
ListObjects.Items.AddRange(objNames);
}
private void Load_Click(object sender, EventArgs e)
{
Database.SetInitializer(new MigrateDatabaseToLatestVersion<NPLabDbContext, Configuration>());
var db = new NPLabDbContext();
if (ListObjects.SelectedIndex == -1) { MessageBox.Show("Не сте избрали обект"); return; }
int toLoad;
try
{
toLoad = (from p in db.Object
where p.ObjectName == ListObjects.SelectedItem.ToString()
select p.Id).First();
}
catch { MessageBox.Show("Грешка! Не съществува такъв обект"); return; }
Main M = new Main(toLoad, H);
M.Show();
M.Focus();
this.Close();
}
private void Cancel_Click(object sender, EventArgs e)
{
H.Show();
H.Focus();
this.Close();
}
}
}