Пример #1
0
        private static void WriteReport(ExcelXmlWriter ew, string reportName)
        {
            // Report Form
            System.Data.DataTable dt4 = Feng.Data.DbHelper.Instance.ExecuteDataTable("SELECT * FROM AD_Report WHERE Name = '" + reportName + "'");
            ew.WriteExcelXml(dt4, "AD_Report");

            if (dt4.Rows.Count > 0)
            {
                System.Data.DataRow row = dt4.Rows[0];
                System.Data.DataTable dt6 = Feng.Data.DbHelper.Instance.ExecuteDataTable("SELECT * FROM AD_Report_Data WHERE Report = '" + row["Name"].ToString() + "'");
                ew.WriteExcelXml(dt6, "AD_Report_Data");

                WriteGrid(ew, dt6);
            }
        }
Пример #2
0
        private static void WriteWindowForm(ExcelXmlWriter ew, string windowName, string formName)
        {
            System.Data.DataTable dt2 = Feng.Data.DbHelper.Instance.ExecuteDataTable("SELECT * FROM AD_Window WHERE Name = '" + windowName + "'");
            ew.WriteExcelXml(dt2, "AD_Window");
            System.Data.DataTable dt3 = Feng.Data.DbHelper.Instance.ExecuteDataTable("SELECT * FROM AD_Form WHERE Name = '" + formName + "'");
            ew.WriteExcelXml(dt3, "AD_Form");

            if (dt2.Rows.Count > 0)
            {
                dt3 = Feng.Data.DbHelper.Instance.ExecuteDataTable("SELECT * FROM AD_Window_Tab WHERE Window = '" + dt2.Rows[0]["Name"].ToString() + "'");
                ew.WriteExcelXml(dt3, "AD_Window_Tab");

                System.Data.DataTable dt4 = Feng.Data.DbHelper.Instance.ExecuteDataTable("SELECT * FROM AD_Window_Menu WHERE Window = '" + dt2.Rows[0]["Name"].ToString() + "'");
                ew.WriteExcelXml(dt4, "AD_Window_Menu");

                foreach (System.Data.DataRow row in dt4.Rows)
                {
                    System.Data.DataTable dt6 = Feng.Data.DbHelper.Instance.ExecuteDataTable("SELECT * FROM AD_Process WHERE Name = '" + row["ExecuteParam"].ToString() + "'");
                    ew.WriteExcelXml(dt6, "AD_Process");
                }

                if (dt2.Rows[0]["WindowType"].ToString() == "5")
                {
                    WriteReport(ew, dt2.Rows[0]["Name"].ToString());
                }
                else
                {
                    WriteGrid(ew, dt3);
                }

                WriteWindowForm(ew, dt2.Rows[0]["DetailWindow"].ToString(), dt2.Rows[0]["DetailForm"].ToString());
            }
        }
Пример #3
0
 private static void ExportSingleTable(string dirPath, string tableName)
 {
     using (ExcelXmlWriter ew = new ExcelXmlWriter(dirPath + "\\" + tableName + ".xml"))
     {
         ew.WriteExcelXml(Feng.Data.DbHelper.Instance.ExecuteDataTable("SELECT * FROM " + tableName), tableName);
     }
 }
