Пример #1
0
        private void btnRemove_Click(object sender, EventArgs e)
        {
            var selectedItem = cboxBundleContents.SelectedItem;

            if (selectedItem == null)
            {
                return;
            }
            var name         = (string)selectedItem;
            var origName     = name.Replace(" *", "");
            var isSerialized = !(origName.EndsWith(".resS") || origName.EndsWith(".resource"));

            if (ModifiedFiles.ContainsKey(origName))
            {
                ModifiedFiles.Remove(origName);
            }
            else
            {
                ModifiedFiles.Add(origName, AssetModifier.CreateBundleRemover(origName, isSerialized));
            }
            cboxBundleContents.Items.Remove(name);
            if (cboxBundleContents.Items.Count != 0)
            {
                cboxBundleContents.SelectedIndex = 0;
            }
        }
Пример #2
0
        public void GenerateNextDataset()
        {
            var projectId     = 148;//测试收益分配报告-中港
            var assetModifier = new AssetModifier("TestUserName");

            assetModifier.Load(projectId, new DateTime(2016, 3, 1));
            assetModifier.GenerateNextDataset(projectId);
        }
Пример #3
0
        public Dictionary <BundleReplacer, MemoryStream> WriteFilesToMemory(List <AssetsReplacer> replacers)
        {
            var bunDict    = new Dictionary <BundleReplacer, MemoryStream>();
            var lastFileId = replacers.Max(r => r.GetFileID());

            for (var fileId = 0; fileId <= lastFileId; fileId++)
            {
                var id = fileId;
                var sortedAssetsList = replacers.Where(r => r.GetFileID() == id).ToList();
                using var ms     = new MemoryStream();
                using var writer = new AssetsFileWriter(ms);
                var fileInst = Workspace.LoadedFiles[fileId];

                fileInst.file.Write(writer, 0, sortedAssetsList, 0);
                bunDict.Add(AssetModifier.CreateBundleReplacer(fileInst.name, true, ms.ToArray()), ms);
            }
            return(bunDict);
        }
Пример #4
0
        private void RemoveAssetItems()
        {
            var choice = MsgBoxUtils.ShowWarningDialog("Are you sure you want to remove the selected asset(s)?\n" +
                                                       "This will break any reference to this/these.");

            if (choice != DialogResult.Yes)
            {
                return;
            }

            foreach (ListViewItem listItem in assetList.SelectedItems)
            {
                var item = Workspace.LoadedAssets[listItem.Index];
                Workspace.AddReplacer(AssetModifier.CreateAssetRemover(item));
                assetList.Items.Remove(listItem);
                Workspace.LoadedAssets.Remove(item);
            }
        }
