Now fills the sipmtable

This commit is contained in:
David Baranyai 2019-03-19 22:41:18 -04:00
parent 0d904086b4
commit c6a1e2a475
1 changed files with 47 additions and 11 deletions

View File

@ -61,6 +61,7 @@ namespace trayToDB
private void browseButton_Click(object sender, EventArgs e)
{
statusTextbox.Clear();
Excel.Application xlApp;
Excel.Workbook xlWorkBook;
Excel.Worksheet xlWorkSheet;
@ -229,27 +230,62 @@ namespace trayToDB
if (cmd.ExecuteNonQuery() == 1)
{
statusTextbox.AppendText("Succesfully inserted! Tray ID: " + listOfData[i].trayNo + "\n");
cmd.Parameters.Clear();
cmd.CommandText = "SELECT trayid AS trayid FROM hamamatsutraytable WHERE shippingid = (SELECT shippingid FROM hamamatsushippingtable WHERE shipdate = convert(@shipping, DATE) AND arrivedate = convert(@arrival, DATE) AND traynumber = @i)";
cmd.Parameters.AddWithValue("@arrival", dateTimePicker1.Value);
cmd.Parameters.AddWithValue("@shipping", shippingDate);
cmd.Parameters.AddWithValue("@i", i + 1);
reader = cmd.ExecuteReader();
int trayid = 0;
if (reader.Read())
{
if (reader.GetInt16("trayid") != 0)
{
trayid = reader.GetInt16("trayid");
reader.Close();
}
else
{
throw new Exception("Error while reading from database!");
}
}
else
{
throw new Exception("Query error!");
}
for (int j = 0; j < listOfData[i].noOfSipm; j++)
{
cmd.Parameters.Clear();
cmd.CommandText = "INSERT INTO sipmtable (hamamatsutrayid, hamamatsutrayposition, outputtrayid, outputtrayposition) VALUES (@trayid ,@j , 1, 1)";
cmd.Parameters.AddWithValue("@shipping", shippingDate);
cmd.Parameters.AddWithValue("@trayid", trayid);
cmd.Parameters.AddWithValue("@trayno", listOfData[i].trayNo);
cmd.Parameters.AddWithValue("@j", j);
if (cmd.ExecuteNonQuery() == 1)
{
//statusTextbox.AppendText("\tSuccesfully inserted one SiPM position! (" + j + ")\n");
}
else
{
throw new Exception("Something went wrong!");
}
}
statusTextbox.AppendText("\tSuccesfully inserted " + listOfData[i].noOfSipm + " SiPM position!\n");
}
else
{
statusTextbox.AppendText("Something went wrong!");
throw new Exception("Something went wrong!");
}
}
conn.Close();
uploadButton.Enabled = false;
statusTextbox.AppendText("Done!\n");
}
catch (MySqlException ex)
{
switch (ex.Number)
{
case 0:
//MessageBox.Show("Cannot connect to server. Contact administrator");
MessageBox.Show(ex.ToString());
break;
case 1045:
MessageBox.Show("Invalid username/password, please try again");
break;
}
statusTextbox.AppendText(ex.Message);
}
catch (Exception ex)
{