예제 #1
0
        public void AutoRunQuery()
        {
            btnOk.Enabled = false;
            int count = GlobalVariable.FileListSQLUpdate.Split(';').Length;

            try
            {
                CommonFunction.BackupDatabase(splashScreenManager, "BeforeUpdateData", false);
                Cursor = Cursors.WaitCursor;
                splashScreenManager.ShowWaitForm();
                splashScreenManager.SetWaitFormCaption("Đang thực hiện cập nhật dữ liệu");
                splashScreenManager.SetWaitFormDescription("Vui lòng đợi ..");

                int slot = 1;
                while (slot < count)
                {
                    string scriptContent;
                    //var databaseNameForUpdate = (string) grdlookUpEditDatabase.EditValue;
                    //MessageBox.Show(GlobalVariable.DatabaseName);
                    var databaseForUpdate = GlobalVariable.Server.Databases[GlobalVariable.DatabaseName];
                    using (var streamReader = new StreamReader(GlobalVariable.FileListSQLUpdate.Split(';')[slot].Trim()))
                    {
                        scriptContent = streamReader.ReadToEnd();
                    }
                    databaseForUpdate.ExecuteNonQuery(scriptContent);
                    slot++;
                }
                if (splashScreenManager.IsSplashFormVisible)
                {
                    splashScreenManager.CloseWaitForm();
                }
                var resultMessage = XtraMessageBox.Show(ResourceHelper.GetResourceValueByName("ResUpdateDatabaseSucces"),
                                                        ResourceHelper.GetResourceValueByName("ResSuccessfullCaption"),
                                                        MessageBoxButtons.OK, MessageBoxIcon.Information);
                if (resultMessage == DialogResult.OK)
                {
                    splashScreenManager.Dispose();
                    for (int i = 1; i < count; i++)
                    {
                        File.Delete(GlobalVariable.FileListSQLUpdate.Split(';')[i]);
                    }
                    AutoUpdaterPlugin.IsAutoUpdate = true;
                    System.Windows.Forms.Application.Restart();
                }


                Cursor = Cursors.Default;
            }
            catch (Exception ex)
            {
                Cursor = Cursors.Default;
                splashScreenManager.CloseWaitForm();
                XtraMessageBox.Show(ResourceHelper.GetResourceValueByName("ErrorAuroRunQuery") + ": " + ex,//ex.ToString(),
                                    ResourceHelper.GetResourceValueByName("ResExceptionCaption"), MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
예제 #2
0
        /// <summary>
        /// Handles the Click event of the btnOk control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
        private void btnOk_Click(object sender, EventArgs e)
        {
            try
            {
                CommonFunction.BackupDatabase(splashScreenManager, "BeforeUpdateData", false);
                Cursor = Cursors.WaitCursor;
                splashScreenManager.ShowWaitForm();
                splashScreenManager.SetWaitFormCaption("Đang thực hiện cập nhật dữ liệu");
                splashScreenManager.SetWaitFormDescription("Vui lòng đợi ..");
                if (ValidData())
                {
                    string scriptContent;
                    var    databaseNameForUpdate = (string)grdlookUpEditDatabase.EditValue;
                    var    databaseForUpdate     = GlobalVariable.Server.Databases[databaseNameForUpdate];
                    using (var streamReader = new StreamReader(btnSelectFile.Text.Trim()))
                    {
                        scriptContent = streamReader.ReadToEnd();
                    }
                    databaseForUpdate.ExecuteNonQuery(scriptContent);
                    splashScreenManager.CloseWaitForm();
                    var resultMessage = XtraMessageBox.Show(ResourceHelper.GetResourceValueByName("ResUpdateDatabaseSucces"),
                                                            ResourceHelper.GetResourceValueByName("ResSuccessfullCaption"),
                                                            MessageBoxButtons.OK, MessageBoxIcon.Information);
                    if (resultMessage == DialogResult.OK)
                    {
                        AutoUpdaterPlugin.IsAutoUpdate = true;
                        System.Windows.Forms.Application.Restart();
                    }
                }

                Cursor = Cursors.Default;
            }
            catch (Exception ex)
            {
                Cursor = Cursors.Default;
                splashScreenManager.CloseWaitForm();
                XtraMessageBox.Show(ex.ToString(),
                                    ResourceHelper.GetResourceValueByName("ResExceptionCaption"), MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }