Example #1
0
        public async Task <IActionResult> PutProjectionData([FromRoute] int id, [FromBody] ProjectionData projectionData)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != projectionData.Id)
            {
                return(BadRequest());
            }

            _context.Entry(projectionData).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ProjectionDataExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Example #2
0
            public ProjectSystemHandler(MonoDevelopWorkspace workspace, ProjectDataMap projectMap, ProjectionData projections)
            {
                this.workspace   = workspace;
                this.projectMap  = projectMap;
                this.projections = projections;

                metadataHandler = new Lazy <MetadataReferenceHandler> (() => new MetadataReferenceHandler(workspace.MetadataReferenceManager, projectMap));
            }
Example #3
0
            public ProjectSystemHandler(MonoDevelopWorkspace workspace, ProjectDataMap projectMap, ProjectionData projections)
            {
                this.workspace   = workspace;
                this.projectMap  = projectMap;
                this.projections = projections;

                metadataHandler            = new Lazy <MetadataReferenceHandler> (() => new MetadataReferenceHandler(workspace.MetadataReferenceManager, projectMap));
                hostDiagnosticUpdateSource = new Lazy <HostDiagnosticUpdateSource> (() => new HostDiagnosticUpdateSource(workspace, Composition.CompositionManager.GetExportedValue <IDiagnosticUpdateSourceRegistrationService> ()));
            }
Example #4
0
        public async Task <IActionResult> PostProjectionData([FromBody] ProjectionData projectionData)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            _context.ProjectionData.Add(projectionData);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetProjectionData", new { id = projectionData.Id }, projectionData));
        }
Example #5
0
        private void perspectivePanel_Paint(object sender, PaintEventArgs e)
        {
            var transformationMatrix = Matrix4x4.Translation(0, 0, 2) * _view * _world * _rotationX * _rotationY *
                                       _rotationZ *
                                       _scalation * Matrix4x4.Translation(0, 0, -2);
            var projectionData = new ProjectionData(perspectivePanel.Size, 16f / 9f, (float)Math.PI / 3f, 0.1f, 100f);

            Func <Vector4, Vector2> projectPerspective = vector =>
            {
                var perspectiveVector = vector * Matrix4x4.PerspectiveFieldOfView(projectionData);
                perspectiveVector.X /= perspectiveVector.W;
                perspectiveVector.Y /= perspectiveVector.W;
                perspectiveVector.Z /= perspectiveVector.W;

                var deviceVector = perspectiveVector *
                                   Matrix4x4.Scalation(projectionData.CanvasSize.Width / 2.0,
                                                       projectionData.CanvasSize.Height / 2.0, 1);
                return(new Vector2(deviceVector.X + projectionData.CanvasSize.Width / 2,
                                   projectionData.CanvasSize.Height / 2 - deviceVector.Y));
            };

            var displayCoordinates = new PointF[_vertices.Length];

            for (var i = 0; i < _vertices.Length; i++)
            {
                var displayVector = projectPerspective(_vertices[i] * transformationMatrix);
                displayCoordinates[i] = new PointF((float)displayVector.X, (float)displayVector.Y);
            }

            var g = e.Graphics;

            g.SmoothingMode   = SmoothingMode.AntiAlias;
            g.PixelOffsetMode = PixelOffsetMode.HighQuality;
            using (var p = new Pen(_color, 3))
            {
                for (int i = 0, j = 3; i < 4; j = i, i++)
                {
                    g.DrawLine(p, displayCoordinates[i], displayCoordinates[j]);
                }
                for (int i = 4, j = 7; i < 8; j = i, i++)
                {
                    g.DrawLine(p, displayCoordinates[i], displayCoordinates[j]);
                }
                for (int i = 0, j = 4; i < 4; i++, j++)
                {
                    g.DrawLine(p, displayCoordinates[i], displayCoordinates[j]);
                }
            }
        }
Example #6
0
        public static IProjection Val(this IProjection projection)
        {
            if (projection.Data == null)
            {
                throw ProjectionException.ValueNotFound(projection.Metadata);
            }

            IProjectionData newData = ProjectionData.Resolve(projection.Data, projection.Metadata);

            if (newData.Source.Snapshot == null)
            {
                throw ProjectionException.ValueNotFound(newData.Source);
            }

            return(projection.With(data: newData));
        }
