コード例 #1
0
        protected void buttonConvert_Click(object sender, EventArgs e)
        {
            DataTable csvColTable;
            DataTable csvTable;
            string    filename;
            string    exchangeCode;

            try
            {
                csvColTable = (DataTable)ViewState["CSVColData"];
                csvTable    = (DataTable)ViewState["CSVData"];

                if ((csvColTable == null) || (csvColTable.Rows.Count <= 0) || (csvTable == null) || (csvTable.Rows.Count <= 0))
                {
                    labelMessage.Text = "Problem while fetching data from imported file. Please try importing file again.";
                }
                else
                {
                    //first remove all columns that are not mapped from the csvtable
                    foreach (DataRow row in csvColTable.Rows)
                    {
                        if (row["TargetCol"].ToString().Length <= 0)
                        {
                            csvTable.Columns.Remove(row["SourceCol"].ToString());
                        }
                    }
                    csvTable.AcceptChanges();
                    //ViewState["CSVData"] = csvTable;
                    //ViewState["UploadedFileName"] = Session["PortfolioFolder"].ToString() + "\\" + FileUploadCSV.FileName;
                    filename = ViewState["UploadedFileName"].ToString();
                    filename = filename.ToLower().Replace(".csv", ".xml");
                    if (File.Exists(filename))
                    {
                        labelMessage.Text = "Data will be appended to existing file: " + filename;
                    }
                    //int i = 1;
                    //while ((File.Exists(filename)) || (i <= 20))
                    //{
                    //    if (i == 1)
                    //    {
                    //        filename = filename.Replace(".xml", "_" + i.ToString() + ".xml");
                    //    }
                    //    else
                    //    {
                    //        filename = filename.Replace("_" + (i - 1).ToString() + ".xml", "_" + i + ".xml");
                    //    }
                    //    i++;
                    //    if(i == 20)
                    //    {
                    //        labelMessage.Text = "Data will be appended to existing file:" + filename;
                    //    }
                    //}
                    if (ddlCountry.SelectedIndex >= 0)
                    {
                        exchangeCode = ddlCountry.SelectedValue;
                    }
                    else
                    {
                        exchangeCode = ".BSE";
                    }
                    if (StockApi.convertTableToPortfolio(filename, csvTable, csvColTable, exchangeCode, apiKey: Session["ApiKey"].ToString()))
                    {
                        labelMessage.Text = "Data uploaded to file - " + filename;

                        string folderPath = Server.MapPath("~/scriptdata/");
                        bool   bIsTestOn  = true;
                        if (Session["DATAFOLDER"] != null)
                        {
                            folderPath = Session["DATAFOLDER"].ToString();
                        }
                        if (Session["IsTestOn"] != null)
                        {
                            bIsTestOn = System.Convert.ToBoolean(Session["IsTestOn"]);
                        }

                        DataTable dt = StockApi.getPortfolioTable(folderPath, filename, false, bIsTestOn, apiKey: Session["ApiKey"].ToString());
                        if (dt != null)
                        {
                            GridViewMapped.DataSource = dt;
                            GridViewMapped.DataBind();
                            ViewState["MappedData"] = dt;
                        }
                    }
                    else
                    {
                        labelMessage.Text = "Failed to uploaded data to file - " + filename;
                    }
                }
            }
            catch (Exception ex)
            {
            }
        }
コード例 #2
0
 protected void GridViewMapped_PageIndexChanging(object sender, GridViewPageEventArgs e)
 {
     GridViewMapped.PageIndex  = e.NewPageIndex;
     GridViewMapped.DataSource = (DataTable)ViewState["MappedData"];
     GridViewMapped.DataBind();
 }