Ejemplo n.º 1
0
        public void ProccesExcellRows( XPObjectSpace objectSpace, DoWorkEventArgs e, Type type){
            var workerArgs = ((WorkerArgs) e.Argument);
            var records = workerArgs.Rows;
            int i = 0;
            var props = objectSpace.FindXPClassInfo(type).PersistentProperties.OfType<XPMemberInfo>().ToList();
            string keyPropertyName = objectSpace.GetKeyPropertyName(type);
            foreach (Row excelRow in records){
                ++i;
                if (i <= workerArgs.HeaderRows) continue;
                if (_bgWorker.CancellationPending){
                    e.Cancel = true;
                    break;
                }


                string message;

                ProcessSingleRow(objectSpace, e, type, keyPropertyName, excelRow, props, i, out message);

                if (i%50 == 0)
                    objectSpace.CommitChanges();

                _bgWorker.ReportProgress(1, message);
                Application.DoEvents();
            }
            objectSpace.CommitChanges();
        }
Ejemplo n.º 2
0
        public void ProccesExcellRows(XPObjectSpace objectSpace, Row[] rows, Type type, int?headerRows, CancellationToken token, Utils.Threading.IProgress <string> progress)
        {
            var    records         = rows;
            int    i               = 0;
            var    props           = objectSpace.FindXPClassInfo(type).PersistentProperties.OfType <XPMemberInfo>().ToList();
            string keyPropertyName = objectSpace.GetKeyPropertyName(type);

            foreach (Row excelRow in records)
            {
                ++i;
                if (i <= headerRows)
                {
                    continue;
                }
                token.ThrowIfCancellationRequested();
                string message;
                ProcessSingleRow(objectSpace, type, keyPropertyName, excelRow, props, i, out message, progress.Report);
                if (i % TransactionSize == 0)
                {
                    objectSpace.CommitChanges();
                    progress.Report(string.Format(Resources.SuccessProcessingRecord, i - 1));
                }
            }
            progress.Report(string.Format(Resources.SuccessProcessingRecord, i - 1));
            objectSpace.CommitChanges();
        }
        public void ProccesExcellRows(IEnumerable<Row> records, XPObjectSpace objectSpace, DoWorkEventArgs e, Type type){
            int i = 0;
            List<XPMemberInfo> props = objectSpace.FindXPClassInfo(type).PersistentProperties
                .OfType<XPMemberInfo>().ToList();

            //get key property name of the object type being imported
            string keyPropertyName = objectSpace.GetKeyPropertyName(type);

            //for every row in excel sheet
            foreach (Row excelRow in records){
                ++i;
                if (i == 1) continue;
                if (_bgWorker.CancellationPending){
                    e.Cancel = true;
                    break;
                }


                string message;

                ProcessSingleRow(objectSpace, e, type, keyPropertyName, excelRow, props, i, out message);

                if (i%50 == 0)
                    objectSpace.CommitChanges();

                _bgWorker.ReportProgress(1, message);
                Application.DoEvents();
            }
            objectSpace.CommitChanges();
        }
Ejemplo n.º 4
0
        void CreateMappedAssemblyInfo(XPObjectSpace objectSpace, IPersistentAssemblyInfo persistentAssemblyInfo, LogonObject logonObject, string[] selectedTables)
        {
            var assemblyInfo = objectSpace.GetObject(persistentAssemblyInfo);

            new AssemblyGenerator(logonObject, assemblyInfo, selectedTables).Create();
            objectSpace.CommitChanges();
        }
Ejemplo n.º 5
0
 public void CreateObjects()
 {
     foreach (var typeInfo in XafTypesInfo.Instance.PersistentTypes.Where(info => typeof(ICustomer).IsAssignableFrom(info.Type)))
     {
         if (!typeInfo.IsPersistent || _objectSpace.FindObject(typeInfo.Type, null) != null)
         {
             continue;
         }
         var dummyDataAttribute = typeInfo.FindAttribute <DummyDataAttribute>();
         if (dummyDataAttribute != null && dummyDataAttribute.Exclude)
         {
             continue;
         }
         CreateObjects(typeInfo);
     }
     _objectSpace.CommitChanges();
 }
