Пример #1
0
        /*
         * versione originale con carico del file id excel direttamente nella listview
         *
         *   void _readXLS ()
         * {
         * if (File.Exists("CodiciABarre.xls"))
         * {
         *  //ripulisco la itemlistbox
         *  lvMain.Items.Clear();
         *  //inizio lettura file excel
         *  using (var fs = new FileStream("CodiciABarre.xls", FileMode.Open, FileAccess.Read))
         *  {
         *    wb = new HSSFWorkbook(fs);
         *    sh = (HSSFSheet)wb.GetSheet("Etichette");
         *
         *    for (int row = 0; row <= sh.LastRowNum; row++) //Loop the records upto filled row
         *    {
         *      if (sh.GetRow(row) != null) //null is when the row only contains empty cells
         *      {
         *        //carico la listview
         *        ListViewItem _lvItem;
         *        _lvItem = lvMain.Items.Add(sh.GetRow(row).GetCell(0).ToString());
         *        for (int I = 1; I<=5; I++)
         *        {
         *          if (sh.GetRow(row).GetCell(I) == null)
         *            _lvItem.SubItems.Add("");
         *          else
         *        _lvItem.SubItems.Add(sh.GetRow(row).GetCell(I).ToString());
         *        }
         *        //string value = sh.GetRow(row).GetCell(0).ToString(); //Here for sample , I just save the value in "value" field, Here you can write your custom logics...
         *        //MessageBox.Show(value);
         *      }
         *    }
         *  }
         *  lvMain.Items[0].Selected = true;
         * }
         * else
         *  MessageBox.Show("File etichette non trovato");
         * }*/

        private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
        {
            bmp = new Bitmap(PNL.Width, PNL.Height);
            bmp.SetResolution(Convert.ToSingle(numResDPI.Value), Convert.ToSingle(numResDPI.Value));
            PNL.DrawToBitmap(bmp, new Rectangle(0, 0, PNL.Width, PNL.Height));
            e.Graphics.DrawImage(bmp, 0, 0);
        }
        public async Task <IActionResult> PutPNL([FromRoute] Guid id, [FromBody] PNL pNL)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != pNL.Id)
            {
                return(BadRequest());
            }

            _context.Entry(pNL).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!PNLExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
        public async Task <IActionResult> PostPNL([FromBody] PNL pNL)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            _context.PNLs.Add(pNL);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetPNL", new { id = pNL.Id }, pNL));
        }
Пример #4
0
        public ActionResult Create(int?ID, [Bind(Include = "name,key,booking")] PNL pnl)
        {
            if (ModelState.IsValid)
            {
                pnl.FileListId = ID == null ? 0 : (int)ID;

                dbcontext.FileLists.First(p => p.Id == ID).PNLs.Add(pnl);
                dbcontext.SaveChanges();
                string fileName = dbcontext.FileLists.Where(p => p.Id == ID).First().FileName;
                using (StreamWriter sw = new StreamWriter(Path.Combine(Server.MapPath("~/App_Data/uploads"), fileName), true))
                {
                    sw.WriteLine(Environment.NewLine + "1" + pnl.name + "-" + pnl.key + " .L/" + pnl.booking);
                }

                return(View("Index", dbcontext.FileLists.First(p => p.Id == ID).PNLs));
            }
            ModelState.AddModelError("error_msg", "Error.Please enter all values");
            return(View("Create"));
        }
Пример #5
0
        public static List <PNL> getString(string strInput)
        {
            string       tempStr   = "";
            List <PNL>   PNLs      = new List <PNL>();
            StringReader strReader = new StringReader(strInput);

            using (StringReader reader = new StringReader(strInput))

            {
                while ((tempStr = reader.ReadLine()) != null)
                {
                    try
                    {
                        if (tempStr.StartsWith("1"))
                        {
                            var arr = tempStr.Split(' ');
                            if (arr.Length == 2)
                            {
                                if (arr[1].StartsWith(".L/"))
                                {
                                    PNL pnl = new PNL();
                                    pnl.name    = arr[0].Substring(1).Split('-')[0];
                                    pnl.pnlType = "1";

                                    pnl.key     = arr[0].Substring(1).Split('-').Length > 1 ? arr[0].Substring(1).Split('-')[1] : "-";
                                    pnl.booking = arr[1].Substring(3);

                                    PNLs.Add(pnl);
                                }
                            }
                        }
                    }
                    catch { }
                }
            }
            return(PNLs);
        }
