public static bool WriteToLock(int p1Val, int p2Val) { int service, seed, lptnum, passw1, passw2, p1, p2, p3, p4; service = 0; seed = 0; lptnum = 0; //passw1 = Pass1; //passw2 = Pass2; passw1 = 4651; passw2 = 9261; p1 = p1Val; p2 = p2Val; p3 = 0; p4 = 0; bool bSuccess = true; HaspKey.Hasp(HaspService.WriteWord, seed, lptnum, passw1, passw2, p1, p2, p3, p4); if (p3 != 0) { bSuccess = false; //MessageBox.Show(this, "Error.", "TechSOFT", MessageBoxButtons.OK, MessageBoxIcon.Error); } return(bSuccess); }
private HaspKey CreateNew(int id) { HaspKey haspKey = CreateNew(); haspKey.Id = id; return(haspKey); }
public bool Update(HaspKey entity) { if (entity == null) { throw new ArgumentNullException(nameof(entity)); } var haspKey = GetById(entity.Id); if (haspKey == null) { return(false); } haspKey.InnerId = entity.InnerId; haspKey.Number = entity.Number; haspKey.TypeKey = entity.TypeKey; haspKey.IsHome = entity.IsHome; try { db.SaveChanges(); } catch (DbUpdateException) { return(false); } catch { throw; } return(true); }
public bool UnCheck(byte[] Param2) { int iFirst = 0; int iSecond = 0; int iThird = 0; bool bEnc = false; try { iSecond = Param2.Length; object objSecConv = (object)iSecond; object objThirdConv = (object)iThird; HaspKey.Hasp(HaspService.DecodeData, m_iSC, m_iPt, m_iAuth1, m_iAuth2, null, objSecConv, objThirdConv, Param2); iThird = (int)objThirdConv; if (iThird == 0) { bEnc = true; } else { bEnc = false; } return(bEnc); } catch (Exception ex) { return(bEnc); } }
private HaspKey CreateNew(int id, int innerId) { HaspKey haspKey = CreateNew(id); haspKey.InnerId = innerId; return(haspKey); }
private bool NewTest() { int iRlt = 0; int iSts = 0; bool bRetRes = false; try { object oConvRlt = (object)iRlt; object oConvSts = (object)iSts; HaspKey.Hasp(HaspService.IsHasp4, m_iSC, m_iPt, m_iAuth1, m_iAuth2, oConvRlt, null, oConvSts, null); iRlt = (int)oConvRlt; if (iRlt == 1) { bRetRes = true; } else if (iRlt != 1) { bRetRes = false; } return(bRetRes); } catch (Exception ex) { return(bRetRes); } }
public ModelViewHaspKey(HaspKey haspKey) : this() { Id = haspKey.Id; InnerId = haspKey.InnerId; Number = haspKey.Number; IsHome = haspKey.IsHome; TypeKey = haspKey.TypeKey; }
/// <summary> /// Проверка на дубли. /// </summary> /// <param name="entity">HASP-ключ</param> /// <returns>Результат проверки.</returns> public bool ContainsDB(HaspKey entity) { var key = db.HaspKeys .SingleOrDefault(hk => hk.InnerId == entity.InnerId && hk.Number == entity.Number && hk.TypeKey == entity.TypeKey && hk.IsHome == entity.IsHome); return(key != null); }
public bool Update(HaspKey entity) { if (entity == null) { throw new ArgumentNullException(nameof(entity)); } CheckArgument(entity); return(!haspKeyDAO.ContainsDB(entity) ? haspKeyDAO.Update(entity) : false); }
public void SaveDuplicateHaspKey() { bool add; HaspKey haspKey = CreateNew(); using (var db = new EntitesContext()) { ClearTable.HaspKeys(db); haspKeyL = Get(db); haspKeyL.Save(haspKey); add = haspKeyL.Save(haspKey); } Assert.IsFalse(add); }
public void GetByIdHaspKey() { HaspKey getById; HaspKey keyExpected = CreateNew(1); using (var db = new EntitesContext()) { ClearTable.HaspKeys(db); haspKeyDAO = new DbHaspKeyDAO(db); haspKeyDAO.Add(CreateNew()); getById = haspKeyDAO.GetById(1); } Assert.AreEqual(getById, keyExpected); }
private void CheckArgument(HaspKey haspKey) { if (haspKey.InnerId < 0) { throw new ArgumentException(nameof(haspKey.InnerId)); } if (string.IsNullOrWhiteSpace(haspKey.Number)) { throw new ArgumentException(nameof(haspKey.Number)); } if (!Enum.IsDefined(typeof(TypeKey), haspKey.TypeKey)) { throw new ArgumentException(nameof(haspKey.TypeKey)); } }
public static bool CheckHasp() { //int Service = 0; int LptNum = 0, SeedCode = 0; //int Pass1, Pass2; //int p1, p2, p3, p4; //int lock_flag; //long IDNum; int ps1, ps2, p1, p2, p3, p4; ps1 = 4561; ps2 = 9261; p1 = p2 = p3 = p4 = 0; bool findHasp = false; int result = 0; int status = 0; object param1 = (object)result; object param3 = (object)status; HaspKey.Hasp(HaspService.IsHasp, SeedCode, LptNum, 0, 0, param1, null, param3, null); result = (int)param1; status = (int)param3; //if (0 == status) // findHasp = true; if (result == 1) { findHasp = true; } return(findHasp); }
private bool GetAndCheck() { bool bCheckID = false; int idLw = 0; int idHgh = 0; int iSts = 0; try { object oConvidLw = (object)idLw; object oConvidHigh = (object)idHgh; object oConvSts = (object)iSts; HaspKey.Hasp(HaspService.HaspID, m_iSC, m_iPt, m_iAuth1, m_iAuth2, oConvidLw, oConvidHigh, oConvSts, null); idLw = (int)oConvidLw; idHgh = (int)oConvidHigh; int iNewOne = idHgh + idLw; if (iNewOne == 22545) { bCheckID = true; } else { bCheckID = false; } return(bCheckID); } catch (Exception ex) { return(bCheckID); } }
public void UpdateNoDBHaspKey() { var keyNoDB = new HaspKey { Id = 234, InnerId = 1546, Number = "uz-265", IsHome = false, TypeKey = TypeKey.NetTime, }; using (var db = new EntitesContext()) { ClearTable.HaspKeys(db); haspKeyDAO = new DbHaspKeyDAO(db); haspKeyDAO.Add(CreateNew()); Assert.IsFalse(haspKeyDAO.Update(keyNoDB)); } }
public bool Save(HaspKey entity) { if (entity == null) { throw new ArgumentNullException(nameof(entity)); } CheckArgument(entity); int id; if (!haspKeyDAO.ContainsDB(entity)) { id = haspKeyDAO.Add(entity); } else { return(false); } return(id > 0); }
public void ErroneousArgumentSaveHaspKey() { HaspKey haspKey = CreateNew(); using (var db = new EntitesContext()) { ClearTable.HaspKeys(db); haspKeyL = Get(db); haspKey.InnerId = -1456; Assert.ThrowsException <ArgumentException>(() => haspKeyL.Save(haspKey)); haspKey.InnerId = 234; haspKey.Number = null; Assert.ThrowsException <ArgumentException>(() => haspKeyL.Save(haspKey)); haspKey.Number = string.Empty; Assert.ThrowsException <ArgumentException>(() => haspKeyL.Save(haspKey)); haspKey.Number = "____"; haspKey.TypeKey = (TypeKey)12; Assert.ThrowsException <ArgumentException>(() => haspKeyL.Save(haspKey)); } }
public int Add(HaspKey entity) { if (entity == null) { throw new ArgumentNullException(nameof(entity)); } var haspKey = db.HaspKeys.Add(entity); try { db.SaveChanges(); } catch (DbUpdateException) { return(-1); } catch { throw; } return(haspKey.Id); }
public static bool Check_ASTRA_Structure_Lock_18() { short lock_flag = 0; LptNum = 0; /**/ // Memo Lock Pass1 = 4651; Pass2 = 9261; LptNum = 0; // Below is to READ Memo Lock For Release 12/14 Service = 3; SeedCode = 0; p1 = 27; // new address for Structural Analysis //p2 == 1 //Structure Analysis int address = p1; int data = 0; int status = 0; object param1 = (object)address; object param2 = (object)data; object param3 = (object)status; HaspKey.Hasp(HaspService.ReadWord, SeedCode, LptNum, Pass1, Pass2, param1, param2, param3, null); status = (int)param3; p2 = (int)param2; if (p2 == 1 || p2 == 2) { lock_flag = 1; } else { lock_flag = 0; return(false); //MessageBox.Show(this, "Lock not found at any port for ASTRA Release 6.0...!!!", "ASTRA"); //Application.Exit(); } //if (Version_Type == eVersionType.High_Value_Version) //{ // if (!Is_High_Value_18()) return false; //} //if (Version_Type == eVersionType.Low_Value_Version) //{ // if (Is_High_Value_18()) return true; //} return(true); } public static bool Check_ASTRA_Bridge_Lock_18() { short lock_flag = 0; LptNum = 0; /**/ // Memo Lock Pass1 = 4651; Pass2 = 9261; LptNum = 0; // Below is to READ Memo Lock For Release 12/14 Service = 3; SeedCode = 0; p1 = 27; // new address for Structural Analysis //p2 == 1 //Structure Analysis int address = p1; int data = 0; int status = 0; object param1 = (object)address; object param2 = (object)data; object param3 = (object)status; HaspKey.Hasp(HaspService.ReadWord, SeedCode, LptNum, Pass1, Pass2, param1, param2, param3, null); status = (int)param3; p2 = (int)param2; if (p2 == 0 || p2 == 2 || p2 == 65535) //for Bridge { lock_flag = 1; } else { lock_flag = 0; return(false); //MessageBox.Show(this, "Lock not found at any port for ASTRA Release 6.0...!!!", "ASTRA"); //Application.Exit(); } return(true); }
public static bool Check_ASTRA_Lock_18() { if (!CheckHasp()) { return(false); } if (!IsActivate_18 && Get_Activation() <= 0) { return(false); } //else if (Version_Type == eVersionType.High_Value_Version) //{ // if (!Is_High_Value()) return false; //} short lock_flag = 0; LptNum = 0; /**/ // Memo Lock Pass1 = 4651; Pass2 = 9261; LptNum = 0; // Below is to READ Memo Lock For Release 12/14 Service = 3; SeedCode = 0; p1 = 18; //for heads //p2 == 23 int address = p1; int data = 0; int status = 0; object param1 = (object)address; object param2 = (object)data; object param3 = (object)status; HaspKey.Hasp(HaspService.ReadWord, SeedCode, LptNum, Pass1, Pass2, param1, param2, param3, null); status = (int)param3; p2 = (int)param2; if (p2 == 23) { lock_flag = 1; } else { lock_flag = 0; return(false); } Service = 3; SeedCode = 0; p1 = 24; //for heads //p2 == 86 param1 = (object)p1; param2 = (object)data; param3 = (object)status; HaspKey.Hasp(HaspService.ReadWord, SeedCode, LptNum, Pass1, Pass2, param1, param2, param3, null); status = (int)param3; p2 = (int)param2; if (p2 == 86) { lock_flag = 1; } else { lock_flag = 0; return(false); } //if (Version_Type == eVersionType.High_Value_Version) //{ // if (!Is_High_Value_18()) return false; //} //if (Version_Type == eVersionType.Low_Value_Version) //{ // if (Is_High_Value_18()) return true; //} return(true); } public static void MemoLock_18() { short lock_flag = 0; LptNum = 0; /**/ // Memo Lock Pass1 = 4651; Pass2 = 9261; LptNum = 0; // Below is to READ Memo Lock For Release 12/14 Service = 3; SeedCode = 0; p1 = 18; //for heads //p2 == 23 int address = p1; int data = 0; int status = 0; object param1 = (object)address; object param2 = (object)data; object param3 = (object)status; HaspKey.Hasp(HaspService.ReadWord, SeedCode, LptNum, Pass1, Pass2, param1, param2, param3, null); status = (int)param3; p2 = (int)param2; if (p2 == 23) { lock_flag = 1; } else { lock_flag = 0; //MessageBox.Show(this, "Lock not found at any port for ASTRA Release 6.0...!!!", "ASTRA"); //Application.Exit(); } Service = 3; SeedCode = 0; p1 = 24; //for heads //p2 == 86 param1 = (object)p1; param2 = (object)data; param3 = (object)status; HaspKey.Hasp(HaspService.ReadWord, SeedCode, LptNum, Pass1, Pass2, param1, param2, param3, null); status = (int)param3; p2 = (int)param2; if (p2 == 86) { lock_flag = 1; } else { lock_flag = 0; } }
public static bool Get_Authorization_Code_18() { short lock_flag = 0; LptNum = 0; /**/ // Memo Lock Pass1 = 4651; Pass2 = 9261; LptNum = 0; // Below is to READ Memo Lock For Release 12/14 Service = 3; SeedCode = 0; p1 = 10; //for heads //p2 == 1 // If Authorizasion Code entered //p2 == 0 // If Authorizasion Code not entered int address = p1; int data = 0; int status = 0; object param1 = (object)address; object param2 = (object)data; object param3 = (object)status; HaspKey.Hasp(HaspService.ReadWord, SeedCode, LptNum, Pass1, Pass2, param1, param2, param3, null); status = (int)param3; p2 = (int)param2; //p2 == 1 // If Authorizasion Code entered //p2 == 0 // If Authorizasion Code not entered if (p2 == 1) { lock_flag = 1; } else { lock_flag = 0; } return(lock_flag == 1); } public static bool IsActivate_18 { get { return(Get_Authorization_Code_18()); } } public static bool Is_High_Value_18() { LptNum = 0; /**/ // Memo Lock Pass1 = 4651; Pass2 = 9261; LptNum = 0; //Below is to READ Memo Lock For Release 12/14 Service = 3; SeedCode = 0; //p1=17 //for heads p1 = 25; //p2 == 1 int address = p1; int data = 0; int status = 0; object param1 = (object)address; object param2 = (object)data; object param3 = (object)status; HaspKey.Hasp(HaspService.ReadWord, SeedCode, LptNum, Pass1, Pass2, param1, param2, param3, null); status = (int)param3; p2 = (int)param2; return(p2 == 1); }
public static bool Check_ASTRA_Lock_19() { if (!CheckHasp()) { return(false); } if (!IsActivate_19 && Get_Activation() <= 0) { return(false); } short lock_flag = 0; LptNum = 0; /**/ // Memo Lock Pass1 = 4651; Pass2 = 9261; LptNum = 0; // Below is to READ Memo Lock For Release 12/14 Service = 3; SeedCode = 0; p1 = 15; //for ASTRA Pro R19.0 //p2 == 18 int address = p1; int data = 0; int status = 0; object param1 = (object)address; object param2 = (object)data; object param3 = (object)status; HaspKey.Hasp(HaspService.ReadWord, SeedCode, LptNum, Pass1, Pass2, param1, param2, param3, null); status = (int)param3; p2 = (int)param2; if (p2 == 18) { lock_flag = 1; } else { lock_flag = 0; return(false); } Service = 3; SeedCode = 0; p1 = 14; //for heads //p2 == 54 param1 = (object)p1; param2 = (object)data; param3 = (object)status; HaspKey.Hasp(HaspService.ReadWord, SeedCode, LptNum, Pass1, Pass2, param1, param2, param3, null); status = (int)param3; p2 = (int)param2; if (p2 == 54) { lock_flag = 1; } else { lock_flag = 0; return(false); } //if (Version_Type == eVersionType.High_Value_Version) //{ // if (!Is_High_Value_19()) return false; //} //if (Version_Type == eVersionType.Low_Value_Version) //{ // if (Is_High_Value_19()) return true; //} return(true); } public static bool Check_ASTRA_Structure_Lock_19() { short lock_flag = 0; LptNum = 0; Pass1 = 4651; Pass2 = 9261; LptNum = 0; // Below is to READ Memo Lock For Release 12/14 Service = 3; SeedCode = 0; p1 = 7; // new address for Structural Analysis //p2 == 1 //Structure Analysis int address = p1; int data = 0; int status = 0; object param1 = (object)address; object param2 = (object)data; object param3 = (object)status; HaspKey.Hasp(HaspService.ReadWord, SeedCode, LptNum, Pass1, Pass2, param1, param2, param3, null); status = (int)param3; p2 = (int)param2; if (p2 == 1) { lock_flag = 1; } else { lock_flag = 0; return(false); } //if (Version_Type == eVersionType.High_Value_Version) //{ // if (!Is_High_Value_19()) return false; //} //if (Version_Type == eVersionType.Low_Value_Version) //{ // if (Is_High_Value_19()) return true; //} return(true); } public static bool Check_ASTRA_Bridge_Lock_19() { short lock_flag = 0; LptNum = 0; /**/ // Memo Lock Pass1 = 4651; Pass2 = 9261; LptNum = 0; // Below is to READ Memo Lock For Release 12/14 Service = 3; SeedCode = 0; p1 = 12; // ASTRA Pro R 19.0 //p2 == 1 //Structure Analysis int address = p1; int data = 0; int status = 0; object param1 = (object)address; object param2 = (object)data; object param3 = (object)status; HaspKey.Hasp(HaspService.ReadWord, SeedCode, LptNum, Pass1, Pass2, param1, param2, param3, null); status = (int)param3; p2 = (int)param2; if (p2 == 1) //for Bridge { lock_flag = 1; } else { lock_flag = 0; return(false); } //if (Version_Type == eVersionType.High_Value_Version) //{ // if (!Is_High_Value_19()) return false; //} //if (Version_Type == eVersionType.Low_Value_Version) //{ // if (Is_High_Value_19()) return true; //} return(true); }
public static bool Get_Authorization_Code_19() { short lock_flag = 0; LptNum = 0; /**/ // Memo Lock Pass1 = 4651; Pass2 = 9261; LptNum = 0; // Below is to READ Memo Lock For Release 12/14 Service = 3; SeedCode = 0; p1 = 8; //for heads //p2 == 1 // If Authorizasion Code entered //p2 == 0 // If Authorizasion Code not entered int address = p1; int data = 0; int status = 0; object param1 = (object)address; object param2 = (object)data; object param3 = (object)status; HaspKey.Hasp(HaspService.ReadWord, SeedCode, LptNum, Pass1, Pass2, param1, param2, param3, null); status = (int)param3; p2 = (int)param2; //p2 == 1 // If Authorizasion Code entered //p2 == 0 // If Authorizasion Code not entered if (p2 == 1) { lock_flag = 1; } else { lock_flag = 0; } return(lock_flag == 1); } public static bool IsActivate_19 { get { return(Get_Authorization_Code_19()); } } public static bool Is_High_Value_19() { LptNum = 0; Pass1 = 4651; Pass2 = 9261; LptNum = 0; //Below is to READ Memo Lock For Release 12/14 Service = 3; SeedCode = 0; p1 = 13; //ASTRA Pro R 19.0 //p2 == 1 int address = p1; int data = 0; int status = 0; object param1 = (object)address; object param2 = (object)data; object param3 = (object)status; HaspKey.Hasp(HaspService.ReadWord, SeedCode, LptNum, Pass1, Pass2, param1, param2, param3, null); status = (int)param3; p2 = (int)param2; return(p2 == 1); } #endregion ASTRA_Pro R19.0 #region ASTRA_Pro R19.0 public static bool Write_ASTRA_Code() { return(Write_ASTRA_Code_19()); } public static bool Check_ASTRA_Lock() { return(Check_ASTRA_Lock_19()); } public static bool Check_ASTRA_Structure_Lock() { return(Check_ASTRA_Structure_Lock_19()); } public static bool Check_ASTRA_Bridge_Lock() { return(Check_ASTRA_Bridge_Lock_19()); } public static bool IsProfessional_StructuralVersion() { return(IsProfessional_StructuralVersion_19()); } public static bool IsProfessional_BridgeVersion() { return(IsProfessional_BridgeVersion_19()); } public static bool Get_Authorization_Code() { return(Get_Authorization_Code_19()); } public static bool IsActivate { get { return(IsActivate_19); } } public static bool Is_High_Value() { return(Is_High_Value_19()); } #endregion ASTRA_Pro R19.0 #region General Functions public static bool Is_AASHTO() { p2 = 0; //if (p2 != 1) //{ if (TimeZone.CurrentTimeZone.StandardName.ToUpper().StartsWith("INDIA")) { return(false); } else { p2 = 1; } //} return(p2 == 1); } public static int Get_Activation() { LptNum = 0; /**/ // Memo Lock Pass1 = 4651; Pass2 = 9261; LptNum = 0; // Below is to READ Memo Lock For Release 12/14 Service = 3; SeedCode = 0; //p1=17 //for heads p1 = 9; //p2 == 23 int address = p1; int data = 0; int status = 0; object param1 = (object)address; object param2 = (object)data; object param3 = (object)status; HaspKey.Hasp(HaspService.ReadWord, SeedCode, LptNum, Pass1, Pass2, param1, param2, param3, null); status = (int)param3; p2 = (int)param2; return(p2); }