Ejemplo n.º 6
0
 public IPersistentAssemblyInfo Build(string customer, string order, string orderLine, string masterDetailDynamicAssembly) {
     var objectSpace = new XPObjectSpace(XafTypesInfo.Instance, XpandModuleBase.XpoTypeInfoSource, () => new UnitOfWork(_session.DataLayer));
     var persistentAssemblyBuilder = PersistentAssemblyBuilder.BuildAssembly(objectSpace, masterDetailDynamicAssembly);
     IClassInfoHandler classInfoHandler = persistentAssemblyBuilder.CreateClasses(GetClassNames(customer, order, orderLine));
     classInfoHandler.CreateTemplateInfos(persistentClassInfo => GetTemplateInfos(persistentClassInfo, customer, order));
     classInfoHandler.SetInheritance(info => GetInheritance(info));
     classInfoHandler.CreateReferenceMembers(classInfo => GetReferenceMembers(classInfo, customer, order, orderLine), true);
     objectSpace.CommitChanges();
     return persistentAssemblyBuilder.PersistentAssemblyInfo;
 }
Ejemplo n.º 7
0
        public IPersistentAssemblyInfo Build(string customer, string order, string orderLine, string masterDetailDynamicAssembly)
        {
            var objectSpace = new XPObjectSpace(XafTypesInfo.Instance, XpandModuleBase.XpoTypeInfoSource, () => new UnitOfWork(_session.DataLayer));
            var persistentAssemblyBuilder      = PersistentAssemblyBuilder.BuildAssembly(objectSpace, masterDetailDynamicAssembly);
            IClassInfoHandler classInfoHandler = persistentAssemblyBuilder.CreateClasses(GetClassNames(customer, order, orderLine));

            classInfoHandler.CreateTemplateInfos(persistentClassInfo => GetTemplateInfos(persistentClassInfo, customer, order));
            classInfoHandler.SetInheritance(info => GetInheritance(info));
            classInfoHandler.CreateReferenceMembers(classInfo => GetReferenceMembers(classInfo, customer, order, orderLine), true);
            objectSpace.CommitChanges();
            return(persistentAssemblyBuilder.PersistentAssemblyInfo);
        }
Ejemplo n.º 8
0
        public void ProccesExcellRows(IEnumerable <Row> records, XPObjectSpace objectSpace, DoWorkEventArgs e, Type type)
        {
            int i = 0;
            List <XPMemberInfo> props = objectSpace.FindXPClassInfo(type).PersistentProperties
                                        .OfType <XPMemberInfo>().ToList();

            //get key property name of the object type being imported
            string keyPropertyName = objectSpace.GetKeyPropertyName(type);

            //for every row in excel sheet
            foreach (Row excelRow in records)
            {
                ++i;
                if (i == 1)
                {
                    continue;
                }
                if (_bgWorker.CancellationPending)
                {
                    e.Cancel = true;
                    break;
                }


                string message;

                ProcessSingleRow(objectSpace, e, type, keyPropertyName, excelRow, props, i, out message);

                if (i % 50 == 0)
                {
                    objectSpace.CommitChanges();
                }

                _bgWorker.ReportProgress(1, message);
                Application.DoEvents();
            }
            objectSpace.CommitChanges();
        }
Ejemplo n.º 9
0
        public void Process()
        {
            objSpace.CommitChanges(); // persist parameters

            var clauses    = CreateSqlParameters();
            var parameters = CreateParameters(clauses);

            using (var cmd = ((SqlConnection)objSpace.Session.Connection).CreateCommand())
            {
                cmd.Parameters.AddRange(parameters.ToArray());
                cmd.CommandText = ProcessCommandText;
                cmd.ExecuteNonQuery();
            }
        }
Ejemplo n.º 10
0
        void createTypes(Type type1, Type type2, PersistentAssemblyBuilder persistentAssemblyBuilder, string type1Name, string type2Name)
        {
            var persistentClassInfo1 = persistentAssemblyBuilder.PersistentAssemblyInfo.PersistentClassInfos[0];
            var persistentClassInfo2 = persistentAssemblyBuilder.PersistentAssemblyInfo.PersistentClassInfos[1];

            addInterface(type1, persistentClassInfo1);
            addInterface(type2, persistentClassInfo2);
            _XPObjectSpace.CommitChanges();

            var compileModule = new CompileEngine().CompileModule(persistentAssemblyBuilder, Path.GetDirectoryName(Application.ExecutablePath));

            _t1Type = compileModule.Assembly.GetTypes().Single(type => type.Name == type1Name);
            _t2Type = compileModule.Assembly.GetTypes().Where(type => type.Name == type2Name).Single();
        }
