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);
}
}
}";
}
}