/// <summary>
        /// Поиск записи из коллекции.
        /// </summary>
        public static int FindRecordPossition(System.ComponentModel.Component сollection, XPBaseObject record)
        {
            if (record == null)
            {
                return(0);
            }

            if (сollection is XPCollection)
            {
                XPCollection xpCollection = сollection as XPCollection;
                string       propertyName = DBAttribute.GetKey(record.GetType());
                int          idRecord     = (int)record.GetMemberValue(propertyName);

                for (int i = 0; i < xpCollection.Count; i++)
                {
                    XPBaseObject recordInt = (XPBaseObject)xpCollection[i];

                    int idRecordInt = (int)recordInt.GetMemberValue(propertyName);

                    if (idRecordInt == idRecord)
                    {
                        return(i);
                    }
                }
            }
            return(0);
        }
Beispiel #2
0
        void SetMemberValue(XPBaseObject selectedObject, IClassInfoGraphNode classInfoGraphNode,
                            XElement propertyElement)
        {
            var xpMemberInfo = selectedObject.ClassInfo.FindMember(classInfoGraphNode.Name);

            if (xpMemberInfo != null)
            {
                var memberValue = selectedObject.GetMemberValue(classInfoGraphNode.Name);
                if (xpMemberInfo.Converter != null)
                {
                    memberValue = (xpMemberInfo.Converter.ConvertToStorageType(memberValue));
                }
                if (memberValue is byte[])
                {
                    memberValue = Convert.ToBase64String((byte[])memberValue);
                }
                if (memberValue is DateTime)
                {
                    memberValue = ((DateTime)memberValue).Ticks;
                }

                if (memberValue is string)
                {
                    memberValue = IAFModule.SanitizeXmlString((string)memberValue);
                    propertyElement.Add(new XCData(memberValue.ToString()));
                }
                else
                {
                    propertyElement.Value = GetInvariantValue(memberValue);
                }
            }
        }
Beispiel #3
0
 object GetMemberValue(XPBaseObject selectedObject, IClassInfoGraphNode classInfoGraphNode) {
     var memberValue = selectedObject.GetMemberValue(classInfoGraphNode.Name);
     var xpMemberInfo = selectedObject.ClassInfo.GetMember(classInfoGraphNode.Name);
     if (xpMemberInfo.Converter!= null){
         return xpMemberInfo.Converter.ConvertToStorageType(memberValue);
     }
     return memberValue;
 }
Beispiel #4
0
 private decimal GetTempvalue(bool isUnboundColumn, XPBaseObject selectedObject, string columnName)
 {
     return(isUnboundColumn
         ? +Convert.ToDecimal(selectedObject.Evaluate(_gridView.FocusedColumn.UnboundExpression))
         : (columnName.Contains(".")
             ? +Convert.ToDecimal(selectedObject.Evaluate(CriteriaOperator.Parse(columnName)))
             : +Convert.ToDecimal(selectedObject.GetMemberValue(columnName))));
 }
Beispiel #5
0
 public override string GetRuleResult(XPBaseObject instance)
 {
     if (!string.IsNullOrEmpty(属性名称) && (所属方案 != null))
     {
         return(Convert.ToString(instance.GetMemberValue(属性名称)));
     }
     return("");
 }
 public override string GetRuleResult(XPBaseObject instance)
 {
     if (!string.IsNullOrEmpty(属性名称) && (所属方案 != null))
     {
         return Convert.ToString(instance.GetMemberValue(属性名称));
     }
     return "";
 }
Beispiel #7
0
 void CreateRefKeyElements(IEnumerable <IClassInfoGraphNode> serializedClassInfoGraphNodes, XPBaseObject theObject, XElement serializedObjectRefElement)
 {
     foreach (var infoGraphNode in serializedClassInfoGraphNodes.Where(node => node.Key))
     {
         var serializedObjectRefKeyElement = new XElement("Key");
         serializedObjectRefKeyElement.Add(new XAttribute("name", infoGraphNode.Name));
         serializedObjectRefKeyElement.Value = theObject.GetMemberValue(infoGraphNode.Name).ToString();
         serializedObjectRefElement.Add(serializedObjectRefKeyElement);
     }
 }
        void LoadData()
        {
            using (UnitOfWork dataSession = new UnitOfWork(dataStorage)) {
                InitDataDictionary(dataSession);

                XPClassInfo  classCustomer = dataSession.GetClassInfo("", "Customer");
                XPBaseObject customer      = (XPBaseObject)dataSession.FindObject(classCustomer, null);
                IList        orders        = (IList)customer.GetMemberValue("Orders");
            }
        }
Beispiel #9
0
 void ImportProperties(UnitOfWork nestedUnitOfWork, XPBaseObject xpBaseObject, XElement element) {
     ImportSimpleProperties(element, xpBaseObject);
     ImportComplexProperties(element, nestedUnitOfWork,
                             (o, xElement) =>
                             xpBaseObject.SetMemberValue(xElement.Parent.GetAttributeValue("name"), o),
                             NodeType.Object);
     ImportComplexProperties(element, nestedUnitOfWork,
                             (baseObject, element1) =>
                             ((IList) xpBaseObject.GetMemberValue(element1.Parent.GetAttributeValue("name"))).Add(
                                 baseObject), NodeType.Collection);
 }
Beispiel #10
0
 void ImportProperties(IObjectSpace nestedObjectSpace, XPBaseObject xpBaseObject, XElement element)
 {
     ImportSimpleProperties(element, xpBaseObject);
     ImportComplexProperties(element, nestedObjectSpace,
                             (o, xElement) =>
                             xpBaseObject.SetMemberValue(xElement.Parent.GetAttributeValue("name"), o),
                             NodeType.Object);
     ImportComplexProperties(element, nestedObjectSpace,
                             (baseObject, element1) =>
                             ((IList)xpBaseObject.GetMemberValue(element1.Parent.GetAttributeValue("name"))).Add(
                                 baseObject), NodeType.Collection);
 }
