示例#1
0
        private void LblWBS_Click(object sender, EventArgs e)
        {
            string line;
            string wbs;
            string description;

            //Will switch the text of WBS buttons between WBS number and WBS description
            foreach (Button btn in this.Controls.OfType <Button>())
            {
                if (btn.Name.IndexOf("BtnWBS_") >= 0)
                {
                    StreamReader file = new StreamReader(TTStatic.ttAppPath + "\\WBS.txt");

                    while ((line = file.ReadLine()) != null)
                    {
                        wbs         = TTStatic.GetDelimitedFieldData(line, 1, ",");
                        description = TTStatic.GetDelimitedFieldData(line, 2, ",");

                        if (wbs == btn.Text)
                        {
                            btn.Text = description;
                        }
                        else if (description == btn.Text)
                        {
                            btn.Text = wbs;
                        }
                    }

                    file.Close();
                }
            }
        }
示例#2
0
        private void Main_Load(object sender, EventArgs e)
        {
            //MessageBox.Show(Application.StartupPath));
            //MessageBox.Show(Path.GetDirectoryName(Application.ExecutablePath));

            // Load settings
            TTSetting  t;
            TTSettings tts = new TTSettings();

            t = tts.GetTTSettings();

            TxtEmployeeId.Text           = t.EmployeeId;
            TTStatic.ttPathToDataLocal   = t.PathToDataLocal;
            TTStatic.ttPathToDataCentral = t.PathToDataCentral;
            TTStatic.ttPathToWBS         = t.PathToWBS;
            TTStatic.ttAppPath           = Application.StartupPath;
            TimTimer.Interval            = t.Interval;

            DteDate.MinDate = DateTime.Now.AddDays(-42);

            // Position form
            this.Left = t.Left;
            this.Top  = t.Top;

            //Call methid to create WBS buttons (and hidden text fields) from WBS.TXT file
            CreateWBSButtons("WBS");

            //Get week number based on date
            TxtWeek.Text = TTStatic.GetWeekNumber(DteDate.Text).ToString();

            //Get version, interval, hours per day and week for top of window
            GetThisText();
        }
示例#3
0
        private void DteDate_ValueChanged(object sender, EventArgs e)
        {
            //Change week number field if date changes
            TxtWeek.Text = TTStatic.GetWeekNumber(DteDate.Text).ToString();

            //Update windows header
            GetThisText();
        }
示例#4
0
        private void CreateWBSButtons(string show)
        {
            //Variables for positioning buttons
            int left        = 5;
            int top         = 55;
            int width       = 146;
            int height      = 20;
            int hSpace      = 3;
            int vSpace      = 3;
            int hButtons    = 4; //Number of buttons horizontally
            int vButtons    = 4; //Number of buttons vertically
            int buttonIndex = 0;

            string line;
            string WBS;
            string WBSDescription;

            //Create arrays for WBS numbers
            Button[]  buttonArray  = new Button[hButtons * vButtons];
            TextBox[] textBoxArray = new TextBox[hButtons * vButtons];
            ToolTip[] toolTipArray = new ToolTip[hButtons * vButtons];

            //Create instance of TimeTracker to access methods
            TTTimeTracker t = new TTTimeTracker();

            //Open WBS.TXT filr for reading
            StreamReader file = new StreamReader(TTStatic.ttAppPath + "\\WBS.txt");

            //Create buttons (horizontal x vertical)
            for (int i = 0; i < vButtons; i++)
            {
                for (int j = 0; j < hButtons; j++)
                {
                    line = file.ReadLine();

                    if (line != null && line.Length > 0)
                    {
                        WBS            = TTStatic.GetDelimitedFieldData(line, 1, ",");
                        WBSDescription = TTStatic.GetDelimitedFieldData(line, 2, ",");

                        //Hidden textbox array to use for WBS description
                        textBoxArray[buttonIndex]         = new TextBox();
                        textBoxArray[buttonIndex].Name    = "TxtWBSDescription_" + WBS;
                        textBoxArray[buttonIndex].Text    = WBSDescription;
                        textBoxArray[buttonIndex].Visible = false;

                        //Button array to use for WBS
                        buttonArray[buttonIndex]        = new Button();
                        buttonArray[buttonIndex].Name   = "BtnWBS_" + WBS;
                        buttonArray[buttonIndex].Click += new EventHandler(buttonArray_Click);

                        buttonArray[buttonIndex].Size     = new Size(width, height);
                        buttonArray[buttonIndex].Location = new Point(left + j * (width + vSpace), top + i * (height + hSpace));

                        buttonArray[buttonIndex].Text = WBS;
                        toolTipArray[buttonIndex]     = new ToolTip();
                        toolTipArray[buttonIndex].SetToolTip(buttonArray[buttonIndex], WBSDescription);

                        //Add buttons and textboxes to Controls collection
                        this.Controls.Add(buttonArray[buttonIndex]);
                        this.Controls.Add(textBoxArray[buttonIndex]);
                        buttonIndex += 1;
                    }
                }
            }

            file.Close();

            //Call this to show WBS descriptions instead of numbers on buttons
            this.LblWBS_Click(this, null);
        }
