示例#1
0
        public override void ProccessItem(PXGraph graph, TPrimary item)
        {
            PXCache  cache   = graph.Caches[typeof(TPrimary)];
            TPrimary newItem = (TPrimary)cache.CreateInstance();

            PXCache <TPrimary> .RestoreCopy(newItem, item);

            string entityType = CSAnswerType.GetAnswerType(cache.GetItemType());
            string entityID   = CSAnswerType.GetEntityID(cache.GetItemType());

            PXView primaryView = graph.Views[graph.PrimaryView];

            object[] searches    = new object[primaryView.Cache.BqlKeys.Count];
            string[] sortcolumns = new string[primaryView.Cache.BqlKeys.Count];
            for (int i = 0; i < cache.BqlKeys.Count(); i++)
            {
                sortcolumns[i] = cache.BqlKeys[i].Name;
                searches[i]    = cache.GetValue(newItem, sortcolumns[i]);
            }
            int startRow = 0, totalRows = 0;

            List <object> result = primaryView.Select(null, null, searches, sortcolumns, null, null, ref startRow, 1, ref totalRows);

            newItem = (TPrimary)cache.CreateCopy(PXResult.Unwrap <TPrimary>(result[0]));

            foreach (FieldValue fieldValue in Fields.Cache.Cached.Cast <FieldValue>().Where(o => o.AttributeID == null && o.Selected == true))
            {
                PXFieldState  state    = cache.GetStateExt(newItem, fieldValue.Name) as PXFieldState;
                PXIntState    intState = state as PXIntState;
                PXStringState strState = state as PXStringState;
                if ((intState != null && intState.AllowedValues != null && intState.AllowedValues.Length > 0 &&
                     intState.AllowedValues.All(v => v != int.Parse(fieldValue.Value)))
                    ||
                    (strState != null && strState.AllowedValues != null && strState.AllowedValues.Length > 0 &&
                     strState.AllowedValues.All(v => v != fieldValue.Value)))
                {
                    throw new PXSetPropertyException(ErrorMessages.UnallowedListValue, fieldValue.Value, fieldValue.Name);
                }
                if (state != null && !Equals(state.Value, fieldValue.Value))
                {
                    cache.SetValueExt(newItem, fieldValue.Name, fieldValue.Value);
                    cache.Update(newItem);
                }

                result  = primaryView.Select(null, null, searches, sortcolumns, null, null, ref startRow, 1, ref totalRows);
                newItem = (TPrimary)cache.CreateCopy(PXResult.Unwrap <TPrimary>(result[0]));
            }

            PXCache attrCache = cache.Graph.Caches[typeof(CSAnswers)];

            foreach (FieldValue attrValue in Attributes.Cache.Cached.Cast <FieldValue>().Where(o => o.AttributeID != null && o.Selected == true))
            {
                CSAnswers attr = (CSAnswers)attrCache.CreateInstance();
                attr.AttributeID = attrValue.AttributeID;
                attr.EntityID    = cache.GetValue(newItem, entityID) as int?;
                attr.EntityType  = entityType;
                attr.Value       = attrValue.Value;
                attrCache.Update(attr);
            }
        }
示例#2
0
        public virtual void dataSourceFieldSelecting(PXFieldSelectingEventArgs e, string field)
        {
            RMReport report = (RMReport)e.Row;

            if (report != null && report.Type == RMType.GL && field.Equals(typeof(RMDataSource.amountType).Name, StringComparison.InvariantCultureIgnoreCase))
            {
                e.ReturnState = PXIntState.CreateInstance(e.ReturnValue, field, false, 0, null, null,
                                                          new int[] { BalanceType.NotSet, BalanceType.Turnover, BalanceType.Credit, BalanceType.Debit, BalanceType.BeginningBalance, BalanceType.EndingBalance,
                                                                      BalanceType.CuryTurnover, BalanceType.CuryCredit, BalanceType.CuryDebit, BalanceType.CuryBeginningBalance, BalanceType.CuryEndingBalance },
                                                          new string[]
                {
                    Messages.GetLocal(Messages.NotSet),
                    Messages.GetLocal(Messages.Turnover),
                    Messages.GetLocal(Messages.Credit),
                    Messages.GetLocal(Messages.Debit),
                    Messages.GetLocal(Messages.BegBalance),
                    Messages.GetLocal(Messages.EndingBalance),
                    Messages.GetLocal(Messages.CuryTurnover),
                    Messages.GetLocal(Messages.CuryCredit),
                    Messages.GetLocal(Messages.CuryDebit),
                    Messages.GetLocal(Messages.CuryBegBalance),
                    Messages.GetLocal(Messages.CuryEndingBalance),
                },
                                                          typeof(short), BalanceType.NotSet);
                ((PXFieldState)e.ReturnState).DisplayName = Messages.GetLocal(Messages.AmountType);
            }
        }
