public static void ReadQuoteFile(OpenFileDialog fileDialog, DateTime date) { StockRepository stockRepo = new StockRepository(); StockQuoteRepository quoteRepo = new StockQuoteRepository(); stock_quotes quote = new stock_quotes(); bool success = false; bool flag = true; String ErrorMessage; AwaitForm waitForm = new AwaitForm(); string fileName = fileDialog.FileName; Microsoft.Office.Interop.Excel.Application xlApp = new Microsoft.Office.Interop.Excel.Application(); Workbook xlWorkbook = xlApp.Workbooks.Open(fileName); Worksheet xlWorksheet = xlWorkbook.Sheets[1]; Range xlRange = xlWorksheet.UsedRange; int rowCount = xlRange.Rows.Count; int colCount = xlRange.Columns.Count; bool checkDate = quoteRepo.CheckEquityMonth(date.Date); if (!checkDate) { if (xlRange[2, 2].Value2 != null) { for (int i = 2; i <= rowCount; i++) { string stockCode = xlRange[i, 1].Value2.ToString().ToUpper().Trim(); if (stockCode.Length == 4) { bool isExisted = stockRepo.CheckCurrentStock(stockCode); if (!isExisted) { stock stock = new stock(); stock.code = stockCode; quote.stock_id = stockRepo.SaveStock(stock, out ErrorMessage); } quote.stock_id = stockRepo.GetStockId(stockCode); quote.quote_date = date; quote.open = xlRange.Cells[i, 3].Value2 == 0 ? Decimal.Parse(xlRange.Cells[i, 2].Value2.ToString()) : Decimal.Parse(xlRange.Cells[i, 3].Value2.ToString()); quote.high = Decimal.Parse(xlRange.Cells[i, 4].Value2.ToString()); quote.low = Decimal.Parse(xlRange.Cells[i, 5].Value2.ToString()); quote.close = Decimal.Parse(xlRange.Cells[i, 6].Value2.ToString()); quote.volume = Decimal.Parse(xlRange.Cells[i, 7].Value2.ToString()) / 100; quote.value = Decimal.Parse(xlRange.Cells[i, 8].Value2.ToString()); quote.frequency = Decimal.Parse(xlRange.Cells[i, 9].Value2.ToString()); quote.foreign_sell = Decimal.Parse(xlRange.Cells[i, 10].Value2.ToString()) / 100; quote.foreign_buy = Decimal.Parse(xlRange.Cells[i, 11].Value2.ToString()) / 100; success = quoteRepo.SaveStockQuote(quote, out ErrorMessage); if (!String.IsNullOrEmpty(ErrorMessage)) { MessageBox.Show(ErrorMessage); } if (flag) { waitForm.Show(); waitForm.Refresh(); } flag = false; } } if (success) { waitForm.Close(); MessageBox.Show("Data berhasil disimpan"); } } else { MessageBox.Show("File tidak memiliki data"); } } else { MessageBox.Show("Data untuk tanggal ini telah tersedia"); } }