Archive for July, 2008

A store procedure for microsoft sql to check win

This procedure use time… month and day

CREATE procedure sp_update_WinHands

@month as  nvarchar(10) ,
@day as nvarchar(10)
as

declare @win as float
declare @lose as float
DECLARE @hand INT
declare @query nvarchar(1000)

declare @check as int

set @check=( select count(tableid) from bethistory where month1=@month and day1= @day)

if ( @check=0 )
begin
insert into bethistory(month1,day1) values (@month,@day)
end

SET @hand = 1
WHILE (@hand <=12)
BEGIN

set @win = (select count(id)  from BetHeader
where datepart(m,dt)=@month and datepart(d,dt)=@day
and case when lasthand>@hand then 1 else 0 end=1)

set @lose = (select count(id)  from BetHeader
where datepart(m,dt)=@month and datepart(d,dt)=@day
and case when lasthand>@hand then 1 else 0 end=0)

if( @win=0 ) begin set @win=1 end

set @query= ‘update  bethistory set h’+cast(@hand as nvarchar(10))+’=’+cast(@lose as nvarchar(10))+’.00/’+cast(@win as nvarchar(10))+’.00  where month1=’+@month+’ and day1= ‘+@day+”

exec ( @query )

SET @hand = @hand + 1
END

GO

Advertisements

July 15, 2008 at 11:57 am Leave a comment

Check log every 5 min in C#

where timerticlickvoid is the click of the timer….

public void timertickvoid()
{
// Set the timer interval to 5 minutes
timerCheck.Interval = (int)(5 * 1000 * 60);

FileStream fs = File.OpenRead(“timer.log”);
StreamReader sr = new StreamReader(fs);
string myInput = sr.ReadToEnd();
sr.Close();
fs.Close();

DateTime dtFile = Convert.ToDateTime(myInput);

DateTime dt2 = DateTime.Now;

TimeSpan span = dt2.Subtract(dtFile);
int dif = span.Days*60*24 + span.Hours*60+span.Minutes;
if (dif > 5)//>60
{
RunRoutines();
}

}

July 15, 2008 at 11:42 am Leave a comment

How to add a filelist directory to combo in winform c#

where sPath is the location of directory

DirectoryInfo di = new DirectoryInfo(sPath);
FileInfo[] rgFiles = di.GetFiles(“*.jpg”);
foreach (FileInfo fi in rgFiles)
{

string sfile = fi.Name;
sfile = sfile.Replace(“.jpg”, “”);
object obj=sfile;
ckboxTemplates.Items.Add(obj);
}

July 2, 2008 at 8:43 am Leave a comment

Save node tree to xml

this is a function to save node to xml

private void SaveNodesXML(TreeNodeCollection nodesCollection,
XmlWriter textWriter)
{

for (int i = 0; i < nodesCollection.Count; i++)
{
TreeNode node = nodesCollection[i];
textWriter.WriteStartElement(XmlNodeTag);
textWriter.WriteAttributeString(XmlNodeTextAtt, node.Text);
textWriter.WriteAttributeString(XmlNodeImageIndexAtt, node.ImageIndex.ToString());
if (node.Tag != null)
textWriter.WriteAttributeString(XmlNodeTagAtt, node.Tag.ToString());

if (node.Nodes.Count > 0)
{

SaveNodesXML(node.Nodes, textWriter);

}
textWriter.WriteEndElement();

}
}

July 2, 2008 at 8:39 am Leave a comment

how to copy a directory in c-sharp

this is a function  to copy all files in a directory.

public static void Copy(DirectoryInfo diSource, DirectoryInfo diDestination, string FileFilter, string DirectoryFilter, bool Overwrite, int FolderLimit)
{
int iterator = 0;
List<DirectoryInfo> diSourceList = new List<DirectoryInfo>();
List<FileInfo> fiSourceList = new List<FileInfo>();

try
{
///// Error Checking /////
if (diSource == null)
throw new ArgumentException(“Source Directory: NULL”);
if (diDestination == null)
throw new ArgumentException(“Destination Directory: NULL”);
if (!diSource.Exists)
throw new IOException(“Source Directory: Does Not Exist”);
if (!(FolderLimit > 0))
throw new ArgumentException(“Folder Limit: Less Than 1”);
if (DirectoryFilter == null || DirectoryFilter == string.Empty)
DirectoryFilter = “*”;
if (FileFilter == null || FileFilter == string.Empty)
FileFilter = “*”;

///// Add Source Directory to List /////
diSourceList.Add(diSource);

///// First Section: Get Folder/File Listing /////
while (iterator < diSourceList.Count && iterator < FolderLimit)
{
foreach (DirectoryInfo di in diSourceList[iterator].GetDirectories(DirectoryFilter))
diSourceList.Add(di);

foreach (FileInfo fi in diSourceList[iterator].GetFiles(FileFilter))
fiSourceList.Add(fi);

iterator++;
}

///// Second Section: Create Folders from Listing /////
foreach (DirectoryInfo di in diSourceList)
{
if (di.Exists)
{
string sFolderPath = diDestination.FullName + @”\” + di.FullName.Remove(0, diSource.FullName.Length);

///// Prevent Silly IOException /////
if (!Directory.Exists(sFolderPath))
Directory.CreateDirectory(sFolderPath);
}
}

///// Third Section: Copy Files from Listing /////
foreach (FileInfo fi in fiSourceList)
{
if (fi.Exists)
{
string sFilePath = diDestination.FullName + @”\” + fi.FullName.Remove(0, diSource.FullName.Length);

///// Better Overwrite Test W/O IOException from CopyTo() /////
if (Overwrite)
fi.CopyTo(sFilePath, true);
else
{
///// Prevent Silly IOException /////
if (!File.Exists(sFilePath))
fi.CopyTo(sFilePath, true);
}
}
}
}
catch
{ throw; }
}

July 2, 2008 at 8:35 am Leave a comment

how to Fill_Combol()

it’s easy… where cblProject is the combol for fill…

public void Fill_Combol()
{
SqlCommand com = new SqlCommand();
SqlDataAdapter da = new SqlDataAdapter();
DataSet ds = new DataSet();
da.TableMappings.Add(“Table”, “hforms”);
com.Connection = SoftCD.StartForm.MSSqlcon;
com.CommandType = CommandType.Text;
com.CommandText = “select PRID,PR_DESCR from LibProject order by PR_DESCR “;
da.SelectCommand = com;
da.SelectCommand.ExecuteNonQuery();
da.Fill(ds);

cblProject.DataSource = ds.DefaultViewManager;
cblProject.DisplayMember = “hforms.PR_DESCR”;
cblProject.ValueMember = “hforms.PRID”;
}

July 2, 2008 at 8:26 am Leave a comment


July 2008
M T W T F S S
« Jun   Aug »
 123456
78910111213
14151617181920
21222324252627
28293031