示例#3
0
    protected void Page_Load(object sender, EventArgs e)
    {
        EventTaskCategoryMaint categoryMaint = PXGraph.CreateInstance <EventTaskCategoryMaint>();

        RegisterStyle("CssOverdue", null, "Red", false);
        RegisterStyle("CssOverdueBold", null, "Red", true);
        RegisterStyle("BaseBold", null, null, true);

        coloredCategories = new Set <int>(true);
        foreach (EPEventCategory rec in categoryMaint.ColoredCategories.Select())
        {
            PXIntState color = categoryMaint.ColoredCategories.Cache.GetStateExt(rec, "Color") as PXIntState;
            if (color != null)
            {
                coloredCategories.Add(rec.CategoryID ?? 0);
                int colorIndex = color.AllowedValues != null?Array.IndexOf(color.AllowedValues, (int)color.Value) : -1;

                string backColor = (colorIndex > 0)
                    ? color.AllowedLabels[colorIndex]
                    : color.Value.ToString();

                RegisterStyle("Css" + rec.CategoryID, backColor, null, false);
                RegisterStyle("CssBold" + rec.CategoryID, backColor, null, true);
                RegisterStyle("CssOver" + rec.CategoryID, backColor, "Red", false);
                RegisterStyle("CssBoldOver" + rec.CategoryID, backColor, "Red", true);
            }
        }
    }
示例#4
0
        //From PX.Api.OData.Model.GIDataService
        public static object UnwrapValue(object value)
        {
            PXFieldState state = value as PXFieldState;

            if (state != null)
            {
                if (state.Value == null && state.DefaultValue != null) // for a case when field has PXDefault attribute, but null value because of inconsistency in DB
                {
                    state.Value = state.DefaultValue;
                }
                if (state.Value != null && !state.DataType.IsInstanceOfType(state.Value)) // for a case when, for example, some field of int type has PXSelectorAttribute with substitute field of string type, and PXSelectorAttribute can't find corresponding row for substitute field
                {
                    state.Value = Convert.ChangeType(state.Value, state.DataType);
                }
            }

            PXStringState strState = value as PXStringState;

            if (strState != null && strState.Value != null && strState.ValueLabelDic != null && strState.ValueLabelDic.ContainsKey((string)strState.Value))
            {
                return(strState.ValueLabelDic[(string)strState.Value]);
            }
            PXIntState intState = value as PXIntState;

            if (intState != null && intState.Value != null && intState.ValueLabelDic != null)
            {
                return(intState.ValueLabelDic.ContainsKey((int)intState.Value) ? intState.ValueLabelDic[(int)intState.Value] : intState.Value.ToString());
            }
            return(PXFieldState.UnwrapValue(value));
        }
