Ejemplo n.º 1
0
 private void btnTestDataBase_Click(object sender, EventArgs e)
 {
     if (CheckInput())
     {
         string      connStr = GetInputConfig().ToString();
         CtrlWaiting waiting = new CtrlWaiting("连接中...", () =>
         {
             try
             {
                 using (SqlConnection conn = DatabaseHelper.ConnectDatabase(connStr))
                 {
                     conn.Close();
                     this.Invoke(new Action(() =>
                     {
                         lbMsg.Text = "测试连接成功!";
                     }));
                 }
             }
             catch (Exception ex)
             {
                 this.Invoke(new Action(() =>
                 {
                     lbMsg.Text = "测试连接异常," + ex.Message + "!";
                 }));
             }
         });
         waiting.ShowDialog(this);
     }
 }
Ejemplo n.º 2
0
        private bool DoSave()
        {
            string sql  = FrmDataBaseConfig.GetFileSql("smartaccess_createbackupjob.sql");
            string path = this.tbPath.Text.Trim();

            path = path.TrimEnd('\\', '/');
            sql  = sql.Replace("${PATH}", path);
            sql  = sql.Replace("${ENABLE}", cbAutoBk.Checked ? "1" : "0");
            sql  = sql.Replace("${DAYS}", iiDays.Value.ToString());
            var         sqls    = sql.Split(new string[] { "GO\r" }, StringSplitOptions.RemoveEmptyEntries);
            bool        b       = false;
            CtrlWaiting waiting = new CtrlWaiting(() =>
            {
                try
                {
                    foreach (var item in sqls)
                    {
                        Maticsoft.DBUtility.DbHelperSQL.ExecuteSql(item);
                    }
                    b = true;
                }
                catch (System.Exception ex)
                {
                    WinInfoHelper.ShowInfoWindow(this, "保存自动备份配置异常!" + ex.Message);
                    log.Error("保存自动备份配置异常:", ex);
                }
            });

            waiting.ShowDialog(this);
            return(b);
        }
Ejemplo n.º 3
0
        private void btnCreateDatabase_Click(object sender, EventArgs e)
        {
            DatabaseConfigClass config = GetInputConfig();
            bool isupdate = false;

            if (CheckInput())
            {
                bool exsit = false;
                config.database = "master";
                string      connStr = GetInputConfig().ToString();
                CtrlWaiting waiting = new CtrlWaiting("创建中...", () =>
                {
                    try
                    {
                        using (SqlConnection conn = DatabaseHelper.ConnectDatabase(connStr))
                        {
                            using (SqlCommand command = conn.CreateCommand())
                            {
                                command.CommandType = System.Data.CommandType.Text;
                                command.CommandText = "select count(*) From master.dbo.sysdatabases where name='SmartAccess'";//查询数据库路径
                                var single          = command.ExecuteScalar();
                                int num             = 0;
                                if (object.Equals(single, null) || object.Equals(single, DBNull.Value))
                                {
                                    num = 0;
                                }
                                else
                                {
                                    num = int.Parse(single.ToString());
                                }
                                if (num == 0)
                                {
                                    exsit = false;
                                }
                                exsit = true;
                            }
                        }
                        exsit = true;
                    }
                    catch (Exception ex)
                    {
                        exsit = false;
                    }
                });
                waiting.ShowDialog(this);
                if (exsit)
                {//\r\n重新创建,原始数据库会备份至服务器目录:C:\\SmartAccessBak 下。
                    DialogResult dr = MessageBox.Show("数据库已存在,是否升级数据库?", "提示", MessageBoxButtons.YesNo);
                    if (dr == DialogResult.Cancel)
                    {
                        return;
                    }
                    else if (dr == DialogResult.Yes)
                    {
                        isupdate = true;
                    }
                    else
                    {
                        return;
                    }
                }
            }
            else
            {
                return;
            }
            //创建和备份数据库

            CtrlWaiting waiting1 = new CtrlWaiting((isupdate ? "升级" : "创建") + "数据库中...", () =>
            {
                try
                {
                    DoCreateDataBase(config, isupdate);
                    this.Invoke(new Action(() =>
                    {
                        MessageBox.Show((isupdate ? "升级" : "创建") + "数据库成功!");
                    }));
                }
                catch (Exception ex)
                {
                    this.Invoke(new Action(() =>
                    {
                        MessageBox.Show((isupdate ? "升级" : "创建") + "数据库异常:" + ex.Message);
                    }));
                }
            });

            waiting1.Show(this);
        }