Beispiel #11
0
        static void Main(string[] args)
        {
            IDataStore provider = new DevExpress.Xpo.DB.InMemoryDataStore();
            //string connectionString = MSSqlConnectionProvider.GetConnectionString("localhost", "E1139");
            //IDataStore provider = XpoDefault.GetConnectionProvider(connectionString, AutoCreateOption.DatabaseAndSchema);

            XPDictionary dictionary  = new ReflectionDictionary();
            XPClassInfo  myBaseClass = dictionary.GetClassInfo(typeof(MyBaseObject));
            XPClassInfo  myClassA    = dictionary.CreateClass(myBaseClass, "MyObjectA");

            myClassA.CreateMember("ID", typeof(int), new KeyAttribute(true));
            myClassA.CreateMember("Name", typeof(string));

            XpoDefault.Session   = null;
            XpoDefault.DataLayer = new SimpleDataLayer(dictionary, provider);
            //XpoDefault.DataLayer = new ThreadSafeDataLayer(dictionary, provider);

            using (Session session = new Session()) {
                session.UpdateSchema(myClassA);
            }
            using (Session session = new Session()) {
                Console.WriteLine("Create a new object:");
                XPBaseObject obj = (XPBaseObject)myClassA.CreateNewObject(session);
                obj.SetMemberValue("Name", String.Format("sample {0}", DateTime.UtcNow.Ticks));
                obj.Save();
                Console.WriteLine("ID:\t{0}, Name:\t{1}", obj.GetMemberValue("ID"), obj.GetMemberValue("Name"));
            }
            Console.WriteLine("----------------------------");
            using (Session session = new Session()) {
                XPCollection collection = new XPCollection(session, myClassA);
                Console.WriteLine("Objects loaded. Total count: {0}", collection.Count);
                foreach (XPBaseObject obj in collection)
                {
                    Console.WriteLine("ID:\t{0}, Name:\t{1}", obj.GetMemberValue("ID"), obj.GetMemberValue("Name"));
                }
            }
            Console.WriteLine("----------------------------");
            Console.WriteLine("Press Enter to Exit");
            Console.ReadLine();
        }
Beispiel #12
0
 void SetMemberValue(XPBaseObject selectedObject, IClassInfoGraphNode classInfoGraphNode, XElement propertyElement) {
     var memberValue = selectedObject.GetMemberValue(classInfoGraphNode.Name);
     var xpMemberInfo = selectedObject.ClassInfo.FindMember(classInfoGraphNode.Name);
     if (xpMemberInfo != null ) {
         if (xpMemberInfo.Converter != null)
             memberValue = (xpMemberInfo.Converter.ConvertToStorageType(memberValue));
         if (memberValue is byte[])
             memberValue = Convert.ToBase64String((byte[])memberValue);
         if (memberValue is DateTime)
             memberValue = ((DateTime)memberValue).Ticks;
         if (memberValue is string)
             propertyElement.Add(new XCData(memberValue.ToString()));
         else                {
             propertyElement.Value = GetInvariantValue(memberValue);
         }
     }
 }
Beispiel #13
0
        public static List <IFileData> TryGetFileData(UnitOfWork uow, XPBaseObject item, string criteria, int recursiveCount)
        {
            var splitedCriteria       = criteria.Split(new string[] { "].[" }, StringSplitOptions.None);
            var singleCriteria        = splitedCriteria[recursiveCount];
            var splitedSingleCriteria = singleCriteria.Split(new string[] { "[[" }, StringSplitOptions.None);
            var items = item.GetMemberValue(splitedSingleCriteria.FirstOrDefault().ReplaceCriteria());


            if (items is XPBaseCollection)
            {
                var list       = new List <IFileData>();
                var collection = items as XPBaseCollection;
                foreach (XPBaseObject collectionItem in collection)
                {
                    if (splitedSingleCriteria.Count() == 2)
                    {
                        var classInfo  = uow.GetClassInfo(collectionItem);
                        var properties = uow.GetProperties(classInfo);

                        var result = Convert.ToBoolean(new ExpressionEvaluator(properties, CriteriaOperator.Parse(splitedSingleCriteria.LastOrDefault().ReplaceCriteria())).Evaluate(collectionItem) ?? false);
                        if (!result)
                        {
                            continue;
                        }
                    }
                    list.Add(collectionItem.GetMemberValue(splitedCriteria.LastOrDefault().ReplaceCriteria()) as IFileData);
                }

                return(list);
            }
            if (items is IFileData)
            {
                var list = new List <IFileData>()
                {
                    items as IFileData
                };
                return(list);
            }
            if (splitedCriteria.Count() > 1)
            {
                TryGetFileData(uow, items as XPBaseObject, criteria, recursiveCount + 1);
            }
            return(null);
        }