示例#5
0
        public virtual void dataSourceFieldSelecting(PXFieldSelectingEventArgs e, string field)
        {
            RMReport     report     = (RMReport)e.Row;
            RMDataSource dataSource = report != null?Base.DataSourceByID.Select(report.DataSourceID) : null;

            if (dataSource == null)
            {
                object defValue;
                if (Base.DataSourceByID.Cache.RaiseFieldDefaulting(field, null, out defValue))
                {
                    Base.DataSourceByID.Cache.RaiseFieldUpdating(field, null, ref defValue);
                }
                Base.DataSourceByID.Cache.RaiseFieldSelecting(field, null, ref defValue, true);
                e.ReturnState = defValue;
            }
            else
            {
                e.ReturnState = Base.DataSourceByID.Cache.GetStateExt(dataSource, field);
            }

            //Fix AmountType Combo for PM:
            if (report != null && report.Type == RMType.PM && field.Equals(typeof(RMDataSource.amountType).Name, StringComparison.InvariantCultureIgnoreCase))
            {
                e.ReturnState = PXIntState.CreateInstance(e.ReturnValue, field, false, 0, null, null,
                                                          new int[] { BalanceType.NotSet, BalanceType.Amount, BalanceType.Quantity, BalanceType.TurnoverAmount, BalanceType.TurnoverQuantity, BalanceType.BudgetAmount, BalanceType.BudgetQuantity, BalanceType.RevisedAmount, BalanceType.RevisedQuantity, BalanceType.OriginalCommittedAmount, BalanceType.OriginalCommittedQuantity, BalanceType.CommittedAmount, BalanceType.CommittedQuantity, BalanceType.CommittedOpenAmount, BalanceType.CommittedOpenQuantity, BalanceType.CommittedReceivedQuantity, BalanceType.CommittedInvoicedAmount, BalanceType.CommittedInvoicedQuantity },
                                                          new string[]
                {
                    Messages.GetLocal(Messages.NotSet),
                    Messages.GetLocal(Messages.ActualAmount),
                    Messages.GetLocal(Messages.ActualQuantity),
                    Messages.GetLocal(Messages.AmountTurnover),
                    Messages.GetLocal(Messages.QuantityTurnover),
                    Messages.GetLocal(Messages.BudgetAmount),
                    Messages.GetLocal(Messages.BudgetQuantity),
                    Messages.GetLocal(Messages.RevisedAmount),
                    Messages.GetLocal(Messages.RevisedQuantity),
                    Messages.GetLocal(Messages.OriginalCommittedAmount),
                    Messages.GetLocal(Messages.OriginalCommittedQuantity),
                    Messages.GetLocal(Messages.CommittedAmount),
                    Messages.GetLocal(Messages.CommittedQuantity),
                    Messages.GetLocal(Messages.CommittedOpenAmount),
                    Messages.GetLocal(Messages.CommittedOpenQuantity),
                    Messages.GetLocal(Messages.CommittedReceivedQuantity),
                    Messages.GetLocal(Messages.CommittedInvoicedAmount),
                    Messages.GetLocal(Messages.CommittedInvoicedQuantity)
                },
                                                          typeof(short), 0);
                ((PXFieldState)e.ReturnState).DisplayName = Messages.GetLocal(Messages.AmountType);
            }

            Base1.dataSourceFieldSelecting(e, field);

            if (e.ReturnState is PXFieldState)
            {
                ((PXFieldState)e.ReturnState).SetFieldName("DataSource" + field);
                ((PXFieldState)e.ReturnState).Visible = Base.IsFieldVisible(field, report);
            }
        }
示例#6
0
        protected virtual void PMRateSequence_Sequence_FieldSelecting(PXCache sender, PXFieldSelectingEventArgs e)
        {
            PXSelectBase <PMRateDefinition> select = new PXSelect <PMRateDefinition, Where <PMRateDefinition.rateTableID, Equal <Current <PMRateSequence.rateTableID> >,
                                                                                            And <PMRateDefinition.rateTypeID, Equal <Current <PMRateSequence.rateTypeID> > > >, OrderBy <Asc <PMRateDefinition.sequence> > >(this);

            List <string> labels = new List <string>();
            List <int>    values = new List <int>();

            int? retValue   = (int?)e.ReturnValue;
            bool valueValid = false;

            foreach (PMRateDefinition rd in select.Select())
            {
                string description = string.Format("{0} - [ ", rd.Sequence);
                if (rd.Project == true)
                {
                    description = description + PXMessages.LocalizeNoPrefix(Messages.Project) + "  ";
                }
                if (rd.Task == true)
                {
                    description = description + PXMessages.LocalizeNoPrefix(Messages.Task) + "  ";
                }
                if (rd.AccountGroup == true)
                {
                    description = description + PXMessages.LocalizeNoPrefix(Messages.AccountGroup) + "  ";
                }
                if (rd.RateItem == true)
                {
                    description = description + PXMessages.LocalizeNoPrefix(Messages.Item) + "  ";
                }
                if (rd.Employee == true)
                {
                    description = description + PXMessages.LocalizeNoPrefix(EP.Messages.Employee) + "  ";
                }


                description = description + "] " + rd.Description;

                if (retValue != null && retValue.Value == rd.Sequence.Value)
                {
                    valueValid = true;
                }

                labels.Add(description);
                values.Add(Convert.ToInt32(rd.Sequence.Value));
            }


            if (!valueValid && values.Count > 0)
            {
                e.ReturnValue = values[0];
            }

            e.ReturnState = PXIntState.CreateInstance(e.ReturnState, "Sequence", false, 1, null, null,
                                                      values.ToArray(), labels.ToArray(), null, null);
        }
        protected virtual void CRFixedFilterRow_Condition_FieldSelecting(PXCache cache, PXFieldSelectingEventArgs e)
        {
            string[] labels = null;
            int[]    values = null;
            var      row    = e.Row as CRFixedFilterRow;

            if (row != null)
            {
                GetConditions(row.DataField, out values, out labels);
            }
            string[] localizedLabels = LocalizeFilterConditionLabels(labels);
            e.ReturnState = PXIntState.CreateInstance(row == null ? null : row.Condition, typeof(CRFixedFilterRow.condition).Name, false, null, null, null, values, localizedLabels, null, null);
        }
