Beispiel #1
0
        static void Main()
        {
            bool isGoogleSetup = TCOSheetsInterface.Init();

            InputHook.Start();

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            if (isGoogleSetup == false)
            {
                DialogMessage message = new DialogMessage("Google Sheets Error", "An error occured initializing Google Sheets service.\n\nLogs will not be written to Google Sheets.");
                message.ShowDialog();
            }

            Application.Run(new Form1());

            InputHook.End();
        }
Beispiel #2
0
        private void googleSheetsInterfaceSetup()
        {
            // not run if the target isn't set up within the program
            if (m_foundGoogleSheetAndTab == false)
            {
                return;
            }

            PrefsData.PrefLogIndex index = m_userPrefs.getActiveSheet();

            string googleSheetsId = m_userPrefs.getLogGoogleId(index);
            string tabName        = m_userPrefs.getProjectName(index);

            if (googleSheetsId == "" || tabName == "")
            {
                DialogMessage message = new DialogMessage("Information", "A Google Sheets id and tab name must be set in order to use google sheets interface.\nInteraction with google sheet will not function.");
                message.ShowDialog();
                return;
            }

            // check wth google sheets to see if the tab needs to be created
            if (!TCOSheetsInterface.tabExists(m_userPrefs.getLogGoogleId(index), m_userPrefs.getProjectName(index)))
            {
                System.Drawing.Size size = new System.Drawing.Size(5, 2);
                if (!TCOSheetsInterface.createTab(m_userPrefs.getLogGoogleId(index), m_userPrefs.getProjectName(index), size, 1))
                {
                    Console.WriteLine("Create new tab [" + m_userPrefs.getProjectName(index) + "] failed");
                }

                // create the header bar in the created tab
                SheetsLogEntry entryMaker = new SheetsLogEntry();
                List <Google.Apis.Sheets.v4.Data.RowData> rows = entryMaker.createTitleBar();
                TCOSheetsInterface.updateCells(
                    m_userPrefs.getLogGoogleId(index),
                    m_userPrefs.getProjectName(index),
                    "A1", "E2", rows);
            }
        }
Beispiel #3
0
        public void logTime()
        {
            // run only if write to local file succeeds
            if (LocalLogger.writeToLogFile())
            {
                if (m_foundGoogleSheetAndTab == false)
                {
                    return;
                }

                PrefsData.PrefLogIndex index = m_userPrefs.getActiveSheet();

                if (TCOSheetsInterface.getIsServiceActive() == false)
                {
                    Console.WriteLine("Google Sheets service inactive.");
                }

                if (!TCOSheetsInterface.WriteTimeNowToCell(
                        m_userPrefs.getLogGoogleId(index),
                        m_userPrefs.getProjectName(index),
                        m_timeStr, m_userPrefs.getProjectDescription(index)))
                {
                    Console.WriteLine("Attempt to log to google sheets failed.");
                    return;
                }

                m_timeConfirmed     += m_timePending;
                m_timePending        = 0;
                m_logTimeAccumulator = 0;
                Console.WriteLine("Total time logged is " + m_timeStr);
            }
            else
            {
                Console.WriteLine("Log failed");
            }
        }
Beispiel #4
0
        public DialogSheetsWindow(PrefsData userPrefs)
        {
            m_userPrefs   = userPrefs;
            m_selectedLog = m_userPrefs.getActiveSheet();

            this.ShowInTaskbar   = false;
            this.BackColor       = Color.LightGray;
            this.Text            = m_stringTitle;
            this.StartPosition   = FormStartPosition.CenterParent;
            this.FormBorderStyle = FormBorderStyle.FixedToolWindow;
            this.ShowInTaskbar   = false;
            this.MaximizeBox     = false;
            this.MinimizeBox     = false;
            this.AutoSizeMode    = AutoSizeMode.GrowAndShrink;
            this.AutoSize        = true;

            m_labelText               = new Label();
            m_labelFilepath           = new Label();
            m_labelLogName            = new Label();
            m_labelProjectName        = new Label();
            m_labelProjectDescription = new Label();
            m_labelGoogleSheetId      = new Label();

            m_buttonConfirm = new Button();
            m_buttonCancel  = new Button();

            // Size
            m_labelText.Size                   = new Size(600, 130);
            m_labelFilepath.AutoSize           = true;
            m_labelLogName.AutoSize            = true;
            m_labelProjectName.AutoSize        = true;
            m_labelProjectDescription.AutoSize = true;
            m_labelGoogleSheetId.AutoSize      = true;
            m_buttonConfirm.Size               = new Size(80, 40);
            m_buttonCancel.Size                = new Size(80, 40);

            // Location
            m_labelText.Location               = new Point(0, 0);
            m_labelFilepath.Location           = new Point(20, 5 + m_labelText.Size.Height);
            m_labelLogName.Location            = new Point(63, 5 + m_labelText.Size.Height);
            m_labelProjectName.Location        = new Point(178, 5 + m_labelText.Size.Height);
            m_labelProjectDescription.Location = new Point(293, 5 + m_labelText.Size.Height);
            m_labelGoogleSheetId.Location      = new Point(565, 5 + m_labelText.Size.Height);
            m_buttonConfirm.Location           = new Point(290, 380);
            m_buttonCancel.Location            = new Point(190, 380);

            // Text
            m_labelText.Text               = m_stringLabelText;
            m_labelFilepath.Text           = m_stringLabelFilepath;
            m_labelLogName.Text            = m_stringLabelLogName;
            m_labelProjectName.Text        = m_stringLabelProjectName;
            m_labelProjectDescription.Text = m_stringLabelProjectDescription;
            m_labelGoogleSheetId.Text      = m_stringLabelGoogleSheetId;
            m_buttonConfirm.Text           = m_stringButtonConfirm;
            m_buttonCancel.Text            = m_stringButtonCancel;

            // lambdas
            m_buttonConfirm.MouseUp += (s, e) =>
            {
                if (TCOSheetsInterface.getIsServiceActive() == false)
                {
                    DialogMessage message = new DialogMessage("Google Sheets Service Inactive", "The Google Sheets service has not been set up correctly.");
                    message.ShowDialog();
                }

                m_userPrefs.setActiveLog(m_selectedLog);

                for (PrefsData.PrefLogIndex i = 0; i < PrefsData.PrefLogIndex.Count; i++)
                {
                    m_userPrefs.setLogName(m_logData[(int)i].getLogName(), i);
                    m_userPrefs.setProjectName(m_logData[(int)i].getProjectName(), i);
                    m_userPrefs.setProjectDescription(m_logData[(int)i].getProjectDescription(), i);
                    m_userPrefs.setLogGoogleId(m_logData[(int)i].getGoogleSheetsId(), i);
                }

                this.DialogResult = DialogResult.OK;
                this.Close();
            };
            m_buttonCancel.MouseUp += (s, e) =>
            {
                this.DialogResult = DialogResult.Cancel;
                this.Close();
            };

            m_labelText.BackColor = Color.White;

            // create log data rows
            PrefsData.PrefLogIndex entryCount = UserPrefs.getMaxEntries();
            m_logData = new ControlLogData[(int)entryCount];
            for (PrefsData.PrefLogIndex i = 0; i < entryCount; i++)
            {
                m_logData[(int)i] = new ControlLogData();

                int Ypos = m_labelFilepath.Location.Y + m_labelFilepath.Size.Height + (int)i * (m_logData[(int)i].m_height + 5);

                // get the log profile data from user prefs
                m_logData[(int)i].setLogPath(""); // NOT IMPLEMENTED IN MAIN PROGRAM OR USER PREFERENCES
                m_logData[(int)i].setLogName(m_userPrefs.getLogName(i));
                m_logData[(int)i].setProjectName(m_userPrefs.getProjectName(i));
                m_logData[(int)i].setProjectDescription(m_userPrefs.getProjectDescription(i));
                m_logData[(int)i].setGoogleSheetsId(m_userPrefs.getLogGoogleId(i));

                // create a new instance of the iteration in memory to be used as an index in on CheckedChanged lambda
                PrefsData.PrefLogIndex radioIndex = i; // NOTE: if this isn't done the value used in the lambda will always be PrefLogIndex.Count

                // create radio buttun used to select the log
                RadioButton selectLog = new RadioButton();
                selectLog.Size     = new Size(15, 15);
                selectLog.Location = new Point(0, Ypos);

                if (i == m_selectedLog)
                {
                    selectLog.Checked = true;
                }

                selectLog.CheckedChanged += (s, e) => {
                    RadioButton rb = (RadioButton)s;
                    if (rb.Checked == true)
                    {
                        m_selectedLog = radioIndex;
                    }
                };

                // set position in dialog
                m_logData[(int)i].Location = new Point(selectLog.Location.X + selectLog.Size.Width + 5, Ypos);

                this.Controls.Add(selectLog);
                this.Controls.Add(m_logData[(int)i]);
            } // END create log data rows

            this.Controls.Add(m_labelText);
            this.Controls.Add(m_labelFilepath);
            this.Controls.Add(m_labelLogName);
            this.Controls.Add(m_labelProjectName);
            this.Controls.Add(m_labelProjectDescription);
            this.Controls.Add(m_labelGoogleSheetId);
            this.Controls.Add(m_buttonConfirm);
            this.Controls.Add(m_buttonCancel);
        }