I made an algorithm to calculate when the user has to purchase material adjusting the date in which the order has to be made, I'm using datagridviews to make it work, but I was wondering if there is a better way using a DataTable.
private void Suggestion()
{
for (int i = 1; i < dataGridView9.RowCount; i++)
{
string PartNumber = dataGridView9.Rows[i - 1].Cells["PartNumber"].Value.ToString();
string Requested_Date = dataGridView9.Rows[i - 1].Cells["Requested_Date"].Value.ToString();
string material = dataGridView9.Rows[i - 1].Cells["Material"].Value.ToString();
string requierd_Qty = dataGridView9.Rows[i - 1].Cells["Requierd_Qty"].Value.ToString();
for (int l = 1; l < dataGridView10.RowCount; l++)
{
string partNumber = dataGridView10.Rows[l - 1].Cells["PartNumber"].Value.ToString();
double leadTime = double.Parse(dataGridView10.Rows[l - 1].Cells["PUR LT"].Value.ToString());
if (partNumber == material)
{
DateTime _requested_Date = Convert.ToDateTime(Requested_Date);
DateTime suggestedDate = GetWorkDays.AddWorkdays(_requested_Date, Convert.ToDouble(leadTime));
try
{
oleDbCmd = new OleDbCommand("InsertSuggested", connection);
oleDbCmd.CommandType = CommandType.StoredProcedure;
oleDbCmd.Parameters.Add("@PartNumber", OleDbType.VarChar, 30).Value = material.ToString();
oleDbCmd.Parameters.Add("@AdjustedDate", OleDbType.Date, 50).Value = _requested_Date;
oleDbCmd.Parameters.Add("@SuggestedDate", OleDbType.Date, 50).Value = suggestedDate;
oleDbCmd.Parameters.Add("@Qty", OleDbType.VarChar, 30).Value = requierd_Qty;
connection.Open();
oleDbCmd.ExecuteNonQuery();
}
catch (OleDbException error)
{
MessageBox.Show(error.ToString());
}
finally
{
connection.Close();
}
break;
}
}
}
}
I want to know if there a better way of achieving this. Right now there inst that much data, but in the long run their might be. If there are other comments of the code please let me know.
Edit:changed variable names to correct ones.
string partNumber
within the same scope. This won't work. You can safely remove the first because you don't use it. \$\endgroup\$Requested_Date
ofDateTime _requested_Date = Convert.ToDateTime(Requested_Date);
come from ? \$\endgroup\$