示例#8
0
        protected virtual void PMRateSequence_Sequence_FieldSelecting(PXCache sender, PXFieldSelectingEventArgs e)
        {
            PXSelectBase <PMRateDefinition> select = new PXSelect <PMRateDefinition, Where <PMRateDefinition.rateTableID, Equal <Current <PMRateSequence.rateTableID> >,
                                                                                            And <PMRateDefinition.rateTypeID, Equal <Current <PMRateSequence.rateTypeID> > > >, OrderBy <Asc <PMRateDefinition.sequence> > >(this);

            List <string> labels = new List <string>();
            List <int>    values = new List <int>();

            labels.Add(" ");
            values.Add(0);

            foreach (PMRateDefinition rd in select.Select())
            {
                string description = string.Format("{0} - [ ", rd.Sequence);
                if (rd.Project == true)
                {
                    description = description + "Project  ";
                }
                if (rd.Task == true)
                {
                    description = description + "Task  ";
                }
                if (rd.AccountGroup == true)
                {
                    description = description + "AccountGroup  ";
                }
                if (rd.RateItem == true)
                {
                    description = description + "Item ";
                }
                if (rd.Employee == true)
                {
                    description = description + "Employee ";
                }


                description = description + "] " + rd.Description;



                labels.Add(description);
                values.Add(Convert.ToInt32(rd.Sequence.Value));
            }

            e.ReturnState = PXIntState.CreateInstance(e.ReturnState, "Sequence", false, 1, null, null,
                                                      values.ToArray(), labels.ToArray(), null, null);
        }
        public virtual void dataSourceFieldSelecting(PXFieldSelectingEventArgs e, string field)
        {
            RMReport report = (RMReport)e.Row;

            //Fix AmountType Combo for GL:[PXIntList("0;Not Set,1;Turnover,2;Credit,3;Debit,4;Beg. Balance,5;Ending Balance")]
            if (report != null && report.Type == RMType.GL && field.Equals(typeof(RMDataSource.amountType).Name, StringComparison.InvariantCultureIgnoreCase))
            {
                e.ReturnState = PXIntState.CreateInstance(e.ReturnValue, field, false, 0, null, null,
                                                          new int[6] {
                    BalanceType.NotSet, BalanceType.Turnover, BalanceType.Credit, BalanceType.Debit, BalanceType.BeginningBalance, BalanceType.EndingBalance
                },
                                                          new string[6]
                {
                    PXLocalizer.Localize(Messages.NotSet, typeof(Messages).FullName),
                    PXLocalizer.Localize(Messages.Turnover, typeof(Messages).FullName),
                    PXLocalizer.Localize(Messages.Credit, typeof(Messages).FullName),
                    PXLocalizer.Localize(Messages.Debit, typeof(Messages).FullName),
                    PXLocalizer.Localize(Messages.BegBalance, typeof(Messages).FullName),
                    PXLocalizer.Localize(Messages.EndingBalance, typeof(Messages).FullName),
                },
                                                          typeof(short), BalanceType.NotSet);
                ((PXFieldState)e.ReturnState).DisplayName = PXLocalizer.Localize(Messages.AmountType, typeof(Messages).FullName);
            }
        }
示例#10
0
 protected override PXFieldState DefaultState(PXCache sender, PXFieldSelectingEventArgs e) => PXIntState.CreateInstance(e.ReturnState, FieldName, null, null, null, null, null, null, typeof(int), DefaultValue, null);
