Skip to content

Commit 16aef60

Browse files
tduguidtduguid
tduguid
authored and
tduguid
committed
#5 Added a table for time formats
1 parent bbf68db commit 16aef60

File tree

5 files changed

+82
-15
lines changed

5 files changed

+82
-15
lines changed

CS/App_Data/ScriptHelp.sdf

0 Bytes
Binary file not shown.

CS/Ribbon.xml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -175,25 +175,25 @@ Or use the following tag to remove all other ribbons when this loads
175175
keytip="DTA"
176176
/>
177177
<comboBox
178-
id="cboDateFormatReplace"
178+
id="cboFormatDate"
179179
onChange="OnChange"
180180
getText="GetText"
181181
getItemCount="GetItemCount"
182182
getItemLabel="GetItemLabel"
183183
sizeString= "XXXXXXXXXXXXXXXXXXXX"
184-
screentip="Replace Date Format"
184+
screentip="Date Format"
185185
supertip="This is the date format the script uses to replace the formatting for date columns."
186186
keytip="DFR"
187187
/>
188188
<comboBox
189-
id="cboDateFormatFind"
189+
id="cboFormatTime"
190190
onChange="OnChange"
191191
getText="GetText"
192192
getItemCount="GetItemCount"
193193
getItemLabel="GetItemLabel"
194194
sizeString= "XXXXXXXXXXXXXXXXXXXX"
195-
screentip="Find Date Format"
196-
supertip="This is the date format to find. It defaults to the format from SQL Server Management Studio after you paste records into Excel."
195+
screentip="Time Format"
196+
supertip="This is the time format the script uses to replace the formatting for time columns."
197197
keytip="DFF"
198198
/>
199199
<button
@@ -220,7 +220,7 @@ Or use the following tag to remove all other ribbons when this loads
220220
onAction="OnAction"
221221
screentip="Open Date Format List"
222222
supertip="This will open the date format list form."
223-
tag="DateFormat"
223+
tag="TimeFormat"
224224
keytip="LFR"
225225
/>
226226
<separator

CS/Scripts/Data.cs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@ public static string Connection()
3434
/// </summary>
3535
public static DataTable DateFormatTable = new DataTable();
3636

37+
/// <summary>
38+
/// List of time format strings
39+
/// </summary>
40+
public static DataTable TimeFormatTable = new DataTable();
41+
3742
/// <summary>
3843
/// List of graph data
3944
/// </summary>
@@ -107,6 +112,40 @@ public static void CreateDateFormatTable()
107112

108113
}
109114

115+
/// <summary>
116+
/// Creates the datatable for the date format strings
117+
/// </summary>
118+
public static void CreateTimeFormatTable()
119+
{
120+
try
121+
{
122+
string tableName = "TimeFormat";
123+
string columnName = "FormatString";
124+
string sql = "SELECT * FROM " + tableName + " ORDER BY " + columnName;
125+
dynamic dcFormatString = new DataColumn(columnName, typeof(string));
126+
TimeFormatTable.Rows.Clear();
127+
DataColumnCollection columns = TimeFormatTable.Columns;
128+
if (columns.Contains(columnName) == false)
129+
{
130+
TimeFormatTable.Columns.Add(dcFormatString);
131+
}
132+
133+
using (var da = new SqlCeDataAdapter(sql, Connection()))
134+
{
135+
da.Fill(TimeFormatTable);
136+
}
137+
TimeFormatTable.DefaultView.Sort = columnName + " asc";
138+
TimeFormatTable.TableName = tableName;
139+
140+
}
141+
catch (Exception ex)
142+
{
143+
ErrorHandler.DisplayMessage(ex);
144+
145+
}
146+
147+
}
148+
110149
/// <summary>
111150
/// Creates the datatable for the graph data
112151
/// </summary>

CS/Scripts/Ribbon.cs

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ public void Ribbon_Load(Office.IRibbonUI ribbonUI)
176176

177177
Data.CreateTableAliasTable();
178178
Data.CreateDateFormatTable();
179+
Data.CreateTimeFormatTable();
179180
Data.CreateGraphDataTable();
180181

