示例#1
0
        private static PrefsData loadPrefs()
        {
            PrefsData result = new PrefsData();

            string filePath = System.Environment.CurrentDirectory + m_fileName;

            if (File.Exists(filePath))
            {
                PrefsData.PrefLogIndex currentSpreadheetIndex = PrefsData.PrefLogIndex.Log01;
                foreach (string line in File.ReadLines(filePath))
                {
                    if (line.Length == 0)
                    {
                        continue;
                    }
                    if (line.StartsWith(m_commentToken))
                    {
                        continue;
                    }

                    if (line.StartsWith(m_versionToken))
                    {
                        checkVersion(line.TrimStart(m_versionToken.ToCharArray()));
                    }

                    // get ints
                    if (line.StartsWith(m_intToken))
                    {
                        // remove the line token that shows this line contains int data
                        string intData = line.Remove(0, m_intToken.Length);

                        string logInterval = m_dataTokens[(int)PrefsData.PrefInt.LogInterval];
                        string idleTime    = m_dataTokens[(int)PrefsData.PrefInt.IdleTime];
                        string timeoutTime = m_dataTokens[(int)PrefsData.PrefInt.TimeoutTime];
                        string ActiveLog   = m_dataTokens[(int)PrefsData.PrefInt.ActiveLog];

                        if (intData.StartsWith(logInterval))
                        {
                            int defaultValue = m_defaultLogInterval;
                            int.TryParse(intData.Remove(0, intData.LastIndexOf(m_dataSeperator) + 1), out defaultValue);
                            result.setInt(defaultValue, PrefsData.PrefInt.LogInterval);
                        }

                        if (intData.StartsWith(idleTime))
                        {
                            int defaultValue = m_defaultIdleTime;
                            int.TryParse(intData.Remove(0, intData.LastIndexOf(m_dataSeperator) + 1), out defaultValue);
                            result.setInt(defaultValue, PrefsData.PrefInt.IdleTime);
                        }

                        if (intData.StartsWith(timeoutTime))
                        {
                            int defaultValue = m_defaultTimeoutTime;
                            int.TryParse(intData.Remove(0, intData.LastIndexOf(m_dataSeperator) + 1), out defaultValue);
                            result.setInt(defaultValue, PrefsData.PrefInt.TimeoutTime);
                        }

                        if (intData.StartsWith(ActiveLog))
                        {
                            int defaultValue = m_defaultActiveLog;
                            int.TryParse(intData.Remove(0, intData.LastIndexOf(m_dataSeperator) + 1), out defaultValue);

                            result.setInt(defaultValue, PrefsData.PrefInt.ActiveLog);
                        }
                    } // END get ints

                    // get strings
                    if (line.StartsWith(m_stringToken))
                    {
                        // remove the line token shwoing this line contains a string of strings of data
                        // then split each string into its own string
                        string[] strData = (line.Remove(0, m_stringToken.Length))
                                           .Split(m_sheetsSeperator.ToCharArray());

                        // if token was the only character continue
                        if (strData.Length == 0)
                        {
                            continue;
                        }
                        // if data storage is full continue
                        if (currentSpreadheetIndex >= PrefsData.PrefLogIndex.Count)
                        {
                            continue;
                        }

                        result.setLogName(strData[0], currentSpreadheetIndex);
                        result.setProjectName(strData[1], currentSpreadheetIndex);
                        result.setProjectDescription(strData[2], currentSpreadheetIndex);
                        result.setLogGoogleId(strData[3], currentSpreadheetIndex);

                        currentSpreadheetIndex++;
                    } // END get strings
                }
                Console.WriteLine("Pref file loaded");
            }
            else // file did not exist
            {
                Console.WriteLine("Pref file not found");

                // create a default user preference file
                result.setInt(m_defaultLogInterval, PrefsData.PrefInt.LogInterval);
                result.setInt(m_defaultIdleTime, PrefsData.PrefInt.IdleTime);
                result.setInt(m_defaultTimeoutTime, PrefsData.PrefInt.TimeoutTime);
                result.setInt(m_defaultActiveLog, PrefsData.PrefInt.ActiveLog);

                // preset first log profile
                result.setLogName("Default Log", 0);
                result.setProjectName("Default Project", 0);
                result.setProjectDescription("Default Description", 0);
                result.setLogGoogleId("", 0);

                // set the other profiles as empty
                for (PrefsData.PrefLogIndex i = PrefsData.PrefLogIndex.Log02; i < PrefsData.PrefLogIndex.Count; i++)
                {
                    result.setLogName("", i);
                    result.setProjectName("", i);
                    result.setProjectDescription("", i);
                    result.setLogGoogleId("", i);
                }
            }

            return(result);
        }
示例#2
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);
        }