Skip to content

Commit 20b3704

Browse files
tduguidtduguid
authored andcommitted
Added time format button
1 parent 6c7a45a commit 20b3704

File tree

14 files changed

+216
-106
lines changed

14 files changed

+216
-106
lines changed

CS/Properties/Settings.Designer.cs

Lines changed: 19 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

CS/Properties/Settings.settings

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@
1414
<Setting Name="Column_TypeDate" Type="System.Int32" Scope="User">
1515
<Value Profile="(Default)">2</Value>
1616
</Setting>
17-
<Setting Name="Table_ColumnDateFormatReplace" Type="System.String" Scope="User">
17+
<Setting Name="Table_ColumnFormatDateReplace" Type="System.String" Scope="User">
1818
<Value Profile="(Default)">dd-mmm-yyyy</Value>
1919
</Setting>
20-
<Setting Name="Table_ColumnDateFormatFind" Type="System.String" Scope="User">
20+
<Setting Name="Table_ColumnFormatDateFind" Type="System.String" Scope="User">
2121
<Value Profile="(Default)">mm:ss.0</Value>
2222
</Setting>
2323
<Setting Name="Table_ColumnScriptNull" Type="System.String" Scope="User">
@@ -66,7 +66,7 @@
6666
<Value Profile="(Default)">True</Value>
6767
</Setting>
6868
<Setting Name="Table_ColumnSeparateValuesDelimiter" Type="System.Char" Scope="User">
69-
<Value Profile="(Default)">,</Value>
69+
<Value Profile="(Default)">;</Value>
7070
</Setting>
7171
<Setting Name="App_PathDeploy" Type="System.String" Scope="User">
7272
<Value Profile="(Default)">https://raw.githubusercontent.com/Office-projects/ScriptHelp/master/publish/</Value>
@@ -104,5 +104,8 @@
104104
<Setting Name="App_PathNewIssue" Type="System.String" Scope="User">
105105
<Value Profile="(Default)">https://github.com/Office-projects/ScriptHelp/issues/new</Value>
106106
</Setting>
107+
<Setting Name="Table_ColumnFormatTime" Type="System.String" Scope="User">
108+
<Value Profile="(Default)">h:mm:ss AM/PM</Value>
109+
</Setting>
107110
</Settings>
108111
</SettingsFile>

CS/Ribbon.xml

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,12 +112,23 @@ Or use the following tag to remove all other ribbons when this loads
112112
label="Format Date Columns"
113113
onAction="OnAction"
114114
getEnabled="GetEnabled"
115-
imageMso="DateAndTimeInsert"
115+
imageMso="NewAppointment"
116116
size="large"
117117
screentip="Format Date Columns"
118-
supertip="Update the default date format of the cell"
118+
supertip="Update the default date format of any column that has a date without a zero string value"
119119
keytip="DTE"
120120
/>
121+
<button
122+
id="btnFormatTimeColumns"
123+
label="Format Time Columns"
124+
onAction="OnAction"
125+
getEnabled="GetEnabled"
126+
imageMso="DateAndTimeInsert"
127+
size="large"
128+
screentip="Format Time Columns"
129+
supertip="Update the default time format of the selected column"
130+
keytip="TIM"
131+
/>
121132
<button
122133
id="btnClearInteriorColor"
123134
label="Clear Interior Color"

CS/Scripts/Data.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ public static void InsertRecord(DataTable tbl, string text)
213213
{
214214
string tableName = tbl.TableName.ToString();
215215
string columnName = tbl.Columns[0].ColumnName.ToString();
216-
string sql = "SELECT * FROM " + tableName + " ORDER BY " + columnName;
216+
string sql = "SELECT * FROM " + tableName; //+ " ORDER BY " + columnName;
217217
if (tbl.Select(columnName + " = '" + text.Replace("'", "''") + "'").Length == 0)
218218
{
219219
DialogResult dr = MessageBox.Show("Would you like to add '" + text + "' to the list?", "Add New Value", MessageBoxButtons.YesNo, MessageBoxIcon.Question);

CS/Scripts/ErrorHandler.cs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,5 +313,30 @@ public static bool IsDate(object expression)
313313
return false;
314314
}
315315

316+
/// <summary>
317+
/// Check if the object is a time
318+
/// </summary>
319+
/// <param name="expression">Represents the cell value </param>
320+
/// <returns>A method that returns true or false if there is a valid time </returns>
321+
/// <remarks></remarks>
322+
public static bool IsTime(object expression)
323+
{
324+
try
325+
{
326+
string timeValue = Convert.ToString(expression);
327+
//timeValue = String.Format("{0:" + Properties.Settings.Default.Table_ColumnFormatTime + "}", expression);
328+
//timeValue = timeValue.ToString(Properties.Settings.Default.Table_ColumnFormatTime, System.Globalization.CultureInfo.InvariantCulture);
329+
//timeValue = timeValue.ToString(Properties.Settings.Default.Table_ColumnFormatTime);
330+
//string timeValue = expression.ToString().Format(Properties.Settings.Default.Table_ColumnFormatTime);
331+
TimeSpan time1;
332+
//return TimeSpan.TryParse((string)expression, out time1);
333+
return TimeSpan.TryParse(timeValue, out time1);
334+
}
335+
catch (Exception)
336+
{
337+
return false;
338+
}
339+
}
340+
316341
}
317342
}

