Ejemplo n.º 1
0
        public void Initial(SqlCopier sqlSource,SqlCopier sqlDest, object param)
        {
            Commands.Clear();

            MigrateCommandBase cmd1 = new cmdMigrateUser(sqlSource, sqlDest, param);
            Commands.Add(CommandNames[0], cmd1);
        }
 public MigrateCommandBase(SqlCopier sqlSourceCopier, SqlCopier sqlDestCopier, object parameters)
 {
     this.Name = "commandName";
     SqlSourceCopier = sqlSourceCopier;
     SqlDestCopier = sqlDestCopier;
     Parameters = parameters;
 }
Ejemplo n.º 3
0
 private void btnSourceCnn_Click(object sender, EventArgs e)
 {
     if (GetSourceConnectionClick != null)
     {
         GetSourceConnectionClick.Invoke(this, out sourceCnn);
         if (sourceCnn != string.Empty)
         {
             sqlSourceCopier = new SqlCopier(sourceCnn);
             this.gridSource.DataSource = sqlSourceCopier.GetAllTables();
         }
     }
 }
Ejemplo n.º 4
0
        private void btnDestCnn_Click(object sender, EventArgs e)
        {
            if (GetDestinationConnectionClick != null)
            {
                GetDestinationConnectionClick.Invoke(this, out destCnn);

                if (destCnn != string.Empty)
                {
                    sqlDestCopier = new SqlCopier(destCnn);
                    this.gridDestination.DataSource = sqlDestCopier.GetAllTables();
                }
            }
        }
        public void DoUpgrate()
        {
            SqlCopier sqlCopier = new SqlCopier(_connection);
            UpgradeDatabase upgradeDatabase = new UpgradeDatabase();
            string unitCode = FDHelper.RgCodeOfUnit();

            var currentVersions = _version.Split('.');
            int fromVersion = 0;

            for (int i = 0; i < UpgradeDatabase.CommandNames.Length; i++)
            {
                var newVersions = UpgradeDatabase.CommandNames[i].Split('.');
                if (int.Parse(currentVersions[0]) < int.Parse(newVersions[0]) ||
                    int.Parse(currentVersions[1]) < int.Parse(newVersions[1]) ||
                    int.Parse(currentVersions[2]) < int.Parse(newVersions[2]))
                {
                    fromVersion = i;
                    break;
                }
            }

            upgradeDatabase.InitialCommands(sqlCopier);

            for (int i = fromVersion; i < UpgradeDatabase.CommandNames.Length; i++)
            {
                if (!upgradeDatabase.UpgradeCommands[UpgradeDatabase.CommandNames[i]].DoUpgrade(new List<object> { this.progressBar1, unitCode }))
                {
                    MessageBox.Show(
                        "Nâng cấp cơ sở dữ liệu không thành công. Ứng dụng không thể tiếp tục chạy.\r\nVui lòng liên hệ với TechLink để được trợ giúp!",
                        "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    Environment.Exit(0);
                }

            }

            MessageBox.Show(
                "Nâng cấp cơ sở dữ liệu thành công. Nhấn OK để tiếp tục!",
                "Info", MessageBoxButtons.OK, MessageBoxIcon.Information);
            this.Close();
        }
        private void btnBackup_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(connectionString))
            {
                MessageBox.Show("Chưa có thông tin cơ sở dữ liệu sao lưu!", "Warning", MessageBoxButtons.OK,
                                MessageBoxIcon.Warning);
                return;
            }

            if (string.IsNullOrEmpty(txtSavePath.Text))
            {
                MessageBox.Show("Chưa có chọn thư mục lưu trữ cơ sở dữ liệu sao lưu!", "Warning", MessageBoxButtons.OK,
                                MessageBoxIcon.Warning);
                return;
            }

            SqlCopier sqlCopier = new SqlCopier(connectionString);
            if(optBackupAll.Checked)
            {
                var ret = sqlCopier.RunStoreProc("BackupFullDatabase", new object[] { "@fileSaved", txtSavePath.Text });
                if(ret!=null)
                {
                    MessageBox.Show("Sao lưu dữ liệu thành công!", "Info", MessageBoxButtons.OK,
                                MessageBoxIcon.Information);
                }
            }
            else
            {
                var ret = sqlCopier.RunStoreProc("BackupDiferentialDatabase", new object[] { "@fileSaved", txtSavePath.Text });
                if (ret != null)
                {
                    MessageBox.Show("Sao lưu dữ liệu thành công!", "Info", MessageBoxButtons.OK,
                                MessageBoxIcon.Information);
                }
            }
        }
