Professional Applications Programmers/Consultants برمجة واستشارات تطبيقات الإنترنت
Skip Navigation LinksHome » Code Library » Inventory

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

Inventory Entity Framework class for Next Generation Network (NGN) entity model.

   1:  using System;
   2:  using System.Collections.Generic;
   3:  using System.Linq;
   4:  using System.Web;
   5:  using System.Web.Security;
   6:   
   7:  namespace Ia.Ngn.Cl.Model
   8:  {
   9:      ////////////////////////////////////////////////////////////////////////////
  10:   
  11:      /// <summary publish="true">
  12:      /// Inventory Entity Framework class for Next Generation Network (NGN) entity model.
  13:      /// </summary>
  14:      /// 
  15:      /// <remarks> 
  16:      /// Copyright © 2006-2017 Jasem Y. Al-Shamlan (info@ia.com.kw), Internet 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 partial class Inventory
  29:      {
  30:          /// <summary/>
  31:          public Inventory() { }
  32:   
  33:          /// <summary/>
  34:          public int Id { get; set; }
  35:   
  36:          /// <summary/>
  37:          public string Name { get; set; }
  38:   
  39:          /// <summary/>
  40:          public int Company { get; set; }
  41:   
  42:          /// <summary/>
  43:          public string Description { get; set; }
  44:   
  45:          /// <summary/>
  46:          public string BarCode { get; set; }
  47:   
  48:          /// <summary/>
  49:          public int Quantity { get; set; }
  50:   
  51:          /// <summary/>
  52:          public float Price { get; set; }
  53:   
  54:          /// <summary/>
  55:          public DateTime Created { get; set; }
  56:   
  57:          /// <summary/>
  58:          public DateTime Updated { get; set; }
  59:   
  60:          /// <summary/>
  61:          public System.Guid UserId { get; set; }
  62:   
  63:          ////////////////////////////////////////////////////////////////////////////
  64:   
  65:          /// <summary>
  66:          ///
  67:          /// </summary>
  68:          public static bool Create(Inventory newInventory, out string result)
  69:          {
  70:              bool b;
  71:   
  72:              b = false;
  73:              result = "";
  74:   
  75:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
  76:              {
  77:                  newInventory.Created = newInventory.Updated = DateTime.UtcNow.AddHours(3);
  78:   
  79:                  db.Inventory.Add(newInventory);
  80:                  db.SaveChanges();
  81:   
  82:                  b = true;
  83:              }
  84:   
  85:              return b;
  86:          }
  87:   
  88:          ////////////////////////////////////////////////////////////////////////////
  89:   
  90:          /// <summary>
  91:          ///
  92:          /// </summary>
  93:          public static Inventory Read(int id)
  94:          {
  95:              Inventory inventory;
  96:   
  97:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
  98:              {
  99:                  inventory = (from i in db.Inventory where i.Id == id select i).SingleOrDefault();
 100:              }
 101:   
 102:              return inventory;
 103:          }
 104:   
 105:          ////////////////////////////////////////////////////////////////////////////
 106:   
 107:          /// <summary>
 108:          ///
 109:          /// </summary>
 110:          public static List<Inventory> ReadList()
 111:          {
 112:              List<Inventory> inventoryList;
 113:   
 114:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 115:              {
 116:                  inventoryList = (from i in db.Inventory select i).ToList();
 117:              }
 118:   
 119:              return inventoryList;
 120:          }
 121:   
 122:          ////////////////////////////////////////////////////////////////////////////
 123:   
 124:          /// <summary>
 125:          ///
 126:          /// </summary>
 127:          public static bool Update(Inventory updatedInventory, out string result)
 128:          {
 129:              bool b;
 130:   
 131:              b = false;
 132:              result = "";
 133:   
 134:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 135:              {
 136:                  updatedInventory = (from i in db.Inventory where i.Id == updatedInventory.Id select i).SingleOrDefault();
 137:   
 138:                  updatedInventory.Updated = DateTime.UtcNow.AddHours(3);
 139:   
 140:                  db.Inventory.Attach(updatedInventory);
 141:   
 142:                  var v = db.Entry(updatedInventory);
 143:                  v.State = System.Data.Entity.EntityState.Modified;
 144:                  db.SaveChanges();
 145:   
 146:                  b = true;
 147:              }
 148:   
 149:              return b;
 150:          }
 151:   
 152:          ////////////////////////////////////////////////////////////////////////////
 153:   
 154:          /// <summary>
 155:          ///
 156:          /// </summary>
 157:          public bool Update(/*Ont updatedOnt*/ object updatedObject)
 158:          {
 159:              // below: this will not update Id, Created
 160:              bool updated;
 161:   
 162:              updated = false;
 163:   
 164:              //if (this.StateId != updatedOnt.StateId) { this.StateId = updatedOnt.StateId; updated = true; }
 165:   
 166:              //if (updated) this.Updated = DateTime.UtcNow.AddHours(3);
 167:   
 168:              return updated;
 169:          }
 170:   
 171:          ////////////////////////////////////////////////////////////////////////////
 172:   
 173:          /// <summary>
 174:          ///
 175:          /// </summary>
 176:          public static bool QuantityChange(int inventoryId, int increment, out string result)
 177:          {
 178:              bool b;
 179:              Inventory updatedInventory;
 180:   
 181:              b = false;
 182:              result = "";
 183:   
 184:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 185:              {
 186:                  updatedInventory = (from i in db.Inventory where i.Id == inventoryId select i).SingleOrDefault();
 187:   
 188:                  updatedInventory.Quantity += increment;
 189:   
 190:                  if (updatedInventory.Quantity >= 0)
 191:                  {
 192:                      // below: don't go below 0
 193:                      updatedInventory.Updated = DateTime.UtcNow.AddHours(3);
 194:   
 195:                      db.Inventory.Attach(updatedInventory);
 196:   
 197:                      var v = db.Entry(updatedInventory);
 198:                      v.State = System.Data.Entity.EntityState.Modified;
 199:                      db.SaveChanges();
 200:   
 201:                      b = true;
 202:                  }
 203:                  else
 204:                  {
 205:                      b = false;
 206:                  }
 207:              }
 208:   
 209:              return b;
 210:          }
 211:   
 212:          ////////////////////////////////////////////////////////////////////////////
 213:   
 214:          /// <summary>
 215:          ///
 216:          /// </summary>
 217:          public static bool Delete(int id, out string result)
 218:          {
 219:              bool b;
 220:   
 221:              b = false;
 222:              result = "";
 223:   
 224:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 225:              {
 226:                  var v = (from i in db.Inventory where i.Id == id select i).FirstOrDefault();
 227:   
 228:                  if (v.Quantity == 0)
 229:                  {
 230:                      db.Inventory.Remove(v);
 231:                      db.SaveChanges();
 232:   
 233:                      b = true;
 234:                  }
 235:                  else
 236:                  {
 237:                      result = "Item can't be deleted because quantity is not zero. ";
 238:   
 239:                      b = false;
 240:                  }
 241:              }
 242:   
 243:              return b;
 244:          }
 245:   
 246:          /*
 247:  <?xml version="1.0" encoding="utf-8"?>
 248:  
 249:  <inventory>
 250:  
 251:    <!--
 252:    Inventory System Requirements
 253:  
 254:    demand and
 255:    replenishment lead time data
 256:  
 257:    forecasts
 258:  
 259:    reviewing the stock
 260:    position;
 261:    - preparing the purchase
 262:    request;
 263:    - selecting the supplier;
 264:    receiving, inspecting, and
 265:    placing the material in
 266:    storage; and
 267:    - paying the vendor.
 268:  
 269:    Does the system estimate and
 270:    routinely update the per unit
 271:    inventory holding cost, which
 272:    is an estimate of the cost to
 273:    hold each additional unit of
 274:    inventory? Its primary
 275:    elements are storage space,
 276:    obsolescence, interest on
 277:    inventory investment, and
 278:    inventory shrinkage (due to
 279:    deterioration, theft, damage,
 280:    etc.).
 281:    4.
 282:  
 283:  
 284:    Does the system recompute
 285:    the Economic Order Quantity
 286:    (EOQ) on a regular, frequent
 287:    schedule, using the demand
 288:    forecast, ordering cost,
 289:    inventory holding cost, and
 290:    unit cost of the material? In
 291:    lieu of the EOQ, any other
 292:    optimum order quantity
 293:    calculation may be used,
 294:    provided (a) it is based on
 295:    sound business principles and
 296:    (b) it minimizes total cost,
 297:    including the sum of ordering
 298:    and inventory holding costs
 299:  
 300:  
 301:    Does the system recompute
 302:    the safety stock, if any, on a
 303:    regular and frequent schedule
 304:  
 305:  
 306:    Does the system recompute
 307:    the reorder point level on a
 308:    regular and frequent schedule
 309:  
 310:  
 311:    Does the system determine if
 312:    replenishment is needed on a
 313:    regular and frequent schedule,
 314:    basing the determination on
 315:    net stock and reorder point? If
 316:    needed, immediately initiate a
 317:    replenishment action using the
 318:    EOQ or other order quantity,
 319:  
 320:    Does the system provide
 321:    information on current
 322:    inventories and historical
 323:    usage to be used in capacity
 324:    planning?
 325:  
 326:    Does the system provide to
 327:    agency inventory managers
 328:    and designated internal review
 329:    officials, on a periodic or
 330:    requested basis, at least the
 331:    following types of
 332:    management information:
 333:    - demand?
 334:    - procurement lead time?
 335:    - procurement cycle?
 336:    - requirements?
 337:    - assets?
 338:    - available funds?
 339:    - budget versus actual?
 340:    - rates of fund utilization?
 341:  
 342:    Does the system record
 343:    information on material
 344:    returned by customers?
 345:  
 346:    Does the system provide
 347:    support for physical
 348:    verification of inventory
 349:    balances by location and type?
 350:  
 351:    Does the system record
 352:    changes in physical condition
 353:    (e.g., excellent, good, fair, or
 354:    poor), quantities, etc., based
 355:    on the results of physical
 356:    inventory verifications?
 357:  
 358:    =====================================
 359:  
 360:    Inventory System supports updating inventory information for all items, monitoring inventory depletion, and importing and exporting
 361:    inventory information to and from external systems of record
 362:  
 363:    =====================================
 364:  
 365:    Flexible configuration that allows for backordering and display of out of stock stock-keeping units (SKUs).
 366:  
 367:    Order checking and update through pipeline components.
 368:  
 369:    Full text search and query integration with the Catalog System.
 370:  
 371:    Transactional updates.
 372:  
 373:    Import and export operations similar to the Catalog System.
 374:  
 375:    Runtime APIs with methods for searching, browsing, viewing details, inventory search options that include product filtering, assigning inventory conditions, and roll-up values.
 376:    
 377:    
 378:    
 379:    Inventory Disposition consists of the following processes: (a) loaning
 380:  process, (b) issuing process, and (c) disposal process.
 381:  
 382:  
 383:  inventory shrinkage (due to
 384:  deterioration, theft, damage,
 385:  etc.).
 386:  4.
 387:  
 388:  Economic Order Quantity
 389:  (EOQ) on
 390:  
 391:  
 392:    <inventory>
 393:      <transaction>
 394:        <type id="1" name="Purchased" name_ar=""/>
 395:        <type id="2" name="Sold" name_ar=""/>
 396:        <type id="3" name="On Hold" name_ar=""/>
 397:        <type id="4" name="Waste" name_ar=""/>
 398:        <type id="0" name="Unspecified" name_ar="غير معرف"/>
 399:      </transaction>
 400:    </inventory>
 401:  
 402:    -->
 403:  
 404:    <type id="1" name="ONT" description=""/>
 405:    <type id="2" name="Computer" description=""/>
 406:    <type id="3" name="Board" description=""/>
 407:    <type id="4" name="Card" description=""/>
 408:    <type id="5" name="Switch" description=""/>
 409:    <type id="6" name="Cable" description=""/>
 410:    <type id="7" name="RJ" description=""/>
 411:    <type id="8" name="Screen" description=""/>
 412:    <type id="9" name="Keyboard" description=""/>
 413:    <type id="10" name="Mouse" description=""/>
 414:    <type id="11" name="Phone" description=""/>
 415:  
 416:    <item id="1" type_id="1" name="SFU" code="" discontinued="" description=""/>
 417:  
 418:  </inventory>
 419:           */
 420:   
 421:          ////////////////////////////////////////////////////////////////////////////
 422:          ////////////////////////////////////////////////////////////////////////////
 423:      }
 424:   
 425:      ////////////////////////////////////////////////////////////////////////////
 426:      ////////////////////////////////////////////////////////////////////////////
 427:  }