CS/Scripts/Formula.cs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ public static void DqlAppend()
104104
}
105105
if (Ribbon.GetSqlDataType(col) == Properties.Settings.Default.Column_TypeDate)
106106
{
107-
formula += valuePrefix + "\"DATE(" + qt + "\" & " + colRef + " & \"" + qt + ", " + qt + Properties.Settings.Default.Table_ColumnDateFormatReplace + qt + ")\"";
107+
formula += valuePrefix + "\"DATE(" + qt + "\" & " + colRef + " & \"" + qt + ", " + qt + Properties.Settings.Default.Table_ColumnFormatDateReplace + qt + ")\"";
108108
}
109109
else
110110
{
@@ -113,7 +113,7 @@ public static void DqlAppend()
113113
}
114114
}
115115
//replace NULL values with DQL format
116-
formula = "SUBSTITUTE(" + formula + ", \"'" + Properties.Settings.Default.Table_ColumnScriptNull + "', '" + Properties.Settings.Default.Table_ColumnDateFormatReplace + "'\", \"'nulldate'\")";
116+
formula = "SUBSTITUTE(" + formula + ", \"'" + Properties.Settings.Default.Table_ColumnScriptNull + "', '" + Properties.Settings.Default.Table_ColumnFormatDateReplace + "'\", \"'nulldate'\")";
117117
formula = "SUBSTITUTE(" + formula + ", \"'" + Properties.Settings.Default.Table_ColumnScriptNull + "'\", \"nullstring\")";
118118
formula = "SUBSTITUTE(" + formula + ", \"" + Properties.Settings.Default.Table_ColumnScriptNull + "\", \"nullint\")";
119119

@@ -255,10 +255,10 @@ public static void DqlAppendLocked()
255255
{
256256
if (afterWhere == true)
257257
{
258-
whereClause += valuePrefix + "\"DATE(" + qt + "\" & " + colRef + " & \"" + qt + ", " + qt + Properties.Settings.Default.Table_ColumnDateFormatReplace + qt + ")\"";
258+
whereClause += valuePrefix + "\"DATE(" + qt + "\" & " + colRef + " & \"" + qt + ", " + qt + Properties.Settings.Default.Table_ColumnFormatDateReplace + qt + ")\"";
259259

260260
}
261-
formula += valuePrefix + "\"DATE(" + qt + "\" & " + colRef + " & \"" + qt + ", " + qt + Properties.Settings.Default.Table_ColumnDateFormatReplace + qt + ")\"";
261+
formula += valuePrefix + "\"DATE(" + qt + "\" & " + colRef + " & \"" + qt + ", " + qt + Properties.Settings.Default.Table_ColumnFormatDateReplace + qt + ")\"";
262262
}
263263
else
264264
{
@@ -271,7 +271,7 @@ public static void DqlAppendLocked()
271271
}
272272
}
273273
//replace NULL values with DQL format
274-
formula = "SUBSTITUTE(" + formula + ", \"'" + Properties.Settings.Default.Table_ColumnScriptNull + "', '" + Properties.Settings.Default.Table_ColumnDateFormatReplace + "'\", \"'nulldate'\")";
274+
formula = "SUBSTITUTE(" + formula + ", \"'" + Properties.Settings.Default.Table_ColumnScriptNull + "', '" + Properties.Settings.Default.Table_ColumnFormatDateReplace + "'\", \"'nulldate'\")";
275275
formula = "SUBSTITUTE(" + formula + ", \"'" + Properties.Settings.Default.Table_ColumnScriptNull + "'\", \"nullstring\")";
276276
formula = "SUBSTITUTE(" + formula + ", \"" + Properties.Settings.Default.Table_ColumnScriptNull + "\", \"nullint\")";
277277

