/// <summary> /// download all information from hardware /// </summary> /// <param name="DevName"></param> public void DownloadSMSFrmDeviceToBuf(string DevName, int wdDeviceType, int intActivePage, int num1, int num2)// 0 mean all, else that tab only { string strMainRemark = DevName.Split('\\')[1].Trim(); DevName = DevName.Split('\\')[0].Trim(); //保存basic informations网络信息 byte bytSubID = byte.Parse(DevName.Split('-')[0].ToString()); byte bytDevID = byte.Parse(DevName.Split('-')[1].ToString()); // read basic paramters byte[] ArayTmp = null; if (CsConst.mySends.AddBufToSndList(ArayTmp, 0x000E, bytSubID, bytDevID, false, true, true, false) == true) { byte[] arayRemark = new byte[20]; for (int intI = 0; intI < 20; intI++) { arayRemark[intI] = CsConst.myRevBuf[25 + intI]; } Devname = bytSubID.ToString() + "-" + bytDevID.ToString() + "\\" + HDLPF.Byte2String(arayRemark); } else { return; } ArayTmp = new byte[3]; ArayTmp[0] = 0; ArayTmp[1] = 1; if (intActivePage == 0 || intActivePage == 1) { if (CsConst.isRestore) { num1 = 0; num2 = 99; if (wdDeviceType == 4001) { num2 = 90; } } MyControls = new List <SMSControls>(); #region for (byte bytI = (byte)num1; bytI < num2; bytI++) { ArayTmp[2] = bytI; SMSControls oTmpSMS = new SMSControls(); oTmpSMS.ID = bytI; oTmpSMS.MyVerify = new List <PhoneInF>(); oTmpSMS.MyTargets = new List <UVCMD.ControlTargets>(); if (CsConst.mySends.AddBufToSndList(ArayTmp, 0xC017, bytSubID, bytDevID, true, true, true, false) == true) { // 20 bytes remark byte[] arayRemark = new byte[20]; for (int intI = 0; intI < 20; intI++) { arayRemark[intI] = CsConst.myRevBuf[28 + intI]; } oTmpSMS.strRemark = HDLPF.Byte2String(arayRemark); // 30 bytes sms content unicode arayRemark = new byte[32]; for (int intI = 0; intI < 32; intI++) { arayRemark[intI] = CsConst.myRevBuf[48 + intI]; } oTmpSMS.strSMSContent = HDLPF.Byte22String(arayRemark, true); // 判断是否验证手机号码 #region oTmpSMS.blnIsVerify = (CsConst.myRevBuf[896] == 0x11); oTmpSMS.blnReply = (CsConst.myRevBuf[897] == 0x11); for (int intJ = 0; intJ < 12; intJ++) { PhoneInF oPhone = new PhoneInF(); arayRemark = new byte[20]; for (int intI = 0; intI < 20; intI++) { arayRemark[intI] = CsConst.myRevBuf[80 + intJ * 36 + intI]; } oPhone.Remark = HDLPF.Byte2String(arayRemark); arayRemark = new byte[16]; for (int intI = 0; intI < 16; intI++) { if (CsConst.myRevBuf[100 + intJ * 36 + intI] != 0x45) { arayRemark[intI] = CsConst.myRevBuf[100 + intJ * 36 + intI]; } else { arayRemark[intI] = 0; } } oPhone.PhoneNum = HDLPF.Byte2String(arayRemark); oTmpSMS.MyVerify.Add(oPhone); } #endregion // 判断是否存在控制目标 #region int intTmpST = 512; for (int intI = 0; intI < 48; intI++) { //if (CsConst.myRevBuf[intTmpST + intI * 8 + 7] == 0xAA) //只保留有效 //{ UVCMD.ControlTargets oCMD = new UVCMD.ControlTargets(); oCMD.SubnetID = CsConst.myRevBuf[intTmpST + intI * 8]; oCMD.DeviceID = CsConst.myRevBuf[intTmpST + intI * 8 + 1]; oCMD.Type = CsConst.myRevBuf[intTmpST + intI * 8 + 2]; //oCMD.Type = HDLSysPF.GetIDAccordinglyRightControlTypeSMS(CsConst.myRevBuf[intTmpST + intI * 8 + 2]); //转换为正确的类型 oCMD.Param1 = CsConst.myRevBuf[intTmpST + intI * 8 + 3]; oCMD.Param2 = CsConst.myRevBuf[intTmpST + intI * 8 + 4]; oCMD.Param3 = CsConst.myRevBuf[intTmpST + intI * 8 + 5]; oCMD.Param4 = CsConst.myRevBuf[intTmpST + intI * 8 + 6]; oCMD.IsValid = (CsConst.myRevBuf[intTmpST + intI * 8 + 7] == 0xAA); oTmpSMS.MyTargets.Add(oCMD); //} } #endregion MyControls.Add(oTmpSMS); } else { return; } if (CsConst.calculationWorker != null && CsConst.calculationWorker.IsBusy) { CsConst.calculationWorker.ReportProgress(bytI / 2, null); } HDLUDP.TimeBetwnNext(20); } #endregion MyRead2UpFlags[0] = true; } if (intActivePage == 0 || intActivePage == 2) { // send message when needs #region ArayTmp = new byte[4]; ArayTmp[0] = 0; ArayTmp[1] = 2; MySendSMS = new List <SendSMS>(); if (CsConst.isRestore) { num1 = 0; num2 = 20; if (wdDeviceType == 4001) { num2 = 90; } } for (byte bytI = (byte)num1; bytI < num2; bytI++) { ArayTmp[2] = bytI; byte[] TmpSMS = new byte[1794]; SendSMS oTmpSMS = new SendSMS(); oTmpSMS.ID = bytI; oTmpSMS.MyGuests = new List <PhoneInF>(); if (wdDeviceType == 4001) { if (CsConst.mySends.AddBufToSndList(ArayTmp, 0xC060, bytSubID, bytDevID, true, true, true, false) == true) { Array.Copy(CsConst.myRevBuf, 29, TmpSMS, 0, 598); HDLUDP.TimeBetwnNext(20); } else { return; } } else { for (int intI = 0; intI < 3; intI++) //分三次读取数据 { ArayTmp[3] = Convert.ToByte(intI); if (CsConst.mySends.AddBufToSndList(ArayTmp, 0xC060, bytSubID, bytDevID, true, true, true, false) == true) { Array.Copy(CsConst.myRevBuf, 29, TmpSMS, intI * 598, 598); HDLUDP.TimeBetwnNext(20); } else { return; } } } // 20 bytes remark byte[] arayRemark = new byte[20]; for (int intI = 0; intI < 20; intI++) { arayRemark[intI] = TmpSMS[intI]; } oTmpSMS.strRemark = HDLPF.Byte2String(arayRemark); // 判断接收的手机号码 #region int num = 10; if (wdDeviceType == 4001) { num = 3; } for (int intJ = 0; intJ < num; intJ++) { PhoneInF oPhone = new PhoneInF(); if (TmpSMS[200 + intJ * 177] == 0xAA) { oPhone.Valid = true; } else { oPhone.Valid = false; } oPhone.ID = Convert.ToByte(intJ); arayRemark = new byte[20]; for (int intI = 0; intI < 20; intI++) { arayRemark[intI] = TmpSMS[24 + intJ * 177 + intI]; } oPhone.Remark = HDLPF.Byte2String(arayRemark); arayRemark = new byte[16]; for (int intI = 0; intI < 16; intI++) { if (TmpSMS[44 + intJ * 177 + intI] != 0x45) { arayRemark[intI] = TmpSMS[44 + intJ * 177 + intI]; } else { arayRemark[intI] = 0; } } oPhone.PhoneNum = HDLPF.Byte2String(arayRemark); arayRemark = new byte[140]; for (int intI = 0; intI < 140; intI++) { arayRemark[intI] = TmpSMS[60 + intJ * 177 + intI]; } oPhone.strSMS = HDLPF.Byte22String(arayRemark, true); oTmpSMS.MyGuests.Add(oPhone); } #endregion MySendSMS.Add(oTmpSMS); if (CsConst.calculationWorker != null) { CsConst.calculationWorker.ReportProgress(50 + bytI / 2, null); } } #endregion MyRead2UpFlags[1] = true; } if (CsConst.calculationWorker != null && CsConst.calculationWorker.IsBusy) { CsConst.calculationWorker.ReportProgress(100, null); } }
///<summary> ///读取数据库面板设置,将所有数据读至缓存 ///</summary> public void ReadSensorInfoFromDB(int DIndex) { //read GPRS Info #region string str = string.Format("select * from dbGPRSbasic where DIndex={0}", DIndex); OleDbDataReader dr = DataModule.SearchAResultSQLDB(str, CsConst.mstrCurPath); if (dr == null) { return; } while (dr.Read()) { strIP = dr.GetString(1); strRouterIP = dr.GetString(2); strMAC = dr.GetString(3); strSevCentre = dr.GetString(4); strCode = dr.GetString(5); strIMEI = dr.GetString(6); blnTo485 = dr.GetBoolean(7); } dr.Close(); #endregion //read GPRS Control Info #region MyControls = new List <SMSControls>(); str = string.Format("select * from dbGPRSControls where DIndex={0} order by SenNum", DIndex); dr = DataModule.SearchAResultSQLDB(str, CsConst.mstrCurPath); if (dr != null) { while (dr.Read()) { SMSControls temp = new SMSControls(); temp.MyVerify = new List <PhoneInF>(); temp.MyTargets = new List <UVCMD.ControlTargets>(); temp.ID = dr.GetInt16(1); temp.strRemark = dr.GetString(2); temp.strSMSContent = dr.GetString(3); temp.blnIsVerify = dr.GetBoolean(4); temp.blnReply = dr.GetBoolean(5); #region if (temp.blnIsVerify == true) { str = string.Format("select * from dbGPRSVerify where DIndex={0} and SenNum ={1} order by VerifyNum", DIndex, temp.ID); OleDbDataReader drVerify = DataModule.SearchAResultSQLDB(str, CsConst.mstrCurPath); if (drVerify != null) { while (drVerify.Read()) { PhoneInF tmp = new PhoneInF(); tmp.ID = drVerify.GetInt16(2); tmp.Remark = drVerify.GetString(3); tmp.PhoneNum = drVerify.GetString(4); temp.MyVerify.Add(tmp); } drVerify.Close(); } } #endregion str = string.Format("select * from dbKeyTargets where DIndex ={0} and KeyIndex = {1} order by objID", DIndex, temp.ID); OleDbDataReader drKeyCmds = DataModule.SearchAResultSQLDB(str, CsConst.mstrCurPath); if (drKeyCmds != null) { while (drKeyCmds.Read()) { UVCMD.ControlTargets TmpCmd = new UVCMD.ControlTargets(); TmpCmd.ID = drKeyCmds.GetByte(2); TmpCmd.Type = drKeyCmds.GetByte(3); TmpCmd.SubnetID = drKeyCmds.GetByte(4); TmpCmd.DeviceID = drKeyCmds.GetByte(5); TmpCmd.Param1 = drKeyCmds.GetByte(6); TmpCmd.Param2 = drKeyCmds.GetByte(7); TmpCmd.Param3 = drKeyCmds.GetByte(8); TmpCmd.Param4 = drKeyCmds.GetByte(9); temp.MyTargets.Add(TmpCmd); } drKeyCmds.Close(); MyControls.Add(temp); } } dr.Close(); } #endregion //read GPRS SMS Send Info #region MySendSMS = new List <SendSMS>(); str = string.Format("select * from dbGPRSSendSMS where DIndex = {0} order by SenNum", DIndex); dr = DataModule.SearchAResultSQLDB(str, CsConst.mstrCurPath); if (dr != null) { while (dr.Read()) { SendSMS temp = new SendSMS(); temp.MyGuests = new List <PhoneInF>(); temp.ID = dr.GetInt16(1); temp.strRemark = dr.GetString(2); str = string.Format("select * from dbGPRSSendSMSInfo where DIndex={0} and SenNum ={1} order by TargetNum", DIndex, temp.ID); OleDbDataReader drSend = DataModule.SearchAResultSQLDB(str, CsConst.mstrCurPath); if (drSend != null) { while (drSend.Read()) { PhoneInF tmp = new PhoneInF(); tmp.ID = drSend.GetInt16(2); tmp.Remark = drSend.GetString(3); tmp.PhoneNum = drSend.GetString(4); tmp.strSMS = drSend.GetString(5); temp.MyGuests.Add(tmp); } drSend.Close(); } MySendSMS.Add(temp); } dr.Close(); } #endregion }
///<summary> ///保存数据库面板设置,将所有数据保存 ///</summary> public void SaveSensorInfoToDB() { //delete GPRS Info #region string strsql = string.Format("delete * from dbGPRSbasic where DIndex={0}", DIndex); DataModule.ExecuteSQLDatabase(strsql); //delete GPRS Control Info strsql = string.Format("delete * from dbGPRSControls where DIndex ={0}", DIndex); DataModule.ExecuteSQLDatabase(strsql); strsql = string.Format("delete * from dbGPRSVerify where DIndex={0}", DIndex); DataModule.ExecuteSQLDatabase(strsql); strsql = string.Format("delete * from dbGPRSTargets where DIndex={0}", DIndex); DataModule.ExecuteSQLDatabase(strsql); strsql = string.Format("delete * form dbGPRSSendSMS where DIndex={0}", DIndex); DataModule.ExecuteSQLDatabase(strsql); strsql = string.Format("delete * from dbGPRSSendSMSInfo where DIndex={0}", DIndex); DataModule.ExecuteSQLDatabase(strsql); #endregion //save GPRS Info #region strsql = string.Format("insert into dbGPRSbasic(DIndex,strIP,strRouterIP,strMAC,strSevCentre,strCode,strIMEI,blnTo485)values({0},'{1}','{2}','{3}','{4}','{5}','{6}',{7})", DIndex, strIP, strRouterIP, strMAC, strSevCentre, strCode, strIMEI, blnTo485); DataModule.ExecuteSQLDatabase(strsql); #endregion //save GPRS SMS Control Info #region if (MyControls != null) { foreach (SMSControls temp in MyControls) { strsql = string.Format("insert into dbGPRSControls(DIndex,SenNum,strRemark,strSMSContent,blnIsVerify,blnReply)values({0},{1},'{2}'," + "'{3}',{4},{5})", DIndex, temp.ID, temp.strRemark, temp.strSMSContent, temp.blnIsVerify, temp.blnReply); DataModule.ExecuteSQLDatabase(strsql); if (temp.MyVerify != null) { for (int i = 0; i < temp.MyVerify.Count; i++) { PhoneInF tmp = temp.MyVerify[i]; strsql = string.Format("insert into dbGPRSVerify(DIndex,SenNum,VerifyNum,Remark,PhoneNum)values({0},{1},{2},'{3}','{4}')", DIndex, temp.ID, i, tmp.Remark, tmp.PhoneNum); DataModule.ExecuteSQLDatabase(strsql); } } if (temp.MyTargets != null) { for (int i = 0; i < temp.MyTargets.Count; i++) { UVCMD.ControlTargets TmpCmds = temp.MyTargets[i]; strsql = string.Format("Insert into dbKeyTargets(DIndex,KeyIndex,objID,KeyFunType,SubNetID,DeviceID,FirstParameter," + "SecondParameter,RunTimeMinute,RunTimeSecond,Ms04State) values ({0},{1},'{2}',{3},{4},{5},{6},{7},{8},{9},{10})", DIndex, temp.ID, TmpCmds.ID, TmpCmds.Type, TmpCmds.SubnetID, TmpCmds.DeviceID, TmpCmds.Param1, TmpCmds.Param2, TmpCmds.Param3, TmpCmds.Param4, 0); DataModule.ExecuteSQLDatabase(strsql); } } } } #endregion //save GPRS SMS Send Info #region if (MySendSMS != null) { foreach (SendSMS temp in MySendSMS) { strsql = string.Format("insert into dbGPRSSendSMS(DIndex,SenNum,Remark)values({0},{1},'{2}')", DIndex, temp.ID, temp.strRemark); DataModule.ExecuteSQLDatabase(strsql); if (temp.MyGuests != null) { for (int i = 0; i < temp.MyGuests.Count; i++) { PhoneInF tmp = temp.MyGuests[i]; strsql = string.Format("insert into dbGPRSSendSMSInfo(DIndex,SenNum,TargetNum,Remark,PhoneNum,SMS)values({0},{1},{2},'{3}','{4}','{5}')", DIndex, temp.ID, i + 1, tmp.Remark, tmp.PhoneNum, tmp.strSMS); DataModule.ExecuteSQLDatabase(strsql); } } } } #endregion }