Пример #4
0
        private static void WriteGrid(ExcelXmlWriter ew, System.Data.DataTable dt3)
        {
            System.Data.DataTable dt4 = null;
            foreach (System.Data.DataRow row in dt3.Rows)
            {
                dt4 = Feng.Data.DbHelper.Instance.ExecuteDataTable("SELECT * FROM AD_Grid WHERE GridName = '" + row["GridName"].ToString() + "'");
                ew.WriteExcelXml(dt4, "AD_Grid");
            }

            System.Data.DataTable dt5;

            foreach (System.Data.DataRow row in dt3.Rows)
            {
                dt4 = Feng.Data.DbHelper.Instance.ExecuteDataTable("SELECT * FROM AD_Grid_Column WHERE GridName = '" + row["GridName"].ToString() + "'");
                ew.WriteExcelXml(dt4, "AD_Grid_Column");

                foreach (System.Data.DataRow row1 in dt4.Rows)
                {
                    string gridColumnName = null;
                    if (row1["GridColumnName"] != System.DBNull.Value)
                        gridColumnName = row1["GridColumnName"].ToString();
                    else if (row1["Navigator"] != System.DBNull.Value)
                        gridColumnName = row1["Navigator"].ToString() + "." + row1["PropertyName"].ToString();
                    else
                        gridColumnName = row1["PropertyName"].ToString();
                    dt5 = Feng.Data.DbHelper.Instance.ExecuteDataTable("SELECT * FROM AD_Grid_Column_Warning WHERE GroupName = '" + gridColumnName + "'");
                    ew.WriteExcelXml(dt5, "AD_Grid_Column_Warning");
                }
            }

            foreach (System.Data.DataRow row in dt3.Rows)
            {
                dt5 = Feng.Data.DbHelper.Instance.ExecuteDataTable("SELECT * FROM AD_Grid_Row WHERE GridName = '" + row["GridName"].ToString() + "'");
                ew.WriteExcelXml(dt5, "AD_Grid_Row");
            }

            foreach (System.Data.DataRow row in dt3.Rows)
            {
                dt5 = Feng.Data.DbHelper.Instance.ExecuteDataTable("SELECT * FROM AD_Grid_Cell WHERE GridName = '" + row["GridName"].ToString() + "'");
                ew.WriteExcelXml(dt5, "AD_Grid_Cell");
            }

            foreach (System.Data.DataRow row in dt3.Rows)
            {
                dt5 = Feng.Data.DbHelper.Instance.ExecuteDataTable("SELECT * FROM AD_Grid_Related WHERE GridName = '" + row["GridName"].ToString() + "'");
                ew.WriteExcelXml(dt5, "AD_Grid_Related");
            }

            foreach (System.Data.DataRow row in dt3.Rows)
            {
                dt5 = Feng.Data.DbHelper.Instance.ExecuteDataTable("SELECT * FROM AD_Grid_Group WHERE GridName = '" + row["GridName"].ToString() + "'");
                ew.WriteExcelXml(dt5, "AD_Grid_Group");
            }

            foreach (System.Data.DataRow row in dt3.Rows)
            {
                dt5 = Feng.Data.DbHelper.Instance.ExecuteDataTable("SELECT * FROM AD_Grid_Filter WHERE GridName = '" + row["GridName"].ToString() + "'");
                ew.WriteExcelXml(dt5, "AD_Grid_Filter");
            }
        }
Пример #5
0
        /// <summary>
        /// 把现有数据库中的所有配置保存到数据文件中(多个文件)
        /// </summary>
        /// <param name="dirPath"></param>
        public static void ExportAllToPath(string dirPath)
        {
            Feng.Utils.IOHelper.TryCreateDirectory(dirPath + s_exportPathOthers);
            Feng.Utils.IOHelper.TryCreateDirectory(dirPath + s_exportPathMenus);
            Feng.Utils.IOHelper.TryCreateDirectory(dirPath + s_exportPathWindows);
            Feng.Utils.IOHelper.TryCreateDirectory(dirPath + s_exportPathReports);
            Feng.Utils.IOHelper.TryCreateDirectory(dirPath + s_exportPathSelectWindows);

            // Others
            using (ExcelXmlWriter ew = new ExcelXmlWriter(dirPath + s_exportPathOthers + "\\AD_Alerts.xml"))
            {
                ew.WriteExcelXml(Feng.Data.DbHelper.Instance.ExecuteDataTable("SELECT * FROM AD_AlertRule"), "AD_AlertRule");
                ew.WriteExcelXml(Feng.Data.DbHelper.Instance.ExecuteDataTable("SELECT * FROM AD_Task"), "AD_Task");
            }

            using (ExcelXmlWriter ew = new ExcelXmlWriter(dirPath + s_exportPathOthers + "\\AD_MultiOrgs.xml"))
            {
                ew.WriteExcelXml(Feng.Data.DbHelper.Instance.ExecuteDataTable("SELECT * FROM AD_Client"), "AD_Client");
                ew.WriteExcelXml(Feng.Data.DbHelper.Instance.ExecuteDataTable("SELECT * FROM Ad_Org"), "Ad_Org");
            }

            using (ExcelXmlWriter ew = new ExcelXmlWriter(dirPath + s_exportPathOthers + "\\AD_Buffers.xml"))
            {
                ew.WriteExcelXml(Feng.Data.DbHelper.Instance.ExecuteDataTable("SELECT * FROM AD_EntityBuffer"), "AD_EntityBuffer");
                ew.WriteExcelXml(Feng.Data.DbHelper.Instance.ExecuteDataTable("SELECT * FROM AD_NameValueMapping"), "AD_NameValueMapping");
                ew.WriteExcelXml(Feng.Data.DbHelper.Instance.ExecuteDataTable("SELECT * FROM AD_SimpleParam"), "AD_SimpleParam");
                ew.WriteExcelXml(Feng.Data.DbHelper.Instance.ExecuteDataTable("SELECT * FROM AD_Param_Creator"), "AD_Param_Creator");

            }

            ExportSingleTable(dirPath + s_exportPathOthers, "AD_Search_Custom");
            ExportSingleTable(dirPath + s_exportPathOthers, "AD_EventProcess");
            ExportSingleTable(dirPath + s_exportPathOthers, "AD_Server_TaskSchedule");
            ExportSingleTable(dirPath + s_exportPathOthers, "AD_Process");
            ExportSingleTable(dirPath + s_exportPathOthers, "AD_Web_Service");
            ExportSingleTable(dirPath + s_exportPathOthers, "AD_Command_Binding");
            ExportSingleTable(dirPath + s_exportPathOthers, "AD_Plugin");
            ExportSingleTable(dirPath + s_exportPathOthers, "AD_Resource");
            ExportSingleTable(dirPath + s_exportPathOthers, "AD_Resource");
            ExportSingleTable(dirPath + s_exportPathOthers, "AD_Resource");
            ExportSingleTable(dirPath + s_exportPathOthers, "AD_Resource");

            // Select Window
            System.Data.DataTable dt = Feng.Data.DbHelper.Instance.ExecuteDataTable("SELECT * FROM Ad_Window_Select");
            foreach (System.Data.DataRow row in dt.Rows)
            {
                using (ExcelXmlWriter ew = new ExcelXmlWriter(dirPath + s_exportPathSelectWindows + "\\AD_WindowSelect_" + row["Name"].ToString() + ".xml"))
                {
                    System.Data.DataTable dt2 = DbHelper.Instance.ExecuteDataTable("SELECT * FROM Ad_Window_Select WHERE NAME = '" + row["Name"].ToString() + "'");
                    ew.WriteExcelXml(dt2, "Ad_Window_Select");

                    WriteWindowForm(ew, row["Window"].ToString(), row["Form"].ToString());
                }
            }

            // Menus(main)
            IList<MenuInfo> menus;
            using (var rep = GenerateRepository())
            {
                menus = rep.List<MenuInfo>(NHibernate.Criterion.DetachedCriteria.For<MenuInfo>()
                .Add(NHibernate.Criterion.Expression.IsNotNull("ParentMenu")));
            }

            foreach (MenuInfo menuInfo in menus)
            {
                using (ExcelXmlWriter ew = new ExcelXmlWriter(dirPath + s_exportPathMenus + "\\AD_Menu_" + menuInfo.Name + ".xml"))
                {
                    string sql = "SELECT * FROM AD_Menu WHERE Name = '" + menuInfo.Name + "'";
                    dt = DbHelper.Instance.ExecuteDataTable(sql);
                    string parentName = (string)dt.Rows[0]["ParentMenu"];
                    ew.WriteExcelXml(dt, "AD_Menu");
                    while (true)
                    {
                        string sql2 = "SELECT * FROM AD_Menu WHERE Name = '" + parentName + "'";
                        System.Data.DataTable dtt = DbHelper.Instance.ExecuteDataTable(sql2);

                        if (dtt.Rows[0]["ParentMenu"] == System.DBNull.Value)
                            break;
                        parentName = (string)dtt.Rows[0]["ParentMenu"];
                        ew.WriteExcelXml(dtt, "AD_Menu");
                    }

                    if (menuInfo.Action != null)
                    {
                        dt = Feng.Data.DbHelper.Instance.ExecuteDataTable("SELECT * FROM AD_Action WHERE Name = '" + menuInfo.Action.Name + "'");
                        ew.WriteExcelXml(dt, "AD_Action");

                        if (dt.Rows[0]["ActionType"].ToString() == "2")
                        {
                            System.Data.DataTable dt3 = Feng.Data.DbHelper.Instance.ExecuteDataTable("SELECT * FROM AD_Process WHERE Name = '" + dt.Rows[0]["Process"].ToString() + "'");
                            ew.WriteExcelXml(dt3, "AD_Process");
                        }
                        else
                        {
                            WriteWindowForm(ew, dt.Rows[0]["Window"].ToString(), dt.Rows[0]["Form"].ToString());
                        }
                    }
                }
            }

            // Windows
            IList<WindowInfo> windows;
            using (IRepository rep = ServiceProvider.GetService<IRepositoryFactory>().GenerateRepository(typeof(WindowInfo)))
            {
                windows = rep.List<WindowInfo>();
            }
            foreach (WindowInfo windowInfo in windows)
            {
                using (ExcelXmlWriter ew = new ExcelXmlWriter(dirPath + s_exportPathWindows + "\\AD_Window_" + windowInfo.Name + ".xml"))
                {
                    WriteWindowForm(ew, windowInfo.Name, null);
                }
            }

            // Report
            IList<ReportInfo> reports;
            using (IRepository rep = GenerateRepository())
            {
                reports = rep.List<ReportInfo>();
            }
            foreach (ReportInfo reportInfo in reports)
            {
                using (ExcelXmlWriter ew = new ExcelXmlWriter(dirPath + s_exportPathReports + "\\AD_Report_" + reportInfo.Name + ".xml"))
                {
                    WriteReport(ew, reportInfo.Name);
                }
            }
        }
Пример #6
0
        /// <summary>
        /// 按照Module定义信息打包Module
        /// </summary>
        /// <param name="moduleName"></param>
        public static void PackageModule(string moduleName)
        {
            CreateNecessaryDirectories(moduleName);

            string dir = System.IO.Directory.GetCurrentDirectory() + "\\" + moduleName;

            // Write ModuleInfo
            DataTable dt;
            dt = DbHelper.Instance.ExecuteDataTable("SELECT * FROM AD_Module WHERE NAME = '" + moduleName + "'");
            foreach (System.Data.DataRow row in dt.Rows)
            {
                row["ModuleData"] = System.DBNull.Value;
            }
            using (ExcelXmlWriter ew = new ExcelXmlWriter(dir + "\\src-db\\database\\sourcedata\\AD_Module.xml"))
            {
                ew.WriteExcelXml(dt, "AD_Module");
            }
            dt = DbHelper.Instance.ExecuteDataTable("SELECT * FROM AD_Module_Dependency WHERE Module = '" + moduleName + "'");
            using (ExcelXmlWriter ew = new ExcelXmlWriter(dir + "\\src-db\\database\\sourcedata\\AD_Module_Dependency.xml"))
            {
                ew.WriteExcelXml(dt, "AD_Module_Dependency");
            }
            dt = DbHelper.Instance.ExecuteDataTable("SELECT * FROM AD_Module_Include WHERE Module = '" + moduleName + "'");
            using (ExcelXmlWriter ew = new ExcelXmlWriter(dir + "\\src-db\\database\\sourcedata\\AD_Module_Include.xml"))
            {
                ew.WriteExcelXml(dt, "AD_Module_Include");
            }

            // Write Module Include Info
            foreach (System.Data.DataRow includeInfo in dt.Rows)
            {
                switch ((ModuleIncludeType)includeInfo["ModuleIncludeType"])
                {
                    case ModuleIncludeType.ReferenceData:
                        {
                            dt = DbHelper.Instance.ExecuteDataTable("SELECT * FROM " + includeInfo["Params"].ToString());
                            using (ExcelXmlWriter ew = new ExcelXmlWriter(dir + "\\referencedata\\standard\\" + includeInfo["Params"].ToString() + ".xml"))
                            {
                                ew.WriteExcelXml(dt, includeInfo["Params"].ToString());
                            }
                        }
                        break;
                    case ModuleIncludeType.ApplicationDictionaryData:
                        {
                            dt = DbHelper.Instance.ExecuteDataTable("SELECT * FROM " + includeInfo["Params"].ToString());
                            using (ExcelXmlWriter ew = new ExcelXmlWriter(dir + "\\src-db\\database\\sourcedata\\" + includeInfo["Params"].ToString() + ".xml"))
                            {
                                ew.WriteExcelXml(dt, includeInfo["Params"].ToString());
                            }
                        }
                        break;
                    //case ModuleIncludeType.DbTable:
                    //    {
                    //        string script = includeInfo["Params"].ToString();
                    //        DbHelper.Instance.ExecuteNonQuery(script);
                    //    }
                    //    break;
                    case ModuleIncludeType.DbView:
                        {
                            string script = DbHelper.Instance.GetSqlObjectDefinition(includeInfo["Params"].ToString());
                            using (System.IO.StreamWriter sw = new System.IO.StreamWriter(dir + "\\src-db\\database\\model\\views\\" + includeInfo["Params"].ToString(), false, Encoding.UTF8))
                            {
                                sw.Write(script);
                            }
                        }
                        break;
                    case ModuleIncludeType.DbFunction:
                        {
                            string script = DbHelper.Instance.GetSqlObjectDefinition(includeInfo["Params"].ToString());
                            using (System.IO.StreamWriter sw = new System.IO.StreamWriter(dir + "\\src-db\\database\\model\\functions\\" + includeInfo["Params"].ToString(), false, Encoding.UTF8))
                            {
                                sw.Write(script);
                            }
                        }
                        break;
                    case ModuleIncludeType.DbTrigger:
                        {
                            string script = DbHelper.Instance.GetSqlObjectDefinition(includeInfo["Params"].ToString());
                            using (System.IO.StreamWriter sw = new System.IO.StreamWriter(dir + "\\src-db\\database\\model\\triggers\\" + includeInfo["Params"].ToString(), false, Encoding.UTF8))
                            {
                                sw.Write(script);
                            }
                        }
                        break;
                    case ModuleIncludeType.DbProcedure:
                        {
                            string script = DbHelper.Instance.GetSqlObjectDefinition(includeInfo["Params"].ToString());
                            using (System.IO.StreamWriter sw = new System.IO.StreamWriter(dir + "\\src-db\\database\\model\\procedures\\" + includeInfo["Params"].ToString(), false, Encoding.UTF8))
                            {
                                sw.Write(script);
                            }
                        }
                        break;
                    //case ModuleIncludeType.SourceModel:
                    //    {
                    //        string fileName = includeInfo["Params"].ToString();
                    //        string newFileName = null;
                    //        System.IO.File.Copy(fileName, newFileName);
                    //    }
                    //    break;
                    //case ModuleIncludeType.SourceScript:
                    //    {
                    //        string fileName = includeInfo["Params"].ToString();
                    //        string newFileName = null;
                    //        System.IO.File.Copy(fileName, newFileName);
                    //    }
                    //    break;
                    //case ModuleIncludeType.SourceReport:
                    //    {
                    //        string fileName = includeInfo["Params"].ToString();
                    //        string newFileName = null;
                    //        System.IO.File.Copy(fileName, newFileName);
                    //    }
                    //    break;
                    default:
                        throw new NotSupportedException("ModuleIncludeType");
                }

            }

            // zip
            string zipFile = dir + "\\..\\" + moduleName + ".zip";
            CompressionHelper.ZipFromFolder(dir, zipFile);

            byte[] data;
            using (System.IO.FileStream fs = new System.IO.FileStream(zipFile, System.IO.FileMode.Open))
            {
                data = new byte[fs.Length];
                fs.Read(data, 0, data.Length);
            }

            using (var rep = ServiceProvider.GetService<IRepositoryFactory>().GenerateRepository<ModuleInfo>())
            {
                try
                {
                    rep.BeginTransaction();
                    IList<ModuleInfo> modules = (rep as Feng.NH.INHibernateRepository).Session
                        .CreateCriteria<ModuleInfo>()
                        .Add(NHibernate.Criterion.Expression.Eq("Name", moduleName))
                        .List<ModuleInfo>();
                    modules[0].ModuleData = data;
                    rep.Update(modules[0]);

                    rep.CommitTransaction();
                }
                catch (Exception ex)
                {
                    rep.RollbackTransaction();
                    ExceptionProcess.ProcessWithNotify(ex);
                }
            }
        }
Пример #7
0
        /// <summary>
        /// 把当前数据库的所有内容作为一个模块Export
        /// </summary>
        /// <param name="moduleName"></param>
        public static void PackageCurrentDatabase(string moduleName)
        {
            CreateNecessaryDirectories(moduleName);

            string dir = System.IO.Directory.GetCurrentDirectory() + "\\" + moduleName;

            string[] userDataTables = DbHelper.GetUserDataTables();
            foreach (string s in userDataTables)
            {
                System.Data.DataTable dt = Feng.Data.DbHelper.Instance.ExecuteDataTable("SELECT * FROM " + s);
                if (dt.Rows.Count > 0)
                {
                    using (ExcelXmlWriter ew = new ExcelXmlWriter(moduleName + "\\referencedata\\standard\\" + s + ".xml"))
                    {
                        ew.WriteExcelXml(dt, s);
                    }
                }
            }

            System.Data.DataTable views = DbHelper.GetViewFuncProcTrigs();
            foreach (System.Data.DataRow row in views.Rows)
            {
                if (row["type"].ToString() == "Function")
                {
                    using (System.IO.StreamWriter sw = new System.IO.StreamWriter(moduleName + "\\src-db\\database\\model\\functions\\" + row["name"].ToString(), false, Encoding.UTF8))
                    {
                        sw.Write(row["definition"].ToString());
                    }
                }
            }

            foreach (System.Data.DataRow row in views.Rows)
            {
                if (row["type"].ToString() == "Trigger")
                {
                    using (System.IO.StreamWriter sw = new System.IO.StreamWriter(moduleName + "\\src-db\\database\\model\\triggers\\" + row["name"].ToString(), false, Encoding.UTF8))
                    {
                        sw.Write(row["definition"].ToString());
                    }
                }
            }

            foreach (System.Data.DataRow row in views.Rows)
            {
                if (row["type"].ToString() == "View")
                {
                    using (System.IO.StreamWriter sw = new System.IO.StreamWriter(moduleName + "\\src-db\\database\\model\\views\\" + row["name"].ToString(), false, Encoding.UTF8))
                    {
                        sw.Write(row["definition"].ToString());
                    }
                }
            }

            foreach (System.Data.DataRow row in views.Rows)
            {
                if (row["type"].ToString() == "Procedure")
                {
                    using (System.IO.StreamWriter sw = new System.IO.StreamWriter(moduleName + "\\src-db\\database\\model\\procedures\\" + row["name"].ToString(), false, Encoding.UTF8))
                    {
                        sw.Write(row["definition"].ToString());
                    }
                }
            }

            string[] adDataTables = DbHelper.GetAdDataTables();
            foreach (string s in adDataTables)
            {
                System.Data.DataTable dt = Feng.Data.DbHelper.Instance.ExecuteDataTable("SELECT * FROM " + s);
                if (dt.Rows.Count > 0)
                {
                    using (ExcelXmlWriter ew = new ExcelXmlWriter(moduleName + "\\src-db\\database\\sourcedata\\" + s + ".xml"))
                    {
                        ew.WriteExcelXml(dt, s);
                    }
                }
            }
        }