Пример #5
0
        private void btnImport_Click(object sender, EventArgs e)
        {
            if (BundleInst == null)
            {
                return;
            }
            var ofd = new OpenFileDialog
            {
                Title  = @"Open assets file",
                Filter = @"All types (*.*)|*.*|Assets file (*.assets)|*.assets"
            };

            if (ofd.ShowDialog() != DialogResult.OK)
            {
                return;
            }
            var i = 0;

            foreach (var file in ofd.FileNames)
            {
                var fileName     = Path.GetFileName(file);
                var fileBytes    = File.ReadAllBytes(fileName);
                var isSerialized = !(file.EndsWith(".resS") || file.EndsWith(".resource"));
                var replacer     = AssetModifier.CreateBundleReplacer(fileName, isSerialized, fileBytes);
                if (!cboxBundleContents.Items.Contains(fileName))
                {
                    cboxBundleContents.Items.Add(fileName + " *");
                }
                else
                {
                    var item = cboxBundleContents.Items[i] + " *";
                    cboxBundleContents.Items.Remove(item);
                    cboxBundleContents.Items.Insert(i, item);
                }
                ModifiedFiles[fileName] = replacer;
                i++;
            }
            Modified = true;
        }
        public ActionResult PrepayAmortizationByAsset(string projectGuid, string paymentDate, int assetId,
                                                      string prepayDate, double money, string distributionType, string distributionDetail, string comment)
        {
            return(ActionUtils.Json(() =>
            {
                CommUtils.Assert(money >= 0, "提前偿付金额不能为负数");
                var type = CommUtils.ParseEnum <PrepayDistrubutionType>(distributionType);

                var project = new ProjectLogicModel(CurrentUserName, projectGuid);
                var dataset = project.DealSchedule.GetByPaymentDay(DateUtils.ParseDigitDate(paymentDate)).Dataset;
                var asset = dataset.Assets.Single(x => x.AssetId == assetId);

                CommUtils.Assert(DateUtils.ParseDigitDate(prepayDate) >= dataset.DatasetSchedule.AsOfDateBegin &&
                                 DateUtils.ParseDigitDate(prepayDate) <= dataset.DatasetSchedule.AsOfDateEnd,
                                 "提前偿付日期必须在当期时间范围(" + dataset.DatasetSchedule.AsOfDateBegin.ToShortDateString()
                                 + "~" + dataset.DatasetSchedule.AsOfDateEnd.ToShortDateString() + ")内");

                if (asset.AmortizationType == AmortizationType.UserDefined)
                {
                    var amortization = dataset.AmortizationSchedule;
                    amortization.AddPrepayment(assetId, DateUtils.ParseDigitDate(prepayDate), money, type, distributionDetail);
                    amortization.Save();

                    var history = new AssetPrepaymentHistory();
                    history.ProjectId = project.Instance.ProjectId;
                    history.DatasetId = dataset.Instance.DatasetId;
                    history.AssetId = assetId;
                    history.PrepayAmount = money;
                    history.PrepayTime = DateUtils.ParseDigitDate(prepayDate);
                    history.DistributionType = distributionType;
                    history.DistributionDetail = distributionDetail;
                    history.Comment = comment;
                    history.TimeStamp = DateTime.Now;
                    history.TimeStampUserName = CurrentUserName;
                    m_dbAdapter.PaymentHistory.NewAssetPrepaymentHistory(history);

                    var viewModel = new PrepayRecordListViewModel(dataset.DatasetSchedule, amortization.SelectByAsset(assetId));
                    return ActionUtils.Success(viewModel);
                }

                CommUtils.Assert(type != PrepayDistrubutionType.Custom, "等额本金、等额本息、一次偿付类的资产不支持自定义偿付。");

                //处理等额本金、等额本息、一次偿付类的提前偿付,需要下期模型存在
                if (dataset.Next == null)
                {
                    //下期模型不存在,自动生成下一期模型
                    CommUtils.AssertNotNull(dataset.DatasetSchedule.Next, "找不到下期模型封包日,提前偿付测算失败");

                    CreateDataset(project.Instance, dataset.DatasetSchedule.Next.AsOfDateBegin.ToString("yyyyMMdd"));

                    var assetModifier = new AssetModifier(CurrentUserName);
                    assetModifier.Load(project.Instance.ProjectId, dataset.DatasetSchedule.AsOfDateBegin);
                    assetModifier.GenerateNextDataset(project.Instance.ProjectId);
                }
                CommUtils.AssertNotNull(dataset.Next, "无法找到下期模型数据,提前偿付测算失败");

                if (IsEqualPmtOrEqualPrin(asset.AmortizationType))
                {
                    var curDatasetBasicAnalyticsData = NancyUtils.GetBasicAnalyticsData(project.Instance.ProjectId, null, dataset.DatasetSchedule.AsOfDateBegin);

                    double curDatasetPrincipal = 0;
                    if (IsEqualPmtOrEqualPrin(asset.SecurityData.PaymentMethod))
                    {
                        //当期未发生过提前偿付,当期偿付金额是Nancy测算金额
                        curDatasetPrincipal = curDatasetBasicAnalyticsData.BasicAssetCashflow.BasicAssetCashflowItems
                                              .Single(x => x.AssetId == assetId && x.PaymentDate == dataset.DatasetSchedule.PaymentDate).Principal;
                    }
                    else
                    {
                        var nextDatasetAsset = dataset.Next.Assets.Single(x => x.AssetId == assetId);
                        CommUtils.Assert(IsEqualPmtOrEqualPrin(nextDatasetAsset.AmortizationType),
                                         "第[" + dataset.Next.DatasetSchedule.PaymentDate.ToString("yyyyMMdd") + "]期偿付类型错误,提前偿付测算失败");

                        //当期发生过提前偿付,当期偿付金额是AmortizationSchedule中金额
                        var curAmortizationRecord = dataset.AmortizationSchedule.Single(x => x.ReductionDate == dataset.DatasetSchedule.PaymentDate);
                        //当期未发生本次提前偿付的偿付本金
                        curDatasetPrincipal = (double)curAmortizationRecord.ReductionAmount;
                    }

                    //保存AmortizationSchedule
                    var amortization = dataset.AmortizationSchedule;
                    amortization.Add(new AmortizationScheduleRecord {
                        AssetId = assetId,
                        ReductionAmount = money + curDatasetPrincipal,
                        ReductionDate = DateUtils.ParseDigitDate(prepayDate)
                    });
                    amortization.Save();

                    //更新PaymentMethod
                    dataset.CollateralCsv.UpdateCellValue(assetId, "PaymentMethod", "");
                    dataset.CollateralCsv.Save();

                    var sumFutureDatasetPrincipal = curDatasetBasicAnalyticsData.BasicAssetCashflow.BasicAssetCashflowItems
                                                    .Where(x => x.AssetId == assetId && x.PaymentDate > dataset.DatasetSchedule.PaymentDate)
                                                    .Sum(x => x.Principal);

                    var records = new List <AmortizationScheduleRecord>();
                    //当期的新的本金偿付值是 根据等额本金/等额本息计算出的本金值 加上提前偿付金额
                    records.Add(new AmortizationScheduleRecord
                    {
                        AssetId = assetId,
                        ReductionAmount = curDatasetPrincipal + money,
                        ReductionDate = dataset.DatasetSchedule.PaymentDate
                    });

                    //更新下期的本金期末余额(减去提前偿付金额),重新根据等额本金/等额本息计算本金
                    dataset.Next.CollateralCsv.UpdateCellValue(assetId, "PrincipalBalance", (sumFutureDatasetPrincipal - money).ToString());
                    dataset.Next.CollateralCsv.Save();

                    var nextDatasetBasicAnalyticsData = NancyUtils.GetBasicAnalyticsData(project.Instance.ProjectId, null, dataset.DatasetSchedule.Next.AsOfDateBegin);
                    var nextAssetCashflowItems = nextDatasetBasicAnalyticsData.BasicAssetCashflow.BasicAssetCashflowItems
                                                 .Where(x => x.AssetId == assetId && x.PaymentDate > dataset.DatasetSchedule.PaymentDate && x.Principal != 0)
                                                 .OrderBy(x => x.PaymentDate);

                    foreach (var item in nextAssetCashflowItems)
                    {
                        records.Add(new AmortizationScheduleRecord
                        {
                            AssetId = assetId,
                            ReductionAmount = item.Principal,
                            ReductionDate = item.PaymentDate
                        });
                    }

                    var viewModel = new PrepayRecordListViewModel(dataset.DatasetSchedule, records);
                    return ActionUtils.Success(viewModel);
                }
                else if (asset.AmortizationType == AmortizationType.SingleAmortization)
                {
                    var nextDatasetAsset = dataset.Next.Assets.Single(x => x.AssetId == assetId);
                    CommUtils.AssertEquals(nextDatasetAsset.SecurityData.PaymentMethod, ZEnums.EPaymentMethod.UNDEFINEDENUM,
                                           "无法识别的偿付类型,提前偿付测算失败。");

                    var nextAmortizationRecords = dataset.Next.AmortizationSchedule.SelectByAsset(assetId);
                    CommUtils.AssertEquals(nextAmortizationRecords.Count, 0,
                                           "第[" + dataset.Next.DatasetSchedule.PaymentDate.ToString("yyyyMMdd") + "]期已发生提前偿付, 提前偿付测算失败");

                    var records = dataset.AmortizationSchedule.SelectByAsset(assetId);
                    var prepayRecord = new AmortizationScheduleRecord
                    {
                        AssetId = assetId,
                        ReductionAmount = money,
                        ReductionDate = DateUtils.ParseDigitDate(prepayDate)
                    };

                    records.Add(prepayRecord);

                    var sumPrepayAmount = records.Sum(x => x.ReductionAmount);
                    CommUtils.Assert(sumPrepayAmount <= asset.SecurityData.PrincipalBalance,
                                     "提前偿付金额[" + sumPrepayAmount + "]大于剩余未偿付金额[" + asset.SecurityData.PrincipalBalance + "]");

                    records.Add(new AmortizationScheduleRecord()
                    {
                        AssetId = assetId,
                        ReductionAmount = asset.SecurityData.PrincipalBalance - sumPrepayAmount,
                        ReductionDate = asset.SecurityData.MaturityDate
                    });

                    dataset.AmortizationSchedule.AddPrepayment(assetId, DateUtils.ParseDigitDate(prepayDate), money, type, distributionDetail);
                    dataset.AmortizationSchedule.Save();

                    dataset.Next.CollateralCsv.UpdateCellValue(assetId, "PrincipalBalance",
                                                               (asset.SecurityData.PrincipalBalance - sumPrepayAmount).ToString());
                    dataset.Next.CollateralCsv.Save();

                    var viewModel = new PrepayRecordListViewModel(dataset.DatasetSchedule, records);
                    return ActionUtils.Success(viewModel);
                }

                return ActionUtils.Success("无法识别的偿付类型,projectGuid=["
                                           + projectGuid + "] + paymentDate=[" + paymentDate + "] + assetId=[" + assetId + "]");
            }));
        }
