private void button3_Click(object sender, EventArgs e) { try { string dat = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); string PW = PermitHelper.EncrypOrDecryp(dat, dat, true); StringBuilder sb = new StringBuilder(4096); #region 其他加密,暂时没用 //sb.Append("IF OBJECT_ID('PivasDesPassWord') IS NULL "); //sb.Append(" begin "); //sb.Append(" Create table [PivasDesPassWord](ID INT identity(1,1) PRIMARY key,MacSSID VARCHAR(250),PivasWord text,Dat datetime) "); //sb.Append(" end "); //sb.Append(" else "); //sb.Append(" begin "); //sb.Append(string.Format(" UPDATE [PivasDesPassWord] SET [MacSSID] = '{0}' WHERE ID=(SELECT MAX(ID) FROM [PivasDesPassWord]) ", HDssid)); //sb.Append(" end "); #endregion sb.Append("IF OBJECT_ID('PivasDesSoftTAB') IS NULL "); sb.Append(" begin "); sb.Append(" Create table [PivasDesSoftTAB](ID INT identity(1,1) PRIMARY key,SoftPW VARCHAR(512),Dat datetime) "); sb.Append(string.Format(" insert into [PivasDesSoftTAB] values('{0}','{1}') ", PW, dat)); sb.Append(" end "); sb.Append(" else "); sb.Append(" begin "); sb.Append(" truncate table [PivasDesSoftTAB] "); sb.Append(string.Format(" insert into [PivasDesSoftTAB] values('{0}','{1}') ", PW, dat)); sb.Append(" end "); dbHelp.SetPIVAsDB(sb.ToString()); } catch (Exception ex) { ShowMsgHelper.ShowError("设置同步程序最新出错" + ex.Message); } }
/// <summary> /// 更新PivasDesPassWord表ID最大的记录synMac为本次运行的硬盘序列号加密后的值 /// 插入PivasDesSoftTAB表一条记录,记录时间加密后的值 /// </summary> private void RunDesTab() { try { string dat = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); string PW = PermitHelper.EncrypOrDecryp(dat, dat, true); StringBuilder sb = new StringBuilder(4096); sb.Append("IF OBJECT_ID('PivasDesPassWord') IS NULL "); sb.Append(" begin "); sb.Append(" Create table [PivasDesPassWord](ID INT identity(1,1) PRIMARY key,MacSSID VARCHAR(250),PivasWord text,Dat datetime) "); sb.Append(" end "); sb.Append(" else "); sb.Append(" begin "); sb.Append(string.Format(" UPDATE [PivasDesPassWord] SET [MacSSID] = '{0}' WHERE ID=(SELECT MAX(ID) FROM [PivasDesPassWord]) ", HDssid)); sb.Append(" end "); sb.Append("IF OBJECT_ID('PivasDesSoftTAB') IS NULL "); sb.Append(" begin "); sb.Append(" Create table [PivasDesSoftTAB](ID INT identity(1,1) PRIMARY key,SoftPW VARCHAR(512),Dat datetime) "); sb.Append(string.Format(" insert into [PivasDesSoftTAB] values('{0}','{1}') ", PW, dat)); sb.Append(" end "); sb.Append(" else "); sb.Append(" begin "); sb.Append(" truncate table [PivasDesSoftTAB] "); sb.Append(string.Format(" insert into [PivasDesSoftTAB] values('{0}','{1}') ", PW, dat)); sb.Append(" end "); dbHelp.SetPIVAsDB(sb.ToString()); } catch (Exception ex) { InternalLogger.Log.Error("更新加密信息出错" + ex.Message); } }
/// <summary> /// 判断同步程序是不是最新的 /// </summary> /// <returns></returns> private bool SynToolIsLatest() { try { StringBuilder sb = new StringBuilder(4096); sb.AppendLine(" if not exists (SELECT 1 FROM sys.all_objects where type='U' AND name='PivasDesPassWord') begin Create table [PivasDesPassWord](ID INT identity(1,1) PRIMARY key,MacSSID VARCHAR(250),PivasWord text,Dat datetime) end"); sb.AppendLine(" if not exists (SELECT 1 FROM sys.all_objects where type='U' AND name='PivasDesSoftTAB') "); sb.AppendLine(" begin "); sb.AppendLine(" Create table [PivasDesSoftTAB](ID INT identity(1,1) PRIMARY key,SoftPW VARCHAR(512),Dat datetime) "); sb.AppendLine(" insert into [PivasDesSoftTAB] values('',getdate()) "); sb.AppendLine(" end "); sb.AppendLine(" SELECT SoftPW,Dat,Getdate() gs FROM [PivasDesSoftTAB] "); DataSet ds = dbHelp.GetPIVAsDB(sb.ToString()); if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0) { if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0][0].ToString().Trim()) && !string.IsNullOrEmpty(ds.Tables[0].Rows[0][1].ToString().Trim())) { DateTime val1 = DateTime.Now.AddDays(-1); DateTime.TryParse(ds.Tables[0].Rows[0][1].ToString().Trim(), out val1); string dat = PermitHelper.EncrypOrDecryp(ds.Tables[0].Rows[0][0].ToString().Trim(), val1.ToString("yyyy-MM-dd HH:mm:ss"), false); DateTime dt = DateTime.Now.AddDays(-1); bool isok = DateTime.TryParse(dat, out dt); DateTime.TryParse(ds.Tables[0].Rows[0][2].ToString().Trim(), out val1); if (isok && val1 < dt.AddHours(1)) { return(true); } else { MessageBox.Show("同步程序不是最新的!!!请更新同步程序"); } } else { MessageBox.Show("请运行最新的同步程序!!!"); } } } catch (Exception ex) { MessageBox.Show(ex.Message); } return(false); }
/// <summary> /// 获取权限 /// </summary> /// <param name="Pro"></param> /// <returns></returns> private bool GetLimt(string Pro) { bool ret = false; try { DataSet ds = dbHelp.GetPIVAsDB( "select [MacSSID],[PivasWord] from [PivasDesPassWord] where ID=(select max(ID) from [PivasDesPassWord])"); if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0) { using (DataSet dt = new DataSet()) { string val = PermitHelper.EncrypOrDecryp(ds.Tables[0].Rows[0][1].ToString().Trim(), ds.Tables[0].Rows[0][0].ToString().Trim(), false); if (!string.IsNullOrEmpty(val)) { using (StringReader sr = new StringReader(val)) dt.ReadXml(sr, XmlReadMode.Auto); if (dt != null && dt.Tables.Count > 0 && dt.Tables[0].Rows.Count > 0) { if (dt.Tables[0].Columns.Contains(Pro)) { bool.TryParse(dt.Tables[0].Rows[0][Pro].ToString(), out ret); } } } } } } catch (Exception ex) { MessageBox.Show(ex.Message); } return(ret); }
public PermitHelperTests() { _helper = new PermitHelper(_mockVerintServiceGateway.Object, _mockConfiguration.Object); }