Пример #1
0
        private void btnLog_Click(object sender, EventArgs e)
        {
            if (mUserId <= 0)
            {
                MessageBox.Show("You must login with a valid username and password before you can log!", "Cannot Log", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

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

            data.evNewCaseLogged           += data_NewCaseLogged;
            data.evNewCaseLoggedError      += data_NewCaseLoggedError;
            data.evNewCasePreviouslyLogged += data_NewCasePreviouslyLogged;

            Cursor.Current = Cursors.WaitCursor;

            try
            {
                if (lsvSessions.SelectedItems.Count > 0 && lsvSessions.Items.Count > 0)
                {
                    if (lsvSessions.SelectedItems.Count > 1)
                    {
                        if (MessageBox.Show("You have selected " + lsvSessions.SelectedItems.Count + " sessions to log. Are you sure you want to continue?", "Multi session Log mode", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
                        {
                            return;
                        }
                    }

                    foreach (ListViewItem selectedItem in lsvSessions.SelectedItems)
                    {
                        var film = (cFilm)selectedItem.Tag;

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

                            var sf = new StatsReport();
                            sf.userId = mUserId;
                            sf.BindFormData(reportFilm);
                            sf.Show(this);

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

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

                            Application.DoEvents();

                            int sessionLogged;
                            data.checkLoggedSessions(film, out sessionLogged);
                            selectedItem.BackColor = sessionLogged == 1 ? Color.Purple : Color.Green;
                        }

                        if (data.pError.Length > 0)
                        {
                            if (film.getFirstValidPictureFile() != null)
                            {
                                MessageBox.Show("ERROR with logging film " + film.getFirstValidPictureFile().pFormattedSession + " - " + data.pError, "Log Failed!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            }
                            else
                            {
                                MessageBox.Show("ERROR with logging film <SESSION READ ERROR> - " + data.pError, "Log Failed!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            }
                        }

                        mPhysicalStudio.ClearFilm(film);
                    }
                }
                else
                {
                    MessageBox.Show("You must select a session with encrypted files before you can log!", "Cannot Log", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            finally
            {
                Cursor.Current = Cursors.Default;
                MessageBox.Show("The system logged " + totalLoggedCases.ToString() + " new cases!", "Logged Complete", MessageBoxButtons.OK, MessageBoxIcon.Information);
                lblInfo.Text = "The system logged " + totalLoggedCases + " new cases!";
            }
        }
Пример #2
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);
            }
        }