public String InsertDimensionInformation(String pDimensionCode, String pLength, String pWidth, String pHeight, string CustomerID, String ppartNumber)
{
SqlConnection SqlCon = new SqlConnection(constr);
try
{
SqlCommand SqlCmd3 = new SqlCommand("select Partnumber from dimensions where Partnumber=" + ppartNumber.ToString() + " ", SqlCon);
if (SqlCon.State == ConnectionState.Closed) { SqlCon.Open(); }
String result;
try
{
SqlDataReader dr = SqlCmd3.ExecuteReader(CommandBehavior.CloseConnection);
if (dr.Read())
{
result = "The PartNumber is already existed";
if (SqlCon.State == ConnectionState.Open)
SqlCon.Close();
dr.Close();
return result;
}
dr.Close();
}
catch (Exception ex)
{
if (SqlCon.State == ConnectionState.Open)
SqlCon.Close();
}
finally
{
if (SqlCon.State == ConnectionState.Open)
SqlCon.Close();
}
SqlCommand SqlCmd = new SqlCommand("sp_select_dimensions", SqlCon);
SqlCmd.CommandType = CommandType.StoredProcedure;
SqlCmd.Parameters.AddWithValue("@LENGTH", pLength);
SqlCmd.Parameters.AddWithValue("@WIDTH", pWidth);
SqlCmd.Parameters.AddWithValue("@HEIGHT", pHeight);
SqlCmd.Parameters.AddWithValue("@CUSTOMERID", CustomerID);
SqlCmd.Parameters.AddWithValue("@PartNumber", ppartNumber);
if (SqlCon.State == ConnectionState.Closed) { SqlCon.Open(); }
try
{
SqlDataReader dr = SqlCmd.ExecuteReader(CommandBehavior.CloseConnection);
if (dr.Read())
{
result = "The combination is already existed";
if (SqlCon.State == ConnectionState.Open)
SqlCon.Close();
dr.Close();
return result;
}
dr.Close();
}
catch (Exception ex)
{
if (SqlCon.State == ConnectionState.Open)
SqlCon.Close();
}
finally
{
if (SqlCon.State == ConnectionState.Open)
SqlCon.Close();
}
SqlCmd = new SqlCommand("sp_curd_dimensions", SqlCon);
SqlCmd.CommandType = CommandType.StoredProcedure;
SqlCmd.Parameters.AddWithValue("@OPERATIONS", "INSERT");
SqlCmd.Parameters.AddWithValue("@LENGTH", pLength);
SqlCmd.Parameters.AddWithValue("@WIDTH", pWidth);
SqlCmd.Parameters.AddWithValue("@HEIGHT", pHeight);
SqlCmd.Parameters.AddWithValue("@DIMENSIONCODE", pDimensionCode);
SqlCmd.Parameters.AddWithValue("@CUSTOMERID", CustomerID);
SqlCmd.Parameters.AddWithValue("@PartNumber", ppartNumber);
if (SqlCon.State == ConnectionState.Closed) { SqlCon.Open(); }
int strResult = SqlCmd.ExecuteNonQuery();
if (SqlCon.State == ConnectionState.Open)
SqlCon.Close();
if (strResult == 1)
return "Success";
else
return strResult.ToString();
}
catch (Exception ex)
{
if (SqlCon.State == ConnectionState.Open)
SqlCon.Close();
return ex.Message;
}
finally
{
if (SqlCon.State == ConnectionState.Open)
SqlCon.Close();
}
}