示例#1
0
        private string CreateSharesTraded(List <string> trades, string companyName, DtstCOI.documentRow dbDoc)
        {
            companyName = Dbo.FilterName(companyName);
            if (ReadOnly)
            {
                return("Readonly mode detected, Not saving share trade information");
            }
            var log   = new StringWriter();
            var dal   = new SharesManager();
            var table = dal.GetIndividualSharesTradedByCo(companyName);

            foreach (var trade in trades)
            {
                try
                {
                    var     details = trade.Split('|');
                    var     date    = DateTime.Parse(details[1]);
                    var     traded  = decimal.Parse(details[2]);
                    var     owned   = decimal.Parse(details[3]);
                    var     form    = int.Parse(details[5]);
                    var     no      = int.Parse(details[6]);
                    decimal price;
                    try
                    {
                        price = decimal.Parse(details[4]);
                    }
                    catch
                    {
                        price = 0;
                    }
                    var row = table.FindByindividual_namecompany_namedateformnumber
                                  (details[0], companyName, date, form, no);
                    if (row == null)
                    {
                        table.Addindividual_company_sharesRow(details[0], companyName,
                                                              date, form, no, dbDoc.document_id, traded, owned, SourceId, price);
                    }
                }catch
                {
                }
            }
            dal.Save(table);
            return(log.ToString());
        }
        public void DoSharesVolume()
        {
            if (_companyName == string.Empty)
            {
                return;
            }
            var s = _chart.Series.Add("Shares Volume");

            _series.Add(s.Name);
            s.ChartType = "Line";
            //s.YAxisType =AxisType.Secondary;
            var dal   = new SharesManager();
            var table = dal.GetSharesTraded(_companyName, _sourceID);
            var vw    = new DataView(table, "", table.dateColumn.ColumnName + " asc", DataViewRowState.CurrentRows);

            foreach (DataRowView rowView in vw)
            {
                var row = (DtstCOI.company_shares_tradedRow)rowView.Row;
                if (IsPointUsable(row))
                {
                    s.Points.AddXY(row.date, row.vloume);
                }
            }
        }
        public string CreateSharesData()
        {
            IFormatProvider culture = new CultureInfo("en-US", true);
            var             dal     = new SharesManager();
            var             l       = new StringWriter();
            var             doc     = GetDoc(l);
            var             dbDoc   = GetOrCreateDbDoc();
            var             data    = Url.ToLower().IndexOf("nasdaq") == -1 ? GetCellFromCSV(doc) : GetCellFromTSV(doc);
            var             table   = dal.GetSharesTraded(CompanyName, SourceId);

            foreach (var row in data)
            {
                try
                {
                    //Date,Open,High,Low,Close,Volume
                    //13-Oct-09,0.01,0.01,0.01,0.01,300
                    if (row.Count < 6)
                    {
                        continue;
                    }
                    if (row[0].ToLower() == "date")
                    {
                        continue;
                    }
                    var date = DateTime.Parse(row[0], culture);//Exact(row[0], "dd-MMM-yy", culture);
                    for (var z = 1; z <= 5; z++)
                    {
                        if (row[z] == "-")
                        {
                            row[z] = 0.ToString();
                        }
                        if (row[z].IndexOf(',') != -1)
                        {
                            row[z] = row[z].Replace(",", "");
                        }
                    }
                    var price = new decimal[]
                    { decimal.Parse(row[1]), decimal.Parse(row[2])
                      , decimal.Parse(row[3]), decimal.Parse(row[4]) };
                    var volume   = int.Parse(row[5]);
                    var existing = table.FindBycompany_namedatesource_idintervalDays
                                       (CompanyName, date, SourceId, IntervalDays);
                    if (existing == null)
                    {
                        table.Addcompany_shares_tradedRow(CompanyName, date, price[0],
                                                          price[1], price[2], price[3], volume, dbDoc.document_id, SourceId, IntervalDays);
                    }
                }
                catch (Exception ex)
                {
                    l.WriteLine(ex.Message + string.Join(",", row.ToArray()));
                }
            }
            try
            {
                dal.Save(table);
                l.WriteLine("Shares traded saved");
            }
            catch (Exception ex)
            {
                l.WriteLine(ex.Message);
            }
            return(l.ToString());
        }
        protected void DoShares()
        {
            Series       s;
            const string area   = "SharesTraded";
            const string volume = "Shares volume";

            if (_series.IndexOf(volume) >= 0)
            {
                s = Chart1.Series[volume];
            }
            else
            {
                _series.Add(volume);
                s           = Chart1.Series.Add(volume);
                s.ChartArea = area;
                s.ChartType = "Line";
                s.Legend    = area;
            }
            Series       sp;
            const string price = "Shares price";

            if (_series.IndexOf(price) >= 0)
            {
                sp = Chart1.Series[price];
            }
            else
            {
                _series.Add(price);
                sp           = Chart1.Series.Add(price);
                sp.ChartArea = area;
                sp.ChartType = "StepLine";
                sp.Legend    = area;
                sp.YAxisType = AxisType.Secondary;
            }
            var dal   = new SharesManager();
            var table = dal.GetSharesTraded(_coName, 70);
            var vw    = new DataView(table, "", table.dateColumn.ColumnName + " asc", DataViewRowState.CurrentRows);

            foreach (DataRowView rowView in vw)
            {
                var row = (DtstCOI.company_shares_tradedRow)rowView.Row;
                if (!IsPointUsable(row.date))
                {
                    continue;
                }
                var p  = s.Points.AddXY(row.date, row.vloume);
                var pp = sp.Points.AddXY(row.date, row.price_close);
                SetMaxMinDates(row.date, row.date);
            }
            //-------------------------------------------------------------------------------
            if (!checkArea.Checked)
            {
                return;
            }
            //-------------------------------------------------------------------------------
            double ratio;

            try
            {
                ratio = double.Parse(TextRatio.Text);
            }
            catch {
                ratio = 0.5D;
            }
            const string vol = "Highlighted Volume";

            if (_series.IndexOf(vol) >= 0)
            {
                s = Chart1.Series[vol];
            }
            else
            {
                _series.Add(vol);
                s           = Chart1.Series.Add(vol);
                s.ChartArea = area;
                s.ChartType = "Area";
                s.Legend    = area;
            }
            if (TextAreaDescription.Text.Trim() != string.Empty)
            {
                s.LegendText = TextAreaDescription.Text;
            }
            var ct  = new ChartTools(_coName, Chart1, 70, 1);
            var vwA = ct.GetAreaPoints(int.Parse(this.TextVolume.Text));

            foreach (DataRowView rowView in vwA)
            {
                var row = (DtstCOI.company_shares_tradedRow)rowView.Row;
                var p   = s.Points.AddXY(row.date, row.vloume * ratio);
            }
        }