示例#5
0
        private void BtnSave_Click(object sender, EventArgs e)
        {
            string date;
            int    weeknumber;
            string line;
            string errMessage = "";

            //Save position of form
            SavePosition();

            //Update window header information
            GetThisText();



            //Validate WBS Format
            string shortWBS = @"^(I|C)-([0-9]{6})\.([0-9]{2})\.([0-9][1-8])";
            string longWBS  = @"^(I|C)-([0-9]{6})\.([0-9]{2})\.([0-9]{2})\.([0-9][1-8])$";

            Match match  = Regex.Match(TxtWBS.Text, shortWBS, RegexOptions.IgnoreCase);
            Match match1 = Regex.Match(TxtWBS.Text, longWBS, RegexOptions.IgnoreCase);

            if (TxtWBS.Text.Length >= 15)
            {
                if (match1.Success)
                {
                    /*proceed*/;
                }
                else
                {
                    errMessage += "Invalid WBS"; errMessage += Environment.NewLine;
                }
            }
            if (match.Success)
            {
                /*proceed*/;
            }
            else
            {
                errMessage += "Invalid WBS"; errMessage += Environment.NewLine;
            }


            //Validates Hours entry
            Match match2 = Regex.Match(TxtHours.Text, "^?[0-9].?[0-9]*$");

            if (match2.Success)
            {
                /*proceed*/;
            }
            else
            {
                errMessage += "Invalid Hours Format"; errMessage += Environment.NewLine;
            }


            //Reads WBS file path from ttsettings
            string settingsPath     = TTStatic.ttAppPath + "//ttsettings.txt";
            string PathToWBS        = File.ReadLines(settingsPath).Skip(6).Take(1).First();
            var    validWbsFilePath = PathToWBS.Substring(PathToWBS.LastIndexOf('=') + 1);


            if (File.Exists(validWbsFilePath))
            {
                var  wbslist   = File.ReadAllLines(validWbsFilePath);
                bool wbsExists = wbslist.Any(x => x.Contains(TxtWBS.Text.Substring(0, 14)));
                if (wbsExists)
                {
                    ;
                }
                else
                {
                    errMessage += "This WBS does not exist" + Environment.NewLine;
                }
            }
            else
            {
                errMessage += "WBS file path is not configured in Debug/Incoming/" + Environment.NewLine;
            }


            //Reads all the valid WBS then checks if the user entered a valid WBS in field

            /*
             * bool contains = false;
             * string[] lines = File.ReadAllLines(validWbsFilePath);
             * foreach (string lin in lines)
             * {
             *  if (lin.Contains(TxtWBS.Text))
             *      contains = true;
             * }
             * if (contains)
             *  ;
             * else
             *  errMessage += "This WBS does not exist" + Environment.NewLine;
             */

            //Show Error upon empty fields
            if (TxtEmployeeId.Text == "")
            {
                errMessage += "Employee ID can't be empty"; errMessage += Environment.NewLine;
            }
            if (TxtWBS.Text == "")
            {
                errMessage += "WBS can't be empty"; errMessage += Environment.NewLine;
            }
            if (DteDate.Text == "")
            {
                errMessage += "Date can't be empty"; errMessage += Environment.NewLine;
            }
            if (TxtHours.Text == "")
            {
                errMessage += "Hours can't be empty";
            }
            if (TxtHours.Text == "0" || TxtHours.Text == "0.0")
            {
                errMessage += "Hours can't be 0";
            }

            if (errMessage != "")
            {
                MessageBox.Show(errMessage); return;
            }

            //Convert date to YYYYMMDD for filename
            date = TTStatic.ConvertDate(DteDate.Text);

            //Get weeknumber for filename
            weeknumber = TTStatic.GetWeekNumber(DteDate.Text);

            //Craete the line to save in the file
            line = TxtEmployeeId.Text + "," + date + "," + TxtWBS.Text + "," + TxtWBSDescription.Text + "," + TxtHours.Text + "," + TxtComment.Text;

            //Create file or add line to file
            using (StreamWriter file = new StreamWriter(TTStatic.ttPathToDataLocal + "\\" + this.TxtEmployeeId.Text + "_" + weeknumber + "_" + date + ".txt", true))
            {
                file.WriteLine(line);
            }

            TxtHours.Text          = "";
            TxtWBS.Text            = "";
            TxtWBSDescription.Text = "";
            TxtComment.Text        = "";

            //Update window header information
            GetThisText();
        }
示例#6
0
        //SET and GET functions ending with "JSON" use NewtonSofts JSON serializer/deserializer to write/read TTSETTINGS.JSON
        //To remove dependency on NewtonSoft there are also SET and GET methods for .TXT file settings

        public TTSetting GetTTSettings()
        {
            //Get all settings when stored in .TXT file
            string line;
            string name;
            string value;

            TTSetting tts = new TTSetting();

            StreamReader file = new StreamReader(Application.StartupPath + "\\ttsettings.txt");

            while ((line = file.ReadLine()) != null)
            {
                name  = TTStatic.GetDelimitedFieldData(line, 1, "=");
                value = TTStatic.GetDelimitedFieldData(line, 2, "=");

                switch (name.ToUpper())
                {
                case "EMPLOYEEID":
                    tts.EmployeeId = value;
                    break;

                case "INTERVAL":
                    tts.Interval = Int32.Parse(value);
                    break;

                case "LEFT":
                    tts.Left = Int32.Parse(value);
                    break;

                case "TOP":
                    tts.Top = Int32.Parse(value);
                    break;

                case "PATHTODATALOCAL":
                    if (value.Substring(0, 2) == "..")
                    {
                        value = Application.StartupPath + value.Substring(2);
                    }
                    tts.PathToDataLocal = value;
                    break;

                case "PATHTODATACENTRAL":
                    if (value.Substring(0, 2) == "..")
                    {
                        value = Application.StartupPath + value.Substring(2);
                    }

                    tts.PathToDataCentral = value;
                    break;

                case "PATHTOWBS":
                    tts.PathToWBS = value;
                    break;

                default:
                    tts.Interval = 360000;
                    break;
                }
            }

            file.Close();

            return(tts);
        }