Use ProgressBar, BackgroundWorker & LisBox to display all the files w/i the directory

Use ProgressBar, BackgroundWorker & LisBox to display all the files w/i the directory
and simulation of processing each file


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Threading;
using System.IO;

namespace WindowsFormsApplication12
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void Form1_Load(object sender, System.EventArgs e)
{
// Start the BackgroundWorker.
progressBar1.Minimum = 0;
progressBar1.Maximum = GetProgressMax();
backgroundWorker1.RunWorkerAsync();
}

protected int GetProgressMax()
{
int i = 0;
DirectoryInfo di = new DirectoryInfo(@"C:\Documents and Settings\user\My Documents\eric scheduler\ci review\Debug-Full\ContractReviewLog");
if (di.Exists)
{
i = di.GetFiles("*.txt").Length;
}

return i;
}

private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
{
/* for (int i = 1; i <= 100; i++)
{
// Wait 100 milliseconds.
Thread.Sleep(100);
// Report progress.
backgroundWorker1.ReportProgress(i);

}*/

DirectoryInfo di = new DirectoryInfo(@"C:\Documents and Settings\user\My Documents\eric scheduler\ci review\Debug-Full\ContractReviewLog");

if (di.Exists)
{
int i = 0;
foreach (FileInfo fi in di.GetFiles("*.txt"))
{
backgroundWorker1.ReportProgress(i);
i++;
Thread.Sleep(100);
listBox1.Items.Add(fi.Name);
}
}

}

private void backgroundWorker1_ProgressChanged(object sender, ProgressChangedEventArgs e)
{
// Change the value of the ProgressBar to the BackgroundWorker progress.
progressBar1.Value = e.ProgressPercentage;
// Set the text.
//this.Text = e.ProgressPercentage.ToString();
label1.Text = "percent: " + e.ProgressPercentage.ToString() + "%";
label1.Refresh();
}
}
}

Are You Ready For Google+? Need an invite?


Do you need a google+ (google plus) invite? invitation give away, please leave your NAME and GMAIL address in the comment section.

2-D Array + Sum up Horizontally & Vertically


public class Matrix
{
public static void main(String[] args)
{
int[][] x = new int[8][8];
int[] y = new int[x.length];
int[] z = new int[x.length];

for(int i=0; i< x.length; i++)
{
for(int j=0; j < x[i].length; j++)
{
x[i][j]=(int)(Math.random()/Math.random());
}
}

System.out.println();
System.out.println("2-D Random Integer Array!");
int counter=0;

for(int i=0; i< x.length; i++)
{
for(int j=0; j < x[i].length; j++)
{
System.out.print(x[i][j]+" ");
y[i] +=x[i][j];
z[i] +=x[j][i];
}

System.out.println();
}

System.out.println();
System.out.println("Sum 2-D Random Integer Array Horizontally!");

for(int i=0; i<y.length; i++)
{
System.out.println(y[i]);
}

System.out.println();
System.out.println("Sum 2-D Random Integer Array Vertically!");
for(int i=0; i<z.length; i++)
{
System.out.println(z[i]);
}
}
}

SQL Raw Bar Chart

PRINT '==>USER VISIT BAR CHART DB DIV5<=='
SELECT TOP 10* FROM
(
SELECT CONVERT(DATETIME,CONVERT(VARCHAR,[LoginDate],101)) LoginDate
,COUNT(*) LoginFreq
,LoginChart
=CASE
WHEN SUBSTRING(REPLACE(SPACE(COUNT(*)/10),' ','|'),1,200) =''
THEN '|'
ELSE
SUBSTRING(REPLACE(SPACE(COUNT(*)/10),' ','|'),1,200)
END
FROM [DB].[dbo].[UserLoginView]
WHERE
Application='DB'
AND MONTH(LoginDate) = MONTH(GETDATE())
AND YEAR(LoginDate)=YEAR(GETDATE())
GROUP BY CONVERT(DATETIME,CONVERT(VARCHAR,[LoginDate],101))
--ORDER BY 1 DESC
)X
ORDER BY 1 DESC

