hi,all my friends!
I am a new coder!
I must learn C++ and C# by myself as soon as possible!
Recently,I revise a C# program.
There is a DataGridView in the program.
Run program,Display of the DataGridView is normal。
But it is dead or no-response when i click or move scrollBar.
I don't know why.
Please help!
1/28,I found that maybe is backgroundWorker1.RunWorkerAsync() problem!
code:
private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
{
Int32 TimeFrom, TimeTo;
ClearGraph();
_lstLine.Clear();
_lstRestore._errors.Clear();
_lstRestore._happentime.Clear();
_lstRestore._line.Clear();
_lstRestore._process.Clear();
lblUpdateTime.Visible = false;
if (cbTimeFrom.Text == "" || cbTimeTo.Text == "")
{
MessageBox.Show("Select Start and End time");
}
else if (cbProcess.Text == "")
MessageBox.Show("Select Process");
if (cboMain.Text == "")
MessageBox.Show("Select Floor");
else
{
TimeFrom = Convert.ToInt32(cbTimeFrom.Text);
TimeTo = Convert.ToInt32(cbTimeTo.Text);
DateTime DateFrom = new DateTime(dtpDateFrom.Value.Year, dtpDateFrom.Value.Month, dtpDateFrom.Value.Day, TimeFrom, 0, 0);
DateTime DateTo = new DateTime(dtpDateTo.Value.Year, dtpDateTo.Value.Month, dtpDateTo.Value.Day, TimeTo, 59, 59);
MySqlConnection connection = new MySqlConnection(MyConnectionString);
try
{
connection.Open();
}
catch (Exception ex)
{
MessageBox.Show("Connected to Database errors!: " + ex.Message);
}
tblRobotMonitoring temp_lstRestore = new tblRobotMonitoring();
temp_lstRestore._happentime = new List<DateTime>();
temp_lstRestore._errors = new List<string>();
temp_lstRestore._line = new List<string>();
temp_lstRestore._process = new List<string>();
MySqlCommand cmd = connection.CreateCommand();
cmd.CommandText = "set names utf8";
cmd.ExecuteNonQuery();
cmd.CommandText = "select HappenTime,Errors,Line,Process from tblRobotMonitoring where HappenTime >= @Time1 and HappenTime<=@Time2";
cmd.Parameters.Add(new MySqlParameter("@Time1", MySqlDbType.DateTime, 0));
cmd.Parameters.Add(new MySqlParameter("@Time2", MySqlDbType.DateTime, 0));
cmd.Parameters["@Time1"].Value = DateFrom;
cmd.Parameters["@Time2"].Value = DateTo;
MySqlDataReader rd = cmd.ExecuteReader();
while (rd.Read())
{
DateTime temp_happentime = new DateTime();
DateTime.TryParse(rd[0].ToString(), out temp_happentime);
_lstRestore._happentime.Add(temp_happentime);
_lstRestore._errors.Add(rd[1].ToString());
_lstRestore._line.Add(rd[2].ToString());
_lstRestore._process.Add(rd[3].ToString());
}
rd.Close();
cmd.Parameters.Clear();
connection.Close();
if (_lstRestore._line.Count() <= 0)
{
MessageBox.Show("No Data !");
lblResult.Text = "Fail SUM : " + _lstRestore._line.Count().ToString();
lblMainAveResult.Text = "No Data";
lblResult.Visible = true;
_lstRestore._errors.Clear();
_lstRestore._happentime.Clear();
_lstRestore._line.Clear();
_lstRestore._process.Clear();
return;
}
else
{
lblResult.Visible = true;
foreach (string va in _lstRestore._line)
{
if (!_lstLine.Contains(va))
_lstLine.Add(va);
}
var Dictionarys = new Dictionary<string, int>(_lstLine.Count());
foreach (string line in _lstLine)
{
int count = 0;
foreach (string va in _lstRestore._line)
{
if (va.Equals(line)) ++count;
}
Dictionarys.Add(line, count);
}
var take = (from tbl in Dictionarys orderby tbl.Value descending select tbl).Take(100);
List<string> listLine = new List<string>();
List<Double> listLineValue = new List<double>();
foreach (var pair in take)
{
listLine.Add(pair.Key);
listLineValue.Add((double)pair.Value);
}
List<string> _lstError = new List<string>();
List<string> _lstFilteredError = new List<string>();
foreach (var va in _lstRestore._errors)
{
_lstError.Add(va);
}
backgroundWorker1.ReportProgress(40);
dgv1.DataSource = null;
dgv1.Rows.Clear();
for (int i = 0; i < _lstError.Count(); i++)
{
int per =40+ 60 *i/ _lstError.Count();
backgroundWorker1.ReportProgress(per);
for (int j = 0; j < _lstError.Count(); j++)
{
if (StringCompare(_lstError[i], _lstError[j]))
{
_lstError[i] = sResult;
_lstError[j] = sResult;
}
}
if (!_lstFilteredError.Contains(sResult))
_lstFilteredError.Add(sResult);
}
lblResult.Text = "Fail SUM: " + _lstRestore._line.Count().ToString();
_lstLine = listLine;
ShowGraph so = new ShowGraph(zg1, "Fail", "Line", "Count", listLine, listLineValue, "Bar");
foreach (string error in _lstFilteredError)
{
var RecordError = from tbl in _lstError where tbl.Equals(error) select tbl;
dgv1.Rows.Add(error, RecordError.Count());
}
dgv1.Refresh();
lblMainAveResult.Text = (_lstRestore._line.Count() / _lstLine.Count()).ToString();
}
}
}