private static void UploadDocument(MySqlConnection conn, APIInterface apiInterface, string text)
{
string documentText = text.Replace("'", "''");
string documentName = "com_object_" + apiInterface.Name.ToLower();
string documentTitle = apiInterface.Name + " object";
string documentLatestChange = DateTime.Now.ToString("yyyy'-'MM'-'dd");
int documentReads = 0;
int documentParentID = 53;
int documentIndex = 0;
int documentIsBook = 0;
int documentFirstPage = 0;
// check if the document exists.
string name = "select * from hm_documents where documentname = '" + documentName + "'";
MySqlCommand command = new MySqlCommand(name, conn);
bool exists = false;
using (MySqlDataReader reader = command.ExecuteReader())
{
exists = reader.Read();
reader.Close();
}
string sql = null;
if (exists)
{
sql = string.Format("update hm_documents set documenttext = '{0}' where documentname = '{1}'", documentText, documentName);
}
else
{
sql = string.Format(@"insert into hm_documents (documentname, documenttitle, documenttext, documentlatestchange, documentreads, documentparentid, documentindex, documentisbook, documentfirstpage) VALUES
('{0}', '{1}', '{2}', '{3}', '{4}', {5}, {6}, {7}, {8})",
documentName, documentTitle, documentText, documentLatestChange, documentReads, documentParentID, documentIndex, documentIsBook, documentFirstPage);
}
MySqlCommand updateCommand = new MySqlCommand(sql, conn);
updateCommand.ExecuteNonQuery();
}