public static string Run(ITableSource src, IDatabaseSource dst, out bool copydata, out TableCopyOptions opts) { CopyTableForm win = new CopyTableForm(src, dst); DialogResult res = win.ShowDialogEx(); copydata = win.cbcopydata.Checked; opts = win.GetCopyOptions(); if (res == DialogResult.OK) { return(win.tbltblname.Text); } return(null); }
public void DragDrop_CopyTable(AppObject appobj) { //var tobj = appobj as TableAppObject; //if (tobj == null) return; var conn = this.FindDatabaseConnection(); ITableSource tsource = appobj.TableSource; TableStructure tbl = new TableStructure(tsource.InvokeLoadStructure(TableStructureMembers.AllNoRefs)); TableCopyOptions opts; bool copydata; string newname = CopyTableForm.Run(tsource, conn, out copydata, out opts); if (newname == null) { return; } List <NameWithSchema> names = new List <NameWithSchema>(conn.InvokeLoadFullTableNames()); if (ArrayTool.Contains(names, new NameWithSchema(newname))) { StdDialog.ShowError(Texts.Get("s_table_allready_exists")); return; } tbl.FullName = new NameWithSchema(newname); if (conn.Dialect != null) { conn.Dialect.MigrateTable(tbl, conn.Dialect.CreateMigrationProfile(), null); } tbl.RemoveConstraints <IForeignKey>(); PrimaryKey pk = (PrimaryKey)TableStructureExtension.FindConstraint <IPrimaryKey>(tbl); if (pk != null && pk.Name != null && pk.Name.ToUpper().StartsWith("PK_")) { pk.Name = "PK_" + tbl.Name; } try { ITableSource dst = conn.CreateTable(tbl); if (copydata) { BulkCopyJob.Create(tsource.GetDataStoreAndClone(), dst.GetDataStoreAndClone(), new IdentityTransform(tbl), opts, null).StartProcess(); } } catch (Exception e) { Errors.Report(e); } }