Beispiel #14
0
        private void ExecuteAction(IObjectSpace newFormOs, 单据 fromObject, FlowAction action)
        {
            //action数据是来自于 初始化按钮时的os,它可能不是当前objectspace
            action = ObjectSpace.GetObject(action);
            var os = new NonPersistentObjectSpace(null);


            var toType = ReflectionHelper.FindType(action.To.Form);

            #region 生成目标单据主表属性
            单据 toObject = null;
            //查找当前单据是从那张单据生成过来的
            var record = ObjectSpace.FindObject <单据流程状态记录>(CriteriaOperator.Parse("目标单据=?", CurrentObject.GetMemberValue("Oid").ToString()));

            if (action.目标类型 == 目标类型.生成单据)
            {
                toObject = newFormOs.CreateObject(toType) as 单据;
            }
            else if (action.目标类型 == 目标类型.更新单据)
            {
                var history = ObjectSpace.FindObject <单据流程状态记录>(CriteriaOperator.Parse("来源单据=? and 执行动作.Oid=?", CurrentObject.GetMemberValue("Oid").ToString(), action.Oid));
                if (history != null)
                {
                    //更新动作已经执行过了,不要再执行。
                    return;
                }

                //如果是更新单据,那必然是有已经生成过的单据。
                if (record != null)
                {
                    toObject = newFormOs.GetObject(record.来源单据); // newFormOs.GetObjectByStringKey(action.ToType, record.来源单据) as 单据;
                }
                else
                {
                    return;
                }
                if (toObject == null)
                {
                    return;
                }
            }

            var clsname                    = action.GetFlowLogicClassFullName();
            var actionLogicType            = ReflectionHelper.FindType(clsname);
            IExecuteFlowAction actionLogic = null;
            if (actionLogicType != null)
            {
                actionLogic = Activator.CreateInstance(actionLogicType) as IExecuteFlowAction;
                if (actionLogic != null)
                {
                    actionLogic.ExecuteMasterCore(fromObject, toObject);
                }
            }

            #endregion

            #region 生成目标单据子表记录
            var fromItems  = fromObject.GetMemberValue("明细项目") as XPBaseCollection;
            var toItems    = toObject.GetMemberValue("明细项目") as XPBaseCollection;
            var toItemType = toItems.GetObjectClassInfo().ClassType;
            //来源单据的明细,当前单据
            var detailRecords = new List <Tuple <string, string> >();
            foreach (XPBaseObject item in fromItems)
            {
                //查找记录?
                XPBaseObject toItem = null;
                if (action.目标类型 == 目标类型.更新单据)
                {
                    //如果是更新单据(反写)时,没有找到反写目标明细,则继续。忽略当前条目。
                    //recs可以查到来源明细
                    //
                    var recs = record.明细.FirstOrDefault(x => x.目标 == item.GetMemberValue("Oid").ToString());
                    toItem = (toObject.GetMemberValue("明细项目") as IList).OfType <BaseObject>().FirstOrDefault(x => x.Oid.ToString() == recs.来源);
                    if (toItem == null)
                    {
                        continue;
                    }
                }
                else if (action.目标类型 == 目标类型.生成单据)
                {
                    toItem = newFormOs.CreateObject(toItemType) as XPBaseObject;
                }
                else
                {
                    throw new Exception("未处理的目标类型!");
                }
                toItems.BaseAdd(toItem);

                if (actionLogic != null)
                {
                    actionLogic.ExecuteChildrenCore(item, toItem);
                }
                //foreach (var f in action.ItemsMapping)
                //{
                //    var fromValue = item.Evaluate(f.FromProperty.Name);
                //    toItem.SetMemberValue(f.ToProperty.Name, fromValue);
                //}

                detailRecords.Add(new Tuple <string, string>(item.GetMemberValue("Oid").ToString(), toItem.GetMemberValue("Oid").ToString()));
            }

            #region 生成主表记录
            EventHandler act = null;
            act = (snd, evt) =>
            {
                newFormOs.Committed -= act;
                var process = ObjectSpace.CreateObject <单据流程状态记录>();
                process.来源单据 = this.CurrentObject as 单据;
                process.目标单据 = this.ObjectSpace.GetObject(toObject);

                process.执行动作 = action;
                process.业务项目 = process.来源单据.业务项目;
                foreach (var item in detailRecords)
                {
                    var det = ObjectSpace.CreateObject <单据流程记录明细>();
                    det.来源 = item.Item1;
                    det.目标 = item.Item2;
                    process.明细.Add(det);
                }

                ObjectSpace.CommitChanges();
            };
            newFormOs.Committed += act;
            #endregion

            #endregion

            if (action.自动保存)
            {
                newFormOs.CommitChanges();
            }

            if (action.显示编辑界面)
            {
                var para = new ShowViewParameters();
                para.CreatedView  = Application.CreateDetailView(newFormOs, toObject, true);
                para.TargetWindow = TargetWindow.Default;

                Application.ShowViewStrategy.ShowView(para, new ShowViewSource(this.Frame, this.FlowToNext));
                //e.ShowViewParameters.CreatedView =
            }
        }
        private ASPxEdit GetControlForColumn(IModelColumn column, XPBaseObject item){
            object value = item.GetMemberValue(column.PropertyName);
            ASPxEdit c;
            if (typeof (XPBaseObject).IsAssignableFrom(column.ModelMember.MemberInfo.MemberType)){
                c = RenderHelper.CreateASPxComboBox();
                var helper = new WebLookupEditorHelper(_application, _objectSpace,
                    column.ModelMember.MemberInfo.MemberTypeInfo, column);

                ((ASPxComboBox) c).ClientSideEvents.KeyUp =
                    "function(s, e) { if(e.htmlEvent.keyCode == 46){ s.SetSelectedIndex(-1); } }";
                ((ASPxComboBox) c).ValueType = column.ModelMember.MemberInfo.MemberTypeInfo.KeyMember.MemberType;
                ((ASPxComboBox) c).SelectedIndexChanged += DetailItemControlValueChanged;
                c.Style.Add("min-width", "120px");
                c.Width = new Unit(100, UnitType.Percentage);

                FillEditorValues(value, ((ASPxComboBox) c), helper, item, column.ModelMember);
                if (column.ModelMember.MemberInfo.FindAttribute<ImmediatePostDataAttribute>() != null)
                    ((ASPxComboBox) c).ClientSideEvents.SelectedIndexChanged = "function(s, e) { " + "CallbackPanel" +
                                                                               Model.Id + ".PerformCallback(\"changed_" +
                                                                               column.PropertyName + "_" +
                                                                               item.GetMemberValue(
                                                                                   Model.ModelClass.KeyProperty) +
                                                                               "\"); }";
            }
            else if (typeof (Enum).IsAssignableFrom(column.ModelMember.MemberInfo.MemberType)){
                c = RenderHelper.CreateASPxComboBox();
                ((ASPxComboBox) c).ClientSideEvents.KeyUp =
                    "function(s, e) { if(e.htmlEvent.keyCode == 46){ s.SetSelectedIndex(-1); } }";
                var descriptor = new EnumDescriptor(column.ModelMember.MemberInfo.MemberType);
                var source = (Enum.GetValues(column.ModelMember.MemberInfo.MemberType).Cast<object>()
                    .Select(v => new Tuple<object, string>(v, descriptor.GetCaption(v)))).ToList();
                c.DataSource = source;
                ((ASPxComboBox) c).ValueField = "Item1";
                ((ASPxComboBox) c).TextField = "Item2";
                ((ASPxComboBox) c).ValueType = column.ModelMember.MemberInfo.MemberType;
                ((ASPxComboBox) c).SelectedIndexChanged += DetailItemControlValueChanged;
                c.Style.Add("min-width", "120px");
                c.Width = new Unit(100, UnitType.Percentage);
                c.Load += c_Load;
                if (column.ModelMember.MemberInfo.FindAttribute<ImmediatePostDataAttribute>() != null)
                    ((ASPxComboBox) c).ClientSideEvents.SelectedIndexChanged = "function(s, e) { " + "CallbackPanel" +
                                                                               Model.Id + ".PerformCallback(\"changed_" +
                                                                               column.PropertyName + "_" +
                                                                               item.GetMemberValue(
                                                                                   Model.ModelClass.KeyProperty) +
                                                                               "\"); }";
            }
            else{
                switch (column.ModelMember.MemberInfo.MemberType.ToString()){
                    case "System.Boolean":
                    case "System.bool":
                        c = RenderHelper.CreateASPxCheckBox();
                        ((ASPxCheckBox) c).CheckedChanged += DetailItemControlValueChanged;
                        c.Style.Add("max-width", "20px");
                        if (column.ModelMember.MemberInfo.FindAttribute<ImmediatePostDataAttribute>() != null)
                            ((ASPxCheckBox) c).ClientSideEvents.CheckedChanged = "function(s, e) { " + "CallbackPanel" +
                                                                                 Model.Id +
                                                                                 ".PerformCallback(\"changed_" +
                                                                                 column.PropertyName + "_" +
                                                                                 item.GetMemberValue(
                                                                                     Model.ModelClass.KeyProperty) +
                                                                                 "\"); }";
                        break;
                    case "System.String":
                    case "System.string":
                        c = RenderHelper.CreateASPxTextBox();
                        ((ASPxTextBox) c).MaxLength = 100;
                        if (column.ModelMember.Size > 0)
                            ((ASPxTextBox) c).MaxLength = column.ModelMember.Size;
                        ((ASPxTextBox) c).TextChanged += DetailItemControlValueChanged;
                        if (column.ModelMember.MemberInfo.FindAttribute<ImmediatePostDataAttribute>() != null)
                            ((ASPxTextBox) c).ClientSideEvents.TextChanged = "function(s, e) { " + "CallbackPanel" +
                                                                             Model.Id + ".PerformCallback(\"changed_" +
                                                                             column.PropertyName + "_" +
                                                                             item.GetMemberValue(
                                                                                 Model.ModelClass.KeyProperty) +
                                                                             "\"); }";
                        c.Style.Add("min-width", "130px");
                        break;
                    case "System.Int32":
                    case "System.int":
                    case "System.Int64":
                    case "System.long":
                        c = RenderHelper.CreateASPxSpinEdit();
                        ((ASPxSpinEdit) c).NumberType = SpinEditNumberType.Integer;
                        ((ASPxSpinEdit) c).DecimalPlaces = 0;
                        c.ValueChanged += DetailItemControlValueChanged;
                        if (column.ModelMember.MemberInfo.FindAttribute<ImmediatePostDataAttribute>() != null)
                            ((ASPxSpinEdit) c).ClientSideEvents.NumberChanged = "function(s, e) { " + "CallbackPanel" +
                                                                                Model.Id + ".PerformCallback(\"changed_" +
                                                                                column.PropertyName + "_" +
                                                                                item.GetMemberValue(
                                                                                    Model.ModelClass.KeyProperty) +
                                                                                "\"); }";
                        c.Style.Add("min-width", "100px");
                        break;
                    case "System.Double":
                    case "System.double":
                    case "System.Decimal":
                    case "System.decimal":
                    case "System.Nullable`1[System.Decimal]":
                        c = RenderHelper.CreateASPxSpinEdit();
                        ((ASPxSpinEdit) c).NumberType = SpinEditNumberType.Float;
                        string format = column.ModelMember.DisplayFormat;
                        if (format == "{0:C}") format = null;
                        ((ASPxSpinEdit) c).DisplayFormatString = format;
                        if (string.IsNullOrEmpty(format))
                            ((ASPxSpinEdit) c).DecimalPlaces = 2;
                        c.ValueChanged += DetailItemControlValueChanged;
                        if (column.ModelMember.MemberInfo.FindAttribute<ImmediatePostDataAttribute>() != null)
                            ((ASPxSpinEdit) c).ClientSideEvents.NumberChanged = "function(s, e) { " + "CallbackPanel" +
                                                                                Model.Id + ".PerformCallback(\"changed_" +
                                                                                column.PropertyName + "_" +
                                                                                item.GetMemberValue(
                                                                                    Model.ModelClass.KeyProperty) +
                                                                                "\"); }";
                        c.Style.Add("min-width", "100px");
                        break;
                    case "System.DateTime":
                        c = RenderHelper.CreateASPxDateEdit();
                        ((ASPxDateEdit) c).DateChanged += DetailItemControlValueChanged;
                        if (column.ModelMember.MemberInfo.FindAttribute<ImmediatePostDataAttribute>() != null)
                            ((ASPxDateEdit) c).ClientSideEvents.DateChanged = "function(s, e) { " + "CallbackPanel" +
                                                                              Model.Id + ".PerformCallback(\"changed_" +
                                                                              column.PropertyName + "_" +
                                                                              item.GetMemberValue(
                                                                                  Model.ModelClass.KeyProperty) +
                                                                              "\"); }";
                        c.Style.Add("min-width", "90px");

                        break;
                    default:
                        c = RenderHelper.CreateASPxTextBox();
                        ((ASPxTextBox) c).MaxLength = 100;
                        ((ASPxTextBox) c).TextChanged += DetailItemControlValueChanged;
                        if (column.ModelMember.MemberInfo.FindAttribute<ImmediatePostDataAttribute>() != null)
                            ((ASPxTextBox) c).ClientSideEvents.TextChanged = "function(s, e) { " + "CallbackPanel" +
                                                                             Model.Id + ".PerformCallback(\"changed_" +
                                                                             column.PropertyName + "_" +
                                                                             item.GetMemberValue(
                                                                                 Model.ModelClass.KeyProperty) +
                                                                             "\"); }";
                        c.Style.Add("min-width", "130px");
                        break;
                }
                c.Width = new Unit(100, UnitType.Percentage);
            }

            SetValueToControl(value, c);
            _controls.Add(c);

            OnControlCreated(column.PropertyName, c, item);

            return c;
        }