181182
}
@@ -358,9 +359,10 @@ public int GetItemCount(Office.IRibbonControl control)
358359
{
359360
switch (control.Id)
360361
{
361-
case "cboDateFormatReplace":
362-
case "cboDateFormatFind":
362+
case "cboFormatDate":
363363
return Data.DateFormatTable.Rows.Count;
364+
case "cboFormatTime":
365+
return Data.TimeFormatTable.Rows.Count;
364366
case "cboTableAlias":
365367
return Data.TableAliasTable.Rows.Count;
366368
default:
@@ -386,9 +388,10 @@ public string GetItemLabel(Office.IRibbonControl control, int index)
386388
{
387389
switch (control.Id)
388390
{
389-
case "cboDateFormatReplace":
390-
case "cboDateFormatFind":
391+
case "cboFormatDate":
391392
return UpdateDateFormatComboBoxSource(index);
393+
case "cboFormatTime":
394+
return UpdateTimeFormatComboBoxSource(index);
392395
case "cboTableAlias":
393396
return UpdateTableAliasComboBoxSource(index);
394397
default:
@@ -413,9 +416,9 @@ public string GetText(Office.IRibbonControl control)
413416
{
414417
switch (control.Id)
415418
{
416-
case "cboDateFormatReplace":
419+
case "cboFormatDate":
417420
return Properties.Settings.Default.Table_ColumnFormatDate;
418-
case "cboDateFormatFind":
421+
case "cboFormatTime":
419422
return Properties.Settings.Default.Table_ColumnFormatTime;
420423
case "cboTableAlias":
421424
return Properties.Settings.Default.Table_ColumnTableAlias;
@@ -622,11 +625,11 @@ public void OnChange(Office.IRibbonControl control, string text)
622625
{
623626
switch (control.Id)
624627
{
625-
case "cboDateFormatReplace":
628+
case "cboFormatDate":
626629
Properties.Settings.Default.Table_ColumnFormatDate = text;
627630
Data.InsertRecord(Data.DateFormatTable, text);
628631
break;
629-
case "cboDateFormatFind":
632+
case "cboFormatTime":
630633
Properties.Settings.Default.Table_ColumnFormatTime = text;
631634
Data.InsertRecord(Data.DateFormatTable, text);
632635
break;
@@ -1535,7 +1538,7 @@ public void OpenTableDataPane()
15351538
myTableData.Dispose();
15361539
}
15371540
myTableData = new TaskPane.TableData();
1538-
myTaskPaneTableData = Globals.ThisAddIn.CustomTaskPanes.Add(myTableData, "List of " + Ribbon.AppVariables.TableName + " for " + Scripts.AssemblyInfo.Title);
1541+
myTaskPaneTableData = Globals.ThisAddIn.CustomTaskPanes.Add(myTableData, Ribbon.AppVariables.TableName);
15391542
myTaskPaneTableData.DockPosition = Office.MsoCTPDockPosition.msoCTPDockPositionRight;
15401543
myTaskPaneTableData.DockPositionRestrict = Office.MsoCTPDockPositionRestrict.msoCTPDockPositionRestrictNoChange;
15411544
myTaskPaneTableData.Width = 300;
@@ -1566,6 +1569,24 @@ public string UpdateDateFormatComboBoxSource(int itemIndex)
15661569
}
15671570
}
15681571

1572+
/// <summary>
1573+
/// Update the value of the combobox from a data table by index
1574+
/// </summary>
1575+
/// <param name="itemIndex">Represents the index of the list value </param>
1576+
/// <returns>the label value for the combobox index</returns>
1577+
public string UpdateTimeFormatComboBoxSource(int itemIndex)
1578+
{
1579+
try
1580+
{
1581+
return Data.TimeFormatTable.Rows[itemIndex]["FormatString"].ToString();
1582+
}
1583+
catch (Exception ex)
1584+
{
1585+
ErrorHandler.DisplayMessage(ex);
1586+
return string.Empty;
1587+
}
1588+
}
1589+
15691590
/// <summary>
15701591
/// Update the value of the combobox from a data table by index
15711592
/// </summary>

CS/TaskPane/TableData.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ public TableData()
3030
case "DateFormat":
3131
dgvList.DataSource = Data.DateFormatTable;
3232
break;
33+
case "TimeFormat":
34+
dgvList.DataSource = Data.TimeFormatTable;
35+
break;
3336
}
3437
this.dgvList.Columns[0].Width = dgvList.Width - 75;
3538

@@ -85,6 +88,10 @@ private void btnSave_Click(object sender, EventArgs e)
8588
sda.Update(Data.DateFormatTable);
8689
Data.CreateDateFormatTable();
8790
break;
91+
case "TimeFormat":
92+
sda.Update(Data.TimeFormatTable);
93+
Data.CreateDateFormatTable();
94+
break;
8895
}
8996
Ribbon.ribbonref.InvalidateRibbon();
9097

0 commit comments

Comments
 (0)