示例#1
0
        private void listSheetnames_SelectedIndexChanged(object sender, EventArgs e)
        {
            var data = _excelRepository.Load(listSheetnames.SelectedItem.ToString());

            dataGridView1.DataSource = data;

            _athleteRepository = new AthleteRepository(data);

            var races = _athleteRepository.GetRaces().ToList();

            textRaces.Text = Newtonsoft.Json.JsonConvert.SerializeObject(races);

            Application.DoEvents();

            _raceAthletes = new RaceAthletes(_athleteRepository.GetAthletes(), _excelRepository.GetFiletime());

            textAthletes.Text = Newtonsoft.Json.JsonConvert.SerializeObject(_raceAthletes);

            _stopwatch.Stop();
            toolStripStatusLabel1.Text = string.Format("{0:HH:mm:ss} - {1:F}", DateTime.Now, _stopwatch.Elapsed.TotalSeconds);
        }
示例#2
0
        public JsonResult UploadFile()
        {
            if (!Directory.Exists(ProjectUploadFolder))
            {
                Directory.CreateDirectory(ProjectUploadFolder);
            }

            //var streamProvider = new bytera(ServerUploadFolder);
            var data = Request.Content.ReadAsFormDataAsync().Result;
            //var messages = UploadFiles(streamProvider, false);
            var filename = Request.GetQueryNameValuePairs().First().Value;

            filename = string.Format(@"{0}\{1}_{2}", ProjectUploadFolder, DateTime.Now.Ticks, filename);
            var html = data.Keys[0];

            html = html.Substring(html.IndexOf("base64,") + "base64,".Length).Trim().Replace(' ', '+');
            try
            {
                if (html.Length % 4 > 0)
                {
                    html = html.PadRight(html.Length + 4 - html.Length % 4, '=');
                }
                var image64 = Convert.FromBase64String(html);
                File.WriteAllBytes(filename, image64);
            }
            catch (Exception exception)
            {
                html = exception.ToString();
                //throw;
            }

            var racejson    = "";
            var athletejson = "";

            try
            {
                using (var excelRepository = new ExcelRepository(filename))
                {
                    foreach (var sheetName in excelRepository.GetSheetNames())
                    {
                        var exceldata         = excelRepository.Load(sheetName);
                        var athleteRepository = new AthleteRepository(exceldata);
                        var races             = athleteRepository.GetRaces().ToList();
                        racejson = Newtonsoft.Json.JsonConvert.SerializeObject(races);
                        var raceAthletes = new RaceAthletes(athleteRepository.GetAthletes(), excelRepository.GetFiletime());
                        athletejson = Newtonsoft.Json.JsonConvert.SerializeObject(raceAthletes);
                        break;
                    }
                }
            }
            catch (Exception exception)
            {
                racejson    = exception.Message;
                athletejson = exception.ToString();
            }
            //foreach (var message in messages)
            //{
            //    if (!string.IsNullOrEmpty(html)) html += "<br>";
            //    html += string.Format("<a href=\"{0}\">{0}</a>", message.Second);
            //}

            var rr = new JsonResult
            {
                Data = new jsondata
                {
                    races    = racejson,
                    athletes = athletejson
                }
            };

            return(rr);


            //var response = new HttpResponseMessage
            //{
            //    Content = new StringContent(string.Format("<p>{0}</p><p>{1}</p>", racejson, athletejson))
            //};
            //response.Content.Headers.ContentType = new MediaTypeHeaderValue("text/html");
            //return response;
        }