예제 #1
0
        private string ImportFXRates(DataSet ds)
        {
            string res = String.Empty;

            //курсы пишутся через механизм импорта;
            //т.к. максимальное количество параметров в SQL запросе 2100, то пишется кусками по 1000 строк
            const int pageSize = 1000;
            DataSet   tempDataSet;
            DataTable tempDataTable;

            FormModel model = FormModelRepository.GetFormModel("FXRate", FormModelType.ImportExport);

            ds.Tables[0].Columns[CurrencyCodeColumnName].ColumnName = "Currency";
            ds.Tables[0].TableName = model.Caption.Replace(" ", "_");
            for (int i = 0; i < ds.Tables[0].Rows.Count; i = i + pageSize)
            {
                tempDataSet             = new DataSet();
                tempDataTable           = new DataTable();
                tempDataTable           = ds.Tables[0].AsEnumerable().Skip(i).Take(pageSize).CopyToDataTable();
                tempDataTable.TableName = ds.Tables[0].TableName;
                tempDataSet.Tables.Add(tempDataTable);

                ImportResult result = ImportExportHelper.Import(model.MainViewName, tempDataSet);
                res += result.GetReport(new ImportResultTextFormatter()) + Environment.NewLine;
            }

            return(res);
        }
예제 #2
0
        private void SetShowImportExportOptions(MetaFormModel form)
        {
            var model = FormModelRepository.GetFormModel(form.Id, FormModelType.All);

            if (model.IsEmpty || string.IsNullOrEmpty(model.MainViewName))
            {
                return;
            }

            var viewNames = model.Blocks.Select(b => b.ViewName).Distinct().ToList();

            using (var context = Settings.CreateDataContext())
            {
                var containsForbidden = context.MetaView.Any(mv => !mv.MasterEntity.IsAvailableForImportExport && viewNames.Contains(mv.Name));

                form.ShowImportExportOptions = !containsForbidden;
            }
        }
예제 #3
0
파일: Budget.cs 프로젝트: ljxu1/DWKit
        public void DeleteEntityByForms(string columnName, object valueId, List <string> formNames)
        {
            if (formNames == null)
            {
                return;
            }

            var replaceIds = new Dictionary <object, object>();
            var mdRep      = new MetadataRepositoty();

            foreach (var formName in formNames)
            {
                var form = FormModelRepository.GetFormModel(formName, FormModelType.All);

                EntityMetadata md      = mdRep.GetEntityMetadataByViewName(form.MainViewName);
                List <dynamic> records = md.Get(FilterCriteriaSet.And.Equal(valueId, columnName), ExternalMethodsCallMode.None);

                DynamicRepository.DeleteByView(md.Name, records.Select(c => (c as DynamicEntity).GetId()).ToList(), false);
            }
        }
예제 #4
0
파일: Budget.cs 프로젝트: ljxu1/DWKit
        public Dictionary <string, Dictionary <object, object> > CopyEntityByForms(string columnName, object fromId, object toId, List <string> formNames, Dictionary <string, FilterCriteriaSet> filters)
        {
            var replaceIds = new Dictionary <string, Dictionary <object, object> >();
            var formList   = new List <FormModel>();

            var mdRep = new MetadataRepositoty();

            #region Вставка основной записи
            foreach (var formName in formNames)
            {
                var form = FormModelRepository.GetFormModel(formName, FormModelType.All);

                EntityMetadata md = mdRep.GetEntityMetadataByViewName(form.MainViewName);

                var filter = FilterCriteriaSet.And.Equal(fromId, columnName);
                if (filters.ContainsKey(form.MainViewName))
                {
                    filter = filter.Merge(filters[form.MainViewName]);
                }

                List <dynamic> records = md.Get(filter, ExternalMethodsCallMode.None);

                foreach (DynamicEntity r in records)
                {
                    var oldId = r[md.PrimaryKeyAttribute.ColumnName];
                    md.SetNewPrimaryKey(r);
                    if (!replaceIds.ContainsKey(md.TableName))
                    {
                        replaceIds.Add(md.TableName, new Dictionary <object, object>());
                    }

                    replaceIds[md.TableName].Add(oldId, r[md.PrimaryKeyAttribute.ColumnName]);
                    r[columnName] = toId;
                }

                md.Insert(records, ExternalMethodsCallMode.None);
                formList.Add(form);
            }
            #endregion

            #region Вставка дочерних и обновленеи ids
            foreach (var form in formList)
            {
                EntityMetadata md         = mdRep.GetEntityMetadataByViewName(form.MainViewName);
                var            replaceAtt = md.Attributes.Where(c => !string.IsNullOrEmpty(c.ReferencedTableName) &&
                                                                replaceIds.ContainsKey(c.ReferencedTableName)).ToList();

                if (form.Blocks.Where(c => !string.IsNullOrWhiteSpace(c.BaseEntityIdName)).Count() == 1 &&
                    replaceAtt.Count == 0)
                {
                    continue;
                }

                var filter1 = FilterCriteriaSet.And.Equal(toId, columnName);
                if (filters.ContainsKey(form.MainViewName))
                {
                    filter1 = filter1.Merge(filters[form.MainViewName]);
                }

                List <dynamic> records = md.Get(filter1, ExternalMethodsCallMode.None);

                foreach (DynamicEntity r in records)
                {
                    foreach (AttributeDescription rAtt in replaceAtt)
                    {
                        var replaceIdsForTable = replaceIds[rAtt.ReferencedTableName];
                        if (r[rAtt.PropertyName] != null && replaceIdsForTable.ContainsKey(r[rAtt.PropertyName]))
                        {
                            r[rAtt.PropertyName] = replaceIdsForTable[r[rAtt.PropertyName]];
                        }
                    }

                    #region Создаем записи в дочерних таблицах
                    foreach (var block in form.Blocks.Where(c => form.MainViewName != c.ViewName &&
                                                            !string.IsNullOrWhiteSpace(c.BaseEntityIdName)))
                    {
                        EntityMetadata blockMd = mdRep.GetEntityMetadataByViewName(block.ViewName);
                        if (md.TableName == blockMd.TableName)
                        {
                            continue;
                        }

                        object oldParentEntityId = replaceIds[md.TableName].Where(c => c.Value.Equals(r.GetId())).Select(c => c.Key).First();

                        var filter2 = FilterCriteriaSet.And.Equal(oldParentEntityId, block.BaseEntityIdName);
                        if (filters.ContainsKey(block.ViewName))
                        {
                            filter2 = filter2.Merge(filters[block.ViewName]);
                        }

                        List <dynamic> blockRecords = blockMd.Get(filter2, ExternalMethodsCallMode.None);

                        foreach (DynamicEntity blockR in blockRecords)
                        {
                            var oldId = blockR[blockMd.PrimaryKeyAttribute.ColumnName];
                            blockMd.SetNewPrimaryKey(blockR);
                            if (!replaceIds.ContainsKey(blockMd.TableName))
                            {
                                replaceIds.Add(blockMd.TableName, new Dictionary <object, object>());
                            }

                            replaceIds[blockMd.TableName].Add(oldId, blockR[blockMd.PrimaryKeyAttribute.ColumnName]);

                            var replaceAttForBlock = blockMd.Attributes.Where(c => !string.IsNullOrEmpty(c.ReferencedTableName) &&
                                                                              replaceIds.ContainsKey(c.ReferencedTableName)).ToList();

                            foreach (AttributeDescription rAtt in replaceAttForBlock)
                            {
                                var replaceIdsForTable = replaceIds[rAtt.ReferencedTableName];
                                if (replaceIdsForTable.ContainsKey(blockR[rAtt.PropertyName]))
                                {
                                    blockR[rAtt.PropertyName] = replaceIdsForTable[blockR[rAtt.PropertyName]];
                                }
                            }
                        }

                        blockMd.Insert(blockRecords, ExternalMethodsCallMode.None);
                    }
                    #endregion
                }

                md.Update(records, ExternalMethodsCallMode.None);
            }

            return(replaceIds);

            #endregion
        }