-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDbAccessController.cs
158 lines (141 loc) · 6.89 KB
/
DbAccessController.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Web;
using System.Web.Configuration;
using System.Web.Mvc;
using IGIT.ASP.WebUI.Models;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using static System.Web.Helpers.Json;
using System.Data.Linq;
using System.Globalization;
using System.Net;
using Microsoft.EntityFrameworkCore;
using IGIT.ASP.WebUI.DataAccess;
namespace IGIT.ASP.WebUI.Controllers
{
public class DbAccessController : Controller
{
//OracleDbContext db2 = new OracleDbContext();
MsAdmShip db3 = new MsAdmShip(@""+WebConfigurationManager.ConnectionStrings["IGIT.ASP.WebUI.Properties.Settings.AdmShipConnectionString"] +"");
//AdmShipDataContext db = new AdmShipDataContext();
//CycloneDataContext dc = new CycloneDataContext();
[HttpPost]
public JsonResult GetEmployees()
{
Dictionary<string, List<GisRasp>> toJson = new Dictionary<string, List<GisRasp>>();
//string json = "";
var employees = AbstractDataAccess.SelectA(@"select * from V_GIS_PERS order by FNAME", r => new GisRasp(r));//where PROF_NAME not likec '%Начальник%'db2.Users.Where(c => !c.profName.Contains("Начальник")).OrderBy(o=>o.fName).ToList();
//toJson.Add("list", employees);
//json = JsonConvert.SerializeObject(toJson, Formatting.Indented);
return Json(employees);
}
[HttpPost]
public JsonResult GetChiefs()
{
Dictionary<string, List<GisRasp>> toJson = new Dictionary<string, List<GisRasp>>();
string json = "";
var chiefs = AbstractDataAccess.SelectA(@"select * from V_GIS_PERS where PROF_NAME like 'Начальник%' or PROF_NAME like 'Главный%' or PROF_NAME like 'Генеральный%' or PROF_NAME like 'Заместитель%' order by FNAME", r => new GisRasp(r));//db2.Users.Where(c=> c.profName.Contains("Начальник")).OrderBy(o => o.fName).ToList();
toJson.Add("list", chiefs);
json = JsonConvert.SerializeObject(toJson, Formatting.Indented);
return Json(json);
}
[HttpPost]
public JsonResult GetBuildings()
{
using (CycloneDataContext dc = new CycloneDataContext())
{
var buildings = dc.GetBuildingList().ToList();
return Json(buildings);
}
//var buildingsAll = AbstractDataAccess.SelectA(@"select distinct inv_number, name, kc_up from v_gis_os1 where code_subsection = 210 order by inv_number", r => GisOs1.Get4(r));
//var buildings = buildingsC.Join(buildingsAll, bc => bc.InvNumber.Substring(0,6), ba => ba.invNumber.Substring(0,6), (bc, ba) => new { name = bc.ObjName, invNumber = bc.InvNumber, codeSubdiv = ba.codeSubdivision }).ToList();
}
[HttpPost]
public JsonResult GetBuildings3D()
{
using (AdmShipDataContext db = new AdmShipDataContext())
{
var buildings = db.GetBuildings3d().ToList();
return Json(buildings);
}
}
[HttpPost]
public JsonResult GetSubdivisions()
{
Dictionary<string, List<GisOs1>> toJson = new Dictionary<string, List<GisOs1>>();
//string json = "";
//var subdivisionsB = (from s in db3.GetTable<Room>()
// select new { codeSubdivision = s.departId, subdivId = s.subdivisionId, subdivisionName = s.subdivisionName}).Distinct().ToList();
var subdivisionsU = AbstractDataAccess.SelectA(@"select distinct department, dep_short_name, dep_full_name from v_gis_pers order by department", r => GisRasp.Get3(r));
//db2.Users.Select(s => new { codeSubdivision = s.departmentId, subdivisionName = s.departmentFullName, idChief = s.Id }).Distinct().ToList();
//var subdivisions = subdivisionsB
// .Join(subdivisionsU, b => b.codeSubdivision, u => u.departmentId, (b, u) => new
// {
// codeSubdivision = b.subdivId,
// subdivisionName = b.subdivisionName,
// depId = u.departmentId,
// })
// .OrderBy(o => o.subdivisionName)
// .GroupBy(g=>g.codeSubdivision)
// .ToList();
//toJson.Add("list", subdivisions);
//json = JsonConvert.SerializeObject(toJson, Formatting.Indented);
return Json(subdivisionsU);
}
[HttpPost]
public JsonResult GetSubdivisions2D() {
using (AdmShipDataContext db = new AdmShipDataContext())
{
var subdivisionsU = db.GetSubdivisions2D().ToList();
return Json(subdivisionsU);
}
}
[HttpPost]
public JsonResult GetRooms3D()
{
using (AdmShipDataContext db = new AdmShipDataContext())
{
var rooms = db.GetRooms().OrderBy(o => o.roomId).ToList();
JsonSerializerSettings settings = new JsonSerializerSettings();
settings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore;
JsonResult jsonResult = Json(rooms);
jsonResult.MaxJsonLength = int.MaxValue;
return jsonResult;
}
}
[HttpPost]
public JsonResult GetRooms2D()
{
using (AdmShipDataContext db = new AdmShipDataContext())
{
var rooms = db.GetRooms2D().OrderBy(o => o.roomId).ToList();
JsonSerializerSettings settings = new JsonSerializerSettings();
settings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore;
JsonResult jsonResult = Json(rooms);
jsonResult.MaxJsonLength = int.MaxValue;
return jsonResult;
}
}
public JsonResult GetRoomEmployees(int roomId, int subdiv) {
using (AdmShipDataContext db = new AdmShipDataContext())
{
var rooms = db.GetRoomsForEdit(roomId, subdiv).ToList();
return Json(rooms);
}
}
//методы для функционала экспорта объектов в dwg формат
[HttpPost]
public JsonResult GetGeoprocUrl(string val) {
string url = url = WebConfigurationManager.AppSettings[val];
return Json(url);
}
[HttpPost]
public void GetDwgResult(string url, string filename) {
WebClient wc = new WebClient();
wc.DownloadFile(url, filename);
}
}
}