private static bool MySqlProductPlanDelete(JXAPI.Component.IBLL.IMysqlBLL.IProductPlanMySqlBLL iMysqlBLL, DataRow dr) { bool flag = true; try { OperationResult <bool> result = iMysqlBLL.Delete(dr); if (result.ResultType != OperationResultType.Success) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("mysql {0}{1}表删除数据失败,主键ID:{2},失败信息:{3}", dr["DbName"], dr["TableName"], dr["KeyValue"], result.Message); myLog.ErrorFormat("mysql {0}{1}表删除数据失败,主键ID:{2},失败信息:{3}", dr["DbName"], dr["TableName"], dr["KeyValue"], result.Message); flag = false; } else { Console.ForegroundColor = ConsoleColor.White; Console.WriteLine("mysql {0}{1}表删除数据成功,主键ID:{2}", dr["DbName"], dr["TableName"], dr["KeyValue"]); } } catch (Exception ex) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("MYSQL DELETE ERROR:{0}", ex.Message); myLog.ErrorFormat("MYSQL DELETE ERROR:{0}", ex.Message); flag = false; } return(flag); }
/// <summary> /// 更新mysql 相关表的公共方法 /// </summary> /// <param name="iBLL">sql对象</param> /// <param name="iMysqlBLL">mysql对象</param> /// <param name="tbName">表名</param> /// <param name="colName">mysql表对应的列名</param> /// <param name="sqlServerColName">sqlServer表对应的列名</param> /// <param name="updateSqlFlag">更新sql数据库更新标记</param> private static void MySqlProductPlanUpdate(JXAPI.Component.IBLL.ISqlServerBLL.IProductPlanBLL iBLL, JXAPI.Component.IBLL.IMysqlBLL.IProductPlanMySqlBLL iMysqlBLL, string tbName , string[] colName, string[] sqlServerColName, bool updateSqlFlag) { int errorSum = 0; Console.WriteLine("===============Mysql {0} BEGIN===================", tbName); try { int maxID = iMysqlBLL.GetMaxID(tbName, colName[0]); string errorMsg = string.Empty; DataTable dTable = iBLL.GetList(tbName, out errorMsg); if (dTable != null && dTable.Rows.Count > 0) { for (int i = 0; i < dTable.Rows.Count; i++) { OperationResult <bool> result = null; if (dTable.Rows[i][0].ToInt() > maxID) { result = iMysqlBLL.Add(tbName, colName, sqlServerColName, dTable.Rows[i]); } else { result = iMysqlBLL.Update(tbName, colName, sqlServerColName, dTable.Rows[i]); } if (result.ResultType != OperationResultType.Success) { errorSum++; Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine(string.Format("{0}表更新数据失败,{1}:{2},失败信息:{3}", tbName, colName[0], dTable.Rows[i][0], result.Message)); myLog.ErrorFormat("{0}表更新数据失败,{1}:{2},失败信息:{3}", tbName, colName[0], dTable.Rows[i][0], result.Message); } else { //由于在同步mysql时需要向不同库的相同表中同步更新数据,而在sqlserver中对应的是同一张表; //因此在修改sqlserver的同步标记时,要等到mysql多张表更新完成之后才能去更新; //当mysql对应数据更新成功之后,去更新sql相应的更新标记 if (updateSqlFlag) { SqlProductPlanUpdate(tbName, sqlServerColName[0], dTable.Rows[i][0].ToInt()); } Console.ForegroundColor = ConsoleColor.White; Console.WriteLine("{0}表已更新{1}条数据", tbName, i + 1); } } if (errorSum != 0) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine(string.Format("{0} 表总共更新完 {1} 条数据,失败数:{2}", tbName, dTable.Rows.Count, errorSum)); } else { Console.ForegroundColor = ConsoleColor.White; Console.WriteLine(string.Format("{0} 表总共更新完 {1} 条数据", tbName, dTable.Rows.Count)); } } if (!string.IsNullOrEmpty(errorMsg)) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine(errorMsg); myLog.ErrorFormat(errorMsg); } } catch (Exception ex) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("Mysql {0} ERROR:{1}", tbName, ex.Message); myLog.ErrorFormat("Mysql {0} ERROR:{1}", tbName, ex.Message); } Console.ForegroundColor = ConsoleColor.White; Console.WriteLine("===============Mysql {0} END===================", tbName); }