Example #7
0
            public ProjectSystemHandler(MonoDevelopWorkspace workspace, ProjectDataMap projectMap, ProjectionData projections)
            {
                this.workspace      = workspace;
                this.projectMap     = projectMap;
                this.projections    = projections;
                this.workspaceCache = new WorkspaceFilesCache();

                metadataHandler            = new Lazy <MetadataReferenceHandler> (() => new MetadataReferenceHandler(workspace.MetadataReferenceManager, projectMap));
                hostDiagnosticUpdateSource = new Lazy <HostDiagnosticUpdateSource> (() => new HostDiagnosticUpdateSource(workspace, workspace.compositionManager.GetExportedValue <IDiagnosticUpdateSourceRegistrationService> ()));

                var persistentStorageLocationService = (MonoDevelopPersistentStorageLocationService)workspace.Services.GetService <IPersistentStorageLocationService> ();

                if (workspace.MonoDevelopSolution != null)
                {
                    persistentStorageLocationServiceRegistration = persistentStorageLocationService.RegisterPrimaryWorkspace(workspace.Id);
                }
            }
Example #8
0
        /// <summary>
        ///     Adds an underlay registration to the database.
        /// </summary>
        /// <param name="definition">optional satellite definition used to generate underlay</param>
        /// <param name="data">underlay rendering options</param>
        /// <param name="underlayPath">path to rendered underlay</param>
        public async Task RegisterCacheAsync(SatelliteDefinition?definition, ProjectionData data, string underlayPath)
        {
            await using var connection = new SqliteConnection(ConnectionString);
            await connection.OpenAsync();

            string sql = definition == null
                ? "INSERT INTO UnderlayCache(Filename, Configuration, Timestamp) VALUES(@Filename, @Configuration, @Timestamp)"
                : "INSERT INTO UnderlayCache(Filename, Configuration, Longitude, Timestamp) VALUES(@Filename, @Configuration, @Longitude, @Timestamp)";

            var timestamp = File.GetLastWriteTimeUtc(underlayPath);
            await connection.ExecuteAsync(sql, new
            {
                Filename      = underlayPath,
                Configuration = JsonConvert.SerializeObject(data),
                Longitude     = definition?.Longitude,
                Timestamp     = (DateTimeOffset)timestamp
            });
        }
Example #9
0
        private void perspectivePanel_Paint(object sender, PaintEventArgs e)
        {
            var transformationMatrix = Matrix4x4.Translation(0, 0, 2)*_view*_world*_rotationX*_rotationY*_rotationZ*
                                       _scalation*Matrix4x4.Translation(0, 0, -2);
            var projectionData = new ProjectionData(perspectivePanel.Size, 16f/9f, (float) Math.PI/3f, 0.1f, 100f);

            Func<Vector4, Vector2> projectPerspective = vector =>
            {
                var perspectiveVector = vector*Matrix4x4.PerspectiveFieldOfView(projectionData);
                perspectiveVector.X /= perspectiveVector.W;
                perspectiveVector.Y /= perspectiveVector.W;
                perspectiveVector.Z /= perspectiveVector.W;

                var deviceVector = perspectiveVector*
                                   Matrix4x4.Scalation(projectionData.CanvasSize.Width/2.0,
                                       projectionData.CanvasSize.Height/2.0, 1);
                return new Vector2(deviceVector.X + projectionData.CanvasSize.Width/2,
                    (projectionData.CanvasSize.Height/2) - deviceVector.Y);
            };

            PointF[] displayCoordinates = new PointF[_vertices.Length];
            for (int i = 0; i < _vertices.Length; i++)
            {
                Vector2 displayVector = projectPerspective(_vertices[i]*transformationMatrix);
                displayCoordinates[i] = new PointF((float) displayVector.X, (float) displayVector.Y);
            }

            Graphics g = e.Graphics;
            g.SmoothingMode = SmoothingMode.AntiAlias;
            g.PixelOffsetMode = PixelOffsetMode.HighQuality;
            using (Pen p = new Pen(_color, 3))
            {
                for (int i = 0, j = 3; i < 4; j = i, i++)
                    g.DrawLine(p, displayCoordinates[i], displayCoordinates[j]);
                for (int i = 4, j = 7; i < 8; j = i, i++)
                    g.DrawLine(p, displayCoordinates[i], displayCoordinates[j]);
                for (int i = 0, j = 4; i < 4; i++, j++)
                    g.DrawLine(p, displayCoordinates[i], displayCoordinates[j]);
            }
        }
Example #10
0
        public override void DoBulkInsert <T>(Table <T> table, List <T> rows, IDbConnection connection)
        {
            int pageSize = UseBulkInsert[table];
            //ProjectionData projData = ProjectionData.FromReflectedType(typeof(T));
            ProjectionData projData    = AttribHelper.GetProjectionData(typeof(T));
            TableAttribute tableAttrib = typeof(T).GetCustomAttributes(false).OfType <TableAttribute>().Single();

            //build "INSERT INTO products (ProductName, SupplierID, CategoryID, QuantityPerUnit)"
            string header = "INSERT INTO " + tableAttrib.Name + " " + InsertClauseBuilder.InsertRowHeader(projData);

            foreach (List <T> page in Page.Paginate(rows, pageSize))
            {
                int                     numFieldsAdded = 0;
                StringBuilder           sbValues       = new StringBuilder(" VALUES ");
                List <IDbDataParameter> paramList      = new List <IDbDataParameter>();

                IDbCommand cmd = connection.CreateCommand();

                //package up all fields in N rows:
                string separator = "";
                foreach (T row in page)
                {
                    //prepare values = "(?P1, ?P2, ?P3, ?P4)"
                    string values =
                        InsertClauseBuilder.InsertRowFields(this, cmd, row, projData, paramList, ref numFieldsAdded);
                    sbValues.Append(separator).Append(values);
                    separator = ", ";
                }

                string sql = header + sbValues; //'INSET t1 (field1) VALUES (11),(12)'
                cmd.CommandText = sql;
                paramList.ForEach(param => cmd.Parameters.Add(param));

                int result = cmd.ExecuteNonQuery();
            }
        }