示例#11
0
        protected virtual object GetFieldValue(PXCache sender, object row, Type field, bool disableLazyLoading)
        {
            if (disableLazyLoading)
            {
                if (!IsListAttributeField(sender, field))
                {
                    return(sender.GetValue(row, field.Name));
                }
            }

            object       val   = sender.GetStateExt(row, field.Name);
            PXFieldState state = val as PXFieldState;

            if (state != null)
            {
                val = state.Value;
            }

            if (state is PXIntState)
            {
                PXIntState istate = (PXIntState)state;
                if (istate.AllowedValues != null && istate.AllowedLabels != null)
                {
                    for (int i = 0; i < istate.AllowedValues.Length && i < istate.AllowedLabels.Length; i++)
                    {
                        if (istate.AllowedValues[i] == (int)val)
                        {
                            val = istate.AllowedLabels[i];
                            break;
                        }
                    }
                }
            }
            else if (state is PXStringState)
            {
                PXStringState sstate = (PXStringState)state;
                if (sstate.AllowedValues != null && sstate.AllowedLabels != null)
                {
                    for (int i = 0; i < sstate.AllowedValues.Length && i < sstate.AllowedLabels.Length; i++)
                    {
                        if (sstate.AllowedValues[i] == (string)val)
                        {
                            val = sstate.AllowedLabels[i];
                            break;
                        }
                    }
                }
            }


            PXStringState strState = state as PXStringState;

            //Following is a hack to get FinPeriod to format as it is visible to the user... couldn't find any other way to do it ((.
            if (strState != null && strState.InputMask == "##-####")
            {
                string strFinPeriod = val.ToString();
                if (strFinPeriod.Length == 6)
                {
                    val = string.Format("{0}-{1}", strFinPeriod.Substring(0, 2), strFinPeriod.Substring(2, 4));
                }
            }


            return(val);
        }
        private object GetFieldValue(PXCache sender, object row, Type field, bool disableLazyLoading, bool buildTranslations)
        {
            var dbLocalizableAttr = sender.GetAttributes(field.Name).FirstOrDefault(attr => attr is PXDBLocalizableStringAttribute);
            var listAttr          = IsListAttributeField(sender, field);

            if (!buildTranslations)
            {
                if (listAttr == 2)
                {
                    listAttr = 1;
                }
                dbLocalizableAttr = null;
            }

            if (disableLazyLoading)
            {
                if (listAttr == 0 && dbLocalizableAttr == null)
                {
                    return(sender.GetValue(row, field.Name));
                }
            }

            object       val   = sender.GetStateExt(row, field.Name);
            PXFieldState state = val as PXFieldState;

            if (state != null)
            {
                if (dbLocalizableAttr != null)
                {
                    var translations = sender.GetStateExt(row, field.Name + "Translations") as string[];
                    if (translations != null)
                    {
                        return(string.Join(" ", translations));
                    }
                }

                val = state.Value;
            }

            if (state is PXIntState)
            {
                PXIntState istate = (PXIntState)state;
                if (istate.AllowedValues != null && istate._NeutralLabels != null)
                {
                    for (int i = 0; i < istate.AllowedValues.Length && i < istate.AllowedLabels.Length && i < istate._NeutralLabels.Length; i++)
                    {
                        if (istate.AllowedValues[i] == (int)val)
                        {
                            if (listAttr == 2)
                            {
                                val = GetAllTranslations(sender, istate.Name, i, istate._NeutralLabels, istate.AllowedLabels);
                            }
                            else
                            {
                                val = istate.AllowedLabels[i];
                            }
                            break;
                        }
                    }
                }
            }
            else if (state is PXStringState)
            {
                PXStringState sstate = (PXStringState)state;
                if (sstate.AllowedValues != null && sstate._NeutralLabels != null)
                {
                    for (int i = 0; i < sstate.AllowedValues.Length && i < sstate.AllowedLabels.Length && i < sstate._NeutralLabels.Length; i++)
                    {
                        if (sstate.AllowedValues[i] == (string)val)
                        {
                            if (listAttr == 2)
                            {
                                val = GetAllTranslations(sender, sstate.Name, i, sstate._NeutralLabels, sstate.AllowedLabels);
                            }
                            else
                            {
                                val = sstate.AllowedLabels[i];
                            }
                            break;
                        }
                    }
                }
            }


            PXStringState strState = state as PXStringState;

            //Following is a hack to get FinPeriod to format as it is visible to the user... couldn't find any other way to do it ((.
            if (strState != null && strState.InputMask == "##-####")
            {
                string strFinPeriod = val.ToString();
                if (strFinPeriod.Length == 6)
                {
                    val = string.Format("{0}-{1}", strFinPeriod.Substring(0, 2), strFinPeriod.Substring(2, 4));
                }
            }


            return(val);
        }