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

            if (entityState == EntityStates.Added && WarehouseCodeExists(item.WarehouseCodeID, ClientSessionSingleton.Instance.CompanyID))
            {
                errorMessage = "Item AllReady Exists.";
                return(1);
            }
            //check cached list for duplicates...
            int count = WarehouseCodeList.Count(q => q.WarehouseCodeID == item.WarehouseCodeID);

            if (count > 1)
            {
                errorMessage = "Item AllReady Exists.";
                return(1);
            }
            //validate Description
            if (string.IsNullOrEmpty(item.Description))
            {
                errorMessage = "Description Is Required.";
                return(1);
            }
            //a value of 2 is pending changes...
            //On Commit we will give it a value of 0...
            return(2);
        }
Esempio n. 2
0
        public void DeleteFromRepository(WarehouseCode itemCode)
        {
            if (_repositoryContext.GetEntityDescriptor(itemCode) != null)
            {//if it exists in the db delete it from the db
                WarehouseEntities context = new WarehouseEntities(_rootUri);
                context.MergeOption = MergeOption.AppendOnly;
                context.IgnoreResourceNotFoundException = true;
                WarehouseCode deletedWarehouseCode = (from q in context.WarehouseCodes
                                                      where q.WarehouseCodeID == itemCode.WarehouseCodeID
                                                      select q).FirstOrDefault();
                if (deletedWarehouseCode != null)
                {
                    context.DeleteObject(deletedWarehouseCode);
                    context.SaveChanges();
                }
                context = null;

                _repositoryContext.MergeOption = MergeOption.AppendOnly;
                //if it is being tracked remove it...
                if (GetWarehouseCodeEntityState(itemCode) != EntityStates.Detached)
                {
                    _repositoryContext.Detach(itemCode);
                }
            }
        }
        public static List <Temp> GetMetaData(this WarehouseCode entityObject)
        {
            XERP.Server.DAL.WarehouseDAL.DALUtility dalUtility = new DALUtility();
            List <Temp> tempList = new List <Temp>();
            int         id       = 0;

            using (WarehouseEntities ctx = new WarehouseEntities(dalUtility.EntityConectionString))
            {
                var c            = ctx.WarehouseCodes.FirstOrDefault();
                var queryResults = from meta in ctx.MetadataWorkspace.GetItems(DataSpace.CSpace)
                                   .Where(m => m.BuiltInTypeKind == BuiltInTypeKind.EntityType)
                                   from query in (meta as EntityType).Properties
                                   .Where(p => p.DeclaringType.Name == entityObject.GetType().Name)
                                   select query;

                if (queryResults.Count() > 0)
                {
                    foreach (var queryResult in queryResults.ToList())
                    {
                        Temp temp = new Temp();
                        temp.ID          = id;
                        temp.Name        = queryResult.Name.ToString();
                        temp.ShortChar_1 = queryResult.TypeUsage.EdmType.Name;
                        if (queryResult.TypeUsage.EdmType.Name == "String")
                        {
                            temp.Int_1 = Convert.ToInt32(queryResult.TypeUsage.Facets["MaxLength"].Value);
                        }
                        temp.Bool_1 = false; //we use this as a error trigger false = not an error...
                        tempList.Add(temp);
                        id++;
                    }
                }
            }
            return(tempList);
        }
 private void ChangeKeyLogic()
 {
     if (!string.IsNullOrEmpty(SelectedWarehouseCode.WarehouseCodeID))
     {//check to see if key is part of the current companylist...
         WarehouseCode query = WarehouseCodeList.Where(company => company.WarehouseCodeID == SelectedWarehouseCode.WarehouseCodeID &&
                                                       company.AutoID != SelectedWarehouseCode.AutoID).FirstOrDefault();
         if (query != null)
         {//revert it back...
             SelectedWarehouseCode.WarehouseCodeID = SelectedWarehouseCodeMirror.WarehouseCodeID;
             //change to the newly selected item...
             SelectedWarehouseCode = query;
             return;
         }
         //it is not part of the existing list try to fetch it from the db...
         WarehouseCodeList = GetWarehouseCodeByID(SelectedWarehouseCode.WarehouseCodeID, XERP.Client.ClientSessionSingleton.Instance.CompanyID);
         if (WarehouseCodeList.Count == 0)//it was not found do new record required logic...
         {
             NotifyNewRecordNeeded("Record " + SelectedWarehouseCode.WarehouseCodeID + " Does Not Exist.  Create A New Record?");
         }
         else
         {
             SelectedWarehouseCode = WarehouseCodeList.FirstOrDefault();
         }
     }
     else
     {
         string errorMessage = "ID Is Required.";
         NotifyMessage(errorMessage);
         //revert back to the value it was before it was changed...
         if (SelectedWarehouseCode.WarehouseCodeID != SelectedWarehouseCodeMirror.WarehouseCodeID)
         {
             SelectedWarehouseCode.WarehouseCodeID = SelectedWarehouseCodeMirror.WarehouseCodeID;
         }
     }
 }