Ejemplo n.º 7
0
        private static void RegisterSuccess()
        {
            if (ConfigurationManager.ConnectionStrings["dbEcustomEntities"] == null)
            {
                Application.Run(new frmConfigSQL());
            }
            if (ConfigurationManager.ConnectionStrings["dbEcustomEntities"] == null)
            {
                Application.Exit();
                return;
            }
            string connectionString =
                Common.Decrypt(ConfigurationManager.ConnectionStrings["dbEcustomEntities"].ConnectionString, true);
            connectionString = connectionString.Substring(connectionString.IndexOf('\'') == -1 ? 0 : connectionString.IndexOf('\'')).Trim('\'');
            SqlCopier sqlCopier = new SqlCopier(connectionString);

            var tables = sqlCopier.GetAllTables();
            var tblSettings = tables.FirstOrDefault(item => item.Name.ToLower() == "tblsettings");
            if (tblSettings == null)
            {
                ConfirmUpgradeDB();
                //frmUpgradeDatabase upgradeDatabase = new frmUpgradeDatabase(ConstantInfo.CurrentVersion, connectionString);
                Application.Run(new frmUpgradeDatabase(ConstantInfo.CurrentVersion, connectionString));
            }
            else
            {
                var data = sqlCopier.GetDataFromTable(tblSettings.Name);
                var version = (data.Rows.Count == 0 ? ConstantInfo.CurrentVersion : data.Rows[0]["Version"].ToString());

                if (version != UpgradeDatabase.CommandNames[UpgradeDatabase.CommandNames.Length - 1])
                {
                    ConfirmUpgradeDB();
                    Application.Run(new frmUpgradeDatabase(version, connectionString));

                }
            }

            Application.Run(new frmLogin());
        }
        public UpgradeCommandBase(SqlCopier sqlCopier)
        {
            Version = "1.0.0";
            _SqlCopier = sqlCopier;

        }
        public UpgradeVersion100(SqlCopier sqlCopier)
            : base(sqlCopier)
        {
            Version = "1.0.1";
            
            sqlQueries.Add(
                string.Format(
                    "CREATE PROCEDURE [dbo].[BackupDiferentialDatabase] @fileSaved nvarchar(500) AS BACKUP DATABASE {0} TO DISK = @fileSaved WITH DIFFERENTIAL, MEDIANAME = 'Z_SQLServerBackups', NAME = 'Diferential Backup of {0}';",
                    sqlCopier.Database));
            sqlQueries.Add(
                string.Format(
                    "CREATE PROCEDURE [dbo].[BackupFullDatabase] @fileSaved nvarchar(500) AS BACKUP DATABASE {0} TO DISK = @fileSaved WITH FORMAT, MEDIANAME = 'Z_SQLServerBackups', NAME = 'Full Backup of {0}';",
                    sqlCopier.Database));

            if (FDHelper.RgGetSizeOfUnit() == ConstantInfo.Boss)
            {
                sqlQueries.Add(
                    "CREATE TABLE [dbo].[tblBranchDatabases]([Id] [nvarchar] (15) NOT NULL,[DatabaseName] [nvarchar](120) NOT NULL,[RegisterSerial] [nvarchar](128) NOT NULL,[BranchName] [nvarchar](300) NOT NULL,[LastSync] [datetime] NOT NULL, [IsRequestingSync] [bit] NOT NULL,CONSTRAINT [PK_tblBranchDatabases] PRIMARY KEY CLUSTERED ([Id] ASC)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]) ON [PRIMARY]");
            }

            sqlQueries.Add("CREATE TABLE [dbo].[tblSettings]([Version] [nvarchar](50) NOT NULL,[LastSync] [datetime] NOT NULL,[SyncInterval] [int] NULL,[SyncTime] [nvarchar](6) NULL,[IsStartingSync] [bit] NOT NULL,CONSTRAINT [PK_tblSettings] PRIMARY KEY CLUSTERED ([Version] ASC)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]) ON [PRIMARY]");
            sqlQueries.Add("INSERT INTO [dbo].[tblSettings]([Version],[LastSync], [IsStartingSync]) VALUES('1.0.1', '09/02/2012', 0)");

            sqlQueries.Add("ALTER TABLE dbo.tblDeclaration DROP CONSTRAINT FK_tblDeclaration_tblUser");
            //sqlQueries.Add("ALTER TABLE dbo.tblUser DROP CONSTRAINT PK_tblUsers");
            sqlQueries.Add("ALTER TABLE dbo.tblUser ADD CONSTRAINT	PK_tblUsers PRIMARY KEY CLUSTERED(UserID,BranchId) WITH( STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]");

            //sqlQueries.Add("ALTER TABLE dbo.tblApplicationObject DROP CONSTRAINT PK_ApplicationObject");
            sqlQueries.Add("ALTER TABLE dbo.tblApplicationObject ADD CONSTRAINT	PK_ApplicationObject PRIMARY KEY CLUSTERED (	ApplicationObjectID,BranchId) WITH( STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]");

            //sqlQueries.Add("ALTER TABLE dbo.tblCheck DROP CONSTRAINT PK_tblCheck");
            sqlQueries.Add("ALTER TABLE dbo.tblCheck ADD CONSTRAINT	PK_tblCheck PRIMARY KEY CLUSTERED (CheckID,BranchId) WITH( STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]");

            //sqlQueries.Add("ALTER TABLE dbo.tblCompany DROP CONSTRAINT PK_tblCompany");
            sqlQueries.Add("ALTER TABLE dbo.tblCompany ADD CONSTRAINT PK_tblCompany PRIMARY KEY CLUSTERED (CompanyCode,BranchId) WITH( STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]");

            //sqlQueries.Add("ALTER TABLE dbo.tblCustoms DROP CONSTRAINT PK_tblCustoms");
            sqlQueries.Add("ALTER TABLE dbo.tblCustoms ADD CONSTRAINT PK_tblCustoms PRIMARY KEY CLUSTERED (CustomsCode,	BranchId) WITH( STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]");

            //sqlQueries.Add("ALTER TABLE dbo.tblDeclaration DROP CONSTRAINT PK_tblDeclaration");
            sqlQueries.Add("ALTER TABLE dbo.tblDeclaration ADD CONSTRAINT PK_tblDeclaration PRIMARY KEY CLUSTERED (DeclarationID, BranchId) WITH( STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]");

            //sqlQueries.Add("ALTER TABLE dbo.tblGoodsType DROP CONSTRAINT PK_tblGoodsType");
            sqlQueries.Add("ALTER TABLE dbo.tblGoodsType ADD CONSTRAINT PK_tblGoodsType PRIMARY KEY CLUSTERED (TypeId,	BranchId) WITH( STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]");

            //sqlQueries.Add("ALTER TABLE dbo.tblGate DROP CONSTRAINT PK_tblGate");
            sqlQueries.Add("ALTER TABLE dbo.tblGate ADD CONSTRAINT	PK_tblGate PRIMARY KEY CLUSTERED (GateCode,	BranchId) WITH( STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]");

            //sqlQueries.Add("ALTER TABLE dbo.tblDeclarationVehicle DROP CONSTRAINT PK_tblDeclarationVehicle");
            sqlQueries.Add("ALTER TABLE dbo.tblDeclarationVehicle ADD CONSTRAINT PK_tblDeclarationVehicle PRIMARY KEY CLUSTERED (DeclarationID,	VehicleID,	BranchId) WITH( STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]");

            //sqlQueries.Add("ALTER TABLE dbo.tblDeclarationLoan DROP CONSTRAINT PK_tblDeclarationLoan");
            sqlQueries.Add("ALTER TABLE dbo.tblDeclarationLoan ADD CONSTRAINT PK_tblDeclarationLoan PRIMARY KEY CLUSTERED (ID,	BranchId) WITH( STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]");

            //sqlQueries.Add("ALTER TABLE dbo.tblGroup DROP CONSTRAINT PK_tblGroup");
            sqlQueries.Add("ALTER TABLE dbo.tblGroup ADD CONSTRAINT PK_tblGroup PRIMARY KEY CLUSTERED (GroupID,	BranchId) WITH( STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]");

            //sqlQueries.Add("ALTER TABLE dbo.tblPermission DROP CONSTRAINT PK__tblPermi__EFA6FB0F29E1370A");
            sqlQueries.Add("ALTER TABLE dbo.tblPermission ADD CONSTRAINT PK_tblPermission PRIMARY KEY CLUSTERED (PermissionID, BranchId) WITH( STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]");

            //sqlQueries.Add("ALTER TABLE dbo.tblPermissionType DROP CONSTRAINT PK_tblPermissionType");
            sqlQueries.Add("ALTER TABLE dbo.tblPermissionType ADD CONSTRAINT PK_tblPermissionType PRIMARY KEY CLUSTERED (TypeCode,	BranchId) WITH( STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]");

            //sqlQueries.Add("ALTER TABLE dbo.tblProfileConfig DROP CONSTRAINT PK_tblProfileConfig");
            sqlQueries.Add("ALTER TABLE dbo.tblProfileConfig ADD CONSTRAINT PK_tblProfileConfig PRIMARY KEY CLUSTERED (ID,	BranchId) WITH( STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]");

            //sqlQueries.Add("ALTER TABLE dbo.tblUserInGroup DROP CONSTRAINT PK_tblUserInGroup");
            sqlQueries.Add("ALTER TABLE dbo.tblUserInGroup ADD CONSTRAINT PK_tblUserInGroup PRIMARY KEY CLUSTERED (UserID,	GroupID, BranchId) WITH( STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]");

            //sqlQueries.Add("ALTER TABLE dbo.tblUserGroupPermission DROP CONSTRAINT PK__tblUserG__3214EC277D439ABD");
            sqlQueries.Add("ALTER TABLE dbo.tblUserGroupPermission ADD CONSTRAINT PK_tblUserGroupPms PRIMARY KEY CLUSTERED (ID,	BranchId) WITH( STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]");

            //sqlQueries.Add("ALTER TABLE dbo.tblType DROP CONSTRAINT PK_tblType");
            sqlQueries.Add("ALTER TABLE dbo.tblType ADD CONSTRAINT	PK_tblType PRIMARY KEY CLUSTERED (TypeCode,	BranchId) WITH( STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]");

            //sqlQueries.Add("ALTER TABLE dbo.tblRoleInGroup DROP CONSTRAINT PK_tblRoleInGroup");
            sqlQueries.Add("ALTER TABLE dbo.tblRoleInGroup ADD CONSTRAINT PK_tblRoleGroups PRIMARY KEY CLUSTERED (GroupID,	RoleID,	BranchId) WITH( STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]");

            //sqlQueries.Add("ALTER TABLE dbo.tblVehicle DROP CONSTRAINT PK_tblVehicle");
            sqlQueries.Add("ALTER TABLE dbo.tblVehicle ADD CONSTRAINT PK_tblVehicle PRIMARY KEY CLUSTERED (VehicleID, BranchId) WITH( STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]");

            //sqlQueries.Add("ALTER TABLE dbo.tblVehicleCheck DROP CONSTRAINT PK_tblVehicleCheck");
            sqlQueries.Add("ALTER TABLE dbo.tblVehicleCheck ADD CONSTRAINT PK_tblVehicleCheck PRIMARY KEY CLUSTERED (VehicleCheckID, BranchId) WITH( STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]");

            //sqlQueries.Add("ALTER TABLE dbo.tblVehicleFeeSetting DROP CONSTRAINT PK_tblVehicleFeeSetting");
            sqlQueries.Add("ALTER TABLE dbo.tblVehicleFeeSetting ADD CONSTRAINT	PK_tblVehicleFeeSetting PRIMARY KEY CLUSTERED (VehicleTypeId,	GoodsTypeId, BranchId) WITH( STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]");

            //sqlQueries.Add("ALTER TABLE dbo.tblVehicleType DROP CONSTRAINT PK_tblVehicleType");
            sqlQueries.Add("ALTER TABLE dbo.tblVehicleType ADD CONSTRAINT PK_tblVehicleType PRIMARY KEY CLUSTERED (VehicleTypeID, BranchId) WITH( STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]");

            //sqlQueries.Add("ALTER TABLE dbo.tblRoleInGroup DROP CONSTRAINT PK_tblRoleInGroup");
            sqlQueries.Add("ALTER TABLE dbo.tblRoleInGroup DROP CONSTRAINT FK_tblRoleInGroup_tlbRole");

            //sqlQueries.Add("ALTER TABLE dbo.tlbRole DROP CONSTRAINT PK_tlbRole");
            sqlQueries.Add("ALTER TABLE dbo.tlbRole ADD CONSTRAINT PK_tlbRole PRIMARY KEY CLUSTERED (RoleID, BranchId) WITH( STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]");
        }
 public void InitialCommands(SqlCopier sqlCopier)
 {
     UpgradeCommandBase cmd1 = new UpgradeVersion100(sqlCopier);
     UpgradeCommands.Add(CommandNames[0], cmd1);
 }
Ejemplo n.º 11
0
 public cmdMigrateUser(SqlCopier sqlSourceCopier, SqlCopier sqlDestCopier, object parameters)
     : base(sqlSourceCopier, sqlDestCopier, parameters)
 {
     this.Name = "cmdMigrateUser";
 }