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(); }
private int SaveCooperatorData() { int errorCount = 0; DataSet cooperatorChanges = new DataSet(); DataSet cooperatorSaveResults = new DataSet(); // Process COOPERATOR... // Make sure the last edited row in the Accessions Form has been commited to the datatable... _cooperatorBindingSource.EndEdit(); // Make sure the navigator is not currently editing a cell... foreach (DataRowView drv in _cooperatorBindingSource.List) { if (drv.IsEdit || drv.Row.RowState == DataRowState.Added || drv.Row.RowState == DataRowState.Deleted || drv.Row.RowState == DataRowState.Detached || drv.Row.RowState == DataRowState.Modified) { drv.EndEdit(); //drv.Row.ClearErrors(); } } // Get the changes (if any) for the accession table and commit them to the remote database... if (_cooperator.GetChanges() != null) { cooperatorChanges.Tables.Add(_cooperator.GetChanges()); ScrubData(cooperatorChanges); // Save the changes to the remote server... cooperatorSaveResults = _sharedUtils.SaveWebServiceData(cooperatorChanges); if (cooperatorSaveResults.Tables.Contains(_cooperator.TableName)) { errorCount += SyncSavedResults(_cooperator, cooperatorSaveResults.Tables[_cooperator.TableName]); } } // Now add the new changes to the _changedRecords dataset (this data will be passed back to the calling program)... if (cooperatorSaveResults != null && cooperatorSaveResults.Tables.Contains(_cooperator.TableName)) { string pkeyName = cooperatorSaveResults.Tables[_cooperator.TableName].PrimaryKey[0].ColumnName; bool origColumnReadOnlyValue = cooperatorSaveResults.Tables[_cooperator.TableName].Columns[pkeyName].ReadOnly; foreach (DataRow dr in cooperatorSaveResults.Tables[_cooperator.TableName].Rows) { dr.Table.Columns[pkeyName].ReadOnly = false; dr[pkeyName] = dr["NewPrimaryKeyID"]; dr.AcceptChanges(); } cooperatorSaveResults.Tables[_cooperator.TableName].Columns[pkeyName].ReadOnly = origColumnReadOnlyValue; if (_changedRecords.Tables.Contains(_cooperator.TableName)) { // If the saved results table exists - update or insert the new records... _changedRecords.Tables[_cooperator.TableName].Load(cooperatorSaveResults.Tables[_cooperator.TableName].CreateDataReader(), LoadOption.Upsert); _changedRecords.Tables[_cooperator.TableName].AcceptChanges(); } else { // If the saved results table doesn't exist - create it (and include the new records)... _changedRecords.Tables.Add(cooperatorSaveResults.Tables[_cooperator.TableName].Copy()); _changedRecords.AcceptChanges(); } } return(errorCount); }