DataBinding: ‘System.Data.DataRowView’ does not contain a property with the name when using ImportRow(row)

issue: when try to bind or access the data colum from the datatable (from ImportRow method)


DataTable dTable = datatablesource //sql fetch
DataTable dTableFilter = new DataTable();

for (int i = 0; i < dTable.Rows.Count; ++i)
{
dTableFilter.ImportRow(dTable.Rows[i]);
}

//then

for (int i = 0; i < dTableFilter.Rows.Count; i++)
{

lblRet.Text += "
" + dTableFilter.Rows[i]["columnname"].ToString(); // produce following error
}

error: DataBinding: ‘System.Data.DataRowView’ does not contain a property with the name “columname”

solution: make sure you clone the structure of the schema of the old datatable

e.g. before the importrow for loop
put: dTableFilter = dTable.Clone(); // clone the structure & schema

Kill & Restart a Process/Program C#

using System.Diagnostics;

static bool IsProcessOpen(string name)
{
Process[] pArry = Process.GetProcesses();
foreach (Process p in pArry)
{
string s = p.ProcessName;
s = s.ToLower();
if (s.CompareTo(name.ToLower()) == 0)
{
p.Kill();
if (name == “processname”) //processname is the name of the running process to check
{
StartProcess(); //function to start process
}
return true;
}
}
return false;
}

static void StartProcess()
{
ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.FileName = @”****.exe”; //path/process name
Process.Start(startInfo);
}

Unpack the packed COBOL COMP-3 Field in SAS w/ S370FPDw

problem:

DSN w/ Date field is packed w/ COBOL COMP-3

request:

read and unpack the date field in SAS

solution:

use data format: S370FPDw (where w is packed length for the field)

e.g.

for a packed field PIC 9(08) COMP-3 at position 200     total length for the date is 8 and packed length is 5

to read from DSN:

INPUT @200 testDate  S370FPD5

to write to DSN
PUT @200 testDate $8.

SSMS Connection to SQL Azure

Please be aware that SSMS is not supported with SQL Azure yet. However, you can use the following workaround for the time being:

1. Click Cancel in Connect to Server Dialog
2. Click New Query which will bring up the new connection dialog.
3. Enter your credentials. By default, you will connect to Master database. If you want to connect to specific database, click options and enter the database name. Please be aware that USE is not supported.
4. Now click Connect and you will get an error “Unable to apply connection settings. The detailed error message is: ‘ANSI_NULLS’ is not a recognized SET option. “
5. Click Ok.

Turn on Virtual Machine on Virtual Server Automatically

To autostart Virtual Machine, open Virtual Server web administration. With the VM off, edit the configuration for the VM you want to Autostart. Under the General Properties, you’ll see options to automatically turn on the virtual machine. You need to check Run virtual machine under the following user account, and type username and password. Click OK to save the settings.

SQL convert string ‘mmddyy’ to date time format

1) T-SQL scalar function
CREATE FUNCTION DBO.[format_mmddyy_date] (@mmddyy_value varchar(6)) returns smalldatetime
as
begin
 declare @return_value smalldatetime
 set @return_value =(select CAST(
   substring(Right(’000000′ + convert(varchar(6),@mmddyy_value),6),1,2)
 +’/'+substring(Right(’000000′ + convert(varchar(6),@mmddyy_value),6),3,2)
 +’/'+substring(Right(’000000′ + convert(varchar(6),@mmddyy_value),6),5,2)
 as smalldatetime))
 return @return_value
end

2) SQL Select statement
select CAST(
 substring(Right(’000000′ + convert(varchar(6),@mmddyy_value),6),1,2)
 +’/'+substring(Right(’000000′ + convert(varchar(6),@mmddyy_value),6),3,2)
 +’/'+substring(Right(’000000′ + convert(varchar(6),@mmddyy_value),6),5,2)
 as smalldatetime)

*replace the @mmddyy_value w/ your variable, column or string (e.g ’071509′)

Follow

Get every new post delivered to your Inbox.