private void DeletePicture() { SqlConnection connection = new SqlConnection(Properties.Settings.Default.connectionStringMriyaDataDb); SqlCommand cmd = new SqlCommand("DELETE FROM [UserPhoto] WHERE Id=@Id;", connection); cmd.Parameters.Add("@Id", SqlDbType.Int).Value = m_nRecordID; // Omnitrack db FormWait formWait = new FormWait("Оновлення бази даних"); try { connection.Open(); cmd.ExecuteScalar(); connection.Close(); } catch (Exception ex) { MessageBox.Show("Сталася помилка під час видалення фотографії:\r\n" + ex.Message, "Видалення фотографії", MessageBoxButtons.OK, MessageBoxIcon.Error); } formWait.Close(); // Update Sharepoint profile if there were no errors while reading file and updating DB string login = GetLogingName(); string sharepointUrl = Properties.Settings.Default.sharepointSite; // User has no SP profile (user name is not specified) or Sharepoint is not configured if (!string.IsNullOrEmpty(login) && !string.IsNullOrEmpty(sharepointUrl)) { formWait = new FormWait("Оновлення профілю користувача Sharepoint"); try { UpdateSPProfile(sharepointUrl, login, null); } catch (Exception ex) { MessageBox.Show("Сталася помилка під час оновлення профілю Sharepoint:\r\n\r\n" + ex.Message, "Завантажити файл", MessageBoxButtons.OK, MessageBoxIcon.Error); } formWait.Close(); } ReadPictureFromDB(); }
private void UploadPictureToDB() { if (!m_bUploadPending) return; if (!System.IO.Directory.Exists(openFileDialogImage.FileName) == false) { MessageBox.Show("Файл \"" + openFileDialogImage.FileName + "\" не знайден!", "Загрузка фото", MessageBoxButtons.OK, MessageBoxIcon.Warning); m_bUploadPending = false; buttonUpload.Enabled = false; return; } Byte[] byteImage = null; bool updateSPProfile = true; // Update OmniTrack custom database FormWait formWait = new FormWait("Оновлення бази даних"); try { Image image = System.Drawing.Image.FromFile(openFileDialogImage.FileName); byteImage = System.IO.File.ReadAllBytes(openFileDialogImage.FileName); string sFileName = System.IO.Path.GetFileNameWithoutExtension(openFileDialogImage.FileName); string sFileExt = System.IO.Path.GetExtension(openFileDialogImage.FileName); int nSize = byteImage.Length; int nWidth = image.Width; int nHeight = image.Height; if (m_rowPicture != null) UpdatePicture(image, byteImage, sFileName, sFileExt, nSize, nWidth, nHeight); else InsertPicture(image, byteImage, sFileName, sFileExt, nSize, nWidth, nHeight); formWait.Close(); } catch (Exception ex) { updateSPProfile = false; MessageBox.Show("Сталася помилка під час завантаження файлу:\r\n\r\n" + ex.Message, "Завантажити файл", MessageBoxButtons.OK, MessageBoxIcon.Error); } formWait.Close(); // Update Sharepoint profile if there were no errors while reading file and updating DB if (updateSPProfile && byteImage != null) { string login = GetLogingName(); string sharepointUrl = Properties.Settings.Default.sharepointSite; // User has no SP profile (user name is not specified) or Sharepoint is not configured if (!string.IsNullOrEmpty(login) && !string.IsNullOrEmpty(sharepointUrl)) { formWait = new FormWait("Оновлення профілю користувача Sharepoint"); try { UpdateSPProfile(sharepointUrl, login, byteImage); } catch (Exception ex) { MessageBox.Show("Сталася помилка під час оновлення профілю Sharepoint:\r\n\r\n" + ex.Message, "Завантажити файл", MessageBoxButtons.OK, MessageBoxIcon.Error); } formWait.Close(); } } m_bUploadPending = false; buttonUpload.Enabled = false; ReadPictureFromDB(); }
private void UploadPictureToDB() { if (!m_bUploadPending) { return; } if (!System.IO.Directory.Exists(openFileDialogImage.FileName) == false) { MessageBox.Show("Файл \"" + openFileDialogImage.FileName + "\" не знайден!", "Загрузка фото", MessageBoxButtons.OK, MessageBoxIcon.Warning); m_bUploadPending = false; buttonUpload.Enabled = false; return; } Byte[] byteImage = null; bool updateSPProfile = true; // Update OmniTrack custom database FormWait formWait = new FormWait("Оновлення бази даних"); try { Image image = System.Drawing.Image.FromFile(openFileDialogImage.FileName); byteImage = System.IO.File.ReadAllBytes(openFileDialogImage.FileName); string sFileName = System.IO.Path.GetFileNameWithoutExtension(openFileDialogImage.FileName); string sFileExt = System.IO.Path.GetExtension(openFileDialogImage.FileName); int nSize = byteImage.Length; int nWidth = image.Width; int nHeight = image.Height; if (m_rowPicture != null) { UpdatePicture(image, byteImage, sFileName, sFileExt, nSize, nWidth, nHeight); } else { InsertPicture(image, byteImage, sFileName, sFileExt, nSize, nWidth, nHeight); } formWait.Close(); } catch (Exception ex) { updateSPProfile = false; MessageBox.Show("Сталася помилка під час завантаження файлу:\r\n\r\n" + ex.Message, "Завантажити файл", MessageBoxButtons.OK, MessageBoxIcon.Error); } formWait.Close(); // Update Sharepoint profile if there were no errors while reading file and updating DB if (updateSPProfile && byteImage != null) { string login = GetLogingName(); string sharepointUrl = Properties.Settings.Default.sharepointSite; // User has no SP profile (user name is not specified) or Sharepoint is not configured if (!string.IsNullOrEmpty(login) && !string.IsNullOrEmpty(sharepointUrl)) { formWait = new FormWait("Оновлення профілю користувача Sharepoint"); try { UpdateSPProfile(sharepointUrl, login, byteImage); } catch (Exception ex) { MessageBox.Show("Сталася помилка під час оновлення профілю Sharepoint:\r\n\r\n" + ex.Message, "Завантажити файл", MessageBoxButtons.OK, MessageBoxIcon.Error); } formWait.Close(); } } m_bUploadPending = false; buttonUpload.Enabled = false; ReadPictureFromDB(); }