@@ -390,7 +390,7 @@ public static void DqlCreate()
390390
valuePrefix = "\" SET " + col.Name + " = \" & ";
391391
if (Ribbon.GetSqlDataType(col) == Properties.Settings.Default.Column_TypeDate)
392392
{
393-
formula += valuePrefix + "\"DATE(" + qt + "\" & " + colRef + " & \"" + qt + ", " + qt + Properties.Settings.Default.Table_ColumnDateFormatReplace + qt + ")\"";
393+
formula += valuePrefix + "\"DATE(" + qt + "\" & " + colRef + " & \"" + qt + ", " + qt + Properties.Settings.Default.Table_ColumnFormatDateReplace + qt + ")\"";
394394
}
395395
else
396396
{
@@ -399,7 +399,7 @@ public static void DqlCreate()
399399
}
400400
}
401401
//replace NULL values with DQL format
402-
formula = "SUBSTITUTE(" + formula + ", \"'" + Properties.Settings.Default.Table_ColumnScriptNull + "', '" + Properties.Settings.Default.Table_ColumnDateFormatReplace + "'\", \"'nulldate'\")";
402+
formula = "SUBSTITUTE(" + formula + ", \"'" + Properties.Settings.Default.Table_ColumnScriptNull + "', '" + Properties.Settings.Default.Table_ColumnFormatDateReplace + "'\", \"'nulldate'\")";
403403
formula = "SUBSTITUTE(" + formula + ", \"'" + Properties.Settings.Default.Table_ColumnScriptNull + "'\", \"nullstring\")";
404404
formula = "SUBSTITUTE(" + formula + ", \"" + Properties.Settings.Default.Table_ColumnScriptNull + "\", \"nullint\")";
405405

@@ -533,7 +533,7 @@ public static void DqlTruncateAppend()
533533
}
534534
if (Ribbon.GetSqlDataType(col) == Properties.Settings.Default.Column_TypeDate)
535535
{
536-
formula += valuePrefix + "\"DATE(" + qt + "\" & " + colRef + " & \"" + qt + ", " + qt + Properties.Settings.Default.Table_ColumnDateFormatReplace + qt + ")\"";
536+
formula += valuePrefix + "\"DATE(" + qt + "\" & " + colRef + " & \"" + qt + ", " + qt + Properties.Settings.Default.Table_ColumnFormatDateReplace + qt + ")\"";
537537
}
538538
else
539539
{
@@ -542,7 +542,7 @@ public static void DqlTruncateAppend()
542542
}
543543
}
544544
//replace NULL values with DQL format
545-
formula = "SUBSTITUTE(" + formula + ", \"'" + Properties.Settings.Default.Table_ColumnScriptNull + "', '" + Properties.Settings.Default.Table_ColumnDateFormatReplace + "'\", \"'nulldate'\")";
545+
formula = "SUBSTITUTE(" + formula + ", \"'" + Properties.Settings.Default.Table_ColumnScriptNull + "', '" + Properties.Settings.Default.Table_ColumnFormatDateReplace + "'\", \"'nulldate'\")";
546546
formula = "SUBSTITUTE(" + formula + ", \"'" + Properties.Settings.Default.Table_ColumnScriptNull + "'\", \"nullstring\")";
547547
formula = "SUBSTITUTE(" + formula + ", \"" + Properties.Settings.Default.Table_ColumnScriptNull + "\", \"nullint\")";
548548