Esempio n. 5
0
        public static string getReturnJson(string url)
        {
            StreamReader streamReader = null;
            string       Rstring      = "";

            try
            {
                HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
                request.Method = "GET";
                // request.Accept = "text/html, application/xhtml+xml, */*";
                request.ContentType = "application/json";
                request.Headers.Add("X-User", user);
                request.Headers.Add("X-DB", db);
                WarehouseCode warehouseCode = new WarehouseCode(warehouse);
                string        w             = JsonConvert.SerializeObject(warehouseCode);
                request.Headers.Add("x-params", w);
                WebResponse response = (WebResponse)request.GetResponse();
                streamReader = new StreamReader(response.GetResponseStream(), Encoding.UTF8);
                // XmlDocument doc = new XmlDocument();
                string s = streamReader.ReadToEnd();
                streamReader.Close();
                // doc.LoadXml(s);
                //  Rstring = JsonConvert.SerializeXmlNode(doc);
                Rstring = s;
            }
            catch (Exception ex)
            {
                LogExecute.WriteExceptionLog("GET", ex);
            }
            return(Rstring);
        }
Esempio n. 6
0
        public IEnumerable <WarehouseCode> GetWarehouseCodes(WarehouseCode itemCodeQuerryObject, string companyID)
        {
            _repositoryContext             = new WarehouseEntities(_rootUri);
            _repositoryContext.MergeOption = MergeOption.AppendOnly;
            _repositoryContext.IgnoreResourceNotFoundException = true;
            var queryResult = from q in _repositoryContext.WarehouseCodes
                              where q.CompanyID == companyID
                              select q;

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

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

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

            return(queryResult);
        }
        private void Refresh()
        {//refetch current records...
            long   selectedAutoID = SelectedWarehouseCode.AutoID;
            string autoIDs        = "";

            //bool isFirstItem = true;
            foreach (WarehouseCode itemCode in WarehouseCodeList)
            {//auto seeded starts at 1 any records at 0 or less or not valid records...
                if (itemCode.AutoID > 0)
                {
                    autoIDs = autoIDs + itemCode.AutoID.ToString() + ",";
                }
            }
            if (autoIDs.Length > 0)
            {
                //ditch the extra comma...
                autoIDs               = autoIDs.Remove(autoIDs.Length - 1, 1);
                WarehouseCodeList     = new BindingList <WarehouseCode>(_serviceAgent.RefreshWarehouseCode(autoIDs).ToList());
                SelectedWarehouseCode = (from q in WarehouseCodeList
                                         where q.AutoID == selectedAutoID
                                         select q).FirstOrDefault();
                Dirty       = false;
                AllowCommit = false;
            }
        }
        public void DeleteWarehouseCodeCommand()
        {
            try
            {//company is fk to 100's of tables deleting it can be tricky...
                int i  = 0;
                int ii = 0;
                for (int j = SelectedWarehouseCodeList.Count - 1; j >= 0; j--)
                {
                    WarehouseCode item = (WarehouseCode)SelectedWarehouseCodeList[j];
                    //get Max Index...
                    i = WarehouseCodeList.IndexOf(item);
                    if (i > ii)
                    {
                        ii = i;
                    }
                    Delete(item);
                    WarehouseCodeList.Remove(item);
                }

                if (WarehouseCodeList != null && WarehouseCodeList.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 >= WarehouseCodeList.Count())
                    {
                        ii = WarehouseCodeList.Count - 1;
                    }

                    SelectedWarehouseCode = WarehouseCodeList[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("WarehouseCode/s Can Not Be Deleted.  Contact XERP Admin For More Details.");
                Refresh();
            }
        }
        private BindingList <WarehouseCode> GetWarehouseCodes(WarehouseCode itemCode, string companyID)
        {
            BindingList <WarehouseCode> itemCodeList = new BindingList <WarehouseCode>(_serviceAgent.GetWarehouseCodes(itemCode, companyID).ToList());

            Dirty       = false;
            AllowCommit = false;
            return(itemCodeList);
        }
Esempio n. 10
0
 private void SetAsEmptySelection()
 {
     SelectedWarehouseCode = new WarehouseCode();
     AllowEdit             = false;
     AllowDelete           = false;
     Dirty        = false;
     AllowCommit  = false;
     AllowRowCopy = false;
 }
Esempio n. 11
0
        public static void SetPropertyValue(this WarehouseCode myObj, object propertyName, object propertyValue)
        {
            var propInfo = typeof(WarehouseCode).GetProperty((string)propertyName);

            if (propInfo != null)
            {
                propInfo.SetValue(myObj, propertyValue, null);
            }
        }
Esempio n. 12
0
 public void UpdateRepository(WarehouseCode itemCode)
 {
     if (_repositoryContext.GetEntityDescriptor(itemCode) != null)
     {
         itemCode.LastModifiedBy        = XERP.Client.ClientSessionSingleton.Instance.SystemUserID;
         itemCode.LastModifiedByDate    = DateTime.Now;
         _repositoryContext.MergeOption = MergeOption.AppendOnly;
         _repositoryContext.UpdateObject(itemCode);
     }
 }
Esempio n. 13
0
 public EntityStates GetWarehouseCodeEntityState(WarehouseCode itemCode)
 {
     if (_repositoryContext.GetEntityDescriptor(itemCode) != null)
     {
         return(_repositoryContext.GetEntityDescriptor(itemCode).State);
     }
     else
     {
         return(EntityStates.Detached);
     }
 }
Esempio n. 14
0
 private void OnSearchResult(object sender, NotificationEventArgs <BindingList <WarehouseCode> > e)
 {
     if (e.Data != null && e.Data.Count > 0)
     {
         WarehouseCodeList     = e.Data;
         SelectedWarehouseCode = WarehouseCodeList.FirstOrDefault();
         Dirty       = false;
         AllowCommit = false;
     }
     UnregisterToReceiveMessages <BindingList <WarehouseCode> >(MessageTokens.WarehouseCodeSearchToken.ToString(), OnSearchResult);
 }
Esempio n. 15
0
        public static string postReturnJson(string url, IDictionary <string, string> parameters)
        {
            StreamReader   streamReader = null;
            string         Rstring      = "";
            HttpWebRequest request      = (HttpWebRequest)WebRequest.Create(url);

            request.Method = "POST";
            // request.Accept = "text/html, application/xhtml+xml, */*";
            request.ContentType = "application/json";
            //request.ContentType = "application/x-www-form-urlencoded";
            WarehouseCode warehousecode = new WarehouseCode(warehouse);

            request.Headers.Add("X-User", user);
            request.Headers.Add("X-DB", db);
            request.Headers.Add("x-params", JsonToolEx.ToJson(warehousecode));
            //如果需要POST数据
            if (!(parameters == null || parameters.Count == 0))
            {
                StringBuilder buffer = new StringBuilder();
                int           i      = 0;
                foreach (string key in parameters.Keys)
                {
                    if (i > 0)
                    {
                        buffer.AppendFormat("&{0}={1}", key, parameters[key]);
                    }
                    else
                    {
                        buffer.AppendFormat("{0}={1}", key, parameters[key]);
                    }
                    i++;
                }
                byte[] data = Encoding.UTF8.GetBytes(buffer.ToString());
                using (Stream stream = request.GetRequestStream())
                {
                    stream.Write(data, 0, data.Length);
                    stream.Close();
                }
            }

            WebResponse response = (WebResponse)request.GetResponse();

            //  Stream myResponseStream = response.GetResponseStream();
            streamReader = new StreamReader(response.GetResponseStream(), Encoding.UTF8);
            XmlDocument doc = new XmlDocument();

            doc.LoadXml(streamReader.ReadToEnd());
            string str = JsonConvert.SerializeXmlNode(doc);

            Rstring = JsonConvert.SerializeXmlNode(doc);
            return(Rstring);
        }
Esempio n. 16
0
        public static object GetPropertyValue(this WarehouseCode myObj, string propertyName)
        {
            var propInfo = typeof(WarehouseCode).GetProperty(propertyName);

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

            if (propInfo != null)
            {
                return(propInfo.PropertyType.Name.ToString());
            }
            else
            {
                return(null);
            }
        }
Esempio n. 18
0
 public void OnChangeWarehouseTypes(WarehouseCode warehouseCode, UpdateOperations operations)
 {
     if (operations == UpdateOperations.Delete)
     {//update a null to any place the Code was used by its parent record...
         XERP.Server.DAL.WarehouseDAL.DALUtility dalUtility = new DALUtility();
         var context = new WarehouseEntities(dalUtility.EntityConectionString);
         context.Warehouses.MergeOption = System.Data.Objects.MergeOption.NoTracking;
         string companyID = warehouseCode.CompanyID;
         string codeID    = warehouseCode.WarehouseCodeID;
         string sqlstring = "UPDATE Warehouses SET WarehouseCodeID = null WHERE CompanyID = '" + companyID + "' and WarehouseCodeID = '" + codeID + "'";
         context.ExecuteStoreCommand(sqlstring);
     }
 }
Esempio n. 19
0
 //udpate merely updates the repository a commit is required
 //to commit it to the db...
 private bool Update(WarehouseCode item)
 {
     _serviceAgent.UpdateWarehouseCodeRepository(item);
     Dirty = true;
     if (CommitIsAllowed())
     {
         AllowCommit = true;
     }
     else
     {
         AllowCommit = false;
     }
     return(AllowCommit);
 }
Esempio n. 20
0
        private bool CheckMe(decimal?workerId)
        {
            if (!workerId.HasValue)
            {
                ShowMessage(string.Format("К пользователю '{0}' не привязан работник. Невозможно создать выполнение работы", WMSEnvironment.Instance.AuthenticatedUser.GetSignature()));
                return(false);
            }

            if (!OpenCloseInArgumentArgument.Get(_context))
            {
                return(true);
            }

            var workerFilter = string.Format("{0} = {1} and {2} = {3} and {4} is null"
                                             , Working.WORKERID_RPropertyName
                                             , workerId.Value
                                             , Working.WORKID_RPropertyName
                                             , CurrentWork.GetKey()
                                             , Working.WORKINGTILLPropertyName);

            var warehouseCode = WarehouseCode.Get(_context);
            var filter        = GetWorkersFilter(false); // в данном случае неважно, есть ли working

            filter += (!string.IsNullOrEmpty(filter) ? " and " : string.Empty) +
                      string.Format("(workerid = {0})", workerId);
            Worker[] items;
            using (var mgr = IoC.Instance.Resolve <IBaseManager <Worker> >())
                items = mgr.GetFiltered(filter, GetModeEnum.Partial).ToArray();
            if (items.Length == 0)
            {
                ShowMessage(
                    string.Format(
                        "Сотрудник (код '{0}') не существует или не привязан к складу (код '{1}') на даты работ",
                        workerId, warehouseCode));
                return(false);
            }

            using (var mgr = IoC.Instance.Resolve <IBaseManager <Working> >())
            {
                var workingItems = mgr.GetFiltered(workerFilter, GetModeEnum.Partial).ToArray();
                if (workingItems.Length > 0)
                {
                    var action = ShowMessage(string.Format("Сотрудник '{0}' уже выполняет работу (код '{1}'). Создать новую детализацию?", items.FirstOrDefault().WorkerFIO, CurrentWork.GetKey()), "Внимание!", MessageBoxButton.YesNo, MessageBoxImage.Warning);
                    return(action == MessageBoxResult.Yes);
                }
            }

            return(true);
        }
Esempio n. 21
0
        public CodeSearchViewModel(IWarehouseServiceAgent serviceAgent)
        {
            this._serviceAgent = serviceAgent;

            SearchObject = new WarehouseCode();
            ResultList   = new BindingList <WarehouseCode>();
            SelectedList = new BindingList <WarehouseCode>();
            //make sure of session authentication...
            if (XERP.Client.ClientSessionSingleton.Instance.SessionIsAuthentic)//make sure user has rights to UI...
            {
                DoFormsAuthentication();
            }
            else
            {//User is not authenticated...
                RegisterToReceiveMessages <bool>(MessageTokens.StartUpLogInToken.ToString(), OnStartUpLogIn);
                FormIsEnabled = false;
                //we will do forms authentication once the log in returns a valid System User...
            }
        }
Esempio n. 22
0
        public IQueryable <Temp> GetMetaData(string tableName)
        {
            switch (tableName)
            {
            case "Warehouses":
                Warehouse Warehouse = new Warehouse();
                return(Warehouse.GetMetaData().AsQueryable());

            case "WarehouseTypes":
                WarehouseType WarehouseType = new WarehouseType();
                return(WarehouseType.GetMetaData().AsQueryable());

            case "WarehouseCodes":
                WarehouseCode WarehouseCode = new WarehouseCode();
                return(WarehouseCode.GetMetaData().AsQueryable());

            case "WarehouseLocationBins":
                WarehouseLocationBin WarehouseLocationBin = new WarehouseLocationBin();
                return(WarehouseLocationBin.GetMetaData().AsQueryable());

            case "WarehouseLocationBinTypes":
                WarehouseLocationBinType WarehouseLocationBinType = new WarehouseLocationBinType();
                return(WarehouseLocationBinType.GetMetaData().AsQueryable());

            case "WarehouseLocationBinCodes":
                WarehouseLocationBinCode WarehouseLocationBinCode = new WarehouseLocationBinCode();
                return(WarehouseLocationBinCode.GetMetaData().AsQueryable());

            default:     //no table exists for the given tablename given...
                List <Temp> tempList = new List <Temp>();
                Temp        temp     = new Temp();
                temp.ID          = 0;
                temp.Int_1       = 0;
                temp.Bool_1      = true; //bool_1 will flag it as an error...
                temp.Name        = "Error";
                temp.ShortChar_1 = "Table " + tableName + " Is Not A Valid Table Within The Given Entity Collection, Or Meta Data Was Not Defined For The Given Table Name";
                tempList.Add(temp);
                return(tempList.AsQueryable());
            }
        }
Esempio n. 23
0
        //Object.Property Scope Validation...
        private bool WarehouseCodeIsValid(WarehouseCode item, _companyValidationProperties validationProperties, out string errorMessage)
        {
            errorMessage = "";
            switch (validationProperties)
            {
            case _companyValidationProperties.WarehouseCodeID:
                //validate key
                if (string.IsNullOrEmpty(item.WarehouseCodeID))
                {
                    errorMessage = "ID Is Required.";
                    return(false);
                }
                EntityStates entityState = GetWarehouseCodeState(item);
                if (entityState == EntityStates.Added && WarehouseCodeExists(item.WarehouseCodeID, ClientSessionSingleton.Instance.CompanyID))
                {
                    errorMessage = "Item All Ready Exists...";
                    return(false);
                }
                //check cached list for duplicates...
                int count = WarehouseCodeList.Count(q => q.WarehouseCodeID == item.WarehouseCodeID);
                if (count > 1)
                {
                    errorMessage = "Item All Ready Exists...";
                    return(false);
                }
                break;

            case _companyValidationProperties.Name:
                //validate Description
                if (string.IsNullOrEmpty(item.Description))
                {
                    errorMessage = "Description Is Required.";
                    return(false);
                }
                break;
            }
            return(true);
        }
Esempio n. 24
0
        private bool NewWarehouseCode(string id)
        {
            WarehouseCode item = new WarehouseCode();

            //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...
            _newWarehouseCodeAutoId = _newWarehouseCodeAutoId - 1;
            item.AutoID             = _newWarehouseCodeAutoId;
            item.WarehouseCodeID    = id;
            item.CompanyID          = ClientSessionSingleton.Instance.CompanyID;
            item.IsValid            = 1;
            item.NotValidMessage    = "New Record Key Field/s Are Required.";
            WarehouseCodeList.Add(item);
            _serviceAgent.AddToWarehouseCodeRepository(item);
            SelectedWarehouseCode = WarehouseCodeList.LastOrDefault();

            AllowEdit = true;
            Dirty     = false;
            return(true);
        }
Esempio n. 25
0
 public EntityStates GetWarehouseCodeEntityState(WarehouseCode itemCode)
 {
     return(WarehouseCodeSingletonRepository.Instance.GetWarehouseCodeEntityState(itemCode));
 }
Esempio n. 26
0
 private BindingList <WarehouseCode> GetWarehouseCodes(WarehouseCode itemQueryObject, string companyID)
 {
     return(new BindingList <WarehouseCode>(_serviceAgent.GetWarehouseCodes(itemQueryObject, companyID).ToList()));
 }
Esempio n. 27
0
 private EntityStates GetWarehouseCodeState(WarehouseCode itemCode)
 {
     return(_serviceAgent.GetWarehouseCodeEntityState(itemCode));
 }
Esempio n. 28
0
 public void AddToRepository(WarehouseCode itemCode)
 {
     _repositoryContext.MergeOption = MergeOption.AppendOnly;
     _repositoryContext.AddToWarehouseCodes(itemCode);
 }
Esempio n. 29
0
 private bool Delete(WarehouseCode itemCode)
 {
     _serviceAgent.DeleteFromWarehouseCodeRepository(itemCode);
     return(true);
 }
Esempio n. 30
0
 private string GetWorkersFilter(bool freeOnly)
 {
     return(RclShowWorkManageActivity.GetWorkersFilter(CurrentWork.GetKey <decimal?>(), WarehouseCode.Get(_context), freeOnly));
 }