CodeKeep C# Feed Luglio 28th, 2008
Description: test
Link:
http://www.codekeep.net/snippets/7c0eba81-d87e-40ef-8b79-e906edee99dd.aspxpublic long GetRegisteredUserCount(int countryId)
{
string sql = "select count(*) Ret from [user] u inner join UserWidget on u.id = userwidget.userid where u.CountryId = :country";
ISQLQuery query = NHibernateSession.CreateSQLQuery(sql);
query.SetInt32("country", countryId);
query.AddScalar("Ret", NHibernateUtil.Int64);
object result = query.UniqueResult();
return result == null ? 0 : Convert.ToInt64(result);
}
CodeKeep C# Feed Luglio 28th, 2008
Description: Access the call stack window content
Link:
http://www.codekeep.net/snippets/1809f49c-c6a1-47ef-8c4a-6bc8e1a8faca.aspxview plaincopy to clipboardprint?
// First create an instance of the call stack
StackTrace callStack = new StackTrace();
// Next select the frame we want...
// 0 : current frame for the current method
// 1 : Frame that called the current method
// 2 : Frame that called the frame that called the current method
// 3 : ...you get the idea!
StackFrame frame = callStack.GetFrame(1);
// Using StackFrame.GetMethod(), which returns a
// MethodBase object, we can obtain detailed
// information about about a method
MethodBase method = frame.GetMethod();
// Get the declaring type and method names
string declaringType = method.DeclaringType.Name;
string methodName = method.Name;
source : http://neilkilbride.blogspot.com/2008/04/how-to-access-call-stack-c.html
WebReference News Luglio 27th, 2008
This week we continue to add functionality and tweak the appearance of our control by implementing search string matching in the list items and by adding a CSS drop shadow effect. By Rob Gravelle. 0918
CodeKeep C# Feed Luglio 25th, 2008
Description: the first column the next 30 days in the year including the current day
the second column is for description information. I didn't write this, i'm storing it here because of how useful it was for me
Link:
http://www.codekeep.net/snippets/50dab7bd-c16b-4683-a258-46e11247c6c0.aspx DateTime _date;
int n = 0;
int max = 30;
while (n < max)
{
_date = DateTime.Now.AddDays(n);
//listView1.Items.AddRange(
ListViewItem item = new ListViewItem(_date.ToShortDateString());
item.SubItems.Add("Description " + n);
listevent.Items.Add(item);
n++;
CodeKeep C# Feed Luglio 25th, 2008
Description: This class contains methods for checking if a form is active or not.
Link:
http://www.codekeep.net/snippets/ec1a8392-a47f-4c2e-9492-29facfb33459.aspx public class Forms
{
#region ~VERSION HISTORY
/*==================================================================
DATE CREATED: 05.12.2004
CREATED BY: ERIC RITZIE
NOTES:
HISTORY:
05.12.2004 ER INITIAL CREATION
==================================================================*/
#endregion
#region CONTRUCTORS
public Forms()
{
//
// TODO: Add constructor logic here
//
}
#endregion
#region DECONSTRUCTORS
// Implement IDisposable.
// Do not make this method virtual.
// A derived class should not be able to override this method.
public void Dispose()
{
Dispose(true);
// Take yourself off the Finalization queue to prevent finalization code for the object
// from executing a second time.
GC.SuppressFinalize(this);
}
// Dispose (bool disposing) executes in two distinct scenarios.
// If disposing equals true, the method has been called directly or indirectly by a user's code.
// Managed and unmanaged resources can be disposed.
// If disposing equals false, the method has been called by the runtime from inside the
// finalizer and you should not reference other objects. Only unmanaged resources can be disposed.
protected virtual void Dispose(bool disposing)
{
// Check to see if Dispose has already been called.
if (!this.disposed)
{
// If disposing equals true, dispose all managed and unmanaged resources.
if (disposing)
{
// Dispose managed resources.
//Components.Dispose();
}
// Release unmanaged resources. If disposing is false, only the following code is executed.
//CloseHandle(handle);
//handle = IntPtr.Zero;
// Note that this is not thread safe.
// Another thread could start disposing the object after the managed resources are disposed,
// but before the disposed flag is set to true.
// If thread safety is necessary, it must be implented by the client.
}
this.disposed = true;
}
// Use C# destructor syntax for finalization code.
// This destructor will run only if the Dispose method does not get called.
// It gives your code class the opportunity to finalize.
// Do not provide destructors in type derived from this class.
~Forms()
{
// Do not re-create Dispose clean-up code here.
// Calling Dispose(false) is optimal in terms of readability and maintainability.
Dispose(false);
}
#endregion
#region PRIVATE VARIABLES
private bool disposed = false;
#endregion
#region PUBLIC METHODS
public bool IsFormActive(Form f)
{
bool Status = false;
//* Check if Form is already open, if so then bring it to the front
if ((f != null) && (f != _Main.ActiveMdiChild))
{
f.Activate();
Status = true;
}
return Status;
}
public bool IsChildFormActive(string Title)
{
bool Status = false;
foreach (Form child in _Main.MdiChildren)
{
if (child.Text == Title)
{
child.Activate();
Status = true;
break;
}
}
return Status;
}
public bool IsChildFormActive(object Tag)
{
bool Status = false;
foreach (Form child in _Main.MdiChildren)
{
if (child.Tag.ToString() == Tag.ToString())
{
child.Activate();
Status = true;
break;
}
}
return Status;
}
public bool IsChildFormActive(string Title, object Tag)
{
bool Status = false;
foreach (Form child in _Main.MdiChildren)
{
if (child.Text == Title)
{
if (child.Tag.ToString() == Tag.ToString())
{
child.Activate();
Status = true;
break;
}
}
}
return Status;
}
#endregion
}
CodeKeep C# Feed Luglio 25th, 2008
Description: GetCurrentMethodName
Link:
http://www.codekeep.net/snippets/f10c7959-cf16-47f3-921f-cf26bdfca643.aspxStackTrace stk = new StackTrace();
StackFrame stf = stk.GetFrame(0);
string methodName = stf.GetMethod().Name;
WebReference News Luglio 25th, 2008
If you're looking to upgrade to a larger hard drive, add an external hard drive, CD drive or give additional life to a switched-out drive, this system is as simple as it gets. By Lee Underwood. 0916.
CodeKeep C# Feed Luglio 25th, 2008
Description: this is a genric evalutor based in Microsfot Jscript
Link:
http://www.codekeep.net/snippets/13c05ab9-1a8f-4cb3-928d-bccd20f781af.aspxusing System;
using System.CodeDom.Compiler;
using System.Reflection;
using System.Collections;
using Microsoft.JScript;
using System.Text.RegularExpressions;
namespace REISys.BHCMIS.UDS.Utilities
{
public class Evaluator
{
public static int EvalToInteger(string statement)
{
string s = EvalToString(statement);
return int.Parse(s.ToString());
}
public static double ComputeResult(string expression,Hashtable Values)
{
string newExpression = expression;
string[] strarray = Regex.Split(expression, @"[\+\-\%\*()\[\]\{\}]");
foreach (string str in strarray)
{
if (str != "")
{
newExpression = newExpression.Replace(str, Values[str].ToString());
}
}
return EvalToDouble(newExpression);
}
public static double EvalToDouble(string statement)
{
string s = EvalToString(statement);
return double.Parse(s);
}
public static string EvalToString(string statement)
{
object o = EvalToObject(statement);
return o.ToString();
}
public static object EvalToObject(string statement)
{
return _evaluatorType.InvokeMember(
"Eval",
BindingFlags.InvokeMethod,
null,
_evaluator,
new object[] { statement }
);
}
static Evaluator()
{
ICodeCompiler compiler;
compiler = new JScriptCodeProvider().CreateCompiler();
CompilerParameters parameters;
parameters = new CompilerParameters();
parameters.GenerateInMemory = true;
CompilerResults results;
results = compiler.CompileAssemblyFromSource(parameters, _jscriptSource);
Assembly assembly = results.CompiledAssembly;
_evaluatorType = assembly.GetType("Evaluator.Evaluator");
_evaluator = Activator.CreateInstance(_evaluatorType);
}
private static object _evaluator = null;
private static Type _evaluatorType = null;
private static readonly string _jscriptSource =
@"package Evaluator
{
class Evaluator
{
public function Eval(expr : String) : String
{
return eval(expr);
}
}
}";
}
}
CodeKeep C# Feed Luglio 24th, 2008
Description: Parse a string for firstname, middleinitial and lastname
Link:
http://www.codekeep.net/snippets/a57fa506-0afe-4b60-8033-3589eb776315.aspx /// <summary>
/// Parses the full name.
/// </summary>
/// <param name="FullName">The full name.</param>
/// <param name="_firstName">Name of the _first.</param>
/// <param name="_middleInitial">The _middle initial.</param>
/// <param name="_lastName">Name of the _last.</param>
public static void ParseFullName(string FullName, out string _firstName, out string _middleInitial, out string _lastName)
{
_firstName = "";
_middleInitial = "";
_lastName = "";
string[] parts = new string[] { };
string[] seperators = new string[1] { " " };
parts = FullName.Split(seperators, StringSplitOptions.RemoveEmptyEntries);
switch (parts.Length)
{
case 1:
{
// OPTIONS
//
// 0=firstname
//
_firstName = parts[0]; // 0=firstname
break;
}
case 2:
{
// OPTIONS:
//
// option1: 0=salutation, 1=lastname
// option2: 0=firstname, 1=lastname
//
if (parts[0].EndsWith(".")) // option2
{
try
{
//TODO: parse salutation // 0=salutation
}
catch
{
_firstName = parts[0]; // 0=firstname
}
_lastName = parts[1]; // 1=lastname
}
else // option2
{
_firstName = parts[0]; // 0=firstname
_lastName = parts[1]; // 1=lastname
}
break;
}
case 3:
{
// OPTIONS:
//
// option1: 0=salutation, 1=firstname, 2=lastname
// option2: 0=firstname, 1=middle, 2=lastname
// option3: 0=firstname, 1=lastname, 3=namesuffix
//
if (parts[0].EndsWith("."))
{
//TODO: parse salutation // 0=salutation
_firstName = parts[1]; // 1=firstname
_lastName = parts[2]; // 2=lastname
}
else
{
_firstName = parts[0]; // 0=firstname
if (parts[1].EndsWith(".") | parts[1].Length == 1)
{
_middleInitial = parts[1].Substring(0, 1).ToUpper(); // 1=middle
_lastName = parts[2]; // 2=lastname
}
else
{
if (parts[3].EndsWith(".") | parts[1].Length == 1)
{
_firstName = parts[0]; // 0=firstname
_lastName = parts[1]; // 1=lastname
//TODO: parse namesuffix // 3=namesuffix
}
}
}
break;
}
case 4:
{
// OPTIONS:
//
// option1: 0=salutation, 1=firstname, 2=lastname, 3=namesuffix
// option2: 0=salutation, 1=firstname, 2=middle, 3=lastname
// option3: 0=firstname, 1=middle, 2=lastname, 3=namesuffix
//
if (parts[0].EndsWith(".")) //option1
{
//TODO: parse salutation // 0=salutation
_firstName = parts[1]; // 1=firstname
if (parts[2].EndsWith(".")) //option2
{
_middleInitial = parts[2].Substring(0, 1).ToUpper(); // 2=middleinitial
_lastName = parts[3]; // 3=lastname
}
else //option1
{
_lastName = parts[2]; // 2=lastname
//TODO: parse namesuffix // 3=namesuffix
}
}
else //option3
{
_firstName = parts[0]; // 0=firstname
_middleInitial = parts[1].Substring(0, 1).ToUpper(); // 1=middle
_lastName = parts[2]; // 2=lastname
//TODO: parse namesuffix // 3=namesuffix
}
break;
}
}
}
WebReference News Luglio 23rd, 2008
This week we look at how to add a vertical scrollbar to the list. We're also going to use a parameter to set the list size, so a vertical scrollbar will appear when the number of items exceeds it. By Rob Gravelle. 0605