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