Beispiel #1
0
        /// <summary>
        ///   JGENGO: Return Japanese gengo (the name of an era)
        /// </summary>
        protected internal void eval_op_jgengo(ExpressionEvaluator.ExpVal resVal, NUM_TYPE val1, NUM_TYPE val2,
                                               DisplayConvertor displayConvertor)
        {
            String strFormat;
            int    intType;

            resVal.Attr = StorageAttribute.ALPHA;
            if (val1 == null || val2 == null)
            {
                _expressionEvaluator.SetNULL(resVal, StorageAttribute.ALPHA);
                return;
            }

            intType = val2.NUM_2_LONG();

            if (intType >= 4)
            {
                strFormat = "JJJJ";
            }
            else if (intType >= 2)
            {
                strFormat = "JJ";
            }
            else if (intType >= 1)
            {
                strFormat = "J";
            }
            else
            {
                resVal.StrVal = "";
                return;
            }

            _expressionEvaluator.eval_op_date_str(resVal, val1, strFormat, displayConvertor);
        }
Beispiel #2
0
        /// <summary>
        /// Converts Magic 'Date' Type to 'dotNetType'
        /// </summary>
        /// <param name="magicVal"></param>
        /// <param name="dotNetType"></param>
        /// <returns></returns>
        private static object convertDateToDotNet(string magicVal, Type dotNetType)
        {
            if (dotNetType == typeof(DateTime))
            {
                NUM_TYPE         numType          = new NUM_TYPE(magicVal);
                DisplayConvertor displayConvertor = DisplayConvertor.Instance;

                int date = numType.NUM_2_LONG();
                if (date == 0)
                {
                    magicVal = FieldDef.getMagicDefaultValue(StorageAttribute.DATE);
                    numType  = new NUM_TYPE(magicVal);
                    date     = numType.NUM_2_LONG();
                }

                // Break date into its components - year month date
                DisplayConvertor.DateBreakParams breakParams = displayConvertor.getNewDateBreakParams();
                displayConvertor.date_break_datemode(breakParams, date, true, -1);
                int year  = breakParams.year;
                int month = breakParams.month;
                int day   = breakParams.day;

                return(new DateTime(year, month, day));
            }
            else
            {
                return(null);
            }
        }
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            NUM_TYPE type = (NUM_TYPE)value;
            string   s_type;

            switch (type)
            {
            case NUM_TYPE.DEC:
                s_type = "DEC";
                break;

            case NUM_TYPE.HEX:
                s_type = "HEX";
                break;

            case NUM_TYPE.BIN:
                s_type = "BIN";
                break;

            default:
                s_type = "";
                break;
            }

            return(s_type);
        }
Beispiel #4
0
        /// <summary>
        /// Converts 'dotNetObj' to 'Time' Magic type
        /// </summary>
        /// <param name="dotNetObj"></param>
        /// <returns></returns>
        private static string convertDotNetToTime(object dotNetObj)
        {
            String retObject  = "";
            Type   dotNetType = dotNetObj.GetType();

            if (dotNetType == typeof(DateTime))
            {
                DateTime date = (DateTime)dotNetObj;

                int      magicTime        = DisplayConvertor.Instance.time_2_int(date.Hour, date.Minute, date.Second);
                NUM_TYPE numtypeMagicTime = new NUM_TYPE();
                numtypeMagicTime.NUM_4_LONG(magicTime);

                retObject = numtypeMagicTime.toXMLrecord();
            }
            else if (dotNetType == typeof(TimeSpan))
            {
                TimeSpan time = (TimeSpan)dotNetObj;

                int      magicTime        = DisplayConvertor.Instance.time_2_int(time.Hours, time.Minutes, time.Seconds);
                NUM_TYPE numtypeMagicTime = new NUM_TYPE();
                numtypeMagicTime.NUM_4_LONG(magicTime);

                retObject = numtypeMagicTime.toXMLrecord();
            }

            return(retObject);
        }
Beispiel #5
0
        /// <summary>
        /// Converts Magic 'Numeric' Type to 'dotNetType'
        /// </summary>
        /// <param name="magicVal"></param>
        /// <param name="dotNetType"></param>
        /// <returns></returns>
        private static Object convertNumericToDotNet(String magicVal, Type dotNetType)
        {
            Object   retObject = null;
            NUM_TYPE numType   = new NUM_TYPE(magicVal);
            double   doubleVal = 0.0;

            if (dotNetType == typeof(SByte) || dotNetType == typeof(Byte) || dotNetType == typeof(Int16) ||
                dotNetType == typeof(UInt16) || dotNetType == typeof(Int32) || dotNetType == typeof(UInt32) ||
                dotNetType == typeof(Int64) || dotNetType == typeof(UInt64) || dotNetType == typeof(float) ||
                dotNetType == typeof(Decimal) || dotNetType == typeof(Single) || dotNetType == typeof(Double))
            {
                doubleVal = numType.to_double();
                retObject = ReflectionServices.DynCast(doubleVal, dotNetType);
            }
            else
            {
                doubleVal = numType.to_double();

                if (dotNetType == typeof(Char))
                {
                    retObject = ReflectionServices.DynCast((Int64)doubleVal, dotNetType);
                }
                else if (dotNetType == typeof(IntPtr))
                {
                    retObject = new IntPtr((long)doubleVal);
                }
                else if (dotNetType == typeof(UIntPtr))
                {
                    retObject = new UIntPtr((ulong)doubleVal);
                }
            }

            return(retObject);
        }
