Skip to content

Instantly share code, notes, and snippets.

@thorsman99
thorsman99 / alert_from_code_behind.cs
Last active March 8, 2017 13:30
C# alert from code behind #C#
Response.Write("<script>alert('Hello');</script>");
@thorsman99
thorsman99 / asp_table_example.cs
Last active March 8, 2017 13:29
ASP.NET Table Example #C#
protected void MakeQuarantineList(String strClientID)
{
// get a list of batches that are quarantined for the current client.
// client dropdown too.... as this is admin level? for Now only the current
pnlQuarantineList.Visible = true;
pnlEditBatch.Visible = false;
pnlBatchImportRows.Visible = false;
pnlBatchImages.Visible = false;
@thorsman99
thorsman99 / Checkbox_in_Repeater.cs
Created March 8, 2017 13:42
ASP.NET Example of checkbox in Repeater #C#
protected void chkSelectAll_Clicked(Object sender, EventArgs e)
{
//Response.Write("<script>alert('Test')</script>");
CheckBox chkSelectAll = (CheckBox)sender;
foreach (RepeaterItem i in rptUserSelectView.Items)
{
CheckBox chkSelect = (CheckBox)i.FindControl("chkSelect");
chkSelect.Checked = chkSelectAll.Checked;
}
@thorsman99
thorsman99 / Copy_Directory.cs
Last active March 8, 2017 13:43
C# directory copying function #C#
private static void DirectoryCopy(string sourceDirName, string destDirName, bool copySubDirs)
{
// Get the subdirectories for the specified directory.
DirectoryInfo dir = new DirectoryInfo(sourceDirName);
DirectoryInfo[] dirs = dir.GetDirectories();
if (!dir.Exists)
{
throw new DirectoryNotFoundException(
"Source directory does not exist or could not be found: "
@thorsman99
thorsman99 / Email_Send_Example.cs
Last active March 8, 2017 13:49
C# composing and sending email from #C#
private static bool CreateBelowMinEmails()
{
SqlConnection objConn = null;
SqlConnection objConn2 = null;
SqlDataReader drData = null;
SqlCommand objComm = null;
SqlCommand objComm2 = null;
string strEmail = "", strName = "", strUserID = "", strHeader = "", strBody = "", strFooter = "";
string strMsg = "", strColor = "f5f5f5", strTemp = "", strNotificationSQL = "";
string strPrevEmail = "", strPrevUserID = "", strPrevName = "";
@thorsman99
thorsman99 / Find_Control_Recursive.cs
Created March 8, 2017 13:48
C# recursive function for finding a control by ID #C#
public static Control FindControlRecursive(string controlId, Control parent)
{
foreach (Control control in parent.Controls)
{
Control result = FindControlRecursive(controlId, control);
if (result != null)
{
return result;
}
}
@thorsman99
thorsman99 / First_Last_Day_of_month_functions.cs
Created March 8, 2017 13:51
C# Functions for finding first or last day of the month given a datetime #C#
public DateTime FirstDayOfMonthFromDateTime(DateTime dateTime)
{
return new DateTime(dateTime.Year, dateTime.Month, 1);
}
public DateTime LastDayOfMonthFromDateTime(DateTime dateTime)
{
DateTime firstDayOfTheMonth = new DateTime(dateTime.Year, dateTime.Month, 1);
return firstDayOfTheMonth.AddMonths(1).AddDays(-1);
}
@thorsman99
thorsman99 / function_ExecNonQuery.cs
Last active June 10, 2021 13:12
C# execute a non-query SQL command with a dictionary of parameters #C#
/// <summary>
/// Executes a non query SQL command with a Dictionary Object of Parameters
/// </summary>
/// <param name="strSQL"></param>
/// <param name="colParams"></param>
/// <returns></returns>
private void ExecuteNonQuery(string strSQL, Dictionary<string, string> dctParams)
{
try
{
@thorsman99
thorsman99 / function_GetDataTable.cs
Last active March 8, 2017 14:05
C# function returns a data table from a SQL query with a dictionary of parameters #C#
/// <summary>
/// Returns a DataTable for a SQL Query with a Dictionary Object of Parameters
/// </summary>
/// <param name="strSQL"></param>
/// <param name="colParams"></param>
/// <returns></returns>
private DataTable GetDataTable(string strSQL, Dictionary<string,string> colParams)
{
DataTable dt = null;
@thorsman99
thorsman99 / Number_is_Prime.cs
Last active March 8, 2017 14:06
C# function for determiming if a number is prime #C#
bool p(int n)
{
if (n == 1 || n % 2 == 0) return false;
if (n == 2) return true;
var b = (int)Math.Floor(Math.Sqrt(n));
int i = 3;
while (i <= b)
{