示例#5
0
        public static void Main()
        {
            Console.WriteLine("1: Split\n2: Combine");
            var choice = Console.ReadLine();

            if (choice == "1")
            {
                Console.WriteLine("Players: ");
                var playerStr = Console.ReadLine();

                Console.WriteLine("Required: ");
                var requiredStr = Console.ReadLine();

                Console.WriteLine("Message:");
                var message = Console.ReadLine();

                var players  = int.Parse(playerStr);
                var required = int.Parse(requiredStr);

                var polynomsCount = 3;

                var byteKey = KeyGenerator.GenerateKey(polynomsCount * 16);
                var key     = KeyGenerator.GenerateDoubleBytesKey(byteKey);
                var hexKey  = KeyGenerator.GetHexKey(key);

                var encrypted = Encryption.Encrypt(message, hexKey);

                Console.WriteLine("\nEncrypted message:\n{0}", encrypted);

                Console.WriteLine("\nShares: ");

                var splitted = SharesManager.SplitKey(key, players, required);
                for (var i = 0; i < splitted.Length; i++)
                {
                    Console.WriteLine(splitted[i]);
                }
                Console.WriteLine();
            }
            else if (choice == "2")
            {
                Console.WriteLine("Encrypted message: ");
                var message = Console.ReadLine();

                Console.WriteLine("Number of shares: ");
                var sharesCountStr = Console.ReadLine();
                var sharesCount    = int.Parse(sharesCountStr);


                var shares = new string[sharesCount];

                for (var i = 0; i < sharesCount; i++)
                {
                    Console.WriteLine("Share {0}:", i + 1);
                    shares[i] = Console.ReadLine();
                }

                var generatedKey = SharesManager.CombineKey(shares);
                var hexKey       = KeyGenerator.GetHexKey(generatedKey);

                var decrypted = Encryption.Decrypt(message, hexKey);
                Console.WriteLine("\nDecrypted message:");
                Console.WriteLine(decrypted);
                Console.WriteLine();
            }

            var a = Console.ReadLine();
        }