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