//DBStoredImage Object Scope Validation check the entire object for validity...
        private byte DBStoredImageIsValid(DBStoredImage item, out string errorMessage)
        {   //validate key
            errorMessage = "";
            if (string.IsNullOrEmpty(item.ImageID))
            {
                errorMessage = "ID Is Required.";
                return(1);
            }
            EntityStates entityState = GetDBStoredImageState(item);

            if (entityState == EntityStates.Added && DBStoredImageExists(item.ImageID))
            {
                errorMessage = "Item AllReady Exists.";
                return(1);
            }
            //check cached list for duplicates...
            int count = DBStoredImageList.Count(q => q.ImageID == item.ImageID);

            if (count > 1)
            {
                errorMessage = "Item AllReady Exists.";
                return(1);
            }
            ////validate Description
            //if (string.IsNullOrEmpty(item.Name))
            //{
            //    errorMessage = "Name Is Required.";
            //    return 1;
            //}
            ////a value of 2 is pending changes...
            ////On Commit we will give it a value of 0...
            return(2);
        }
 private void ChangeKeyLogic()
 {
     if (!string.IsNullOrEmpty(SelectedDBStoredImage.ImageID))
     {//check to see if key is part of the current companylist...
         DBStoredImage query = DBStoredImageList.Where(company => company.ImageID == SelectedDBStoredImage.ImageID &&
                                                       company.AutoID != SelectedDBStoredImage.AutoID).FirstOrDefault();
         if (query != null)
         {//revert it back
             SelectedDBStoredImage.ImageID = SelectedDBStoredImageMirror.ImageID;
             //change to the newly selected company...
             SelectedDBStoredImage = query;
             return;
         }
         //it is not part of the existing list try to fetch it from the db...
         DBStoredImageList = GetDBStoredImageByID(SelectedDBStoredImage.ImageID, XERP.Client.ClientSessionSingleton.Instance.CompanyID);
         if (DBStoredImageList.Count == 0)//it was not found do new record required logic...
         {
             NotifyNewRecordNeeded("Record " + SelectedDBStoredImage.ImageID + " Does Not Exist.  Create A New Record?");
         }
         else
         {
             SelectedDBStoredImage = DBStoredImageList.FirstOrDefault();
         }
     }
     else
     {
         string errorMessage = "ID Is Required.";
         NotifyMessage(errorMessage);
         //revert back to the value it was before it was changed...
         if (SelectedDBStoredImage.ImageID != SelectedDBStoredImageMirror.ImageID)
         {
             SelectedDBStoredImage.ImageID = SelectedDBStoredImageMirror.ImageID;
         }
     }
 }
        public void DeleteFromRepository(DBStoredImage dBStoredImage)
        {
            if (_repositoryContext.GetEntityDescriptor(dBStoredImage) != null)
            {//if it exists in the db delete it from the db
                MenuSecurityEntities context = new MenuSecurityEntities(_rootUri);
                context.MergeOption = MergeOption.AppendOnly;
                context.IgnoreResourceNotFoundException = true;
                DBStoredImage deletedDBStoredImage = (from q in context.DBStoredImages
                                                      where q.ImageID == dBStoredImage.ImageID
                                                      select q).FirstOrDefault();
                if (deletedDBStoredImage != null)
                {
                    context.DeleteObject(deletedDBStoredImage);
                    context.SaveChanges();
                }
                context = null;

                _repositoryContext.MergeOption = MergeOption.AppendOnly;
                //if it is being tracked remove it...
                if (GetDBStoredImageEntityState(dBStoredImage) != EntityStates.Detached)
                {
                    _repositoryContext.Detach(dBStoredImage);
                }
            }
        }
