)>}]
شركة التطبيقات المتكاملة لتصميم وبرمجة البرمجيات الخاصة ش.ش.و.
Integrated Applications Programming Company
Home » Code Library » Inventory (Ia.Cl.Models.Business.Nfc)

Public general use code classes and xml files that we've compiled and used over the years:

Inventory NFC Near-Field Communication (NFC) Support Business functions

    1: using System;
    2: using System.Collections.Generic;
    3: using System.Linq;
    4:  
    5: namespace Ia.Cl.Models.Business.Nfc
    6: {
    7:     ////////////////////////////////////////////////////////////////////////////
    8:  
    9:     /// <summary publish="true">
   10:     /// Inventory NFC Near-Field Communication (NFC) Support Business functions
   11:     /// </summary>
   12:     /// <remarks> 
   13:     /// Copyright © 2020-2021 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 partial class Inventory
   26:     {
   27:         ////////////////////////////////////////////////////////////////////////////
   28:  
   29:         /*
   30:          * Don't remove items that are obsolete, just mark them with obsolete="true"
   31:          * Insertable is true if not explicitly specified
   32:          */
   33:  
   34:         ////////////////////////////////////////////////////////////////////////////
   35:  
   36:         /// <summary>
   37:         ///
   38:         /// </summary>
   39:  
   40:         public enum CreateOrUpdateCondition 
   41:         {
   42:             /// <summary/>
   43:             IgnoreLatitudeAndLongitude,
   44:  
   45:             /// <summary/>
   46:             None
   47:         };
   48:  
   49:         ////////////////////////////////////////////////////////////////////////////
   50:  
   51:         /// <summary>
   52:         ///
   53:         /// </summary>
   54:         public class Type
   55:         {
   56:             /// <summary/>
   57:             public int Id { get; set; }
   58:  
   59:             /// <summary/>
   60:             public bool Obsolete { get; set; }
   61:  
   62:             /// <summary/>
   63:             public bool Insertable { get; set; }
   64:  
   65:             /// <summary/>
   66:             public string Name { get; set; }
   67:  
   68:             /// <summary/>
   69:             public string ArabicName { get; set; }
   70:         }
   71:  
   72:         ////////////////////////////////////////////////////////////////////////////
   73:  
   74:         /// <summary>
   75:         ///
   76:         /// </summary>
   77:         public static List<Type> TypeList(int projectId)
   78:         {
   79:             List<Type> list;
   80:  
   81:             list = new List<Type>();
   82:  
   83:             list.Add(new Type { Id = 1, Name = "Tree", ArabicName = "", Obsolete = false, Insertable = true });
   84:             list.Add(new Type { Id = 2, Name = "Engine", ArabicName = "", Obsolete = false, Insertable = true });
   85:             list.Add(new Type { Id = 3, Name = "Filter", ArabicName = "", Obsolete = false, Insertable = true });
   86:             list.Add(new Type { Id = 4, Name = "Tire", ArabicName = "", Obsolete = false, Insertable = true });
   87:             list.Add(new Type { Id = 5, Name = "Cat", ArabicName = "", Obsolete = false, Insertable = true });
   88:             list.Add(new Type { Id = 6, Name = "Vehicle", ArabicName = "", Obsolete = false, Insertable = true });
   89:  
   90:             if (list.Select(u => u.Id).Distinct().Count() != list.Count())
   91:             {
   92:                 throw new Exception("Duplicate Id in Ia.Cl.Models.Business.Nfc.Default.NfcTypeList.");
   93:             }
   94:  
   95:             return list;
   96:         }
   97:  
   98:         ////////////////////////////////////////////////////////////////////////////
   99:  
  100:         /// <summary>
  101:         ///
  102:         /// </summary>
  103:         public class State
  104:         {
  105:             /// <summary/>
  106:             public int Id { get; set; }
  107:  
  108:             /// <summary/>
  109:             public bool Obsolete { get; set; }
  110:  
  111:             /// <summary/>
  112:             public bool Insertable { get; set; }
  113:  
  114:             /// <summary/>
  115:             public string Name { get; set; }
  116:  
  117:             /// <summary/>
  118:             public string ArabicName { get; set; }
  119:         }
  120:  
  121:         ////////////////////////////////////////////////////////////////////////////
  122:  
  123:         /// <summary>
  124:         ///
  125:         /// </summary>
  126:         public static List<State> StateList(int projectId)
  127:         {
  128:             List<State> list;
  129:  
  130:             list = new List<State>();
  131:  
  132:             list.Add(new State { Id = 1, Name = "Available", ArabicName = "", Obsolete = false, Insertable = true });
  133:             list.Add(new State { Id = 2, Name = "Stolen", ArabicName = "", Obsolete = false, Insertable = true });
  134:             list.Add(new State { Id = 3, Name = "Lost", ArabicName = "", Obsolete = false, Insertable = true });
  135:             list.Add(new State { Id = 4, Name = "Missing", ArabicName = "", Obsolete = false, Insertable = true });
  136:             list.Add(new State { Id = 5, Name = "Damaged", ArabicName = "", Obsolete = false, Insertable = true });
  137:             list.Add(new State { Id = 6, Name = "Recovered", ArabicName = "", Obsolete = false, Insertable = true });
  138:             list.Add(new State { Id = 7, Name = "Displayed", ArabicName = "", Obsolete = false, Insertable = true });
  139:             list.Add(new State { Id = 8, Name = "Spoiled", ArabicName = "", Obsolete = false, Insertable = true });
  140:  
  141:             if (list.Select(u => u.Id).Distinct().Count() != list.Count())
  142:             {
  143:                 throw new Exception("Duplicate Id in Ia.Cl.Models.Business.Nfc.Default.NfcStateList.");
  144:             }
  145:  
  146:             return list;
  147:         }
  148:  
  149:         ////////////////////////////////////////////////////////////////////////////
  150:  
  151:         /// <summary>
  152:         ///
  153:         /// </summary>
  154:         public static string TypeNameByTypeId(int projectId, int typeId)
  155:         {
  156:             string name;
  157:  
  158:             name = (from t in Ia.Cl.Models.Business.Nfc.Inventory.TypeList(projectId) where t.Id == typeId select t.Name).SingleOrDefault();
  159:  
  160:             return name;
  161:         }
  162:  
  163:         ////////////////////////////////////////////////////////////////////////////
  164:  
  165:         /// <summary>
  166:         ///
  167:         /// </summary>
  168:         public static string StateNameListByStateIdList(int projectId, string stateIdList)
  169:         {
  170:             string name;
  171:             var nameList = new List<string>();
  172:  
  173:             foreach (string stateId in stateIdList.Split(','))
  174:             {
  175:                 if (int.TryParse(stateId, out int i))
  176:                 {
  177:                     name = (from t in Ia.Cl.Models.Business.Nfc.Inventory.StateList(projectId) where t.Id == i select t.Name).SingleOrDefault();
  178:  
  179:                     if (!string.IsNullOrEmpty(name)) nameList.Add(name);
  180:                 }
  181:                 else
  182:                 {
  183:                 }
  184:             }
  185:  
  186:             return string.Join(", ", nameList);
  187:         }
  188:  
  189:         ////////////////////////////////////////////////////////////////////////////
  190:  
  191:         /// <summary>
  192:         ///
  193:         /// </summary>
  194:         public Inventory() { }
  195:  
  196:         ////////////////////////////////////////////////////////////////////////////
  197:  
  198:         /// <summary>
  199:         ///
  200:         /// </summary>
  201:         public static void CreateOrUpdate(string tagId, string name, string description, string content, string note, int typeId, string stateIdList, Guid userId)
  202:         {
  203:             CreateOrUpdate(tagId, name, description, content, note, typeId, stateIdList, 0, 0, userId, CreateOrUpdateCondition.IgnoreLatitudeAndLongitude);
  204:         }
  205:  
  206:         ////////////////////////////////////////////////////////////////////////////
  207:  
  208:         /// <summary>
  209:         ///
  210:         /// </summary>
  211:         public static void CreateOrUpdate(string tagId, string name, string description, string content, string note, int typeId, string stateIdList, double latitude, double longitude, Guid userId)
  212:         {
  213:             CreateOrUpdate(tagId, name, description, content, note, typeId, stateIdList, latitude, longitude, userId, CreateOrUpdateCondition.None);
  214:         }
  215:  
  216:         ////////////////////////////////////////////////////////////////////////////
  217:  
  218:         /// <summary>
  219:         ///
  220:         /// </summary>
  221:         public static void CreateOrUpdate(string tagId, string name, string description, string content, string note, int typeId, string stateIdList, double latitude, double longitude, Guid userId, CreateOrUpdateCondition createOrUpdateCondition)
  222:         {
  223:             var tag = Ia.Cl.Models.Data.Nfc.Tag.Read(tagId);
  224:  
  225:             if (tag != null)
  226:             {
  227:                 var dateTime = DateTime.UtcNow.AddHours(3);
  228:  
  229:                 var id = tagId;
  230:  
  231:                 /*
  232:                 using (var db = new Ia.Cl.Models.IaDbContext())
  233:                 {
  234:                     Ia.Cl.Models.Nfc.Inventory newInventory;
  235: 
  236:                     if (createOrUpdateCondition == CreateOrUpdateCondition.IgnoreLatitudeAndLongitude)
  237:                     {
  238:                         newInventory = new Ia.Cl.Models.Nfc.Inventory
  239:                         {
  240:                             Id = id,
  241:                             ProjectId = tag.ProjectId,
  242:                             Name = name,
  243:                             Description = description,
  244:                             Content = content,
  245:                             Note = note,
  246:                             TypeId = typeId,
  247:                             StateIdList = stateIdList,
  248:                             UserId = userId,
  249:                             Created = dateTime,
  250:                             Updated = dateTime,
  251:                             Deleted = null
  252:                         };
  253:                     }
  254:                     else
  255:                     {
  256:                         newInventory = new Ia.Cl.Models.Nfc.Inventory
  257:                         {
  258:                             Id = id,
  259:                             ProjectId = tag.ProjectId,
  260:                             Name = name,
  261:                             Description = description,
  262:                             Content = content,
  263:                             Note = note,
  264:                             TypeId = typeId,
  265:                             StateIdList = stateIdList,
  266:                             Latitude = latitude,
  267:                             Longitude = longitude,
  268:                             UserId = userId,
  269:                             Created = dateTime,
  270:                             Updated = dateTime,
  271:                             Deleted = null
  272:                         };
  273:                     }
  274: 
  275:                     var persistentStorageState = Ia.Cl.Models.Data.Nfc.Inventory.CreateOrUpdate(newInventory);
  276:                 }
  277:                 */
  278:             }
  279:             else
  280:             {
  281:                 //
  282:             }
  283:         }
  284:  
  285:         ////////////////////////////////////////////////////////////////////////////
  286:         ////////////////////////////////////////////////////////////////////////////
  287:     }
  288:  
  289:     ////////////////////////////////////////////////////////////////////////////
  290:     ////////////////////////////////////////////////////////////////////////////
  291: }