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(); } } }
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); }
//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); }