Пример #8
0
        /// <summary>
        /// 把当前数据库的所有内容作为一个模块Export
        /// </summary>
        /// <param name="moduleName"></param>
        public static void PackageCurrentDatabase(string moduleName)
        {
            CreateNecessaryDirectories(moduleName);

            string dir = System.IO.Directory.GetCurrentDirectory() + "\\" + moduleName;

            string[] userDataTables = DbHelper.GetUserDataTables();
            foreach (string s in userDataTables)
            {
                System.Data.DataTable dt = Feng.Data.DbHelper.Instance.ExecuteDataTable("SELECT * FROM " + s);
                if (dt.Rows.Count > 0)
                {
                    using (ExcelXmlWriter ew = new ExcelXmlWriter(moduleName + "\\referencedata\\standard\\" + s + ".xml"))
                    {
                        ew.WriteExcelXml(dt, s);
                    }
                }
            }

            System.Data.DataTable views = DbHelper.GetViewFuncProcTrigs();
            foreach (System.Data.DataRow row in views.Rows)
            {
                if (row["type"].ToString() == "Function")
                {
                    using (System.IO.StreamWriter sw = new System.IO.StreamWriter(moduleName + "\\src-db\\database\\model\\functions\\" + row["name"].ToString(), false, Encoding.UTF8))
                    {
                        sw.Write(row["definition"].ToString());
                    }
                }
            }

            foreach (System.Data.DataRow row in views.Rows)
            {
                if (row["type"].ToString() == "Trigger")
                {
                    using (System.IO.StreamWriter sw = new System.IO.StreamWriter(moduleName + "\\src-db\\database\\model\\triggers\\" + row["name"].ToString(), false, Encoding.UTF8))
                    {
                        sw.Write(row["definition"].ToString());
                    }
                }
            }

            foreach (System.Data.DataRow row in views.Rows)
            {
                if (row["type"].ToString() == "View")
                {
                    using (System.IO.StreamWriter sw = new System.IO.StreamWriter(moduleName + "\\src-db\\database\\model\\views\\" + row["name"].ToString(), false, Encoding.UTF8))
                    {
                        sw.Write(row["definition"].ToString());
                    }
                }
            }

            foreach (System.Data.DataRow row in views.Rows)
            {
                if (row["type"].ToString() == "Procedure")
                {
                    using (System.IO.StreamWriter sw = new System.IO.StreamWriter(moduleName + "\\src-db\\database\\model\\procedures\\" + row["name"].ToString(), false, Encoding.UTF8))
                    {
                        sw.Write(row["definition"].ToString());
                    }
                }
            }

            string[] adDataTables = DbHelper.GetAdDataTables();
            foreach (string s in adDataTables)
            {
                System.Data.DataTable dt = Feng.Data.DbHelper.Instance.ExecuteDataTable("SELECT * FROM " + s);
                if (dt.Rows.Count > 0)
                {
                    using (ExcelXmlWriter ew = new ExcelXmlWriter(moduleName + "\\src-db\\database\\sourcedata\\" + s + ".xml"))
                    {
                        ew.WriteExcelXml(dt, s);
                    }
                }
            }
        }