Beispiel #6
0
        internal override object ConvertRuntimeFieldToGateway(DBField dbField, string gatewayValue)
        {
            NUM_TYPE A = new NUM_TYPE(gatewayValue);

            //return ((NUM_TYPE)gatewayValue).to_double().ToString();
            return(ConvertMgValueToGateway(dbField, A));
        }
Beispiel #7
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="fieldView"></param>
        /// <param name="userRange"></param>
        /// <returns></returns>
        private UnitComputeResult CheckUserRange(IFieldView fieldView, UserRange userRange)
        {
            UnitComputeResult result = new UnitComputeResult();

            string fieldValue = fieldView.ValueFromCurrentRecord.Trim();

            switch (fieldView.StorageAttribute)
            {
            case StorageAttribute.NUMERIC:
            case StorageAttribute.DATE:
            case StorageAttribute.TIME:
            {
                int fieldValueInt = new NUM_TYPE(fieldValue).NUM_2_LONG();

                // check the min value
                if (!userRange.nullMin && !userRange.discardMin)
                {
                    int min = new NUM_TYPE(userRange.min).NUM_2_LONG();
                    if (fieldValueInt < min)
                    {
                        result.ErrorCode = UnitComputeErrorCode.RangeFailed;
                    }
                }

                // check the max value
                if (result.Success && !userRange.nullMax && !userRange.discardMax)
                {
                    int max = new NUM_TYPE(userRange.max).NUM_2_LONG();
                    if (fieldValueInt > max)
                    {
                        result.ErrorCode = UnitComputeErrorCode.RangeFailed;
                    }
                }
            }
            break;

            default:
            {
                // check the min value
                if (!userRange.nullMin && !userRange.discardMin)
                {
                    if (String.Compare(fieldValue, (string)userRange.min, StringComparison.Ordinal) < 0)
                    {
                        result.ErrorCode = UnitComputeErrorCode.RangeFailed;
                    }
                }

                // check the max value
                if (result.Success && !userRange.nullMax && !userRange.discardMax)
                {
                    if (String.Compare(fieldValue, (string)userRange.max, StringComparison.Ordinal) > 0)
                    {
                        result.ErrorCode = UnitComputeErrorCode.RangeFailed;
                    }
                }
            }
            break;
            }
            return(result);
        }
Beispiel #8
0
        /// <summary> convert numbers to our secret format
        /// </summary>
        /// <param name="fileName"></param>
        private static String Encode(String numStr, StorageAttribute attr, String picStr)
        {
            PIC      pic      = new PIC(picStr, attr, 0);
            NUM_TYPE num_type = new NUM_TYPE(numStr, pic, 0);

            String encoded_num = num_type.toXMLrecord();

            encoded_num = Base64.encode(RecordUtils.byteStreamToString(encoded_num), ClientManager.Instance.getEnvironment().GetEncoding());
            return(XmlParser.escape(encoded_num));
        }
Beispiel #9
0
        /// <summary>
        /// Ref to coversion table in ConvertMagicToDotNet, gets the default DotNetType for 'magicType'
        /// </summary>
        /// <param name="magicType"></param>
        /// <returns></returns>
        public static Type getDefaultDotNetTypeForMagicType(String magicVal, StorageAttribute magicType)
        {
            Type dotNetType = null;

            switch (magicType)
            {
            case StorageAttribute.NUMERIC:
                NUM_TYPE numType = new NUM_TYPE(magicVal);

                if (numType.NUM_IS_LONG())
                {
                    dotNetType = typeof(long);
                }
                else
                {
                    dotNetType = typeof(Double);
                }
                break;

            case StorageAttribute.ALPHA:
            case StorageAttribute.UNICODE:
                dotNetType = typeof(String);
                break;

            case StorageAttribute.DATE:
                dotNetType = typeof(DateTime);
                break;

            case StorageAttribute.TIME:
                dotNetType = typeof(TimeSpan);
                break;

            case StorageAttribute.BOOLEAN:
                dotNetType = typeof(Boolean);
                break;

            case StorageAttribute.BLOB:
                dotNetType = typeof(String);
                break;

            case StorageAttribute.BLOB_VECTOR:
                dotNetType = typeof(Array);
                break;

            case StorageAttribute.DOTNET:
                dotNetType = typeof(Object);
                break;

            default:
                break;
            }

            return(dotNetType);
        }
Beispiel #10
0
        /// <summary> convert numbers from our secret format
        /// </summary>
        /// <param name="fileName"></param>
        private static String Decode(String numStr, StorageAttribute attr, String picStr)
        {
            String decoded_num = XmlParser.unescape(numStr);

            decoded_num = XmlParser.unescape(decoded_num);
            decoded_num = Base64.decodeToHex(decoded_num);

            NUM_TYPE num_type = new NUM_TYPE(decoded_num);
            PIC      pic      = new PIC(picStr, attr, 0);

            return(num_type.toDisplayValue(pic));
        }