Example #11
0
        /// <summary>
        ///     Retrieves an underlay image from the cache.
        /// </summary>
        public async Task <Image <Rgba32>?> GetUnderlayAsync(SatelliteDefinition?definition, ProjectionData data)
        {
            var metadata = await _repository.GetCacheMetadataAsync(definition, data);

            if (metadata == null)
            {
                return(null);
            }

            var path = metadata.Filename;

            var fullPath = Path.Combine(_cachePath, path);

            // Remove underlay registration from cache if it has been deleted from disk
            if (!File.Exists(fullPath))
            {
                _logger.LogWarning("Cache file {path} not found; removing from cache registration", path);
                await _repository.ClearCacheEntryAsync(path);
            }

            var fileTimestamp = File.GetLastWriteTimeUtc(_options.UnderlayPath);

            // Check if the source underlay file has been updated since the cache was created
            if (metadata.Timestamp < fileTimestamp)
            {
                _logger.LogInformation("Timestamp of underlay changed; updating cache");
                await _repository.ClearCacheEntryAsync(path);

                return(null);
            }

            try
            {
                if (definition == null)
                {
                    _logger.LogInformation("Using cached underlay");
                }
                else
                {
                    _logger.LogInformation("{definition:l0} Using cached underlay", definition.DisplayName);
                }

                return(await Image.LoadAsync <Rgba32>(fullPath));
            }
            catch (Exception e)
            {
                // Remove underlay registration from cache if there was an error reading it from disk
                _logger.LogWarning(e, "Cache file {path} unable to be read; removing from cache registration", path);
                await _repository.ClearCacheEntryAsync(path);
            }

            return(null);
        }
Example #12
0
        /// <summary>
        ///     Sets an underlay image to the cache.
        /// </summary>
        public async Task SetUnderlayAsync(Image <Rgba32> underlay, SatelliteDefinition?definition, ProjectionData data)
        {
            if (definition == null)
            {
                _logger.LogInformation("Caching underlay");
            }
            else
            {
                _logger.LogInformation("{definition:l0} Caching underlay", definition.DisplayName);
            }

            // Save underlay to disk
            var filename     = $"{Guid.NewGuid()}.jpg";
            var underlayPath = Path.Combine(_cachePath, filename);
            await underlay.SaveAsync(underlayPath);

            // Register underlay path in the cache
            await _repository.RegisterCacheAsync(definition, data, underlayPath);
        }
        public MappingProfile()
        {
            // Domain to API Resouce with Reverse
            CreateMap <UserRegistration, User>()
            .ReverseMap();

            CreateMap <UsersListResource, User>()
            .ReverseMap();

            CreateMap <BuildingDto, Building>()
            .ReverseMap();

            CreateMap <EmployeeDto, Employee>()
            .ReverseMap();

            CreateMap <Project, ProjectDto>()
            .ForMember(pd => pd.CreatedBy, opt => opt.MapFrom(p => string.Format($"{p.CreatedByUser.FirstName} {p.CreatedByUser.LastName}")));

            CreateMap <ProjectDto, Project>()
            .ForMember(p => p.Id, pd => pd.Ignore())
            .ForMember(p => p.Buildings, pd => pd.Ignore())
            .AfterMap((pd, p) =>
            {
                var addedBuildings = pd.Buildings.Select(g => g);
                foreach (var b in addedBuildings)
                {
                    var building = new Building
                    {
                        ProjectId = pd.Id == 0 ? 0 : (int)pd.Id,
                        Title     = b.Title,
                        City      = b.City,
                        Address   = b.Address,
                        Class     = b.Class,
                        Country   = b.Country,
                        IsActive  = true,
                        State     = b.State,
                        Submarket = b.Submarket,
                        Zip       = b.Zip
                    };

                    p.Buildings.Add(building);
                }
            });

            CreateMap <ProjectionDataDto, ProjectionData>()
            .ForMember(p => p.Id, opt => opt.MapFrom(pd => pd.Id == 0 ? 0 : (int)pd.Id))
            .ForMember(p => p.CreatedByUser, opt => opt.Ignore())
            .ForMember(p => p.LastUpdatedBy, opt => opt.MapFrom(pd => pd.UserId))
            .AfterMap((pd, p) =>
            {
                if (pd.UserId == null)
                {
                    p.CreatedBy = pd.UserId;
                }
            })
            .ReverseMap();

            CreateMap <ReportDto, Report>()
            .ForMember(r => r.Id, rd => rd.Ignore())
            .ForMember(r => r.Projections, rd => rd.Ignore())
            .AfterMap((rd, r) =>
            {
                var addedProjections = rd.Projections.Select(g => g);
                foreach (var p in addedProjections)
                {
                    var projectionData = new ProjectionData
                    {
                        BuildingAddress = p.BuildingAddress,
                        BuildingCity    = p.BuildingCity,
                        BuildingCountry = p.BuildingCountry,
                        BuildingState   = p.BuildingState,
                        BuildingTitle   = p.BuildingTitle,
                        BuildingZip     = p.BuildingZip,
                        Class           = p.Class,
                        Designation     = p.Designation,
                        Distance        = p.Distance,
                        Duration        = p.Duration,
                        Email           = p.Email,
                        EmployeeAddress = p.EmployeeAddress,
                        EmployeeCity    = p.EmployeeCity,
                        EmployeeState   = p.EmployeeState,
                        EmployeeCountry = p.EmployeeCountry,
                        EmployeeZip     = p.EmployeeZip,
                        FirstName       = p.FirstName,
                        LastName        = p.LastName,
                        Phone           = p.Phone,
                        Submarket       = p.Submarket
                    };

                    r.Projections.Add(projectionData);
                }
            });
        }
