Example #1
0
        /// <summary>
        /// 保存所有编辑器
        /// </summary>
        private void saveAllWithNoResult()
        {
            if (projectObj != null)
            {
                CircleProgressBarDialog dialoga = new CircleProgressBarDialog();
                dialoga.TransparencyKey        = dialoga.BackColor;
                dialoga.ProgressBar.ForeColor  = Color.Red;
                dialoga.MessageLabel.ForeColor = Color.Blue;
                dialoga.FormBorderStyle        = FormBorderStyle.None;
                dialoga.MessageLabel.Text      = "正在保存,请等待...";
                dialoga.Start(new EventHandler <CircleProgressBarEventArgs>(delegate(object thisObject, CircleProgressBarEventArgs argss)
                {
                    //创建一个倒叙列表用于解决因为保存顺序问题导致的某些列表项保存失败的BUG
                    List <BaseEditor> tempLists = new List <BaseEditor>();
                    tempLists.AddRange(editorMap.Values);
                    tempLists.Reverse();

                    if (((CircleProgressBarDialog)thisObject).IsHandleCreated)
                    {
                        ((CircleProgressBarDialog)thisObject).Invoke(new MethodInvoker(delegate()
                        {
                            //循环所有控件,一个一个保存
                            int currentIndex = 0;
                            foreach (BaseEditor be in tempLists)
                            {
                                currentIndex++;

                                //保存
                                try
                                {
                                    be.OnSaveEvent();
                                }
                                catch (Exception ex)
                                {
                                    MessageBox.Show("对不起,页签(" + be.EditorName + ")保存失败!Ex:" + ex.ToString());
                                }

                                //进度条移动
                                ((CircleProgressBarDialog)thisObject).ReportProgress((int)(((double)currentIndex / (double)tempLists.Count) * 100), 100);

                                //立即执行消息
                                Application.DoEvents();
                            }
                        }));
                    }

                    //刷新
                    if (((CircleProgressBarDialog)thisObject).IsHandleCreated)
                    {
                        ((CircleProgressBarDialog)thisObject).Invoke(new MethodInvoker(delegate()
                        {
                            refreshEditors();
                        }));
                    }
                }));
            }
        }
