Click here to Skip to main content
15,899,679 members
Home / Discussions / C#
   

C#

 
GeneralRe: progress window Pin
Mogaambo18-Jul-08 1:38
Mogaambo18-Jul-08 1:38 
GeneralRe: progress window Pin
enginço18-Jul-08 1:43
enginço18-Jul-08 1:43 
GeneralRe: progress window Pin
N a v a n e e t h18-Jul-08 1:46
N a v a n e e t h18-Jul-08 1:46 
GeneralRe: progress window Pin
Mogaambo18-Jul-08 1:51
Mogaambo18-Jul-08 1:51 
GeneralRe: progress window Pin
N a v a n e e t h18-Jul-08 2:05
N a v a n e e t h18-Jul-08 2:05 
GeneralRe: progress window Pin
Mogaambo18-Jul-08 2:34
Mogaambo18-Jul-08 2:34 
GeneralRe: progress window Pin
N a v a n e e t h18-Jul-08 2:45
N a v a n e e t h18-Jul-08 2:45 
GeneralRe: Please check only that lines which are commented AND IGNORE REST Pin
Mogaambo18-Jul-08 2:52
Mogaambo18-Jul-08 2:52 
using System;
using Microsoft.Win32;
using System.Management;
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.Diagnostics;
using System.Collections;
using System.IO;
using System.Net;
using System.Net.Sockets;
using System.Net.NetworkInformation;
using System.Windows;
using System.Configuration;
using System.Threading;