Beispiel #16
0
 void CreateRefKeyElements(IEnumerable<IClassInfoGraphNode> serializedClassInfoGraphNodes, XPBaseObject theObject, XElement serializedObjectRefElement) {
     foreach (var infoGraphNode in serializedClassInfoGraphNodes.Where(node => node.Key)) {
         var serializedObjectRefKeyElement = new XElement("Key");
         serializedObjectRefKeyElement.Add(new XAttribute("name",infoGraphNode.Name));
         serializedObjectRefKeyElement.Value = theObject.GetMemberValue(infoGraphNode.Name).ToString();
         serializedObjectRefElement.Add(serializedObjectRefKeyElement);
     }
 }
Beispiel #17
0
        private ASPxEdit GetControlForColumn(IModelColumn column, XPBaseObject item)
        {
            object   value = item.GetMemberValue(column.PropertyName);
            ASPxEdit c;

            if (typeof(XPBaseObject).IsAssignableFrom(column.ModelMember.MemberInfo.MemberType))
            {
                c = RenderHelper.CreateASPxComboBox();
                var helper = new WebLookupEditorHelper(_application, _objectSpace,
                                                       column.ModelMember.MemberInfo.MemberTypeInfo, column);

                ((ASPxComboBox)c).ClientSideEvents.KeyUp =
                    "function(s, e) { if(e.htmlEvent.keyCode == 46){ s.SetSelectedIndex(-1); } }";
                ((ASPxComboBox)c).ValueType             = column.ModelMember.MemberInfo.MemberTypeInfo.KeyMember.MemberType;
                ((ASPxComboBox)c).SelectedIndexChanged += DetailItemControlValueChanged;
                c.Style.Add("min-width", "120px");
                c.Width = new Unit(100, UnitType.Percentage);

                FillEditorValues(value, ((ASPxComboBox)c), helper, item, column.ModelMember);
                if (column.ModelMember.MemberInfo.FindAttribute <ImmediatePostDataAttribute>() != null)
                {
                    ((ASPxComboBox)c).ClientSideEvents.SelectedIndexChanged = "function(s, e) { " + "CallbackPanel" +
                                                                              Model.Id + ".PerformCallback(\"changed_" +
                                                                              column.PropertyName + "_" +
                                                                              item.GetMemberValue(
                        Model.ModelClass.KeyProperty) +
                                                                              "\"); }";
                }
            }
            else if (typeof(Enum).IsAssignableFrom(column.ModelMember.MemberInfo.MemberType))
            {
                c = RenderHelper.CreateASPxComboBox();
                ((ASPxComboBox)c).ClientSideEvents.KeyUp =
                    "function(s, e) { if(e.htmlEvent.keyCode == 46){ s.SetSelectedIndex(-1); } }";
                var descriptor = new EnumDescriptor(column.ModelMember.MemberInfo.MemberType);
                var source     = (Enum.GetValues(column.ModelMember.MemberInfo.MemberType).Cast <object>()
                                  .Select(v => new Tuple <object, string>(v, descriptor.GetCaption(v)))).ToList();
                c.DataSource = source;
                ((ASPxComboBox)c).ValueField            = "Item1";
                ((ASPxComboBox)c).TextField             = "Item2";
                ((ASPxComboBox)c).ValueType             = column.ModelMember.MemberInfo.MemberType;
                ((ASPxComboBox)c).SelectedIndexChanged += DetailItemControlValueChanged;
                c.Style.Add("min-width", "120px");
                c.Width = new Unit(100, UnitType.Percentage);
                c.Load += c_Load;
                if (column.ModelMember.MemberInfo.FindAttribute <ImmediatePostDataAttribute>() != null)
                {
                    ((ASPxComboBox)c).ClientSideEvents.SelectedIndexChanged = "function(s, e) { " + "CallbackPanel" +
                                                                              Model.Id + ".PerformCallback(\"changed_" +
                                                                              column.PropertyName + "_" +
                                                                              item.GetMemberValue(
                        Model.ModelClass.KeyProperty) +
                                                                              "\"); }";
                }
            }
            else
            {
                switch (column.ModelMember.MemberInfo.MemberType.ToString())
                {
                case "System.Boolean":
                case "System.bool":
                    c = RenderHelper.CreateASPxCheckBox();
                    ((ASPxCheckBox)c).CheckedChanged += DetailItemControlValueChanged;
                    c.Style.Add("max-width", "20px");
                    if (column.ModelMember.MemberInfo.FindAttribute <ImmediatePostDataAttribute>() != null)
                    {
                        ((ASPxCheckBox)c).ClientSideEvents.CheckedChanged = "function(s, e) { " + "CallbackPanel" +
                                                                            Model.Id +
                                                                            ".PerformCallback(\"changed_" +
                                                                            column.PropertyName + "_" +
                                                                            item.GetMemberValue(
                            Model.ModelClass.KeyProperty) +
                                                                            "\"); }";
                    }
                    break;

                case "System.String":
                case "System.string":
                    c = RenderHelper.CreateASPxTextBox();
                    ((ASPxTextBox)c).MaxLength = 100;
                    if (column.ModelMember.Size > 0)
                    {
                        ((ASPxTextBox)c).MaxLength = column.ModelMember.Size;
                    }
                    ((ASPxTextBox)c).TextChanged += DetailItemControlValueChanged;
                    if (column.ModelMember.MemberInfo.FindAttribute <ImmediatePostDataAttribute>() != null)
                    {
                        ((ASPxTextBox)c).ClientSideEvents.TextChanged = "function(s, e) { " + "CallbackPanel" +
                                                                        Model.Id + ".PerformCallback(\"changed_" +
                                                                        column.PropertyName + "_" +
                                                                        item.GetMemberValue(
                            Model.ModelClass.KeyProperty) +
                                                                        "\"); }";
                    }
                    c.Style.Add("min-width", "130px");
                    break;

                case "System.Int32":
                case "System.int":
                case "System.Int64":
                case "System.long":
                    c = RenderHelper.CreateASPxSpinEdit();
                    ((ASPxSpinEdit)c).NumberType    = SpinEditNumberType.Integer;
                    ((ASPxSpinEdit)c).DecimalPlaces = 0;
                    c.ValueChanged += DetailItemControlValueChanged;
                    if (column.ModelMember.MemberInfo.FindAttribute <ImmediatePostDataAttribute>() != null)
                    {
                        ((ASPxSpinEdit)c).ClientSideEvents.NumberChanged = "function(s, e) { " + "CallbackPanel" +
                                                                           Model.Id + ".PerformCallback(\"changed_" +
                                                                           column.PropertyName + "_" +
                                                                           item.GetMemberValue(
                            Model.ModelClass.KeyProperty) +
                                                                           "\"); }";
                    }
                    c.Style.Add("min-width", "100px");
                    break;

                case "System.Double":
                case "System.double":
                case "System.Decimal":
                case "System.decimal":
                case "System.Nullable`1[System.Decimal]":
                    c = RenderHelper.CreateASPxSpinEdit();
                    ((ASPxSpinEdit)c).NumberType = SpinEditNumberType.Float;
                    string format = column.ModelMember.DisplayFormat;
                    if (format == "{0:C}")
                    {
                        format = null;
                    }
                    ((ASPxSpinEdit)c).DisplayFormatString = format;
                    if (string.IsNullOrEmpty(format))
                    {
                        ((ASPxSpinEdit)c).DecimalPlaces = 2;
                    }
                    c.ValueChanged += DetailItemControlValueChanged;
                    if (column.ModelMember.MemberInfo.FindAttribute <ImmediatePostDataAttribute>() != null)
                    {
                        ((ASPxSpinEdit)c).ClientSideEvents.NumberChanged = "function(s, e) { " + "CallbackPanel" +
                                                                           Model.Id + ".PerformCallback(\"changed_" +
                                                                           column.PropertyName + "_" +
                                                                           item.GetMemberValue(
                            Model.ModelClass.KeyProperty) +
                                                                           "\"); }";
                    }
                    c.Style.Add("min-width", "100px");
                    break;

                case "System.DateTime":
                    c = RenderHelper.CreateASPxDateEdit();
                    ((ASPxDateEdit)c).DateChanged += DetailItemControlValueChanged;
                    if (column.ModelMember.MemberInfo.FindAttribute <ImmediatePostDataAttribute>() != null)
                    {
                        ((ASPxDateEdit)c).ClientSideEvents.DateChanged = "function(s, e) { " + "CallbackPanel" +
                                                                         Model.Id + ".PerformCallback(\"changed_" +
                                                                         column.PropertyName + "_" +
                                                                         item.GetMemberValue(
                            Model.ModelClass.KeyProperty) +
                                                                         "\"); }";
                    }
                    c.Style.Add("min-width", "90px");

                    break;

                default:
                    c = RenderHelper.CreateASPxTextBox();
                    ((ASPxTextBox)c).MaxLength    = 100;
                    ((ASPxTextBox)c).TextChanged += DetailItemControlValueChanged;
                    if (column.ModelMember.MemberInfo.FindAttribute <ImmediatePostDataAttribute>() != null)
                    {
                        ((ASPxTextBox)c).ClientSideEvents.TextChanged = "function(s, e) { " + "CallbackPanel" +
                                                                        Model.Id + ".PerformCallback(\"changed_" +
                                                                        column.PropertyName + "_" +
                                                                        item.GetMemberValue(
                            Model.ModelClass.KeyProperty) +
                                                                        "\"); }";
                    }
                    c.Style.Add("min-width", "130px");
                    break;
                }
                c.Width = new Unit(100, UnitType.Percentage);
            }

            SetValueToControl(value, c);
            _controls.Add(c);

            OnControlCreated(column.PropertyName, c, item);

            return(c);
        }
