Skip to main content
Solved

how to get more than 24 hrs in a PXTimeList Dropdown Field??


Forum|alt.badge.img+1

Hi,
I developed new screen. Inside that added one new Field “Labor Time Hrs” which consist of PXTimeList Attribute.
Currently PXTimeList is showing up to 24:00 Hrs.

How to customize that Field to show More than 24 Hrs in a Time dropdown.
Thanks
Giri.

Best answer by Naveen Boga

Hey Giri, I hope you are doing well!

The default TimeList attribute will provide you only 24 Hrs. We need to customize if you want to show more than 24 Hrs.

I just worked on it and please find the customized attribute and screenshot for your reference.

 

In the below example, I’ve added up to 30 hours. If you want to show more than 30 hours you can increase the values in GetValues(30, 60).


 

 

SOOrder Extended DAC 

 public class SOOrderExt : PXCacheExtension<SOOrder>
    { 
        [PXDBInt]
        [UsrPXTimeListAttribute]
        [PXUIField(DisplayName = "Time Span")]
        public int? UsrTimeSpan { get; set; }
        public abstract class usrTimeSpan : IBqlField{ }

    }




Customized Attribute

    public class UsrPXTimeListAttribute : PXIntListAttribute
    {
        public override bool IsLocalizable
        {
            get
            {
                return false;
            }
        }

        public UsrPXTimeListAttribute()
            : base(UsrPXTimeListAttribute.GetValues(30, 60), UsrPXTimeListAttribute.GetLabels(UsrPXTimeListAttribute.GetValues(30, 60)))
        {
        }

        public UsrPXTimeListAttribute(int step, int count)
            : base(UsrPXTimeListAttribute.GetValues(step, count), UsrPXTimeListAttribute.GetLabels(UsrPXTimeListAttribute.GetValues(step, count)))
        {
        }

        public override void CacheAttached(PXCache sender)
        {
            base.CacheAttached(sender);
            sender.Graph.FieldUpdating.AddHandler(sender.GetItemType(), base._FieldName, this.FieldUpdating);
        }

        public override void FieldSelecting(PXCache sender, PXFieldSelectingEventArgs e)
        {
            base.FieldSelecting(sender, e);
            PXIntState V_8 = e.ReturnState as PXIntState;
            if (V_8 != null)
            {
                int[] V_10 = V_8.AllowedValues;
                string[] V_9 = V_8.AllowedLabels;
                if (V_8.Required.HasValue)
                {
                    bool? V_7 = V_8.Required;
                    bool V_6 = true;
                    bool flag = V_7.GetValueOrDefault() == V_6 & V_7.HasValue;
                }
                if (e.ReturnValue != null)
                {
                    int V_5 = (int)e.ReturnValue;
                    if (V_10 != null && !V_10.Contains(V_5))
                    {
                        V_10 = V_10.Append(V_5).ToArray();
                        V_9 = V_9.Append(UsrPXTimeListAttribute.GetString(V_5)).ToArray();
                    }
                }
                e.ReturnState = PXTimeState.CreateInstance(V_8, V_10, V_9);
            }
        }

        protected void FieldUpdating(PXCache sender, PXFieldUpdatingEventArgs e)
        {
            if (!sender.Graph.IsImportFromExcel && !sender.Graph.IsImport)
            {
                return;
            }
            if (!(e.NewValue is int) && !string.IsNullOrEmpty((string)e.NewValue))
            {
                string V_0 = e.NewValue as string;
                if (V_0 != null && !new Regex("^[0-9]+$", RegexOptions.Compiled | RegexOptions.Singleline).IsMatch(V_0))
                {
                    TimeSpan V_ = default(TimeSpan);
                    if (!TimeSpan.TryParse(V_0, out V_))
                    {
                        throw new PXException("\"{0}\" cannot be converted to Time.", e.NewValue);
                    }
                    e.NewValue = (int)V_.TotalMinutes;
                }
            }
        }

        public static int[] GetValues(int step, int count)
        {
            List<int> V_2 = new List<int>(100);
            for (int V_ = 0; V_ <= count; V_++)
            {
                V_2.Add(V_ * step);
            }
            return V_2.ToArray();
        }

        public static string[] GetLabels(int[] values)
        {
            List<string> V_5 = new List<string>();
            foreach (int V_3 in values)
            {
                V_5.Add(UsrPXTimeListAttribute.GetString(V_3));
            }
            return V_5.ToArray();
        }

        public static string GetString(int totalMinutes)
        {
            TimeSpan V_0 = TimeSpan.FromMinutes((double)Math.Abs(totalMinutes));
            if (totalMinutes < 0)
            {
                return string.Format("-{0:d2}:{1:d2}", (int)Math.Truncate(V_0.TotalHours), V_0.Minutes);
            }
            return string.Format("{0:d2}:{1:d2}", (int)Math.Truncate(V_0.TotalHours), V_0.Minutes);
        }
    }


 

