/// <summary> /// 检查加密狗 /// </summary> /// <returns></returns> public static bool Check() { bool result = true; SoftDogReader reader = new SoftDogReader(); SoftDogInfo info = null; try { info = reader.ReadDog(); if (info == null) { MessageBox.Show(Resource1.FrmMain_SoftDogError, Resource1.Form_Alert); result = false; } else if ((info.SoftwareList & SoftwareType.TYPE_PARK) == 0) //没有写停车场权限 { MessageBox.Show(Resource1.FrmMain_SoftDogNoRights, Resource1.Form_Alert); result = false; } else if (info.ExpiredDate.AddDays(15) < DateTime.Today) { MessageBox.Show(Resource1.FrmMain_SoftDogExpired, Resource1.Form_Alert); result = false; } } catch (InvalidOperationException ex) { Ralid.GeneralLibrary.ExceptionHandling.ExceptionPolicy.HandleException(ex); result = false; } return(result); }
private void WriteLIC(SoftDogInfo dog, string licFile) { StringBuilder sb = new StringBuilder(); sb.Append(string.Format("ProjectNo:{0};", dog.ProjectNo)); if (!string.IsNullOrEmpty(dog.ProjectName)) { var pn = Convert.ToBase64String(System.Text.ASCIIEncoding.Default.GetBytes(dog.ProjectName)); sb.Append(string.Format("ProjectName:{0};", pn)); } sb.Append(string.Format("SoftwareList:{0};", (int)dog.SoftwareList)); sb.Append(string.Format("StartDate:{0};", dog.StartDate.ToString("yyyy-MM-dd"))); sb.Append(string.Format("ExpiredDate:{0};", dog.ExpiredDate.ToString("yyyy-MM-dd"))); sb.Append(string.Format("IsHost:{0};", dog.IsHost.ToString())); sb.Append(string.Format("DBName:{0};", dog.DBName)); sb.Append(string.Format("DBUser:{0};", dog.DBUser)); if (!string.IsNullOrEmpty(dog.DBServer)) { sb.Append(string.Format("DBServer:{0};", dog.DBServer)); } sb.Append(string.Format("DBPassword:{0};", dog.DBPassword)); sb.Append(string.Format("MAC:{0};", dog.MAC)); sb.Append(string.Format("WebAPIUrl:{0};", dog.WebAPIUrl.Replace(":", "___"))); using (FileStream fs = new FileStream(licFile, FileMode.Create, FileAccess.ReadWrite)) { var data = System.Text.ASCIIEncoding.ASCII.GetBytes(new DTEncrypt().Encrypt(sb.ToString())); fs.Write(data, 0, data.Length); fs.Flush(); } }
private void btnReadLic_Click(object sender, EventArgs e) { OpenFileDialog dig = new OpenFileDialog(); if (dig.ShowDialog() == DialogResult.OK) { SoftDogInfo dog = LICReader.ReadDog(dig.FileName); if (dog != null) { ShowDog(dog); MessageBox.Show("读LIC成功"); } } }
private void btnRead_Click(object sender, EventArgs e) { try { SoftDogInfo info = _Writer.ReadDog(); if (info != null) { ShowDog(info); MessageBox.Show("读狗成功"); } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void ShowDog(SoftDogInfo info) { txtProjectID.IntergerValue = info.ProjectNo; txtProjectName.Text = info.ProjectName; chkInventory.Checked = (info.SoftwareList & SoftwareType.TYPE_Inventory) == SoftwareType.TYPE_Inventory; chkACS.Checked = (info.SoftwareList & SoftwareType.TYPE_ACS) == SoftwareType.TYPE_ACS; chkTA.Checked = (info.SoftwareList & SoftwareType.TYPE_TA) == SoftwareType.TYPE_TA; chkPark.Checked = (info.SoftwareList & SoftwareType.TYPE_PARK) == SoftwareType.TYPE_PARK; chkTYPE_SteelRollInventory_COST.Checked = ((info.SoftwareList & SoftwareType.TYPE_SteelRollInventory_COST) == SoftwareType.TYPE_SteelRollInventory_COST); dtStart.Value = info.StartDate; dtEnd.Value = info.ExpiredDate; chkHost.Checked = info.IsHost; txtDBName.Text = info.DBName; txtDBServer.Text = info.DBServer; txtUser.Text = info.DBUser; txtPassword.Text = info.DBPassword; txtMAC.Text = info.MAC; txtWebAPIUrl.Text = info.WebAPIUrl; }
private void btnRead_Click(object sender, EventArgs e) { try { SoftDogInfo info = _Writer.ReadDog(); txtProjectID.IntergerValue = info.ProjectNo; this.chk学生体测.Checked = (info.SoftwareList & SoftwareType.TYPE_汇海学生体测软件) == SoftwareType.TYPE_汇海学生体测软件; this.chk汇海中考软件.Checked = (info.SoftwareList & SoftwareType.TYPE_汇海中考软件) == SoftwareType.TYPE_汇海中考软件; this.chk国民体测.Checked = (info.SoftwareList & SoftwareType.TYPE_汇海国民体测软件) == SoftwareType.TYPE_汇海国民体测软件; this.chk运动会.Checked = (info.SoftwareList & SoftwareType.TYPE_汇海运动会软件) == SoftwareType.TYPE_汇海运动会软件; dtStart.Value = info.StartDate; dtEnd.Value = info.ExpiredDate; MessageBox.Show("读狗成功"); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private bool _HasGenerateResult = false; //是否已经自动生成了考勤结果,用于自动生成考勤结果 #endregion #region 私有方法 private void ReadSoftDog() { SoftDogReader reader = new SoftDogReader(); SoftDogInfo info = null; bool ret = true; try { info = reader.ReadDog(); if (info == null) { MessageBox.Show(LJH.Attendance.UI.Properties.Resources.FrmMain_SoftDogError, LJH.Attendance.UI.Properties.Resources.Form_Alert); ret = false; } else if ((info.SoftwareList & SoftwareType.TYPE_TA) == 0) //没有写考勤软件权限 { MessageBox.Show(LJH.Attendance.UI.Properties.Resources.FrmMain_SoftDogNoRights, LJH.Attendance.UI.Properties.Resources.Form_Alert); ret = false; } else if (info.ExpiredDate < DateTime.Today && info.ExpiredDate.AddDays(15) >= DateTime.Today) //已经过期 { DateTime expire = info.ExpiredDate.AddDays(15); TimeSpan ts = new TimeSpan(expire.Ticks - DateTime.Today.Ticks); MessageBox.Show(string.Format(LJH.Attendance.UI.Properties.Resources.FrmMain_SoftDogExpiredAlert, (int)(ts.TotalDays + 1)), LJH.Attendance.UI.Properties.Resources.Form_Alert); } else if (info.ExpiredDate.AddDays(15) < DateTime.Today) { MessageBox.Show(LJH.Attendance.UI.Properties.Resources.FrmMain_SoftDogExpired, LJH.Attendance.UI.Properties.Resources.Form_Alert); ret = false; } } catch (InvalidOperationException ex) { MessageBox.Show(ex.Message); ret = false; } if (!ret) { System.Environment.Exit(0); } }
private SoftDogInfo GetDogInfoFromInput() { SoftDogInfo dog = new SoftDogInfo(); dog.ProjectNo = txtProjectID.IntergerValue; dog.ProjectName = txtProjectName.Text.Trim(); dog.SoftwareList = SoftwareType.None; if (chkACS.Checked) { dog.SoftwareList |= SoftwareType.TYPE_ACS; } if (chkInventory.Checked) { dog.SoftwareList |= SoftwareType.TYPE_Inventory; } if (chkTA.Checked) { dog.SoftwareList |= SoftwareType.TYPE_TA; } if (chkPark.Checked) { dog.SoftwareList |= SoftwareType.TYPE_PARK; } if (chkTYPE_SteelRollInventory_COST.Checked) { dog.SoftwareList |= SoftwareType.TYPE_SteelRollInventory_COST; } dog.StartDate = dtStart.Value.Date; dog.ExpiredDate = dtEnd.Value.Date; dog.IsHost = chkHost.Checked; dog.DBServer = txtDBServer.Text.Trim(); dog.DBName = txtDBName.Text.Trim(); dog.DBUser = txtUser.Text.Trim(); dog.DBPassword = txtPassword.Text.Trim(); dog.MAC = txtMAC.Text.Trim(); if (!string.IsNullOrEmpty(dog.MAC)) { dog.MAC = dog.MAC.ToUpper(); } dog.WebAPIUrl = txtWebAPIUrl.Text.Trim(); return(dog); }
private void ReadSoftDog() { string skey = AppSettings.Current.GetConfigContent("SKey"); if (string.IsNullOrEmpty(skey)) { skey = @"#i~xnUc4RH1G@\)$&7z6qv9xy@~<mTR5nUR?OU}jh`4r<qN>:*xZwz~E$0"; AppSettings.Current.SaveConfig("SKey", skey); } SoftDogReader reader = new SoftDogReader(skey); try { _SoftDog = reader.ReadDog(); if (_SoftDog == null) { MessageBox.Show("加密狗访问错误:没有找到加密狗。如果加密狗已经插上,则可能是加密狗还没有加密,请先联系厂家进行加密!", "注意"); System.Environment.Exit(0); } else if ((_SoftDog.SoftwareList & SoftwareType.TYPE_Inventory) == 0) //没有写停车场权限 { MessageBox.Show("加密狗权限不足:原因可能是加密狗中没有开放进销存软件权限,请联系厂家开放相应的权限!", "注意"); System.Environment.Exit(0); } else if (_SoftDog.ExpiredDate < DateTime.Today && _SoftDog.ExpiredDate.AddDays(15) >= DateTime.Today) //已经过期 { DateTime expire = _SoftDog.ExpiredDate.AddDays(15); TimeSpan ts = new TimeSpan(expire.Ticks - DateTime.Today.Ticks); MessageBox.Show(string.Format("软件已经过期,还可以再试用 {0} 天,请尽快与供应商联系延长您的软件使用期!", (int)(ts.TotalDays + 1)), "注意"); } else if (_SoftDog.ExpiredDate.AddDays(15) < DateTime.Today) { MessageBox.Show("软件已经过期,请联系厂家延长期限!", "注意"); System.Environment.Exit(0); } } catch (InvalidOperationException ex) { MessageBox.Show(ex.Message); System.Environment.Exit(0); } }
/// <summary> /// 检查停车场加密狗权限 /// </summary> /// <returns></returns> public static bool VerifyRight() { SoftDogReader reader = new SoftDogReader(); SoftDogInfo info = null; try { info = reader.ReadDog(); if (info == null) { MessageBox.Show(Resource1.FrmMain_SoftDogError, Resource1.Form_Alert); return(false); } else if ((info.SoftwareList & SoftwareType.TYPE_PARK) == 0) //没有写停车场权限 { MessageBox.Show(Resource1.FrmMain_SoftDogNoRights, Resource1.Form_Alert); return(false); } else if (info.ExpiredDate < DateTime.Today && info.ExpiredDate.AddDays(15) >= DateTime.Today) //已经过期 { DateTime expire = info.ExpiredDate.AddDays(15); TimeSpan ts = new TimeSpan(expire.Ticks - DateTime.Today.Ticks); MessageBox.Show(string.Format(Resource1.FrmMain_SoftDogExpiredAlert, (int)(ts.TotalDays + 1)), Resource1.Form_Alert); } else if (info.ExpiredDate.AddDays(15) < DateTime.Today) { MessageBox.Show(Resource1.FrmMain_SoftDogExpired, Resource1.Form_Alert); return(false); } } catch (InvalidOperationException ex) { MessageBox.Show(ex.Message); return(false); } return(true); }
private void WriteDog(SoftDogInfo dog) { int ret = -1; byte[] rdDate = new byte[100]; _myRandom.NextBytes(rdDate); ret = DogWrite_32(rdDate.Length, 0, rdDate); byte[] data = null; if (ret == 0) { data = System.Text.ASCIIEncoding.GetEncoding("GB2312").GetBytes(MydsEncrypt.Encrypt(CHECKSTRING)); ret = DogWrite_32(data.Length, CHECKPOSITON, data); } if (ret == 0) { data = SEBinaryConverter.IntToBytes(dog.ProjectNo); ret = DogWrite_32(data.Length, 61, data); } if (ret == 0) { data = SEBinaryConverter.IntToBytes((int)dog.SoftwareList); ret = DogWrite_32(data.Length, 31, data); } if (ret == 0) { data = System.Text.ASCIIEncoding.GetEncoding("GB2312").GetBytes(MydsEncrypt.Encrypt(dog.StartDate.ToString("yyMMdd"))); ret = DogWrite_32(data.Length, 17, data); } if (ret == 0) { data = System.Text.ASCIIEncoding.GetEncoding("GB2312").GetBytes(MydsEncrypt.Encrypt(dog.ExpiredDate.ToString("yyMMdd"))); ret = DogWrite_32(data.Length, 5, data); } if (ret == 0) { ret = DogWrite_32(1, 37, new byte[] { (byte)(dog.IsHost ? 1 : 0) }); } if (ret == 0 && !string.IsNullOrEmpty(txtUser.Text.Trim())) { data = System.Text.ASCIIEncoding.GetEncoding("GB2312").GetBytes(MydsEncrypt.Encrypt(dog.DBUser)); byte[] temp = new byte[10]; for (int i = 0; i < temp.Length; i++) { if (i < data.Length) { temp[i] = data[i]; } else { temp[i] = 0x20; } } ret = DogWrite_32(temp.Length, 40, temp); } if (ret == 0 && !string.IsNullOrEmpty(txtPassword.Text.Trim())) { data = System.Text.ASCIIEncoding.GetEncoding("GB2312").GetBytes(MydsEncrypt.Encrypt(dog.DBPassword)); byte[] temp = new byte[10]; for (int i = 0; i < temp.Length; i++) { if (i < data.Length) { temp[i] = data[i]; } else { temp[i] = 0x20; } } ret = DogWrite_32(temp.Length, 50, temp); } if (ret != 0) { throw new InvalidOperationException("写狗失败 errorcode=" + ret.ToString()); } }
private void button1_Click(object sender, EventArgs e) { SoftDogReader reader = new SoftDogReader(); SoftDogInfo dog = reader.ReadDog(); }