Пример #1
0
        private void SaveScript(string sFileName)
        {
            using (StreamWriter oSW = new StreamWriter(path: sFileName, append: false))
            {
                oSW.WriteLine("/* VERSION: " + m_Version + " */");

                foreach (ListViewItem oItem in lvwDifferences.Items)
                {
                    if (oItem.Checked == true)
                    {
                        object oValue    = oItem.Tag;
                        string sTypeName = oValue.GetType().ToString();

                        if (oValue.GetType() == typeof(SQLAutoDocLib.BLL.Table))
                        {
                            //This is a table
                            SQLAutoDocLib.BLL.Table oTable = (SQLAutoDocLib.BLL.Table)oValue;
                            if (oTable.CurrentlyExists == true)
                            {
                                oSW.WriteLine("/* ALTER */");
                            }
                            else
                            {
                                oSW.WriteLine("/* CREATE */");
                            }

                            SQLAutoDocLib.BLL.Table_Factory oFactory = new SQLAutoDocLib.BLL.Table_Factory();
                            oSW.WriteLine(oFactory.Reconstitute(oTable));
                        }
                        else if (oValue.GetType() == typeof(SQLAutoDocLib.BLL.View))
                        {
                            //This is a view
                            SQLAutoDocLib.BLL.View         oView    = (SQLAutoDocLib.BLL.View)oValue;
                            SQLAutoDocLib.BLL.View_Factory oFactory = new SQLAutoDocLib.BLL.View_Factory();
                            oSW.WriteLine(oFactory.Reconstitute(oView));
                        }
                        else if (oValue.GetType() == typeof(SQLAutoDocLib.BLL.Function))
                        {
                            //This is a function
                            SQLAutoDocLib.BLL.Function         oFunction = (SQLAutoDocLib.BLL.Function)oValue;
                            SQLAutoDocLib.BLL.Function_Factory oFactory  = new SQLAutoDocLib.BLL.Function_Factory();
                            oSW.WriteLine(oFactory.Reconstitute(oFunction));
                        }
                        else if (oValue.GetType() == typeof(SQLAutoDocLib.BLL.Procedure))
                        {
                            //This is a procedure
                            SQLAutoDocLib.BLL.Procedure         oProcedure = (SQLAutoDocLib.BLL.Procedure)oValue;
                            SQLAutoDocLib.BLL.Procedure_Factory oFactory   = new SQLAutoDocLib.BLL.Procedure_Factory();
                            oSW.WriteLine(oFactory.Reconstitute(oProcedure));
                        }
                        else if (oValue.GetType() == typeof(SQLAutoDocLib.BLL.Trigger))
                        {
                            //This is a trigger
                            SQLAutoDocLib.BLL.Trigger         oTrigger = (SQLAutoDocLib.BLL.Trigger)oValue;
                            SQLAutoDocLib.BLL.Trigger_Factory oFactory = new SQLAutoDocLib.BLL.Trigger_Factory();
                            oSW.WriteLine(oFactory.Reconstitute(oTrigger));
                        }
                    }
                }
            }
        }