View original
Did this topic help you find an answer to your question?

2 replies

Naveen Boga
Captain II
Forum|alt.badge.img+19
  • Captain II
  • 3404 replies
  • Answer
  • April 15, 2021

Hey Giri, I hope you are doing well!

The default TimeList attribute will provide you only 24 Hrs. We need to customize if you want to show more than 24 Hrs.

I just worked on it and please find the customized attribute and screenshot for your reference.

 

In the below example, I’ve added up to 30 hours. If you want to show more than 30 hours you can increase the values in GetValues(30, 60).


 

 

SOOrder Extended DAC 

 public class SOOrderExt : PXCacheExtension<SOOrder>
    { 
        [PXDBInt]
        [UsrPXTimeListAttribute]
        [PXUIField(DisplayName = "Time Span")]
        public int? UsrTimeSpan { get; set; }
        public abstract class usrTimeSpan : IBqlField{ }

    }




Customized Attribute

    public class UsrPXTimeListAttribute : PXIntListAttribute
    {
        public override bool IsLocalizable
        {
            get
            {
                return false;
            }
        }

        public UsrPXTimeListAttribute()
            : base(UsrPXTimeListAttribute.GetValues(30, 60), UsrPXTimeListAttribute.GetLabels(UsrPXTimeListAttribute.GetValues(30, 60)))
        {
        }

        public UsrPXTimeListAttribute(int step, int count)
            : base(UsrPXTimeListAttribute.GetValues(step, count), UsrPXTimeListAttribute.GetLabels(UsrPXTimeListAttribute.GetValues(step, count)))
        {
        }

        public override void CacheAttached(PXCache sender)
        {
            base.CacheAttached(sender);
            sender.Graph.FieldUpdating.AddHandler(sender.GetItemType(), base._FieldName, this.FieldUpdating);
        }

        public override void FieldSelecting(PXCache sender, PXFieldSelectingEventArgs e)
        {
            base.FieldSelecting(sender, e);
            PXIntState V_8 = e.ReturnState as PXIntState;
            if (V_8 != null)
            {
                int[] V_10 = V_8.AllowedValues;
                string[] V_9 = V_8.AllowedLabels;
                if (V_8.Required.HasValue)
                {
                    bool? V_7 = V_8.Required;
                    bool V_6 = true;
                    bool flag = V_7.GetValueOrDefault() == V_6 & V_7.HasValue;
                }
                if (e.ReturnValue != null)
                {
                    int V_5 = (int)e.ReturnValue;
                    if (V_10 != null && !V_10.Contains(V_5))
                    {
                        V_10 = V_10.Append(V_5).ToArray();
                        V_9 = V_9.Append(UsrPXTimeListAttribute.GetString(V_5)).ToArray();
                    }
                }
                e.ReturnState = PXTimeState.CreateInstance(V_8, V_10, V_9);
            }
        }

        protected void FieldUpdating(PXCache sender, PXFieldUpdatingEventArgs e)
        {
            if (!sender.Graph.IsImportFromExcel && !sender.Graph.IsImport)
            {
                return;
            }
            if (!(e.NewValue is int) && !string.IsNullOrEmpty((string)e.NewValue))
            {
                string V_0 = e.NewValue as string;
                if (V_0 != null && !new Regex("^[0-9]+$", RegexOptions.Compiled | RegexOptions.Singleline).IsMatch(V_0))
                {
                    TimeSpan V_ = default(TimeSpan);
                    if (!TimeSpan.TryParse(V_0, out V_))
                    {
                        throw new PXException("\"{0}\" cannot be converted to Time.", e.NewValue);
                    }
                    e.NewValue = (int)V_.TotalMinutes;
                }
            }
        }

        public static int[] GetValues(int step, int count)
        {
            List<int> V_2 = new List<int>(100);
            for (int V_ = 0; V_ <= count; V_++)
            {
                V_2.Add(V_ * step);
            }
            return V_2.ToArray();
        }

        public static string[] GetLabels(int[] values)
        {
            List<string> V_5 = new List<string>();
            foreach (int V_3 in values)
            {
                V_5.Add(UsrPXTimeListAttribute.GetString(V_3));
            }
            return V_5.ToArray();
        }

        public static string GetString(int totalMinutes)
        {
            TimeSpan V_0 = TimeSpan.FromMinutes((double)Math.Abs(totalMinutes));
            if (totalMinutes < 0)
            {
                return string.Format("-{0:d2}:{1:d2}", (int)Math.Truncate(V_0.TotalHours), V_0.Minutes);
            }
            return string.Format("{0:d2}:{1:d2}", (int)Math.Truncate(V_0.TotalHours), V_0.Minutes);
        }
    }


 


Forum|alt.badge.img+1
  • Author
  • Pro I
  • 59 replies
  • April 30, 2021

Thanks Naveen.


Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings