private void btnOk_Click(object sender, EventArgs e)
        {
            string FileName = txtBak.Text;
            string msg      = Pub.GetResText(formCode, "Msg002", "");
            bool   IsOk     = false;

            if (FileName == "")
            {
                btnDBPath.Focus();
                Pub.MessageBoxShow(Pub.GetResText(formCode, "Error001", ""));
                return;
            }
            Pub.ShowMessageForm(msg);
            try
            {
                IsOk = SystemInfo.db.UpdateScript(FileName);
            }
            catch (Exception E)
            {
                Pub.ShowErrorMsg(E);
            }
            finally
            {
                Pub.FreeMessageForm();
            }
            if (IsOk)
            {
                UpdateIsOk = true;
                Pub.MessageBoxShow(Pub.GetResText(formCode, "Msg003", ""), MessageBoxIcon.Information);
            }
        }
Exemple #2
0
        private void btnOk_Click(object sender, EventArgs e)
        {
            string FileName = txtBak.Text;
            string msg      = string.Format(Pub.GetResText(formCode, "Msg002", ""), AccName);
            bool   IsOk     = false;

            if (FileName == "")
            {
                btnDBName.Focus();
                Pub.ShowErrorMsg(Pub.GetResText(formCode, "Error001", ""));
                return;
            }
            Pub.ShowMessageForm(msg);
            try
            {
                if (!db.IsOpen)
                {
                    db.Open(GetConnStr(DBName));
                }
                IsOk = db.UpdateScript(FileName);
            }
            catch (Exception E)
            {
                Pub.ShowErrorMsg(E);
            }
            finally
            {
                Pub.FreeMessageForm();
            }
            if (IsOk)
            {
                UpdateIsOk = true;
                Pub.MessageBoxShow(string.Format(Pub.GetResText(formCode, "Msg003", ""), AccName), MessageBoxIcon.Information);
            }
        }
Exemple #3
0
        private void btnOk_Click(object sender, EventArgs e)
        {
            string msg  = "";
            bool   IsOk = false;

            if (rbInfo.Checked)
            {
                msg = Pub.GetResText(formCode, "Msg001", "");
            }
            else
            {
                msg = Pub.GetResText(formCode, "Msg003", "");
            }
            if (Pub.MessageBoxShowQuestion(msg))
            {
                return;
            }
            try
            {
                if (!db.IsOpen)
                {
                    db.Open(SystemInfo.ConnStr);
                }
                if (rbInfo.Checked)
                {
                    IsOk = true;
                }
                else
                {
                    Pub.ShowMessageForm(string.Format(Pub.GetResText(formCode, "Msg004", ""), DBName));
                    IsOk = db.DeleteDatabase(DBName, false);
                }
                if (IsOk)
                {
                    db.ExecSQL(Pub.GetSQL(DBCode.DB_000001, new string[] { "107", AccName }));
                }
            }
            catch (Exception E)
            {
                Pub.ShowErrorMsg(E);
            }
            finally
            {
                Pub.FreeMessageForm();
            }
            if (IsOk)
            {
                Pub.MessageBoxShow(string.Format(Pub.GetResText(formCode, "Msg002", ""), AccName), MessageBoxIcon.Information);
                this.DialogResult = DialogResult.OK;
                this.Close();
            }
        }
        private void btnOk_Click(object sender, EventArgs e)
        {
            string FileName = txtBak.Text;
            string msg      = Pub.GetResText(formCode, "Msg001", "");
            bool   IsOk     = false;

            if (FileName == "")
            {
                btnDBPath.Focus();
                Pub.MessageBoxShow(Pub.GetResText(formCode, "ErrorDBFileEmpty", ""));
                return;
            }
            Pub.ShowMessageForm(msg);
            try
            {
                IsOk = SystemInfo.db.RestoreDatabase(FileName);
                SystemInfo.db.Close();
                if (IsOk)
                {
                    string fn = FileName.Substring(FileName.LastIndexOf("\\") + 1).ToLower();
                    try
                    {
                        SystemInfo.db.Open(SystemInfo.ConnStr);
                    }
                    catch (Exception E)
                    {
                        IsOk = false;
                        Pub.ShowErrorMsg(E);
                    }
                }
            }
            catch (Exception E)
            {
                Pub.ShowErrorMsg(E);
            }
            finally
            {
                Pub.FreeMessageForm();
            }
            if (IsOk)
            {
                Pub.MessageBoxShow(Pub.GetResText(formCode, "Msg002", ""), MessageBoxIcon.Information);
                this.DialogResult = DialogResult.OK;
                this.Close();
            }
        }
Exemple #5
0
        private void btnOk_Click(object sender, EventArgs e)
        {
            string FileName = txtBak.Text;
            string msg      = string.Format(Pub.GetResText(formCode, "Msg001", ""), AccName);
            bool   IsOk     = false;

            if (Pub.MessageBoxShowQuestion(Pub.GetResText(formCode, "Msg000", "")))
            {
                return;
            }
            if (FileName == "")
            {
                btnDBName.Focus();
                Pub.ShowErrorMsg(Pub.GetResText(formCode, "ErrorDBFileEmpty", ""));
                return;
            }
            Pub.ShowMessageForm(msg);
            try
            {
                if (!db.IsOpen)
                {
                    db.Open(SystemInfo.ConnStr);
                }
                IsOk = db.RestoreDatabase(DBName, FileName);
                if (IsOk)
                {
                    IsOk = true;
                    string   fn   = FileName.Substring(FileName.LastIndexOf("\\") + 1).ToLower();
                    Database dbEx = new Database(GetConnStr(DBName));
                    try
                    {
                        dbEx.Open();
                    }
                    catch (Exception E)
                    {
                        IsOk = false;
                        Pub.ShowErrorMsg(E);
                    }
                    finally
                    {
                        dbEx.Close();
                        dbEx = null;
                    }
                    db.ExecSQL(Pub.GetSQL(DBCode.DB_000001, new string[] { "108", DBName }));
                }
            }
            catch (Exception E)
            {
                Pub.ShowErrorMsg(E);
            }
            finally
            {
                Pub.FreeMessageForm();
            }
            if (IsOk)
            {
                Pub.MessageBoxShow(string.Format(Pub.GetResText(formCode, "Msg002", ""), AccName), MessageBoxIcon.Information);
                this.DialogResult = DialogResult.OK;
                this.Close();
            }
        }
Exemple #6
0
        private void btnOk_Click(object sender, EventArgs e)
        {
            string          AccName  = txtAccName.Text.Trim();
            string          DBName   = "";
            string          FileName = txtBak.Text;
            string          DBPath   = txtPath.Text;
            string          msg      = string.Format(Pub.GetResText(formCode, "Msg001", ""), AccName);
            bool            b;
            bool            IsOk = false;
            DataTableReader dr   = null;

            DBName = rbNew.Checked || rbBak.Checked || rbMDF.Checked ? txtDBName.Text.Trim() : cbbDBName.Text;
            if (AccName == "")
            {
                txtAccName.Focus();
                Pub.ShowErrorMsg(Pub.GetResText(formCode, "ErrorAccountNameEmpty", ""));
                return;
            }
            if (DBName == "")
            {
                if (rbNew.Checked)
                {
                    txtDBName.Focus();
                }
                else
                {
                    cbbDBName.Focus();
                }
                Pub.ShowErrorMsg(Pub.GetResText(formCode, "ErrorDBNameEmpty", ""));
                return;
            }
            try
            {
                if (!db.IsOpen)
                {
                    db.Open(SystemInfo.ConnStr);
                }
                dr = db.GetDataReader(Pub.GetSQL(DBCode.DB_000001, new string[] { "105", AccName }));
                b  = dr.Read();
                dr.Close();
                if (b)
                {
                    txtAccName.Focus();
                    Pub.ShowErrorMsg(Pub.GetResText(formCode, "ErrorAccountNameExists", ""));
                    return;
                }
                dr = db.GetDataReader(Pub.GetSQL(DBCode.DB_000001, new string[] { "106", DBName }));
                b  = dr.Read();
                dr.Close();
                if (rbNew.Checked)
                {
                    if (b)
                    {
                        txtDBName.Focus();
                        Pub.ShowErrorMsg(Pub.GetResText(formCode, "ErrorDBNameExists", ""));
                        return;
                    }
                    if (DBPath == "")
                    {
                        btnDBPath.Focus();
                        Pub.ShowErrorMsg(Pub.GetResText(formCode, "ErrorDBPathEmpty", ""));
                        return;
                    }
                    Pub.ShowMessageForm(msg);
                    if (!db.CreateDatabase(DBPath, DBName))
                    {
                        db.DeleteDatabase(DBName, true);
                    }
                    else
                    {
                        IsOk = true;
                        DateTime dt   = new DateTime();
                        Database dbEx = new Database(GetConnStr(DBName));
                        try
                        {
                            dbEx.Open();
                            IsOk = dbEx.UpdateDatabase(this.Text, new DateTime(2000, 1, 1));
                            dbEx.ExecSQL(Pub.GetSQL(DBCode.DB_000001, new string[] { "5002" }));
                            dbEx.ExecSQL(Pub.GetSQL(DBCode.DB_000001, new string[] { "5003" }));
                            if (IsOk)
                            {
                                IsOk = dbEx.UpdateDatabasesLang();
                            }
                            if (IsOk)
                            {
                                IsOk = dbEx.UpdateDatabase(this.Text, new DateTime(2000, 1, 1));
                            }
                            if (IsOk)
                            {
                                dr = dbEx.GetDataReader(Pub.GetSQL(DBCode.DB_000002, new string[] { "2" }));
                                if (dr.Read())
                                {
                                    dt = Convert.ToDateTime(dr["DbDate"]);
                                    dbEx.UpdateDatabase(this.Text, dt);
                                }
                            }
                        }
                        catch (Exception E)
                        {
                            IsOk = false;
                            Pub.ShowErrorMsg(E);
                        }
                        finally
                        {
                            if (dr != null)
                            {
                                dr.Close();
                            }
                            dr = null;
                            dbEx.Close();
                            dbEx = null;
                        }
                        if (!IsOk)
                        {
                            db.DeleteDatabase(DBName, true);
                        }
                    }
                }
                else if (rbBak.Checked)
                {
                    if (b)
                    {
                        txtDBName.Focus();
                        Pub.ShowErrorMsg(Pub.GetResText(formCode, "ErrorDBNameExists", ""));
                        return;
                    }
                    if (FileName == "")
                    {
                        btnDBName.Focus();
                        Pub.ShowErrorMsg(Pub.GetResText(formCode, "ErrorDBFileEmpty", ""));
                        return;
                    }
                    if (DBPath == "")
                    {
                        btnDBPath.Focus();
                        Pub.ShowErrorMsg(Pub.GetResText(formCode, "ErrorDBPathEmpty", ""));
                        return;
                    }
                    Pub.ShowMessageForm(msg);
                    if (db.AttachDB(DBPath, DBName) != "")
                    {
                        if (!db.CreateDatabase(DBPath, DBName))
                        {
                            db.DeleteDatabase(DBName, true);
                        }
                        else if (!db.RestoreDatabase(DBName, FileName))
                        {
                            db.DeleteDatabase(DBName, true);
                        }
                        else
                        {
                            IsOk = true;
                            string   fn   = FileName.Substring(FileName.LastIndexOf("\\") + 1).ToLower();
                            Database dbEx = new Database(GetConnStr(DBName));
                            try
                            {
                                dbEx.Open();
                                if (fn == SystemInfo.DefaultDBBak.ToLower())
                                {
                                    IsOk = dbEx.UpdateDatabasesLang();
                                }
                            }
                            catch (Exception E)
                            {
                                IsOk = false;
                                Pub.ShowErrorMsg(E);
                            }
                            finally
                            {
                                dbEx.Close();
                                dbEx = null;
                            }
                            if (!IsOk)
                            {
                                db.DeleteDatabase(DBName, true);
                            }
                        }
                    }
                }
                else
                {
                    if (rbOld.Checked && !b)
                    {
                        cbbDBName.Focus();
                        Pub.ShowErrorMsg(Pub.GetResText(formCode, "ErrorDBNameNotExists", ""));
                        return;
                    }
                    if (rbMDF.Checked && ((SystemInfo.DBType == 1) || (SystemInfo.DBType == 2)))
                    {
                        string MDFFile = txtMDF.Text.Trim();
                        if (MDFFile == "")
                        {
                            Pub.ShowErrorMsg(Pub.GetResText(formCode, "Error001", ""));
                            return;
                        }
                        string LDFFile = MDFFile.Replace(".mdf", ".ldf");
                        string SqlStr  = "";
                        if (db.DBFileExists(LDFFile))
                        {
                            SqlStr = "EXEC sp_attach_db @dbname=N'" + DBName + "',@filename1=N'" + MDFFile + "',@filename2=N'" + LDFFile + "'";
                        }
                        else
                        {
                            SqlStr = "EXEC sp_attach_single_file_db @dbname='" + DBName + "',@physname='" + MDFFile + "'";
                        }
                        db.ExecSQL(SqlStr);
                    }
                    Pub.ShowMessageForm(msg);
                    IsOk = true;
                }
                if (IsOk)
                {
                    string sql = Pub.GetSQL(DBCode.DB_000001, new string[] { "801", AccName, DBName, DBPath + DBName });
                    db.ExecSQL(sql);
                }
            }
            catch (Exception E)
            {
                IsOk = false;
                Pub.ShowErrorMsg(E);
            }
            finally
            {
                if (dr != null)
                {
                    dr.Close();
                }
                dr = null;
                Pub.FreeMessageForm();
            }
            if (IsOk)
            {
                Pub.MessageBoxShow(string.Format(Pub.GetResText(formCode, "Msg002", ""), AccName), MessageBoxIcon.Information);
                this.DialogResult = DialogResult.OK;
                this.Close();
            }
        }
Exemple #7
0
        private void btnOk_Click(object sender, EventArgs e)
        {
            formCode = "DBBack";
            string FileName = txtBak.Text.Trim();
            string DBPath   = txtPath.Text;
            string msg      = string.Format(Pub.GetResText(formCode, "Msg001", ""), AccName);
            bool   IsOk     = false;

            string[] s = FileName.Split('.');

            if (FileName == "")
            {
                txtBak.Focus();
                Pub.ShowErrorMsg(Pub.GetResText(formCode, "ErrorDBFileEmpty", ""));
                return;
            }
            if (DBPath == "")
            {
                btnDBPath.Focus();
                Pub.ShowErrorMsg(Pub.GetResText(formCode, "ErrorDBPathEmpty", ""));
                return;
            }
            if (s.Length == 1)
            {
                FileName = FileName + ".bak";
            }
            else if (s[s.Length - 1].Trim() == "")
            {
                FileName = "";
                for (int i = 0; i < s.Length; i++)
                {
                    if (s[i].Trim() != "")
                    {
                        FileName = FileName + s[i].Trim() + ".";
                    }
                }
                FileName = FileName.Substring(0, FileName.Length - 1);
            }
            s = FileName.Split('.');
            if (s.Length == 1)
            {
                FileName = FileName + ".bak";
            }
            FileName = DBPath + FileName;
            Pub.ShowMessageForm(msg);
            try
            {
                if (!db.IsOpen)
                {
                    db.Open(SystemInfo.ConnStr);
                }
                IsOk = db.BackupDatabase(DBName, FileName);
            }
            catch (Exception E)
            {
                Pub.ShowErrorMsg(E);
            }
            finally
            {
                Pub.FreeMessageForm();
            }
            if (IsOk)
            {
                Pub.MessageBoxShow(string.Format(Pub.GetResText(formCode, "Msg002", ""), AccName, "\r\n" + FileName), MessageBoxIcon.Information);
                this.DialogResult = DialogResult.OK;
                this.Close();
            }
            formCode = "DBBack";
        }
Exemple #8
0
        private void LoadData()
        {
            string          DefNo = SystemInfo.ini.ReadIni("Public", "OprtNo", "");
            DataTableReader dr    = null;
            TOprtObject     objOprt;
            string          DBPath = "";
            string          DBName = SystemInfo.NameSpace;
            string          sql    = "";

            cbbOpter.Items.Clear();
            try
            {
                if (SystemInfo.DBType == 0)
                {
                    if (!File.Exists(SystemInfo.AccessDB))
                    {
                        Pub.ShowMessageForm(Pub.GetResText("", "MsgCreating", ""));
                        SystemInfo.objAC.CreateDatabase();
                        SystemInfo.db.Open(SystemInfo.ConnStr);
                        SystemInfo.db.UpdateDatabase(SystemInfo.AppTitle, new DateTime());
                    }
                }
                else if (SystemInfo.DBType == 1 || SystemInfo.DBType == 2)
                {
                    if (SystemInfo.db.IsOpen)
                    {
                        SystemInfo.db.Close();
                    }
                    SystemInfo.db.Open(Pub.GetMSSQLConnStr(DBServerInfo.ServerName, DBServerInfo.WindowsNT,
                                                           DBServerInfo.UserName, DBServerInfo.UserPass, "master"));          //打开数据库
                    dr = SystemInfo.db.GetDataReader("SELECT * FROM sysdatabases WHERE name='" + SystemInfo.NameSpace + "'"); //查询数据库信息
                    if (!dr.Read())
                    {
                        Pub.ShowMessageForm(Pub.GetResText("", "MsgCreating", ""));
                        DBPath = SystemInfo.db.GetDatabasePath().ToString();
                        string mdfFile = DBPath + DBName + ".mdf";
                        string ldfFile = DBPath + DBName + ".ldf";
                        if (File.Exists(mdfFile) && File.Exists(ldfFile))
                        {
                            sql = "EXEC sp_attach_db '" + DBName + "','" + mdfFile + "','" + ldfFile + "'"; //将数据库附加到服务器
                        }
                        else if (File.Exists(mdfFile))
                        {
                            sql = "EXEC sp_attach_single_file_db '" + DBName + "','" + mdfFile + "'";  //恢复数据库
                        }
                        else
                        {
                            sql = "CREATE DATABASE " + DBName + " ON(NAME='" + DBName + "_Data', FILENAME='" + mdfFile +
                                  "') LOG ON(NAME='" + DBName + "_Log',FILENAME='" + ldfFile + "')";   //创建数据库
                        }
                        SystemInfo.db.ExecSQL(sql);
                        SystemInfo.db.Close();
                        SystemInfo.db.Open(SystemInfo.ConnStr);
                        SystemInfo.db.UpdateDatabase(SystemInfo.AppTitle, new DateTime());
                    }
                    dr.Close();
                    SystemInfo.db.Close();
                }
                if (!SystemInfo.db.IsOpen)
                {
                    SystemInfo.db.Open(SystemInfo.ConnStr);
                }
                CheckDBUpdate();
                dr = SystemInfo.db.GetDataReader(Pub.GetSQL(DBCode.DB_000001, new string[] { "1" }));
                while (dr.Read())
                {
                    objOprt       = new TOprtObject();
                    objOprt.Name  = dr["OprtName"].ToString();
                    objOprt.Value = dr["OprtNo"].ToString();
                    objOprt.Text  = objOprt.Value + "[" + objOprt.Name + "]";
                    cbbOpter.Items.Add(objOprt);
                    if ((DefNo != "") && (objOprt.Value == DefNo))
                    {
                        cbbOpter.SelectedIndex = cbbOpter.Items.Count - 1;
                    }
                }
                dr.Close();
            }
            catch (Exception E)
            {
                Pub.ShowErrorMsg(E);
            }
            finally
            {
                Pub.FreeMessageForm();
                if (dr != null)
                {
                    dr.Close();
                }
                dr = null;
            }
            if ((cbbOpter.SelectedIndex == -1) && (cbbOpter.Items.Count > 0))
            {
                cbbOpter.SelectedIndex = 0;
            }
            btnOk.Enabled = (cbbOpter.SelectedIndex >= 0);
        }