private void btnSaveToServer_Click(object sender, EventArgs e) { //we show where data will be saved to, prompt if there's need to chaneg the connection var serverConfig = new frmServerConfig() { StartPosition = FormStartPosition.CenterParent }; if (serverConfig.ShowDialog() == DialogResult.OK) { //we get valuesDataset var ds = valuesDataset; if (ds.Tables.Count == 0) { MessageBox.Show("Nothing to export"); return; } var tempTableName = new RandomTableNameGenerator().Execute(); valuesDataset.Tables[0].TableName = tempTableName; var dataImporter = new SaveTableToDbCommand() { TargetDataset = valuesDataset }; dataImporter.Execute(); //we start the merge var dataMerge = new DataMergeCommand() { TempTableName = tempTableName, DestinationTable = "FacilityData" }; // we save, dataMerge.Execute(); EnableSaveButtons(false); lblSelectedFile.Text = "No file selected"; //and show the confirmatin that the file has been saved //perhaps show a tick //MessageBox.Show("Merge completed"); //we clear the grid ShowGridDisplayPort(null); //dataGridView1.DataSource = ""; } else { btnSaveToCsv.EnableControl(true); btnSaveToServer.EnableControl(false); } }
void SaveToServer(bool saveToDevServer) { //we get valuesDataset if (ExcelDataValues == null || ExcelDataValues.Count == 0) { return; } var valuesDataset = ExcelDataValues.ToDataset(); if (valuesDataset.Tables.Count == 0) { MessageBox.Show("Nothing to export"); return; } var tempTableName = new RandomTableNameGenerator().Execute(); valuesDataset.Tables[0].TableName = tempTableName; var connBuilder = DbFactory.GetDefaultConnection(CurrentProjectName, saveToDevServer); if (connBuilder == null) { return; } var contextDb = new DbHelper(connBuilder); try { var dataImporter = new SaveTableToDbCommand() { TargetDataset = valuesDataset, Db = contextDb }; dataImporter.Execute(); } catch { throw; } try { //we start the merge var dataMerge = new DataMergeCommand() { TempTableName = tempTableName, DestinationTable = "FacilityData", Db = contextDb }; // we save, dataMerge.Execute(); } catch (Exception ex) { throw; } finally { tHelpfulTip.Content = "Select Files to Import"; ResetAllGrids(); } }