Ejemplo n.º 11
0
        void CreateMappedAssemblyInfo(XPObjectSpace objectSpace, IPersistentAssemblyInfo persistentAssemblyInfo, ISqlMapperInfo sqlMapperInfo)
        {
            string   connectionString = sqlMapperInfo.GetConnectionString();
            var      sqlConnection    = (SqlConnection) new SimpleDataLayer(XpoDefault.GetConnectionProvider(connectionString, AutoCreateOption.None)).Connection;
            var      server           = new Server(new ServerConnection(sqlConnection));
            Database database         = server.Databases[sqlConnection.Database];

            database.Refresh();
            IPersistentAssemblyInfo assemblyInfo = objectSpace.GetObject(persistentAssemblyInfo);
            var dbMapper = new DbMapper(objectSpace, assemblyInfo, sqlMapperInfo);

            dbMapper.Map(database, sqlMapperInfo.MapperInfo);
            objectSpace.CommitChanges();
        }
Ejemplo n.º 12
0
        public void ProccesExcellRows(XPObjectSpace objectSpace, DoWorkEventArgs e, Type type)
        {
            var    workerArgs      = ((WorkerArgs)e.Argument);
            var    records         = workerArgs.Rows;
            int    i               = 0;
            var    props           = objectSpace.FindXPClassInfo(type).PersistentProperties.OfType <XPMemberInfo>().ToList();
            string keyPropertyName = objectSpace.GetKeyPropertyName(type);

            foreach (Row excelRow in records)
            {
                ++i;
                if (i <= workerArgs.HeaderRows)
                {
                    continue;
                }
                if (_bgWorker.CancellationPending)
                {
                    e.Cancel = true;
                    break;
                }


                string message;

                ProcessSingleRow(objectSpace, e, type, keyPropertyName, excelRow, props, i, out message);

                if (i % 50 == 0)
                {
                    objectSpace.CommitChanges();
                }

                _bgWorker.ReportProgress(1, message);
                Application.DoEvents();
            }
            objectSpace.CommitChanges();
        }
Ejemplo n.º 13
0
        public void Process()
        {
            objSpace.CommitChanges(); // persist parameters

            var clauses    = CreateSqlParameters();
            var parameters = CreateParameters(clauses);

            using (var cmd = ((SqlConnection)objSpace.Session.Connection).CreateCommand())
            {
                cmd.CommandTimeout = CashDiscipline.Common.Constants.SqlCommandTimeout;
                //cmd.Parameters.AddRange(parameters.ToArray());
                //cmd.CommandText = ProcessCommandText;
                cmd.CommandText = "exec dbo.sp_cashflow_reval";
                cmd.ExecuteNonQuery();
            }
        }
Ejemplo n.º 14
0
        public bool Run(RuntimeSetupInfo setupInfo)
        {
            var typesInfo = new TypesInfo();

            typesInfo.AddEntityStore(new NonPersistentEntityStore(typesInfo));
            var reflectionDictionary = new ReflectionDictionary(); reflectionDictionary.CollectClassInfos(typeof(ModuleArtifact).Assembly);
            var xpoTypeInfoSource    = new XpoTypeInfoSource(typesInfo, reflectionDictionary);

            typesInfo.AddEntityStore(xpoTypeInfoSource);
            typesInfo.LoadTypes(typeof(ModuleArtifact).Assembly);
            var exportedTypesFromAssembly = ModuleHelper.CollectExportedTypesFromAssembly(typeof(ModuleArtifact).Assembly, ExportedTypeHelpers.IsExportedType);

            foreach (var type in exportedTypesFromAssembly)
            {
                xpoTypeInfoSource.RegisterEntity(type);
            }

            var objectSpace = new XPObjectSpace(typesInfo, xpoTypeInfoSource, () => new UnitOfWork(reflectionDictionary)
            {
                ConnectionString = setupInfo.ConnectionString
            });

            if (!objectSpace.Contains <ModuleChild>())
            {
                var moduleTypes  = GetModuleTypes(setupInfo);
                var childModules = objectSpace.GetModuleChilds(moduleTypes);
                foreach (var childModule in childModules)
                {
                    childModule.Value.CreateArtifacts(childModule.Key);
                    childModule.Value.CreateExtenderInterfaces(childModule.Key);
                }
                UpdateMapViewModule(childModules, objectSpace);
            }
            CreateObjects(objectSpace, setupInfo);
            objectSpace.CommitChanges();
            return(true);
        }
