Пример #1
0
        public BizDataControl CreateEditor(Editor editor, DocDef def)
        {
            BizDataControl result  = null;
            AttrDef        attrDef = null;

            if (def != null)
            {
                if (editor.Attribute_Id != null)
                {
                    attrDef = def.Attributes.FirstOrDefault(a => a.Id == editor.Attribute_Id);
                }
                if (attrDef == null && !String.IsNullOrEmpty(editor.Attribute_Name) && editor.Attribute_Name[0] != '&')
                {
                    attrDef =
                        def.Attributes.FirstOrDefault(
                            a => String.Equals(a.Name, editor.Attribute_Name, StringComparison.OrdinalIgnoreCase));
                }
            }
            if (attrDef != null)
            {
                result = CreateTypeEditor(editor, attrDef);
            }

            /*else
             *  {
             *      if (!editor.Attribute_DefsReference.IsLoaded) editor.Attribute_DefsReference.Load();
             *      if (editor.Attribute_Defs == null) return null;
             *
             *      result = CreateTypeEditor(editor.Attribute_Defs);
             *  }*/

            else
            {
                var attrName = editor.Attribute_Name ?? String.Empty;

                SystemIdent attrIdent;
                if (SystemIdentConverter.TryConvert(attrName, out attrIdent))
                {
                    switch (attrIdent)
                    {
                    case SystemIdent.OrgId:
                    case SystemIdent.OrgName:
                    case SystemIdent.OrgCode:
                    case SystemIdent.State:
//                        case SystemIdent.InState:
                        result = new BizEditText {
                            Ident = attrIdent, ReadOnly = true, AttributeName = attrName
                        };
                        break;

                    case SystemIdent.Id:
                    case SystemIdent.UserId:
                    case SystemIdent.UserName:
                        result = new BizEditText {
                            Ident = attrIdent, ReadOnly = true, AttributeName = attrName
                        };
                        break;

                    case SystemIdent.Created:
                    case SystemIdent.Modified:
                    case SystemIdent.StateDate:
                        result = new BizEditDateTime {
                            Ident = attrIdent, ReadOnly = true, AttributeName = attrName
                        };
                        break;
                    }
                }
            }

            AddChildren(result, editor, def);
            if (result is BizEdit)
            {
                InitEditor((BizEdit)result, editor);
            }
            if (result is BizComboBox)
            {
                InitComboBox(result as BizComboBox, editor, attrDef);
            }

            return(result);
        }
