private void ux_buttonLoad_Click(object sender, EventArgs e) { _imageDGV.ReadOnly = true; ux_progressbarLoading.Show(); ux_progressbarLoading.Minimum = 0; ux_progressbarLoading.Maximum = _imageDGV.Rows.Count; ux_progressbarLoading.Step = 1; foreach (DataGridViewRow dgvr in _imageDGV.Rows) { string remotePath = ""; // Get the byte array for the image... byte[] imageBytes = System.IO.File.ReadAllBytes(dgvr.Cells["image_file_physical_path"].Value.ToString()); // Attempt to upload the image to the remote server... if (imageBytes != null && !string.IsNullOrEmpty(dgvr.Cells["virtual_path"].Value.ToString())) { remotePath = _sharedUtils.SaveImage(dgvr.Cells["virtual_path"].Value.ToString(), imageBytes, true, true); } // If the upload was successful the remotePath will contain the destination path (so now we can insert the record)... if (!string.IsNullOrEmpty(remotePath)) { // See if any records already exist for this inventory_id and if so update it // otherwise insert a new record... DataSet ds = _sharedUtils.GetWebServiceData("get_accession_inv_attach", ":inventoryid=" + ((DataRowView)dgvr.DataBoundItem).Row["inventory_id"].ToString() + "; :accessionid=; :orderrequestid=; :cooperatorid=;", 0, 0); if (ds.Tables.Contains("get_accession_inv_attach")) { DataRow[] inventoryImageRows = ds.Tables["get_accession_inv_attach"].Select("virtual_path='" + dgvr.Cells["virtual_path"].Value.ToString() + "'"); // This row does not exist - so create a new record... if (inventoryImageRows != null && inventoryImageRows.Length == 0) { DataRow newInventoryImageRow = ds.Tables["get_accession_inv_attach"].NewRow(); newInventoryImageRow["accession_inv_attach_id"] = -1; newInventoryImageRow["inventory_id"] = ((DataRowView)dgvr.DataBoundItem).Row["inventory_id"]; newInventoryImageRow["virtual_path"] = dgvr.Cells["virtual_path"].Value; newInventoryImageRow["thumbnail_virtual_path"] = dgvr.Cells["thumbnail_virtual_path"].Value; //newInventoryImageRow["sort_order"] = dgvr.Cells["sort_order"].Value; //newInventoryImageRow["title"] = dgvr.Cells["title"].Value; //newInventoryImageRow["description"] = dgvr.Cells["description"].Value; //newInventoryImageRow["content_type"] = dgvr.Cells["content_type"].Value; newInventoryImageRow["category_code"] = dgvr.Cells["category_code"].Value; newInventoryImageRow["is_web_visible"] = dgvr.Cells["is_web_visible"].Value; newInventoryImageRow["note"] = dgvr.Cells["note"].Value; ds.Tables["get_accession_inv_attach"].Rows.Add(newInventoryImageRow); } // The row exists already (probably because it was previously uploaded) - so update the first existing record... else if (inventoryImageRows != null && inventoryImageRows.Length > 0) { inventoryImageRows[0]["virtual_path"] = dgvr.Cells["virtual_path"].Value; inventoryImageRows[0]["thumbnail_virtual_path"] = dgvr.Cells["thumbnail_virtual_path"].Value; //newInventoryImageRow["sort_order"] = dgvr.Cells["sort_order"].Value; //newInventoryImageRow["title"] = dgvr.Cells["title"].Value; //newInventoryImageRow["description"] = dgvr.Cells["description"].Value; //newInventoryImageRow["content_type"] = dgvr.Cells["content_type"].Value; inventoryImageRows[0]["category_code"] = dgvr.Cells["category_code"].Value; inventoryImageRows[0]["is_web_visible"] = dgvr.Cells["is_web_visible"].Value; inventoryImageRows[0]["note"] = dgvr.Cells["note"].Value; } // Get the changes that need to be committed to the remote database... DataSet modifiedData = new DataSet(); modifiedData.Tables.Add(ds.Tables["get_accession_inv_attach"].GetChanges()); if (modifiedData.Tables.Contains("get_accession_inv_attach")) { _sharedUtils.SaveWebServiceData(modifiedData); } } } ux_progressbarLoading.PerformStep(); } // Close the form... this.Close(); }