/// <summary> /// 测试数据连接通断 /// </summary> /// <param name="idx">连接序号,0为第一个连接</param> /// <returns>True 通; False 断</returns> public static bool TestConnection(int idx = 0) { if (dataStatus == EDataStatus.数据库) { return(DirectDBAccessor.testConn(idx)); } else { bool result = false; try { if (wcf == null) { WCF.WinLogin login = new WCF.WinLogin(); if (login.ShowDialog() == false) { System.Windows.MessageBox.Show("WCF数据服务连接失败,退出程序!"); Environment.Exit(0); } } result = true; } catch { } return(result); } }
/// <summary> /// 按给定的SQL语句查询数据,查询将依次尝试所有连接,直至获取数据,不通的连接在程序运行期间将不再尝试 /// </summary> /// <param name="sql">SQL语句</param> /// <param name="isShowMessage">出错时,是否弹出错误信息窗体</param> /// <param name="groupNum">分组号,仅同时多种数据源时需给出此参数</param> /// <returns>返回DataTable</returns> public static DataTable getDataTableFromSQL(string sql, bool isShowMessage = true) { if (string.IsNullOrWhiteSpace(sql)) { return(null); } DataTable dt = null; if (dataStatus == EDataStatus.WCF) { try { if (wcf == null) { WCF.WinLogin login = new WCF.WinLogin(); if (login.ShowDialog() == false) { if (isShowMessage) { System.Windows.MessageBox.Show("WCF数据服务失败,退出程序!"); Environment.Exit(0); } } } dt = wcf.GetDataTable(sql, curDataSourceName); } catch (Exception ee) { try { WCF.WinLogin login = new WCF.WinLogin(); if (login.ShowDialog() == false) { if (isShowMessage) { System.Windows.MessageBox.Show("WCF数据服务失败,退出程序!" + ee.Message); Environment.Exit(0); } } dt = wcf.GetDataTable(sql, curDataSourceName); } catch (Exception eee) { if (isShowMessage) { System.Windows.MessageBox.Show("WCF数据服务失败,退出程序!" + eee.Message); Environment.Exit(0); } } } } else { dt = DirectDBAccessor.readDataBase(sql, isShowMessage, curDataSourceName); } return(dt); }
/// <summary> /// 批量执行 /// </summary> /// <param name="sqls">sql语句列表</param> public static void bacthExecute(List <string> sqls) { if (dataStatus == EDataStatus.数据库) { DirectDBAccessor.bacthExecute(sqls, curDataSourceName); } else { } }
/// <summary> /// 执行给定的SQL语句,程序尝试对所有连接执行该SQL语句,不通的连接在程序运行期间不再尝试。 /// </summary> /// <param name="sql">SQL语句</param> public static bool ExecuteSQL(string sql, bool isShowMessage = true) { if (dataStatus != EDataStatus.WCF) { return(DirectDBAccessor.executeCommand(sql, isShowMessage, curDataSourceName)); } else { try { if (wcf == null) { WCF.WinLogin login = new WCF.WinLogin(); if (login.ShowDialog() == false) { if (isShowMessage) { System.Windows.MessageBox.Show("WCF数据服务连接失败,退出程序!"); Environment.Exit(0); } } } return(wcf.ExecuteCommand(sql, curDataSourceName)); } catch { try { WCF.WinLogin login = new WCF.WinLogin(); if (login.ShowDialog() == false) { if (isShowMessage) { System.Windows.MessageBox.Show("WCF数据服务连接失败,退出程序!"); Environment.Exit(0); } } return(wcf.ExecuteCommand(sql, curDataSourceName)); } catch { System.Windows.MessageBox.Show("WCF数据服务连接失败,退出程序!"); Environment.Exit(0); } return(false); } } }