Пример #2
0
        /*[Obsolete("Устаревший метод")]
         * private static BizDataControl CreateTypeEditor(Attribute_Def def)
         * {
         *  BizDataControl result = null;
         *
         *  switch (def.Type_Id)
         *  {
         *      case (short)CissaDataType.Int:
         *          result = new BizEditInt
         *                       {
         *                           MaxValue = Convert.ToInt32(def.Max_Value),
         *                           MinValue = Convert.ToInt32(def.Min_Value),
         *                           MaxLength = (uint?)def.Max_Length ?? 0
         *                       };
         *          break;
         *      case (short)CissaDataType.Float:
         *          result = new BizEditFloat
         *                       {
         *                           MaxValue = Convert.ToInt32(def.Max_Value),
         *                           MinValue = Convert.ToInt32(def.Min_Value),
         *                           MaxLength = (uint?)def.Max_Length ?? 0
         *                       };
         *          break;
         *      case (short)CissaDataType.Currency:
         *          result = new BizEditCurrency
         *                       {
         *                           MaxValue = Convert.ToInt32(def.Max_Value),
         *                           MinValue = Convert.ToInt32(def.Min_Value),
         *                           MaxLength = (uint?)def.Max_Length ?? 0
         *                       };
         *          break;
         *      case (short)CissaDataType.Text:
         *          result = new BizEditText
         *                       {
         *                           MaxLength = (uint?)def.Max_Length ?? 0
         *                       };
         *          break;
         *      case (short)CissaDataType.DateTime:
         *          result = new BizEditDateTime();
         *          break;
         *      case (short)CissaDataType.Bool:
         *          result = new BizEditBool();
         *          break;
         *      case (short)CissaDataType.Enum:
         *          result = new BizComboBox();
         *          break;
         *      case (short)CissaDataType.Organization:
         *          result = new BizEditText {MaxLength = 1000, ReadOnly = true};
         *          break;
         *      case (short)CissaDataType.DocumentState:
         *          result = new BizEditText { MaxLength = 1000, ReadOnly = true};
         *          break;
         *  }
         *
         *  return result;
         * }*/

        private static BizDataControl CreateTypeEditor(Control control, AttrDef def)
        {
            if (def == null)
            {
                return(null);
            }

            BizDataControl result = null;

            switch (def.Type.Id)
            {
            case (short)CissaDataType.Int:
                result = new BizEditInt
                {
                    AttributeDefId = def.Id,
                    AttributeName  = def.Name,
                    MaxValue       = Convert.ToInt32(def.MaxValue),
                    MinValue       = Convert.ToInt32(def.MinValue),
                    MaxLength      = (uint)def.MaxLength
                };
                break;

            case (short)CissaDataType.Float:
                result = new BizEditFloat
                {
                    AttributeDefId = def.Id,
                    AttributeName  = def.Name,
                    MaxValue       = Convert.ToInt32(def.MaxValue),
                    MinValue       = Convert.ToInt32(def.MinValue),
                    MaxLength      = (uint)def.MaxLength
                };
                break;

            case (short)CissaDataType.Currency:
                result = new BizEditCurrency
                {
                    AttributeDefId = def.Id,
                    AttributeName  = def.Name,
                    MaxValue       = Convert.ToInt32(def.MaxValue),
                    MinValue       = Convert.ToInt32(def.MinValue),
                    MaxLength      = (uint)def.MaxLength
                };
                break;

            case (short)CissaDataType.Text:
                result = new BizEditText
                {
                    AttributeDefId = def.Id,
                    AttributeName  = def.Name,
                    MaxLength      = (uint)def.MaxLength
                };
                break;

            case (short)CissaDataType.DateTime:
                result = new BizEditDateTime
                {
                    AttributeDefId = def.Id,
                    AttributeName  = def.Name
                };
                break;

            case (short)CissaDataType.Bool:
                result = new BizEditBool
                {
                    AttributeDefId = def.Id,
                    AttributeName  = def.Name
                };
                break;

            case (short)CissaDataType.Enum:
                result = new BizComboBox
                {
                    AttributeDefId = def.Id,
                    AttributeName  = def.Name
                };
                break;

            case (short)CissaDataType.Organization:
                if (control.Read_Only ?? false)
                {
                    result = new BizEditText
                    {
                        MaxLength      = 800,
                        ReadOnly       = true,
                        AttributeDefId = def.Id,
                        AttributeName  = def.Name
                    }
                }
                ;
                else
                {
                    result = new BizComboBox
                    {
                        AttributeDefId = def.Id,
                        AttributeName  = def.Name
                    }
                };
                break;

            case (short)CissaDataType.DocumentState:
                result = new BizEditText
                {
                    MaxLength      = 800,
                    ReadOnly       = true,
                    AttributeDefId = def.Id,
                    AttributeName  = def.Name
                };
                break;

            case (short)CissaDataType.Blob:
                result = new BizEditFile
                {
                    ReadOnly       = control.Read_Only ?? false,
                    AttributeDefId = def.Id,
                    AttributeName  = def.Name
                };
                break;

            case (short)CissaDataType.User:
                result = new BizComboBox
                {
                    ReadOnly       = control.Read_Only ?? false,
                    AttributeDefId = def.Id,
                    AttributeName  = def.Name
                };
                break;

            case (short)CissaDataType.ClassOfDocument:
            case (short)CissaDataType.AuthorOfDocument:
            case (short)CissaDataType.OrganizationOfDocument:
            case (short)CissaDataType.OrgUnitOfDocument:
            case (short)CissaDataType.StateOfDocument:
            case (short)CissaDataType.DocumentId:
                result = new BizEditText
                {
                    MaxLength      = 800,
                    ReadOnly       = true,
                    AttributeDefId = def.Id,
                    AttributeName  = def.Name
                };
                break;

            case (short)CissaDataType.CreateTimeOfDocument:
                result = new BizEditDateTime
                {
                    ReadOnly       = true,
                    AttributeDefId = def.Id,
                    AttributeName  = def.Name
                };
                break;
            }

            return(result);
        }