Example #14
0
        protected void btnImport_Click(object sender, EventArgs e)
        {
            try
            {
                string Err = string.Empty;
                if (!FileUpload1.HasFile)
                {
                    Err                = "Please select file";
                    lblerror.Text      = Err;
                    lblerror.ForeColor = Color.Red;
                    lblerror.Visible   = true;
                    return;
                }
                if (!(Path.GetExtension(FileUpload1.FileName).Equals(".xlsx") || Path.GetExtension(FileUpload1.FileName).Equals(".xls")))
                {
                    Err                = "Please Select Excel file (.xls or .xlsx) only ";
                    lblerror.Text      = Err;
                    lblerror.ForeColor = Color.Red;
                    lblerror.Visible   = true;
                    return;
                }
                if (drpYear.SelectedIndex == 0)
                {
                    Err                 = "Please Select Year";
                    lblYerror.Text      = Err;
                    lblYerror.ForeColor = Color.Red;
                    lblYerror.Visible   = true;
                    return;
                }
                if (drpMonth.SelectedIndex == 0)
                {
                    Err                 = "Please Select Month";
                    lblMerror.Text      = Err;
                    lblMerror.ForeColor = Color.Red;
                    lblMerror.Visible   = true;
                    return;
                }
                if (drpCumCA.SelectedIndex == 0)
                {
                    Err = "Please Select Column Number For Cum. Contract Award Actual From Excel";
                    lblCumCAerr.Text      = Err;
                    lblCumCAerr.ForeColor = Color.Red;
                    lblCumCAerr.Visible   = true;
                    return;
                }
                if (drpCumDisb.SelectedIndex == 0)
                {
                    Err                  = "Please Select Column Number For Cum. Disbursement Actual From Excel";
                    lblCumDisb.Text      = Err;
                    lblCumDisb.ForeColor = Color.Red;
                    lblCumDisb.Visible   = true;
                    return;
                }
                if (drpCAct.SelectedIndex == 0)
                {
                    Err                  = "Please Select Column Number For Contract Award Actual From Excel";
                    lblCTarErr.Text      = Err;
                    lblCTarErr.ForeColor = Color.Red;
                    lblCTarErr.Visible   = true;
                    return;
                }
                if (drpDAct.SelectedIndex == 0)
                {
                    Err                  = "Please Select Column Number For Disbursement Award Actual From Excel";
                    lblDTarErr.Text      = Err;
                    lblDTarErr.ForeColor = Color.Red;
                    lblDTarErr.Visible   = true;
                    return;
                }
                if (drpRowNum.SelectedIndex == 0)
                {
                    Err                 = "Please Select Starting Row From Excel";
                    lblRerror.Text      = Err;
                    lblRerror.ForeColor = Color.Red;
                    lblRerror.Visible   = true;
                    return;
                }
                string path = Server.MapPath(@"~/writereaddata/") + FileUpload1.FileName;
                try
                {
                    System.IO.File.Delete(path);
                }
                catch (Exception ex)
                {
                }

                FileUpload1.SaveAs(path);

                clsExcelInterface     objExcel    = new clsExcelInterface();
                DataTable             dtExcelData = objExcel.getExcelDataTable(path);
                List <ProjectionData> ListRows    = new List <ProjectionData>();
                List <ErrorMessage>   ListError   = new List <ErrorMessage>();
                int rowIndex = 0;
                int skiprows = 0;

                foreach (DataRow dr in dtExcelData.Rows)
                {
                    if (skiprows < int.Parse(drpRowNum.SelectedValue) - 1)
                    {
                        skiprows++;
                        continue;
                    }

                    string loanno = dr[0].ToString();
                    if (!string.IsNullOrWhiteSpace(loanno) && loanno.IsNumericText())
                    {
                        if ((dr[drpCumCA.SelectedValue].ToString() != "-") && (!dr[drpCumCA.SelectedValue].ToString().IsNumericText()))
                        {
                            ListError.Add(new ErrorMessage()
                            {
                                row = rowIndex.ToString(), ColumnIndex = 2, LoanNum = loanno, column = "Cum. Contract Award ", Message = "Please enter Numeric value"
                            });
                        }

                        if ((dr[drpCumDisb.SelectedValue].ToString() != "-") && (!dr[drpCumDisb.SelectedValue].ToString().IsNumericText()))
                        {
                            ListError.Add(new ErrorMessage()
                            {
                                row = rowIndex.ToString(), ColumnIndex = 3, LoanNum = loanno, column = "Cum. Disbursement ", Message = "Please enter Numeric value"
                            });
                        }

                        if ((dr[drpCAct.SelectedValue].ToString() != "-") && (!dr[drpCAct.SelectedValue].ToString().IsNumericText()))
                        {
                            ListError.Add(new ErrorMessage()
                            {
                                row = rowIndex.ToString(), ColumnIndex = 4, LoanNum = loanno, column = "Contract Award Monthly", Message = "Please enter Numeric value"
                            });
                        }

                        if ((dr[drpDAct.SelectedValue].ToString() != "-") && (!dr[drpDAct.SelectedValue].ToString().IsNumericText()))
                        {
                            ListError.Add(new ErrorMessage()
                            {
                                row = rowIndex.ToString(), ColumnIndex = 5, LoanNum = loanno, column = "Disbursement Monthly", Message = "Please enter Numeric value"
                            });
                        }

                        if (dr[drpCAct.SelectedValue].ToString() == "-")
                        {
                            camact = "0";
                        }
                        else
                        {
                            if (dr[drpCAct.SelectedValue].ToString().IsNumericText())
                            {
                                camact = String.Format("{0:0.000}", (Math.Round(decimal.Parse(dr[drpCAct.SelectedValue].ToString()), 3)));
                            }
                        }

                        if (dr[drpCumCA.SelectedValue].ToString() == "-")
                        {
                            cumca = "0";
                        }
                        else
                        {
                            if (dr[drpCumCA.SelectedValue].ToString().IsNumericText())
                            {
                                cumca = String.Format("{0:0.000}", (Math.Round(decimal.Parse(dr[drpCumCA.SelectedValue].ToString()), 3)));
                            }
                        }

                        if (dr[drpCumDisb.SelectedValue].ToString() == "-")
                        {
                            cumdisb = "0";
                        }
                        else
                        {
                            if (dr[drpCumDisb.SelectedValue].ToString().IsNumericText())
                            {
                                cumdisb = String.Format("{0:0.000}", (Math.Round(decimal.Parse(dr[drpCumDisb.SelectedValue].ToString()), 3)));
                            }
                        }

                        if (camact.IsNumericText())
                        {
                            ctotal = ctotal + decimal.Parse(camact);
                        }

                        if (dr[drpDAct.SelectedValue].ToString() == "-")
                        {
                            dmact = "0";
                        }
                        else
                        {
                            if (dr[drpDAct.SelectedValue].ToString().IsNumericText())
                            {
                                dmact = String.Format("{0:0.000}", (Math.Round(decimal.Parse(dr[drpDAct.SelectedValue].ToString()), 3)));
                            }
                        }
                        if (dmact.IsNumericText())
                        {
                            dtotal = dtotal + decimal.Parse(dmact);
                        }
                        ProjectionData row = new ProjectionData()
                        {
                            rowIndex = rowIndex.ToString(),
                            LoanNo   = dr[0].ToString(),
                            LoanName = dr[1].ToString(),
                            CAMAct   = camact,
                            DMAct    = dmact,
                            CumCA    = cumca,
                            CumDisb  = cumdisb
                        };
                        ListRows.Add(row);
                        rowIndex++;
                    }
                    camact = string.Empty;
                    dmact  = string.Empty;
                    if (loanno.Contains("Sub-Total"))
                    {
                        ProjectionData row = new ProjectionData()
                        {
                            LoanName = dr[0].ToString(),
                            CAMAct   = String.Format("{0:0.000}", ctotal),
                            DMAct    = String.Format("{0:0.000}", dtotal)
                        };
                        if (!(String.Format("{0:0.000}", (decimal.Parse(dr[drpCAct.SelectedValue].ToString()))) == ctotal.ToString()))
                        {
                            ListError.Add(new ErrorMessage()
                            {
                                row = rowIndex.ToString(), ColumnIndex = 2, LoanNum = loanno, column = "Contract Award", Message = "Total For Contract Award Actual Does Not Match"
                            });
                        }


                        if (!(String.Format("{0:0.000}", (decimal.Parse(dr[drpDAct.SelectedValue].ToString()))) == dtotal.ToString()))
                        {
                            ListError.Add(new ErrorMessage()
                            {
                                row = rowIndex.ToString(), ColumnIndex = 3, LoanNum = loanno, column = "Disbursement", Message = "Total For Disbursement Actual Does Not Match"
                            });
                        }
                        ListRows.Add(row);
                        rowIndex++;
                        ctotal = 0;
                        dtotal = 0;
                    }
                }

                grdExcel.DataSource = ListRows;
                grdExcel.DataBind();
                Session["ExcelRows"] = ListRows;
                grdErrors.DataSource = ListError;
                grdErrors.DataBind();


                foreach (ErrorMessage er in ListError)
                {
                    grdExcel.Rows[Convert.ToInt32(er.row)].BackColor = Color.FromArgb(255, 165, 165);
                    grdExcel.Rows[Convert.ToInt32(er.row)].Cells[er.ColumnIndex + 1].BackColor = Color.FromArgb(255, 140, 140);
                }
                if (grdErrors.Rows.Count == 0)
                {
                    grdErrors.Visible = false;
                    btnUpload.Visible = true;
                    lblerr.Visible    = false;
                }
                else
                {
                    lblerr.Visible    = true;
                    grdErrors.Visible = true;
                    btnUpload.Visible = false;
                }
                //}
            }
            catch (Exception ex)
            {
            }
        }