Example #2
0
        private void exportPkg(string currentDir, FormClosingEventArgs e)
        {
            if (needExport)
            {
                //检查是否文件被占有了
                bool          acceptExport = true;
                List <string> filesList    = new List <string>();
                filesList.AddRange(Directory.GetFiles(currentDir));
                filesList.AddRange(Directory.GetFiles(Path.Combine(currentDir, "Files")));
                foreach (string s in filesList)
                {
                    if (s != null && s.Contains("static.db"))
                    {
                        continue;
                    }
                    else
                    {
                        if (IsFileInUse(s))
                        {
                            e.Cancel     = true;
                            acceptExport = false;
                            MessageBox.Show("对不起,文件(" + s + ")被占用,无法导出!");
                            break;
                        }
                    }
                }

                //导出
                if (acceptExport)
                {
                    //检查目标文件是否存在,如果存在则删除
                    string destFile = DestZipPath;
                    if (File.Exists(destFile))
                    {
                        try
                        {
                            File.Delete(destFile);
                        }
                        catch (Exception ex) { }
                    }

                    try
                    {
                        CircleProgressBarDialog dialoga = new CircleProgressBarDialog();
                        dialoga.TransparencyKey        = dialoga.BackColor;
                        dialoga.ProgressBar.ForeColor  = Color.Red;
                        dialoga.MessageLabel.ForeColor = Color.Blue;
                        dialoga.FormBorderStyle        = FormBorderStyle.None;
                        dialoga.Start(new EventHandler <CircleProgressBarEventArgs>(delegate(object thisObject, CircleProgressBarEventArgs argss)
                        {
                            CircleProgressBarDialog senderForm = ((CircleProgressBarDialog)thisObject);

                            senderForm.ReportProgress(10, 100);
                            senderForm.ReportInfo("准备导出...");
                            try { System.Threading.Thread.Sleep(1000); }
                            catch (Exception ex) { }

                            #region 尝试关闭Sqlite数据库连接
                            try
                            {
                                dynamic script = CSScriptLibrary.CSScript.LoadCode(
                                    @"using System.Windows.Forms;
                             public class Script
                             {
                                 public void CloseDB()
                                 {
                                     ProjectMilitaryTechnologPlanPlugin.DB.ConnectionManager.Close();
                                 }
                             }")
                                                 .CreateObject("*");
                                script.CloseDB();
                            }
                            catch (Exception ex) { }
                            #endregion

                            senderForm.ReportProgress(20, 100);
                            senderForm.ReportInfo("正在导出...");
                            try { System.Threading.Thread.Sleep(1000); }
                            catch (Exception ex) { }

                            //压缩
                            new PublicReporterLib.Utility.ZipUtil().ZipFileDirectory(currentDir, destFile);

                            senderForm.ReportProgress(90, 100);
                            senderForm.ReportInfo("导出完成...");
                            try { System.Threading.Thread.Sleep(1000); }
                            catch (Exception ex) { }

                            //导出完成事件
                            if (senderForm.IsHandleCreated)
                            {
                                senderForm.Invoke(new MethodInvoker(delegate()
                                {
                                    if (OnExportComplete != null)
                                    {
                                        OnExportComplete(this, new ExportCompleteEventArgs(DestZipPath));
                                    }
                                }));
                            }
                        }));
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show("导出失败!Ex:" + ex.ToString());
                    }
                }
            }
        }
Example #3
0
        private void btnGetTables_Click(object sender, EventArgs e)
        {
            //清空树列表
            tvTables.Nodes.Clear();

            //根节点
            TreeNode firstNode = new TreeNode();

            firstNode.Text = "数据库";
            tvTables.Nodes.Add(firstNode);

            string dbType  = cbDbType.Text;
            string connUrl = txtConnectionUrl.Text;

            CircleProgressBarDialog dialog = new CircleProgressBarDialog();

            dialog.Start(new EventHandler <CircleProgressBarEventArgs>(delegate(object senders, CircleProgressBarEventArgs args)
            {
                try
                {
                    DBSchema.DbSchema schemaObj = DBSchema.DbSchemaFactory.Create(dbType, connUrl);

                    if (schemaObj != null)
                    {
                        List <SuperCodeFactory.DBSchema.SchemaObject.SOTable> tableList = schemaObj.GetTableList(schemaObj.GetDatabaseList()[0]);

                        if (tableList != null)
                        {
                            foreach (SuperCodeFactory.DBSchema.SchemaObject.SOTable table in tableList)
                            {
                                //报告进度
                                ((CircleProgressBarDialog)senders).ReportProgress((int)(((float)tableList.IndexOf(table) / (float)tableList.Count) * 100), 100);

                                //添加表格节点
                                TreeNode tableNode = new TreeNode();
                                tableNode.Text     = "表格(" + table.Name + ")";
                                tableNode.Tag      = table;

                                if (IsHandleCreated)
                                {
                                    Invoke(new MethodInvoker(delegate()
                                    {
                                        firstNode.Nodes.Add(tableNode);
                                    }));
                                }

                                if (table.ColumnList != null)
                                {
                                    foreach (SuperCodeFactory.DBSchema.SchemaObject.SOColumn col in table.ColumnList)
                                    {
                                        //添加字段节点
                                        TreeNode columnNode = new TreeNode();
                                        columnNode.Text     = "字段(" + col.Name + "," + col.DataType + ")";
                                        columnNode.Tag      = col;

                                        if (IsHandleCreated)
                                        {
                                            Invoke(new MethodInvoker(delegate()
                                            {
                                                tableNode.Nodes.Add(columnNode);
                                            }));
                                        }
                                    }
                                }
                            }
                        }

                        //展开根节点
                        if (IsHandleCreated)
                        {
                            Invoke(new MethodInvoker(delegate()
                            {
                                firstNode.Expand();
                            }));
                        }
                    }

                    try
                    {
                        Thread.Sleep(100);
                    }
                    catch (Exception ex) { }
                }
                catch (Exception ex)
                {
                    dialog.TopMost = false;
                    MessageBox.Show("操作失败!Ex:" + ex.ToString());
                }
            }));
        }
Example #4
0
        /// <summary>
        /// 按钮事件处理
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void tempButton_Click(object sender, EventArgs e)
        {
            ToolStripButton button = ((ToolStripButton)sender);

            switch (button.Text)
            {
            case "保存所有":
                if (projectObj == null)
                {
                    MessageBox.Show("对不起,请先填写项目信息,然后再继续!");
                    return;
                }

                saveAllWithNoResult();
                break;

            case "帮助":
                FrmHelpBox helpForm = new FrmHelpBox();
                helpForm.ShowDialog();
                break;

            case "导出":
                if (projectObj == null)
                {
                    MessageBox.Show("对不起,请先填写项目信息,然后再继续!");
                    return;
                }

                if (isSaveAllSucess() == false)
                {
                    MessageBox.Show("对不起,保存失败,请检查!");
                    return;
                }

                if (File.Exists(Path.Combine(dataDir, "合同书.doc")) == false)
                {
                    MessageBox.Show("对不起,请先点击预览按钮生成项目申报书!");
                    return;
                }

                string errorPage = string.Empty;
                if (!isInputCompleted(ref errorPage))
                {
                    MessageBox.Show("对不起,内容未填写完不能上报!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    MessageBox.Show("请将页签[" + errorPage + "]填写完整再点击上报!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    return;
                }

                SaveFileDialog sfd = new SaveFileDialog();
                sfd.Filter = "ZIP申报包|*.zip";
                if (sfd.ShowDialog() == DialogResult.OK)
                {
                    if (MessageBox.Show("真的要导出吗?", "提示", MessageBoxButtons.YesNo) == DialogResult.Yes)
                    {
                        CircleProgressBarDialog dialoga = new CircleProgressBarDialog();
                        dialoga.TransparencyKey        = dialoga.BackColor;
                        dialoga.ProgressBar.ForeColor  = Color.Red;
                        dialoga.MessageLabel.ForeColor = Color.Blue;
                        dialoga.FormBorderStyle        = FormBorderStyle.None;
                        dialoga.Start(new EventHandler <CircleProgressBarEventArgs>(delegate(object thisObject, CircleProgressBarEventArgs argss)
                        {
                            ((CircleProgressBarDialog)thisObject).ReportProgress(10, 100);
                            ((CircleProgressBarDialog)thisObject).ReportInfo("准备导出...");
                            try { System.Threading.Thread.Sleep(1000); }
                            catch (Exception ex) { }

                            //关闭连接
                            DB.ConnectionManager.Close();

                            //当前项目目录
                            string currentPath = System.IO.Path.Combine(System.IO.Path.Combine(PublicReporterLib.PluginLoader.getLocalPluginRoot <PluginRoot>().RootDir, "Data"), "Current");

                            ((CircleProgressBarDialog)thisObject).ReportProgress(20, 100);
                            ((CircleProgressBarDialog)thisObject).ReportInfo("正在导出...");
                            try { System.Threading.Thread.Sleep(1000); }
                            catch (Exception ex) { }

                            //压缩
                            PublicReporterLib.Utility.ZipUtil zu = new PublicReporterLib.Utility.ZipUtil();
                            zu.ZipFileDirectory(currentPath, sfd.FileName);

                            ((CircleProgressBarDialog)thisObject).ReportProgress(90, 100);
                            ((CircleProgressBarDialog)thisObject).ReportInfo("导出完成,准备重启...");
                            try { System.Threading.Thread.Sleep(1000); }
                            catch (Exception ex) { }

                            //重启软件
                            PublicReporterLib.PluginLoader.getLocalPluginRoot <PluginRoot>().enabledShowExitHint = false;
                            DB.ConnectionManager.Close();
                            System.Diagnostics.Process.Start(Application.ExecutablePath);
                            PublicReporterLib.PluginLoader.getLocalPluginRoot <PluginRoot>().projectObj = null;
                            Application.Exit();
                        }));
                    }
                }
                break;

            case "预览":
                if (projectObj == null)
                {
                    MessageBox.Show("对不起,请先填写项目信息,然后再继续!");
                    return;
                }

                CircleProgressBarDialog dialogc = new CircleProgressBarDialog();
                dialogc.TransparencyKey        = dialogc.BackColor;
                dialogc.ProgressBar.ForeColor  = Color.Red;
                dialogc.MessageLabel.ForeColor = Color.Blue;
                dialogc.FormBorderStyle        = FormBorderStyle.None;
                dialogc.Start(new EventHandler <CircleProgressBarEventArgs>(delegate(object thisObject, CircleProgressBarEventArgs argss)
                {
                    //word预览
                    WordPrinter.wordOutput(((CircleProgressBarDialog)thisObject));
                }
                                                                            ));
                break;

            case "导入":
                OpenFileDialog ofd = new OpenFileDialog();
                ofd.Filter = "ZIP申报包|*.zip";
                if (ofd.ShowDialog() == DialogResult.OK)
                {
                    if (MessageBox.Show("真的要导入吗?", "提示", MessageBoxButtons.YesNo) == DialogResult.Yes)
                    {
                        CircleProgressBarDialog dialogb = new CircleProgressBarDialog();
                        dialogb.TransparencyKey        = dialogb.BackColor;
                        dialogb.ProgressBar.ForeColor  = Color.Red;
                        dialogb.MessageLabel.ForeColor = Color.Blue;
                        dialogb.FormBorderStyle        = FormBorderStyle.None;
                        dialogb.Start(new EventHandler <CircleProgressBarEventArgs>(delegate(object thisObject, CircleProgressBarEventArgs argss)
                        {
                            ((CircleProgressBarDialog)thisObject).ReportProgress(10, 100);
                            ((CircleProgressBarDialog)thisObject).ReportInfo("准备导入...");
                            try { System.Threading.Thread.Sleep(1000); }
                            catch (Exception ex) { }

                            string uuid = projectObj != null ? projectObj.BianHao : string.Empty;

                            //关闭连接
                            DB.ConnectionManager.Close();

                            //当前项目目录
                            string currentPath = System.IO.Path.Combine(System.IO.Path.Combine(PublicReporterLib.PluginLoader.getLocalPluginRoot <PluginRoot>().RootDir, "Data"), "Current");

                            //backup
                            string backupPath = System.IO.Path.Combine(System.IO.Path.Combine(PublicReporterLib.PluginLoader.getLocalPluginRoot <PluginRoot>().RootDir, "Data"), uuid);

                            ((CircleProgressBarDialog)thisObject).ReportProgress(20, 100);
                            ((CircleProgressBarDialog)thisObject).ReportInfo("清空当前目录...");
                            try { System.Threading.Thread.Sleep(1000); }
                            catch (Exception ex) { }

                            //检查是否需要备份
                            if (uuid != null && uuid.Length >= 2)
                            {
                                //移动backupDir
                                if (System.IO.Directory.Exists(backupPath))
                                {
                                    System.IO.Directory.Delete(backupPath, true);
                                }
                                //备份当前
                                System.IO.Directory.Move(currentPath, backupPath);
                            }
                            else
                            {
                                //直接删除Current
                                if (System.IO.Directory.Exists(currentPath))
                                {
                                    System.IO.Directory.Delete(currentPath, true);
                                }
                            }

                            ((CircleProgressBarDialog)thisObject).ReportProgress(30, 100);
                            ((CircleProgressBarDialog)thisObject).ReportInfo("创建导入目录...");
                            try { System.Threading.Thread.Sleep(1000); }
                            catch (Exception ex) { }

                            //创建当前目录
                            try
                            {
                                Directory.CreateDirectory(currentPath);
                            }
                            catch (Exception ex) { }

                            ((CircleProgressBarDialog)thisObject).ReportProgress(40, 100);
                            ((CircleProgressBarDialog)thisObject).ReportInfo("正在导入...");
                            try { System.Threading.Thread.Sleep(1000); }
                            catch (Exception ex) { }

                            //解压
                            PublicReporterLib.Utility.ZipUtil zu = new PublicReporterLib.Utility.ZipUtil();
                            zu.UnZipFile(ofd.FileName, currentPath, string.Empty, true);

                            ((CircleProgressBarDialog)thisObject).ReportProgress(90, 100);
                            ((CircleProgressBarDialog)thisObject).ReportInfo("导入完成,准备重启...");
                            try { System.Threading.Thread.Sleep(1000); }
                            catch (Exception ex) { }

                            //重启软件
                            PublicReporterLib.PluginLoader.getLocalPluginRoot <PluginRoot>().enabledShowExitHint = false;
                            DB.ConnectionManager.Close();
                            System.Diagnostics.Process.Start(Application.ExecutablePath);
                            PublicReporterLib.PluginLoader.getLocalPluginRoot <PluginRoot>().projectObj = null;
                            Application.Exit();
                        }));
                    }
                }
                break;

            case "新建":
                if (MessageBox.Show("真的要新建吗?", "提示", MessageBoxButtons.YesNo) == DialogResult.Yes)
                {
                    //关闭连接
                    DB.ConnectionManager.Close();

                    //当前项目目录
                    string currentPath = System.IO.Path.Combine(System.IO.Path.Combine(PublicReporterLib.PluginLoader.getLocalPluginRoot <PluginRoot>().RootDir, "Data"), "Current");

                    //移动当前目录
                    if (System.IO.Directory.Exists(currentPath))
                    {
                        System.IO.Directory.Delete(currentPath, true);
                    }

                    PublicReporterLib.PluginLoader.getLocalPluginRoot <PluginRoot>().enabledShowExitHint = false;
                    DB.ConnectionManager.Close();
                    System.Diagnostics.Process.Start(Application.ExecutablePath);
                    PublicReporterLib.PluginLoader.getLocalPluginRoot <PluginRoot>().projectObj = null;
                    Application.Exit();
                }
                break;

            case "项目管理":
                FrmProjectManager manager = new FrmProjectManager();
                manager.ShowDialog();
                break;
            }
        }
Example #5
0
        private void btnMakeAll_Click(object sender, EventArgs e)
        {
            string dbTypeStr        = cbDbType.Text;
            string nameSpaceStr     = txtNameSpace.Text;
            string classBeforeStr   = txtClassBefore.Text;
            string classAfterStr    = txtClassAfter.Text;
            string connectionUrlStr = txtConnectionUrl.Text;

            if (tvTables.Nodes.Count >= 1 && tvTables.Nodes[0].Nodes.Count >= 1)
            {
                #region 准备表格字典
                Dictionary <string, List <string[]> > tables = new Dictionary <string, List <string[]> >();
                foreach (TreeNode tableNode in tvTables.Nodes[0].Nodes)
                {
                    //表名
                    string tableName = ((SOTable)tableNode.Tag).Name;

                    //列
                    List <string[]> columns = new List <string[]>();
                    foreach (TreeNode columnNode in tableNode.Nodes)
                    {
                        //输出字段信息
                        columns.Add(new string[] { ((SOColumn)columnNode.Tag).Name, ((SOColumn)columnNode.Tag).DataType.ToString() });
                    }

                    //添加表格
                    tables[tableName] = columns;
                }
                #endregion

                if (fbdOutputDir.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {
                    try
                    {
                        CircleProgressBarDialog dialog = new CircleProgressBarDialog();
                        dialog.Start(new EventHandler <CircleProgressBarEventArgs>(delegate(object senders, CircleProgressBarEventArgs args)
                        {
                            try
                            {
                                ((CircleProgressBarDialog)senders).ReportProgress(10, 100);

                                try
                                {
                                    Directory.CreateDirectory(fbdOutputDir.SelectedPath);
                                }
                                catch (Exception ex) { }

                                ((CircleProgressBarDialog)senders).ReportProgress(20, 100);

                                //复制目录
                                SuperCodeFactoryLib.Utilities.IOUtil.CopyDirectory(Path.Combine(Application.StartupPath, @"Templetes"), fbdOutputDir.SelectedPath, true);

                                //删除脚本目录
                                try
                                {
                                    Directory.Delete(Path.Combine(fbdOutputDir.SelectedPath, "script"), true);
                                }
                                catch (Exception ex) { }

                                ((CircleProgressBarDialog)senders).ReportProgress(60, 100);

                                #region 运行动态代码
                                var make      = CSScript.CreateFunc <string>(File.ReadAllText(Path.Combine(Application.StartupPath, @"Templetes\script\" + allScript)));
                                string result = make(dbTypeStr, nameSpaceStr, classBeforeStr, classAfterStr, fbdOutputDir.SelectedPath, connectionUrlStr, tables);

                                if (IsHandleCreated)
                                {
                                    Invoke(new MethodInvoker(delegate()
                                    {
                                        ((CircleProgressBarDialog)senders).TopMost = false;
                                        MessageBox.Show(result);
                                    }));
                                }
                                #endregion

                                ((CircleProgressBarDialog)senders).ReportProgress(100, 100);
                            }
                            catch (Exception ex)
                            {
                                if (IsHandleCreated)
                                {
                                    Invoke(new MethodInvoker(delegate()
                                    {
                                        ((CircleProgressBarDialog)senders).TopMost = false;
                                        MessageBox.Show("生成错误!Ex:" + ex.ToString());
                                    }));
                                }
                            }
                        }));
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show("生成错误!Ex:" + ex.ToString());
                    }
                }
            }
            else
            {
                MessageBox.Show("对不起,请先配置数据库连接!");
            }
        }