private void buttonValuesApply_Click(object sender, EventArgs e)
 {
     try {
         Settings.Default.fuelLiterToKilometer = float.Parse(textBoxValuesFuelToKilometers.Text);
         Settings.Default.fuelLiterToCost = float.Parse(textBoxValuesFuelToCost.Text);
         Settings.Default.Save();
         MessageBox.Show(this, "Fuel and Cost has been saved!", "Save", MessageBoxButtons.OK, MessageBoxIcon.Information);
     } catch (Exception exception) {
         Log log = new Log(LogFileType.TXT, LogType.EXCEPTION);
         string logData = DateTime.Now.ToString() + "\t\t Exception \t\t" + "Values" + " : " + exception.Message;
         log.write(logData);
         MessageBox.Show(this, "Wrong Format! Please try again. Ex. '10.00'", "Exception", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
Esempio n. 2
0
        public void dataTableToText(DataTable dataTable, string fileName)
        {
            StreamWriter streamWriter;
            streamWriter = new StreamWriter(fileName, true);
            try {

                streamWriter.Write("ReportType\t\t\t" + Enum.GetName(typeof(ReportType), reportType) + "\r\n");
                streamWriter.Write("CompanyName\t\t\t" + reportInformation.companyName + "\r\n");

                if (
                    this.reportType == ReportType.HISTORICAL ||
                    this.reportType == ReportType.RUNNING ||
                    this.reportType == ReportType.IDLING ||
                    this.reportType == ReportType.GEOFENCE ||
                    this.reportType == ReportType.ACC ||
                    this.reportType == ReportType.OVERSPEED ||
                    this.reportType == ReportType.EXTERNAL_POWER_CUT
                    ) {

                    streamWriter.Write("VehicleRegistration\t" + reportInformation.trackerVehicleReg + "\r\n");
                    streamWriter.Write("VehicleModel\t\t\t" + reportInformation.trackerVehicleModel + "\r\n");
                    streamWriter.Write("OwnerName\t\t\t" + reportInformation.trackerOwnerName + "\r\n");
                    streamWriter.Write("DriverName\t\t\t" + reportInformation.trackerDriverName + "\r\n");
                    streamWriter.Write("DeviceImei\t\t\t" + reportInformation.trackerDeviceImei + "\r\n");
                }

                switch (this.reportType) {
                    case ReportType.RUNNING:
                        streamWriter.Write("Total Distance\t\t\t" + reportInformation.summaryTotalDistance + "\r\n");
                        streamWriter.Write("Total Fuel\t\t\t" + reportInformation.summaryTotalFuel + "\r\n");
                        streamWriter.Write("Total Cosl\t\t\t" + reportInformation.summaryTotalCost + "\r\n");
                        streamWriter.Write("Total Running Time\t\t\t" + reportInformation.summaryTotalRunningTime + "\r\n");
                        break;
                    case ReportType.IDLING:
                        streamWriter.Write("Total Distance\t\t\t" + reportInformation.summaryTotalDistance + "\r\n");
                        streamWriter.Write("Total Fuel\t\t\t" + reportInformation.summaryTotalFuel + "\r\n");
                        streamWriter.Write("Total Cosl\t\t\t" + reportInformation.summaryTotalCost + "\r\n");
                        streamWriter.Write("Total Idling Time\t\t\t" + reportInformation.summaryTotalIdlingTime + "\r\n");
                        break;
                    case ReportType.GEOFENCE:
                        streamWriter.Write("Total Distance\t\t\t" + reportInformation.summaryTotalDistance + "\r\n");
                        streamWriter.Write("Total Fuel\t\t\t" + reportInformation.summaryTotalFuel + "\r\n");
                        streamWriter.Write("Total Cosl\t\t\t" + reportInformation.summaryTotalCost + "\r\n");
                        streamWriter.Write("Total Geofence Active Time\t\t\t" + reportInformation.summaryTotalGeofenceActiveTime + "\r\n");
                        break;
                    case ReportType.ACC:
                        streamWriter.Write("Total Distance\t\t\t" + reportInformation.summaryTotalDistance + "\r\n");
                        streamWriter.Write("Total Fuel\t\t\t" + reportInformation.summaryTotalFuel + "\r\n");
                        streamWriter.Write("Total Cosl\t\t\t" + reportInformation.summaryTotalCost + "\r\n");
                        streamWriter.Write("Total ACC Active Time\t\t\t" + reportInformation.summaryTotalAccActiveTime + "\r\n");
                        break;
                    case ReportType.EXTERNAL_POWER_CUT:
                        streamWriter.Write("Total Distance\t\t\t" + reportInformation.summaryTotalDistance + "\r\n");
                        streamWriter.Write("Total Fuel\t\t\t" + reportInformation.summaryTotalFuel + "\r\n");
                        streamWriter.Write("Total Cosl\t\t\t" + reportInformation.summaryTotalCost + "\r\n");
                        streamWriter.Write("Total ExternalPower Cut Time\t\t\t" + reportInformation.summaryTotalExternalPowerCutTime + "\r\n");
                        break;
                    case ReportType.TRACKERS_GEOFENCE:
                        streamWriter.Write("Total Distance\t\t\t" + reportInformation.summaryTotalDistance + "\r\n");
                        streamWriter.Write("Total Fuel\t\t\t" + reportInformation.summaryTotalFuel + "\r\n");
                        streamWriter.Write("Total Cost\t\t\t" + reportInformation.summaryTotalCost + "\r\n");
                        break;
                }
                if (
                  this.reportType == ReportType.HISTORICAL ||
                  this.reportType == ReportType.RUNNING ||
                  this.reportType == ReportType.IDLING ||
                  this.reportType == ReportType.GEOFENCE ||
                  this.reportType == ReportType.ACC ||
                  this.reportType == ReportType.OVERSPEED ||
                  this.reportType == ReportType.EXTERNAL_POWER_CUT
                  ) {
                    streamWriter.Write("DateTime From\t\t\t" + reportInformation.summaryDateTimeFrom + "\r\n");
                    streamWriter.Write("DateTime To\t\t\t" + reportInformation.summaryDateTimeTo + "\r\n");
                }
                streamWriter.Write("Created On\t\t\t" + DateTime.Now.ToString() + "\r\n\r\n");
                //====================================================
                foreach (DataColumn dataColumn in dataTable.Columns) {
                    streamWriter.Write(dataColumn.ColumnName + "\t\t");
                }
                streamWriter.Write("\r\n");

                foreach (DataRow dataRow in dataTable.Rows) {
                    for (int index = 0; index < dataTable.Columns.Count; index++) {
                        streamWriter.Write(dataRow[index] + "\t\t");
                    }
                    streamWriter.Write("\r\n");
                }
            } catch (Exception exception) {
                Log log = new Log(LogFileType.TXT, LogType.EXCEPTION);
                string logData = DateTime.Now.ToString() + "\t\t Exception \t\t" + exception.Message;
                log.write(logData);
            } finally {
                streamWriter.Close();
            }
        }
Esempio n. 3
0
        public override void OnOpenDocument(PdfWriter writer, Document document)
        {
            try {

                baseFont = BaseFont.CreateFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
                pdfContentByte = writer.DirectContent;
                pdfTemplate = pdfContentByte.CreateTemplate(50, 50);
            } catch (DocumentException documentException) {
                Log log = new Log(LogFileType.TXT, LogType.EXCEPTION);
                string logData = DateTime.Now.ToString() + "\t\t documentException \t\t" + documentException.Message;
                log.write(logData);
            } catch (System.IO.IOException ioException) {
                Log log = new Log(LogFileType.TXT, LogType.EXCEPTION);
                string logData = DateTime.Now.ToString() + "\t\t documentException \t\t" + ioException.Message;
                log.write(logData);
            }
        }
        void run(object state)
        {
            pictureBoxLoading.Invoke(new MethodInvoker(delegate {
                pictureBoxLoading.Visible = true;
            }));

            try {

                database = new Database(Settings.Default.DatabaseHost, Settings.Default.DatabaseUsername, Settings.Default.DatabasePassword);

                Query query = new Query(database);

                query.getCompany(company);
                query.getUser(company, user);

                if (user.AccessLevel != 1) {

                    int isExpired = company.DateTimeExpired.CompareTo(DateTime.Now);

                    if (isExpired == -1)
                        throw new QueryException(1, "This company is expired.");
                    if (!company.IsActive)
                        throw new QueryException(1, "Company is deactivated.");

                    isExpired = user.DateTimeExpired.CompareTo(DateTime.Now);

                    if (isExpired == -1)
                        throw new QueryException(1, "This user is expired.");
                    if (!user.IsActive)
                        throw new QueryException(1, "User is deactivated.");
                }
                //=============================Login successful

                query.fillGeofences(company);

                query.fillUsers(company, user);

                query.fillCollection(company);

                query.fillTrackers(company);

                query.fillPois(company);

                this.Invoke(new MethodInvoker(delegate {
                    Settings.Default.accountRememberMe = (bool)user.RememberMe;
                    Settings.Default.accountCompanyUsername = company.Username;
                    Settings.Default.accountUsername = user.Username;
                    Settings.Default.accountPassword = user.Password;
                    Settings.Default.Save();

                    this.DialogResult = DialogResult.OK;
                    this.Close();
                }));
            } catch (QueryException queryException) {
                this.Invoke(new MethodInvoker(delegate {
                    MessageBox.Show(this, queryException.Message, "Query Exception", MessageBoxButtons.OK, MessageBoxIcon.Error);

                    Log log = new Log(LogFileType.TXT, LogType.EXCEPTION);
                    string logData = DateTime.Now.ToString() + "\t\t queryException \t\t" + queryException.Message;
                    log.write(logData);
                }));
            } catch (DatabaseException databaseException){
                this.Invoke(new MethodInvoker(delegate {
                    MessageBox.Show(this, databaseException.Message, "DatabaseException", MessageBoxButtons.OK, MessageBoxIcon.Error);

                    Log log = new Log(LogFileType.TXT, LogType.EXCEPTION);
                    string logData = DateTime.Now.ToString() + "\t\t DatabaseException \t\t" + databaseException.Message;
                    log.write(logData);
                }));

            } finally {
                try {
                    pictureBoxLoading.Invoke(new MethodInvoker(delegate {
                        pictureBoxLoading.Visible = false;
                    }));
                } catch {

                }
            }
        }
        private void buttonLogin_Click(object sender, EventArgs e)
        {
            /*
             *  Validate Inputs
             *
             */
            if (String.IsNullOrEmpty(textBoxCompany.Text)) {
                errorProviderDatabaseConfiguration.SetError(textBoxCompany, "Field is empty.");
            } else {
                errorProviderDatabaseConfiguration.SetError(textBoxCompany, String.Empty);
            }

            if (String.IsNullOrEmpty(textBoxUsername.Text)) {
                errorProviderDatabaseConfiguration.SetError(textBoxUsername, "Field is empty.");
            } else {
                errorProviderDatabaseConfiguration.SetError(textBoxUsername, String.Empty);
            }

            if (String.IsNullOrEmpty(textBoxPassword.Text)) {
                errorProviderDatabaseConfiguration.SetError(textBoxPassword, "Field is empty.");
            } else {
                errorProviderDatabaseConfiguration.SetError(textBoxPassword, String.Empty);
            }

            if (String.IsNullOrEmpty(textBoxCompany.Text) || String.IsNullOrEmpty(textBoxUsername.Text) || String.IsNullOrEmpty(textBoxPassword.Text) || (String.IsNullOrEmpty(textBoxCompany.Text))) {
                return;
            }

            try {

                company.Username = textBoxCompany.Text;
                user.Username = textBoxUsername.Text;
                user.Password = textBoxPassword.Text;
                user.RememberMe = checkBoxRememberMe.Checked;

                ThreadPool.QueueUserWorkItem(new WaitCallback(run), null);

            } catch (DatabaseException databaseException) {
                MessageBox.Show(this, databaseException.Message, "Database Exception", MessageBoxButtons.OK, MessageBoxIcon.Error);
                Log log = new Log(LogFileType.TXT, LogType.EXCEPTION);
                string logData = DateTime.Now.ToString() + "\t\t databaseException \t\t" + databaseException.Message;
                log.write(logData);
            } finally {
            }
        }
Esempio n. 6
0
        private void buttonFilter_Click(object sender, EventArgs e)
        {
            if (tabControl == null)
                return;

            if (tabControl.TabPages.Count == 0)
                return;

            TabPage tabPage = tabControl.SelectedTab;
            TableLayoutPanel TableLayoutInformation = (TableLayoutPanel)tabPage.Controls[0];
            DataGridView dataGridViewInformation = (DataGridView)TableLayoutInformation.Controls[0];

            try {
                if (comboBoxFilterContains.Enabled == true) {
                    string rowFilter = "";
                    if (!String.IsNullOrEmpty(comboBoxFilterContains.Text)) {
                        rowFilter = string.Format("[{0}] = '{1}'", comboBoxColumn.SelectedItem.ToString(), comboBoxFilterContains.Text);
                    }
                    (dataGridViewInformation.DataSource as DataTable).DefaultView.RowFilter = rowFilter;
                } else if (comboBoxFilterValueFrom.Enabled == true && comboBoxFilterValueTo.Enabled == true) {

                    double valueFrom = double.Parse(comboBoxFilterValueFrom.Text);
                    double valueTo = double.Parse(comboBoxFilterValueTo.Text);
                    string rowFilter = "";

                    if (valueFrom < valueTo) {
                        rowFilter = comboBoxColumn.Text + " >= " + valueFrom.ToString() + " and " + comboBoxColumn.Text + " <= " + valueTo.ToString();
                    } else if (valueFrom > valueTo) {
                        rowFilter = comboBoxColumn.Text + " <= " + valueFrom.ToString() + " and " + comboBoxColumn.Text + " >= " + valueTo.ToString();
                    } else if (valueFrom == valueTo) {
                        rowFilter = comboBoxColumn.Text + " = " + valueFrom.ToString();
                    }

                    (dataGridViewInformation.DataSource as DataTable).DefaultView.RowFilter = rowFilter;
                }

            } catch (Exception exception) {
                MessageBox.Show(this, exception.Message, "Exception", MessageBoxButtons.OK, MessageBoxIcon.Error);
                Log log = new Log(LogFileType.TXT, LogType.EXCEPTION);
                string logData = DateTime.Now.ToString() + "\t\tException\t\t" + exception.Message;
                log.write(logData);
            }
        }
Esempio n. 7
0
        public void threadShortQuery(object uncast)
        {
            #region -instances
            DataTable dataTableDetails = new DataTable();
            Hashtable hashTable = (Hashtable)uncast;
            Query query = new Query(database);

            Tracker tracker = (Tracker)hashTable["tracker"];

            DateTime dateTimeFrom = (DateTime)hashTable["dateTimeFrom"];
            DateTime dateTimeTo = (DateTime)hashTable["dateTimeTo"];

            DataGridView dataGridViewInformation = (DataGridView)hashTable["dataGridViewInformation"];

            string comboBoxReportTypeText = (string)hashTable["comboBoxReportTypeItem"];
            ReportType reportType = (ReportType)Enum.Parse(typeof(ReportType), comboBoxReportTypeText);

            int queryLimit = ((int)hashTable["limit"]);
            int offset = (int)hashTable["offset"];
            #endregion
            #region -loop

            try {
                #region querySelection
                switch (reportType) {
                    case ReportType.HISTORICAL:
                        dataTableDetails = query.getTrackerHistoricalData(this.company, this.user, dateTimeFrom, dateTimeTo, queryLimit, offset, tracker);
                        break;
                    case ReportType.IDLING:
                        dataTableDetails = query.getTrackerIdlingData(this.company, this.user, dateTimeFrom, dateTimeTo, queryLimit, offset, tracker);
                        break;
                    case ReportType.RUNNING:
                        dataTableDetails = query.getTrackerRunningData(this.company, this.user, dateTimeFrom, dateTimeTo, queryLimit, offset, tracker);
                        break;
                    case ReportType.GEOFENCE:
                        dataTableDetails = query.getTrackerGeofence(this.company, this.user, dateTimeFrom, dateTimeTo, queryLimit, offset, tracker);
                        break;
                    case ReportType.TRACKERS:
                        //dataTableDetails = query.getTrackers(this.account, userId);
                        break;
                    case ReportType.ALL_COMPANIES:
                        //dataTableDetails = query.getAllCompanies();
                        break;
                    case ReportType.ALL_TRACKERS:
                        //dataTableDetails = query.getAllTrackers();
                        break;

                }
                #endregion
                #region updateDataGridView
                this.Invoke(new MethodInvoker(delegate {
                    dataGridViewInformation.DataSource = dataTableDetails;
                }));
                #endregion
            } catch (QueryException queryException) {
                Log log = new Log(LogFileType.TXT, LogType.EXCEPTION);
                string logData = DateTime.Now.ToString() + "\t\t queryException \t\t" + tracker.VehicleRegistration + " : " + queryException.Message;
                log.write(logData);

            } catch (MySqlException mySqlException) {
                Log log = new Log(LogFileType.TXT, LogType.EXCEPTION);
                string logData = DateTime.Now.ToString() + "\t\t mySqlException \t\t" + tracker.VehicleRegistration + " : " + mySqlException.Message;
                log.write(logData);
                if (mySqlException.ErrorCode == -2147467259) {

                } else {

                }
            } catch (Exception exception) {
                Log log = new Log(LogFileType.TXT, LogType.EXCEPTION);
                string logData = DateTime.Now.ToString() + "\t\t exception \t\t" + tracker.VehicleRegistration + " : " + exception.Message;
                log.write(logData);

            }

            #endregion
            updateProgressBarStatus(100);
        }
Esempio n. 8
0
        public void threadLoadFilters(object uncast)
        {
            try {

                this.BeginInvoke(new MethodInvoker(delegate() {

                    comboBoxCollection.Items.Clear();

                    User user = (User)comboBoxUser.SelectedItem;

                    foreach (Collection collection in user.Collections) {
                        comboBoxCollection.Items.Add(collection);
                    }

                    comboBoxCollection.DisplayMember = "Name";

                    comboBoxCollection.SelectedItem = comboBoxCollection.Items[0];

                    ContextMenuStrip contextMenuStripCheckedListBoxTrackers = new ContextMenuStrip();
                    ToolStripItem toolStripItemCheckedListBoxTrackersCheckAll = contextMenuStripCheckedListBoxTrackers.Items.Add("Check all");
                    toolStripItemCheckedListBoxTrackersCheckAll.Click += toolStripItemCheckedListBoxTrackersCheckAll_Click;
                    ToolStripItem toolStripItemCheckedListBoxTrackersUncheckAll = contextMenuStripCheckedListBoxTrackers.Items.Add("Uncheck all");
                    toolStripItemCheckedListBoxTrackersUncheckAll.Click += toolStripItemCheckedListBoxTrackersUncheckAll_Click;
                    ToolStripItem toolStripItemCheckedNextGroup = contextMenuStripCheckedListBoxTrackers.Items.Add("Check Next 10 items");
                    toolStripItemCheckedNextGroup.Click += toolStripItemCheckedNextGroup_Click;
                    ToolStripItem toolStripItemCheckedPrevGroup = contextMenuStripCheckedListBoxTrackers.Items.Add("Check Prev 10 items");
                    toolStripItemCheckedPrevGroup.Click += toolStripItemCheckedPrevGroup_Click;

                    ToolStripItem toolStripItemSortAscending = contextMenuStripCheckedListBoxTrackers.Items.Add("Sort/Unsort");
                    toolStripItemSortAscending.Click += toolStripItemSortAscending_Click;

                    checkedListBoxTrackers.ContextMenuStrip = contextMenuStripCheckedListBoxTrackers;
                    checkedListBoxTrackers.ItemCheck += checkedListBoxTrackers_ItemCheck;
                    checkedListBoxTrackers.ResumeLayout();

                }));
            } catch (QueryException queryException) {
                this.Invoke(new MethodInvoker(delegate() {
                    MessageBox.Show(this, queryException.Message, "Query Exception", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }));
                Log log = new Log(LogFileType.TXT, LogType.EXCEPTION);
                string logData = DateTime.Now.ToString() + "\t\t queryException \t\t" + queryException.Message;
                log.write(logData);
            } finally {
                updateProgressBarStatus(100);
            }
        }
Esempio n. 9
0
        public void prepareExport(TabPage tabPage, bool openTheFile)
        {
            if (String.IsNullOrEmpty(comboBoxExportFileType.Text))
                return;

            if (tabPage == null)
                return;

            TableLayoutPanel tableLayoutInformation = (TableLayoutPanel)tabPage.Controls[0];
            if (tableLayoutInformation == null)
                return;

            DataGridView dataGridViewInformation = (DataGridView)tableLayoutInformation.Controls[0];
            if (dataGridViewInformation == null)
                return;

            DataTable dataTable = new DataTable();

            foreach (DataGridViewColumn dataGridViewColumn in dataGridViewInformation.Columns) {
                if (dataGridViewColumn.Visible)
                    dataTable.Columns.Add(dataGridViewColumn.Name, dataGridViewColumn.ValueType);
            }

            foreach (DataGridViewRow dataGridViewRow in dataGridViewInformation.Rows) {
                DataRow dataRow = dataTable.NewRow();
                foreach (DataColumn dataColumn in dataTable.Columns) {
                    dataRow[dataColumn.ColumnName] = dataGridViewRow.Cells[dataColumn.ColumnName].Value;
                }
                dataTable.Rows.Add(dataRow);
            }

            ExportFileType exportFileType = (ExportFileType)(Enum.Parse(typeof(ExportFileType), comboBoxExportFileType.Text));
            ReportType reportType = (ReportType)(Enum.Parse(typeof(ReportType), dataGridViewInformation.Name));

            ReportInformation reportInformation = new ReportInformation();

            TableLayoutPanel tableLayoutPanelParent = (TableLayoutPanel)tabPage.Controls[0];
            TableLayoutPanel tableLayoutPanelRight = (TableLayoutPanel)tableLayoutPanelParent.Controls[2];

            ListView listViewDetails = (ListView)tableLayoutPanelRight.Controls[0];

            reportInformation.companyName = listViewDetails.Items[0].SubItems[1].Text;
            reportInformation.userName = listViewDetails.Items[1].SubItems[1].Text;

            if (reportType == ReportType.HISTORICAL || reportType == ReportType.RUNNING || reportType == ReportType.IDLING || reportType == ReportType.ACC || reportType == ReportType.GEOFENCE || reportType == ReportType.OVERSPEED || reportType == ReportType.ACC) {
                reportInformation.trackerVehicleReg = listViewDetails.Items[2].SubItems[1].Text;
                reportInformation.trackerVehicleModel = listViewDetails.Items[3].SubItems[1].Text;
                reportInformation.trackerOwnerName = listViewDetails.Items[4].SubItems[1].Text;
                reportInformation.trackerDriverName = listViewDetails.Items[5].SubItems[1].Text;

                reportInformation.trackerDeviceImei = listViewDetails.Items[6].SubItems[1].Text;
                reportInformation.trackerSimNumber = listViewDetails.Items[7].SubItems[1].Text;
                reportInformation.trackerVehicleCreated = listViewDetails.Items[8].SubItems[1].Text;
                reportInformation.trackerDeviceExpiry = listViewDetails.Items[9].SubItems[1].Text;

            }

            ListView listViewSummary = (ListView)tableLayoutPanelRight.Controls[1];
            reportInformation.summaryDateTimeFrom = listViewSummary.Items[0].SubItems[1].Text;
            reportInformation.summaryDateTimeTo = listViewSummary.Items[1].SubItems[1].Text;

            if (reportType == ReportType.RUNNING) {
                reportInformation.summaryTotalDistance = listViewSummary.Items[2].SubItems[1].Text;
                reportInformation.summaryTotalFuel = listViewSummary.Items[3].SubItems[1].Text;
                reportInformation.summaryTotalCost = listViewSummary.Items[4].SubItems[1].Text;
                reportInformation.summaryTotalRunningTime = listViewSummary.Items[5].SubItems[1].Text;
            } else if (reportType == ReportType.IDLING) {
                reportInformation.summaryTotalDistance = listViewSummary.Items[2].SubItems[1].Text;
                reportInformation.summaryTotalFuel = listViewSummary.Items[3].SubItems[1].Text;
                reportInformation.summaryTotalCost = listViewSummary.Items[4].SubItems[1].Text;
                reportInformation.summaryTotalIdlingTime = listViewSummary.Items[5].SubItems[1].Text;
            } else if (reportType == ReportType.GEOFENCE) {
                reportInformation.summaryTotalDistance = listViewSummary.Items[2].SubItems[1].Text;
                reportInformation.summaryTotalFuel = listViewSummary.Items[3].SubItems[1].Text;
                reportInformation.summaryTotalCost = listViewSummary.Items[4].SubItems[1].Text;
                reportInformation.summaryTotalGeofenceActiveTime = listViewSummary.Items[5].SubItems[1].Text;
            } else if (reportType == ReportType.ACC) {
                reportInformation.summaryTotalDistance = listViewSummary.Items[2].SubItems[1].Text;
                reportInformation.summaryTotalFuel = listViewSummary.Items[3].SubItems[1].Text;
                reportInformation.summaryTotalCost = listViewSummary.Items[4].SubItems[1].Text;
                reportInformation.summaryTotalAccActiveTime = listViewSummary.Items[5].SubItems[1].Text;
            } else if (reportType == ReportType.TRACKERS_GEOFENCE) {
                reportInformation.summaryTotalDistance = listViewSummary.Items[2].SubItems[1].Text;
                reportInformation.summaryTotalFuel = listViewSummary.Items[3].SubItems[1].Text;
                reportInformation.summaryTotalCost = listViewSummary.Items[4].SubItems[1].Text;
            }

            if (string.IsNullOrEmpty(comboBoxExportFileType.Text))
                return;

            try {
                Export export = new Export(exportFileType, reportType);
                export.parentDirectory = "TqatExportFiles";
                export.path = comboBoxExportFilePath.Text;
                export.title = reportInformation.trackerVehicleReg;//tabControl.TabPages[0].Name;

                if (!File.Exists(Settings.Default.UserLogoPath)) {
                    export.logoPath = Directory.GetCurrentDirectory() + "\\logo.png";
                } else {
                    export.logoPath = Settings.Default.UserLogoPath;
                }
                export.companyName = company.DisplayName;
                export.reportInformation = reportInformation;
                if (!export.dataTable(dataTable, openTheFile)) {
                    throw new Exception();
                }
            } catch (Exception exception) {
                MessageBox.Show(this, exception.Message, "Exception", MessageBoxButtons.OK, MessageBoxIcon.Error);
                Log log = new Log(LogFileType.TXT, LogType.EXCEPTION);
                string logData = DateTime.Now.ToString() + "\t\tException\t\t" + exception.Message;
                log.write(logData);
            }
        }
Esempio n. 10
0
        public void threadFunctionQuery(object uncast)
        {
            #region -instances

            DataTable dataTableDetails = new DataTable();
            int speedLimit;

            Hashtable hashTable = (Hashtable)uncast;
            Query query = new Query(database);

            Tracker tracker = (Tracker)hashTable["tracker"];
            if (tracker != null)
                speedLimit = tracker.SpeedLimit;

            TabControl tabControl = (TabControl)hashTable["tabControl"];

            DateTime dateTimeFrom = (DateTime)hashTable["dateTimeFrom"];
            DateTime dateTimeTo = (DateTime)hashTable["dateTimeTo"];
            List<Tracker> trackerList = (List<Tracker>)hashTable["trackerList"];

            int limit = (int)hashTable["limit"];
            int offset = (int)hashTable["offset"];

            int userId = (int)hashTable["comboBoxAccountId"];

            int dataCount = 0;

            string comboBoxReportTypeText = (string)hashTable["comboBoxReportTypeItem"];
            ReportType reportType = (ReportType)Enum.Parse(typeof(ReportType), comboBoxReportTypeText);

            bool tabPageExist = false;
            string tabPageName = "";
            string reportItemName = (string)hashTable["reportItemName"];
            string reportTypeName = Enum.GetName(typeof(ReportType), reportType);

            bool pagingStatus = false;
            #endregion
            #region -loop
            //If timeout we will query again up to 3 times
            for (int count = 0; count < 3; count++) {
                try {
                    #region checkTabPage
                    tabPageName = reportTypeName + " : " + reportItemName;
                    this.Invoke(new MethodInvoker(delegate {
                        foreach (TabPage tabPageItem in tabControl.TabPages) {
                            if (tabPageItem.Text == tabPageName) {
                                tabControl.SelectedTab = tabPageItem;
                                tabPageExist = true;
                                break;
                            }
                        }
                    }));

                    if (tabPageExist == true) {
                        break;
                    }
                    #endregion
                    #region querySelection
                    switch (reportType) {
                        case ReportType.HISTORICAL:
                            dataTableDetails = query.getTrackerHistoricalData(this.company, this.user, dateTimeFrom, dateTimeTo, limit, offset, tracker);
                            dataCount = query.getTrackerHistoricalDataCount(this.user, dateTimeFrom, dateTimeTo, tracker);
                            //dataTableDetails.writeToCsvFile(Directory.GetCurrentDirectory());
                            pagingStatus = true;
                            break;
                        case ReportType.IDLING:
                            dataTableDetails = query.getTrackerIdlingData(this.company, this.user, dateTimeFrom, dateTimeTo, 1000000, 0, tracker);
                            dataCount = dataTableDetails.Rows.Count;
                            break;
                        case ReportType.RUNNING:
                            dataTableDetails = query.getTrackerRunningData(this.company, this.user, dateTimeFrom, dateTimeTo, 1000000, 0, tracker);
                            dataCount = dataTableDetails.Rows.Count;
                            break;
                        case ReportType.GEOFENCE:
                            dataTableDetails = query.getTrackerGeofence(this.company, this.user, dateTimeFrom, dateTimeTo, 1000000, 0, tracker);
                            dataCount = dataTableDetails.Rows.Count;
                            break;
                        case ReportType.TRACKERS:
                            dataTableDetails = query.getTrackers(this.company);
                            dataCount = dataTableDetails.Rows.Count;
                            break;
                        case ReportType.ACC:
                            dataTableDetails = query.getTrackerAccData(this.company, this.user, dateTimeFrom, dateTimeTo, 1000000, 0, tracker);
                            dataCount = dataTableDetails.Rows.Count;
                            break;
                        case ReportType.EXTERNAL_POWER_CUT:
                            dataTableDetails = query.getTrackerExternalPowerCutData(this.company, this.user, dateTimeFrom, dateTimeTo, 1000000, 0, tracker);
                            dataCount = dataTableDetails.Rows.Count;
                            break;
                        case ReportType.OVERSPEED:
                            dataTableDetails = query.getTrackerOverSpeedData(this.company, this.user, dateTimeFrom, dateTimeTo, 1000000, 0, tracker);
                            dataCount = dataTableDetails.Rows.Count;
                            break;
                        case ReportType.TRACKERS_GEOFENCE:
                            dataTableDetails = query.getTrackersGeofence(this.company, this.user, dateTimeFrom, dateTimeTo, 1000000, 0, trackerList);
                            dataCount = dataTableDetails.Rows.Count;
                            break;
                        case ReportType.TRACKERS_HISTORICAL:
                            dataTableDetails = query.getTrackersHistorical(this.company, this.user, dateTimeFrom, dateTimeTo, 500, 0, trackerList);
                            dataCount = dataTableDetails.Rows.Count;
                            break;
                        case ReportType.ALL_COMPANIES:
                            dataTableDetails = query.getAllCompanies();
                            dataCount = dataTableDetails.Rows.Count;
                            break;
                        case ReportType.ALL_TRACKERS:
                            dataTableDetails = query.getAllTrackers();
                            dataCount = dataTableDetails.Rows.Count;
                            break;
                    }
                    #endregion
                    #region dataGridViewInformation
                    DataGridView dataGridView = new DataGridView();
                    dataGridView.Tag = dataTableDetails;
                    dataGridView.VirtualMode = true;
                    dataGridView.BackgroundColor = Color.White;
                    dataGridView.Name = reportTypeName;
                    dataGridView.RowHeadersVisible = false;
                    dataGridView.AllowUserToAddRows = false;
                    dataGridView.AllowUserToDeleteRows = false;
                    dataGridView.ReadOnly = true;

                    //DataView dataView = new DataView();
                    //dataView.Table = (DataTable)dataGridView.Tag;
                    //dataView.RowFilter = ("No > 0 AND No <= 100");

                    dataGridView.DataSource = dataTableDetails;
                    dataGridView.Dock = DockStyle.Fill;
                    dataGridView.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells;
                    dataGridView.DataBindingComplete += dataGridView_DataBindingComplete;
                    dataGridView.CellDoubleClick += dataGridView_CellDoubleClick;
                    dataGridView.MouseHover += dataGridView_MouseHover;

                    ContextMenuStrip contextMenuStripDataGridView = new ContextMenuStrip();
                    contextMenuStripDataGridView.Name = "dataGridView";
                    contextMenuStripDataGridView.Opening += contextMenuStripDataGridView_Opening;

                    dataGridView.ContextMenuStrip = contextMenuStripDataGridView;
                    #endregion
                    #region tableLayoutPanelRight
                    ListViewItem[] listViewItemsDetail = new ListViewItem[11];
                    for (int index = 0; index < listViewItemsDetail.Count(); index++) {
                        listViewItemsDetail[index] = new ListViewItem();
                    }

                    listViewItemsDetail[0].Text = "Company Name";
                    listViewItemsDetail[0].SubItems.Add(company.DisplayName);

                    listViewItemsDetail[1].Text = "User Name";
                    listViewItemsDetail[1].SubItems.Add(user.Username);

                    if (tracker != null) {
                        listViewItemsDetail[2].Text = "Vehicle Reg";
                        listViewItemsDetail[2].SubItems.Add(tracker.VehicleRegistration);

                        listViewItemsDetail[3].Text = "Vehicle Model";
                        listViewItemsDetail[3].SubItems.Add(tracker.VehicleModel);

                        listViewItemsDetail[4].Text = "Owner Name";
                        listViewItemsDetail[4].SubItems.Add(tracker.OwnerName);

                        listViewItemsDetail[5].Text = "Driver Name";
                        listViewItemsDetail[5].SubItems.Add(tracker.DriverName);

                        listViewItemsDetail[6].Text = "Device Imei";
                        listViewItemsDetail[6].SubItems.Add(tracker.TrackerImei);

                        listViewItemsDetail[7].Text = "Sim Number";
                        listViewItemsDetail[7].SubItems.Add(tracker.SimNumber);

                        listViewItemsDetail[8].Text = "Vehicle Created";
                        listViewItemsDetail[8].SubItems.Add(tracker.DateTimeCreated.ToString("yyyy/MM/dd HH:mm:ss"));

                        listViewItemsDetail[9].Text = "Vehicle Expiry";
                        listViewItemsDetail[9].SubItems.Add(tracker.VehicleRegistrationExpiry.ToString("yyyy/MM/dd HH:mm:ss"));

                        listViewItemsDetail[10].Text = "Device Expiry";
                        listViewItemsDetail[10].SubItems.Add(tracker.DateTimeExpired.ToString("yyyy/MM/dd HH:mm:ss"));
                    }

                    ListView listViewDetails = new ListView();
                    listViewDetails.Dock = DockStyle.Fill;
                    listViewDetails.View = View.Details;
                    listViewDetails.Scrollable = false;
                    listViewDetails.FullRowSelect = true;

                    ColumnHeader columnHeaderLabelDetail = listViewDetails.Columns.Add("Details");
                    columnHeaderLabelDetail.Width = 90;

                    ColumnHeader columnHeaderValueDetail = listViewDetails.Columns.Add("Value");
                    columnHeaderValueDetail.Width = 150;

                    listViewDetails.Items.AddRange(listViewItemsDetail);

                    ListViewItem[] listViewItemsSummary = new ListViewItem[10];
                    for (int index = 0; index < listViewItemsSummary.Count(); index++) {
                        listViewItemsSummary[index] = new ListViewItem();
                    }

                    listViewItemsSummary[0].Text = "DateTime From";
                    listViewItemsSummary[0].SubItems.Add(dateTimeFrom.ToString("yyyy/MM/dd HH:mm:ss"));

                    listViewItemsSummary[1].Text = "DateTime To";
                    listViewItemsSummary[1].SubItems.Add(dateTimeTo.ToString("yyyy/MM/dd HH:mm:ss"));

                    if (reportType == ReportType.RUNNING ||
                        reportType == ReportType.IDLING ||
                        reportType == ReportType.ACC ||
                        reportType == ReportType.GEOFENCE ||
                        reportType == ReportType.EXTERNAL_POWER_CUT) {
                        listViewItemsSummary[2].Text = "Total Distance";
                        listViewItemsSummary[2].SubItems.Add(Converter.dataTableColumnSumValueIfTrue(dataTableDetails, "Distance").ToString() + " Km");
                        listViewItemsSummary[3].Text = "Total Fuel";
                        listViewItemsSummary[3].SubItems.Add(Converter.dataTableColumnSumValueIfTrue(dataTableDetails, "Fuel").ToString() + " L");
                        listViewItemsSummary[4].Text = "Total Cost";
                        listViewItemsSummary[4].SubItems.Add(Converter.dataTableColumnSumValueIfTrue(dataTableDetails, "Cost").ToString() + " Qr");
                    }
                    if (reportType == ReportType.TRACKERS_GEOFENCE) {
                        listViewItemsSummary[2].Text = "Total Distance";
                        listViewItemsSummary[2].SubItems.Add(Converter.dataTableColumnSumValue(dataTableDetails, "Distance").ToString() + " Km");
                        listViewItemsSummary[3].Text = "Total Fuel";
                        listViewItemsSummary[3].SubItems.Add(Converter.dataTableColumnSumValue(dataTableDetails, "Fuel").ToString() + " L");
                        listViewItemsSummary[4].Text = "Total Cost";
                        listViewItemsSummary[4].SubItems.Add(Converter.dataTableColumnSumValue(dataTableDetails, "Cost").ToString() + " Qr");
                    }

                    if (reportType == ReportType.RUNNING ||
                        reportType == ReportType.IDLING ||
                        reportType == ReportType.ACC ||
                        reportType == ReportType.GEOFENCE ||
                        reportType == ReportType.EXTERNAL_POWER_CUT) {

                        if (reportType == ReportType.RUNNING) {
                            listViewItemsSummary[5].Text = "Total Running Time";
                        } else if (reportType == ReportType.IDLING) {
                            listViewItemsSummary[5].Text = "Total Idling Time";
                        } else if (reportType == ReportType.GEOFENCE) {
                            listViewItemsSummary[5].Text = "Total Geofence Active Time";
                        } else if (reportType == ReportType.ACC) {
                            listViewItemsSummary[5].Text = "Total ACC Active Time";
                        } else if (reportType == ReportType.EXTERNAL_POWER_CUT) {
                            listViewItemsSummary[5].Text = "Total ExternalPower Cut Time";
                        }
                        listViewItemsSummary[5].SubItems.Add(Converter.dataTableColumnSumTimeSpanIfTrue(dataTableDetails, "Time").ToString(@"dd\.hh\:mm\:ss"));
                    }

                    ListView listViewSummary = new ListView();
                    listViewSummary.Dock = DockStyle.Fill;
                    listViewSummary.View = View.Details;
                    listViewSummary.Scrollable = false;
                    listViewSummary.FullRowSelect = true;

                    ColumnHeader columnHeaderLabelSummary = listViewSummary.Columns.Add("Summary");
                    columnHeaderLabelSummary.Width = 90;

                    ColumnHeader columnHeaderValueSummary = listViewSummary.Columns.Add("Value");
                    columnHeaderValueSummary.Width = 150;

                    listViewSummary.Items.AddRange(listViewItemsSummary);

                    TableLayoutPanel tableLayoutPanelRight = new TableLayoutPanel();
                    tableLayoutPanelRight.Dock = DockStyle.Fill;
                    tableLayoutPanelRight.RowStyles.Clear();
                    tableLayoutPanelRight.ColumnStyles.Clear();
                    tableLayoutPanelRight.Margin = new Padding(0, 0, 0, 0);
                    tableLayoutPanelRight.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 100));
                    tableLayoutPanelRight.RowStyles.Add(new RowStyle(SizeType.Absolute, 220));
                    tableLayoutPanelRight.RowStyles.Add(new RowStyle(SizeType.Absolute, 220));
                    tableLayoutPanelRight.RowStyles.Add(new RowStyle(SizeType.Percent, 100));

                    tableLayoutPanelRight.Controls.Add(listViewDetails, 0, 0);
                    tableLayoutPanelRight.Controls.Add(listViewSummary, 0, 1);
                    #endregion
                    #region tableLayoutPanelBottom
                    Button buttonNext = new Button();
                    buttonNext.Dock = DockStyle.Fill;
                    //buttonNext.Text = "Next";
                    buttonNext.Click += buttonNext_Click;
                    buttonNext.Visible = pagingStatus;
                    buttonNext.BackgroundImage = Resources.icon_stepr_001;
                    buttonNext.BackgroundImageLayout = ImageLayout.Zoom;

                    Button buttonPrev = new Button();
                    buttonPrev.Dock = DockStyle.Fill;
                    //buttonPrev.Text = "Prev";
                    buttonPrev.Click += buttonPrev_Click;
                    buttonPrev.Visible = pagingStatus;
                    buttonPrev.BackgroundImage = Resources.icon_stepl_001;
                    buttonPrev.BackgroundImageLayout = ImageLayout.Zoom;

                    Button buttonFirst = new Button();
                    buttonFirst.Dock = DockStyle.Fill;
                    //buttonFirst.Text = "First";
                    buttonFirst.Click += buttonFirst_Click;
                    buttonFirst.Visible = pagingStatus;
                    buttonFirst.BackgroundImage = Resources.icon_stepll_001;
                    buttonFirst.BackgroundImageLayout = ImageLayout.Zoom;

                    Button buttonLast = new Button();
                    buttonLast.Dock = DockStyle.Fill;
                    //buttonLast.Text = "Last";
                    buttonLast.Click += buttonLast_Click;
                    buttonLast.Visible = pagingStatus;
                    buttonLast.BackgroundImage = Resources.icon_steprl_001;
                    buttonLast.BackgroundImageLayout = ImageLayout.Zoom;

                    Label LabelPageNumber = new Label();
                    LabelPageNumber.Dock = DockStyle.Fill;
                    LabelPageNumber.Text = "1";
                    LabelPageNumber.TextAlign = ContentAlignment.MiddleRight;
                    LabelPageNumber.Visible = pagingStatus;

                    Label LabelTotalPageNumber = new Label();
                    LabelTotalPageNumber.Dock = DockStyle.Fill;
                    int totalPageNumber = (dataCount / (int)hashTable["limit"]) + 1;
                    LabelTotalPageNumber.Text = "/    " + totalPageNumber.ToString() + " Page(s)";
                    LabelTotalPageNumber.TextAlign = ContentAlignment.MiddleLeft;
                    LabelTotalPageNumber.Visible = pagingStatus;

                    Label LabelDataCount = new Label();
                    LabelDataCount.Dock = DockStyle.Fill;
                    LabelDataCount.Text = dataCount.ToString();
                    LabelDataCount.TextAlign = ContentAlignment.MiddleRight;

                    Label labelDetails = new Label();
                    labelDetails.Dock = DockStyle.Fill;
                    labelDetails.TextAlign = ContentAlignment.MiddleLeft;
                    labelDetails.Text = "Record(s) found";

                    TableLayoutPanel tableLayoutPanelBottom = new TableLayoutPanel();
                    tableLayoutPanelBottom.Dock = DockStyle.Fill;
                    tableLayoutPanelBottom.RowStyles.Clear();
                    tableLayoutPanelBottom.ColumnStyles.Clear();
                    tableLayoutPanelBottom.ColumnStyles.Add(new ColumnStyle(SizeType.Absolute, 50));
                    tableLayoutPanelBottom.ColumnStyles.Add(new ColumnStyle(SizeType.Absolute, 50));
                    tableLayoutPanelBottom.ColumnStyles.Add(new ColumnStyle(SizeType.Absolute, 50));
                    tableLayoutPanelBottom.ColumnStyles.Add(new ColumnStyle(SizeType.Absolute, 50));
                    tableLayoutPanelBottom.ColumnStyles.Add(new ColumnStyle(SizeType.Absolute, 50));
                    tableLayoutPanelBottom.ColumnStyles.Add(new ColumnStyle(SizeType.Absolute, 100));
                    tableLayoutPanelBottom.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 100));
                    tableLayoutPanelBottom.ColumnStyles.Add(new ColumnStyle(SizeType.Absolute, 100));

                    tableLayoutPanelBottom.RowStyles.Add(new RowStyle(SizeType.Percent, 100));
                    tableLayoutPanelBottom.Controls.Add(buttonFirst, 0, 0);
                    tableLayoutPanelBottom.Controls.Add(buttonPrev, 1, 0);
                    tableLayoutPanelBottom.Controls.Add(buttonNext, 2, 0);
                    tableLayoutPanelBottom.Controls.Add(buttonLast, 3, 0);
                    tableLayoutPanelBottom.Controls.Add(LabelPageNumber, 4, 0);
                    tableLayoutPanelBottom.Controls.Add(LabelTotalPageNumber, 5, 0);
                    tableLayoutPanelBottom.Controls.Add(LabelDataCount, 6, 0);
                    tableLayoutPanelBottom.Controls.Add(labelDetails, 7, 0);
                    #endregion
                    #region tableLayoutInformationParent
                    TableLayoutPanel tableLayoutInformationParent = new TableLayoutPanel();
                    tableLayoutInformationParent.RowStyles.Clear();
                    tableLayoutInformationParent.ColumnStyles.Clear();
                    tableLayoutInformationParent.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 100));
                    tableLayoutInformationParent.ColumnStyles.Add(new ColumnStyle(SizeType.Absolute, 250));
                    tableLayoutInformationParent.RowStyles.Add(new RowStyle(SizeType.Percent, 100));
                    tableLayoutInformationParent.RowStyles.Add(new RowStyle(SizeType.Absolute, 40));
                    tableLayoutInformationParent.Controls.Add(dataGridView, 0, 0);
                    tableLayoutInformationParent.Controls.Add(tableLayoutPanelBottom, 0, 1);
                    tableLayoutInformationParent.Controls.Add(tableLayoutPanelRight, 1, 0);
                    //tableLayoutInformationParent.Controls.Add(labelDetails, 1, 1);
                    tableLayoutInformationParent.Dock = DockStyle.Fill;
                    #endregion
                    #region tabPageAndTabControls
                    TabPage tabPage = new TabPage(tabPageName);
                    tabPage.Name = reportItemName;

                    tabPage.Tag = hashTable;
                    tabPage.Controls.Add(tableLayoutInformationParent);

                    hashTable["dataGridViewInformation"] = dataGridView;

                    if (tabControl != null) {
                        this.Invoke(new MethodInvoker(delegate {
                            tabControl.TabPages.Add(tabPage);
                            tabControl.SelectTab(tabPage);
                            tabControl.Click += tabControl_Click;
                            tabControl.Refresh();
                            Application.DoEvents();
                        }));
                    }
                    #endregion
                    break;
                } catch (QueryException queryException) {
                    Log log = new Log(LogFileType.TXT, LogType.EXCEPTION);
                    string logData = "";
                    if (tracker != null)
                        logData = DateTime.Now.ToString() + "\t\t queryException \t\t" + tracker.VehicleRegistration + " : " + queryException.Message;
                    else
                        logData = DateTime.Now.ToString() + "\t\t queryException \t\t" + queryException.Message;

                    log.write(logData);
                    break;
                } catch (MySqlException mySqlException) {
                    Log log = new Log(LogFileType.TXT, LogType.EXCEPTION);
                    string logData = "";
                    if (tracker != null)
                        logData = DateTime.Now.ToString() + "\t\t mySqlException \t\t" + tracker.VehicleRegistration + " : " + mySqlException.Message;
                    else
                        logData = DateTime.Now.ToString() + "\t\t mySqlException \t\t" + mySqlException.Message;
                    log.write(logData);
                    if (mySqlException.ErrorCode == -2147467259) {
                        //requery
                        if (count == 2) {
                            break;
                        }
                    } else {
                        break;
                    }
                } catch (Exception exception) {
                    Log log = new Log(LogFileType.TXT, LogType.EXCEPTION);
                    string logData = "";
                    if (tracker != null) {
                        logData = DateTime.Now.ToString() + "\t\t exception \t\t" + tracker.VehicleRegistration + " : " + exception.Message;
                    } else {
                        logData = DateTime.Now.ToString() + "\t\t exception \t\t" + exception.Message;
                    }
                    log.write(logData);
                    break;
                }
            }
            #endregion
            #region -updateProgressBarStatus
            lock (this.progressBarStatus) {
                workerThreadFinished++;
                double result = workerThreadFinished / workerThreadCount;
                double progressValue = result * (double)progressBarStatus.Maximum;
                updateProgressBarStatus((int)progressValue);
            }
            #endregion
        }