Esempio n. 4
0
        public BitmapImage GetMenuItemImage(string imageID, string companyID)
        {
            System.Windows.Media.Imaging.BitmapImage wpfImg = new System.Windows.Media.Imaging.BitmapImage();
            try
            {
                DBStoredImage dbStoredImage = _context.DBStoredImages.First();
                _context.IgnoreResourceNotFoundException = true;
                _context.MergeOption = MergeOption.NoTracking;
                dbStoredImage        = (from q in _context.DBStoredImages
                                        where q.ImageID == imageID &&
                                        q.CompanyID == companyID
                                        select q).FirstOrDefault();

                MemoryStream stream = new MemoryStream();
                stream.Write(dbStoredImage.StoredImage, 0, dbStoredImage.StoredImage.Length);

                //System.Windows.Media.Imaging.BitmapImage wpfImg = new System.Windows.Media.Imaging.BitmapImage();
                wpfImg.BeginInit();
                wpfImg.StreamSource = stream;
                wpfImg.EndInit();
            }//if image fails we will return the empty bitmapimage object
            catch
            {//reset it as to have a new crisp empty one to return... as to hopefull not cause errors when trying to display a corrupted one...
                wpfImg = new System.Windows.Media.Imaging.BitmapImage();
            }
            return(wpfImg);
        }
        public void DeleteDBStoredImageCommand()
        {
            try
            {
                int i  = 0;
                int ii = 0;
                for (int j = SelectedDBStoredImageList.Count - 1; j >= 0; j--)
                {
                    DBStoredImage item = (DBStoredImage)SelectedDBStoredImageList[j];
                    //get Max Index...
                    i = DBStoredImageList.IndexOf(item);
                    if (i > ii)
                    {
                        ii = i;
                    }
                    Delete(item);
                    DBStoredImageList.Remove(item);
                }

                if (DBStoredImageList != null && DBStoredImageList.Count > 0)
                {
                    //back off one index from the max index...
                    ii = ii - 1;

                    //if they delete the first row...
                    if (ii < 0)
                    {
                        ii = 0;
                    }

                    //make sure it does not exceed the list count...
                    if (ii >= DBStoredImageList.Count())
                    {
                        ii = DBStoredImageList.Count - 1;
                    }

                    SelectedDBStoredImage = DBStoredImageList[ii];
                    //we will only enable committ for dirty validated records...
                    if (Dirty == true)
                    {
                        AllowCommit = CommitIsAllowed();
                    }
                    else
                    {
                        AllowCommit = false;
                    }
                }
                else//only one record, deleting will result in no records...
                {
                    SetAsEmptySelection();
                }
            }//we try catch company delete as it may be used in another table as a key...
            //As well we will force a refresh to sqare up the UI after the botched delete...
            catch
            {
                NotifyMessage("DBStoredImage/s Can Not Be Deleted.  Contact XERP Admin For More Details.");
                Refresh();
            }
        }
        private BindingList <DBStoredImage> GetDBStoredImages(DBStoredImage item, string companyID)
        {
            BindingList <DBStoredImage> itemList = new BindingList <DBStoredImage>(_serviceAgent.GetDBStoredImages(item, companyID).ToList());

            Dirty       = false;
            AllowCommit = false;
            return(itemList);
        }
        public static void SetPropertyValue(this DBStoredImage myObj, object propertyName, object propertyValue)
        {
            var propInfo = typeof(DBStoredImage).GetProperty((string)propertyName);

            if (propInfo != null)
            {
                propInfo.SetValue(myObj, propertyValue, null);
            }
        }
 private void SetAsEmptySelection()
 {
     SelectedDBStoredImage = new DBStoredImage();
     AllowEdit             = false;
     AllowDelete           = false;
     Dirty        = false;
     AllowCommit  = false;
     AllowRowCopy = false;
 }
 public void UpdateRepository(DBStoredImage item)
 {
     if (_repositoryContext.GetEntityDescriptor(item) != null)
     {
         item.LastModifiedBy            = XERP.Client.ClientSessionSingleton.Instance.SystemUserID;
         item.LastModifiedByDate        = DateTime.Now;
         _repositoryContext.MergeOption = MergeOption.AppendOnly;
         _repositoryContext.UpdateObject(item);
     }
 }
 public EntityStates GetDBStoredImageEntityState(DBStoredImage dBStoredImage)
 {
     if (_repositoryContext.GetEntityDescriptor(dBStoredImage) != null)
     {
         return(_repositoryContext.GetEntityDescriptor(dBStoredImage).State);
     }
     else
     {
         return(EntityStates.Detached);
     }
 }
