Exemplo n.º 1
0
        protected virtual int GetIpAddressPart(DateTime dt, int partNumber)
        {
            if (partNumber < 0 || partNumber > 3)
            {
                throw new Exception("Given part number is out of IPv4 address parts");
            }

            string[] ipSplitted = IPAddressHelper.ToIPAddress(dt).ToStringArray();
            return(Convert.ToInt16(ipSplitted[partNumber]));
        }
Exemplo n.º 2
0
        public override string GetDisplayText(FormatInfo format, object editValue)
        {
            if (editValue is DateTime && IPAddressHelper.IsConvertible((DateTime)editValue))
            {
                return(IPAddressHelper.ToIPAddress((DateTime)editValue).ToString());
            }

            if (editValue is IPv4Addr || editValue is string)
            {
                return(editValue.ToString());
            }

            return(GetDisplayText(null, new IPv4Addr("0.0.0.0")));
        }
Exemplo n.º 3
0
        public override DateTime ApplyElement(int result, DateTime editedDateTime)
        {
            string[] ipSplitted = IPAddressHelper.ToIPAddress(editedDateTime).ToStringArray();

            for (int i = 0; i < ipSplitted.Length; i++)
            {
                if (i == ipAddressPart)
                {
                    ipSplitted[i] = String.Format("{0:d3}", result);
                }
                else
                {
                    ipSplitted[i] = String.Format("{0:d3}", Convert.ToInt16(ipSplitted[i]));
                }
            }

            return(IPAddressHelper.ToDateTime(new IPv4Addr(String.Join(".", ipSplitted))));
        }
Exemplo n.º 4
0
        public override void SetInitialEditText(string initialEditText)
        {
            KillCurrentElementEditor();
            DateTime?initialEditValue = new DateTime(0);

            if (!string.IsNullOrEmpty(initialEditText))
            {
                try
                {
                    initialEditValue = IPAddressHelper.ToDateTime(new IPv4Addr(initialEditText));
                }
                catch
                {
                }
            }

            SetInitialEditValue(initialEditValue);
        }