Beispiel #11
0
 private void setNumericVals()
 {
     if (_isNumericType && _linkVals != null)
     {
         _numVals = new NUM_TYPE[_linkVals.Length];
         for (int j = 0; j < _linkVals.Length; j++)
         {
             _numVals[j] = new NUM_TYPE(_linkVals[j]);
         }
     }
     else
     {
         _numVals = null;
     }
 }
Beispiel #12
0
        internal override object ConvertGatewayToRuntimeField(DBField dbField, object gatewayValue)
        {
            NUM_TYPE value = new NUM_TYPE();

            if (dbField.Length <= 2)
            {
                value.NUM_4_LONG((short)gatewayValue);
            }
            else
            {
                value.NUM_4_LONG((int)gatewayValue);
            }

            return(value.toXMLrecord());
        }
Beispiel #13
0
        /// <summary>
        /// Converts 'dotNetObj' to 'Date' Magic type
        /// </summary>
        /// <param name="dotNetObj"></param>
        /// <returns></returns>
        private static string convertDotNetToDate(object dotNetObj)
        {
            String retObject  = "";
            Type   dotNetType = dotNetObj.GetType();

            if (dotNetType == typeof(DateTime))
            {
                DateTime date = (DateTime)dotNetObj;

                int      magicDate        = DisplayConvertor.Instance.date_4_calender(date.Year, date.Month, date.Day, 0, false);
                NUM_TYPE numtypeMagicDate = new NUM_TYPE();
                numtypeMagicDate.NUM_4_LONG(magicDate);

                retObject = numtypeMagicDate.toXMLrecord();
            }

            return(retObject);
        }
Beispiel #14
0
        /// <summary>Adds the pane to the status bar/// </summary>
        /// <param name="statusBarIdx">Status bar index</param>
        /// <param name="paneType">Pane type: label or image</param>
        /// <param name="paneIdx">Pane index</param>
        /// <param name="paneWidth">Pane width</param>
        /// <param name="showPaneBorder">Show border or not</param>
        public void AddPane(MgControlType paneType, int paneIdx, int paneWidth, bool showPaneBorder)
        {
            var num = new NUM_TYPE();

            //Get status bar index.
            int statusBarIdx = getForm().getControlIdx(this);

            // Create pane object
            MgControlBase paneObj = getForm().ConstructMgControl(paneType, getForm().getTask(), statusBarIdx);

            if (paneObj != null)
            {
                // Set width of pane object.
                num.NUM_4_LONG(paneWidth);
                paneObj.setProp(PropInterface.PROP_TYPE_WIDTH, num.toXMLrecord());

                // Set Idx of pane object.
                num.NUM_4_LONG(paneIdx);
                paneObj.setProp(PropInterface.PROP_TYPE_LAYER, num.toXMLrecord());

                // Set border of pane object.
                if (showPaneBorder)
                {
                    paneObj.setProp(PropInterface.PROP_TYPE_BORDER, "1");
                }

                //Properties specific to image pane only.
                if (paneObj.Type == MgControlType.CTRL_TYPE_SB_IMAGE)
                {
                    paneObj.DataType = StorageAttribute.ALPHA;
                    paneObj.setPIC("1000");

                    num.NUM_4_LONG((int)CtrlImageStyle.Copied);
                    paneObj.setProp(PropInterface.PROP_TYPE_IMAGE_STYLE, num.toXMLrecord());
                }

                //Add to control table collection.
                getForm().CtrlTab.addControl(paneObj);

                //Add to collection.
                Debug.Assert(!_paneObjectsCollection.ContainsKey(paneIdx));
                _paneObjectsCollection[paneIdx] = paneObj;
            }
        }
Beispiel #15
0
        /// <summary>
        /// Converts 'dotNetObj' to 'Numeric' Magic type
        /// </summary>
        /// <param name="dotNetObj"></param>
        /// <returns></returns>
        private static string convertDotNetToNumeric(object dotNetObj)
        {
            Double   doubleVal  = 0.0;
            Type     dotNetType = dotNetObj.GetType();
            NUM_TYPE numType;

            if (dotNetType.IsEnum)
            {
                dotNetType = Enum.GetUnderlyingType(dotNetType);
            }


            if (dotNetType == typeof(SByte) || dotNetType == typeof(Byte) || dotNetType == typeof(Int16) ||
                dotNetType == typeof(UInt16) || dotNetType == typeof(Int32) || dotNetType == typeof(Char))
            {
                int intVal = (int)ReflectionServices.DynCast(dotNetObj, typeof(int));

                numType = new NUM_TYPE();
                numType.NUM_4_LONG(intVal);
            }
            else if (dotNetType == typeof(UInt32) ||
                     dotNetType == typeof(Int64) || dotNetType == typeof(UInt64) || dotNetType == typeof(float) ||
                     dotNetType == typeof(Decimal) || dotNetType == typeof(Single) || dotNetType == typeof(Double))
            {
                doubleVal = (Double)ReflectionServices.DynCast(dotNetObj, typeof(Double));

                numType = NUM_TYPE.from_double(doubleVal);
            }
            else
            {
                if (dotNetType == typeof(IntPtr))
                {
                    doubleVal = (Double)((IntPtr)dotNetObj).ToInt64();
                }
                else if (dotNetType == typeof(UIntPtr))
                {
                    doubleVal = (Double)((UIntPtr)dotNetObj).ToUInt64();
                }

                numType = NUM_TYPE.from_double(doubleVal);
            }

            return(numType.toXMLrecord());
        }