Esempio n. 11
0
        public static object GetPropertyValue(this DBStoredImage myObj, string propertyName)
        {
            var propInfo = typeof(DBStoredImage).GetProperty(propertyName);

            if (propInfo != null)
            {
                return(propInfo.GetValue(myObj, null));
            }
            else
            {
                return(string.Empty);
            }
        }
Esempio n. 12
0
        public static string GetPropertyType(this DBStoredImage myObj, string propertyName)
        {
            var propInfo = typeof(DBStoredImage).GetProperty(propertyName);

            if (propInfo != null)
            {
                return(propInfo.PropertyType.Name.ToString());
            }
            else
            {
                return(null);
            }
        }
Esempio n. 13
0
 //udpate merely updates the repository a commit is required
 //to commit it to the db...
 private bool Update(DBStoredImage item)
 {
     _serviceAgent.UpdateDBStoredImageRepository(item);
     Dirty = true;
     if (CommitIsAllowed())
     {
         AllowCommit = true;
     }
     else
     {
         AllowCommit = false;
     }
     return(AllowCommit);
 }
        public IEnumerable <DBStoredImage> GetDBStoredImages(DBStoredImage dBStoredImageQuerryObject, string companyID)
        {
            _repositoryContext             = new MenuSecurityEntities(_rootUri);
            _repositoryContext.MergeOption = MergeOption.AppendOnly;
            _repositoryContext.IgnoreResourceNotFoundException = true;
            var queryResult = from q in _repositoryContext.DBStoredImages
                              where q.CompanyID == companyID
                              select q;

            if (!string.IsNullOrEmpty(dBStoredImageQuerryObject.Description))
            {
                queryResult = queryResult.Where(q => q.Description.StartsWith(dBStoredImageQuerryObject.Description.ToString()));
            }

            return(queryResult);
        }
Esempio n. 15
0
        public MainSearchViewModel(IDBStoredImageServiceAgent serviceAgent)
        {
            this._serviceAgent = serviceAgent;

            SearchObject = new DBStoredImage();
            ResultList   = new BindingList <DBStoredImage>();
            SelectedList = new BindingList <DBStoredImage>();
            //make sure of session authentication...
            if (ClientSessionSingleton.Instance.SessionIsAuthentic) //make sure user has rights to UI...
            {
                DoFormsAuthentication();
            }
            else
            {//User is not authenticated...
                RegisterToReceiveMessages <bool>(MessageTokens.StartUpLogInToken.ToString(), OnStartUpLogIn);
                FormIsEnabled = false;
            }
        }
Esempio n. 16
0
        //Object.Property Scope Validation...
        private bool DBStoredImageIsValid(DBStoredImage item, _dBStoredImageValidationProperties validationProperties, out string errorMessage)
        {
            errorMessage = "";
            switch (validationProperties)
            {
            case _dBStoredImageValidationProperties.ImageID:
                //validate key
                if (string.IsNullOrEmpty(item.ImageID))
                {
                    errorMessage = "ID Is Required.";
                    return(false);
                }
                EntityStates entityState = GetDBStoredImageState(item);
                if (entityState == EntityStates.Added && DBStoredImageExists(item.ImageID))
                {
                    errorMessage = "Item All Ready Exists...";
                    return(false);
                }
                //check cached list for duplicates...
                int count = DBStoredImageList.Count(q => q.ImageID == item.ImageID);
                if (count > 1)
                {
                    errorMessage = "Item All Ready Exists...";
                    return(false);
                }
                break;

                //case _dBStoredImageValidationProperties.Name:
                //    //validate Description
                //    if (string.IsNullOrEmpty(item.Name))
                //    {
                //        errorMessage = "Description Is Required.";
                //        return false;
                //    }
                //    break;
            }
            return(true);
        }
Esempio n. 17
0
        private bool NewDBStoredImage(string itemID)
        {
            DBStoredImage newItem = new DBStoredImage();

            //all new records will be give a negative int autoid...
            //when they are updated then sql will generate one for them overiding this set value...
            //it will allow us to give uniqueness to the tempory new records...
            //Before they are updated to the entity and given an autoid...
            //we use a negative number and keep subtracting by 1 for each new item added...
            //This will allow it to alwasy be unique and never interfere with SQL's positive autoid...
            _newDBStoredImageAutoId = _newDBStoredImageAutoId - 1;
            newItem.AutoID          = _newDBStoredImageAutoId;
            newItem.ImageID         = itemID;
            newItem.CompanyID       = ClientSessionSingleton.Instance.CompanyID;
            newItem.IsValid         = 1;
            newItem.NotValidMessage = "New Record Key Field/s Are Required.";
            DBStoredImageList.Add(newItem);
            _serviceAgent.AddToDBStoredImageRepository(newItem);
            SelectedDBStoredImage = DBStoredImageList.LastOrDefault();

            AllowEdit = true;
            Dirty     = false;
            return(true);
        }
Esempio n. 18
0
 private BindingList <DBStoredImage> GetDBStoredImages(DBStoredImage itemQueryObject, string companyID)
 {//note this get is to the singleton repository...
     return(new BindingList <DBStoredImage>(_serviceAgent.GetDBStoredImages(itemQueryObject, companyID).ToList()));
 }
Esempio n. 19
0
 private bool Delete(DBStoredImage item)
 {//deletes are done indenpendently of the repository as a delete will not commit
     //dirty records it will simply just delete the record...
     _serviceAgent.DeleteFromDBStoredImageRepository(item);
     return(true);
 }
 public void AddToRepository(DBStoredImage dBStoredImage)
 {
     dBStoredImage.CompanyID        = XERP.Client.ClientSessionSingleton.Instance.CompanyID;
     _repositoryContext.MergeOption = MergeOption.AppendOnly;
     _repositoryContext.AddToDBStoredImages(dBStoredImage);
 }
Esempio n. 21
0
 private EntityStates GetDBStoredImageState(DBStoredImage item)
 {
     return(_serviceAgent.GetDBStoredImageEntityState(item));
 }
Esempio n. 22
0
 public IEnumerable <DBStoredImage> GetDBStoredImages(DBStoredImage dBStoredImageQuerryObject, string companyID)
 {
     return(DBStoredImageSingletonRepository.Instance.GetDBStoredImages(dBStoredImageQuerryObject, companyID));
 }
Esempio n. 23
0
 public void UpdateDBStoredImageRepository(DBStoredImage dBStoredImage)
 {
     DBStoredImageSingletonRepository.Instance.UpdateRepository(dBStoredImage);
 }
Esempio n. 24
0
 public void AddToDBStoredImageRepository(DBStoredImage dBStoredImage)
 {
     DBStoredImageSingletonRepository.Instance.AddToRepository(dBStoredImage);
 }
Esempio n. 25
0
 public void DeleteFromDBStoredImageRepository(DBStoredImage dBStoredImage)
 {
     DBStoredImageSingletonRepository.Instance.DeleteFromRepository(dBStoredImage);
 }
Esempio n. 26
0
 public EntityStates GetDBStoredImageEntityState(DBStoredImage dBStoredImage)
 {
     return(DBStoredImageSingletonRepository.Instance.GetDBStoredImageEntityState(dBStoredImage));
 }