private void SaveAs(bool onlyUpdate) { if (Templates.Current != null) { BqlCommand command = BqlCommand.CreateInstance(typeof(Select <CRFilterTemplate, Where <CRFilterTemplate.name, Equal <Current <CRFilterTemplate.name> >, And <CRFilterTemplate.graphType, Equal <Required <CRFilterTemplate.graphType> > > > >)); CRFilterTemplate templateToUpdate = (new PXView(this, true, command)).SelectSingle(graphTypeName) as CRFilterTemplate; if (onlyUpdate && templateToUpdate == null) { return; } if (templateToUpdate == null) { InsertNewTemplate(); } else { UpdateExistingTemplate(templateToUpdate); } CorrectGraphType(); CorrectDefaultValues(); SafetyPersist(Templates.Cache, PXDBOperation.Insert, PXDBOperation.Update); SafetyPersist(Filters.Cache, PXDBOperation.Delete, PXDBOperation.Insert, PXDBOperation.Update); Filters.Cache.Clear(); Templates.Cache.Clear(); Templates.View.RequestRefresh(); } }
private void LoadTemplates(string graphTypeName) { templates.Clear(); if (!string.IsNullOrEmpty(graphTypeName)) { CRFilterTemplate currentTemplate; try { foreach (PXDataRecord item in PXDatabase.SelectMulti <CRFilterTemplate>( new PXDataField("FilterTemplateID"), new PXDataField("Name"), new PXDataFieldValue("GraphType", PXDbType.NVarChar, 255, graphTypeName, PXComp.EQ))) { currentTemplate = new CRFilterTemplate(); currentTemplate.FilterTemplateID = (int?)item["FilterTemplateID"]; currentTemplate.Name = item["Name"].ToString(); templates.Add(currentTemplate); } } catch (ExecutionEngineException) { throw; } catch (OutOfMemoryException) { throw; } catch (StackOverflowException) { throw; } catch (Exception) { templates.Clear(); } } }
public virtual void CRFilterTemplate_Name_FieldVarifying(PXCache cache, PXFieldVerifyingEventArgs e) { CRFilterTemplate row = e.Row as CRFilterTemplate; if (row != null && GetExistingTemplateNames().Contains(Convert.ToString(e.NewValue))) { throw new PXSetPropertyException(Messages.TemplateDublicateError); } }
private void UpdateExistingTemplate(CRFilterTemplate templateToUpdate) { if (Templates.Current.FilterTemplateID < 0 || Templates.Current.FilterTemplateID != templateToUpdate.FilterTemplateID) { CopyTemplate(Templates.Current, templateToUpdate); Templates.Cache.SetStatus(Templates.Current, PXEntryStatus.Notchanged); Templates.Current = templateToUpdate; Templates.Update(templateToUpdate); } }
private void InsertNewTemplate() { if (Templates.Cache.GetStatus(Templates.Current) != PXEntryStatus.Inserted) { Templates.Cache.SetStatus(Templates.Current, PXEntryStatus.Notchanged); CRFilterTemplate newTemplate = new CRFilterTemplate(); CopyTemplate(Templates.Current, newTemplate); CRFilterItem newItem; PXEntryStatus itemStatus; foreach (CRFilterItem item in Filters.Select()) { itemStatus = Filters.Cache.GetStatus(item); if (itemStatus == PXEntryStatus.Notchanged || itemStatus == PXEntryStatus.Inserted || itemStatus == PXEntryStatus.Updated) { newItem = Filters.Insert(new CRFilterItem()); CopyFilterItem(item, newItem); } Filters.Cache.SetStatus(item, PXEntryStatus.Notchanged); } Templates.Insert(newTemplate); } }
//public virtual IEnumerable items() //{ // Hashtable hashTable = new Hashtable(); // foreach (object item in Items.Cache.Updated) // { // hashTable.Add(GetKeyValue(item), item); // yield return item; // } // foreach (object item in Items.Cache.Inserted) // { // hashTable.Add(GetKeyValue(item), item); // yield return item; // } // PXView view = new PXView(this, true, Items.View.BqlSelect); // object row; // foreach (object item in SelectItems(view)) // { // row = item is PXResult ? ((PXResult)item)[selectTable] : item; // if (!hashTable.Contains(GetKeyValue(row))) // yield return item; // } // if (hashTable.Count < 1) Items.Cache.IsDirty = false; //} public override IEnumerable ExecuteSelect(string viewName, object[] parameters, object[] searches, string[] sortcolumns, bool[] descendings, PXFilterRow[] filters, ref int startRow, int maximumRows, ref int totalRows) { if (searches != null && searches.Length > 0 && searches[0] != null) { if (viewName == "Templates") { TemplatesSecond.Current = TemplatesSecond.Search <CRFilterTemplate1.filterTemplateID>(searches[0]); } if (viewName == "TemplatesSecond") { Templates.Current = Templates.Search <CRFilterTemplate.filterTemplateID>(searches[0]); } } CRFilterTemplate current = Templates.Current; CRFilterTemplate1 current1 = TemplatesSecond.Current; IEnumerable result = base.ExecuteSelect(viewName, parameters, searches, sortcolumns, descendings, filters, ref startRow, maximumRows, ref totalRows); if (viewName == "Templates" || viewName == "TemplatesSecond") { startRow = 0; if (maximumRows != 1) { if (viewName == "Templates") { Templates.Current = current; } if (viewName == "TemplatesSecond") { TemplatesSecond.Current = current1; } } } return(result); }
private void CopyTemplate(CRFilterTemplate source, CRFilterTemplate target) { target.Name = source.Name; target.IsDefault = source.IsDefault; target.IsShared = source.IsShared; }