Пример #1
0
        public void TestRemoveFisdStr()
        {
            var tempConnection = DataBaseLink.Fabricate.CreateConnection(_connection, ConnectionType.Npgsql);

            DataBaseLink.DbLink dbLink = new DbLink(tempConnection);

            fin_instrument fin_instrument = new fin_instrument("roman", 13, "bushuev");

            if (FinInstrument.FindId(dbLink, fin_instrument.ident) == null)
            {
                FinInstrument.Insert(dbLink, fin_instrument);
            }

            var result = FinInstrument.FindId(dbLink, fin_instrument.ident);

            //fisd_id
            ffd ffd = new ffd()
            {
                ds_id  = 17,
                fi_id  = result.fi_id,
                fif_id = 11,
            };

            if (FFD.Find(dbLink, result.fi_id, ffd.ds_id, ffd.fif_id) == null)
            {
                FFD.Insert(dbLink, ffd);
            }
            var ffdResult = FFD.Find(dbLink, result.fi_id, ffd.ds_id, ffd.fif_id);

            fisd_str fisd_str = new fisd_str()
            {
                fisd_id  = ffdResult.fisd_id,
                dat_from = new DateTime(2018, 03, 24),
                val      = "roman"
            };

            if (FisdStr.FindId(dbLink, fisd_str.fisd_id, fisd_str.dat_from) == null)
            {
                FisdStr.Insert(dbLink, fisd_str);
                var one = FisdStr.FindId(dbLink, fisd_str.fisd_id, fisd_str.dat_from);
                FisdStr.Remove(dbLink, one.fisd_id, one.dat_from);
            }
            else
            {
                FisdStr.Insert(dbLink, fisd_str);
                var one = FisdStr.FindId(dbLink, fisd_str.fisd_id, fisd_str.dat_from);
                FisdStr.Remove(dbLink, one.fisd_id, one.dat_from);
            }
        }
        //insert
        public static void Insert(DbLink dbLink, fisd_str fisd_str)
        {
            //при первой вставке дату указываем = 01.01.1900
            if (FindId(dbLink, fisd_str.fisd_id, fisd_str.dat_from) == null)
            {
                fisd_str.dat_from = new DateTime(1900, 01, 01);
            }
            else
            {
                var result = FindId(dbLink, fisd_str.fisd_id, fisd_str.dat_from);
                if (fisd_str.val == result.val)
                {
                    return;
                }
            }

            string query =
                @"insert into fisd_str(val, dat_from, fisd_id)
                    values(@val, @dat_from, @fisd_id)";

            dbLink.GetConnection().Execute(query, fisd_str);
        }
        private void Save(Dictionary <KeyValuePair <PortfolioPosition, Enum>, ScalarStr> storage)
        {
            foreach (var x in storage)
            {
                var transaction = _dbLink.GetConnection().BeginTransaction(IsolationLevel.ReadCommitted);
                try
                {
                    // найдем тип финансового инструмента
                    var    finIdent     = x.Key.Key.Ident;
                    var    finType      = x.Key.Key.FinType;
                    string finTypeIdent = _mapping.GetAI(finType);

                    #region финансовый инструмент
                    fin_instrument finInstrument = new fin_instrument()
                    {
                        ident = finIdent,
                        title = finIdent,
                        ft_id = int.Parse(finTypeIdent)
                    };

                    if (FinInstrument.FindId(_dbLink, finInstrument.ident) == null)
                    {
                        FinInstrument.Insert(_dbLink, finInstrument);
                    }

                    finInstrument = FinInstrument.FindId(_dbLink, finInstrument.ident);

                    #endregion

                    #region Data_source
                    data_source dataSource = new data_source()
                    {
                        ident = _providerParams[SCALAR].ToString(),
                    };

                    dataSource = DataSource.FindId(_dbLink, dataSource.ident);
                    #endregion

                    #region fisd_id
                    ffd ffd = new ffd()
                    {
                        ds_id  = dataSource.ds_id,
                        fi_id  = finInstrument.fi_id,
                        fif_id = int.Parse(_mapping.GetAI(x.Key.Value))
                    };

                    if (FFD.Find(_dbLink, ffd.fi_id, ffd.ds_id, ffd.fif_id) == null)
                    {
                        FFD.Insert(_dbLink, ffd);
                    }
                    ffd = FFD.Find(_dbLink, ffd.fi_id, ffd.ds_id, ffd.fif_id);
                    #endregion

                    fisd_str fisdStr = new fisd_str()
                    {
                        fisd_id  = ffd.fisd_id,
                        dat_from = x.Value.Dictionary.First().Key,
                        val      = x.Value.Dictionary.First().Value
                    };

                    FisdStr.Insert(_dbLink, fisdStr);
                    transaction.Commit();
                }
                catch
                {
                    transaction.Rollback();
                }
            }
        }