Example #15
0
        /// <summary>
        ///     Retrieves a cached underlay filename and timestamp based on an optional satellite definition and render options, or
        ///     <c>null</c> if the underlay isn't in the cache.
        /// </summary>
        public async Task <UnderlayMetadata?> GetCacheMetadataAsync(SatelliteDefinition?definition, ProjectionData data)
        {
            await using var connection = new SqliteConnection(ConnectionString);
            await connection.OpenAsync();

            var sql = "SELECT Filename, Timestamp FROM UnderlayCache WHERE Configuration=@Configuration";

            if (definition != null)
            {
                sql += " AND Longitude=@Longitude";
            }

            return(await connection.QueryFirstOrDefaultAsync <UnderlayMetadata>(sql, new
            {
                definition?.Longitude,
                Configuration = JsonConvert.SerializeObject(data)
            }));
        }
        protected void btnImport_Click(object sender, EventArgs e)
        {
            try
            {
                string Err = string.Empty;
                if (!FileUpload1.HasFile)
                {
                    Err                = "               Please select file";
                    lblerror.Text      = Err;
                    lblerror.ForeColor = Color.Red;
                    lblerror.Visible   = true;
                    grdErrors.Visible  = false;
                    grdExcel.Visible   = false;
                    btnUpload.Visible  = false;
                    return;
                }
                if (!(Path.GetExtension(FileUpload1.FileName).Equals(".xlsx")))

                {
                    Err                = "               Please Select Excel file (.xlsx) only ";
                    lblerror.Text      = Err;
                    lblerror.ForeColor = Color.Red;
                    lblerror.Visible   = true;
                    grdErrors.Visible  = false;
                    grdExcel.Visible   = false;
                    btnUpload.Visible  = false;
                    return;
                }

                if (drpYear.SelectedIndex == 0)
                {
                    Err                 = "Please Select Year";
                    lblYerror.Text      = Err;
                    lblYerror.ForeColor = Color.Red;
                    lblYerror.Visible   = true;
                    return;
                }


                path = Server.MapPath(@"~/writereaddata/") + FileUpload1.FileName;


                try
                {
                    System.IO.File.Delete(path);
                }
                catch (Exception ex)
                {
                }
                try
                {
                    FileUpload1.SaveAs(path);
                }
                catch (FileNotFoundException ex)
                {
                    lblerror.Text = "Error creating file";
                }
                catch (Exception ex)
                {
                    throw ex;
                }


                clsExcelInterface     objExcel    = new clsExcelInterface();
                DataTable             dtExcelData = objExcel.getExcelDataTable(path);
                List <ProjectionData> ListRows    = new List <ProjectionData>();
                List <ErrorMessage>   ListError   = new List <ErrorMessage>();
                int rowIndex = 0;
                foreach (DataRow dr in dtExcelData.Rows)
                {
                    string loanno = dr[0].ToString();
                    if (!string.IsNullOrWhiteSpace(loanno) && loanno.IsNumericText())
                    {
                        if ((dr[2].ToString() != "-") && (!dr[2].ToString().IsNumericText()))
                        {
                            ListError.Add(new ErrorMessage()
                            {
                                row = rowIndex.ToString(), ColumnIndex = 2, LoanNum = loanno, column = "Target Q1(CA)", Message = "Please enter Numeric value"
                            });
                        }
                        if ((dr[3].ToString() != "-") && (!dr[3].ToString().IsNumericText()))
                        {
                            ListError.Add(new ErrorMessage()
                            {
                                row = rowIndex.ToString(), ColumnIndex = 3, LoanNum = loanno, column = "Target Q2(CA)", Message = "Please enter Numeric value"
                            });
                        }
                        if ((dr[4].ToString() != "-") && (!dr[4].ToString().IsNumericText()))
                        {
                            ListError.Add(new ErrorMessage()
                            {
                                row = rowIndex.ToString(), ColumnIndex = 4, LoanNum = loanno, column = "Target Q3(CA)", Message = "Please enter Numeric value"
                            });
                        }
                        if ((dr[5].ToString() != "-") && (!dr[5].ToString().IsNumericText()))
                        {
                            ListError.Add(new ErrorMessage()
                            {
                                row = rowIndex.ToString(), ColumnIndex = 5, LoanNum = loanno, column = "Target Q4(CA)", Message = "Please enter Numeric value"
                            });
                        }
                        if ((dr[6].ToString() != "-") && (!dr[6].ToString().IsNumericText()))
                        {
                            ListError.Add(new ErrorMessage()
                            {
                                row = rowIndex.ToString(), ColumnIndex = 6, LoanNum = loanno, column = "Total Target(CA)", Message = "Please enter Numeric value"
                            });
                        }
                        if ((dr[7].ToString() != "-") && (!dr[7].ToString().IsNumericText()))
                        {
                            ListError.Add(new ErrorMessage()
                            {
                                row = rowIndex.ToString(), ColumnIndex = 7, LoanNum = loanno, column = "Target Q1(Dis.)", Message = "Please enter Numeric value"
                            });
                        }
                        if ((dr[8].ToString() != "-") && (!dr[8].ToString().IsNumericText()))
                        {
                            ListError.Add(new ErrorMessage()
                            {
                                row = rowIndex.ToString(), ColumnIndex = 8, LoanNum = loanno, column = "Target Q2(Dis.)", Message = "Please enter Numeric value"
                            });
                        }
                        if ((dr[9].ToString() != "-") && (!dr[9].ToString().IsNumericText()))
                        {
                            ListError.Add(new ErrorMessage()
                            {
                                row = rowIndex.ToString(), ColumnIndex = 9, LoanNum = loanno, column = "Target Q3(Dis.)", Message = "Please enter Numeric value"
                            });
                        }
                        if ((dr[10].ToString() != "-") && (!dr[10].ToString().IsNumericText()))
                        {
                            ListError.Add(new ErrorMessage()
                            {
                                row = rowIndex.ToString(), ColumnIndex = 10, LoanNum = loanno, column = "Target Q4(Dis.)", Message = "Please enter Numeric value"
                            });
                        }
                        if ((dr[11].ToString() != "-") && (!dr[11].ToString().IsNumericText()))
                        {
                            ListError.Add(new ErrorMessage()
                            {
                                row = rowIndex.ToString(), ColumnIndex = 11, LoanNum = loanno, column = "Total Target(Dis.)", Message = "Please enter Numeric value"
                            });
                        }

                        ProjectionData row = new ProjectionData()
                        {
                            rowIndex = rowIndex.ToString(),
                            LoanNo   = dr[0].ToString(),
                            LoanName = dr[1].ToString(),

                            CTarQ1    = dr[2].ToString(),
                            CTarQ2    = dr[3].ToString(),
                            CTarQ3    = dr[4].ToString(),
                            CTarQ4    = dr[5].ToString(),
                            CTotalTar = dr[6].ToString(),

                            DTarQ1    = dr[7].ToString(),
                            DTarQ2    = dr[8].ToString(),
                            DTarQ3    = dr[9].ToString(),
                            DTarQ4    = dr[10].ToString(),
                            DTotalTar = dr[11].ToString()
                        };

                        ListRows.Add(row);
                        if (dr[2].ToString() == "-")
                        {
                            row.CTarQ1 = Convert.ToString(0);
                        }
                        else
                        {
                            if (dr[2].ToString().IsNumericText())
                            {
                                row.CTarQ1 = String.Format("{0:0.0}", (Math.Round(decimal.Parse(row.CTarQ1), 3)));
                            }
                        }

                        if (dr[3].ToString() == "-")
                        {
                            row.CTarQ2 = Convert.ToString(0);
                        }
                        else
                        {
                            if (dr[3].ToString().IsNumericText())
                            {
                                row.CTarQ2 = String.Format("{0:0.0}", (Math.Round(decimal.Parse(row.CTarQ2), 3)));
                            }
                        }

                        if (dr[4].ToString() == "-")
                        {
                            row.CTarQ3 = Convert.ToString(0);
                        }
                        else
                        {
                            if (dr[4].ToString().IsNumericText())
                            {
                                row.CTarQ3 = String.Format("{0:0.0}", (Math.Round(decimal.Parse(row.CTarQ3), 3)));
                            }
                        }

                        if (dr[5].ToString() == "-")
                        {
                            row.CTarQ4 = Convert.ToString(0);
                        }
                        else
                        {
                            if (dr[5].ToString().IsNumericText())
                            {
                                row.CTarQ4 = String.Format("{0:0.0}", (Math.Round(decimal.Parse(row.CTarQ4), 3)));
                            }
                        }

                        if (dr[6].ToString() == "-")
                        {
                            row.CTotalTar = Convert.ToString(0);
                        }
                        else
                        {
                            if (dr[6].ToString().IsNumericText())
                            {
                                row.CTotalTar = String.Format("{0:0.0}", (Math.Round(decimal.Parse(row.CTotalTar), 3)));
                            }
                        }

                        if (dr[7].ToString() == "-")
                        {
                            row.DTarQ1 = Convert.ToString(0);
                        }
                        else
                        {
                            if (dr[7].ToString().IsNumericText())
                            {
                                row.DTarQ1 = String.Format("{0:0.0}", (Math.Round(decimal.Parse(row.DTarQ1), 3)));
                            }
                        }

                        if (dr[8].ToString() == "-")
                        {
                            row.DTarQ2 = Convert.ToString(0);
                        }
                        else
                        {
                            if (dr[8].ToString().IsNumericText())
                            {
                                row.DTarQ2 = String.Format("{0:0.0}", (Math.Round(decimal.Parse(row.DTarQ2), 3)));
                            }
                        }

                        if (dr[9].ToString() == "-")
                        {
                            row.DTarQ3 = Convert.ToString(0);
                        }
                        else
                        {
                            if (dr[9].ToString().IsNumericText())
                            {
                                row.DTarQ3 = String.Format("{0:0.0}", (Math.Round(decimal.Parse(row.DTarQ3), 3)));
                            }
                        }

                        if (dr[10].ToString() == "-")
                        {
                            row.DTarQ4 = Convert.ToString(0);
                        }
                        else
                        {
                            if (dr[10].ToString().IsNumericText())
                            {
                                row.DTarQ4 = String.Format("{0:0.0}", (Math.Round(decimal.Parse(row.DTarQ4), 3)));
                            }
                        }

                        if (dr[11].ToString() == "-")
                        {
                            row.DTotalTar = Convert.ToString(0);
                        }
                        else
                        {
                            if (dr[11].ToString().IsNumericText())
                            {
                                row.DTotalTar = String.Format("{0:0.0}", (Math.Round(decimal.Parse(row.DTotalTar), 3)));
                            }
                        }

                        rowIndex++;
                    }
                }


                grdExcel.DataSource = ListRows;
                grdExcel.DataBind();
                grdExcel.Visible = true;

                Session["ExcelRows"] = ListRows;
                grdErrors.DataSource = ListError;
                grdErrors.DataBind();
                info.Titles[3] = "<b>Contract Award" + "  " + drpYear.SelectedItem.Text + "</b>";
                info.Titles[8] = "<b>Disbursement Award" + "  " + drpYear.SelectedItem.Text + "</b>";


                foreach (ErrorMessage er in ListError)
                {
                    grdExcel.Rows[Convert.ToInt32(er.row)].BackColor = Color.FromArgb(255, 220, 220);
                    grdExcel.Rows[Convert.ToInt32(er.row)].Cells[er.ColumnIndex + 1].BackColor = Color.FromArgb(255, 140, 140);
                }


                if (grdErrors.Rows.Count == 0)
                {
                    grdErrors.Visible = false;
                    btnUpload.Visible = true;
                    lblerr.Visible    = false;
                }
                else
                {
                    lblerr.Visible    = true;
                    grdErrors.Visible = true;
                    btnUpload.Visible = false;
                }
                //}
            }
            catch (Exception ex)
            {
                grdExcel.Visible  = false;
                grdErrors.Visible = false;
                btnUpload.Visible = false;

                string Error = ex.ToString();
                lblerror.Text      = Error;
                lblerror.ForeColor = Color.Red;
                lblerror.Visible   = true;
            }
            finally
            {
                try
                {
                    System.IO.File.Delete(path);
                }
                catch (Exception ex)
                {
                }
            }
        }