namespace LogApplication
{
public partial class Event_frm : Form
{

ArrayList entries = new ArrayList();
DataGridBoolColumn col = new DataGridBoolColumn();
string selectedPath;

Progress progress = new Progress();// check here it is a form

public Event_frm()
{
InitializeComponent();

}

private void Form1_Load(object sender, EventArgs e)
{
btnDownload.Enabled = false;
chbSelect.Enabled = false;
string strHostName = Dns.GetHostName();
}

private void button1_Click(object sender, EventArgs e)
{
ArrayList machine_names = new ArrayList();
machine_names.Clear();

for (int i = 0; i < gvMachine.RowCount; i++)
{
if (gvMachine.Rows[i].Cells[0].Value != null)
{
machine_names.Add(gvMachine.Rows[i].Cells[1].Value);
}
}

if (machine_names.Count <= 0)
{
MessageBox.Show("Please select atleast one machine name");
}
else
{
Credentials credentials = new Credentials();
credentials.username = "Administrator";
credentials.password = "1A2B3c456789$";

if (dgFolderBrowse.ShowDialog() == DialogResult.OK)
{
selectedPath = dgFolderBrowse.SelectedPath;
}
else
{
return;
}

if (rbtSoft_Inven_Info.Checked)
{
credentials.managementPath = @"\root\cimv2";
LogApplication.RegistryScan registryScan = new LogApplication.RegistryScan();

Hashtable registryEntries = registryScan.getRegistryEntries(machine_names, credentials);
ArrayList pass=(ArrayList)registryEntries["pass"];
ArrayList fail=(ArrayList)registryEntries["fail"];
FileWriter writer = new FileWriter();
int created = writer.write(pass, fail, selectedPath);
if (created > 0)
{
MessageBox.Show("Data Written");
}
}
else
{
credentials.managementPath = @"\root\cimv2";

if (ddEventType.SelectedIndex == -1)
{
errorProvider.DataSource = ddEventType;
errorProvider.SetError(ddEventType, "Please select valid event type");
ddEventType.Focus();
}
else
{
DateTime dateFrom;
DateTime dateEnd;

try
{
dateFrom = DateTime.Parse(string.Format("{0Big Grin | :-D }", dtFrm.Value));
}
catch (Exception ex)
{
MessageBox.Show("Invalid Start Date ");
dtFrm.Focus();
return;
}

try
{
dateEnd = DateTime.Parse(string.Format("{0Big Grin | :-D }", dtEnd.Value.AddDays(1)));
}
catch (Exception ex)
{
MessageBox.Show("Invalid End Date");
dtEnd.Focus();
return;
}

if (dateFrom <= dateEnd)
{
Hashtable logEntries = new EventLog().getLogEntries(machine_names,ddEventType.Text,credentials,dateFrom,dateEnd);
ArrayList pass = (ArrayList)logEntries["pass"];
ArrayList fail = (ArrayList)logEntries["fail"];
FileWriter writer = new FileWriter();
int created = writer.write(pass, fail, selectedPath);
if (created > 0)
{
MessageBox.Show("Data Written");
}
}
else
{
errorProvider.SetError(dtEnd, "End date should be less than or equal to Start date");
}

}

}
}

}

ArrayList generateMachineNames()
{
ProcessStartInfo pinfo = new ProcessStartInfo("net", "view");
pinfo.RedirectStandardOutput = true;
pinfo.UseShellExecute = false;
pinfo.CreateNoWindow = true;
using (Process p = new Process())
{
try
{
p.StartInfo = pinfo;
p.Start();

ArrayList machine_names = new ArrayList();
while (!p.StandardOutput.EndOfStream)
{
string read = p.StandardOutput.ReadLine().Trim();
if (read.StartsWith("\\\\"))
{

string[] machines = read.Split(' ');
machine_names.Add(machines[0].Substring(2).Trim());
}
}
return machine_names;
}

catch (IOException IOException)
{
MessageBox.Show("Error occurred in generating IP list, "+IOException.Message);
return null;
}
catch (Exception ex)
{
MessageBox.Show("Error occurred : " + ex.Message);
return null;
}
}
}

void loadMachines(ArrayList machineList)
{
int count = 0;
foreach (string machine in machineList)
{
gvMachine.Rows.Add();
gvMachine.Rows[count].Cells[1].Value = machine;
count++;
}

}

void loadMachines(string machine)
{
gvMachine.Rows.Add();
gvMachine.Rows[0].Cells[1].Value = machine;
}

private void rbtSoft_Inven_Info_CheckedChanged(object sender, EventArgs e)
{
ddEventType.Enabled = false;
dtFrm.Enabled = false;
dtEnd.Enabled = false;
}

private void rbtEvent_log_history_CheckedChanged(object sender, EventArgs e)
{
ddEventType.Enabled = true;
dtFrm.Enabled = true;
dtEnd.Enabled = true;

}

private void btnSearch_Click(object sender, EventArgs e)
{
if (rbtRemote.Checked == false && rbtLocal.Checked == false)
{
errorProvider.SetError(btnSearch, "Please, select one option");
}
else
{
if (rbtRemote.Checked)
{
// CHECK HERE ALSO
MethodInvoker invoker = new MethodInvoker(showProgress); /check here
invoker.BeginInvoke(null,null); //here tooooo
ArrayList machineList = generateMachineNames();

if (machineList == null || machineList.Count == 0)
{
MessageBox.Show("No machines are available, please check your network or try again");
btnDownload.Enabled = false;
if (gvMachine.Rows.Count > 0)
{
gvMachine.Rows.Clear();
}
progress.Close();
progress.Dispose();
}
else
{
loadMachines(machineList);

btnDownload.Enabled = true;
chbSelect.Enabled = true;
progress.Close();// here i got error
progress.Dispose();
}
}
else
{
try
{
string machine = Dns.GetHostName();
loadMachines(machine);
btnDownload.Enabled = true;
}
catch (SocketException SocketException)
{
MessageBox.Show("Error occurred in getting local machine name, " + SocketException.Message);
}
catch (Exception ex)
{
MessageBox.Show("Error occurred , " + ex.Message);
}
}
}

}

private void chbSelect_CheckedChanged(object sender, EventArgs e)
{
if (chbSelect.Checked)
{
for (int i = 0; i < gvMachine.RowCount; i++)
{
gvMachine.Rows[i].Cells[0].Value = true;
}
}
else
{
for (int i = 0; i < gvMachine.RowCount; i++)
{
gvMachine.Rows[i].Cells[0].Value = false;
}
}
}

private void btnCancel_Click(object sender, EventArgs e)
{
try
{
Environment.Exit(0);
}
catch (System.Security.SecurityException SecurityException)
{
MessageBox.Show(SecurityException.Message);
}
}

void showProgress()//this is the method
{
progress.ShowDialog();
}

}

}
GeneralRe: Please check only that lines which are commented AND IGNORE REST Pin
N a v a n e e t h18-Jul-08 3:05
N a v a n e e t h18-Jul-08 3:05 
GeneralRe: Please check only that lines which are commented AND IGNORE REST Pin
Mogaambo18-Jul-08 3:14
Mogaambo18-Jul-08 3:14 
QuestionAsynchronous call of a dynamically loaded method? Pin
matthias s.18-Jul-08 1:14
matthias s.18-Jul-08 1:14 
AnswerRe: Asynchronous call of a dynamically loaded method? Pin
N a v a n e e t h18-Jul-08 1:34
N a v a n e e t h18-Jul-08 1:34 
GeneralRe: Asynchronous call of a dynamically loaded method? Pin
matthias s.18-Jul-08 1:47
matthias s.18-Jul-08 1:47 
GeneralRe: Asynchronous call of a dynamically loaded method? Pin
N a v a n e e t h18-Jul-08 2:03
N a v a n e e t h18-Jul-08 2:03 
GeneralRe: Asynchronous call of a dynamically loaded method? Pin
matthias s.18-Jul-08 2:59
matthias s.18-Jul-08 2:59 
GeneralRe: Asynchronous call of a dynamically loaded method? Pin
N a v a n e e t h18-Jul-08 3:14
N a v a n e e t h18-Jul-08 3:14 
GeneralRe: Asynchronous call of a dynamically loaded method? Pin
matthias s.18-Jul-08 3:52
matthias s.18-Jul-08 3:52 
GeneralRe: Asynchronous call of a dynamically loaded method? Pin
N a v a n e e t h18-Jul-08 17:17
N a v a n e e t h18-Jul-08 17:17 
QuestionUsing MIRR function in c# Pin
sumit703418-Jul-08 0:16
sumit703418-Jul-08 0:16 
AnswerRe: Using MIRR function in c# Pin
CPallini18-Jul-08 0:32
mveCPallini18-Jul-08 0:32 
GeneralRe: Using MIRR function in c# Pin
sumit703418-Jul-08 0:38
sumit703418-Jul-08 0:38 
GeneralYou are welcome. Pin
CPallini18-Jul-08 0:41
mveCPallini18-Jul-08 0:41 
QuestionSerialPort and data received event Pin
kildareflare18-Jul-08 0:02
kildareflare18-Jul-08 0:02 
AnswerRe: SerialPort and data received event Pin
kildareflare18-Jul-08 1:01
kildareflare18-Jul-08 1:01 
GeneralRe: SerialPort and data received event Pin
Luc Pattyn18-Jul-08 1:38
sitebuilderLuc Pattyn18-Jul-08 1:38 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.