Skip to content

Commit

Permalink
#5 Added a table for time formats
Browse files Browse the repository at this point in the history
  • Loading branch information
tduguid authored and tduguid committed Feb 13, 2018
1 parent bbf68db commit 16aef60
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 15 deletions.
Binary file modified CS/App_Data/ScriptHelp.sdf
Binary file not shown.
12 changes: 6 additions & 6 deletions CS/Ribbon.xml
Original file line number Diff line number Diff line change
Expand Up @@ -175,25 +175,25 @@ Or use the following tag to remove all other ribbons when this loads
keytip="DTA"
/>
<comboBox
id="cboDateFormatReplace"
id="cboFormatDate"
onChange="OnChange"
getText="GetText"
getItemCount="GetItemCount"
getItemLabel="GetItemLabel"
sizeString= "XXXXXXXXXXXXXXXXXXXX"
screentip="Replace Date Format"
screentip="Date Format"
supertip="This is the date format the script uses to replace the formatting for date columns."
keytip="DFR"
/>
<comboBox
id="cboDateFormatFind"
id="cboFormatTime"
onChange="OnChange"
getText="GetText"
getItemCount="GetItemCount"
getItemLabel="GetItemLabel"
sizeString= "XXXXXXXXXXXXXXXXXXXX"
screentip="Find Date Format"
supertip="This is the date format to find. It defaults to the format from SQL Server Management Studio after you paste records into Excel."
screentip="Time Format"
supertip="This is the time format the script uses to replace the formatting for time columns."
keytip="DFF"
/>
<button
Expand All @@ -220,7 +220,7 @@ Or use the following tag to remove all other ribbons when this loads
onAction="OnAction"
screentip="Open Date Format List"
supertip="This will open the date format list form."
tag="DateFormat"
tag="TimeFormat"
keytip="LFR"
/>
<separator
Expand Down
39 changes: 39 additions & 0 deletions CS/Scripts/Data.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ public static string Connection()
/// </summary>
public static DataTable DateFormatTable = new DataTable();

/// <summary>
/// List of time format strings
/// </summary>
public static DataTable TimeFormatTable = new DataTable();

/// <summary>
/// List of graph data
/// </summary>
Expand Down Expand Up @@ -107,6 +112,40 @@ public static void CreateDateFormatTable()

}

/// <summary>
/// Creates the datatable for the date format strings
/// </summary>
public static void CreateTimeFormatTable()
{
try
{
string tableName = "TimeFormat";
string columnName = "FormatString";
string sql = "SELECT * FROM " + tableName + " ORDER BY " + columnName;
dynamic dcFormatString = new DataColumn(columnName, typeof(string));
TimeFormatTable.Rows.Clear();
DataColumnCollection columns = TimeFormatTable.Columns;
if (columns.Contains(columnName) == false)
{
TimeFormatTable.Columns.Add(dcFormatString);
}

using (var da = new SqlCeDataAdapter(sql, Connection()))
{
da.Fill(TimeFormatTable);
}
TimeFormatTable.DefaultView.Sort = columnName + " asc";
TimeFormatTable.TableName = tableName;

}
catch (Exception ex)
{
ErrorHandler.DisplayMessage(ex);

}

}

/// <summary>
/// Creates the datatable for the graph data
/// </summary>
Expand Down
39 changes: 30 additions & 9 deletions CS/Scripts/Ribbon.cs
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ public void Ribbon_Load(Office.IRibbonUI ribbonUI)