Ejemplo n.º 15
0
        public bool Run(RuntimeSetupInfo setupInfo) {
            var typesInfo = new TypesInfo();
            typesInfo.AddEntityStore(new NonPersistentEntityStore(typesInfo));
            var reflectionDictionary = new ReflectionDictionary();reflectionDictionary.CollectClassInfos(typeof(ModuleArtifact).Assembly);
            var xpoTypeInfoSource = new XpoTypeInfoSource(typesInfo,reflectionDictionary);
            typesInfo.AddEntityStore(xpoTypeInfoSource);
            typesInfo.LoadTypes(typeof(ModuleArtifact).Assembly);
            var exportedTypesFromAssembly = ModuleHelper.CollectExportedTypesFromAssembly(typeof(ModuleArtifact).Assembly,ExportedTypeHelpers.IsExportedType);
            foreach (var type in exportedTypesFromAssembly){
                xpoTypeInfoSource.RegisterEntity(type);
            }

            var objectSpace = new XPObjectSpace(typesInfo, xpoTypeInfoSource, () => new UnitOfWork(reflectionDictionary){ ConnectionString = setupInfo.ConnectionString });
            if (!objectSpace.Contains<ModuleChild>()){
                var moduleTypes = GetModuleTypes(setupInfo);
                var childModules = objectSpace.GetModuleChilds(moduleTypes);
                foreach (var childModule in childModules){
                    childModule.Value.CreateArtifacts(childModule.Key);
                    childModule.Value.CreateExtenderInterfaces(childModule.Key);
                }
                UpdateMapViewModule(childModules, objectSpace);
            }
            CreateObjects(objectSpace, setupInfo);
            objectSpace.CommitChanges();
            return true;
        }
Ejemplo n.º 16
0
        public void ProccesExcellRows(IEnumerable records, XPObjectSpace objectSpace, DoWorkEventArgs e) {

            var i = 0;

            //for every row in excell sheet
            foreach (Row record in records) {
                ++i;
                if (i == 1) continue;
                if (_BgWorker.CancellationPending) { e.Cancel = true; break; }

                //var os = new ObjectSpace(objectSpace, XafTypesInfo.Instance);
                object newObj = null;

                //chech if row contains Oid

                //get key property name of the object type being imported
                var kp = objectSpace.GetKeyPropertyName(Type);
                //check if it exists in excel and is mapped ?
                var idMapping = ImportMap.Mappings.FirstOrDefault(p => p.MapedTo == kp);
                if (idMapping != null && GetQString(record[idMapping.Column].Value) != string.Empty) {
                    try {
                        //find existing object
                        var val = record[idMapping.Column];
                        var gwid = new Guid(GetQString(val.Value));
                        newObj = objectSpace.FindObject(Type, new BinaryOperator(kp, gwid), true);
                    } catch {

                    }
                }
                if (newObj == null) //create a new instance
                    newObj = objectSpace.CreateObject(Type) as IXPSimpleObject;

                string message;
                if (newObj != null) {
                    var props = ((IXPSimpleObject)newObj).ClassInfo.PersistentProperties
                        .OfType<XPMemberInfo>().ToList();


                    foreach (var mapping in ImportMap.Mappings) {
                        if (_BgWorker.CancellationPending) { e.Cancel = true; break; }
                        Application.DoEvents();

                        var mapping1 = mapping;
                        var prop = props.FirstOrDefault(p => p.Name == mapping1.MapedTo);

                        try {
                            var val = record[mapping.Column];
                            // continue;

                            if (val != null) {
                                //if simple property
                                if (prop.ReferenceType == null && !prop.MemberType.IsEnum) {
                                    var isNullable = prop.MemberType.IsGenericType && prop.MemberType.GetGenericTypeDefinition() == typeof(Nullable<>);
                                    object convertedValue = null;

                                    if (prop.MemberType == null) return;

                                    if (isNullable) {
                                        if (prop.StorageType == typeof(int)) {
                                            int number;
                                            if (val.Value != String.Empty && Int32.TryParse(val.Value, out number))
                                                convertedValue = number;

                                        } else if (prop.StorageType == typeof(DateTime)) {
                                            if (val.Value != string.Empty) {
                                                //Include validate
                                                var dt = DateTime.FromOADate(Convert.ToDouble(val.Value));
                                                convertedValue = dt;
                                            }
                                        } else if (prop.StorageType == typeof(double)) {
                                            double number;
                                            var rez = Double.TryParse(val.Value, out number);
                                            if (rez) convertedValue = number;
                                        }
                                    } else {
                                        if (prop.MemberType.IsEnum) {
                                            prop.SetValue(newObj, Enum.Parse(prop.MemberType, val.Value));
                                        } else if (prop.MemberType == typeof(char))
                                            convertedValue = Convert.ChangeType(GetQString(val.Value), prop.MemberType);
                                        else if (prop.StorageType == typeof(int)) {
                                            int number;
                                            if (val.Value != String.Empty && Int32.TryParse(val.Value, out number))
                                                convertedValue = number;
                                            else
                                                convertedValue = 0;
                                        } else if (prop.MemberType == typeof(Guid))
                                            convertedValue = new Guid(GetQString(val.Value));
                                        else if (prop.StorageType == typeof(DateTime)) {
                                            if (val.Value != string.Empty) {
                                                //Include validate
                                                var dt = DateTime.FromOADate(Convert.ToDouble(val.Value));
                                                convertedValue = dt;
                                            }
                                        } else if (prop.MemberType == typeof(double)) {
                                            double number;
                                            //  Application.CurrentCulture.NumberFormat.NumberDecimalSeparator = ".";
                                            var rez = Double.TryParse(val.Value, NumberStyles.Number, new NumberFormatInfo { NumberDecimalSeparator = "." }, out number);
                                            if (rez) convertedValue = number;
                                        } else if (prop.MemberType == typeof(bool)) {
                                            if (val.Value != string.Empty && (val.Value.Length == 1 || val.Value.ToLower() == "true" || val.Value.ToLower() == "false")) {
                                                bool truefalse;
                                                if (val.Value.ToLower() == "true" || val.Value.ToLower() == "false")
                                                    truefalse = Convert.ToBoolean(val.Value);
                                                else
                                                    truefalse = Convert.ToBoolean(Convert.ToInt32(val.Value));
                                                convertedValue = truefalse;
                                            }
                                        } else
                                            convertedValue = Convert.ChangeType(val.Value, prop.MemberType);
                                    }

                                    if (convertedValue != null) {
                                        if (convertedValue is double)
                                            convertedValue = Math.Round((double)convertedValue, 2, MidpointRounding.ToEven);

                                        prop.SetValue(newObj, convertedValue);
                                    }
                                }
                                //if referenced property
                                if (prop.ReferenceType != null) {

                                    //if other referenced type
                                    if (prop.MemberType.IsSubclassOf(typeof(XPBaseObject))) {
                                        var text = val.Value;
                                        var typ = prop.MemberType;
                                        var mval = ImportWizard.Helper.GetXpObjectByKeyValue(objectSpace, text, typ);
                                        prop.SetValue(newObj, objectSpace.GetObject(mval));
                                    }
                                }

                            }

                        } catch (Exception ee) {
                            message = string.Format(Resources.ExcelImportWizard_ProccesExcellRows_Error_processing_record__0____1_, i - 1, ee);
                            _BgWorker.ReportProgress(0, message);
                        }

                        if (CurrentCollectionSource != null)
                            AddNewObjectToCollectionSource(CurrentCollectionSource, newObj, ObjectSpace);
                        ObjectSpace.Session.Save(newObj);
                    }
                }

                objectSpace.CommitChanges();
                message = string.Format(Resources.ExcelImportWizard_ProccesExcellRows_Importing_record__0__succesfull_, i - 1);
                _BgWorker.ReportProgress(1, message);
                Application.DoEvents();
            }
        }