@@ -678,7 +678,7 @@ public static void DqlUpdate()
678678
}
679679
if (Ribbon.GetSqlDataType(col) == Properties.Settings.Default.Column_TypeDate)
680680
{
681-
formula += valuePrefix + "\"DATE(" + qt + "\" & " + colRef + " & \"" + qt + ", " + qt + Properties.Settings.Default.Table_ColumnDateFormatReplace + qt + ")\"";
681+
formula += valuePrefix + "\"DATE(" + qt + "\" & " + colRef + " & \"" + qt + ", " + qt + Properties.Settings.Default.Table_ColumnFormatDateReplace + qt + ")\"";
682682
}
683683
else
684684
{
@@ -687,7 +687,7 @@ public static void DqlUpdate()
687687
}
688688
}
689689
//replace NULL values with DQL format
690-
formula = "SUBSTITUTE(" + formula + ", \"'" + Properties.Settings.Default.Table_ColumnScriptNull + "', '" + Properties.Settings.Default.Table_ColumnDateFormatReplace + "'\", \"'nulldate'\")";
690+
formula = "SUBSTITUTE(" + formula + ", \"'" + Properties.Settings.Default.Table_ColumnScriptNull + "', '" + Properties.Settings.Default.Table_ColumnFormatDateReplace + "'\", \"'nulldate'\")";
691691
formula = "SUBSTITUTE(" + formula + ", \"'" + Properties.Settings.Default.Table_ColumnScriptNull + "'\", \"nullstring\")";
692692
formula = "SUBSTITUTE(" + formula + ", \"" + Properties.Settings.Default.Table_ColumnScriptNull + "\", \"nullint\")";
693693

@@ -829,10 +829,10 @@ public static void DqlUpdateLocked()
829829
{
830830
if (afterWhere == true)
831831
{
832-
whereClause += valuePrefix + "\"DATE(" + qt + "\" & " + colRef + " & \"" + qt + ", " + qt + Properties.Settings.Default.Table_ColumnDateFormatReplace + qt + ")\"";
832+
whereClause += valuePrefix + "\"DATE(" + qt + "\" & " + colRef + " & \"" + qt + ", " + qt + Properties.Settings.Default.Table_ColumnFormatDateReplace + qt + ")\"";
833833

834834
}
835-
formula += valuePrefix + "\"DATE(" + qt + "\" & " + colRef + " & \"" + qt + ", " + qt + Properties.Settings.Default.Table_ColumnDateFormatReplace + qt + ")\"";
835+
formula += valuePrefix + "\"DATE(" + qt + "\" & " + colRef + " & \"" + qt + ", " + qt + Properties.Settings.Default.Table_ColumnFormatDateReplace + qt + ")\"";
836836
}
837837
else
838838
{
@@ -845,7 +845,7 @@ public static void DqlUpdateLocked()
845845
}
846846
}
847847
//replace NULL values with DQL format
848-
formula = "SUBSTITUTE(" + formula + ", \"'" + Properties.Settings.Default.Table_ColumnScriptNull + "', '" + Properties.Settings.Default.Table_ColumnDateFormatReplace + "'\", \"'nulldate'\")";
848+
formula = "SUBSTITUTE(" + formula + ", \"'" + Properties.Settings.Default.Table_ColumnScriptNull + "', '" + Properties.Settings.Default.Table_ColumnFormatDateReplace + "'\", \"'nulldate'\")";
849849
formula = "SUBSTITUTE(" + formula + ", \"'" + Properties.Settings.Default.Table_ColumnScriptNull + "'\", \"nullstring\")";
850850
formula = "SUBSTITUTE(" + formula + ", \"" + Properties.Settings.Default.Table_ColumnScriptNull + "\", \"nullint\")";
851851

@@ -1724,7 +1724,7 @@ public static void PlSqlUpdateValues()
17241724
}
17251725
if (Ribbon.GetSqlDataType(col) == Properties.Settings.Default.Column_TypeDate)
17261726
{
1727-
formula += valuePrefix + "\"DATE(" + qt + "\" & " + colRef + " & \"" + qt + ", " + qt + Properties.Settings.Default.Table_ColumnDateFormatReplace + qt + ")\"";
1727+
formula += valuePrefix + "\"DATE(" + qt + "\" & " + colRef + " & \"" + qt + ", " + qt + Properties.Settings.Default.Table_ColumnFormatDateReplace + qt + ")\"";
17281728
}
17291729
else
17301730
{
@@ -2403,7 +2403,7 @@ public static void TSqlUpdateValues()
24032403
}
24042404
if (Ribbon.GetSqlDataType(col) == Properties.Settings.Default.Column_TypeDate)
24052405
{
2406-
formula += valuePrefix + "\"DATE(" + qt + "\" & " + colRef + " & \"" + qt + ", " + qt + Properties.Settings.Default.Table_ColumnDateFormatReplace + qt + ")\"";
2406+
formula += valuePrefix + "\"DATE(" + qt + "\" & " + colRef + " & \"" + qt + ", " + qt + Properties.Settings.Default.Table_ColumnFormatDateReplace + qt + ")\"";
24072407
}
24082408
else
24092409
{

0 commit comments

Comments
 (0)