Beispiel #16
0
        /// <summary>
        ///   Build the expression as a byte array
        /// </summary>
        private void buildByteArray(String expStr)
        {
            String twoHexDigits;

            if (expStr == null || expStr.Length == 0 || expStr.Length % 2 != 0)
            {
                Logger.Instance.WriteExceptionToLog("in Expression.buildByteArray() expStr cannot be changed " + expStr);
                return;
            }

            _expBytes = new sbyte[expStr.Length / 2];
            for (int i = 0;
                 i < expStr.Length;
                 i += 2)
            {
                twoHexDigits     = expStr.Substring(i, 2);
                _expBytes[i / 2] = NUM_TYPE.toSByte(Convert.ToInt32(twoHexDigits, 16));
            }
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="record"></param>
        /// <param name="checkRange"></param>
        /// <returns></returns>
        internal override UnitComputeResult Compute(IRecord record, bool checkRange, bool recompute, bool computeInitExpressions)
        {
            UnitComputeResult result = new UnitComputeResult();

            string fieldValue = fieldView.ValueFromCurrentRecord;

            switch (fieldView.StorageAttribute)
            {
            case StorageAttribute.NUMERIC:
            {
                NUM_TYPE fetchedValue = new NUM_TYPE(fieldValue);
                NUM_TYPE minimumValue = new NUM_TYPE(DisplayConvertor.Instance.toNum((string)minValue, new PIC(fieldView.Picture, StorageAttribute.NUMERIC, 0), 0));

                if (NUM_TYPE.num_cmp(fetchedValue, minimumValue) < 0)
                {
                    result.ErrorCode = UnitComputeErrorCode.LocateFailed;
                }
            }
            break;

            case StorageAttribute.UNICODE:
            case StorageAttribute.ALPHA:
            {
                //QCR # 444514 : Check whether given Incremental Locate String is in between min and max of fetched value.
                //               Locate gets successful when fetched record is greater than or equal to search Incremental Locate String value.
                string minimumValue = minValue.ToString().PadRight(fieldView.Length, char.MinValue);
                string maximumValue = minValue.ToString().PadRight(fieldView.Length, char.MaxValue);

                if (String.Compare(fieldValue, (string)minimumValue, StringComparison.Ordinal) < 0)
                {
                    result.ErrorCode = UnitComputeErrorCode.LocateFailed;
                }
                else if (String.Compare(fieldValue, (string)maximumValue, StringComparison.Ordinal) > 0)
                {
                    result.ErrorCode = UnitComputeErrorCode.LocateFailed;
                }
            }
            break;
            }

            return(result);
        }
Beispiel #18
0
        /// <summary>
        /// convert the string typed by the user to the type the gateway converter expects
        /// </summary>
        /// <param name="type"></param>
        /// <param name="value"></param>
        /// <param name="length"></param>
        /// <returns></returns>
        private object StringToMgVal(StorageAttribute type, string value, int length, string picture)
        {
            switch (type)
            {
            case StorageAttribute.ALPHA:
            case StorageAttribute.UNICODE:
            {
                String newVal = value;
                newVal = newVal.PadRight(length, '\0');
                return(newVal);
            }

            case StorageAttribute.NUMERIC:
                NUM_TYPE numType = new NUM_TYPE(value, new PIC(picture, StorageAttribute.NUMERIC, 0), 0);
                return(numType);

            default:
                Debug.Assert(false, "Unhandled case in incremental locate");
                return(value);
            }
        }
Beispiel #19
0
        internal override object ConvertGatewayToRuntimeField(DBField dbField, object gatewayValue)
        {
            NUM_TYPE runtimeValue = new NUM_TYPE();
            String   numberString = gatewayValue.ToString();

            if (dbField.Dec > 0)
            {
                string systemNumberDecimalSeperator = CultureInfo.CurrentUICulture.NumberFormat.NumberDecimalSeparator;
                char   decimalSeparator             = ClientManager.Instance.getEnvironment().GetDecimal();

                // temporarily exclude this code from Windows mobile. When handling offline and client side storage on Windows mobile
                // please handle this too
#if !PocketPC
                if (!decimalSeparator.Equals(systemNumberDecimalSeperator) && numberString.Contains(systemNumberDecimalSeperator))
                {
                    numberString = numberString.Replace(systemNumberDecimalSeperator, decimalSeparator.ToString());
                }
#endif
            }
            runtimeValue.num_4_a_std((string)numberString);
            return(runtimeValue.toXMLrecord());
        }
Beispiel #20
0
        public void Convert(DBField sourceField, DBField destinationField, FieldValue sourceValue, FieldValue destinationValue)
        {
            switch ((StorageAttribute)destinationField.Attr)
            {
            case StorageAttribute.ALPHA:
            case StorageAttribute.UNICODE:
                var pic = new PIC(sourceField.Picture, StorageAttribute.NUMERIC, 0);
                destinationValue.Value = DisplayConvertor.Instance.mg2disp(sourceValue.Value.ToString(), null, pic, false, 0, true, false);
                break;

            case StorageAttribute.BOOLEAN:
                NUM_TYPE num = new NUM_TYPE(sourceValue.Value.ToString());
                destinationValue.Value = num.NUM_2_LONG() > 0 ? "1" : "0";
                break;

            case StorageAttribute.NUMERIC:
            case StorageAttribute.DATE:
            case StorageAttribute.TIME:
                destinationValue.Value = sourceValue.Value;
                break;
            }
        }
Beispiel #21
0
        /// <summary>
        ///   creates only a real refresh event command
        /// </summary>
        /// <returns>newly created command.</returns>
        internal static RefreshEventCommand CreateRealRefreshCommand(String taskId, int magicEvent, int currentRow, ArgumentsList argList, int currentRecId)
        {
            RefreshEventCommand cmd = new RefreshEventCommand(magicEvent)
            {
                TaskTag          = taskId,
                RefreshMode      = ViewRefreshMode.CurrentLocation,
                KeepUserSort     = false,
                ClientRecId      = currentRecId,
                CurrentRecordRow = currentRow
            };

            if (argList != null && argList.getSize() != 0)
            {
                try
                {
                    var refreshMode = new NUM_TYPE(argList.getArgValue(0, StorageAttribute.NUMERIC, 0));
                    cmd.RefreshMode = (ViewRefreshMode)refreshMode.NUM_2_LONG() + 1;
                }
                catch (Exception)
                {
                    cmd.RefreshMode = ViewRefreshMode.CurrentLocation;
                }

                if (argList.getSize() > 1)
                {
                    try
                    {
                        cmd.KeepUserSort = (argList.getArgValue(1, StorageAttribute.BOOLEAN, 0) == "1");
                    }
                    catch (Exception)
                    {
                        cmd.KeepUserSort = false;
                    }
                }
            }

            return(cmd);
        }
Beispiel #22
0
        /// <summary>
        /// Converts Magic 'Time' Type to 'dotNetType'
        /// </summary>
        /// <param name="magicVal"></param>
        /// <param name="dotNetType"></param>
        /// <returns></returns>
        private static object convertTimeToDotNet(string magicVal, Type dotNetType)
        {
            Object retObject = null;

            if (dotNetType == typeof(DateTime) || dotNetType == typeof(TimeSpan))
            {
                NUM_TYPE         numType          = new NUM_TYPE(magicVal);
                DisplayConvertor displayConvertor = DisplayConvertor.Instance;

                int time = numType.NUM_2_ULONG();

                // Break time into its components - hour min sec
                DisplayConvertor.TimeBreakParams breakParams = displayConvertor.getNewTimeBreakParams();
                DisplayConvertor.time_break(breakParams, time);
                int hour   = breakParams.hour;
                int minute = breakParams.minute;
                int second = breakParams.second;

                if (dotNetType == typeof(DateTime))
                {
                    DateTime dateTimeObj = new DateTime();

                    dateTimeObj = dateTimeObj.AddHours(hour);
                    dateTimeObj = dateTimeObj.AddMinutes(minute);
                    dateTimeObj = dateTimeObj.AddSeconds(second);

                    retObject = dateTimeObj;
                }
                else if (dotNetType == typeof(TimeSpan))
                {
                    retObject = new TimeSpan(hour, minute, second);
                }
            }

            return(retObject);
        }
Beispiel #23
0
        ///   creates an Index Change event command
        /// </summary>
        /// <returns>newly created command.</returns>
        internal static IndexChangeEventCommand CreateIndexChangeCommand(string taskTag, int recId, ArgumentsList argList)
        {
            IndexChangeEventCommand cmd = new IndexChangeEventCommand
            {
                TaskTag     = taskTag,
                ClientRecId = recId
            };

            // 1 parameter : The new Key Index
            if (argList != null && argList.getSize() != 0)
            {
                try
                {
                    var keyIndex = new NUM_TYPE(argList.getArgValue(0, StorageAttribute.NUMERIC, 0));
                    cmd.KeyIndex = keyIndex.NUM_2_LONG();
                }
                catch (Exception)
                {
                    cmd.KeyIndex = 0;
                }
            }

            return(cmd);
        }
Beispiel #24
0
 /// <summary>
 ///   JCDOW: Japanese version of CDOW
 /// </summary>
 protected internal void eval_op_jcdow(ExpressionEvaluator.ExpVal resVal, NUM_TYPE val1,
                                       DisplayConvertor displayConvertor)
 {
     _expressionEvaluator.eval_op_date_str(resVal, val1, "SSSSSST", displayConvertor);
 }
Beispiel #25
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="itemVal"></param>
        /// <param name="itemAttr"></param>
        /// <returns></returns>
        public static byte[] serializeItemVal(String itemVal, StorageAttribute itemAttr)
        {
            Debug.Assert(itemVal != null);

            string valueSize;
            string tmpBufLen = string.Empty;

            Byte []     tmpBuf            = null;
            List <byte> contentWithLength = new List <byte>();
            int         pos         = 0;
            int         fldValLen   = 0;
            String      tempItemVal = string.Empty;
            int         noOfPackets = 0;

            Byte [] tmpNoOfPackets    = null;
            String  tmpStrNoOfPackets = string.Empty;

            switch (itemAttr)
            {
            case StorageAttribute.NUMERIC:
            case StorageAttribute.DATE:
            case StorageAttribute.TIME:
                NUM_TYPE numType = new NUM_TYPE(itemVal);
                tmpBuf = Misc.ToByteArray(numType.Data);
                break;

            case StorageAttribute.BOOLEAN:
                tmpBuf = Manager.Environment.GetEncoding().GetBytes(itemVal);
                break;

            case StorageAttribute.ALPHA:
                itemVal   = StrUtil.rtrim(itemVal);
                valueSize = (Convert.ToString(UtilStrByteMode.lenB(itemVal), 16)).ToUpper();

                // add leading zeros (if needed)
                for (int j = 0; j < 4 - valueSize.Length; j++)
                {
                    tmpBufLen += "0";
                }
                tmpBufLen += valueSize;

                contentWithLength.AddRange(Manager.Environment.GetEncoding().GetBytes(tmpBufLen));
                contentWithLength.AddRange(Manager.Environment.GetEncoding().GetBytes(itemVal));
                tmpBuf = new byte[contentWithLength.Count];
                contentWithLength.CopyTo(tmpBuf);
                break;

            case StorageAttribute.UNICODE:
                itemVal   = StrUtil.rtrim(itemVal);
                valueSize = (Convert.ToString(itemVal.Length, 16)).ToUpper();

                // add leading zeros (if needed)
                for (int j = 0; j < 4 - valueSize.Length; j++)
                {
                    tmpBufLen += "0";
                }
                tmpBufLen += valueSize;

                contentWithLength.AddRange(Manager.Environment.GetEncoding().GetBytes(tmpBufLen));
                contentWithLength.AddRange(Encoding.Unicode.GetBytes(itemVal));
                tmpBuf = new byte[contentWithLength.Count];
                contentWithLength.CopyTo(tmpBuf);
                break;

            case StorageAttribute.BLOB:
                pos = 0;
                // blob will be serialized in packet of size 0xFFFF.
                // So format of serialized buffer for blob is
                // no. of packets (n) + length1 + data1 + length2 + data2 + ......length n + datan
                fldValLen = ISO_8859_1_Encoding.getInstance().GetByteCount(itemVal);

                noOfPackets = (int)fldValLen / 0xFFFF;

                tmpBufLen      = "FFFF";
                tmpNoOfPackets = Manager.Environment.GetEncoding().GetBytes(tmpBufLen);

                for (int i = 0; i < noOfPackets; i++)
                {
                    tempItemVal = itemVal.Substring(pos, 0xFFFF);
                    pos        += 0xFFFF;
                    contentWithLength.AddRange(tmpNoOfPackets);
                    contentWithLength.AddRange(ISO_8859_1_Encoding.getInstance().GetBytes(tempItemVal));
                }

                int lastPacketSize = fldValLen % 0xFFFF;

                if (lastPacketSize > 0)
                {
                    tempItemVal = itemVal.Substring(pos, (fldValLen) - (pos));
                    byte[] tempItemValBytes = ISO_8859_1_Encoding.getInstance().GetBytes(tempItemVal);

                    tmpBufLen = tempItemValBytes.Length.ToString("X4");
                    contentWithLength.AddRange(Manager.Environment.GetEncoding().GetBytes(tmpBufLen));
                    contentWithLength.AddRange(ISO_8859_1_Encoding.getInstance().GetBytes(tempItemVal));
                    noOfPackets++;
                }

                tmpStrNoOfPackets = noOfPackets.ToString("D4");
                tmpNoOfPackets    = Manager.Environment.GetEncoding().GetBytes(tmpStrNoOfPackets);

                tmpBuf = new byte[contentWithLength.Count + tmpNoOfPackets.Length];

                tmpNoOfPackets.CopyTo(tmpBuf, 0);
                contentWithLength.CopyTo(tmpBuf, tmpNoOfPackets.Length);
                break;
            } //end of the type case block

            return(tmpBuf);
        }
Beispiel #26
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="dbField"></param>
        /// <param name="gatewayValue"></param>
        /// <returns></returns>
        internal override object ConvertRuntimeFieldToGateway(DBField dbField, string runtimeValue)
        {
            NUM_TYPE mgNum = new NUM_TYPE(runtimeValue);

            return(ConvertMgValueToGateway(dbField, mgNum));
        }
Beispiel #27
0
        /// <returns> translation of this argument into Magic URL style (e.g. -Aalpha or -N17 etc.)</returns>
        protected internal void toURL(StringBuilder htmlArgs, bool makePrintable)
        {
            if (!skipArg())
            {
                String           argValue = null, rangeStr = null;
                StorageAttribute attribute = StorageAttribute.NONE;
                bool             isNull    = false;
                PIC      pic = null;
                NUM_TYPE num1, num2;
                Expression.ReturnValue retVal;
                int compIdx = 0;

                // Get the value and attribute and set the "is null" flag according
                // to the argument type
                switch (_type)
                {
                case ConstInterface.ARG_TYPE_VALUE:
                    isNull    = _valueIsNull;
                    attribute = _valueAttr;
                    argValue  = _val;
                    break;

                case ConstInterface.ARG_TYPE_EXP:
                    retVal   = _exp.evaluate(2000);
                    argValue = retVal.mgVal;
                    if (argValue == null)
                    {
                        isNull = true;
                    }
                    else
                    {
                        attribute = retVal.type;
                    }
                    compIdx = _exp.getTask().getCompIdx();
                    break;

                case ConstInterface.ARG_TYPE_FIELD:
                    if (_fld.isNull())
                    {
                        isNull = true;
                    }
                    else
                    {
                        argValue  = _fld.getValue(false);
                        attribute = _fld.getType();
                    }
                    compIdx = _fld.getTask().getCompIdx();
                    break;

                case ConstInterface.ARG_TYPE_SKIP:
                    isNull = true; //#919535 If argument is skipped then pass NULL it will handled in server.
                    break;
                }

                // Create the argument string
                if (isNull)
                {
                    htmlArgs.Append(ConstInterface.REQ_ARG_NULL);
                }
                else
                {
                    switch (attribute)
                    {
                    case StorageAttribute.NUMERIC:
                        num1 = new NUM_TYPE(argValue);
                        num2 = new NUM_TYPE(argValue);
                        num1.round(0);
                        if (NUM_TYPE.num_cmp(num1, num2) == 0)
                        {
                            pic = new PIC("" + UtilStrByteMode.lenB(argValue),
                                          StorageAttribute.ALPHA, compIdx);
                            String numDispVal = num2.to_a(pic).Trim();
                            if (numDispVal.Length <= 9)
                            {
                                htmlArgs.Append(ConstInterface.REQ_ARG_NUMERIC + num2.to_a(pic).Trim());
                            }
                            else
                            {
                                htmlArgs.Append(ConstInterface.REQ_ARG_DOUBLE + num2.to_double());
                            }
                        }
                        else
                        {
                            htmlArgs.Append(ConstInterface.REQ_ARG_DOUBLE + num2.to_double());
                        }
                        break;

                    case StorageAttribute.DATE:
                        pic      = new PIC(Manager.GetDefaultDateFormat(), attribute, compIdx);
                        rangeStr = "";
                        htmlArgs.Append(ConstInterface.REQ_ARG_ALPHA);
                        break;

                    case StorageAttribute.TIME:
                        pic      = new PIC(Manager.GetDefaultTimeFormat(), attribute, compIdx);
                        rangeStr = "";
                        htmlArgs.Append(ConstInterface.REQ_ARG_ALPHA);
                        break;

                    case StorageAttribute.ALPHA:
                    // alpha strings are kept internally as Unicode, so fall through to unicode case...

                    case StorageAttribute.UNICODE:
                        pic      = new PIC("" + UtilStrByteMode.lenB(argValue), attribute, compIdx);
                        rangeStr = "";

                        /* TODO: Kaushal. this should be "-U".
                         * "-U" is currently used for null value.
                         */
                        htmlArgs.Append(ConstInterface.REQ_ARG_UNICODE);
                        break;

                    case StorageAttribute.BLOB:
                        pic      = new PIC("", attribute, compIdx);
                        rangeStr = "";

                        char contentType = BlobType.getContentType(argValue);
                        // ANSI blobs are later translated to Unicode
                        if (contentType == BlobType.CONTENT_TYPE_UNICODE || contentType == BlobType.CONTENT_TYPE_ANSI)
                        {
                            htmlArgs.Append(ConstInterface.REQ_ARG_UNICODE);
                        }
                        else
                        {
                            htmlArgs.Append(ConstInterface.REQ_ARG_ALPHA);
                        }
                        break;

                    case StorageAttribute.BLOB_VECTOR:
                        pic      = new PIC("", attribute, compIdx);
                        rangeStr = "";
                        htmlArgs.Append(ConstInterface.REQ_ARG_ALPHA);
                        //QCR 970794 appending eye catcher for vectors passed as arguments on hyperlink
                        argValue = ConstInterface.MG_HYPER_ARGS + BlobType.removeBlobPrefix(argValue) +
                                   ConstInterface.MG_HYPER_ARGS;
                        break;

                    case StorageAttribute.BOOLEAN:
                        pic      = new PIC("5", attribute, compIdx);
                        rangeStr = "TRUE,FALSE";
                        htmlArgs.Append(ConstInterface.REQ_ARG_LOGICAL);
                        break;
                    }

                    if (attribute != StorageAttribute.NUMERIC)
                    {
                        string finalValue = StrUtil.rtrim(DisplayConvertor.Instance.mg2disp(argValue, rangeStr, pic, compIdx, false));

                        //QCR 970794 converting the url to a legal format
                        htmlArgs.Append(makePrintable
                                    ? GUIManager.Instance.makeURLPrintable(finalValue)
                                    : finalValue);
                    }
                }
            }
        }
Beispiel #28
0
        /// <summary>
        ///   returns the array of indice for an item in the list by comparing the mgVal to the linked value or (-1) if none was
        ///   found
        /// </summary>
        /// <param name = "mgVal">the internal value to look for </param>
        /// <param name = "isVectorValue">Denotes whether the value in mgVal should be treated as a vector (true) or not (false).</param>
        /// <param name = "isNull">true if the value to look for is null </param>
        /// <param name = "extraVals">Additional values, prepended to the searched values.</param>
        /// <param name="extraNums">Additional numeric values to be prepended to the searched values.</param>
        /// <param name = "splitCommaSeperatedVals">to split the val on comma or not </param>
        public int[] getIndexOf(string mgVal, bool isVectorValue, bool isNull, string[] extraVals, NUM_TYPE[] extraNums, bool splitCommaSeperatedVals)
        {
            int      result = NOT_FOUND;
            String   tmpMgVal;
            NUM_TYPE ctrlNumVal;
            String   trimmedVal;

            String[]   vals                = null;
            NUM_TYPE[] nums                = null;
            int        offset              = 0;
            int        firstFitMatchIdx    = NOT_FOUND;
            int        firstFitMatchLength = -1;
            int        minLength           = -1;
            String     compStr             = "";

            int[]    indice = null;
            string[] values = null;

            if (isNull)
            {
                int i = 0;
                indice = new int[1] {
                    NOT_FOUND
                };
                for (i = 0; _nullFlags != null && i < _nullFlags.Length; i++)
                {
                    if (_nullFlags[i])
                    {
                        indice[0] = i;
                        break;
                    }
                }

                return(indice);
            }

            if (!isVectorValue)
            {
                //split the comma separated values;
                if (splitCommaSeperatedVals)
                {
                    values = mgVal.Split(new char[] { ',' });
                }
                else
                {
                    values = new string[] { mgVal }
                };
            }
            else
            {
                VectorType vector = new VectorType(mgVal);
                values = vector.GetCellValues();
            }

            indice = new int[values.Length];

            for (int iCtr = 0; iCtr < values.Length; iCtr++)
            {
                //Initialize result.
                result           = NOT_FOUND;
                firstFitMatchIdx = NOT_FOUND;

                tmpMgVal = values[iCtr];

                if (_isNumericType || extraNums != null)
                {
                    try
                    {
                        ctrlNumVal = new NUM_TYPE(tmpMgVal);
                    }
                    catch (IndexOutOfRangeException)
                    {
                        indice = new int[1];

                        indice[0] = NOT_FOUND;
                        return(indice);
                    }
                    trimmedVal = tmpMgVal;
                }
                else
                {
                    ctrlNumVal = null;
                    trimmedVal = StrUtil.rtrim(tmpMgVal);
                }


                // Run two passes. First one on extra values, second one on values belonging to this object
                for (int i = 0; i < 2 && result == NOT_FOUND; i++)
                {
                    switch (i)
                    {
                    case 0:
                        vals   = extraVals;
                        nums   = extraNums;
                        offset = 0;
                        break;

                    case 1:
                    default:
                        if (_isNumericType || nums != null)
                        {
                            offset = (nums == null ? 0 : nums.Length);
                        }
                        else
                        {
                            offset = (vals == null ? 0 : vals.Length);
                        }
                        vals = _linkVals;
                        nums = _numVals;
                        break;
                    }

                    if (vals != null)
                    {
                        for (int j = 0; j < vals.Length && result == NOT_FOUND; j++)
                        {
                            if (_isNumericType || nums != null)
                            {
                                if (NUM_TYPE.num_cmp(ctrlNumVal, nums[j]) == 0 || (Object)tmpMgVal == (Object)vals[j] ||
                                    tmpMgVal.Equals(vals[j]))
                                {
                                    // the numeric type is found exactly
                                    result = j + offset;
                                    break;
                                }
                            }
                            else
                            {
                                if (vals[j].Equals(tmpMgVal) || trimmedVal.Length > 0 && StrUtil.rtrim(vals[j]).Equals(trimmedVal))
                                {
                                    result = j + offset;
                                    break;
                                }

                                //If Magic sent us a blank value, and such a value exists in the "non DC range" select it.
                                //QCR # 751037 - search for blank values even in the linked values array of the data control
                                if (trimmedVal.Length == 0 && StrUtil.rtrim(vals[j]).Length == 0)
                                {
                                    result = j + offset;
                                    break;
                                }

                                // save the first fitting result
                                // fixed bug#: 935015, the comparison will be according to the min length of the data & the options
                                if (result == NOT_FOUND && trimmedVal.Length > 0)
                                {
                                    minLength = Math.Min(trimmedVal.Length, vals[j].Length);
                                    compStr   = trimmedVal.Substring(0, minLength);
                                    if (compStr.Length > 0 && vals[j].StartsWith(compStr))
                                    {
                                        // if there is a min length match, check if it is the first fit match.
                                        // eg: if list has a,aaa,aaaaa and field value is 'aa' then first fit match is 'aaa'.
                                        // if list is a,aaaaa,aaa and field value is 'aa' then first fit match is 'aaaaa'.
                                        // if first fit not found, then closest match is used (eg- if field value is
                                        // 'aaaaaaaaa' in both the above list, closest match would be 'aaaaa').
                                        if (minLength > firstFitMatchLength)
                                        {
                                            firstFitMatchIdx    = j + offset;
                                            firstFitMatchLength = minLength;
                                        }
                                    }
                                }
                            }
                        }
                    }
                }

                if (result == NOT_FOUND)
                {
                    result = firstFitMatchIdx;
                }

                //store indice found in integer array.
                indice[iCtr] = result;
            }

            return(indice);
        }