Beispiel #18
0
        private void CreateRowForObject(XPBaseObject item, bool focusFirstControl, int rowindex)
        {
            _rowsPerObject[item.GetMemberValue(Model.ModelClass.KeyProperty)] = new List <TableRow>();
            var headerRowsForItem = new List <TableRow>();

            if (!HeadersOnTopOnly)
            {
                headerRowsForItem = CreateHeaderRows(item, rowindex);
                _rowsPerObject[item.GetMemberValue(Model.ModelClass.KeyProperty)].AddRange(headerRowsForItem);
            }

            if (_btnAddFirst != null)
            {
                _btnAddFirst.Visible = false;
            }

            TableRow tr = null;

            var controlsOfRowPerColumn = new Dictionary <string, ASPxEdit>();

            int  i = 0;
            int  headerrowsadded     = 0;
            bool firstControlFocused = false;

            foreach (IModelColumn column in Model.Columns)
            {
                if (column.Index >= 0)
                {
                    if (i % ColumnsPerRow == 0)
                    {
                        if (headerRowsForItem.Count > headerrowsadded)
                        {
                            _table.Rows.Add(headerRowsForItem[headerrowsadded]);
                            headerrowsadded++;
                        }
                        tr = new TableRow {
                            CssClass = rowindex % 2 == 0 ? "evenrow" : "oddrow"
                        };
                        _table.Rows.Add(tr);
                        _rowsPerObject[item.GetMemberValue(Model.ModelClass.KeyProperty)].Add(tr);
                    }
                    i++;

                    var tc = new TableCell();
                    if (tr != null)
                    {
                        tr.Cells.Add(tc);
                    }

                    if (!AllowEdit)
                    {
                        object itemGetMemberValue = item.GetMemberValue(column.PropertyName);
                        if (itemGetMemberValue == null)
                        {
                            tc.Text = "";
                        }
                        else if (itemGetMemberValue is XPBaseObject)
                        {
                            ITypeInfo typeInfo =
                                XafTypesInfo.Instance.FindTypeInfo(
                                    (itemGetMemberValue as XPBaseObject).ClassInfo.ClassType);
                            if (typeInfo.DefaultMember != null)
                            {
                                object defMembVal =
                                    (itemGetMemberValue as XPBaseObject).GetMemberValue(typeInfo.DefaultMember.Name);
                                tc.Text = defMembVal != null?defMembVal.ToString() : "";
                            }
                            else
                            {
                                tc.Text = itemGetMemberValue.ToString();
                            }
                        }
                        else if (itemGetMemberValue is Enum)
                        {
                            {
                                string caption =
                                    new EnumDescriptor(column.ModelMember.MemberInfo.MemberType).GetCaption(
                                        itemGetMemberValue);
                                tc.Text = string.IsNullOrEmpty(column.DisplayFormat)
                                    ? caption
                                    : string.Format(column.DisplayFormat, caption);
                            }
                        }
                        else
                        {
                            if (!string.IsNullOrEmpty(column.DisplayFormat))
                            {
                                tc.Text = string.Format(column.DisplayFormat, itemGetMemberValue);
                            }
                            else if (itemGetMemberValue is decimal)
                            {
                                tc.Text = string.Format("{0:C2}", itemGetMemberValue);
                            }
                            else
                            {
                                tc.Text = itemGetMemberValue.ToString();
                            }
                        }

                        tc.CssClass = "StaticText";
                    }
                    else
                    {
                        ASPxEdit cellControl = GetControlForColumn(column, item);
                        if (!column.AllowEdit)
                        {
                            cellControl.Enabled = false;
                        }

                        //handle control width
                        int tableColumns = Math.Max(Model.Columns.Count(c => c.Index >= 0), ColumnsPerRow);
                        if (cellControl is ASPxCheckBox)
                        {
                            tc.Width = new Unit(1, UnitType.Percentage);
                        }
                        else if (tableColumns > 0)
                        {
                            var value = 100 / tableColumns;
                            tc.Width = new Unit(value, UnitType.Percentage);
                        }

                        cellControl.ID = column.PropertyName + "_control_" +
                                         item.GetMemberValue(Model.ModelClass.KeyProperty)
                                         .ToString()
                                         .Replace("-", "_minus_");
                        cellControl.ValidationSettings.ErrorDisplayMode  = ErrorDisplayMode.ImageWithTooltip;
                        cellControl.ValidationSettings.Display           = Display.Dynamic;
                        cellControl.ValidationSettings.ErrorTextPosition = ErrorTextPosition.Left;
                        cellControl.ValidationSettings.ErrorImage.Url    =
                            ImageLoader.Instance.GetImageInfo("ximage").ImageUrl;

                        controlsOfRowPerColumn.Add(column.PropertyName, cellControl);
                        _baseObjectsHandledByControl[cellControl] = new Tuple <XPBaseObject, string>(item,
                                                                                                     column.PropertyName);

                        tc.Controls.Add(cellControl);

                        if (focusFirstControl && !firstControlFocused)
                        {
                            cellControl.Focus();
                            firstControlFocused = true;
                        }
                    }
                    OnCustomizeAppearance(new CustomizeAppearanceEventArgs(column.PropertyName,
                                                                           new WebControlAppearanceAdapter(tc, tc), item));
                }
            }

            if (tr == null)
            {
                tr = new TableRow {
                    CssClass = rowindex % 2 == 0 ? "evenrow" : "oddrow"
                };
                _table.Rows.Add(tr);
                _rowsPerObject[item.GetMemberValue(Model.ModelClass.KeyProperty)].Add(tr);
            }

            var tcButtons = new TableCell {
                Wrap = false, Width = new Unit(1, UnitType.Percentage)
            };

            if (i % ColumnsPerRow != 0)
            {
                tcButtons.ColumnSpan = ColumnsPerRow - i % ColumnsPerRow;
            }
            else
            {
                tr = new TableRow {
                    CssClass = rowindex % 2 == 0 ? "evenrow" : "oddrow"
                };
                _table.Rows.Add(tr);
                _rowsPerObject[item.GetMemberValue(Model.ModelClass.KeyProperty)].Add(tr);
                //a new row will be created and the whole row will be the buttons
                tcButtons.ColumnSpan = ColumnsPerRow;
            }

            tr.Cells.Add(tcButtons);

            var tblButtons = new Table();

            tcButtons.Controls.Add(tblButtons);
            var btnsrow = new TableRow();

            tblButtons.Rows.Add(btnsrow);

            if (AllowEdit && ShowButtons)
            {
                var btnRemove = new ASPxButton {
                    AutoPostBack = false, EnableClientSideAPI = true
                };

                btnRemove.SetClientSideEventHandler("Click",
                                                    "function(s, e) { " + "CallbackPanel" + Model.Id + ".PerformCallback(\"rem_" +
                                                    item.GetMemberValue(Model.ModelClass.KeyProperty) + "\"); }");
                btnRemove.Text = DeleteButtonCaption;
                btnRemove.ID   = "btnRemove_" + item.GetMemberValue(Model.ModelClass.KeyProperty);

                var t = new TableCell();
                btnsrow.Cells.Add(t);
                t.Controls.Add(btnRemove);
            }

            if (AllowEdit && ShowButtons)
            {
                var btnAdd = new ASPxButton {
                    AutoPostBack = false, EnableClientSideAPI = true
                };

                btnAdd.SetClientSideEventHandler("Click",
                                                 "function(s, e) { " + "CallbackPanel" + Model.Id + ".PerformCallback(\"add\"); }");
                btnAdd.Text = AddButtonCaption;
                btnAdd.ID   = "btnAdd_" + item.GetMemberValue(Model.ModelClass.KeyProperty);

                var t = new TableCell();
                btnsrow.Cells.Add(t);
                t.Controls.Add(btnAdd);
            }
            _controlsPerObjectInList[item.GetMemberValue(Model.ModelClass.KeyProperty)] = controlsOfRowPerColumn;
        }
        private void CreateRowForObject(XPBaseObject item, bool focusFirstControl, int rowindex){
            _rowsPerObject[item.GetMemberValue(Model.ModelClass.KeyProperty)] = new List<TableRow>();
            var headerRowsForItem = new List<TableRow>();
            if (!HeadersOnTopOnly){
                headerRowsForItem = CreateHeaderRows(item, rowindex);
                _rowsPerObject[item.GetMemberValue(Model.ModelClass.KeyProperty)].AddRange(headerRowsForItem);
            }

            if (_btnAddFirst != null)
                _btnAddFirst.Visible = false;

            TableRow tr = null;

            var controlsOfRowPerColumn = new Dictionary<string, ASPxEdit>();

            int i = 0;
            int headerrowsadded = 0;
            bool firstControlFocused = false;
            foreach (IModelColumn column in Model.Columns){
                if (column.Index >= 0){
                    if (i%ColumnsPerRow == 0){
                        if (headerRowsForItem.Count > headerrowsadded){
                            _table.Rows.Add(headerRowsForItem[headerrowsadded]);
                            headerrowsadded++;
                        }
                        tr = new TableRow{CssClass = rowindex%2 == 0 ? "evenrow" : "oddrow"};
                        _table.Rows.Add(tr);
                        _rowsPerObject[item.GetMemberValue(Model.ModelClass.KeyProperty)].Add(tr);
                    }
                    i++;

                    var tc = new TableCell();
                    if (tr != null) tr.Cells.Add(tc);

                    if (!AllowEdit){
                        object itemGetMemberValue = item.GetMemberValue(column.PropertyName);
                        if (itemGetMemberValue == null)
                            tc.Text = "";
                        else if (itemGetMemberValue is XPBaseObject){
                            ITypeInfo typeInfo =
                                XafTypesInfo.Instance.FindTypeInfo(
                                    (itemGetMemberValue as XPBaseObject).ClassInfo.ClassType);
                            if (typeInfo.DefaultMember != null){
                                object defMembVal =
                                    (itemGetMemberValue as XPBaseObject).GetMemberValue(typeInfo.DefaultMember.Name);
                                tc.Text = defMembVal != null ? defMembVal.ToString() : "";
                            }
                            else
                                tc.Text = itemGetMemberValue.ToString();
                        }
                        else if (itemGetMemberValue is Enum){
                            {
                                string caption =
                                    new EnumDescriptor(column.ModelMember.MemberInfo.MemberType).GetCaption(
                                        itemGetMemberValue);
                                tc.Text = string.IsNullOrEmpty(column.DisplayFormat)
                                    ? caption
                                    : string.Format(column.DisplayFormat, caption);
                            }
                        }
                        else{
                            if (!string.IsNullOrEmpty(column.DisplayFormat)){
                                tc.Text = string.Format(column.DisplayFormat, itemGetMemberValue);
                            }
                            else if (itemGetMemberValue is decimal){
                                tc.Text = string.Format("{0:C2}", itemGetMemberValue);
                            }
                            else
                                tc.Text = itemGetMemberValue.ToString();
                        }

                        tc.CssClass = "StaticText";
                    }
                    else{
                        ASPxEdit cellControl = GetControlForColumn(column, item);
                        if (!column.AllowEdit)
                            cellControl.Enabled = false;

                        //handle control width
                        int tableColumns = Math.Max(Model.Columns.Count(c => c.Index >= 0), ColumnsPerRow);
                        if (cellControl is ASPxCheckBox){
                            tc.Width = new Unit(1, UnitType.Percentage);
                        }
                        else if (tableColumns>0){
                            var value = 100/tableColumns;
                            tc.Width = new Unit(value, UnitType.Percentage);
                        }

                        cellControl.ID = column.PropertyName + "_control_" +
                                         item.GetMemberValue(Model.ModelClass.KeyProperty)
                                             .ToString()
                                             .Replace("-", "_minus_");
                        cellControl.ValidationSettings.ErrorDisplayMode = ErrorDisplayMode.ImageWithTooltip;
                        cellControl.ValidationSettings.Display = Display.Dynamic;
                        cellControl.ValidationSettings.ErrorTextPosition = ErrorTextPosition.Left;
                        cellControl.ValidationSettings.ErrorImage.Url =
                            ImageLoader.Instance.GetImageInfo("ximage").ImageUrl;

                        controlsOfRowPerColumn.Add(column.PropertyName, cellControl);
                        _baseObjectsHandledByControl[cellControl] = new Tuple<XPBaseObject, string>(item,
                            column.PropertyName);

                        tc.Controls.Add(cellControl);

                        if (focusFirstControl && !firstControlFocused){
                            cellControl.Focus();
                            firstControlFocused = true;
                        }
                    }
                    OnCustomizeAppearance(new CustomizeAppearanceEventArgs(column.PropertyName,
                        new WebControlAppearanceAdapter(tc, tc), item));
                }
            }

            if (tr == null){
                tr = new TableRow{CssClass = rowindex%2 == 0 ? "evenrow" : "oddrow"};
                _table.Rows.Add(tr);
                _rowsPerObject[item.GetMemberValue(Model.ModelClass.KeyProperty)].Add(tr);
            }

            var tcButtons = new TableCell{Wrap = false, Width = new Unit(1, UnitType.Percentage)};

            if (i%ColumnsPerRow != 0){
                tcButtons.ColumnSpan = ColumnsPerRow - i%ColumnsPerRow;
            }
            else{
                tr = new TableRow{CssClass = rowindex%2 == 0 ? "evenrow" : "oddrow"};
                _table.Rows.Add(tr);
                _rowsPerObject[item.GetMemberValue(Model.ModelClass.KeyProperty)].Add(tr);
                //a new row will be created and the whole row will be the buttons
                tcButtons.ColumnSpan = ColumnsPerRow;
            }

            tr.Cells.Add(tcButtons);

            var tblButtons = new Table();
            tcButtons.Controls.Add(tblButtons);
            var btnsrow = new TableRow();
            tblButtons.Rows.Add(btnsrow);

            if (AllowEdit && ShowButtons){
                var btnRemove = new ASPxButton{AutoPostBack = false, EnableClientSideAPI = true};

                btnRemove.SetClientSideEventHandler("Click",
                    "function(s, e) { " + "CallbackPanel" + Model.Id + ".PerformCallback(\"rem_" +
                    item.GetMemberValue(Model.ModelClass.KeyProperty) + "\"); }");
                btnRemove.Text = DeleteButtonCaption;
                btnRemove.ID = "btnRemove_" + item.GetMemberValue(Model.ModelClass.KeyProperty);

                var t = new TableCell();
                btnsrow.Cells.Add(t);
                t.Controls.Add(btnRemove);
            }

            if (AllowEdit && ShowButtons){
                var btnAdd = new ASPxButton{AutoPostBack = false, EnableClientSideAPI = true};

                btnAdd.SetClientSideEventHandler("Click",
                    "function(s, e) { " + "CallbackPanel" + Model.Id + ".PerformCallback(\"add\"); }");
                btnAdd.Text = AddButtonCaption;
                btnAdd.ID = "btnAdd_" + item.GetMemberValue(Model.ModelClass.KeyProperty);

                var t = new TableCell();
                btnsrow.Cells.Add(t);
                t.Controls.Add(btnAdd);
            }
            _controlsPerObjectInList[item.GetMemberValue(Model.ModelClass.KeyProperty)] = controlsOfRowPerColumn;
        }