I am working on a application to chart boards inspected and board with defects based on work order number. I realize after looking at the chart and comparing the actual data, that the series do not match up for work order number. I am at a loss on how to match both series to the work order number to get a correct chart.
Here is my code for the data pull Boards_Inspected pulled first
public DataSet Get_Boards_Inspected(string startDate, string endDate, int location)
{
DataSet ds = new DataSet();
NpgsqlConnection conn = DatabaseConnection.getConnectionString();
try
{
conn.Open();
NpgsqlDataAdapter da = new NpgsqlDataAdapter("select new_table.top_or_bottom, new_table.board_wo_number, count(new_table.board_serial_number) from" +
" (select distinct master_board.board_serial_number, board_wo.board_wo_number,board_wo.board_part_number, board_time.top_or_bottom from master_board" +
" inner join board_time on board_time.board_time_id = master_board.id" +
" inner join board_wo on board_wo.board_wo_number = master_board.board_wo_number" +
" where time_in between '" + startDate + "' and '" + endDate + "'" +
" and board_time.location_id = '" + location + "')" +
" as new_table" +
" group by new_table.top_or_bottom, new_table.board_wo_number" +
" order by top_or_bottom;", conn);
ds.Reset();
da.Fill(ds);
da.Dispose();
}
catch (Exception ex)
{
MessageBox.Show("An unexpected error has occured with the application. \n" +
"An email has been sent to the software developer for analysis. \n" +
"this program will now close.", "Unexpected Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
eMessageBody = ex.ToString();
Mail sendMessage = new Mail();
sendMessage.SendSMTP(eMessageBody, eMessageSubject);
Application.Exit();
}
finally
{
conn.Close();
}
return ds;
}
Board with defects
public DataSet Get_Boards_With_Issue(string startDate, string endDate, int location)
{
DataSet ds = new DataSet();
NpgsqlConnection conn = DatabaseConnection.getConnectionString();
try
{
conn.Open();
NpgsqlDataAdapter da = new NpgsqlDataAdapter("select new_table.top_or_bottom, new_table.board_wo_number, count(new_table.defect_id) from" +
" (select distinct defect_id, top_or_bottom, board_wo_number from defect" +
" inner join master_board on defect.defect_id = master_board.id" +
" where defect_time between '" + startDate + "' and '" + endDate + " 23:59:59'" +
" and location_id = '" + location + "')" +
" as new_table" +
" group by new_table.top_or_bottom, new_table.board_wo_number" +
" order by top_or_bottom;", conn);
ds.Reset();
da.Fill(ds);
da.Dispose();
}
catch(Exception ex)
{
MessageBox.Show("An unexpected error has occured with the application. \n" +
"An email has been sent to the software developer for analysis. \n" +
"this program will now close.", "Unexpected Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
eMessageBody = ex.ToString();
Mail sendMessage = new Mail();
sendMessage.SendSMTP(eMessageBody, eMessageSubject);
Application.Exit();
}
finally
{
conn.Close();
}
return ds;
}
Here is my chart series assignment code
private void Boards_Without_Issue_Chart(string starDate, string endDate, int location)
{
try
{
#region Chart Setup
chart1.Series.Clear();
chart1.Series.Add("Boards Inspected");
chart1.Series.Add("Boards Without Issue");
chart1.Series.Add("Boards With Issue");
chart1.Series["Boards Inspected"].Points.Clear();
chart1.Series["Boards Without Issue"].Points.Clear();
chart1.Series["Boards With Issue"].Points.Clear();
chart1.Series["Boards Inspected"]["LabelStyle"] = "Top";
chart1.Series["Boards Without Issue"]["LabelStyle"] = "Top";
chart1.Series["Boards With Issue"]["LabelStyle"] = "Top";
chart1.ChartAreas[0].AxisX.Interval = 1;
chart1.Series["Boards Inspected"].ChartType = SeriesChartType.Column;
chart1.Series["Boards Without Issue"].ChartType = SeriesChartType.Column;
chart1.Series["Boards With Issue"].ChartType = SeriesChartType.Column;
chart1.Series["Boards Inspected"]["DrawingStyle"] = "LightToDark";
chart1.Series["Boards Without Issue"]["DrawingStyle"] = "LightToDark";
chart1.Series["Boards With Issue"]["DrawingStyle"] = "LightToDark";
if (chart1.Titles.Contains(t1))
{
t1.Font = new System.Drawing.Font("Microsoft Sans serif", 14, FontStyle.Bold);
t1.Text = titleText + " - Boards Without Issue - (" + startDate + " - " +endDate+ ")";
}
else
{
t1.Name = "tTitle1";
t1.Font = new System.Drawing.Font("Microsoft Sans serif", 14, FontStyle.Bold);
t1.Text = titleText + " - Boards Without Issue - (" + startDate + " - " + endDate + ")";
chart1.Titles.Add(t1);
}
chart1.ChartAreas[0].BorderDashStyle = ChartDashStyle.Solid;
chart1.ChartAreas[0].AxisX.MajorGrid.LineWidth = 0;
chart1.ChartAreas[0].AxisY.TitleFont = new System.Drawing.Font("Microsoft Sans serif", 14, FontStyle.Bold);
chart1.ChartAreas[0].AxisY.Title = "Amount of Boards";
chart1.ChartAreas[0].AxisX.TitleFont = new System.Drawing.Font("Microsoft Sans serif", 14, FontStyle.Bold);
chart1.ChartAreas[0].AxisX.Title = "Work Order";
chart1.ChartAreas[0].AxisX.LabelStyle.Angle = -45;
chart1.ChartAreas[0].AxisX.LabelStyle.Font = new System.Drawing.Font("Microsoft Sans serif", 12, FontStyle.Regular);
chart1.Series["Boards Inspected"].IsValueShownAsLabel = true;
chart1.Series["Boards With Issue"].IsValueShownAsLabel = true;
#endregion
#region Chart Data Assignment
DataAccess DA = new DataAccess();
DataAccess DA2 = new DataAccess();
DataSet mda = new DataSet();
if ((DA.Get_Boards_Inspected(startDate, endDate, location).Tables[0].Rows.Equals(0)) &&
(DA2.Get_Boards_With_Issue(startDate, endDate, location).Tables[0].Rows.Equals(0)))
lblError.Text = "No information Availiable";
else
{
foreach (DataTable tb in DA.Get_Boards_Inspected(startDate, endDate, location).Tables)
{
foreach (DataRow dr in tb.Rows)
{
object tpn = dr["top_or_bottom"];
var ct = (dr["count"].ToString());
var wo = (dr["board_wo_number"].ToString());
if (tpn == DBNull.Value)
chart1.Series["Boards Inspected"].Points.AddXY(wo, ct);
else
chart1.Series["Boards Inspected"].Points.AddXY(wo + " - " + tpn, ct);
}
}
DA.Get_Boards_Inspected(startDate, endDate, location).Clear();
DA.Get_Boards_Inspected(startDate, endDate, location).Dispose();
foreach (DataTable tb2 in DA2.Get_Boards_With_Issue(startDate, endDate, location).Tables)
{
foreach (DataRow dr2 in tb2.Rows)
{
object tpn2 = dr2["top_or_bottom"];
var ct = (dr2["count"].ToString());
var wo = (dr2["board_wo_number"].ToString());
if (tpn2 == DBNull.Value)
chart1.Series["Boards With Issue"].Points.AddXY(wo, ct);
else
chart1.Series["Boards With Issue"].Points.AddXY(wo + " - " + tpn2, ct);
}
}
DA2.Get_Boards_With_Issue(startDate, endDate, location).Clear();
DA2.Get_Boards_With_Issue(startDate, endDate, location).Dispose();
}
#endregion
}
catch(Exception ex)
{
MessageBox.Show("An unexpected error has occured with the application. \n" +
"An email has been sent to the software developer for analysis. \n" +
"this program will now close.", "Unexpected Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
eMessageBody = ex.ToString();
Mail sendMessage = new Mail();
sendMessage.SendSMTP(eMessageBody, eMessageSubject);
Application.Exit();
MessageBox.Show(ex.ToString());
}
}
EDIT: Here is the code for the chart data
DataAccess DA = new DataAccess();
DataAccess DA2 = new DataAccess();
DataSet mda = new DataSet();
if ((DA.Get_Boards_Inspected(startDate, endDate, location).Tables[0].Rows.Equals(0)) &&
(DA2.Get_Boards_With_Issue(startDate, endDate, location).Tables[0].Rows.Equals(0)))
lblError.Text = "No information Availiable";
else
{
foreach (DataTable tb in DA.Get_Boards_Inspected(startDate, endDate, location).Tables)
{
foreach (DataRow dr in tb.Rows)
{
object tpn = dr["top_or_bottom"];
var ct = (dr["count"].ToString());
var wo = (dr["board_wo_number"].ToString());
if (tpn == DBNull.Value)
chart1.Series["Boards Inspected"].Points.AddXY(wo, ct);
else
chart1.Series["Boards Inspected"].Points.AddXY(wo + " - " + tpn, ct);
}
}
DA.Get_Boards_Inspected(startDate, endDate, location).Clear();
DA.Get_Boards_Inspected(startDate, endDate, location).Dispose();
foreach (DataTable tb2 in DA2.Get_Boards_With_Issue(startDate, endDate, location).Tables)
{
foreach (DataRow dr2 in tb2.Rows)
{
object tpn2 = dr2["top_or_bottom"];
var ct = (dr2["count"].ToString());
var wo = (dr2["board_wo_number"].ToString());
if (tpn2 == DBNull.Value)
chart1.Series["Boards With Issue"].Points.AddXY(wo, ct);
else
chart1.Series["Boards With Issue"].Points.AddXY(wo + " - " + tpn2, ct);
}
}
DA2.Get_Boards_With_Issue(startDate, endDate, location).Clear();
DA2.Get_Boards_With_Issue(startDate, endDate, location).Dispose();
EDIT: Links
Both data sets, trying to line them up in a chart
Recent chart