Ejemplo n.º 17
0
        public void ProccesExcellRows(IEnumerable records, XPObjectSpace objectSpace, DoWorkEventArgs e)
        {
            var i = 0;

            //for every row in excell sheet
            foreach (Row record in records)
            {
                ++i;
                if (i == 1)
                {
                    continue;
                }
                if (_BgWorker.CancellationPending)
                {
                    e.Cancel = true; break;
                }

                //var os = new ObjectSpace(objectSpace, XafTypesInfo.Instance);
                object newObj = null;

                //chech if row contains Oid

                //get key property name of the object type being imported
                var kp = objectSpace.GetKeyPropertyName(Type);
                //check if it exists in excel and is mapped ?
                var idMapping = ImportMap.Mappings.FirstOrDefault(p => p.MapedTo == kp);
                if (idMapping != null && GetQString(record[idMapping.Column].Value) != string.Empty)
                {
                    try {
                        //find existing object
                        var val  = record[idMapping.Column];
                        var gwid = new Guid(GetQString(val.Value));
                        newObj = objectSpace.FindObject(Type, new BinaryOperator(kp, gwid), true);
                    } catch {
                    }
                }
                if (newObj == null) //create a new instance
                {
                    newObj = objectSpace.CreateObject(Type) as IXPSimpleObject;
                }

                string message;
                if (newObj != null)
                {
                    var props = ((IXPSimpleObject)newObj).ClassInfo.PersistentProperties
                                .OfType <XPMemberInfo>().ToList();


                    foreach (var mapping in ImportMap.Mappings)
                    {
                        if (_BgWorker.CancellationPending)
                        {
                            e.Cancel = true; break;
                        }
                        Application.DoEvents();

                        var mapping1 = mapping;
                        var prop     = props.FirstOrDefault(p => p.Name == mapping1.MapedTo);

                        try {
                            var val = record[mapping.Column];
                            // continue;

                            if (val != null)
                            {
                                //if simple property
                                if (prop.ReferenceType == null && !prop.MemberType.IsEnum)
                                {
                                    var    isNullable     = prop.MemberType.IsGenericType && prop.MemberType.GetGenericTypeDefinition() == typeof(Nullable <>);
                                    object convertedValue = null;

                                    if (prop.MemberType == null)
                                    {
                                        return;
                                    }

                                    if (isNullable)
                                    {
                                        if (prop.StorageType == typeof(int))
                                        {
                                            int number;
                                            if (val.Value != String.Empty && Int32.TryParse(val.Value, out number))
                                            {
                                                convertedValue = number;
                                            }
                                        }
                                        else if (prop.StorageType == typeof(DateTime))
                                        {
                                            if (val.Value != string.Empty)
                                            {
                                                //Include validate
                                                var dt = DateTime.FromOADate(Convert.ToDouble(val.Value));
                                                convertedValue = dt;
                                            }
                                        }
                                        else if (prop.StorageType == typeof(double))
                                        {
                                            double number;
                                            var    rez = Double.TryParse(val.Value, out number);
                                            if (rez)
                                            {
                                                convertedValue = number;
                                            }
                                        }
                                    }
                                    else
                                    {
                                        if (prop.MemberType.IsEnum)
                                        {
                                            prop.SetValue(newObj, Enum.Parse(prop.MemberType, val.Value));
                                        }
                                        else if (prop.MemberType == typeof(char))
                                        {
                                            convertedValue = Convert.ChangeType(GetQString(val.Value), prop.MemberType);
                                        }
                                        else if (prop.StorageType == typeof(int))
                                        {
                                            int number;
                                            if (val.Value != String.Empty && Int32.TryParse(val.Value, out number))
                                            {
                                                convertedValue = number;
                                            }
                                            else
                                            {
                                                convertedValue = 0;
                                            }
                                        }
                                        else if (prop.MemberType == typeof(Guid))
                                        {
                                            convertedValue = new Guid(GetQString(val.Value));
                                        }
                                        else if (prop.StorageType == typeof(DateTime))
                                        {
                                            if (val.Value != string.Empty)
                                            {
                                                //Include validate
                                                var dt = DateTime.FromOADate(Convert.ToDouble(val.Value));
                                                convertedValue = dt;
                                            }
                                        }
                                        else if (prop.MemberType == typeof(double))
                                        {
                                            double number;
                                            //  Application.CurrentCulture.NumberFormat.NumberDecimalSeparator = ".";
                                            var rez = Double.TryParse(val.Value, NumberStyles.Number, new NumberFormatInfo {
                                                NumberDecimalSeparator = "."
                                            }, out number);
                                            if (rez)
                                            {
                                                convertedValue = number;
                                            }
                                        }
                                        else if (prop.MemberType == typeof(bool))
                                        {
                                            if (val.Value != string.Empty && (val.Value.Length == 1 || val.Value.ToLower() == "true" || val.Value.ToLower() == "false"))
                                            {
                                                bool truefalse;
                                                if (val.Value.ToLower() == "true" || val.Value.ToLower() == "false")
                                                {
                                                    truefalse = Convert.ToBoolean(val.Value);
                                                }
                                                else
                                                {
                                                    truefalse = Convert.ToBoolean(Convert.ToInt32(val.Value));
                                                }
                                                convertedValue = truefalse;
                                            }
                                        }
                                        else
                                        {
                                            convertedValue = Convert.ChangeType(val.Value, prop.MemberType);
                                        }
                                    }

                                    if (convertedValue != null)
                                    {
                                        if (convertedValue is double)
                                        {
                                            convertedValue = Math.Round((double)convertedValue, 2, MidpointRounding.ToEven);
                                        }

                                        prop.SetValue(newObj, convertedValue);
                                    }
                                }
                                //if referenced property
                                if (prop.ReferenceType != null)
                                {
                                    //if other referenced type
                                    if (prop.MemberType.IsSubclassOf(typeof(XPBaseObject)))
                                    {
                                        var text = val.Value;
                                        var typ  = prop.MemberType;
                                        var mval = ImportWizard.Helper.GetXpObjectByKeyValue(objectSpace, text, typ);
                                        prop.SetValue(newObj, objectSpace.GetObject(mval));
                                    }
                                }
                            }
                        } catch (Exception ee) {
                            message = string.Format(Resources.ExcelImportWizard_ProccesExcellRows_Error_processing_record__0____1_, i - 1, ee);
                            _BgWorker.ReportProgress(0, message);
                        }

                        if (CurrentCollectionSource != null)
                        {
                            AddNewObjectToCollectionSource(CurrentCollectionSource, newObj, ObjectSpace);
                        }
                        ObjectSpace.Session.Save(newObj);
                    }
                }

                objectSpace.CommitChanges();
                message = string.Format(Resources.ExcelImportWizard_ProccesExcellRows_Importing_record__0__succesfull_, i - 1);
                _BgWorker.ReportProgress(1, message);
                Application.DoEvents();
            }
        }
