public static List <Temp> GetMetaData(this PlantCode entityObject) { XERP.Server.DAL.PlantDAL.DALUtility dalUtility = new DALUtility(); List <Temp> tempList = new List <Temp>(); int id = 0; using (PlantEntities ctx = new PlantEntities(dalUtility.EntityConectionString)) { var c = ctx.PlantCodes.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(SelectedPlantCode.PlantCodeID)) {//check to see if key is part of the current companylist... PlantCode query = PlantCodeList.Where(company => company.PlantCodeID == SelectedPlantCode.PlantCodeID && company.AutoID != SelectedPlantCode.AutoID).FirstOrDefault(); if (query != null) {//revert it back... SelectedPlantCode.PlantCodeID = SelectedPlantCodeMirror.PlantCodeID; //change to the newly selected item... SelectedPlantCode = query; return; } //it is not part of the existing list try to fetch it from the db... PlantCodeList = GetPlantCodeByID(SelectedPlantCode.PlantCodeID, XERP.Client.ClientSessionSingleton.Instance.CompanyID); if (PlantCodeList.Count == 0)//it was not found do new record required logic... NotifyNewRecordNeeded("Record " + SelectedPlantCode.PlantCodeID + " Does Not Exist. Create A New Record?"); else SelectedPlantCode = PlantCodeList.FirstOrDefault(); } else { string errorMessage = "ID Is Required."; NotifyMessage(errorMessage); //revert back to the value it was before it was changed... if (SelectedPlantCode.PlantCodeID != SelectedPlantCodeMirror.PlantCodeID) SelectedPlantCode.PlantCodeID = SelectedPlantCodeMirror.PlantCodeID; } }
public IQueryable <Temp> GetMetaData(string tableName) { switch (tableName) { case "Plants": Plant Plant = new Plant(); return(Plant.GetMetaData().AsQueryable()); case "PlantTypes": PlantType PlantType = new PlantType(); return(PlantType.GetMetaData().AsQueryable()); case "PlantCodes": PlantCode PlantCode = new PlantCode(); return(PlantCode.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()); } }
public IEnumerable <PlantCode> GetPlantCodes(PlantCode itemCodeQuerryObject, string companyID) { _repositoryContext = new PlantEntities(_rootUri); _repositoryContext.MergeOption = MergeOption.AppendOnly; _repositoryContext.IgnoreResourceNotFoundException = true; var queryResult = from q in _repositoryContext.PlantCodes 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.PlantCodeID)) { queryResult = queryResult.Where(q => q.Description.StartsWith(itemCodeQuerryObject.PlantCodeID.ToString())); } return(queryResult); }
public void DeleteFromRepository(PlantCode itemCode) { if (_repositoryContext.GetEntityDescriptor(itemCode) != null) {//if it exists in the db delete it from the db PlantEntities context = new PlantEntities(_rootUri); context.MergeOption = MergeOption.AppendOnly; context.IgnoreResourceNotFoundException = true; PlantCode deletedPlantCode = (from q in context.PlantCodes where q.PlantCodeID == itemCode.PlantCodeID select q).FirstOrDefault(); if (deletedPlantCode != null) { context.DeleteObject(deletedPlantCode); context.SaveChanges(); } context = null; _repositoryContext.MergeOption = MergeOption.AppendOnly; //if it is being tracked remove it... if (GetPlantCodeEntityState(itemCode) != EntityStates.Detached) { _repositoryContext.Detach(itemCode); } } }
private BindingList<PlantCode> GetPlantCodes(PlantCode itemCode, string companyID) { BindingList<PlantCode> itemCodeList = new BindingList<PlantCode>(_serviceAgent.GetPlantCodes(itemCode, companyID).ToList()); Dirty = false; AllowCommit = false; return itemCodeList; }
//PlantCode Object Scope Validation check the entire object for validity... private byte PlantCodeIsValid(PlantCode item, out string errorMessage) { //validate key errorMessage = ""; if (string.IsNullOrEmpty(item.PlantCodeID)) { errorMessage = "ID Is Required."; return 1; } EntityStates entityState = GetPlantCodeState(item); if (entityState == EntityStates.Added && PlantCodeExists(item.PlantCodeID, ClientSessionSingleton.Instance.CompanyID)) { errorMessage = "Item AllReady Exists."; return 1; } //check cached list for duplicates... int count = PlantCodeList.Count(q => q.PlantCodeID == item.PlantCodeID); 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; }
public static object GetPropertyValue(this PlantCode myObj, string propertyName) { var propInfo = typeof(PlantCode).GetProperty(propertyName); if (propInfo != null) return propInfo.GetValue(myObj, null); else return string.Empty; }
public static string GetPropertyCode(this PlantCode myObj, string propertyName) { var propInfo = typeof(PlantCode).GetProperty(propertyName); if (propInfo != null) return propInfo.PropertyType.Name.ToString(); else return null; }
private void SetAsEmptySelection() { SelectedPlantCode = new PlantCode(); AllowEdit = false; AllowDelete = false; Dirty = false; AllowCommit = false; AllowRowCopy = false; }
//udpate merely updates the repository a commit is required //to commit it to the db... private bool Update(PlantCode item) { _serviceAgent.UpdatePlantCodeRepository(item); Dirty = true; if (CommitIsAllowed()) AllowCommit = true; else AllowCommit = false; return AllowCommit; }
public void UpdateRepository(PlantCode itemCode) { if (_repositoryContext.GetEntityDescriptor(itemCode) != null) { itemCode.LastModifiedBy = XERP.Client.ClientSessionSingleton.Instance.SystemUserID; itemCode.LastModifiedByDate = DateTime.Now; _repositoryContext.MergeOption = MergeOption.AppendOnly; _repositoryContext.UpdateObject(itemCode); } }
public EntityStates GetPlantCodeEntityState(PlantCode itemCode) { if (_repositoryContext.GetEntityDescriptor(itemCode) != null) { return(_repositoryContext.GetEntityDescriptor(itemCode).State); } else { return(EntityStates.Detached); } }
private void OnSearchResult(object sender, NotificationEventArgs<BindingList<PlantCode>> e) { if (e.Data != null && e.Data.Count > 0) { PlantCodeList = e.Data; SelectedPlantCode = PlantCodeList.FirstOrDefault(); Dirty = false; AllowCommit = false; } UnregisterToReceiveMessages<BindingList<PlantCode>>(MessageTokens.PlantCodeSearchToken.ToString(), OnSearchResult); }
public override int GetHashCode() { // Get the hash code for the Name field if it is not null. int hashProductName = PlantName == null ? 0 : PlantName.GetHashCode(); // Get the hash code for the Code field. int hashProductCode = PlantCode.GetHashCode(); // Calculate the hash code for the product. return(hashProductName ^ hashProductCode); }
public void OnChangePlantTypes(PlantCode PlantCode, UpdateOperations operations) { if (operations == UpdateOperations.Delete) {//update a null to any place the Code was used by its parent record... XERP.Server.DAL.PlantDAL.DALUtility dalUtility = new DALUtility(); var context = new PlantEntities(dalUtility.EntityConectionString); context.Plants.MergeOption = System.Data.Objects.MergeOption.NoTracking; string companyID = PlantCode.CompanyID; string codeID = PlantCode.PlantCodeID; string sqlstring = "UPDATE Plants SET PlantCodeID = null WHERE CompanyID = '" + companyID + "' and PlantCodeID = '" + codeID + "'"; context.ExecuteStoreCommand(sqlstring); } }
private void AddCommand(string command, string unlessFollowing = null) { // add the command unless the last thing on the list is the second parameter // if it is, remove that entry and don't add the command if (unlessFollowing != null && PlantCode.LastOrDefault() == unlessFollowing) { PlantCode.RemoveAt(PlantCode.Count - 1); return; } Debug.WriteLine("----------------------------------"); Debug.WriteLine(currentTitle); Debug.WriteLine(" " + command); PlantCode.Add(command); }
public void DeletePlantCodeCommand() { try {//company is fk to 100's of tables deleting it can be tricky... int i = 0; int ii = 0; for (int j = SelectedPlantCodeList.Count - 1; j >= 0; j--) { PlantCode item = (PlantCode)SelectedPlantCodeList[j]; //get Max Index... i = PlantCodeList.IndexOf(item); if (i > ii) ii = i; Delete(item); PlantCodeList.Remove(item); } if (PlantCodeList != null && PlantCodeList.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 >= PlantCodeList.Count()) ii = PlantCodeList.Count - 1; SelectedPlantCode = PlantCodeList[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("PlantCode/s Can Not Be Deleted. Contact XERP Admin For More Details."); Refresh(); } }
public bool Equals(Plant p) { // Check whether the compared object is null. if (Object.ReferenceEquals(p, null)) { return(false); } // Check whether the compared object references the same data. if (Object.ReferenceEquals(this, p)) { return(true); } // Check whether the products' properties are equal. return(PlantCode.Equals(p.PlantCode) && PlantName.Equals(p.PlantName)); }
public CodeSearchViewModel(IPlantServiceAgent serviceAgent) { this._serviceAgent = serviceAgent; SearchObject = new PlantCode(); ResultList = new BindingList <PlantCode>(); SelectedList = new BindingList <PlantCode>(); //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... } }
private void Refresh() {//refetch current records... long selectedAutoID = SelectedPlantCode.AutoID; string autoIDs = ""; //bool isFirstItem = true; foreach (PlantCode itemCode in PlantCodeList) {//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); PlantCodeList = new BindingList<PlantCode>(_serviceAgent.RefreshPlantCode(autoIDs).ToList()); SelectedPlantCode = (from q in PlantCodeList where q.AutoID == selectedAutoID select q).FirstOrDefault(); Dirty = false; AllowCommit = false; } }
private void DeletePlant_Click(object sender, EventArgs e) { // Prompt the user if they're sure about deleting the record var m = (Machine)Machines.Current; var message = string.Format("Are you sure you want to delete the following record\n{0}\n{1}\n{2}\n{3}\n{4}\n{5}", m.Code, m.DetailLn1, m.DetailLn2, m.DetailLn3, m.DetailLn4, m.DetailLn5); var result = MessageBox.Show(message, "Delete record", MessageBoxButtons.YesNo, MessageBoxIcon.Error); // Check the user's response if (result == DialogResult.Yes) { // Temporarily unbind BindingSource from DataGridView DataSource MachineDataGridView.DataSource = null; // Remove the item from the binding source Machines.Remove(m); // Rebind BindinSgource to DataGridView DataSource MachineDataGridView.DataSource = Machines; // Save the change to file UpdateCsvFile <Machine>(((SortableBindingList <Machine>)Machines.DataSource).ToList(), PlantCsvPath); // Refocus on the Code ComboBox PlantCode.Select(); } }
private bool NewPlantCode(string id) { PlantCode item = new PlantCode(); //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... _newPlantCodeAutoId = _newPlantCodeAutoId - 1; item.AutoID = _newPlantCodeAutoId; item.PlantCodeID = id; item.CompanyID = ClientSessionSingleton.Instance.CompanyID; item.IsValid = 1; item.NotValidMessage = "New Record Key Field/s Are Required."; PlantCodeList.Add(item); _serviceAgent.AddToPlantCodeRepository(item); SelectedPlantCode = PlantCodeList.LastOrDefault(); AllowEdit = true; Dirty = false; return true; }
//Object.Property Scope Validation... private bool PlantCodeIsValid(PlantCode item, _companyValidationProperties validationProperties, out string errorMessage) { errorMessage = ""; switch (validationProperties) { case _companyValidationProperties.PlantCodeID: //validate key if (string.IsNullOrEmpty(item.PlantCodeID)) { errorMessage = "ID Is Required."; return false; } EntityStates entityState = GetPlantCodeState(item); if (entityState == EntityStates.Added && PlantCodeExists(item.PlantCodeID, ClientSessionSingleton.Instance.CompanyID)) { errorMessage = "Item All Ready Exists..."; return false; } //check cached list for duplicates... int count = PlantCodeList.Count(q => q.PlantCodeID == item.PlantCodeID); 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; }
public EntityStates GetPlantCodeEntityState(PlantCode itemCode) { return(PlantCodeSingletonRepository.Instance.GetPlantCodeEntityState(itemCode)); }
public void DeleteFromPlantCodeRepository(PlantCode itemCode) { PlantCodeSingletonRepository.Instance.DeleteFromRepository(itemCode); }
public void AddToPlantCodeRepository(PlantCode itemCode) { PlantCodeSingletonRepository.Instance.AddToRepository(itemCode); }
public void UpdatePlantCodeRepository(PlantCode itemCode) { PlantCodeSingletonRepository.Instance.UpdateRepository(itemCode); }
public IEnumerable <PlantCode> GetPlantCodes(PlantCode itemCodeQuerryObject, string companyID) { return(PlantCodeSingletonRepository.Instance.GetPlantCodes(itemCodeQuerryObject, companyID)); }
public static void SetPropertyValue(this PlantCode myObj, object propertyName, object propertyValue) { var propInfo = typeof(PlantCode).GetProperty((string)propertyName); if (propInfo != null) propInfo.SetValue(myObj, propertyValue, null); }