예제 #1
0
파일: GridFormMgr.cs 프로젝트: AESCR/DBCHM
        /// <summary>
        /// 刷新列表
        /// </summary>
        private void RefreshListView()
        {
            var data = ConfigUtils.SelectAll();

            if (data != null)
            {
                GV_DBConfigs.DataSource = data;

                if (data.Count > 0)
                {
                    GV_DBConfigs.Columns[0].Visible = false;
                    GV_DBConfigs.Columns[1].Width   = 150;
                }
            }
        }
예제 #2
0
파일: GridFormMgr.cs 프로젝트: AESCR/DBCHM
        private void linkRemove_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            if (GV_DBConfigs.SelectedRows.Count <= 0)
            {
                MessageBox.Show("请选择连接!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            if (MessageBox.Show("确定要删除该连接吗?", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation) == DialogResult.OK)
            {
                int Id = Convert.ToInt32(GV_DBConfigs.SelectedRows[0].Cells[0].Value);
                ConfigUtils.Delete(Id);

                RefreshListView();
            }
        }
예제 #3
0
파일: GridFormMgr.cs 프로젝트: AESCR/DBCHM
        private void btnConnect_Click(object sender, EventArgs e)
        {
            if (GV_DBConfigs.SelectedRows.Count <= 0)
            {
                MessageBox.Show("请选择连接!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            int         Id     = Convert.ToInt32(GV_DBConfigs.SelectedRows[0].Cells[0].Value);
            DBCHMConfig config = ConfigUtils.Get(Id);


            if ((DBType)Enum.Parse(typeof(DBType), config.DBType) == DBType.SqlServer &&
                !GV_DBConfigs.SelectedRows[0].Cells[6].Value.ToString().Equals("sa", StringComparison.OrdinalIgnoreCase))
            {
                var dia = MessageBox.Show("非超级管理员的账号,可能因权限不足,查询不出表结构信息,确定要继续吗?", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
                if (dia == DialogResult.Cancel)
                {
                    return;
                }
            }

            FormUtils.ShowProcessing("正在查询表结构信息,请稍等......", this, arg =>
            {
                try
                {
                    DBUtils.Instance = DBMgr.UseDB((DBType)Enum.Parse(typeof(DBType), config.DBType), config.ConnString, 300);
                    ConfigUtils.UpLastModified(Id);
                }
                catch (Exception ex)
                {
                    LogUtils.LogError("连接数据库失败", Developer.SysDefault, ex, config);
                    MessageBox.Show(ex.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
            }, null);
        }
예제 #4
0
        private void ExportToChm()
        {
            #region 使用 HTML Help Workshop 的 hhc.exe 编译 ,先判断系统中是否已经安装有  HTML Help Workshop

            string hhcPath = string.Empty;

            if (!ConfigUtils.CheckInstall("HTML Help Workshop", "hhc.exe", out hhcPath))
            {
                string htmlhelpPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "htmlhelp.exe");
                if (File.Exists(htmlhelpPath))
                {
                    if (MessageBox.Show("导出CHM文档需安装 HTML Help Workshop ,是否现在安装?", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Asterisk) == DialogResult.OK)
                    {
                        var proc = Process.Start(htmlhelpPath);
                    }
                }
                return;
            }

            #endregion

            SaveFileDialog saveDia = new SaveFileDialog();
            saveDia.Filter             = "(*.chm)|*.chm";
            saveDia.Title              = "另存文件为";
            saveDia.CheckPathExists    = true;
            saveDia.AddExtension       = true;
            saveDia.AutoUpgradeEnabled = true;
            saveDia.DefaultExt         = ".chm";
            saveDia.InitialDirectory   = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
            saveDia.OverwritePrompt    = true;
            saveDia.ValidateNames      = true;
            saveDia.FileName           = DBUtils.Instance.Info.DBName + "表结构信息.chm";
            if (saveDia.ShowDialog(this) == DialogResult.OK)
            {
                chm_path = saveDia.FileName;

                System.Diagnostics.Process process;
                if (IsExistProcess(Path.GetFileName(saveDia.FileName), out process))
                {
                    var dia = MessageBox.Show("文件已打开,导出前需关闭,是否继续?", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Information);
                    if (dia == DialogResult.OK)
                    {
                        process.Kill();
                    }
                }

                try
                {
                    //创建临时文件夹,存在则删除,防止已经存在的文件 会导致生成出来的chm 有问题
                    dirPath = Path.Combine(ConfigUtils.AppPath, DBUtils.Instance.DBType + "_" + DBUtils.Instance.Info.DBName);
                    if (ZetaLongPaths.ZlpIOHelper.DirectoryExists(dirPath))
                    {
                        ZetaLongPaths.ZlpIOHelper.DeleteDirectory(dirPath, true);
                    }
                    ZetaLongPaths.ZlpIOHelper.CreateDirectory(dirPath);
                    ConfigUtils.AddSecurityControll2Folder(dirPath);
                }
                catch (Exception ex)
                {
                    LogUtils.LogError("文件目录创建出错", Developer.SysDefault, ex, dirPath);
                    return;
                }

                //设置要 进度条 对应的执行方法,以及进度条最大值
                FormUtils.ProgArg = new ProgressArg(() =>
                {
                    try
                    {
                        System.Collections.Generic.List <TableDto> tableDtos = DBInstanceTransToDto();

                        //生成数据库目录文件
                        indexHtmlpath = Path.Combine(dirPath, defaultHtml);
                        //ChmHtmlHelper.CreateDirHtml("数据库表目录", DBUtils.Instance.Info.TableComments, indexHtmlpath);
                        ChmHtmlHelper.CreateDirHtml("数据库表目录", tableDtos, indexHtmlpath);

                        string structPath = Path.Combine(dirPath, "表结构");
                        if (!ZetaLongPaths.ZlpIOHelper.DirectoryExists(structPath))
                        {
                            ZetaLongPaths.ZlpIOHelper.CreateDirectory(structPath);
                        }

                        bgWork.ReportProgress(2);

                        //生成每张表列结构的html
                        //ChmHtmlHelper.CreateHtml(DBUtils.Instance.Info.TableInfoDict, structPath);
                        ChmHtmlHelper.CreateHtml(tableDtos, structPath);

                        bgWork.ReportProgress(3);

                        ChmHelp c3     = new ChmHelp();
                        c3.HHCPath     = hhcPath;
                        c3.DefaultPage = defaultHtml;
                        c3.Title       = Path.GetFileName(chm_path);
                        c3.ChmFileName = chm_path;
                        c3.SourcePath  = dirPath;
                        c3.Compile();

                        bgWork.ReportProgress(4);

                        if (MessageBox.Show("生成CHM文档成功,是否打开?", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
                        {
                            System.Diagnostics.Process.Start(saveDia.FileName);
                        }
                    }
                    catch (Exception ex)
                    {
                        LogUtils.LogError("DBCHM执行出错", Developer.MJ, ex);
                        bgWork.ReportProgress(4, ex);
                    }
                }, 4);

                bgWork.RunWorkerAsync();
            }
        }
예제 #5
0
파일: DBForm.cs 프로젝트: mkbiltek2019/2
        public DBForm(OPType opType, int?id = null)
        {
            InitializeComponent();

            this.OpType = opType;

            if ((this.OpType == OPType.编辑 || this.OpType == OPType.克隆) && !id.HasValue)
            {
                throw new ArgumentNullException(this.OpType + "操作必须传递要操作的Id!");
            }
            else
            {
                if (id.HasValue)
                {
                    foreach (var item in FormUtils.DictDBType)
                    {
                        cboDBType.Items.Add(item.Value.ToString());
                    }

                    this.Id = id.Value;
                    DBCHMConfig config = ConfigUtils.Get(id.Value);
                    TxtConnectName.Text = config.Name;
                    cboDBType.Text      = config.DBType;
                    TxtHost.Text        = config.Server;
                    TxtPort.Text        = config.Port?.ToString();
                    TxtUName.Text       = config.Uid;
                    TxtPwd.Text         = config.Pwd;
                    cboDBName.Text      = config.DBName;
                    txtConnTimeOut.Text = config.ConnTimeOut?.ToString();

                    if (this.OpType == OPType.克隆)
                    {
                        TxtConnectName.Text += "_Clone";
                    }

                    if (config.DBType == DBType.SQLite.ToString())
                    {
                        btnSelectFile.Visible = true;

                        TxtHost.Enabled  = false;
                        TxtPort.Enabled  = false;
                        TxtUName.Enabled = false;

                        //暂不支持 加密的 Sqlite数据库
                        TxtPwd.Enabled = false;
                    }

                    //编辑时,确定后刷新连接列表
                    BtnOk.DialogResult = DialogResult.OK;
                }
                else
                {
                    btnSelectFile.Visible = false;
                }

                if (string.IsNullOrWhiteSpace(txtConnTimeOut.Text))
                {
                    txtConnTimeOut.Text = "60";
                }
            }

            //为KeyDown能应用到所有控件上 注册 KeyDown 事件
            foreach (Control control in this.Controls)
            {
                control.KeyDown += control_KeyDown;
            }
            lblMsg.Text = string.Empty;
        }
예제 #6
0
파일: DBForm.cs 프로젝트: mkbiltek2019/2
        private void BtnOk_Click(object sender, EventArgs e)
        {
            try
            {
                if (string.IsNullOrWhiteSpace(TxtConnectName.Text))
                {
                    MessageBox.Show("请输入连接名!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }

                if (string.IsNullOrWhiteSpace(cboDBName.Text))
                {
                    MessageBox.Show("请输入数据库名称!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }

                DBType type       = (DBType)Enum.Parse(typeof(DBType), cboDBType.Text);
                string connString = DBMgr.GetConnectionString(type, TxtHost.Text,
                                                              (string.IsNullOrWhiteSpace(TxtPort.Text) ? null : new Nullable <int>(Convert.ToInt32(TxtPort.Text))),
                                                              cboDBName.Text, TxtUName.Text, TxtPwd.Text,
                                                              (string.IsNullOrWhiteSpace(txtConnTimeOut.Text) ? 60 : Convert.ToInt32(txtConnTimeOut.Text))
                                                              );
                NameValueCollection nvc = new NameValueCollection();
                if (OpType == OPType.新建 || OpType == OPType.克隆)
                {
                    nvc.Add("Name", TxtConnectName.Text.Trim());
                    nvc.Add("DBType", cboDBType.Text.Trim());

                    nvc.Add("Server", TxtHost.Enabled ? TxtHost.Text.Trim() : string.Empty);
                    nvc.Add("Port", TxtPort.Enabled ? TxtPort.Text : string.Empty);
                    nvc.Add("DBName", cboDBName.Text.Trim());
                    nvc.Add("Uid", TxtUName.Enabled ? TxtUName.Text.Trim() : string.Empty);
                    nvc.Add("Pwd", TxtPwd.Enabled ? TxtPwd.Text : string.Empty);
                    nvc.Add("ConnTimeOut", txtConnTimeOut.Enabled ? txtConnTimeOut.Text : "60");
                    nvc.Add("ConnString", connString);
                    nvc.Add("Modified", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));

                    ConfigUtils.Save(nvc);
                }
                else if (OpType == OPType.编辑)
                {
                    nvc.Add("Id", Id.ToString());
                    nvc.Add("Name", TxtConnectName.Text.Trim());
                    nvc.Add("DBType", cboDBType.Text.Trim());

                    nvc.Add("Server", TxtHost.Enabled ? TxtHost.Text.Trim() : string.Empty);
                    nvc.Add("Port", TxtPort.Enabled ? TxtPort.Text : string.Empty);
                    nvc.Add("DBName", cboDBName.Text.Trim());
                    nvc.Add("Uid", TxtUName.Enabled ? TxtUName.Text.Trim() : string.Empty);
                    nvc.Add("Pwd", TxtPwd.Enabled ? TxtPwd.Text : string.Empty);
                    nvc.Add("ConnTimeOut", txtConnTimeOut.Enabled ? txtConnTimeOut.Text : "60");
                    nvc.Add("ConnString", connString);
                    nvc.Add("Modified", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
                    ConfigUtils.Save(nvc);
                }

                this.DialogResult = DialogResult.OK;
                this.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
        }