Exemplo n.º 1
0
 private void mPhysicalStudioFilmAdded(object sender, cFilm film)
 {
     if (film.getFirstValidPictureFile() != null)
     {
         lblInfo.Text    = "Adding film session" + film.getFirstValidPictureFile().pSession + " for camera " + film.pCameraDriver.pName + " " + film.pCameraDriver.pVersion + ", " + film.getEncryptedPictureFiles().Count + " files...";
         lblInfo.Visible = true;
         Application.DoEvents();
     }
 }
Exemplo n.º 2
0
        private void data_NewCaseLogged(object sender, cPictureFile pictureFile, int fileNumber, int numberLogged)
        {
            lblInfo.Visible = true;
            lblInfo.Text    = "Logging " + pictureFile.pEncryptedPicture.pEncryptedFileName + ", " + numberLogged + " images";

            cFilm film = pictureFile.pBelongsToFilm;

            film.pCameraDriver.UpdateFileNumber(pictureFile, fileNumber);

            foreach (ListViewItem item in lsvFiles.Items)
            {
                if (item.Group != null)
                {
                    var groupFilm = (cFilm)item.Group.Tag;

                    cPictureFile pic      = film.getFirstValidPictureFile();
                    cPictureFile picGroup = groupFilm.getFirstValidPictureFile();

                    if (pic != null && picGroup != null)
                    {
                        if (pic.pFormattedSession == picGroup.pFormattedSession)
                        {
                            if (item.Text == pictureFile.pEncryptedPicture.pEncryptedFileName)
                            {
                                updateFilesListItem(item, pictureFile, true, true);
                                break;
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 3
0
        private void data_NewCasePreviouslyLogged(object sender, cFilm film, cEncryptedPictureFile encryptedPictureFile)
        {
            lblInfo.Visible = true;
            lblInfo.Text    = "Previously Logged at " + encryptedPictureFile.pEncryptedFileName;

            foreach (ListViewItem item in lsvFiles.Items)
            {
                if (item.Group != null)
                {
                    var groupFilm = (cFilm)item.Group.Tag;

                    cPictureFile pic      = film.getFirstValidPictureFile();
                    cPictureFile picGroup = groupFilm.getFirstValidPictureFile();

                    if (pic != null && picGroup != null)
                    {
                        if (pic.pFormattedSession == picGroup.pFormattedSession)
                        {
                            if (item.Text == encryptedPictureFile.pEncryptedFileName)
                            {
                                updateFilesListItemPreviouslyLogged(item, "Previously Logged");
                                break;
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 4
0
        private void data_NewCaseLoggedError(object sender, cPictureFile pictureFile, string errorDescription)
        {
            ConnectionStringSettings setting = ConfigurationManager.ConnectionStrings["CoreContext"];
            var data = new cDataAccess(setting.ConnectionString);

            lblInfo.Visible = true;
            lblInfo.Text    = "Errors at " + pictureFile.pEncryptedPicture.pEncryptedFileName;

            foreach (ListViewItem item in lsvFiles.Items)
            {
                cFilm film = pictureFile.pBelongsToFilm;

                if (item.Group != null)
                {
                    var groupFilm = (cFilm)item.Group.Tag;

                    cPictureFile pic      = film.getFirstValidPictureFile();
                    cPictureFile picGroup = groupFilm.getFirstValidPictureFile();

                    if (pic != null && picGroup != null)
                    {
                        if (pic.pFormattedSession == picGroup.pFormattedSession)
                        {
                            if (item.Text == pictureFile.pEncryptedPicture.pEncryptedFileName)
                            {
                                updateFilesListItemError(item, pictureFile, errorDescription);
                                break;
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 5
0
        private static int compare(cFilm a, cFilm b)
        {
            int diff;

            if (a.pCreationTime != null && b.pCreationTime != null)
            {
                diff = DateTime.Compare(b.pCreationTime.Value, a.pCreationTime.Value);
                if (diff != 0)
                {
                    return(diff);
                }
            }

            cPictureFile aPictureFile = a.getFirstValidPictureFile();
            cPictureFile bPictureFile = b.getFirstValidPictureFile();

            if (aPictureFile == null || bPictureFile == null)
            {
                return(0);
            }

            diff = System.String.CompareOrdinal(bPictureFile.pLocationCode, aPictureFile.pLocationCode);
            if (diff != 0)
            {
                return(diff);
            }

            diff = System.String.CompareOrdinal(bPictureFile.pFormattedSession, aPictureFile.pFormattedSession);

            return(diff);
        }
Exemplo n.º 6
0
        private void btnExport_Click(object sender, EventArgs e)
        {
            const string delimiter = ",";

            if (txtDirectory.Text.Length == 0)
            {
                MessageBox.Show("Cannot Export. Please select a directory to export to!", "Cannot Export", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            if (!_film.pHasErrors)
            {
                cPictureFile pic = _film.getFirstValidPictureFile();

                using (StreamWriter sw = File.CreateText(Path.Combine(txtDirectory.Text, pic.pSession + ".txt")))
                {
                    TimeSpan duration = new TimeSpan();

                    if (_film.pStartDate.HasValue && _film.pEndDate.HasValue)
                    {
                        duration = _film.pEndDate.Value - _film.pStartDate.Value;

                        sw.WriteLine(_film.pStartDate.Value.ToString("ddMMyyyy") + delimiter +
                                     pic.pSession + delimiter +
                                     pic.pLocationCode + delimiter +
                                     _film.pInfringements + delimiter +
                                     "0" + delimiter +
                                     "0" + delimiter +
                                     "1" + delimiter +
                                     DateTime.Today + delimiter +
                                     _film.pStartDate.Value + delimiter +
                                     _film.pEndDate.Value + delimiter +
                                     duration.TotalMinutes + delimiter +
                                     _film.pVehiclesChecked + delimiter +
                                     _film.pInfringements + delimiter +
                                     _film.pHighestSpeed + delimiter +
                                     "0" + delimiter +
                                     _film.pAverageSpeed
                                     );
                        sw.Close();
                    }
                    else
                    {
                        MessageBox.Show("Cannot Export. Stats file does not have start and end date!", "Cannot Export", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }
                }

                MessageBox.Show("Done", "Exported", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            else
            {
                MessageBox.Show("Cannot Export Stats file - Film Error!", "Cannot Export", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Exemplo n.º 7
0
        public void BindFormData(cFilm film)
        {
            _film = film;

            if (_film.pHasEncryptedPictureFiles)
            {
                _film.applyStats();

                clearDisplay();

                if (!_film.pHasErrors)
                {
                    cPictureFile pic = film.getFirstValidPictureFile();

                    lblCamDate.Text       = pic.pOffenceDateStringDD_MM_YYYY;
                    lblAveSpeed.Text      = film.pAverageSpeed.ToString("0.0") + " km/h";
                    lblCaptureErrors.Text = film.pCaptureErrors.ToString();
                    if (film.pEndDate.HasValue)
                    {
                        lblEndDate.Text = film.pEndDate.Value.ToString("dd MMM yyyy HH:mm:ss");
                    }
                    else
                    {
                        lblEndDate.Text = "";
                    }

                    lblHighestSpeed.Text  = film.pHighestSpeed + " km/h";
                    lblHighSpeed.Text     = film.pHighSpeedCount.ToString();
                    lblInfringements.Text = film.pInfringements.ToString();
                    lblLocationCode.Text  = pic.pLocationCode;
                    lblLowSpeed.Text      = film.pLowSpeedCount.ToString();
                    lblMeasureErrors.Text = film.pMeasurementErrors.ToString();
                    lblTestPhotos.Text    = film.pTestPhotos.ToString();
                    lblSessionName.Text   = pic.pSession;
                    if (film.pStartDate.HasValue)
                    {
                        lblStartDate.Text = film.pStartDate.Value.ToString("dd MMM yyyy HH:mm:ss");
                    }
                    else
                    {
                        lblStartDate.Text = "";
                    }
                    lblVehiclesChecked.Text = film.pVehiclesChecked.ToString();
                    lblJammers.Text         = film.pJammerCount.ToString();
                }
            }
        }
Exemplo n.º 8
0
        private void checkForValidFilesInSession(cFilm film)
        {
            cPictureFile pictureFile = new cPictureFile();

            string result = string.Empty;

            string[] pdfFile = Directory.GetFiles(film.pPath, "*.pdf");

            if (pdfFile == null || pdfFile.Length == 0)
            {
                result = "No Fieldsheet. ";
            }

            string[] statsFile = Directory.GetFiles(film.pPath, "stat*.txt");

            if (statsFile == null || statsFile.Length == 0)
            {
                result = result + "Enc files can not be validated against stats file as stats file missing. ";
            }

            if ((statsFile != null || statsFile.Length >= 0) && (film.pTestPhotos + film.pInfringements != film.pEncryptedPictureFileCollection.Count))
            {
                result = result + "Enc files do not match stats file";
            }

            if (result != string.Empty)
            {
                pictureFile = film.getFirstValidPictureFile();

                dataAccess.ExceptionLog(Environment.MachineName, result, pictureFile.pFormattedSession,
                                        pictureFile.pOffenceDate, pictureFile.pLocationCode,
                                        pictureFile.pEncryptedPicture.pEncryptedFilePath, pictureFile.pEncryptedPicture.pEncryptedFileName);

                errorWriting.WriteErrorLog(result, "Session: " + pictureFile.pFormattedSession +
                                           "; OffenceDate: " + pictureFile.pOffenceDateStringYYYYMMDD +
                                           "; Location: " + pictureFile.pLocationCode +
                                           "; FilePath: " + pictureFile.pEncryptedPicture.pEncryptedFilePath +
                                           "; FileName: " + pictureFile.pEncryptedPicture.pEncryptedFileName);
            }
        }
Exemplo n.º 9
0
        public void BindFormData(cFilm film)
        {
            string statsFileName;

            if (film.pHasEncryptedPictureFiles)
            {
                film.applyStats();

                //*****First Record is the Operator and Stats
                ReportSource rsMain = new ReportSource
                {
                    AverageSpeed         = film.pAverageSpeed,
                    CountOfInfringements = film.pInfringements,
                    ErrorsCount          = film.pCaptureErrors,
                    HighestSpeed         = film.pHighestSpeed,
                    JammerCount          = film.pJammerCount,
                    TestPhotoCount       = film.pTestPhotos,
                    VehiclesChecked      = film.pVehiclesChecked
                };

                statsFileName = film.pStatsFileName == string.Empty ? "None" : film.pStatsFileName;

                if (film.pStartDate != null && film.pEndDate != null)
                {
                    rsMain.Time = film.pStartDate.Value.ToString("HH:mm:ss tt") + "-" + film.pEndDate.Value.ToString("HH:mm:ss tt");
                }

                _rs.Add(rsMain);

                int locationCounter = 0;

                var groupByDate = from f in film.getPicturesFiles()
                                  where f.pHasError == false
                                  group f by f.pOffenceDateStringDD_MM_YYYY into g
                                  select g;

                List <string> lst   = new List <string>();
                List <string> camId = new List <string>();

                foreach (IGrouping <string, cPictureFile> pictureFilesDate in groupByDate)
                {
                    var groupByLocation = from f in pictureFilesDate
                                          where f.pHasError == false
                                          group f by f.pLocationCode into g
                                          select g;

                    foreach (IGrouping <string, cPictureFile> pictureFilesLocation in groupByLocation)
                    {
                        locationCounter++;
                        ReportSource rs = new ReportSource {
                            CamDate = pictureFilesLocation.First().pOffenceDateStringDD_MM_YYYY, Session = "Actual", LocationCode = pictureFilesLocation.First().pLocationCode
                        };

                        foreach (cPictureFile pictureFile in pictureFilesLocation)
                        {
                            if (!lst.Contains(pictureFile.pOperatorId))
                            {
                                lst.Add(pictureFile.pOperatorId);
                            }

                            if (pictureFile.pIsTest)
                            {
                                rs.TestPhotoCount++;
                            }
                            else if (pictureFile.pIsJammer)
                            {
                                rs.JammerCount++;
                            }
                            else if (pictureFile.pHasError)
                            {
                                rs.ErrorsCount++;
                            }
                            else
                            {
                                rs.CountOfInfringements++;
                            }

                            if (!camId.Contains(pictureFile.pMachineId))
                            {
                                camId.Add(pictureFile.pMachineId);
                            }
                        }

                        DateTime?start = pictureFilesLocation.First().pOffenceDate;
                        DateTime?end   = pictureFilesLocation.Last().pOffenceDate;
                        if (start != null && end != null)
                        {
                            rs.Time = start.Value.ToString("HH:mm:ss tt") + "-" + end.Value.ToString("HH:mm:ss tt");
                        }

                        _rs.Add(rs);
                    }
                }

                StringBuilder sb = new StringBuilder();
                foreach (string s in lst)
                {
                    sb.Append(s);
                    sb.Append(",");
                }

                rsMain.Operators = sb.ToString().TrimEnd(',');

                cPictureFile pic = film.getFirstValidPictureFile();

                if (pic != null)
                {
                    rsMain.LocationCode = locationCounter > 1 ? "*VARIOUS" : pic.pLocationCode;
                    rsMain.CamDate      = pic.pOffenceDateStringDD_MM_YYYY;
                    rsMain.Session      = pic.pFormattedSession;
                }

                sb.Clear();
                foreach (string c in camId)
                {
                    sb.Append(c);
                    sb.Append(",");
                }

                rsMain.CamID = sb.ToString().TrimEnd(',');

                rsMain.StatsFileName = string.IsNullOrWhiteSpace(statsFileName) ? "No  File" : statsFileName;

                ConnectionStringSettings setting = ConfigurationManager.ConnectionStrings["CoreContext"];
                var data = new cDataAccess(setting.ConnectionString);

                string userDetail = data.getUserDetail(userId);
                rsMain.LoggedBy = userDetail;
            }
        }
Exemplo n.º 10
0
        private void Log_Case(ListViewItem sessionItem)
        {
            int totalLoggedCases      = 0;
            int totalPreviouslyLogged = 0;

            mUserId            = 2; //AutoiLog user on Credentials
            SavedStatsFilePath = ConfigurationManager.AppSettings["SavedStatsFilePath"];
            SavedStatsFilePath = SavedStatsFilePath + "\\" + serverDateTime.Date.ToString("yyyyMMdd");

            Directory.CreateDirectory(SavedStatsFilePath);
            cFilm film = new cFilm();

            try
            {
                if (sessionItem != null)
                {
                    film = (cFilm)sessionItem.Tag;

                    int   numberLoggedCases;
                    int   previouslyLogged;
                    cFilm reportFilm;
                    if (dataAccess.logNewCases(film, mUserId, mImagePath, out numberLoggedCases, out reportFilm, out previouslyLogged))
                    {
                        totalLoggedCases      += numberLoggedCases;
                        totalPreviouslyLogged += previouslyLogged;

                        if (totalPreviouslyLogged > 0)
                        {
                            errorWriting.WriteErrorLog(string.Format("Total Infringements logged {0} out of {1} and Total Previously logged {2} out of {1}", totalLoggedCases, film.pEncryptedPictureFileCollection.Count(), totalPreviouslyLogged));
                        }
                        else
                        {
                            errorWriting.WriteErrorLog(string.Format("Total Infringements logged {0} out of {1}", totalLoggedCases, film.pEncryptedPictureFileCollection.Count()));
                        }

                        if (numberLoggedCases > 0)
                        {
                            //Check if session is missing any files for SAfETYCAM infringements only
                            if (film.pCameraDriver.pName.ToUpper() == "SAFETYCAM")
                            {
                                checkForValidFilesInSession(film);
                            }

                            string date = DateTime.Now.ToString("yyyyMMdd HHmmss");

                            //Generate stats file here and save it.
                            var sf = new StatsReport();
                            sf.BindFormData(reportFilm);
                            sf.Save(String.Format("{0}\\{1}-{2}.pdf",
                                                  SavedStatsFilePath,
                                                  sessionItem.Text,
                                                  date));

                            //Process vosi list
                            dataAccess.logVosiFile(film);

                            if (!string.IsNullOrEmpty(film.pStatsFileName))
                            {
                                FileInfo fileInfo         = new FileInfo(film.pStatsFileName);
                                var      encStatsFileList = dataAccess.ReadStatsFile(fileInfo);
                                dataAccess.SubmitStatsFile(encStatsFileList);
                            }

                            Application.DoEvents();

                            int sessionLogged;
                            dataAccess.checkLoggedSessions(film, out sessionLogged);
                        }
                    }

                    if (dataAccess.pError.Length > 0)
                    {
                        if (film.getFirstValidPictureFile() != null)
                        {
                            errorWriting.WriteErrorLog("ERROR with logging film in path:" + film.pPath + "; Session: " + film.getFirstValidPictureFile().pFormattedSession + "; Error:  " + dataAccess.pError);
                        }
                        else
                        {
                            errorWriting.WriteErrorLog("ERROR with logging film <SESSION READ ERROR> - " + dataAccess.pError);
                        }
                    }

                    mPhysicalStudio.ClearFilm(film);
                }
            }
            catch (Exception ex)
            {
                dataAccess.ExceptionLog(Environment.MachineName, ex.Message + " Inner: " + ex.InnerException, film.getFirstValidPictureFile().pFormattedSession,
                                        film.getFirstValidPictureFile().pOffenceDate, film.getFirstValidPictureFile().pLocationCode, film.pPath, "");

                errorWriting.WriteErrorLog(ex.Message + " Inner: " + ex.InnerException, "Session: " + film.getFirstValidPictureFile().pFormattedSession +
                                           "; OffenceDate: " + film.getFirstValidPictureFile().pOffenceDate +
                                           "; FilePath: " + film.pPath);
            }
        }