Ejemplo n.º 18
0
        public static void CalculateCashFlow(XPObjectSpace objSpace, DateTime fromDate, DateTime toDate, IList <CashFlowSnapshot> snapshots)
        {
            // delete cash flows within the date range
            CriteriaOperator deleteCriteria = CriteriaOperator.Parse("TranDate Between (?, ?) And LineType = ?",
                                                                     fromDate, toDate, AccountSummaryLineType.Flow);
            var snapshotOids = GetOidsFromSnapshots(snapshots);

            deleteCriteria = deleteCriteria & new InOperator("Snapshot.Oid", snapshotOids);
            objSpace.Session.Delete(objSpace.GetObjects <AccountSummary>(deleteCriteria));

            // get currenet snapshot GUID
            var curSnapshotOid = SetOfBooks.CachedInstance.CurrentCashFlowSnapshot.Oid;

            // add cash flows to AccountSummary
            var maxActualDate            = CashFlow.GetMaxActualTranDate(objSpace.Session); // TODO: why default(DateTime)?
            XPQuery <CashFlow> cashFlows = new XPQuery <CashFlow>(((XPObjectSpace)objSpace).Session);

            foreach (Guid snapshotOid in snapshotOids)
            {
                IQueryable <CashFlowGrouped> cfQuery = null;
                if (snapshotOid != curSnapshotOid)
                {
                    // previous snapshot
                    if (maxActualDate == default(DateTime))
                    {
                        // exclude max actual date from query
                        cfQuery = from c in cashFlows
                                  where c.TranDate >= fromDate && c.TranDate <= toDate &&
                                  (c.Snapshot.Oid == curSnapshotOid &&
                                   c.Status == CashFlowStatus.Actual
                                   ||
                                   c.Snapshot.Oid == snapshotOid
                                   // && c.TranDate > maxActualDate
                                  )
                                  orderby c.TranDate ascending
                                  group c by new { c.TranDate, c.Account } into grp
                            select new CashFlowGrouped(
                            grp.Key.TranDate,
                            grp.Key.Account,
                            (decimal)grp.Sum(c => c.AccountCcyAmt)
                            );
                    }
                    else
                    {
                        cfQuery = from c in cashFlows
                                  where c.TranDate >= fromDate && c.TranDate <= toDate &&
                                  (c.Snapshot.Oid == curSnapshotOid &&
                                   c.Status == CashFlowStatus.Actual
                                   ||
                                   c.Snapshot.Oid == snapshotOid &&
                                   c.TranDate > maxActualDate
                                  )
                                  orderby c.TranDate ascending
                                  group c by new { c.TranDate, c.Account } into grp
                            select new CashFlowGrouped(
                            grp.Key.TranDate,
                            grp.Key.Account,
                            (decimal)grp.Sum(c => c.AccountCcyAmt)
                            );
                    }
                }
                else
                {
                    // current snapshot
                    cfQuery = from c in cashFlows
                              where c.TranDate >= fromDate && c.TranDate <= toDate &&
                              c.Snapshot.Oid == snapshotOid
                              orderby c.TranDate ascending
                              group c by new { c.TranDate, c.Account } into grp
                        select new CashFlowGrouped(
                        grp.Key.TranDate,
                        grp.Key.Account,
                        (decimal)grp.Sum(c => c.AccountCcyAmt)
                        );
                }

                foreach (var cfItem in cfQuery)
                {
                    var summary = objSpace.CreateObject <AccountSummary>();
                    summary.Snapshot      = objSpace.GetObjectByKey <CashFlowSnapshot>(snapshotOid);
                    summary.TranDate      = cfItem.TranDate;
                    summary.Account       = cfItem.Account;
                    summary.AccountCcyAmt = cfItem.AccountCcyAmt;
                    summary.LineType      = AccountSummaryLineType.Flow;
                }
            }
            objSpace.CommitChanges();
        }