Пример #9
0
        /// <summary>
        /// 按照Module定义信息打包Module
        /// </summary>
        /// <param name="moduleName"></param>
        public static void PackageModule(string moduleName)
        {
            CreateNecessaryDirectories(moduleName);

            string dir = System.IO.Directory.GetCurrentDirectory() + "\\" + moduleName;

            // Write ModuleInfo
            DataTable dt;

            dt = DbHelper.Instance.ExecuteDataTable("SELECT * FROM AD_Module WHERE NAME = '" + moduleName + "'");
            foreach (System.Data.DataRow row in dt.Rows)
            {
                row["ModuleData"] = System.DBNull.Value;
            }
            using (ExcelXmlWriter ew = new ExcelXmlWriter(dir + "\\src-db\\database\\sourcedata\\AD_Module.xml"))
            {
                ew.WriteExcelXml(dt, "AD_Module");
            }
            dt = DbHelper.Instance.ExecuteDataTable("SELECT * FROM AD_Module_Dependency WHERE Module = '" + moduleName + "'");
            using (ExcelXmlWriter ew = new ExcelXmlWriter(dir + "\\src-db\\database\\sourcedata\\AD_Module_Dependency.xml"))
            {
                ew.WriteExcelXml(dt, "AD_Module_Dependency");
            }
            dt = DbHelper.Instance.ExecuteDataTable("SELECT * FROM AD_Module_Include WHERE Module = '" + moduleName + "'");
            using (ExcelXmlWriter ew = new ExcelXmlWriter(dir + "\\src-db\\database\\sourcedata\\AD_Module_Include.xml"))
            {
                ew.WriteExcelXml(dt, "AD_Module_Include");
            }

            // Write Module Include Info
            foreach (System.Data.DataRow includeInfo in dt.Rows)
            {
                switch ((ModuleIncludeType)includeInfo["ModuleIncludeType"])
                {
                case ModuleIncludeType.ReferenceData:
                {
                    dt = DbHelper.Instance.ExecuteDataTable("SELECT * FROM " + includeInfo["Params"].ToString());
                    using (ExcelXmlWriter ew = new ExcelXmlWriter(dir + "\\referencedata\\standard\\" + includeInfo["Params"].ToString() + ".xml"))
                    {
                        ew.WriteExcelXml(dt, includeInfo["Params"].ToString());
                    }
                }
                break;

                case ModuleIncludeType.ApplicationDictionaryData:
                {
                    dt = DbHelper.Instance.ExecuteDataTable("SELECT * FROM " + includeInfo["Params"].ToString());
                    using (ExcelXmlWriter ew = new ExcelXmlWriter(dir + "\\src-db\\database\\sourcedata\\" + includeInfo["Params"].ToString() + ".xml"))
                    {
                        ew.WriteExcelXml(dt, includeInfo["Params"].ToString());
                    }
                }
                break;

                //case ModuleIncludeType.DbTable:
                //    {
                //        string script = includeInfo["Params"].ToString();
                //        DbHelper.Instance.ExecuteNonQuery(script);
                //    }
                //    break;
                case ModuleIncludeType.DbView:
                {
                    string script = DbHelper.Instance.GetSqlObjectDefinition(includeInfo["Params"].ToString());
                    using (System.IO.StreamWriter sw = new System.IO.StreamWriter(dir + "\\src-db\\database\\model\\views\\" + includeInfo["Params"].ToString(), false, Encoding.UTF8))
                    {
                        sw.Write(script);
                    }
                }
                break;

                case ModuleIncludeType.DbFunction:
                {
                    string script = DbHelper.Instance.GetSqlObjectDefinition(includeInfo["Params"].ToString());
                    using (System.IO.StreamWriter sw = new System.IO.StreamWriter(dir + "\\src-db\\database\\model\\functions\\" + includeInfo["Params"].ToString(), false, Encoding.UTF8))
                    {
                        sw.Write(script);
                    }
                }
                break;

                case ModuleIncludeType.DbTrigger:
                {
                    string script = DbHelper.Instance.GetSqlObjectDefinition(includeInfo["Params"].ToString());
                    using (System.IO.StreamWriter sw = new System.IO.StreamWriter(dir + "\\src-db\\database\\model\\triggers\\" + includeInfo["Params"].ToString(), false, Encoding.UTF8))
                    {
                        sw.Write(script);
                    }
                }
                break;

                case ModuleIncludeType.DbProcedure:
                {
                    string script = DbHelper.Instance.GetSqlObjectDefinition(includeInfo["Params"].ToString());
                    using (System.IO.StreamWriter sw = new System.IO.StreamWriter(dir + "\\src-db\\database\\model\\procedures\\" + includeInfo["Params"].ToString(), false, Encoding.UTF8))
                    {
                        sw.Write(script);
                    }
                }
                break;

                //case ModuleIncludeType.SourceModel:
                //    {
                //        string fileName = includeInfo["Params"].ToString();
                //        string newFileName = null;
                //        System.IO.File.Copy(fileName, newFileName);
                //    }
                //    break;
                //case ModuleIncludeType.SourceScript:
                //    {
                //        string fileName = includeInfo["Params"].ToString();
                //        string newFileName = null;
                //        System.IO.File.Copy(fileName, newFileName);
                //    }
                //    break;
                //case ModuleIncludeType.SourceReport:
                //    {
                //        string fileName = includeInfo["Params"].ToString();
                //        string newFileName = null;
                //        System.IO.File.Copy(fileName, newFileName);
                //    }
                //    break;
                default:
                    throw new NotSupportedException("ModuleIncludeType");
                }
            }

            // zip
            string zipFile = dir + "\\..\\" + moduleName + ".zip";

            CompressionHelper.ZipFromFolder(dir, zipFile);

            byte[] data;
            using (System.IO.FileStream fs = new System.IO.FileStream(zipFile, System.IO.FileMode.Open))
            {
                data = new byte[fs.Length];
                fs.Read(data, 0, data.Length);
            }

            using (var rep = ServiceProvider.GetService <IRepositoryFactory>().GenerateRepository <ModuleInfo>())
            {
                try
                {
                    rep.BeginTransaction();
                    IList <ModuleInfo> modules = (rep as Feng.NH.INHibernateRepository).Session
                                                 .CreateCriteria <ModuleInfo>()
                                                 .Add(NHibernate.Criterion.Expression.Eq("Name", moduleName))
                                                 .List <ModuleInfo>();
                    modules[0].ModuleData = data;
                    rep.Update(modules[0]);

                    rep.CommitTransaction();
                }
                catch (Exception ex)
                {
                    rep.RollbackTransaction();
                    ExceptionProcess.ProcessWithNotify(ex);
                }
            }
        }