예제 #1
0
        protected virtual void SegmentValue_Value_FieldSelecting(PXCache cache, PXFieldSelectingEventArgs e)
        {
            if (e.Row == null || cache.HasAttributes(e.Row))
            {
                Segment seg = Segment.Current as Segment;
                short   i;

                if (seg != null && seg.SegmentID != null)
                {
                    StringBuilder bld = new StringBuilder();

                    if (seg.AutoNumber != true)
                    {
                        bld.Append((seg.CaseConvert == 1) ? ">" : "");
                        bld.Append((seg.CaseConvert == 2) ? "<" : "");
                    }

                    for (i = 0; i < seg.Length; i++)
                    {
                        if (seg.AutoNumber == true)
                        {
                            bld.Append("C");
                        }
                        else
                        {
                            bld.Append(seg.EditMask);
                        }
                    }

                    e.ReturnState = PXStringState.CreateInstance(e.ReturnState, null, null, "Value", null, null, bld.ToString(), null, null, null, null);
                }
            }
        }
        private void SourceFieldUpdated(PXCache cache, PXFieldUpdatedEventArgs e)
        {
            object sourcedate = cache.GetValue(e.Row, _sourceField);

            if (sourcedate != null)
            {
                PeriodResult result     = GetPeriod(cache, _searchType, (DateTime)sourcedate, new object[] { e.Row }, true);
                string       newValue   = result;
                bool         haspending = false;
                try
                {
                    object pendingValue = cache.GetValuePending(e.Row, _FieldName);
                    if (pendingValue != null && pendingValue != PXCache.NotSetValue)
                    {
                        pendingValue = UnFormatPeriod((string)pendingValue);
                        cache.RaiseFieldVerifying(_FieldName, e.Row, ref pendingValue);
                        haspending = true;
                    }
                }
                catch (PXSetPropertyException)
                {
                    cache.SetValuePending(e.Row, _FieldName, newValue);
                }
                finally
                {
                    if (cache.HasAttributes(e.Row))
                    {
                        cache.RaiseExceptionHandling(_FieldName, e.Row, null, null);
                    }

                    //this will happen only if FirstOpenPeriod is set from OpenPeriod
                    if (!haspending && result.StartDate > (DateTime?)sourcedate)
                    {
                        cache.SetValueExt(e.Row, _sourceField, result.StartDate);
                    }
                    else
                    {
                        cache.SetValueExt(e.Row, _FieldName, newValue);
                    }
                }
            }
            else
            {
                cache.SetValue(e.Row, _FieldName, null);
            }
        }