private void CFunction_Load(object sender, EventArgs e) { _SPName_TextBox.Text = _f.ToString(); _SPHead_richTextBox.Text = _f.TextHeader; _SPBody_richTextBox.Text = _f.TextBody; _Desc_richTextBox.Text = this.Description; if (string.IsNullOrEmpty(this.MethodName)) { _MethodName_textBox.Text = Utils.GetEscapeName(_f); } else { _MethodName_textBox.Text = this.MethodName; } _MethodName_textBox.Text = this.MethodName; foreach (UserDefinedFunctionParameter p in _f.Parameters) { dS.Parms.AddParmsRow(p.Name, false, Utils.GetDescription(p), p.DataType.Name, p.DataType.MaximumLength, p.DataType.NumericPrecision, p.DataType.NumericScale, p.DefaultValue); } dS.Parms.ParmsRowChanged += new DS.ParmsRowChangeEventHandler(Parms_ParmsRowChanged); if (_f.FunctionType == UserDefinedFunctionType.Table || _f.FunctionType == UserDefinedFunctionType.Inline) { //todo: 多字段组合主键 的表达 //todo: 多字段组合唯一索引 的表达 foreach (Column c in _f.Columns) { int i = _Result_dataGridView.Rows.Add((c.InPrimaryKey ? Properties.Resources.SQL_Key : (c.IsForeignKey ? Properties.Resources.SQL_ForeignKey : Properties.Resources.SQL_Empty)), c.Name, Utils.GetCaption(c), Utils.GetDescription(c), c.DataType.Name, c.DataType.MaximumLength, c.Nullable, c.InPrimaryKey, c.Computed); _Result_dataGridView.Rows[i].Tag = c; } } }
public bool Process(SqlSmoObject[] objects, int start) { if (objects == null) { return(AsyncProcessingStatus.CancelProcessing); } SqlSmoObject[] sso = new SqlSmoObject[1]; StringCollection tableForeignKey = new StringCollection(); StringCollection extendedProperties = new StringCollection(); StringCollection bcpOutputCommands = new StringCollection(); StringCollection bcpTargetCommands = new StringCollection(); double step = ((100 - start) / (double)objects.Count()); int loopCnt = 0; bool oldSQLdb = _smoScriptOpts.TargetServer.Equals(Properties.Resources.ServerType_AzureSQLDatabase); List <string> listAssemblyUDF = new List <string>(); List <string> listEncryptedUDF = new List <string>(); List <string> listEncryptedView = new List <string>(); List <string> listAssemblySP = new List <string>(); List <string> listEncryptedSP = new List <string>(); List <string> listAssemblyDDLT = new List <string>(); List <string> listEncryptedDDLT = new List <string>(); foreach (SqlSmoObject obj in objects) { loopCnt++; _eventArgs.StatusMsg = CommonFunc.FormatString(Properties.Resources.ScriptingObj, obj.ToString()); _eventArgs.PercentComplete = (int)(loopCnt * step); _updateStatus(_eventArgs); sso[0] = obj; switch (obj.Urn.Type) { case "Table": _sdb.ScriptTables(sso, ref tableForeignKey, ref extendedProperties, ref bcpOutputCommands, ref bcpTargetCommands, ref _outputDir); break; case "UserDefinedFunction": UserDefinedFunction udf = (UserDefinedFunction)obj; if (udf.IsEncrypted) { if (udf.AssemblyName.Length > 0) { if (oldSQLdb) { listAssemblyUDF.Add(udf.TextBody); } else { _sdb.ScriptUDF(sso); } } else { listEncryptedUDF.Add(udf.ToString()); } } else { _sdb.ScriptUDF(sso); } break; case "View": View vw = (View)obj; if (vw.IsEncrypted) { listEncryptedView.Add(vw.ToString()); } else { _sdb.ScriptViews(sso); } break; case "StoredProcedure": StoredProcedure proc = (StoredProcedure)obj; if (proc.IsEncrypted) { if (proc.AssemblyName.Length > 0) { if (oldSQLdb) { listAssemblySP.Add(proc.TextBody); } else { _sdb.ScriptProcedures(sso); } } else { listEncryptedSP.Add(proc.ToString()); } } else { _sdb.ScriptProcedures(sso); } break; case "DdlTrigger": DatabaseDdlTrigger ddlt = (DatabaseDdlTrigger)obj; if (ddlt.IsEncrypted) { if (ddlt.AssemblyName.Length > 0) { if (oldSQLdb) { listAssemblyDDLT.Add(ddlt.TextBody); } else { _sdb.ScriptTriggers(sso); } } else { listEncryptedDDLT.Add(ddlt.ToString()); } } else { _sdb.ScriptTriggers(sso); } break; } if (AsyncProcessingStatus.CancelProcessing) { _eventArgs.StatusMsg = Properties.Resources.MessageCanceled; _eventArgs.DisplayColor = Color.DarkCyan; _eventArgs.DisplayText = CommonFunc.FormatString(Properties.Resources.MessageCanceledProcessing, DateTime.Now.ToString(CultureInfo.CurrentCulture)) + Environment.NewLine; _eventArgs.PercentComplete = 100; _updateStatus(_eventArgs); return(AsyncProcessingStatus.CancelProcessing); } } OutputNotSupported(Properties.Resources.ObjectTypeUDF, listAssemblyUDF); OutputIsEncrypted(Properties.Resources.ObjectTypeUDF, listEncryptedUDF); OutputIsEncrypted(Properties.Resources.ObjectTypeViews, listEncryptedView); OutputNotSupported(Properties.Resources.ObjectTypeStoredProcedures, listAssemblySP); OutputIsEncrypted(Properties.Resources.ObjectTypeStoredProcedures, listEncryptedSP); OutputNotSupported(Properties.Resources.ObjectTypeTriggers, listAssemblyDDLT); OutputIsEncrypted(Properties.Resources.ObjectTypeTriggers, listEncryptedDDLT); _eventArgs.StatusMsg = CommonFunc.FormatString(Properties.Resources.ForiegnKeys); _updateStatus(_eventArgs); // Ok, due to dependency issues, we need to move the foreign key constraints to the end. // But there is some small problem in that SQL Server allows for a DBA to have circular dependencies. So // in order to solve this problem, we need to upload the data to the circular dependent tables first // with no foreign keys, add foreign key constraints, and then upload the rest of the data. The // reason that the data it not all uploaded before the foreign key constraints is to avoid performance // issues with adding foreign key constraints after the fact. if (_smoScriptOpts.ScriptForeignKeys == true) { _sdb.ScriptStringCollection(ref tableForeignKey, Color.Black); } if (_smoScriptOpts.ScriptExtendedProperties == true) { _sdb.ScriptStringCollection(ref extendedProperties, Color.Black); } if (bcpTargetCommands.Count > 0) { _sdb.ScriptStringCollection(ref bcpTargetCommands, Color.Green); } if (bcpOutputCommands.Count > 0) { _sdb.OutputAnalysisLine(Environment.NewLine + Properties.Resources.BCPOutputSummary, Color.Green); foreach (string bcpOutputCommand in bcpOutputCommands) { _sdb.OutputAnalysisLine(bcpOutputCommand, Color.Green); } } return(AsyncProcessingStatus.CancelProcessing); }