diff --git a/Nuvolar.Module.CSharp/BusinessObjects/Migration/Migration_VC.cs b/Nuvolar.Module.CSharp/BusinessObjects/Migration/Migration_VC.cs index 27d87a1..da81ffc 100644 --- a/Nuvolar.Module.CSharp/BusinessObjects/Migration/Migration_VC.cs +++ b/Nuvolar.Module.CSharp/BusinessObjects/Migration/Migration_VC.cs @@ -59,8 +59,10 @@ namespace Nuvolar.Module.BusinessObjects.Migration //Sync_XPObjectType_MSSQL_MySQL(_ocur); //Sync_HCategory_ChartOfAccounts_MSSQL_MySQL(_ocur); //Sync_ChartOfAccounts_MSSQL_MySQL(_ocur); - Sync_ChartOfAccountsYear_MSSQL_MySQL(_ocur); - //Sync_HCategory_Controlling_MSSQL_MySQL(_ocur); + //Sync_ChartOfAccountsYear_MSSQL_MySQL(_ocur); + + Sync_HCategory_Controlling_MSSQL_MySQL(_ocur); + //Sync_Controlling_MSSQL_MySQL(_ocur); } } @@ -472,6 +474,119 @@ namespace Nuvolar.Module.BusinessObjects.Migration } + } + _SqlConnection.Close(); + _MySqlConnection.Close(); + _ocur.Session.ExecuteNonQuery("SET FOREIGN_KEY_CHECKS=1"); + } + private void Sync_Controlling_MSSQL_MySQL(XPObjectSpace _ocur) + { + MigrationParameters _MigrationParameters = View.SelectedObjects[0] as MigrationParameters; + _ocur.Session.ExecuteNonQuery("SET FOREIGN_KEY_CHECKS=0"); + string _ConnectionStringMSSQL = string.Format(" User ID={0}; " + + " Password={1};" + + " Pooling=false;" + + " Data Source={2};" + + " Initial Catalog={3}", + _MigrationParameters.SQLUser, + _MigrationParameters.SQLPassword, + _MigrationParameters.SQLServer, + _MigrationParameters.SQLDatabase); + + + + SqlConnection _SqlConnection = new SqlConnection(_ConnectionStringMSSQL); + MySqlConnection _MySqlConnection = new MySqlConnection(Nuvolar.Module.GeneralFunction.GLOBAL_ConnectionString.Replace("XpoProvider=MySql;", "")); + + _SqlConnection.Open(); + _MySqlConnection.Open(); + if (_SqlConnection.State == ConnectionState.Open) + { + + + string _SQL = " select t1.* " + + " from Controlling t1 left join HCategory t2 on" + + " t1.Oid=t2.Oid" + + " WHERE t2.GCRecord is null"; + SqlCommand _SqlCommand = new SqlCommand(_SQL, _SqlConnection); + SqlDataReader _SqlDataReader = _SqlCommand.ExecuteReader(); + + if (_SqlDataReader.HasRows) + { + while (_SqlDataReader.Read()) + { + string _MySQL = "SELECT count(*) FROM Controlling WHERE Oid=@Oid"; + using (MySqlCommand _MySqlCommand = new MySqlCommand() { CommandText = _MySQL, Connection = _MySqlConnection }) + { + _MySqlCommand.Parameters.Add(new MySqlParameter() { ParameterName = "@Oid", DbType = DbType.Guid, Value = _SqlDataReader["Oid"] }); + + object _Found = _MySqlCommand.ExecuteScalar(); + + if (_Found != null) + { + double _F; + IsNumeric(_Found, out _F); + if (_F == 0) + { + + _MySQL = " SET FOREIGN_KEY_CHECKS=0;" + + " INSERT INTO Controlling (Oid,IsActive,IsCOCRequired,COCAboveAmount," + + " IsParent,Controllingdirection,IsReinvoiceReason,ReinvoiceDescription,TechnicalContractLimit," + + " Controlling1,Controlling2,Controlling3,Controlling4,Controlling5,IsAdvancePayment," + + " IsEstateStatistics,RequireCars,RequireHRPerson,RequirePhones)" + + " SELECT @Oid,@IsActive,@IsCOCRequired,@COCAboveAmount," + + " @IsParent,@Controllingdirection,@IsReinvoiceReason,@ReinvoiceDescription,@TechnicalContractLimit," + + " @Controlling1,@Controlling2,@Controlling3,@Controlling4,@Controlling5,@IsAdnavcePayment," + + " @IsEstateStatistics,@RequireCars,@RequireHRPerson,@RequirePhones;"; + using (MySqlCommand _MySqlCommand_Insert = new MySqlCommand() { CommandText = _MySQL, Connection = _MySqlConnection }) + { + _MySqlCommand_Insert.Parameters.Add(new MySqlParameter() { ParameterName = "@Oid", DbType = DbType.Guid, Value = _SqlDataReader["Oid"] }); + + _MySqlCommand_Insert.Parameters.Add(new MySqlParameter() { ParameterName = "@IsCOCRequired", DbType = DbType.Boolean, Value = _SqlDataReader["IsCOCRequired"] }); + _MySqlCommand_Insert.Parameters.Add(new MySqlParameter() { ParameterName = "@IsParent", DbType = DbType.Boolean, Value = _SqlDataReader["IsParent"] }); + _MySqlCommand_Insert.Parameters.Add(new MySqlParameter() { ParameterName = "@IsActive", DbType = DbType.Boolean, Value = true }); + _MySqlCommand_Insert.Parameters.Add(new MySqlParameter() { ParameterName = "@IsReinvoiceReason", DbType = DbType.Boolean, Value = _SqlDataReader["IsReinvoiceReason"] }); + _MySqlCommand_Insert.Parameters.Add(new MySqlParameter() { ParameterName = "@IsAdvancePayment", DbType = DbType.Boolean, Value = _SqlDataReader["IsAdvancePayment"] }); + _MySqlCommand_Insert.Parameters.Add(new MySqlParameter() { ParameterName = "@IsEstateStatistics", DbType = DbType.Boolean, Value = _SqlDataReader["IsEstateStatistics"] }); + _MySqlCommand_Insert.Parameters.Add(new MySqlParameter() { ParameterName = "@RequireCars", DbType = DbType.Boolean, Value = _SqlDataReader["RequireCars"] }); + _MySqlCommand_Insert.Parameters.Add(new MySqlParameter() { ParameterName = "@RequireHRPerson", DbType = DbType.Boolean, Value = _SqlDataReader["RequireHRPerson"] }); + _MySqlCommand_Insert.Parameters.Add(new MySqlParameter() { ParameterName = "@RequirePhones", DbType = DbType.Boolean, Value = _SqlDataReader["RequirePhones"] }); + + _MySqlCommand_Insert.Parameters.Add(new MySqlParameter() { ParameterName = "@COCAboveAmount", DbType = DbType.Double, Value = _SqlDataReader["COCAboveAmount"] }); + _MySqlCommand_Insert.Parameters.Add(new MySqlParameter() { ParameterName = "@Controllingdirection", DbType = DbType.Int64, Value = _SqlDataReader["Controllingdirection"] }); + _MySqlCommand_Insert.Parameters.Add(new MySqlParameter() { ParameterName = "@ReinvoiceDescription", DbType = DbType.String, Value = _SqlDataReader["ReinvoiceDescription"] }); + _MySqlCommand_Insert.Parameters.Add(new MySqlParameter() { ParameterName = "@TechnicalContractLimit", DbType = DbType.Double, Value = _SqlDataReader["TechnicalContractLimit"] }); + for (int i = 1; i < 6; i++) + { + _MySqlCommand_Insert.Parameters.Add(new MySqlParameter() { ParameterName = "@Controlling" + i, DbType = DbType.Guid, Value = _SqlDataReader["Controlling" + i] }); + } + _MySqlCommand_Insert.ExecuteNonQuery(); + } + } + else // Ha már VAN + { + //_MySQL = " SET FOREIGN_KEY_CHECKS=0;" + + // " UPDATE HCategory SET Name=@Name," + + // " Parent=@Parent " + + // " WHERE Oid=@Oid"; + //using (MySqlCommand _MySqlCommand_Update = new MySqlCommand() { CommandText = _MySQL, Connection = _MySqlConnection }) + //{ + + // _MySqlCommand_Update.Parameters.Add(new MySqlParameter() { ParameterName = "@Oid", DbType = DbType.Guid, Value = _SqlDataReader["Oid"] }); + // _MySqlCommand_Update.Parameters.Add(new MySqlParameter() { ParameterName = "@Parent", DbType = DbType.Guid, Value = _SqlDataReader["Parent"] }); + // _MySqlCommand_Update.Parameters.Add(new MySqlParameter() { ParameterName = "@Name", DbType = DbType.String, Value = _SqlDataReader["Name"] }); + + // _MySqlCommand_Update.ExecuteNonQuery(); + //} + + } + } + } + + } + } + + } _SqlConnection.Close(); _MySqlConnection.Close();