Data.CreateTableAliasTable();
Data.CreateDateFormatTable();
Data.CreateTimeFormatTable();
Data.CreateGraphDataTable();

}
Expand Down Expand Up @@ -358,9 +359,10 @@ public int GetItemCount(Office.IRibbonControl control)
{
switch (control.Id)
{
case "cboDateFormatReplace":
case "cboDateFormatFind":
case "cboFormatDate":
return Data.DateFormatTable.Rows.Count;
case "cboFormatTime":
return Data.TimeFormatTable.Rows.Count;
case "cboTableAlias":
return Data.TableAliasTable.Rows.Count;
default:
Expand All @@ -386,9 +388,10 @@ public string GetItemLabel(Office.IRibbonControl control, int index)
{
switch (control.Id)
{
case "cboDateFormatReplace":
case "cboDateFormatFind":
case "cboFormatDate":
return UpdateDateFormatComboBoxSource(index);
case "cboFormatTime":
return UpdateTimeFormatComboBoxSource(index);
case "cboTableAlias":
return UpdateTableAliasComboBoxSource(index);
default:
Expand All @@ -413,9 +416,9 @@ public string GetText(Office.IRibbonControl control)
{
switch (control.Id)
{
case "cboDateFormatReplace":
case "cboFormatDate":
return Properties.Settings.Default.Table_ColumnFormatDate;
case "cboDateFormatFind":
case "cboFormatTime":
return Properties.Settings.Default.Table_ColumnFormatTime;
case "cboTableAlias":
return Properties.Settings.Default.Table_ColumnTableAlias;
Expand Down Expand Up @@ -622,11 +625,11 @@ public void OnChange(Office.IRibbonControl control, string text)
{
switch (control.Id)
{
case "cboDateFormatReplace":
case "cboFormatDate":
Properties.Settings.Default.Table_ColumnFormatDate = text;
Data.InsertRecord(Data.DateFormatTable, text);
break;
case "cboDateFormatFind":
case "cboFormatTime":
Properties.Settings.Default.Table_ColumnFormatTime = text;
Data.InsertRecord(Data.DateFormatTable, text);
break;
Expand Down Expand Up @@ -1535,7 +1538,7 @@ public void OpenTableDataPane()
myTableData.Dispose();
}
myTableData = new TaskPane.TableData();
myTaskPaneTableData = Globals.ThisAddIn.CustomTaskPanes.Add(myTableData, "List of " + Ribbon.AppVariables.TableName + " for " + Scripts.AssemblyInfo.Title);
myTaskPaneTableData = Globals.ThisAddIn.CustomTaskPanes.Add(myTableData, Ribbon.AppVariables.TableName);
myTaskPaneTableData.DockPosition = Office.MsoCTPDockPosition.msoCTPDockPositionRight;
myTaskPaneTableData.DockPositionRestrict = Office.MsoCTPDockPositionRestrict.msoCTPDockPositionRestrictNoChange;
myTaskPaneTableData.Width = 300;
Expand Down Expand Up @@ -1566,6 +1569,24 @@ public string UpdateDateFormatComboBoxSource(int itemIndex)
}
}

/// <summary>
/// Update the value of the combobox from a data table by index
/// </summary>
/// <param name="itemIndex">Represents the index of the list value </param>
/// <returns>the label value for the combobox index</returns>
public string UpdateTimeFormatComboBoxSource(int itemIndex)
{
try
{
return Data.TimeFormatTable.Rows[itemIndex]["FormatString"].ToString();
}
catch (Exception ex)
{
ErrorHandler.DisplayMessage(ex);
return string.Empty;
}
}

/// <summary>
/// Update the value of the combobox from a data table by index
/// </summary>
Expand Down
7 changes: 7 additions & 0 deletions CS/TaskPane/TableData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ public TableData()
case "DateFormat":
dgvList.DataSource = Data.DateFormatTable;
break;
case "TimeFormat":
dgvList.DataSource = Data.TimeFormatTable;
break;
}
this.dgvList.Columns[0].Width = dgvList.Width - 75;

Expand Down Expand Up @@ -85,6 +88,10 @@ private void btnSave_Click(object sender, EventArgs e)
sda.Update(Data.DateFormatTable);
Data.CreateDateFormatTable();
break;
case "TimeFormat":
sda.Update(Data.TimeFormatTable);
Data.CreateDateFormatTable();
break;
}
Ribbon.ribbonref.InvalidateRibbon();

Expand Down

0 comments on commit 16aef60

Please sign in to comment.