示例#1
0
        private ResultBuffer BuildQueryResultBuffer()
        {
            ResultBuffer resultBuffer = new ResultBuffer();

            foreach (DataRow dataRow in this._QueryData.Rows)
            {
                DXFCode dXFCode = new DXFCode(dataRow["Type"].ToString());
                object  obj     = dataRow["Value"];
                if (dXFCode.Code == 62)
                {
                    obj = DXFCode.TranslateColorString(obj.ToString());
                }
                if (DXFCode.IsValidTypedValue(dXFCode.Code, obj.ToString()))
                {
                    TypedValue typedValue = DXFCode.CreateTypedValue(dXFCode.Code, obj.ToString());
                    resultBuffer.Add(typedValue);
                }
            }
            return(resultBuffer);
        }
        public override ValidationResult Validate(object value, CultureInfo cultureInfo)
        {
            BindingGroup  bindingGroup  = (BindingGroup)value;
            StringBuilder stringBuilder = null;

            foreach (object current in bindingGroup.Items)
            {
                DataRowView dataRowView = current as DataRowView;
                if (dataRowView != null)
                {
                    try
                    {
                        DataRow   row    = dataRowView.Row;
                        DataTable table  = row.Table;
                        string    value2 = "";
                        if (!DXFCode.IsValid(dataRowView.Row["Type"].ToString(), ref value2))
                        {
                            stringBuilder = new StringBuilder();
                            stringBuilder.Append(value2);
                            ValidationResult result = new ValidationResult(false, stringBuilder.ToString());
                            return(result);
                        }
                        string text = dataRowView.Row["Type"].ToString();
                        foreach (DataRow dataRow in table.Rows)
                        {
                            if (dataRow != row && dataRow["Type"].ToString() == text)
                            {
                                stringBuilder = new StringBuilder();
                                stringBuilder.Append(AfaStrings.DuplicateTypeCode);
                                ValidationResult result = new ValidationResult(false, stringBuilder.ToString());
                                return(result);
                            }
                        }
                        DXFCode dXFCode = new DXFCode(text);
                        object  obj     = dataRowView.Row["Value"];
                        if (dXFCode.Code == 62)
                        {
                            obj = DXFCode.TranslateColorString(obj.ToString());
                        }
                        if (!DXFCode.IsValidTypedValue(dXFCode.Code, obj.ToString()))
                        {
                            stringBuilder = new StringBuilder();
                            stringBuilder.Append(AfaStrings.CodeDoesNotMatchType);
                            ValidationResult result = new ValidationResult(false, stringBuilder.ToString());
                            return(result);
                        }
                    }
                    catch
                    {
                        stringBuilder = new StringBuilder();
                        stringBuilder.Append(AfaStrings.ErrorInDXFCode);
                        ValidationResult result = new ValidationResult(false, stringBuilder.ToString());
                        return(result);
                    }
                    if (!string.IsNullOrEmpty(dataRowView.Row.RowError))
                    {
                        if (stringBuilder == null)
                        {
                            stringBuilder = new StringBuilder();
                        }
                        stringBuilder.Append(((stringBuilder.Length != 0) ? ", " : "") + dataRowView.Row.RowError);
                    }
                }
            }
            if (stringBuilder != null)
            {
                return(new ValidationResult(false, stringBuilder.ToString()));
            }
            return(ValidationResult.ValidResult);
        }
        public static TypedValue CreateTypedValue(int code, string value)
        {
            if (!DXFCode.IsValidTypedValue(code, value))
            {
                return(new TypedValue(3, value));
            }
            TypedValue result;

            try
            {
                if (code >= -5 && code <= 9)
                {
                    result = new TypedValue(code, value);
                }
                else if (code > 9 && code <= 58)
                {
                    result = new TypedValue(code, double.Parse(value));
                }
                else if (code >= 60 && code <= 99)
                {
                    result = new TypedValue(code, int.Parse(value));
                }
                else if (code >= 100 && code <= 105)
                {
                    result = new TypedValue(code, value);
                }
                else if (code >= 210 && code <= 230)
                {
                    result = new TypedValue(code, double.Parse(value));
                }
                else if (code >= 280 && code <= 289)
                {
                    result = new TypedValue(code, short.Parse(value));
                }
                else if (code >= 290 && code <= 299)
                {
                    result = new TypedValue(code, bool.Parse(value));
                }
                else if (code >= 300 && code <= 309)
                {
                    result = new TypedValue(code, value);
                }
                else if (code >= 310 && code <= 319)
                {
                    result = new TypedValue(code, value);
                }
                else if (code >= 320 && code <= 329)
                {
                    result = new TypedValue(code, value);
                }
                else if (code >= 330 && code <= 339)
                {
                    result = new TypedValue(code, value);
                }
                else if (code >= 340 && code <= 349)
                {
                    result = new TypedValue(code, value);
                }
                else if (code >= 350 && code <= 359)
                {
                    result = new TypedValue(code, value);
                }
                else if (code >= 360 && code <= 369)
                {
                    result = new TypedValue(code, value);
                }
                else if (code >= 370 && code <= 379)
                {
                    result = new TypedValue(code, short.Parse(value));
                }
                else if (code >= 380 && code <= 389)
                {
                    result = new TypedValue(code, short.Parse(value));
                }
                else if (code >= 390 && code <= 399)
                {
                    result = new TypedValue(code, value);
                }
                else if (code >= 400 && code <= 409)
                {
                    result = new TypedValue(code, short.Parse(value));
                }
                else if (code >= 410 && code <= 319)
                {
                    result = new TypedValue(code, value);
                }
                else if (code >= 999 && code <= 1005)
                {
                    result = new TypedValue(code, value);
                }
                else if (code >= 1010 && code <= 1042)
                {
                    result = new TypedValue(code, double.Parse(value));
                }
                else if (code == 1070)
                {
                    result = new TypedValue(code, short.Parse(value));
                }
                else if (code == 1071)
                {
                    result = new TypedValue(code, int.Parse(value));
                }
                else
                {
                    result = new TypedValue(3, value);
                }
            }
            catch
            {
                result = new TypedValue(3, value);
            }
            return(result);
        }