/// <summary> /// This method restore the original value stored in a dedicate DefinitionTag class property. /// Remember these original values is all about the first reading of config file. /// </summary> /// <param name="sender">Object that is an object type</param> /// <param name="e">This contains event info about data grid view errors</param> private void btRestore_Click(object sender, EventArgs e) { //progress bar... gbProgressBar.Visible = true; gbProgressBar.Maximum = dgvConfig.Rows.Count; gbProgressBar.Step = 1; gbProgressBar.Value = 0; this.Refresh(); Int32 q = 0; for (Int32 x = 0; x < dgvConfig.Rows.Count; x++) { String myTag = dgvConfig.Rows[x].Cells[Constants.K_ColumnTag].Value.ToString(); String originalValue = dgvConfig[Constants.K_ColumnOriginalValue, x].Value.ToString(); String myDescription = dgvConfig.Rows[x].Cells[Constants.K_ColumnDescriptionHidden].Value.ToString(); DictionaryUtils.UpdateCustomValue(myTag, originalValue, myDescription, ref DictionaryAllRows); dgvConfig[Constants.K_ColumnValue, x].Value = originalValue; q += 1; gbProgressBar.Value = q; } gbProgressBar.Value = 0; gbProgressBar.Visible = false; this.Refresh(); }
/// <summary> /// This method open a file, it reads it through SplitTextDataDescription() method and /// loads info into a public dictionary. /// Furthermore, unscribes two events, where possible, then call GetQuery() /// calling SetDataGridView() method and finally subscribes these two events (because of /// when we set datagridview these events immediately raise...) /// /// For events see: https://stackoverflow.com/questions/5652957/what-event-catches-a-change-of-value-in-a-combobox-in-a-datagridviewcell /// </summary> /// /// <param name="file">Represents </param> private void ReadConfigFile(String pathFile = "") { Int32 size = 0; String[] TextData = null; //https://stackoverflow.com/questions/5652957/what-event-catches-a-change-of-value-in-a-combobox-in-a-datagridviewcell dgvConfig.CurrentCellDirtyStateChanged -= new EventHandler(dataGridView_CurrentCellDirtyStateChanged); dgvConfig.CellValueChanged -= new DataGridViewCellEventHandler(dataGridView_CellValueChanged); Boolean f = FileUtils.OpenTextFile(out TextData, out size, ref pathFile); if (!f) { return; } DictionaryAllRows = DictionaryUtils.SplitDataInDictionary(TextData); //var DataArray = GetQuery(String.Empty, DictionaryAllRows); SetDataGridView(DictionaryAllRows); //https://stackoverflow.com/questions/5652957/what-event-catches-a-change-of-value-in-a-combobox-in-a-datagridviewcell dgvConfig.CellValueChanged += new DataGridViewCellEventHandler(dataGridView_CellValueChanged); dgvConfig.CurrentCellDirtyStateChanged += new EventHandler(dataGridView_CurrentCellDirtyStateChanged); dgvConfig.Rows[0].Selected = true; txtDescription.Text = dgvConfig.Rows[0].Cells[Constants.K_ColumnDescriptionHidden].Value.ToString().Replace("\r\n", ""); lbPath.Text = pathFile + " (" + StringUtils.BytesToString(size) + ")"; }
/// <summary> /// This methods (with btSave_Click) permits to choice /// the path and the name of file you want to create. /// </summary> /// <param name="sender">Object that is an object type</param> /// <param name="e">This contains event info about object</param> private void saveFileDialog1_FileOk(object sender, System.ComponentModel.CancelEventArgs e) { // Get file name. for (Int32 x = 0; x < dgvConfig.Rows.Count; x++) { String myTag = dgvConfig.Rows[x].Cells[Constants.K_ColumnTag].Value.ToString(); String originalValue = dgvConfig[Constants.K_ColumnValue, x].Value.ToString(); String myDescription = dgvConfig.Rows[x].Cells[Constants.K_ColumnDescriptionHidden].Value.ToString(); DictionaryUtils.UpdateCustomValue(myTag, originalValue, myDescription, ref DictionaryAllRows); } String name = saveFileDialog1.FileName; FileUtils.SavingConfFile(name, ref DictionaryAllRows); }
/// <summary> /// Determines if a cell change its value, through calling Trivia.CheckDataIntegrity() method, /// in order to determine if this value is congruent or not. /// </summary> /// <param name="sender">Object that is a dataGridView cell type</param> /// <param name="e">This contains event info about object</param> private void dataGridView_CellValueChanged(object sender, DataGridViewCellEventArgs e) { //Make sure the clicked row/column is valid. Boolean validClick = (e.RowIndex != -1 && e.ColumnIndex != -1); if ((validClick) && (e.ColumnIndex == Constants.K_ColumnValue) && (Trivia.VerifyTypeCellCombo(dgvConfig[Constants.K_ColumnTag, e.RowIndex].Value.ToString(), ref ListCombo))) { dgvConfig.Refresh(); String myTag = dgvConfig[Constants.K_ColumnTag, e.RowIndex].Value.ToString(); String myValue = dgvConfig[Constants.K_ColumnValue, e.RowIndex].Value.ToString(); String myDescription = dgvConfig[Constants.K_ColumnDescriptionHidden, e.RowIndex].Value.ToString(); //TODO: determine cases if (!DictionaryUtils.CheckDataIntegrity(ref DictionaryAllRows, myTag, myValue)) { return; } DictionaryUtils.UpdateCustomValue(myTag, myValue, myDescription, ref DictionaryAllRows); } }
/// <summary> /// This method permits, on user click, to perform two type of actions. /// <list type="On click"> /// <item> The user can iterate with a combo list full of all possible value for this tag.</item> /// <item> It appears a open dialog form where you can specify which path you want indicate.</item> /// <item> It appears an input box where you can insert custom value</item> /// </list> /// </summary> /// <param name="sender">Object that is a dataGridView type</param> /// <param name="e">This contains event info about data cell</param> private void dgvConfig_CellClick(object sender, DataGridViewCellEventArgs e) { Boolean validClick = (e.RowIndex != -1 && e.ColumnIndex != -1); //Make sure the clicked row/column is valid. // Check to make sure the cell clicked is the cell containing the combobox //if ((e.ColumnIndex == kColumnActions) && validClick) { String myTag = dgvConfig.Rows[e.RowIndex].Cells[Constants.K_ColumnTag].Value.ToString(); String myValue = dgvConfig.Rows[e.RowIndex].Cells[Constants.K_ColumnValue].Value.ToString(); String myDescription = dgvConfig.Rows[e.RowIndex].Cells[Constants.K_ColumnDescriptionHidden].Value.ToString(); if ((e.ColumnIndex == Constants.K_ColumnValue) && validClick) { if (dgvConfig.CurrentCell is DataGridViewComboBoxCell) { dgvConfig.ReadOnly = false; dgvConfig.EditMode = DataGridViewEditMode.EditOnEnter; } else { String prompt = "TAG --> " + myTag; if (Trivia.IterateOverList(ListOpenDialog, myTag)) { String Path = String.Empty; Boolean f = FileUtils.OpenFolder(out Path); if (!f) { return; } if (myValue != Path) { DictionaryUtils.UpdateCustomValue(myTag, Path, myDescription, ref DictionaryAllRows); dgvConfig[Constants.K_ColumnValue, e.RowIndex].Value = Path; } } else if (Trivia.IterateOverList(ListOpenTextBox, myTag)) { String title = String.Empty; String content = dgvConfig[Constants.K_ColumnValue, e.RowIndex].Value.ToString(); String tip = String.Empty; InputBoxResult result = InputBox.Show(prompt, title, content, tip, new InputBoxValidatingHandler(inputBox_Validating)); if ((result.OK) && (content != result.Text)) { DictionaryUtils.UpdateCustomValue(myTag, result.Text, myDescription, ref DictionaryAllRows); dgvConfig[Constants.K_ColumnValue, e.RowIndex].Value = result.Text; } } else if (Trivia.IterateOverList(ListOpenCheckBoxList, myTag)) { ChkListBox frm = new ChkListBox(); //add new prefixes here //String[] defaultValues = new String[46]{ "*.c", "*.cc", "*.cxx", "*.cpp", "*.cs", "*.c++", "*.java", "*.ii", "*.ixx", // "*.ipp", "*.i++", "*.inl", "*.idl", "*.ddl", "*.odl", "*.h", "*.hh", // "*.hxx", "*.hpp", "*.h++", "*.cs", "*.d", "*.php", "*.php4", "*.php5", // "*.phtml", "*.inc", "*.m", "*.markdown", "*.md", "*.mm", "*.dox", "*.py", // "*.pyw", "*.f90", "*.f95", "*.f03", "*.f08", "*.f", "*.for", "*.tcl", // "*.vhd", "*.vhdl", "*.ucf", "*.qsf", "*.ice"}; String content = dgvConfig[Constants.K_ColumnValue, e.RowIndex].Value.ToString().Trim(); String[] checkedElements = content.Split(new Char[] { '\\' }, StringSplitOptions.RemoveEmptyEntries); ////remove all spaces in a String array //checkedElements = (from t in checkedElements // select t.Trim()).ToArray(); frm.prompt = prompt; frm.checkedValues = checkedElements; //frm.values = defaultValues; frm.ShowDialog(); if (!String.IsNullOrEmpty(frm.strRet)) { dgvConfig[Constants.K_ColumnValue, e.RowIndex].Value = frm.strRet; } } dgvConfig.ReadOnly = true; } } else { dgvConfig.ReadOnly = true; } if (e.ColumnIndex < 2) { txtDescription.Text = dgvConfig.Rows[e.RowIndex].Cells[Constants.K_ColumnDescriptionHidden].Value.ToString().Replace("\r\n", ""); } }
/// <summary> /// This method create a DataTable object which is loaded with a filtered dictionary. /// Then it creates two column. /// <list type="Column"> /// <item> It contains values and (depending on type of key/tag) it is modified into combo or button (invisible).</item> /// <item> A column where store the original value read of config file (remember this method is called by ReadConfigFile()!).</item> /// </list> /// </summary> /// Finally set datagridview. /// <param name="DictionaryDataSource">This parameter is a dictionary (filtered if it is possible) as datagridview datasource.</param> private void SetDataGridView(Dictionary <String, DefinitionTag> DictionaryDataSource) { CloseConnection(); dgvConfig.ColumnHeadersDefaultCellStyle.ForeColor = Color.Chocolate; dgvConfig.ColumnHeadersDefaultCellStyle.BackColor = Color.Lavender; dgvConfig.EnableHeadersVisualStyles = false; dgvConfig.Visible = false; gbConfFile.Text = "Reading Configuration file..."; dgvConfig.AutoGenerateColumns = true; var filteredValues = DictionaryUtils.GetQuery(txtSearch.Text.Trim(), DictionaryAllRows); DataTable dt = new DataTable(); dt.Columns.Add("TAG", typeof(String)); dt.Columns.Add("Value", typeof(String)); dt.Columns.Add("Description", typeof(String)); dt.Columns.Add("OriginalValue", typeof(String)); //http://robertgreiner.com/2010/05/iterating-through-a-dictionary-in-csharp/ foreach (KeyValuePair <String, DefinitionTag> x in filteredValues) { dt.Rows.Add(x.Key, x.Value.Value, x.Value.Description); } dgvConfig.DataSource = dt; dgvConfig.SelectionMode = DataGridViewSelectionMode.FullRowSelect; dgvConfig.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.None; dgvConfig.AllowUserToResizeRows = false; //progress bar... gbProgressBar.Visible = true; gbProgressBar.Maximum = dgvConfig.Rows.Count * 2; gbProgressBar.Step = 1; gbProgressBar.Value = 0; this.Refresh(); Int32 q = 0; for (Int32 x = 0; x < dgvConfig.Rows.Count; x++) { String myTag = dgvConfig[Constants.K_ColumnTag, x].Value.ToString(); String myValue = dgvConfig[Constants.K_ColumnValue, x].Value.ToString(); if (Trivia.VerifyTypeCellButton(myTag, ref ListButton)) { //DEPRECATED //DataGridViewButtonCell bt = new DataGridViewButtonCell(); //bt.Value = kButtonText; //dgvConfig[kColumnActions, x] = bt; //DEPRECATED -- END String tmp = dgvConfig[Constants.K_ColumnValue, x].Value.ToString().Replace("\"", ""); dgvConfig[Constants.K_ColumnValue, x].Value = tmp; dgvConfig[Constants.K_ColumnOriginalValue, x].Value = tmp; //if (txtSearch.Text.Length == 0) UpdateCustomValue(myTag, tmp); } else if (Trivia.VerifyTypeCellCombo(myTag, ref ListCombo)) { DataGridViewComboBoxCell cb = new DataGridViewComboBoxCell(); cb.FlatStyle = FlatStyle.Flat; Trivia.FillCombo(ref cb, myTag); dgvConfig[Constants.K_ColumnValue, x] = cb; dgvConfig.Refresh(); dgvConfig.Rows[x].Cells[Constants.K_ColumnValue].Value = myValue; dgvConfig[Constants.K_ColumnOriginalValue, x].Value = myValue; //if (txtSearch.Text.Length == 0) UpdateCustomValue(myTag, myValue); } else { if (Trivia.TestingDotLineDescription(myTag)) { //TODO: regex... //(.*) etc //####myValue= myValue.Replace( } //UpdateCustomValue(myTag, myValue); } q += 1; gbProgressBar.Value = q; } this.Refresh(); dgvConfig.Columns[Constants.K_ColumnOriginalValue].Visible = false; dgvConfig.Columns[Constants.K_ColumnDescriptionHidden].Visible = true; //set autosize mode dgvConfig.Columns[Constants.K_ColumnTag].AutoSizeMode = DataGridViewAutoSizeColumnMode.None; dgvConfig.Columns[Constants.K_ColumnValue].AutoSizeMode = DataGridViewAutoSizeColumnMode.None; dgvConfig.Columns[Constants.K_ColumnTag].Width = Constants.K_ColWidthTag; dgvConfig.Columns[Constants.K_ColumnValue].Width = dgvConfig.Width - dgvConfig.Columns[Constants.K_ColumnTag].Width - Constants.K_ColWidthFillUp; dgvConfig.Visible = true; dgvConfig.Rows[0].Selected = true; txtDescription.Text = dgvConfig.Rows[0].Cells[Constants.K_ColumnDescriptionHidden].Value.ToString().Replace("\r\n", "");; gbConfFile.Text = "Configuration file: nr " + dgvConfig.Rows.Count.ToString() + " rows"; gbConfFile.ForeColor = Color.GreenYellow; dgvConfig.Refresh(); gbProgressBar.Value = 0; gbProgressBar.Visible = false; }