protected void ButtonImport_Click(object sender, EventArgs e)
 {
     var uploader = new AddressUploadBatch(GetFileName(), CheckIgnoreErrorsInDataFile.Checked);
     uploader.DoBulkUpload(this.CheckBoxDeleteExisting.Checked);
     PanelImportSuccessful.Visible = true;
     PanelPreview.Visible = false;
 }
 public void DisplayCantProceedBecauseOfGeocode(AddressUploadBatch latestBatch)
 {
     GeocodingProxy geoProxy = new GeocodingProxy();
     LabelNumberAvailableGeocodes.Text = geoProxy.AvailableToday.ToString();
     LabelNumberOfDesiredGeocodes.Text = latestBatch.GetDistinctAddressesInBatch().Count().ToString();
     Panel1CantContinue.Visible = true;
 }
    private void ViewData()
    {
        uploader = new AddressUploadBatch(GetFileName(), CheckIgnoreErrorsInDataFile.Checked);
        try
        {
            PanelUpload.Visible = false;
            PanelPreview.Visible = true;
            ButtonImport.Visible = true;

            var importValid = uploader.IsUploadValid();
            if (!importValid)
            {
                DisplayFileImportError();
            }
            GridViewExcel.DataSource = uploader.GetUploadedData();
            GridViewExcel.DataBind();

            foreach (GridViewRow thisRow in GridViewExcel.Rows)
            {
                var cell = thisRow.Cells[thisRow.Cells.Count - 1];
                if (cell.Text.StartsWith("OK"))
                {
                    cell.BackColor = Color.LightGreen;
                   // cell.ForeColor = Color.White;
                }
                else if (cell.Text.StartsWith("ERROR"))
                {
                    cell.BackColor = Color.DarkRed;
                    cell.ForeColor = Color.White;
                }
                else
                {
                    cell.BackColor = Color.LightGray;
                }
            }

            if (uploader._errorList.Count > 0)
            {
                throw new Exception(); ;

            }
        }
        catch (Exception ex)
        {
            DisplayFileImportError();
        }
    }
        private AddressUploadBatch CreateNewBatch()
        {
            var db = new TerritoryDBDataContext();
            FileInfo thisFileInfo = new FileInfo(_fileName);
            // before uploading a new batch let's delete
            // any other batch that might be related to the same session (file name = session)
            var listToDelete = (from au in db.AddressUploadBatches
                                where au.FileName == thisFileInfo.Name
                                select au);
            db.AddressUploadBatches.DeleteAllOnSubmit(listToDelete);
            db.SubmitChanges();

            // delete all uploads older than 1 day (to clean up the database)
            var cutoffDate = DateTime.Now.AddDays(-1);
            listToDelete = (from au in db.AddressUploadBatches
                            where au.DateStarted < cutoffDate
                            select au);
            db.AddressUploadBatches.DeleteAllOnSubmit(listToDelete);
            db.SubmitChanges();

            var newBatch = new AddressUploadBatch();
            newBatch.DateStarted = DateTime.Now;
            newBatch.Status = "STARTED";
            newBatch.TerritoryId = CurrentUser.TerritoryId;
            newBatch.FileName = thisFileInfo.Name;
            db.AddressUploadBatches.InsertOnSubmit(newBatch);
            db.SubmitChanges();
            return newBatch;
        }
 private void BatchFinished(AddressUploadBatch batch)
 {
     var db = new TerritoryDBDataContext();
     db.AddressUploadBatches.Attach(batch);
     batch.Status = "COMPLETED";
     batch.DateCompleted = DateTime.Now;
     db.SubmitChanges();
 }