string strTempPath = System.Configuration.ConfigurationManager.AppSettings["TempPath"].ToString();
string strFileName = fluplEarningsFile.FileName.ToString();
string strMainFilename = strTempPath + strFileName;
string oledbCon = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + strMainFilename + ";Extended Properties='Excel 12.0;HDR=YES;IMEX=1'";
fluplEarningsFile.SaveAs(strTempPath + strFileName);
if (fluplEarningsFile.HasFile)
{
DataSet ds;
DataSet dssubsector;
OleDbDataAdapter dataadapter;
SqlConnection con = new SqlConnection(connString);
OleDbConnection OLEConn = new OleDbConnection(oledbCon);
OleDbCommand oledbComm = new OleDbCommand();
string strQuarterMonth;
string strQuarterYear;
oledbComm.Connection = OLEConn;
OLEConn.Open();
dataadapter = new System.Data.OleDb.OleDbDataAdapter(oledbComm);
string strSelect = "select * from [Earnings$]";
oledbComm.CommandText = strSelect;
ds = new System.Data.DataSet();
dataadapter.Fill(ds);
if (ds.Tables[0].Rows.Count > 0)
{
for (int i = 0; i <= ds.Tables[0].Rows.Count - 1; i++)
{
string strQuarter = ds.Tables[0].Rows[i][2].ToString();
if (strQuarter != "\n " && strQuarter != "")
{
string[] strSplitQuarter = strQuarter.Split('/');
strQuarterMonth = strSplitQuarter[0];
strQuarterYear = strSplitQuarter[1];
}
else
{
strQuarterMonth = "";
strQuarterYear = "";
}
string PublishedDate = ds.Tables[0].Rows[i]["PublishedDate"].ToString();
PublishedDate = CleanDateField(PublishedDate).ToString();
string TentativeStartDate = ds.Tables[0].Rows[i]["TentativeStartDate"].ToString();
TentativeStartDate = CleanDateField(TentativeStartDate).ToString();
string TentativeEndDate = ds.Tables[0].Rows[i]["TentativeEndDate"].ToString();
TentativeEndDate = CleanDateField(TentativeEndDate).ToString();
UpdateEarnings((ds.Tables[0].Rows[i]["TickerName"]).ToString(), strQuarterMonth, strQuarterYear,
PublishedDate, TentativeStartDate, TentativeEndDate, ds.Tables[0].Rows[i]["Comments"].ToString());
}
}
else
{
//do nothing
}
OLEConn.Close();
System.IO.File.Delete(strTempPath + fluplEarningsFile.FileName.ToString());
AjaxControlToolkit.ToolkitScriptManager.RegisterStartupScript(this, typeof(string), "Success", "alert('The data has been imported successfully');", true);
}