/// <summary> /// 设置是否可用 /// </summary> /// <param name="id"></param> /// <param name="loginAccountId"></param> /// <returns></returns> public bool CanUse(int id, string loginAccountId) { ConnectionStringSettings settings = ConfigurationManager.ConnectionStrings["connectStr_pangu"]; string conStr = SysInfoManage.DENString(settings.ConnectionString); using (ULinker.Common.DB.DBHelper db = new Common.DB.DBHelper(conStr)) { try { string strCmd = @"UPDATE `user` SET `IsUse`=IF( `IsUse`=FALSE,TRUE,FALSE) WHERE `Id`=@Id"; MySqlParameter[] paramters = new MySqlParameter[] { new MySqlParameter("@Id", MySqlDbType.Int32) }; paramters[0].Value = id; int count = db.ExecuteNonQuery(strCmd, paramters); return(count > 0 ? true : false); } catch (Exception ex) { Log4Helper.Error(this.GetType(), String.Format("AdminUserDao.CanUse.{0}", ex.Message), new Exception("error")); return(false); } } }
/// <summary> /// 物理删除 /// </summary> /// <param name="id"></param> /// <param name="loginAccountId"></param> /// <returns></returns> public bool PhysicDelete(int id, string loginAccountId) { ConnectionStringSettings settings = ConfigurationManager.ConnectionStrings["connectStr"]; string conStr = SysInfoManage.DENString(settings.ConnectionString); using (ULinker.Common.DB.DBHelper db = new Common.DB.DBHelper(conStr)) { try { string strCmd = @"DELETE FROM `api` WHERE `Id`=@Id"; MySqlParameter[] paramters = new MySqlParameter[] { new MySqlParameter("@Id", MySqlDbType.Int32) }; paramters[0].Value = id; int count = db.ExecuteNonQuery(strCmd, paramters); return(count > 0 ? true : false); } catch (Exception ex) { Log4Helper.Error(this.GetType(), String.Format("ApiDao.PhysicDelete.{0}", ex.Message), new Exception("error")); return(false); } } }
public Api GetById(int id) { ConnectionStringSettings settings = ConfigurationManager.ConnectionStrings["connectStr"]; string conStr = SysInfoManage.DENString(settings.ConnectionString); using (ULinker.Common.DB.DBHelper db = new Common.DB.DBHelper(conStr)) { Api item = null; try { string strCmd = @"SELECT * FROM `api` WHERE `Id`=@Id"; MySqlParameter[] paramters = new MySqlParameter[] { new MySqlParameter("@Id", MySqlDbType.Int32) }; paramters[0].Value = id; DataRow dr = db.GetDataRow(strCmd, paramters); if (dr != null) { item = RowToObject(dr); } } catch (Exception ex) { Log4Helper.Error(this.GetType(), String.Format("ApiDao.GetById.{0}", ex.Message), new Exception("error")); } return(item); } }
public UserPlatform GetByAppKey(string appkey, string appsecrect) { ConnectionStringSettings settings = ConfigurationManager.ConnectionStrings["connectStr"]; string conStr = SysInfoManage.DENString(settings.ConnectionString); using (ULinker.Common.DB.DBHelper db = new Common.DB.DBHelper(conStr)) { UserPlatform item = null; try { string strCmd = @"SELECT * FROM `userplatform` WHERE `AppKey`=@AppKey AND `AppSecrect`=@AppSecrect"; MySqlParameter[] paramters = new MySqlParameter[] { new MySqlParameter("@AppKey", MySqlDbType.String), new MySqlParameter("@AppSecrect", MySqlDbType.String) }; paramters[0].Value = appkey; paramters[1].Value = appsecrect; DataRow dr = db.GetDataRow(strCmd, paramters); if (dr != null) { item = RowToObject(dr); } } catch (Exception ex) { Log4Helper.Error(this.GetType(), String.Format("UserPlatformDao.GetByAppKey.{0}", ex.Message), new Exception("error")); } return(item); } }
public bool IsExistAppKey(string appKey) { ConnectionStringSettings settings = ConfigurationManager.ConnectionStrings["connectStr"]; string conStr = SysInfoManage.DENString(settings.ConnectionString); using (ULinker.Common.DB.DBHelper db = new Common.DB.DBHelper(conStr)) { int total = 0; try { string strCmd = @"SELECT COUNT(1) FROM `userplatform` WHERE `AppKey`=@AppKey"; MySqlParameter[] paramters = new MySqlParameter[] { new MySqlParameter("@AppKey", MySqlDbType.String) }; paramters[0].Value = appKey; DataRow row = db.GetDataRow(strCmd, paramters); if (row != null) { total = int.Parse(row["COUNT(1)"].ToString()); } } catch (Exception ex) { Log4Helper.Error(this.GetType(), String.Format("PlatformDao.IsExistAppKey.{0}", ex.Message), ex); } return(total > 0 ? true : false); } }
public int DataTableToExcel(DataTable data, string sheetName, bool isColumnWritten) { int i = 0; int j = 0; int count = 0; ISheet sheet = null; Fs = new FileStream(FileName, FileMode.OpenOrCreate, FileAccess.ReadWrite); if (FileName.IndexOf(".xlsx") > 0) // 2007版本 { Workbook = new XSSFWorkbook(); } else if (FileName.IndexOf(".xls") > 0) // 2003版本 { Workbook = new HSSFWorkbook(); } try { if (Workbook != null) { sheet = Workbook.CreateSheet(); } else { return(-1); } if (isColumnWritten == true) //写入DataTable的列名 { IRow row = sheet.CreateRow(0); for (j = 0; j < data.Columns.Count; ++j) { row.CreateCell(j).SetCellValue(data.Columns[j].ColumnName); } count = 1; } else { count = 0; } for (i = 0; i < data.Rows.Count; ++i) { IRow row = sheet.CreateRow(count); for (j = 0; j < data.Columns.Count; ++j) { row.CreateCell(j).SetCellValue(data.Rows[i][j].ToString()); } ++count; } Workbook.Write(Fs); //写入到excel return(count); } catch (Exception ex) { Log4Helper.Error(typeof(ExcelManager), ex.Message, ex); return(-1); } }
public static DataSet ExecuteQuery(string sqrstr) { DataSet ds = new DataSet(); using (NpgsqlConnection SqlConn = new NpgsqlConnection(GetConn())) { try { if (SqlConn.State != ConnectionState.Open) { SqlConn.Open(); } using (NpgsqlDataAdapter sqldap = new NpgsqlDataAdapter(sqrstr, SqlConn)) { sqldap.Fill(ds); } } catch (Exception ex) { Log4Helper.Error(new PostgresqlHelper().GetType(), "数据库操作异常!", ex); throw (ex); } } return(ds); }
public override int ExcuteSql(string sql) { int effectRows = 0; using (IDbConnection iConn = this.GetConnection()) { using (IDbCommand iCmd = this.GetCommand(sql, iConn)) { try { iConn.Open(); effectRows = iCmd.ExecuteNonQuery(); } catch (Exception ex) { Log4Helper.Error(GetType(), "SqlServer数据库操作异常!", ex); throw new Exception(ex.Message); } finally { if (iConn.State != ConnectionState.Closed) { iConn.Close(); } } } } return(effectRows); }
public bool Create(AppApi model) { ConnectionStringSettings settings = ConfigurationManager.ConnectionStrings["connectStr"]; string conStr = SysInfoManage.DENString(settings.ConnectionString); using (ULinker.Common.DB.DBHelper db = new Common.DB.DBHelper(conStr)) { try { string strCmd = @"INSERT INTO `appapi` (`AppId`,`ApiId`,`IsUse`,`CreateTime`,`ModifyTime`) VALUES(@AppId,@ApiId,@IsUse,NOW(),NOW())"; MySqlParameter[] paramters = new MySqlParameter[] { new MySqlParameter("@AppId", MySqlDbType.Int32), new MySqlParameter("@ApiId", MySqlDbType.Int32), new MySqlParameter("@IsUse", MySqlDbType.Binary) }; paramters[0].Value = model.Id; paramters[1].Value = model.Description; paramters[2].Value = model.IsUse; int count = db.ExecuteNonQuery(strCmd, paramters); return(count > 0 ? true : false); } catch (Exception ex) { Log4Helper.Error(this.GetType(), String.Format("AppApiDao.Create.{0}", ex.Message), new Exception("error")); return(false); } } }
public override DataSet Query(string sql, string tableName, params IDataParameter[] iParams) { DataSet ds = new DataSet(); using (IDbConnection iConn = this.GetConnection()) { IDbCommand iCmd = null; try { PrepareCommand(out iCmd, iConn, null, sql, iParams); IDataAdapter ida = this.GetAdapter(iCmd); ida.TableMappings.Add("Table", tableName); ida.Fill(ds); iCmd.Parameters.Clear(); } catch (Exception ex) { Log4Helper.Error(GetType(), "SqlServer数据库操作异常!", ex); throw new Exception(ex.Message); } finally { iCmd.Dispose(); if (iConn.State != ConnectionState.Closed) { iConn.Close(); } } } return(ds); }
public override object GetSingle(string sql, params IDataParameter[] iParams) { using (IDbConnection iConn = this.GetConnection()) { IDbCommand iCmd = null; try { iConn.Open(); PrepareCommand(out iCmd, iConn, null, sql, iParams); object obj = iCmd.ExecuteScalar(); if (Object.Equals(obj, null) || Object.Equals(obj, System.DBNull.Value)) { return(null); } else { return(obj); } } catch (Exception ex) { Log4Helper.Error(GetType(), "SqlServer数据库操作异常!", ex); throw new Exception(ex.Message); } finally { iCmd.Dispose(); if (iConn.State != ConnectionState.Closed) { iConn.Close(); } } } }
public override DataSet Query(string sql, string tableName) { DataSet ds = new DataSet(); using (IDbConnection iConn = this.GetConnection()) { try { iConn.Open(); IDataAdapter ida = this.GetAdapter(sql, iConn); ida.TableMappings.Add("Table", tableName); ida.Fill(ds); } catch (Exception ex) { Log4Helper.Error(GetType(), "SqlServer数据库操作异常!", ex); throw new Exception(ex.Message); } finally { if (iConn.State != ConnectionState.Closed) { iConn.Close(); } } } return(ds); }
public override int ExcuteSql(string sql, params IDataParameter[] iParams) { int effectRows = 0; using (IDbConnection iConn = this.GetConnection()) { IDbCommand iCmd = null; try { PrepareCommand(out iCmd, iConn, null, sql, iParams); effectRows = iCmd.ExecuteNonQuery(); iCmd.Parameters.Clear(); } catch (Exception ex) { Log4Helper.Error(GetType(), "SqlServer数据库操作异常!", ex); throw new Exception(ex.Message); } finally { iCmd.Dispose(); if (iConn.State != ConnectionState.Closed) { iConn.Close(); } } } return(effectRows); }
public AdminUser GetByAccount(string account) { ConnectionStringSettings settings = ConfigurationManager.ConnectionStrings["connectStr"]; string conStr = SysInfoManage.DENString(settings.ConnectionString); using (ULinker.Common.DB.DBHelper db = new Common.DB.DBHelper(conStr)) { AdminUser item = null; try { string strCmd = @"SELECT * FROM `user` WHERE `Account`=@Account"; MySqlParameter[] paramters = new MySqlParameter[] { new MySqlParameter("@Account", MySqlDbType.String) }; paramters[0].Value = account; DataRow dr = db.GetDataRow(strCmd, paramters); if (dr != null) { item = RowToObject(dr); } } catch (Exception ex) { Log4Helper.Error(this.GetType(), String.Format("AdminUserDao.GetByAccount.{0}", ex.Message), new Exception("error")); } return(item); } }
/// <summary> /// 返回table /// </summary> /// <param name="cmdText"></param> /// <param name="param"></param> /// <returns></returns> public static DataTable Adapter(string cmdText, params OleDbParameter[] param) { DataTable dt = new DataTable(); try { using (OleDbConnection conn = new OleDbConnection(connStr)) { using (OleDbDataAdapter oda = new OleDbDataAdapter()) { using (OleDbCommand command = new OleDbCommand(cmdText, conn)) { oda.SelectCommand = command; if (param != null && param.Length != 0) { oda.SelectCommand.Parameters.AddRange(param); } if (conn.State == ConnectionState.Closed) { conn.Open(); } oda.Fill(dt); } } } } catch (Exception ex) { Log4Helper.Error(new AccessHelper().GetType(), "数据库读取Error.", ex); } return(dt); }
public List <App> GetAll() { ConnectionStringSettings settings = ConfigurationManager.ConnectionStrings["connectStr"]; string conStr = SysInfoManage.DENString(settings.ConnectionString); using (ULinker.Common.DB.DBHelper db = new Common.DB.DBHelper(conStr)) { List <App> _Apps = new List <App>(); try { string strCmd = @" SELECT * FROM `app`"; DataTable dt = db.GetDataSet(strCmd); if (dt != null && dt.Rows.Count > 0) { foreach (DataRow row in dt.Rows) { App item = RowToObject(row); _Apps.Add(item); } } } catch (Exception ex) { Log4Helper.Error(this.GetType(), String.Format("PlatformDao.GetAll.{0}", ex.Message), new Exception("error")); } return(_Apps); } }
/// <summary> /// 返回受影响的行数 /// </summary> /// <param name="comText"></param> /// <param name="param"></param> /// <returns></returns> public static int ExecuteNonQuery(string comText, params OleDbParameter[] param) { try { int val = 0; using (OleDbConnection conn = new OleDbConnection(connStr)) { using (OleDbCommand cmd = new OleDbCommand(comText, conn)) { if (param != null && param.Length != 0) { cmd.Parameters.AddRange(param); } if (conn.State == ConnectionState.Closed) { conn.Open(); } val = cmd.ExecuteNonQuery(); } } return(val); } catch (Exception ex) { Log4Helper.Error(new AccessHelper().GetType(), "数据库操作Error.", ex); throw (ex); } }
public void GetAllCall() { callTable.Clear(); CallList.Clear(); string sql = "select * from CallLogTable where CallType=0 or CallType=2"; callTable = AccessHelper.Adapter(sql, null); for (int i = callTable.Rows.Count - 1; i >= 0; i--) { try { var dm = new DataModel(); dm.SetData(callTable.Rows[i]); if (dm.CallerID == "") { continue; } CallList.Add(dm); } catch (Exception ex) { Log4Helper.Error(this.GetType(), "数据库存在异常数据", ex); continue; } } }
/// <summary> /// 确定 /// </summary> public void Sure() { try { if (!PhoneHelper.ValidateMobile(UserName)) { SendMsg("register", "userNameError"); return; } if (CheckCode == "") { SendMsg("register", "checkCodeError"); return; } if (Password == "") { SendMsg("register", "passWordError"); return; } LoginLogic loginLogic = new LoginLogic(); ResultModel <Token> result = loginLogic.Register(InterfacePath.Default.Register, CheckCode, UserName, NickName, Password, "", ""); SendMsg("register", result.code.ToString()); Log4Helper.Info(this.GetType(), $"手机号:{UserName},注册:{result.msg}"); } catch (Exception ex) { SendMsg("register", "Error"); Log4Helper.Error(this.GetType(), ex); } }
private void ReceiveThread() { try { this.SendEvent(new SocketEvent(SocketEventType.StartEvent, "主机开启!")); IPEndPoint Sender = new IPEndPoint(IPAddress.Any, 0); while (!_Stop) { //Receive处于等待,但不影响发送 byte[] Data = UCR.Receive(ref Sender); this.SendEvent(new SocketEvent(SocketEventType.ReceEvent, Data)); Thread.Sleep(1); } if (UCR != null) { UCR.Close(); UCR = null; } } catch (Exception ex) { Log4Helper.Error(this.GetType(), "监听发生异常!", ex); Stop(); } }
public static int ExecuteNonQuery(string sqrstr, NpgsqlParameter[] cmdParms) { int val = 0; using (NpgsqlConnection SqlConn = new NpgsqlConnection(GetConn())) { try { if (SqlConn.State != ConnectionState.Open) { SqlConn.Open(); } using (NpgsqlCommand SqlCommand = new NpgsqlCommand(sqrstr, SqlConn)) { if (cmdParms != null) { foreach (NpgsqlParameter parm in cmdParms) { SqlCommand.Parameters.Add(parm); } } val = SqlCommand.ExecuteNonQuery(); //执行查询并返回受影响的行数 } } catch (Exception ex) { Log4Helper.Error(new PostgresqlHelper().GetType(), "数据库操作异常!", ex); throw (ex); } } return(val); //r如果是>0操作成功! }
public override bool Send(string cmd, string _remoteHostName, int _sendPort) { bool _sendSuccess = false; if (_remoteHostName.Length > 0) { try { Byte[] sendBytes = Encoding.Default.GetBytes(cmd); UCS.Send(sendBytes, sendBytes.Length, _remoteHostName, _sendPort); this.SendEvent(new SocketEvent(SocketEventType.SendEvent, cmd)); _sendSuccess = true; } catch (Exception ex) { Log4Helper.Error(this.GetType(), "发送UDP异常!", ex); this.SendEvent(new SocketEvent(SocketEventType.Other, "发送失败!")); } } else { this.SendEvent(new SocketEvent(SocketEventType.Other, "远程主机没有定义,发送失败!")); } return(_sendSuccess); }
public bool UpdateToken(string appkey, string token, DateTime tokenExpireTime) { ConnectionStringSettings settings = ConfigurationManager.ConnectionStrings["connectStr"]; string conStr = SysInfoManage.DENString(settings.ConnectionString); using (ULinker.Common.DB.DBHelper db = new Common.DB.DBHelper(conStr)) { try { string strCmd = @"UPDATE `userplatform` SET `Token`=@Token,`TokenExpireTime`=@TokenExpireTime WHERE `AppKey`=@AppKey"; MySqlParameter[] paramters = new MySqlParameter[] { new MySqlParameter("@Token", MySqlDbType.String), new MySqlParameter("@AppKey", MySqlDbType.String), new MySqlParameter("@TokenExpireTime", MySqlDbType.DateTime) }; paramters[0].Value = token; paramters[1].Value = appkey; paramters[2].Value = tokenExpireTime; int count = db.ExecuteNonQuery(strCmd, paramters); return(count > 0 ? true : false); } catch (Exception ex) { Log4Helper.Error(this.GetType(), String.Format("UserPlatformDao.UpdateToken.{0}", ex.Message), new Exception("error")); return(false); } } }
public override void Stop() { try { bool _IsStop = false; _Stop = true; if (HostName.Length > 0) { _IsStop = Send("STOP", HostName, Port); } if ((!_IsStop) || HostName.Length == 0) { if ((ThreadUDP.ThreadState & ThreadState.Running) == ThreadState.Running) { ThreadUDP.Abort(); } if ((ThreadUDP.ThreadState & ThreadState.AbortRequested) == ThreadState.AbortRequested) { GC.Collect(); } if ((ThreadUDP.ThreadState & ThreadState.Aborted) == ThreadState.Aborted || (ThreadUDP.ThreadState & ThreadState.Stopped) == ThreadState.Stopped) { ThreadUDP = null; } } } catch (Exception ex) { Log4Helper.Error(this.GetType(), "主机关闭异常!", ex); this.SendEvent(new SocketEvent(SocketEventType.Other, ex.ToString())); } this.SendEvent(new SocketEvent(SocketEventType.StopEvent, "主机已关闭!")); }
/// <summary> /// 重发 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void BtnRepeat_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) { if (!PhoneHelper.ValidateMobile(PhoneNo.Text)) { MessageBox.Show("手机号格式不正确!"); return; } else { //发短信 LoginLogic logic = new LoginLogic(); ResultModel model = logic.SendMessage(InterfacePath.Default.SendMessage, PhoneNo.Text, CheckCodeTypeEnum.RESET_PASSWORD.ToString()); if (model.code == 200) { secondCount = 59; BtnRepeat.Content = "重发"; this.timer.Start(); } else { string result = ((MessageStateEnum)model.code).ToString(); Log4Helper.Error(this.GetType(), $"手机号:{PhoneNo.Text}发送重置密码短信失败!原因:{result}"); MessageBox.Show(result); } } }
/// <summary> /// 添加条件 /// </summary> private void AddCondition() { try { Dictionary <string, string> dic = new Dictionary <string, string>(); dic.Add("direction", "BUY");//BUY,SELL Dictionary <string, string> header = new Dictionary <string, string>(); header.Add("GeneralParam", JsonHelper.ToJson(SoftwareInformation.Instance())); header.Add("Authorization", "Bearer " + Loginer.LoginerUser.Token); ResultModel result = JsonHelper.JsonToObj <ResultModel>(ApiHelper.SendPost(InterfacePath.Default.maimai, dic, header, "post")); if (result.code == 200) { MessageBox.Show("设置成功!"); } else { MessageBox.Show("设置失败!"); } } catch (Exception ex) { Log4Helper.Error(this.GetType(), "设置条件单:" + ex); } }
private int Count(string name) { ConnectionStringSettings settings = ConfigurationManager.ConnectionStrings["connectStr"]; string conStr = SysInfoManage.DENString(settings.ConnectionString); using (ULinker.Common.DB.DBHelper db = new Common.DB.DBHelper(conStr)) { int total = 0; try { string strCmd = @" SELECT COUNT(1) FROM `platform` WHERE 1=1 "; if (!String.IsNullOrEmpty(name)) { strCmd += @" AND `Name` LIKE '%" + name + "%'"; } DataRow row = db.GetDataRow(strCmd); if (row != null) { total = int.Parse(row["COUNT(1)"].ToString()); } } catch (Exception ex) { Log4Helper.Error(this.GetType(), String.Format("PlatformDao.Count.{0}", ex.Message), ex); } return(total); } }
public bool Create(Platform model) { ConnectionStringSettings settings = ConfigurationManager.ConnectionStrings["connectStr"]; string conStr = SysInfoManage.DENString(settings.ConnectionString); using (ULinker.Common.DB.DBHelper db = new Common.DB.DBHelper(conStr)) { try { string strCmd = @"INSERT INTO `platform` (`Name`,`Description`,`CreateTime`,`ModifyTime`) VALUES(@Name,@Description,NOW(),NOW())"; MySqlParameter[] paramters = new MySqlParameter[] { new MySqlParameter("@Name", MySqlDbType.String), new MySqlParameter("@Description", MySqlDbType.String) }; paramters[0].Value = model.Id; paramters[1].Value = model.Description; int count = db.ExecuteNonQuery(strCmd, paramters); return(count > 0 ? true : false); } catch (Exception ex) { Log4Helper.Error(this.GetType(), String.Format("AppTypeDao.Create.{0}", ex.Message), new Exception("error")); return(false); } } }
public void Sure() { try { if (!PhoneHelper.ValidateMobile(UserName)) { SendMsg("resetPassWord", "userNameError"); return; } if (CheckCode == "") { SendMsg("resetPassWord", "checkCodeError"); return; } if (Password == "") { SendMsg("resetPassWord", "passWordError"); return; } var result = new LoginLogic().ResetPassWord(InterfacePath.Default.ResetPassWord, CheckCode, UserName, Password); SendMsg("resetPassWord", result.code.ToString()); Log4Helper.Info(this.GetType(), $"手机号:{UserName},找回密码:{result.msg}"); } catch (Exception ex) { SendMsg("resetPassWord", "Error"); Log4Helper.Error(this.GetType(), ex); } }
/// <summary> /// 删除文件夹以及文件夹下所有文件 /// </summary> /// <param name="directory">文件夹路径</param> public static void DeleteDirectory(string directory) { try { if (Directory.Exists(directory)) { DirectoryInfo dir = new DirectoryInfo(directory); FileSystemInfo[] fileinfo = dir.GetFileSystemInfos(); //返回目录中所有文件和子目录 foreach (FileSystemInfo i in fileinfo) { if (i is DirectoryInfo) //判断是否文件夹 { DirectoryInfo subdir = new DirectoryInfo(i.FullName); subdir.Delete(true); //删除子目录和文件 } else { File.Delete(i.FullName); //删除指定文件 } } } } catch (IOException ex) { Log4Helper.Error(typeof(FileHelper), ex.Message, ex); } }