1: using System;
2: using System.Collections.Generic;
3: using System.Linq;
4: using System.Data;
5: using System.Collections;
6: using System.IO;
7: using Ionic.Zip;
8: using System.Drawing.Imaging;
9:
10: namespace Ia.TentPlay.Cl.Model.Data.Trek
11: {
12: ////////////////////////////////////////////////////////////////////////////
13:
14: /// <summary publish="true">
15: /// Default class for TentPlay Trek data model
16: /// </summary>
17: ///
18: /// <remarks>
19: /// Copyright © 2006-2017 Jasem Y. Al-Shamlan (info@ia.com.kw), Integrated Applications - Kuwait. All Rights Reserved.
20: ///
21: /// 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
22: /// the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
23: ///
24: /// This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
25: /// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
26: ///
27: /// You should have received a copy of the GNU General Public License along with this library. If not, see http://www.gnu.org/licenses.
28: ///
29: /// Copyright notice: This notice may not be removed or altered from any source distribution.
30: /// </remarks>
31: public static class Default
32: {
33: ////////////////////////////////////////////////////////////////////////////
34: ////////////////////////////////////////////////////////////////////////////
35:
36: /// <summary>
37: ///
38: /// </summary>
39: public struct Drawable
40: {
41: ////////////////////////////////////////////////////////////////////////////
42:
43: /// <summary>
44: ///
45: /// </summary>
46: public Drawable(string name, int maxWidth)
47: {
48: this.Name = name;
49: this.MaxWidth = maxWidth;
50: }
51:
52: /// <summary/>
53: public string Name;
54: /// <summary/>
55: public int MaxWidth;
56: }
57:
58: ////////////////////////////////////////////////////////////////////////////
59:
60: /// <summary>
61: ///
62: /// </summary>
63: public static List<Ia.TentPlay.Cl.Model.Business.Trek.FeatureClass> FeatureClassNameAndCountWithinDatabaseList(string countryIso2, Ia.TentPlay.Cl.Model.Data.Trek.ApplicationInformation.Translation translation, out Ia.Cl.Model.Result result)
64: {
65: List<Ia.TentPlay.Cl.Model.Business.Trek.FeatureClass> featureClassList;
66: Dictionary<string, int> featureClassCountDictionary;
67:
68: result = new Ia.Cl.Model.Result();
69: featureClassCountDictionary = new Dictionary<string, int>();
70:
71: featureClassList = Ia.TentPlay.Cl.Model.Data.Trek.FeatureClass.List;
72:
73: using (var db = new Ia.TentPlay.Db())
74: {
75: featureClassCountDictionary = (from ncw in db.Features
76: where ncw.FileCountry == countryIso2
77: group ncw.Class by ncw.Class into g
78: select new Ia.TentPlay.Cl.Model.Business.Trek.FeatureClass() { Id = g.Key, Count = g.Count() }).ToDictionary(f => f.Id, f => f.Count);
79: }
80:
81: foreach (var fc in featureClassList)
82: {
83: fc.Name = (from fc2 in translation.FeatureClassList where fc2.Id == fc.Id select fc2.Name).SingleOrDefault();
84: fc.Caption = (from fc2 in translation.FeatureClassList where fc2.Id == fc.Id select fc2.Caption).SingleOrDefault();
85: fc.Description = (from fc2 in translation.FeatureClassList where fc2.Id == fc.Id select fc2.Description).SingleOrDefault();
86:
87: if (featureClassCountDictionary.ContainsKey(fc.Id)) fc.Count = featureClassCountDictionary[fc.Id];
88: else fc.Count = 0;
89: }
90:
91: return featureClassList;
92: }
93:
94: ////////////////////////////////////////////////////////////////////////////
95:
96: /// <summary>
97: ///
98: /// </summary>
99: public static List<Ia.TentPlay.Cl.Model.Business.Trek.FeatureDesignation> FeatureDesignationNameAndCountWithinDatabaseList(string countryIso2, Ia.TentPlay.Cl.Model.Data.Trek.ApplicationInformation.Translation translation, out Ia.Cl.Model.Result result)
100: {
101: List<Ia.TentPlay.Cl.Model.Business.Trek.FeatureDesignation> featureDesignationList;
102:
103: result = new Ia.Cl.Model.Result();
104:
105: using (var db = new Ia.TentPlay.Db())
106: {
107: featureDesignationList = (from ncw in db.Features
108: where ncw.FileCountry == countryIso2
109: group ncw.Designation.Id by ncw.Designation.Id into g
110: select new Ia.TentPlay.Cl.Model.Business.Trek.FeatureDesignation() { Id = g.Key, Count = g.Count() }).ToList();
111: }
112:
113: foreach (var fd in featureDesignationList)
114: {
115: fd.Name = Ia.TentPlay.Cl.Model.Data.Trek.FeatureDesignation.DesignationIdToDesignationCaptionHashtable(translation.Iso6391)[fd.Id].ToString();
116: fd.FeatureClass = Ia.TentPlay.Cl.Model.Data.Trek.FeatureDesignation.DesignationIdToClassIdHashtable[fd.Id].ToString();
117: }
118:
119: return featureDesignationList;
120: }
121:
122: ////////////////////////////////////////////////////////////////////////////
123:
124: /// <summary>
125: ///
126: /// </summary>
127: public static void GenerateSpecificFeatureSqliteDatabaseFileFromSqlServer(Ia.TentPlay.Cl.Model.Data.Trek.ApplicationInformation.Country applicationCountry, out Ia.Cl.Model.Result result)
128: {
129: int featureDesignationCount, featuresCount;
130: string fileName, sql, filePath, scalar;
131: DataTable dataTable;
132: FileInfo file;
133: Ia.Cl.Model.Db.Sqlite sqlite;
134: List<Ia.TentPlay.Cl.Model.Trek.FeatureDesignation> featureDesignationList;
135: List<Ia.TentPlay.Cl.Model.Trek.Feature> featureList;
136:
137: fileName = Ia.TentPlay.Cl.Model.Business.Trek.Default.SqliteDatabaseFileName(applicationCountry.Iso2, applicationCountry.VersionName);
138:
139: filePath = global::Ia.Cl.Model.Default.AbsolutePath(true) + fileName;
140:
141: file = new FileInfo(filePath);
142:
143: if (file.Exists)
144: {
145: // delete file if it exists
146: File.Delete(filePath);
147: }
148:
149: sqlite = new Ia.Cl.Model.Db.Sqlite(filePath); //, filePassword);
150:
151: // below: drop table if exists
152: sql = "drop table if exists features"; // first because of foreign keys
153: sqlite.Sql(sql);
154: sql = "drop table if exists featuresFts";
155: sqlite.Sql(sql);
156:
157: sql = "drop table if exists featureDesignations";
158: sqlite.Sql(sql);
159:
160: // create and populate non-virtual table FeatureDesignations
161: sql = Ia.TentPlay.Cl.Model.Business.Trek.Default.SqliteDatabaseFileCreateFeatureDesignationTableString(false, applicationCountry.Languages);
162: sqlite.Sql(sql);
163:
164: featureDesignationList = Ia.TentPlay.Cl.Model.Data.Trek.FeatureDesignation.List;
165:
166: dataTable = Ia.Cl.Model.Default.GenerateDataTableFromGenericClassList<Ia.TentPlay.Cl.Model.Trek.FeatureDesignation>(featureDesignationList, "FeatureDesignations");
167:
168: // delete irrelevant entries from dataTable
169: RemoveUnNeededColumns(ref dataTable, applicationCountry.Languages);
170:
171: sqlite.SqlBulkCopy(dataTable, out result);
172:
173: sql = "select count(0) from featureDesignations";
174: scalar = sqlite.Scalar(sql);
175:
176: if (!string.IsNullOrEmpty(scalar))
177: {
178: featureDesignationCount = int.Parse(scalar);
179:
180: if (featureDesignationCount == featureDesignationList.Count)
181: {
182: // regular table
183: sql = Ia.TentPlay.Cl.Model.Business.Trek.Default.SqliteDatabaseFileCreateFeaturesTableString(false);
184: sqlite.Sql(sql);
185:
186: // You can not use index with virtual tables
187: sqlite.Sql("create index if not exists noDiacriticLowerCaseNameIndex on features (noDiacriticLowerCaseName)");
188: sqlite.Sql("create index if not exists fullTextSearchNameIndex on features (fullTextSearchName)");
189:
190: // virtual table
191: sql = Ia.TentPlay.Cl.Model.Business.Trek.Default.SqliteDatabaseFileCreateFeaturesTableString(true);
192: sqlite.Sql(sql);
193:
194: //sqlList = Ia.TentPlay.Cl.Model.Business.Default.SqliteDatabaseFileInsertListSpecificFeaturesTableListString(fileCountry);
195: //sqlite.Sql(sqlList);
196: featureList = Ia.TentPlay.Cl.Model.Data.Trek.Feature.List(applicationCountry.Iso2, out result);
197:
198: featureList = LimitNumberOfFeaturesHenceSizeOfApp(applicationCountry.Iso2, featureList);
199:
200: dataTable = Ia.Cl.Model.Default.GenerateDataTableFromGenericClassList<Ia.TentPlay.Cl.Model.Trek.Feature>(featureList, "Features");
201:
202: dataTable.Columns.Remove("Deleted");
203: dataTable.Columns.Remove("Created");
204: dataTable.Columns.Remove("Updated");
205:
206: sqlite.SqlBulkCopy(dataTable, out result);
207:
208: // the FTS table
209: dataTable.TableName = "featuresFts";
210: sqlite.SqlBulkCopy(dataTable, out result);
211:
212: sql = "select count(0) from features";
213: scalar = sqlite.Scalar(sql);
214:
215: if (!string.IsNullOrEmpty(scalar))
216: {
217: featuresCount = int.Parse(scalar);
218:
219: if (featuresCount == featureList.Count)
220: {
221: result.AddSuccess("Feature designation code count: " + featureDesignationCount + "; country trek count: " + featuresCount + ". ");
222: }
223: }
224: else
225: {
226: result.AddError("dt is null or dt.Rows.Count == 0 for Features. ");
227: }
228: }
229: else
230: {
231: result.AddError("dt.Rows.Count != sqlList.Count for FeatureDesignations. ");
232: }
233: }
234: else
235: {
236: result.AddError("dt is null or dt.Rows.Count == 0 for FeatureDesignations. ");
237: }
238: }
239:
240: ////////////////////////////////////////////////////////////////////////////
241:
242: /// <summary>
243: /// This function will attempt the lower the number of features and limit the size of the database for very large numbers of features
244: /// </summary>
245: public static List<Ia.TentPlay.Cl.Model.Trek.Feature> LimitNumberOfFeaturesHenceSizeOfApp(string fileCountry, List<Ia.TentPlay.Cl.Model.Trek.Feature> featureList)
246: {
247: int r;
248: double specialCases;
249:
250: List<Ia.TentPlay.Cl.Model.Trek.Feature> list;
251:
252: list = new List<Ia.TentPlay.Cl.Model.Trek.Feature>();
253:
254: if (fileCountry == "ir") specialCases = .8; // I think this is because farsi feature has lots of utf8 arabic scripts
255: else if (fileCountry == "ru") specialCases = .48;
256: else specialCases = 1;
257:
258: if (featureList.Count > Ia.TentPlay.Cl.Model.Business.Trek.Default.MaximumNumberOfFeaturesThatWouldAllowForAcceptableAppSizeInAndroidPlayStore * specialCases)
259: {
260: foreach (var f in featureList)
261: {
262: r = Ia.Cl.Model.Default.Random(featureList.Count);
263:
264: if (r < Ia.TentPlay.Cl.Model.Business.Trek.Default.MaximumNumberOfFeaturesThatWouldAllowForAcceptableAppSizeInAndroidPlayStore * specialCases)
265: {
266: list.Add(f);
267: }
268: else
269: {
270: // ignore item to reduce size
271: }
272: }
273: }
274: else list = featureList;
275:
276: return list;
277: }
278:
279: ////////////////////////////////////////////////////////////////////////////
280:
281: /// <summary>
282: ///
283: /// </summary>
284: public static void GenerateDrawableVersionOfNavigationViewBackground(Ia.TentPlay.Cl.Model.Data.Trek.ApplicationInformation.Country applicationCountry, out Ia.Cl.Model.Result result)
285: {
286: /*
287: drawable-ldpi
288: drawable-hdpi
289: drawable-mdpi
290: drawable-xhdpi
291: drawable-xxhdpi
292: drawable-xxxhdpi
293:
294: Maximum width: 320dp
295:
296: ldpi @ 320.00dp = 240.00px
297: mdpi @ 320.00dp = 320.00px
298: hdpi @ 320.00dp = 480.00px
299: xhdpi @ 320.00dp = 640.00px
300: xxhdpi @ 320.00dp = 960.00px
301: xxxhdpi @ 320.00dp = 1280.00px
302: */
303:
304: bool filesMatch;
305: int c;
306: string originalImageFtpLocation, destinationImageFtpLocation, newFile;
307: string temporaryDirectory, temporaryZipFile;
308: System.Drawing.Image newImage;
309: Hashtable ht;
310: ZipFile zipFile;
311: Ia.Cl.Model.Ftp ftp;
312: Ia.Cl.Model.FtpDirectory serverImageFtpDirectory;
313: List<string> imageList, serverImageFtpDirectoryFileNameList, serverImageFtpDirectoryNameOnlyList;
314: List<Drawable> drawableList;
315:
316: temporaryDirectory = Ia.Cl.Model.Default.AbsoluteTempPath() + applicationCountry.Iso2; // + @"\" + DateTime.UtcNow.AddHours(3).Ticks;
317: temporaryZipFile = Ia.Cl.Model.Default.AbsoluteTempPath() + applicationCountry.Iso2 + ".zip";
318:
319: originalImageFtpLocation = Ia.TentPlay.Cl.Model.Business.Trek.Default.OriginalImageFtpLocation(applicationCountry.Iso2);
320: destinationImageFtpLocation = Ia.TentPlay.Cl.Model.Business.Trek.Default.DestinationImageFtpLocation(applicationCountry.Iso2);
321:
322: ht = new Hashtable();
323:
324: zipFile = new ZipFile();
325:
326: drawableList = new List<Drawable>();
327: drawableList.Add(new Drawable("ldpi", 240));
328: drawableList.Add(new Drawable("hdpi", 320));
329: drawableList.Add(new Drawable("mdpi", 480));
330: drawableList.Add(new Drawable("xhdpi", 640));
331: drawableList.Add(new Drawable("xxhdpi", 960));
332: drawableList.Add(new Drawable("xxxhdpi", 1280));
333:
334: result = new Ia.Cl.Model.Result();
335:
336: try
337: {
338: ftp = new Ia.Cl.Model.Ftp(originalImageFtpLocation, Ia.TentPlay.Cl.Model.Business.Trek.Default.FtpUser, Ia.TentPlay.Cl.Model.Business.Trek.Default.FtpPassword);
339:
340: Directory.CreateDirectory(temporaryDirectory);
341: Directory.CreateDirectory(temporaryDirectory + @"\images");
342:
343: foreach (Drawable d in drawableList)
344: {
345: Directory.CreateDirectory(temporaryDirectory + @"\drawable-" + d.Name);
346: }
347:
348: // check that the files on server match the count and names of files in XML
349: serverImageFtpDirectory = ftp.ListDirectoryDetail("/*.*");
350:
351: serverImageFtpDirectoryFileNameList = (from s in serverImageFtpDirectory select s.Filename).ToList();
352: serverImageFtpDirectoryNameOnlyList = (from s in serverImageFtpDirectory select s.NameOnly).ToList();
353:
354: imageList = (from i in applicationCountry.NavigationHeaderImages select i.FileName).ToList();
355:
356: filesMatch = true;
357:
358: if (serverImageFtpDirectory.Count == 0 || imageList.Count == 0)
359: {
360: result.AddError("serverImageFtpDirectory.Count = 0 or imageList.Count = 0. ");
361:
362: filesMatch = false;
363: }
364: else if (serverImageFtpDirectory.Count != imageList.Count)
365: {
366: result.AddError("serverImageFtpDirectory.Count (" + serverImageFtpDirectory.Count + ") != imageList.Count (" + imageList.Count + "). ");
367:
368: filesMatch = false;
369: }
370: else
371: {
372: // check all files have *.jpg extension
373: foreach (Ia.Cl.Model.FtpFileInfo ffi in serverImageFtpDirectory)
374: {
375: if (ffi.Extension != "jpg")
376: {
377: result.AddError(@"serverImageFtpDirectory's """ + ffi.Filename + @""" extension is not the required ""jpg"". ");
378:
379: filesMatch = false;
380: }
381:
382: // check all files are at least 1M
383: if (ffi.Size < 300000)
384: {
385: result.AddError(@"serverImageFtpDirectory's """ + ffi.Filename + @""" size is smaller than the required 300K. ");
386:
387: filesMatch = false;
388: }
389:
390: if (!imageList.Contains(ffi.NameOnly))
391: {
392: result.AddError(@"serverImageFtpDirectory's """ + ffi.Filename + @""" does not exist in imageList. ");
393:
394: filesMatch = false;
395: }
396: }
397:
398: // below: check if imageList has duplicates
399: foreach (string i in imageList)
400: {
401: if (ht.ContainsKey(i))
402: {
403: result.AddError(@"imageList's """ + i + @""" appears more than once in XML file. ");
404:
405: filesMatch = false;
406: }
407: else ht[i] = 1;
408: }
409:
410: foreach (string i in imageList)
411: {
412: if (!serverImageFtpDirectoryNameOnlyList.Contains(i))
413: {
414: result.AddError(@"imageList's """ + i + @""" does not exist in serverImageFtpDirectoryNameOnlyList. ");
415:
416: filesMatch = false;
417: }
418: }
419:
420: if (filesMatch)
421: {
422: // download all original image files and create drawables
423: c = 0;
424:
425: foreach (string fileName in serverImageFtpDirectoryFileNameList)
426: {
427: newFile = fileName.Replace("-", "_");
428:
429: Ia.Cl.Model.Default.DownloadFile(originalImageFtpLocation + @"/" + fileName, temporaryDirectory + @"\images\" + newFile);
430:
431: using (var image = System.Drawing.Image.FromFile(temporaryDirectory + @"\images\" + newFile))
432: {
433: foreach (Drawable d in drawableList)
434: {
435: newImage = Ia.Cl.Model.Image.Resize(image, d.MaxWidth, (image.Height * d.MaxWidth) / image.Width);
436:
437: newImage.Save(temporaryDirectory + @"\drawable-" + d.Name + @"\" + newFile, ImageFormat.Jpeg);
438:
439: c++;
440:
441: newImage.Dispose();
442: }
443:
444: image.Dispose();
445: }
446: }
447:
448: // delete images so it will not be added to zip
449: Directory.Delete(temporaryDirectory + @"\images", true);
450:
451: // Zip all image files and prepare them for download
452: zipFile.AddDirectory(temporaryDirectory);
453:
454: zipFile.Save(temporaryZipFile);
455:
456: Directory.Delete(temporaryDirectory, true);
457:
458: result.AddSuccess("Generated " + c + " drawables for " + serverImageFtpDirectoryNameOnlyList.Count + " *.jpg original images. ");
459: }
460: else
461: {
462: result.AddError("File mismatch between server and XML file. ");
463: }
464: }
465: }
466: catch (Exception ex)
467: {
468: result.AddError("Exception: " + ex.ToString());
469: }
470: }
471:
472: ////////////////////////////////////////////////////////////////////////////
473:
474: /// <summary>
475: ///
476: /// </summary>
477: public static void DownloadSpecificFeatureSqliteDatabaseFileFromTempFolder(Ia.TentPlay.Cl.Model.Data.Trek.ApplicationInformation.Country applicationCountry, System.Web.UI.Page page, out Ia.Cl.Model.Result result)
478: {
479: string fileName, filePath;
480: FileInfo file;
481:
482: result = new Ia.Cl.Model.Result();
483:
484: fileName = Ia.TentPlay.Cl.Model.Business.Trek.Default.SqliteDatabaseFileName(applicationCountry.Iso2, applicationCountry.VersionName);
485:
486: filePath = global::Ia.Cl.Model.Default.AbsolutePath(true) + fileName;
487:
488: file = new FileInfo(filePath);
489:
490: if (file.Exists)
491: {
492: page.Response.Clear();
493: page.Response.ClearHeaders();
494: page.Response.ClearContent();
495: page.Response.AddHeader("Content-Disposition", "attachment; filename=" + file.Name);
496: page.Response.AddHeader("Content-Length", file.Length.ToString());
497: page.Response.ContentType = "text/plain";
498: page.Response.Flush();
499: page.Response.TransmitFile(file.FullName);
500: page.Response.End();
501:
502: result.AddSuccess("Download complete. ");
503: }
504: else
505: {
506: result.AddError("Download file does not exists. ");
507: }
508: }
509:
510: ////////////////////////////////////////////////////////////////////////////
511:
512: /// <summary>
513: ///
514: /// </summary>
515: public static void DownloadSpecificDrawableImageFileFromTempFolder(Ia.TentPlay.Cl.Model.Data.Trek.ApplicationInformation.Country applicationCountry, System.Web.UI.Page page, out Ia.Cl.Model.Result result)
516: {
517: string fileName, filePath;
518: FileInfo file;
519:
520: result = new Ia.Cl.Model.Result();
521:
522: fileName = applicationCountry.Iso2 + ".zip";
523:
524: filePath = global::Ia.Cl.Model.Default.AbsolutePath(true) + fileName;
525:
526: file = new FileInfo(filePath);
527:
528: if (file.Exists)
529: {
530: page.Response.Clear();
531: page.Response.ClearHeaders();
532: page.Response.ClearContent();
533: page.Response.AddHeader("Content-Disposition", "attachment; filename=" + file.Name);
534: page.Response.AddHeader("Content-Length", file.Length.ToString());
535: page.Response.ContentType = "application/x-zip-compressed";
536: page.Response.Flush();
537: page.Response.TransmitFile(file.FullName);
538: page.Response.End();
539:
540: result.AddSuccess("Download complete. ");
541: }
542: else
543: {
544: result.AddError("Download file does not exists. ");
545: }
546: }
547:
548: ////////////////////////////////////////////////////////////////////////////
549:
550: /// <summary>
551: ///
552: /// </summary>
553: public static void WriteFeatureDesignationRecordListXmlToDatabase(out Ia.Cl.Model.Result result)
554: {
555: int c;
556: result = new Ia.Cl.Model.Result();
557:
558: c = 0;
559:
560: try
561: {
562: using (var db = new Ia.TentPlay.Db())
563: {
564: if (db.Database.EnsureCreated())
565: {
566: // below: first will delete all current records
567: var all = from nfdc in db.FeatureDesignations select nfdc;
568: db.FeatureDesignations.RemoveRange(all);
569: db.SaveChanges();
570: }
571:
572: foreach (Ia.TentPlay.Cl.Model.Trek.FeatureDesignation featureDesignation in Ia.TentPlay.Cl.Model.Data.Trek.FeatureDesignation.List)
573: {
574: var p = new Ia.TentPlay.Cl.Model.Trek.FeatureDesignation
575: {
576: Id = featureDesignation.Id,
577:
578: En = featureDesignation.En,
579: Ar = featureDesignation.Ar,
580: Da = featureDesignation.Da,
581: Zh_Simplified = featureDesignation.Zh_Simplified,
582: Zh_Traditional = featureDesignation.Zh_Traditional,
583: Hi = featureDesignation.Hi,
584: Ja = featureDesignation.Ja,
585: De = featureDesignation.De,
586: Ru = featureDesignation.Ru,
587: Pt = featureDesignation.Pt,
588: _Id = featureDesignation._Id,
589: Fr = featureDesignation.Fr,
590: Es = featureDesignation.Es,
591: It = featureDesignation.It,
592: Ko = featureDesignation.Ko,
593: Tr = featureDesignation.Tr,
594: Fa = featureDesignation.Fa,
595: Th = featureDesignation.Th,
596: Ha = featureDesignation.Ha,
597: Ig = featureDesignation.Ig,
598: Yo = featureDesignation.Yo,
599: Pl = featureDesignation.Pl,
600: Ur = featureDesignation.Ur,
601: Nl = featureDesignation.Nl,
602: Ms = featureDesignation.Ms,
603: Tl = featureDesignation.Tl,
604: Af = featureDesignation.Af,
605: Zu = featureDesignation.Zu,
606: Xh = featureDesignation.Xh,
607: Bn = featureDesignation.Bn,
608: Vi = featureDesignation.Vi,
609: Kk = featureDesignation.Kk,
610: Ro = featureDesignation.Ro,
611: No = featureDesignation.No,
612: Uk = featureDesignation.Uk,
613: Cs = featureDesignation.Cs,
614: He = featureDesignation.He,
615: El = featureDesignation.El,
616: My = featureDesignation.My,
617: Hu = featureDesignation.Hu,
618: Ga = featureDesignation.Ga,
619: Si = featureDesignation.Si,
620: Ta = featureDesignation.Ta,
621: Fi = featureDesignation.Fi,
622: Uz = featureDesignation.Uz,
623: Az = featureDesignation.Az,
624: Be = featureDesignation.Be,
625: Sk = featureDesignation.Sk,
626: Am = featureDesignation.Am,
627: Sw = featureDesignation.Sw,
628: Bg = featureDesignation.Bg,
629: Hr = featureDesignation.Hr,
630: Lt = featureDesignation.Lt,
631: Ne = featureDesignation.Ne,
632: Sl = featureDesignation.Sl,
633: Ps = featureDesignation.Ps,
634: Lb = featureDesignation.Lb,
635: Km = featureDesignation.Km,
636: Lv = featureDesignation.Lv,
637: Bs = featureDesignation.Bs,
638: Et = featureDesignation.Et,
639: Lo = featureDesignation.Lo,
640: Mn = featureDesignation.Mn,
641: Mg = featureDesignation.Mg,
642: Ka = featureDesignation.Ka,
643: Sq = featureDesignation.Sq,
644: Mk = featureDesignation.Mk,
645: Hy = featureDesignation.Hy,
646: Tg = featureDesignation.Tg,
647: Ky = featureDesignation.Ky,
648: Is = featureDesignation.Is,
649: Mt = featureDesignation.Mt,
650: Ca = featureDesignation.Ca,
651:
652: Description = featureDesignation.Description,
653: Class = featureDesignation.Class,
654: Deleted = featureDesignation.Deleted,
655:
656: Created = featureDesignation.Created,
657: Updated = featureDesignation.Updated
658: };
659:
660: db.FeatureDesignations.Add(p);
661: c++;
662: }
663:
664: db.SaveChanges();
665:
666: result.AddSuccess("Records added: " + c + ". ");
667: }
668: }
669: catch (Exception ex)
670: {
671: result.AddError(ex.ToString());
672: }
673: }
674:
675: ////////////////////////////////////////////////////////////////////////////
676:
677: /// <summary>
678: ///
679: /// </summary>
680: public static void DeleteFeatureDesignationRecordListFromDatabase(out Ia.Cl.Model.Result result)
681: {
682: result = new Ia.Cl.Model.Result();
683:
684: try
685: {
686: using (var db = new Ia.TentPlay.Db())
687: {
688: if (db.Database.EnsureCreated())
689: {
690: // below: first will delete all current records
691: var all = from nfdc in db.FeatureDesignations select nfdc;
692: db.FeatureDesignations.RemoveRange(all);
693: db.SaveChanges();
694: }
695:
696: db.SaveChanges();
697:
698: result.AddSuccess("Records deleted. ");
699: }
700: }
701: catch (Exception ex)
702: {
703: result.AddError(ex.ToString());
704: }
705: }
706:
707: ////////////////////////////////////////////////////////////////////////////
708:
709: /// <summary>
710: ///
711: /// </summary>
712: public static void RemoveUnNeededColumns(ref DataTable dataTable, List<Ia.Cl.Model.Language> countrySpokenLanguageList)
713: {
714: List<string> columnsToRemove;
715:
716: dataTable.Columns.Remove("Deleted");
717: dataTable.Columns.Remove("Description");
718: dataTable.Columns.Remove("Created");
719: dataTable.Columns.Remove("Updated");
720:
721: columnsToRemove = new List<string>();
722:
723: foreach (DataColumn column in dataTable.Columns)
724: {
725: if (countrySpokenLanguageList.Find(u => u.Symbol == column.ColumnName.ToLower()) == null)
726: {
727: if (column.ColumnName.ToLower() != "id" && column.ColumnName.ToLower() != "class")
728: {
729: columnsToRemove.Add(column.ColumnName);
730: }
731: }
732: }
733:
734: if (columnsToRemove.Count > 0)
735: {
736: foreach (string columnName in columnsToRemove)
737: {
738: dataTable.Columns.Remove(columnName);
739: }
740: }
741: }
742:
743: ////////////////////////////////////////////////////////////////////////////
744: ////////////////////////////////////////////////////////////////////////////
745: }
746: }