///*********************************************************** public bool SendConnectToFatek(DataTable dt) { List <DateToSendClass> ls; ls = new List <DateToSendClass>(); int startAddress = Int32.Parse(dt.Rows[0]["UStartRigster"].ToString()); int endAddress = Int32.Parse(dt.Rows[0]["UEndRigster"].ToString()); int UStatus = Int32.Parse(dt.Rows[0]["UStatus"].ToString()); int UStaticOnHour = (dt.Rows[0]["UStaticOnHour"] == null || dt.Rows[0]["UStaticOnHour"].ToString() == "") ? 0 : Int32.Parse(dt.Rows[0]["UStaticOnHour"].ToString()); if (UStatus != 2) { AddToListForForceFatek(ref ls, UStaticOnHour, UStatus, DateTime.Now); AddToListForForceFatek(ref ls, UStaticOnHour, UStatus, DateTime.Now.AddMinutes(1)); } else { ls = GetAllDatesTimes(dt); } short[] dataToWrite = new short[endAddress - startAddress + 1]; for (int i = 0; i < ls.Count; i++) { dataToWrite[i] = ls[i].NoClassBuffer; } FatekObj.writeBuffer(dataToWrite, startAddress, FatekConnection.getAreaByLetter("R")); return(true); }
//public List<DateToSendClass> getDatesList(int dateListId, int classId, DayOfWeek theDay) //{ // DateList dl = getDateList(dateListId); // return dl.getRealDates(DEFAULT_MAX_NUMBER_OF_CLASSES).FindAll(p => p.ClassNumber == classId && p.Day == theDay); //} public List <DateToSendClass> getDatesList(int classId) { List <DateToSendClass> ls = new List <DateToSendClass>(); string sql = "SELECT * FROM ClassesDictionary WHERE ClassNumber=" + classId.ToString(); OleDbDataAdapter dbCmd = new OleDbDataAdapter(sql, conn); DataTable classesDataTable = new DataTable(); dbCmd.Fill(classesDataTable); if (classesDataTable.Rows.Count == 0) { return(ls); } DataRow classDataRow = classesDataTable.Rows[0]; int startAddress = int.Parse(classDataRow["StartAddress"].ToString()); int endAddress = int.Parse(classDataRow["EndAddress"].ToString()); #if DEBUG ls = FatekObj.getDatesInShortFormat(startAddress, FatekConnection.getAreaByLetter(classDataRow["MemoryType"].ToString()), endAddress - startAddress + 1); // ls = FatekConnection.LastOpenedConnection // .getDatesInShortFormat(startAddress, FatekConnection.getAreaByLetter(classDataRow["MemoryType"].ToString()), endAddress - startAddress + 1); #else Random r = new Random(); for (int i = 0; i <= 6; i++) { int oldValue = 0; for (int j = 0; j < 6; j++) { DateToSendClass d = new DateToSendClass(); oldValue = r.Next(oldValue + 1, 12 + 2 * j); d.Hour = oldValue; d.Minute = (int)i; d.ShouldTurnOn = (j % 2 == 0); d.ClassNumber = classId; d.Day = (DayOfWeek)i; d.DBId = 0; ls.Add(d); } } #endif ls.Sort(DateToSendClass.simpleDatesComparison); return(ls); //DateList dl = getDateList(dateListId); //return dl.getRealDates(DEFAULT_MAX_NUMBER_OF_CLASSES).FindAll(p => p.ClassNumber == classId); }
public bool sendEliorTest(int endAddress, int startAddress, bool IsON) { List <DateToSendClass> ls; ls = new List <DateToSendClass>(); AddToListForForce(ref ls, 103, IsON, DateTime.Now); //AddToListForForce(ref ls, 103, IsON, DateTime.Now.AddMinutes(1)); short[] dataToWrite = new short[endAddress - startAddress + 1]; for (int i = 0; i < ls.Count; i++) { dataToWrite[i] = ls[i].NoClassBuffer; } FatekObj.writeBuffer(dataToWrite, startAddress, FatekConnection.getAreaByLetter("R")); return(true); }
public bool sendDatesToPLC(int classNum) { List <DateToSendClass> ls; ls = new List <DateToSendClass>(); int forceStat = getClassForceStatus(classNum); if (forceStat == 1 || forceStat == -1) { AddToListForForce(ref ls, classNum, (forceStat == 1), DateTime.Now); AddToListForForce(ref ls, classNum, (forceStat == 1), DateTime.Now.AddMinutes(1)); //d = new DateToSendClass(); //t = DateTime.Now.AddMinutes(1); //d.Day = (DayOfWeek)t.DayOfWeek;//DayOfWeek.Sunday; //d.Hour = t.Hour; //d.Minute = t.Minute; //d.ShouldTurnOn = (forceStat == 1); //d.ClassNumber = classNum; //// ls = new List<DateToSendClass>(); //ls.Add(d); } if (forceStat == 0) { ls = getAllDateTimesByClass(classNum); } if (forceStat > 20) { int CastHours = forceStat - 20; AddToListForForce(ref ls, classNum, true, DateTime.Now); AddToListForForce(ref ls, classNum, true, DateTime.Now.AddMinutes(1)); AddToListForForce(ref ls, classNum, false, DateTime.Now.AddHours(CastHours)); //AddToListForForce(ref ls, classNum, false, DateTime.Now.AddHours(CastHours).AddMinutes(1)); } string sql = "Select ClassNumber,ClassName,PLC,StartAddress,EndAddress,MemoryType.Type as MemoryType FROM ClassesDictionary,MemoryType WHERE ClassNumber=" + classNum + " AND ClassesDictionary.MemoryType=MemoryType.ID"; DataTable classData = new DataTable(); OleDbDataAdapter dbCmd = new OleDbDataAdapter(sql, conn); dbCmd.Fill(classData); if (classData.Rows.Count == 0) { ErrorManager.Instance.addError(new NotFoundInDBError(NotFoundInDBError.DBObjects.Class)); return(false); } DataRow classDataRow = classData.Rows[0]; int startAddress = int.Parse(classDataRow["StartAddress"].ToString()); int endAddress = int.Parse(classDataRow["EndAddress"].ToString()); if (startAddress + ls.Count > endAddress) { ErrorManager.Instance.addError(new TriedToWriteTooManyDatesError(classNum)); return(false); } short[] dataToWrite = new short[endAddress - startAddress + 1]; for (int i = 0; i < ls.Count; i++) { dataToWrite[i] = ls[i].NoClassBuffer; } #if DEBUG try { // FatekConnection.LastOpenedConnection.writeBuffer(dataToWrite, startAddress, FatekConnection.getAreaByLetter(classDataRow["MemoryType"].ToString())); FatekObj.writeBuffer(dataToWrite, startAddress, FatekConnection.getAreaByLetter(classDataRow["MemoryType"].ToString())); return(true); } catch (Exception exc) { ErrorManager.Instance.addError(new FailedToWriteDataToPLCError(exc.Message)); return(false); } #endif return(true); }