예제 #1
0
        public List <SpareView> GetSparesStrict(int searchFieldIndex, string searchString)
        {
            List <SpareView> items = new List <SpareView>();

            searchString = searchString.ToLower();
            switch (searchFieldIndex)
            {
            case 0:    // ПОИСК ПО КОДУ
                items = Spares.Where(s => s != null).Where(s => s.code != null).Where(s => s.code.ToLower().Equals(searchString)).ToList();
                break;

            case 1:    // ПОИСК ПО НАИМЕНОВАНИЮ
                items = Spares.Where(s => s != null).Where(s => s.name != null).Where(s => s.name.ToLower().Equals(searchString)).ToList();
                break;

            case 2:    // ПОИСК ПО КОДУ ШАТЕ-М
                items = Spares.Where(s => s != null).Where(s => s.codeShatem != null).Where(s => s.codeShatem.ToLower().Equals(searchString)).ToList();
                break;
            }
            if (items == null)
            {
                items = new List <SpareView>();
            }
            return(items.ToList());
        }
예제 #2
0
파일: SpareVM.cs 프로젝트: Yoba91/EService
 private void SparesListCreator(IList<Spare> list)
 {
     Spares.Clear();
     foreach (var item in list)
     {
         Spares.Add(new SView(item, Spares.Count() + 1));
     }
 }
예제 #3
0
        /*
         * OLD
         * public void Update(SpareView spare)
         * {
         *  if (Spares.Where(x => x!= null).Where(x => x.id != null).Where(x => x.id == spare.id).Count() > 0)
         *  {
         *      SpareView sv = spares.Where(x => x != null).Where(x => x.id != null).FirstOrDefault(x => x.id == spare.id);
         *      if(sv != null)
         *          Spares.Remove(sv);
         *  }
         *  Spares.Add(spare);
         * }*/
        /* dec2012
         * public void Update(SpareView NewSpareInstance, bool UpdateFromDB = true) // обновление без удаления
         * {
         *  if (UpdateFromDB)
         *  {
         *      DataAccess da = new DataAccess();
         *      SpareView OldSpareInstance = Spares.Where(x => x != null).FirstOrDefault(x => x.id == NewSpareInstance.id);
         *
         *      // если в кэше такая есть, запоминает индекс и перезаписываем
         *      if (OldSpareInstance != null)
         *      {
         *          int i = Spares.IndexOf(OldSpareInstance);
         *          spares[i] = NewSpareInstance;
         *      }
         *      else
         *      {
         *          spares.Add(NewSpareInstance);
         *      }
         *  }
         *  else
         *  {
         *  List<SpareView> items = this.Spares;
         *  SpareView ind = items.Where(x => x != null).FirstOrDefault(x => x.id == NewSpareInstance.id);
         *  if (ind != null)
         *  {
         *      int i = spares.IndexOf(ind);
         *      spares[i] = NewSpareInstance;
         *  }
         *  else
         *  {
         *      spares.Add(NewSpareInstance);
         *  }
         * }
         * }
         */

        public void Update(int SpareID, bool UpdateFromDB = true, bool SkipQRestsCalculation = false)
        {
            if (UpdateFromDB)
            {
                DataAccess da = new DataAccess();
                SpareView  OldSpareInstance = Spares.Where(x => x != null).FirstOrDefault(x => x.id == SpareID);
                SpareView  NewSpareInstance = da.GetSpareView(SpareID);

                // если в кэше такая есть, запоминает индекс и перезаписываем
                if (OldSpareInstance != null)
                {
                    int i = Spares.IndexOf(OldSpareInstance);
                    spares[i] = NewSpareInstance;
                }
                else
                {
                    spares.Add(NewSpareInstance);
                }
            }
            else
            {
                List <SpareView> items = this.Spares.ToList();
                SpareView        ind   = items.Where(x => x != null).FirstOrDefault(x => x.id == SpareID);
                if (ind != null)
                {
                    int i = spares.IndexOf(ind);
                    spares[i] = ind;
                }
                else
                {
                    DataAccess db = new DataAccess();
                    SpareView  sv = db.GetSpareView(SpareID);
                    spares.Add(sv);
                }
            }
            if (!SkipQRestsCalculation)
            {
                Helper.CalculateQRests(SpareID);
                Update(SpareID, true, true);
            }
        }
예제 #4
0
 public SpareView GetSpare(int ID)
 {
     return(Spares.FirstOrDefault(s => s.id == ID));
 }
예제 #5
0
        public void Remove(int id)
        {
            SpareView sv = Spares.FirstOrDefault(x => x.id == id);

            spares.Remove(sv);
        }