Пример #6
0
        public static void Initialize(IServiceProvider serviceProvider)
        {
            string path    = Directory.GetCurrentDirectory();
            var    context = serviceProvider.GetRequiredService <ApplicationDbContext>();

            context.Database.EnsureCreated();
            if (!context.Strategies.Any())
            {
                using (TextReader fileReader = File.OpenText(path + propertiesFile))
                {
                    var csv = new CsvReader(fileReader);
                    foreach (dynamic records in csv.GetRecords <dynamic>())
                    {
                        var strategy = new Strategy()
                        {
                            StratName = records.StratName, Region = records.Region
                        };
                        context.Strategies.Add(strategy);
                    }
                }

                context.SaveChanges();
            }

            var strategies = context.Strategies.ToList();

            if (!context.Capitals.Any())
            {
                using (TextReader fileReader = File.OpenText(path + capitalFile))
                {
                    var csv = new CsvReader(fileReader);

                    foreach (dynamic records in csv.GetRecords <dynamic>())
                    {
                        var date = DateTime.Now;
                        foreach (var record in records)
                        {
                            if (record.Key == dateKey)
                            {
                                date = DateTime.ParseExact(record.Value, DateType, null);
                            }
                            else
                            {
                                var strategyId = strategies.First(s => s.StratName.Equals(record.Key)).Id;
                                var capital    = new Capital()
                                {
                                    StrategyId = strategyId, Date = date, Value = Int32.Parse(record.Value)
                                };
                                context.Capitals.Add(capital);
                            }
                        }
                    }
                    context.SaveChanges();
                }
            }

            if (!context.PNLs.Any())
            {
                using (TextReader fileReader = File.OpenText(path + pnlFile))
                {
                    var csv = new CsvReader(fileReader);
                    foreach (dynamic records in csv.GetRecords <dynamic>().ToList())
                    {
                        var date = DateTime.Now;
                        foreach (var record in records)
                        {
                            if (record.Key == dateKey)
                            {
                                date = DateTime.ParseExact(record.Value, DateType, null);
                            }
                            else
                            {
                                var strategyId = strategies.First(s => s.StratName.Equals(record.Key)).Id;
                                var pnl        = new PNL()
                                {
                                    StrategyId = strategyId, Date = date, Value = Int32.Parse(record.Value)
                                };
                                context.PNLs.Add(pnl);
                            }
                        }
                    }
                    context.SaveChanges();
                }
            }
        }
Пример #7
0
        public static void Initialize(IServiceProvider serviceProvider)
        {
            string path    = Directory.GetCurrentDirectory();
            var    context = serviceProvider.GetRequiredService <ApplicationDbContext>();

            context.Database.EnsureCreated();
            if (!context.Strategies.Any())
            {
                // Load strategies
                foreach (dynamic e in new ChoCSVReader(path + "\\DataStore\\properties.csv").WithFirstLineHeader())
                {
                    var strategy = new Strategy()
                    {
                        Name = e.StratName, Region = e.Region
                    };
                    context.Strategies.Add(strategy);
                }
                context.SaveChanges();

                var strategies = context.Strategies.ToList();

                // Load pnl
                using (var parser = new ChoCSVReader(path + "\\DataStore\\pnl.csv").WithFirstLineHeader(true))
                {
                    foreach (var t in parser)
                    {
                        var count = t.Count;
                        var date  = DateTime.ParseExact(t[0], "yyyy-MM-dd", null);

                        for (var i = 1; i < count; i++)
                        {
                            var strategyId = strategies.Find(s => s.Name.Equals("Strategy" + i)).Id;
                            var pnl        = new PNL()
                            {
                                StrategyId = strategyId, Value = Int32.Parse(t[i]), Date = date
                            };
                            context.PNLs.Add(pnl);
                        }
                    }
                }
                context.SaveChanges();

                // Load pnl
                using (var parser = new ChoCSVReader(path + "\\DataStore\\capital.csv").WithFirstLineHeader(true))
                {
                    foreach (var t in parser)
                    {
                        var count = t.Count;
                        var date  = DateTime.ParseExact(t[0], "yyyy-MM-dd", null);

                        for (var i = 1; i < count; i++)
                        {
                            var strategyId = strategies.Find(s => s.Name.Equals("Strategy" + i)).Id;
                            var capital    = new Capital()
                            {
                                StrategyId = strategyId, Value = Int32.Parse(t[i]), Date = date
                            };
                            context.Capitals.Add(capital);
                        }
                    }
                }
                context.SaveChanges();
            }
        }