private void StoreValuesToDataSet()
    {
        if (DsLogs == null)
        {
            AnnualImportDetails impDetails = new AnnualImportDetails(CurrentConnectionManager);
            DsLogs = impDetails.SelectImportDetails(IdImport);
            DsLogs.Tables[0].PrimaryKey = new DataColumn[] { DsLogs.Tables[0].Columns["IdRow"] };
        }
        Hashtable newValues = new Hashtable();

        foreach (GridDataItem item in grdImportDetails.Items)
        {
            if (item.IsInEditMode)
            {
                item.ExtractValues(newValues);
                DataRow row = DsLogs.Tables[0].Rows.Find(item["Row Number"].Text);

                row["CostCenter"]    = DSUtils.GetValueToInsertInDataSet(newValues["CostCenter"]);
                row["ProjectCode"]   = DSUtils.GetValueToInsertInDataSet(newValues["ProjectCode"]);
                row["WPCode"]        = DSUtils.GetValueToInsertInDataSet(newValues["WPCode"]);
                row["AccountNumber"] = DSUtils.GetValueToInsertInDataSet(newValues["AccountNumber"]);
                row["Quantity"]      = DSUtils.GetValueToInsertInDataSet(newValues["Quantity"]);
                row["Value"]         = DSUtils.GetValueToInsertInDataSet(newValues["Value"]);
                row["CurrencyCode"]  = DSUtils.GetValueToInsertInDataSet(newValues["CurrencyCode"]);
                DateTime date;
                if (newValues["Date"] != null && DateTime.TryParse(newValues["Date"].ToString(), out date))
                {
                    row["Date"] = newValues["Date"];
                }
            }
        }
    }
 /// <summary>
 /// Loads the data
 /// </summary>
 private void LoadEditableGrid()
 {
     if (DsLogs == null)
     {
         AnnualImportDetails impDetails = new AnnualImportDetails(CurrentConnectionManager);
         DsLogs = impDetails.AnnualSelectImportDetailsWithErrors(IdImport, Request.ApplicationPath);
         grdImportDetails.DataSource = DsLogs;
     }
     else
     {
         grdImportDetails.DataSource = DsLogs;
     }
     DsLogs.Tables[0].PrimaryKey = new DataColumn[] { DsLogs.Tables[0].Columns["IdRow"] };
 }
    /// <summary>
    /// Populates the controls from header
    /// </summary>
    private void LoadHeader()
    {
        AnnualImportDetails impDetails = new AnnualImportDetails(CurrentConnectionManager);

        impDetails.IdImport = IdImport;
        DataSet dsHeader = impDetails.SelectHeaderInformation();

        if (dsHeader.Tables.Count != 3)
        {
            this.ShowError(new IndException(ApplicationMessages.EXCEPTION_DATA_SET_CORRUPTED));
            return;
        }
        DataRow sourceRow = dsHeader.Tables[0].Rows[0];

        //Populate the controls
        txtCountry.Text  = sourceRow["Country"].ToString();
        txtFileName.Text = sourceRow["FileName"].ToString();
        txtDate.Text     = ((DateTime)sourceRow["Date"]).ToShortDateString();
        txtUserName.Text = sourceRow["UserName"].ToString();
        string TotalNoOfRows = sourceRow["Lines"].ToString();

        txtLines.Text = TotalNoOfRows;


        DataRow sourceRow1 = dsHeader.Tables[1].Rows[0];
        string  NoOfErrors = sourceRow1["NoOfErrors"].ToString();

        txtNoOfErrors.Text = NoOfErrors;

        DataRow sourceRow2 = dsHeader.Tables[2].Rows[0];
        string  NoOfRowsOK = sourceRow2["NoOfRowsOk"].ToString();

        txtNoOfRowsOK.Text = NoOfRowsOK;
        int NoOfRowsIgnored = int.Parse(TotalNoOfRows) - int.Parse(NoOfRowsOK);

        txtNoOfRowsIgnored.Text = NoOfRowsIgnored.ToString();

        txtPeriod.Text = sourceRow["Period"].ToString();
    }
    protected void grdImportDetails_ItemCommand(object source, Telerik.WebControls.GridCommandEventArgs e)
    {
        try
        {
            if (e.CommandName == "UpdateAll")
            {
                //First store modifications made in this page to the dataset
                StoreValuesToDataSet();

                List <AnnualImportDetails> imList = new List <AnnualImportDetails>();

                foreach (DataRow row in DsLogs.Tables[0].Rows)
                {
                    AnnualImportDetails importDetails = new AnnualImportDetails(CurrentConnectionManager);
                    importDetails.IdImport      = (int)row["IdImport"];
                    importDetails.IdRow         = (int)row["IdRow"];
                    importDetails.CostCenter    = (row["CostCenter"] == DBNull.Value) ? string.Empty : row["CostCenter"].ToString();
                    importDetails.ProjectCode   = (row["ProjectCode"] == DBNull.Value) ? string.Empty : row["ProjectCode"].ToString();
                    importDetails.WPCode        = (row["WPCode"] == DBNull.Value) ? string.Empty : row["WPCode"].ToString();
                    importDetails.AccountNumber = (row["AccountNumber"] == DBNull.Value) ? string.Empty : row["AccountNumber"].ToString();
                    if (row["Quantity"] != DBNull.Value)
                    {
                        importDetails.Quantity = (decimal)row["Quantity"];
                    }
                    if (row["Value"] != DBNull.Value)
                    {
                        importDetails.Value = (decimal)row["Value"];
                    }
                    if (row["CurrencyCode"] != DBNull.Value)
                    {
                        importDetails.CurrencyCode = row["CurrencyCode"].ToString();
                    }
                    if (row["Date"] != DBNull.Value)
                    {
                        importDetails.ImportDate = (DateTime)row["Date"];
                    }
                    imList.Add(importDetails);
                }

                if (imList.Count > 0)
                {
                    AnnualImportDetails annualImportDetails = new AnnualImportDetails(CurrentConnectionManager);
                    DataSet             dsNewCreatedFile    = annualImportDetails.UpdateBatchImportDetails(imList);

                    //After saving, remove the previous information from the session so that the old data (from the annual logs)
                    //is loaded from the db
                    DsLogs = null;
                    LoadEditableGrid();

                    CreateNewFile(dsNewCreatedFile);
                }

                if (!Page.ClientScript.IsClientScriptBlockRegistered(this.Page.GetType(), "ButtonUpdateClick"))
                {
                    Page.ClientScript.RegisterClientScriptBlock(this.Page.GetType(), "ButtonUpdateClick", "window.returnValue = 1; window.close();", true);
                }
            }
            //When changing the page, we need to store any possible modifications made to the current page in the underlying datasource of the
            //grid
            if (e.CommandName == "Page")
            {
                StoreValuesToDataSet();
            }
        }
        catch (IndException indExc)
        {
            SaveSuccessful = false;
            ShowError(indExc);
        }
        catch (Exception exc)
        {
            SaveSuccessful = false;
            ShowError(new IndException(exc));
        }
        finally
        {
            if (!ClientScript.IsClientScriptBlockRegistered(this.GetType(), "ResizePopUp"))
            {
                ClientScript.RegisterClientScriptBlock(this.GetType(), "ResizePopUp", "SetPopUpHeight();", true);
            }
        }
    }