Пример #7
0
        private void btnOK_Click(object sender, EventArgs e)
        {
            var cldb     = Workspace.Am.classFile;
            var fileInst = Workspace.LoadedFiles[cboxFileID.SelectedIndex];
            AssetTypeTemplateField templateField;

            var fileId = cboxFileID.SelectedIndex;

            if (!long.TryParse(boxPathID.Text, out var pathId))
            {
                MsgBoxUtils.ShowErrorDialog("Path ID is invalid!");
                return;
            }
            var type = boxTypeNameOrID.Text;
            int typeId;
            var createBlankAsset = chboxCreateBlankAssets.Checked;

            if (fileInst.file.typeTree.hasTypeTree)
            {
                if (!TryParseTypeTree(fileInst, ref type, createBlankAsset, out templateField, out typeId))
                {
                    if (!TryParseClassDatabase(ref type, createBlankAsset, out templateField, out typeId))
                    {
                        MsgBoxUtils.ShowErrorDialog("Class type is invalid!");
                        return;
                    }

                    //has typetree but had to lookup to cldb
                    //we need to add a new typetree entry because this is
                    //probably not a type that existed in this bundle
                    fileInst.file.typeTree.unity5Types.Add(C2T5.Cldb2TypeTree(cldb, typeId));
                }
            }
            else
            {
                if (!TryParseClassDatabase(ref type, createBlankAsset, out templateField, out typeId))
                {
                    MsgBoxUtils.ShowErrorDialog("Class type is invalid!");
                    return;
                }
            }

            var monoSelected = cboxTypePreset.SelectedIndex == 1;

            ushort monoId;

            if (typeId != 0x72 || !monoSelected)
            {
                monoId = ushort.MaxValue;
            }
            else
            {
                if (!ushort.TryParse(boxMonoID.Text, out monoId))
                {
                    MsgBoxUtils.ShowErrorDialog("Mono ID is invalid!");
                    return;
                }
            }

            if (!int.TryParse(boxCount.Text, out var count))
            {
                MsgBoxUtils.ShowErrorDialog("The count of assets being created is invalid!");
                return;
            }

            byte[] assetBytes;
            if (createBlankAsset)
            {
                var baseField = ValueBuilder.DefaultValueFieldFromTemplate(templateField);
                assetBytes = baseField.WriteToByteArray();
            }
            else
            {
                assetBytes = Array.Empty <byte>();
            }
            for (var i = 0; i < count; i++)
            {
                var item = new AssetItem
                {
                    Type     = type,
                    TypeID   = (uint)typeId,
                    FileID   = fileId,
                    PathID   = pathId + i,
                    Size     = assetBytes.Length,
                    Modified = "*",
                    MonoID   = monoId
                };
                Items.Add(item);
                Workspace.AddReplacer(AssetModifier.CreateAssetReplacer(item, assetBytes), new MemoryStream(assetBytes));
            }
            DialogResult = DialogResult.OK;
        }