1: using System;
2: using System.Collections.Generic;
3: using System.Data;
4: using System.Globalization;
5: using System.Linq;
6:
7: namespace Ia.Ngn.Cl.Model.Business
8: {
9: ////////////////////////////////////////////////////////////////////////////
10:
11: /// <summary publish="true">
12: /// Service Request Type support class of Optical Fiber Network (OFN) business model.
13: /// </summary>
14: ///
15: /// <remarks>
16: /// Copyright © 2006-2019 Jasem Y. Al-Shamlan (info@ia.com.kw), Integrated Applications - Kuwait. All Rights Reserved.
17: ///
18: /// This library is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by
19: /// the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
20: ///
21: /// This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
22: /// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
23: ///
24: /// You should have received a copy of the GNU General Public License along with this library. If not, see http://www.gnu.org/licenses.
25: ///
26: /// Copyright notice: This notice may not be removed or altered from any source distribution.
27: /// </remarks>
28: public class ServiceRequestType
29: {
30: /// <summary/>
31: public ServiceRequestType() { }
32:
33: ////////////////////////////////////////////////////////////////////////////
34:
35: /// <summary>
36: ///
37: /// </summary>
38: public static string OracleSqlCommandForGivenDateTime(DateTime dateTime)
39: {
40: string sql;
41:
42: sql = @"select SRV_REQ_FIPER_TECH.SRV_REQ_ID, SRV_REQ_FIPER_TECH.TECH_TYPE_ID, SRV_REQ_FIPER_TECH.VAL from SRV_REQ_FIPER left outer join SRV_REQ_FIPER_TECH on SRV_REQ_FIPER_TECH.SRV_REQ_ID = SRV_REQ_FIPER.SRV_REQ_ID where REQ_DATE >= '" + dateTime.ToString("dd/MM/yyyy", CultureInfo.InvariantCulture) + @"' and REQ_DATE < '" + dateTime.AddDays(1).ToString("dd/MM/yyyy", CultureInfo.InvariantCulture) + @"' and SRV_REQ_FIPER_TECH.SRV_REQ_ID is not null and SRV_REQ_FIPER_TECH.TECH_TYPE_ID is not null and SRV_REQ_FIPER_TECH.VAL is not null order by SRV_REQ_FIPER.SRV_REQ_ID asc";
43:
44: return sql;
45: }
46:
47: ////////////////////////////////////////////////////////////////////////////
48:
49: /// <summary>
50: ///
51: /// </summary>
52: public static string OracleSqlCommandForServiceRequestIdRange(Tuple<int, int> startEndRange)
53: {
54: return OracleSqlCommandForServiceRequestIdRange(startEndRange.Item1, startEndRange.Item2);
55: }
56:
57: ////////////////////////////////////////////////////////////////////////////
58:
59: /// <summary>
60: ///
61: /// </summary>
62: public static string OracleSqlCommandForServiceRequestIdRange(int start, int end)
63: {
64: string sql;
65:
66: sql = @"select SRV_REQ_FIPER_TECH.SRV_REQ_ID, SRV_REQ_FIPER_TECH.TECH_TYPE_ID, SRV_REQ_FIPER_TECH.VAL from SRV_REQ_FIPER left outer join SRV_REQ_FIPER_TECH on SRV_REQ_FIPER_TECH.SRV_REQ_ID = SRV_REQ_FIPER.SRV_REQ_ID where SRV_REQ_FIPER_TECH.SRV_REQ_ID >= " + start + " and SRV_REQ_FIPER_TECH.SRV_REQ_ID <= " + end + " and SRV_REQ_FIPER_TECH.SRV_REQ_ID is not null and SRV_REQ_FIPER_TECH.TECH_TYPE_ID is not null and SRV_REQ_FIPER_TECH.VAL is not null order by SRV_REQ_FIPER.SRV_REQ_ID asc";
67:
68: return sql;
69: }
70:
71: ////////////////////////////////////////////////////////////////////////////
72:
73: /// <summary>
74: ///
75: /// </summary>
76: public static string OracleSqlCommandForServiceRequestByService(string service)
77: {
78: string sql;
79:
80: if (!string.IsNullOrEmpty(service))
81: {
82: sql = @"select SRV_REQ_FIPER_TECH.SRV_REQ_ID, SRV_REQ_FIPER_TECH.TECH_TYPE_ID, SRV_REQ_FIPER_TECH.VAL from SRV_REQ_FIPER
83: left outer join SRV_REQ_FIPER_TECH on SRV_REQ_FIPER_TECH.SRV_REQ_ID = SRV_REQ_FIPER.SRV_REQ_ID
84: where SRV_REQ_FIPER.SRV_NO = " + service + @" and SRV_REQ_FIPER_TECH.SRV_REQ_ID is not null and SRV_REQ_FIPER_TECH.TECH_TYPE_ID is not null and SRV_REQ_FIPER_TECH.VAL is not null
85: order by SRV_REQ_FIPER.SRV_REQ_ID asc";
86: }
87: else sql = string.Empty;
88:
89: return sql;
90: }
91:
92: ////////////////////////////////////////////////////////////////////////////
93:
94: /// <summary>
95: ///
96: /// </summary>
97: public static List<int> ChangedNumberList()
98: {
99: List<int> numberList;
100: List<string> stringNumberList;
101:
102: numberList = new List<int>();
103:
104: using (var db = new Ia.Ngn.Cl.Model.Ngn())
105: {
106: stringNumberList = (from srt in db.ServiceRequestTypes where srt.TypeId == 11 select srt.Value).ToList();
107: }
108:
109: if (stringNumberList.Count > 0)
110: {
111: foreach (string u in stringNumberList)
112: {
113: if (int.TryParse(u, out int i)) numberList.Add(i);
114: }
115: }
116: else
117: {
118: }
119:
120: return numberList;
121: }
122:
123: ////////////////////////////////////////////////////////////////////////////
124:
125: /// <summary>
126: ///
127: /// </summary>
128: public static List<int> ChangedNumberList(List<Ia.Ngn.Cl.Model.ServiceRequestType> serviceRequestTypeList)
129: {
130: List<int> numberList;
131: List<string> stringNumberList;
132:
133: if (serviceRequestTypeList.Count > 0)
134: {
135: stringNumberList = (from srt in serviceRequestTypeList where srt.TypeId == 11 select srt.Value).ToList();
136:
137: if (stringNumberList.Count > 0)
138: {
139: numberList = new List<int>();
140:
141: foreach (string u in stringNumberList)
142: {
143: if (int.TryParse(u, out int i)) numberList.Add(i);
144: }
145: }
146: else numberList = new List<int>();
147: }
148: else numberList = new List<int>();
149:
150: return numberList;
151: }
152:
153: ////////////////////////////////////////////////////////////////////////////
154:
155: /// <summary>
156: ///
157: /// </summary>
158: public static Ia.Ngn.Cl.Model.Access ExtractAccess(int serviceRequestId, List<Ia.Ngn.Cl.Model.ServiceRequestType> serviceRequestTypeList)
159: {
160: Ia.Ngn.Cl.Model.Access access;
161: List<Ia.Ngn.Cl.Model.ServiceRequestType> subtypeSrtList;
162:
163: if (serviceRequestTypeList.Count > 0)
164: {
165: subtypeSrtList = (from srt in serviceRequestTypeList
166: where srt.ServiceRequest.Id == serviceRequestId
167: select srt).ToList();
168:
169: access = ExtractAccess(subtypeSrtList);
170: }
171: else access = null;
172:
173: return access;
174: }
175:
176: ////////////////////////////////////////////////////////////////////////////
177:
178: /// <summary>
179: ///
180: /// </summary>
181: private static Ia.Ngn.Cl.Model.Access ExtractAccess(List<Ia.Ngn.Cl.Model.ServiceRequestType> serviceRequestTypeList)
182: {
183: Dictionary<int, string> typeDictionary;
184: Ia.Ngn.Cl.Model.Access access;
185:
186: typeDictionary = TypeDictionary(serviceRequestTypeList);
187:
188: var nddOnt = Ia.Ngn.Cl.Model.Business.Default.NddOntUsingExtractedAccessNameWithValidSymbolAndLegalFormatForPonAndOntFromDictionaryValueList(typeDictionary);
189:
190: access = (nddOnt != null) ? Ia.Ngn.Cl.Model.Data.Access.Read(nddOnt.Pon.PonGroup.Olt.Id, nddOnt.Pon.Number, nddOnt.Number) : null;
191:
192: return access;
193: }
194:
195: ////////////////////////////////////////////////////////////////////////////
196:
197: /// <summary>
198: ///
199: /// </summary>
200: public static Ia.Ngn.Cl.Model.Access ExtractAccess(Ia.Ngn.Cl.Model.Ngn db, string value)
201: {
202: Dictionary<int, string> typeDictionary;
203: Ia.Ngn.Cl.Model.Access access;
204:
205: typeDictionary = new Dictionary<int, string>(1);
206: typeDictionary.Add(1, value);
207:
208: var nddOnt = Ia.Ngn.Cl.Model.Business.Default.NddOntUsingExtractedAccessNameWithValidSymbolAndLegalFormatForPonAndOntFromDictionaryValueList(typeDictionary);
209:
210: access = Ia.Ngn.Cl.Model.Data.Access.Read(db, nddOnt.Pon.PonGroup.Olt.Id, nddOnt.Pon.Number, nddOnt.Number);
211:
212: return access;
213: }
214:
215: ////////////////////////////////////////////////////////////////////////////
216:
217: /// <summary>
218: ///
219: /// </summary>
220: public static Dictionary<int, string> TypeDictionary(List<Ia.Ngn.Cl.Model.ServiceRequestType> serviceRequestTypeList)
221: {
222: Dictionary<int, string> typeDictionary;
223:
224: typeDictionary = new Dictionary<int, string>(63); // <serviceRequestType> <typeList> <type> has about 63 types max
225:
226: foreach (Ia.Ngn.Cl.Model.ServiceRequestType serviceRequestType in serviceRequestTypeList)
227: {
228: typeDictionary.Add(serviceRequestType.TypeId, serviceRequestType.Value);
229: }
230:
231: return typeDictionary;
232: }
233:
234: ////////////////////////////////////////////////////////////////////////////
235: ////////////////////////////////////////////////////////////////////////////
236: }
237:
238: ////////////////////////////////////////////////////////////////////////////
239: ////////////////////////////////////////////////////////////////////////////
240: }