Ejemplo n.º 19
0
        public static void CalculateBalance(XPObjectSpace objSpace, DateTime atDate, IList <CashFlowSnapshot> snapshots)
        {
            // delete balances matching the specified date
            CriteriaOperator deleteCriteria = Fields.TranDate == atDate & Fields.LineType == new OperandValue(AccountSummaryLineType.Balance);
            var snapshotOids = GetOidsFromSnapshots(snapshots);

            deleteCriteria = deleteCriteria & new InOperator(AccountSummary.Fields.SnapshotOid.PropertyName, snapshotOids);
            objSpace.Session.Delete(objSpace.GetObjects <AccountSummary>(deleteCriteria));

            // get currenet snapshot GUID
            var curSnapshotOid = SetOfBooks.CachedInstance.CurrentCashFlowSnapshot.Oid;

            // add balances to Account Summary
            var maxActualDate            = CashFlow.GetMaxActualTranDate(objSpace.Session);
            XPQuery <CashFlow> cashFlows = new XPQuery <CashFlow>(((XPObjectSpace)objSpace).Session);

            foreach (Guid snapshotOid in snapshotOids)
            {
                IQueryable <CashBalanceGrouped> cfGrouped = null;

                if (snapshotOid != curSnapshotOid)
                {
                    // previous snapshot
                    if (maxActualDate == default(DateTime))
                    {
                        cfGrouped = from c in cashFlows
                                    where c.TranDate <= atDate &&
                                    (
                            c.Snapshot.Oid == snapshotOid
                            //&& c.TranDate > maxActualDate
                            || c.Snapshot.Oid == curSnapshotOid &&
                            c.Status == CashFlowStatus.Actual
                                    )
                                    group c by new { c.Account } into grp
                            select new CashBalanceGrouped(
                            grp.Key.Account,
                            (decimal)grp.Sum(c => c.AccountCcyAmt)
                            );
                    }
                    else
                    {
                        cfGrouped = from c in cashFlows
                                    where c.TranDate <= atDate &&
                                    (
                            c.Snapshot.Oid == snapshotOid &&
                            c.TranDate > maxActualDate ||
                            c.Snapshot.Oid == curSnapshotOid &&
                            c.Status == CashFlowStatus.Actual
                                    )
                                    group c by new { c.Account } into grp
                            select new CashBalanceGrouped(
                            grp.Key.Account,
                            (decimal)grp.Sum(c => c.AccountCcyAmt)
                            );
                    }
                }
                else
                {
                    // current snapshot

                    cfGrouped = from c in cashFlows
                                where c.TranDate <= atDate && c.Snapshot.Oid == snapshotOid
                                group c by new { c.Account } into grp
                        select new CashBalanceGrouped(
                        grp.Key.Account,
                        (decimal)grp.Sum(c => c.AccountCcyAmt)
                        );
                }

                if (cfGrouped == null)
                {
                    return;
                }
                foreach (var cfItem in cfGrouped)
                {
                    var summary = objSpace.CreateObject <AccountSummary>();
                    summary.Snapshot      = objSpace.GetObjectByKey <CashFlowSnapshot>(snapshotOid);
                    summary.TranDate      = atDate;
                    summary.Account       = cfItem.Account;
                    summary.AccountCcyAmt = cfItem.AccountCcyAmt;
                    summary.LineType      = AccountSummaryLineType.Balance;
                }
            }
            objSpace.CommitChanges();
        }