private void btnReName_Click(object sender, EventArgs e) { if (tvEdit.SelectedNode == null) { return; } if (tvEdit.SelectedNode.Level == 0) { return; } if (tbRemark1.Text == null || tbRemark1.Text == "") { return; } string strDevice = tvEdit.SelectedNode.Parent.Text; string strOldRemark = tvEdit.SelectedNode.Text; string strNewRemark = tbRemark1.Text; //更新到数据库 string strsql = string.Format("update tblRemoteCode set Remark='{0}' where ID={1} and RemoteDeviceID = {2} and Remark='{3}'", strNewRemark, tvEdit.SelectedNode.Name, tvEdit.SelectedNode.Parent.Name, strOldRemark); DataModule.ExecuteSQLDatabase(strsql); }
public static void SaveAllGroupCommandsFrmDatabase() { string str = string.Format("delete * from dbGrpRemark"); DataModule.ExecuteSQLDatabase(str); str = string.Format("delete * from dbGrpCMD"); DataModule.ExecuteSQLDatabase(str); if (CsConst.myTemplates == null) { return; } ////read keys commands to buffer foreach (ControlTemplates oTmp in CsConst.myTemplates) { if (oTmp.GpCMD != null) { string strsql = string.Format("Insert into dbGrpRemark(GrpID,Remark,bytType,bytGpID) values ({0},'{1}',{2},{3})", oTmp.ID, oTmp.Name, oTmp.bytType, oTmp.bytGpID); DataModule.ExecuteSQLDatabase(strsql); for (int i = 0; i < oTmp.GpCMD.Count; i++) { UVCMD.ControlTargets TmpCmds = oTmp.GpCMD[i]; ///// insert into all commands to database strsql = string.Format("Insert into dbGrpCMD(GrpID,objID,KeyFunType,SubNetID,DeviceID,FirstParameter," + "SecondParameter,RunTimeMinute,RunTimeSecond,strHint,Default1) values ({0},{1},{2},{3},{4},{5},{6},{7},{8},'{9}',{10})", oTmp.ID, TmpCmds.ID, TmpCmds.Type, TmpCmds.SubnetID, TmpCmds.DeviceID, TmpCmds.Param1, TmpCmds.Param2, TmpCmds.Param3, TmpCmds.Param4, TmpCmds.Hint, oTmp.bytType); DataModule.ExecuteSQLDatabase(strsql); } } } }
//<summary> //保存数据库面板设置,将所有数据保存 //</summary> public override void SaveSendIRToDB(int intDeviceType) { base.SaveSendIRToDB(intDeviceType); //insert new channel information if (Chans != null) { #region string str = ""; string chid = "", remark = "", loadType = "", MinValue = "", MaxValue = "", MaxLevel = ""; string temp = "", Belongs = ""; byte bytI = 0; foreach (RelayChannel ch in Chans) { chid += bytI.ToString() + temp; remark += ch.Remark + temp; loadType += ch.LoadType.ToString() + temp; MinValue += ch.OnDelay.ToString() + temp; MaxValue += ch.ProtectDelay.ToString() + temp; bytI++; } str = "insert into dbDevChnsDR(ID,ChannelID,Remark,LoadType,Low,High,MaxValue,AreaID) values(" + DIndex.ToString() + ",'" + chid + "','" + remark + "','" + loadType + "','" + MinValue + "','" + MaxValue + "','" + MaxLevel + "','" + Belongs + "')"; DataModule.ExecuteSQLDatabase(str); #endregion } }
//<summary> //保存数据库面板设置,将所有数据保存 //</summary> public override void SaveSendIRToDB(int intDeviceType) { base.SaveSendIRToDB(intDeviceType); int wdMaxValue = DeviceTypeList.GetMaxValueFromPublicModeGroup(intDeviceType); Chans = new List <DimmerChannelGenerationTwo>(); for (int i = 0; i < wdMaxValue; i++) { DimmerChannel oChan = Chans[i]; string str = ""; string chid = "", remark = "", loadType = "", MinValue = "", MaxValue = "", MaxLevel = ""; string temp = "", Belongs = ""; if (Chans == null) { return; } temp = "-"; chid += "1" + temp; remark += oChan.remark + temp; loadType += oChan.loadType.ToString() + temp; MinValue += oChan.minValue.ToString() + temp; MaxValue += oChan.maxValue.ToString() + temp; MaxLevel += oChan.maxLevel.ToString() + temp; Belongs += oChan.belongArea.ToString() + temp; str = "insert into dbDevChnsDR(ID,ChannelID,Remark,LoadType,Low,High,MaxValue,AreaID) values(" + "1".ToString() + ",'" + chid + "','" + remark + "','" + loadType + "','" + MinValue + "','" + MaxValue + "','" + MaxLevel + "','" + Belongs + "')"; DataModule.ExecuteSQLDatabase(str); } }
private void btnDel_Click(object sender, EventArgs e) { if (tvEdit.SelectedNode == null) { return; } TreeNode oTmp = tvEdit.SelectedNode; if (oTmp.Level == 0 && (oTmp.Nodes == null || oTmp.Nodes.Count == 0)) // 如果是设备 而且本身没有任何红外码 可以直接移除 { oTmp.Remove(); // 删除当前全部类 string strsql = string.Format("Delete from tblRemoteDevice where ID = {0}", oTmp.Name); DataModule.ExecuteSQLDatabase(strsql); } else if (oTmp.Level == 1) // 如果设备中的其中一个红外码 可以直接删除 { string strDevice = oTmp.Parent.Text; string strOldRemark = oTmp.Text; string strInsert = string.Format("Delete from tblRemoteCode where ID = {0} and RemoteDeviceID = {1} and Remark = '{2}'", oTmp.Name, oTmp.Parent.Name, strOldRemark); DataModule.ExecuteSQLDatabase(strInsert); oTmp.Remove(); } }
public static bool SaveDatatoDB() { bool result = true; int test = -1; try { if (CsConst.WholeTextsList == null || CsConst.WholeTextsList.Count <= 0) { return(true); } string strsql = ""; foreach (FormDisplayTextList temp in CsConst.WholeTextsList) { // check if it has already exist, if yes ,save to ini #region test = temp.iIndexInWholeList; strsql = string.Format("insert into dbLanguaText(TextIndex,TextLength,English) values ({0},{1},'{2}')", temp.iIndexInWholeList, temp.sMaxLimit, temp.sDisplayName); DataModule.ExecuteSQLDatabase(strsql); #endregion } } catch { MessageBox.Show(test.ToString()); result = false; } return(result); }
///<summary> ///保存数据库面板设置,将所有数据保存 ///</summary> public void SaveDevieceInfoToDB() { /// delete all old information and refresh the database string strsql = string.Format("delete from dbBasicBac where DIndex={0}", DIndex); DataModule.ExecuteSQLDatabase(strsql); strsql = string.Format("delete from dbBackNet where DIndex={0}", DIndex); DataModule.ExecuteSQLDatabase(strsql); ///save save basic setup of EIB #region strsql = string.Format("insert into dbBasicBac(DIndex,Remark,strIP,strRouterIP,strMAC,strMaskIP,bytPort,bytSwitch,bytDevID) values({0},'{1}','{2}','{3}','{4}','{5}',{6},{7},{8})", DIndex, DeviceName, "", "", "", ValidCount.ToString(), intPort, Convert.ToByte(blnSwitch), Address); DataModule.ExecuteSQLDatabase(strsql); #endregion //save bus to EIB command #region if (otherInfo == null) { return; } byte bytI = 0; for (int i = 0; i < otherInfo.Count; i++) { bytI++; OtherInfo temp = otherInfo[i]; System.Diagnostics.Debug.WriteLine(otherInfo[1].Param4); string sql = "insert into dbBackNet(DIndex,CurNo,BackNetIDAry,Type,strDevName,Param1,Param2,Param3,Param4,Remark) values(@DIndex,@CurNo,@BackNetIDAry,@Type,@strDevName,@Param1,@Param2,@Param3,@Param4,@Remark)"; //创建一个OleDbConnection对象 OleDbConnection conn; conn = new OleDbConnection(DataModule.ConString + CsConst.mstrDefaultPath); conn.Open(); OleDbCommand cmdTmp = new OleDbCommand(sql, conn); ((OleDbParameter)cmdTmp.Parameters.Add("@DIndex", OleDbType.Integer)).Value = DIndex; ((OleDbParameter)cmdTmp.Parameters.Add("@CurNo", OleDbType.Char)).Value = temp.ID; ((OleDbParameter)cmdTmp.Parameters.Add("@BackNetIDAry", OleDbType.Binary)).Value = temp.BackNetIDAry; ((OleDbParameter)cmdTmp.Parameters.Add("@Type", OleDbType.Integer)).Value = temp.Type; ((OleDbParameter)cmdTmp.Parameters.Add("@strDevName", OleDbType.VarChar)).Value = temp.strDevName; ((OleDbParameter)cmdTmp.Parameters.Add("@Param1", OleDbType.Char)).Value = temp.Param1; ((OleDbParameter)cmdTmp.Parameters.Add("@Param2", OleDbType.Char)).Value = temp.Param2; ((OleDbParameter)cmdTmp.Parameters.Add("@Param3", OleDbType.Char)).Value = temp.Param3; ((OleDbParameter)cmdTmp.Parameters.Add("@Param4", OleDbType.Char)).Value = temp.Param4; ((OleDbParameter)cmdTmp.Parameters.Add("@Remark", OleDbType.VarChar)).Value = temp.Remark; try { cmdTmp.ExecuteNonQuery(); } catch (OleDbException exp) { MessageBox.Show(exp.ToString()); } conn.Close(); } #endregion }
///<summary> ///保存数据库面板设置,将所有数据保存 ///</summary> public void SaveDevieceInfoToDB(int DIndex) { /// delete all old information and refresh the database string strsql = string.Format("delete from dbDeviceInfo where DIndex={0}", DIndex); DataModule.ExecuteSQLDatabase(strsql); strsql = string.Format("delete from dbEIBDev where DIndex={0}", DIndex); DataModule.ExecuteSQLDatabase(strsql); ///save save basic setup of EIB #region strsql = string.Format("insert into dbDeviceInfo(DIndex,Devname,Address) values({0},'{1}','{2}')", DIndex, Devname, Address); DataModule.ExecuteSQLDatabase(strsql); #endregion //save bus to EIB command #region if (otherInfo == null) { return; } byte bytI = 0; for (int i = 0; i < otherInfo.Count; i++) { bytI++; OtherInfo temp = otherInfo[i]; System.Diagnostics.Debug.WriteLine(otherInfo[1].Param4); string sql = "insert into dbEIBDev(DIndex,CurNo,GroupAddress,ControlType,Type,Param1,Param2,Param3,Param4,DestDev) values(@DIndex,@CurNo,@GroupAddress,@ControlType,@Type,@Param1,@Param2,@Param3,@Param4,@DestDev)"; //创建一个OleDbConnection对象 OleDbConnection conn; conn = new OleDbConnection(DataModule.ConString + CsConst.mstrDefaultPath); conn.Open(); OleDbCommand cmdTmp = new OleDbCommand(sql, conn); ((OleDbParameter)cmdTmp.Parameters.Add("@DIndex", OleDbType.Integer)).Value = DIndex; ((OleDbParameter)cmdTmp.Parameters.Add("@CurNo", OleDbType.Char)).Value = i; ((OleDbParameter)cmdTmp.Parameters.Add("@GroupAddress", OleDbType.VarChar)).Value = temp.GroupAddress; ((OleDbParameter)cmdTmp.Parameters.Add("@ControlType", OleDbType.Char)).Value = temp.ControlType; ((OleDbParameter)cmdTmp.Parameters.Add("@Type", OleDbType.Char)).Value = temp.Type; ((OleDbParameter)cmdTmp.Parameters.Add("@Param1", OleDbType.Char)).Value = temp.Param1; ((OleDbParameter)cmdTmp.Parameters.Add("@Param2", OleDbType.Char)).Value = temp.Param2; ((OleDbParameter)cmdTmp.Parameters.Add("@Param3", OleDbType.Char)).Value = temp.Param3; ((OleDbParameter)cmdTmp.Parameters.Add("@Param4", OleDbType.Char)).Value = temp.Param4; ((OleDbParameter)cmdTmp.Parameters.Add("@DestDev", OleDbType.VarChar)).Value = temp.strDevName; try { cmdTmp.ExecuteNonQuery(); } catch (OleDbException exp) { MessageBox.Show(exp.ToString()); } conn.Close(); } #endregion }
//<summary> //保存IP设置,将所有数据保存 //</summary> public void SaveCurtainToDB() { //// delete all old information and refresh the database string strsql = string.Format("delete * from dbIPModule where DIndex=" + DIndex.ToString()); DataModule.ExecuteSQLDatabase(strsql); //// insert curtain Type //strsql = string.Format("insert into dbIPModule(DIndex,strIP,strRouterIP,strMaskIP,strMAC,bytWorkType,strGroup,strPrjName,strUser,strPWD,strServer1,intPort1,strServer2,intPort2," // + "bytTimer,bytEnDHCP ) values({0},'{1}','{2}','{3}','{4}',{5},'{6}','{7}','{8}','{9}','{10}',{11},'{12}',{13},{14},{15})", DIndex,strIP,strRouterIP,strMaskIP,strMAC, // bytWorkType,strGroup,strPrjName,strUser,strPWD,strServer1,intPort1,strServer2,intPort2,bytTimer,bytEnDHCP); //DataModule.ExecuteSQLDatabase(strsql); }
//<summary> //保存数据库面板设置,将所有数据保存 //</summary> public override void SaveSendIRToDB(int intDeviceType) { base.SaveSendIRToDB(intDeviceType); //insert new channel information if (Chans != null) { #region String strParam = Chans.runTime.ToString() + "-" + Chans.onDelay.ToString() + "-" + Chans.offDelay.ToString(); String strsql = string.Format("Insert into dbClassInfomation(DIndex,ClassID,ObjectID,SenNum,Remark,strParam1) values ({0},{1},{2},{3},'{4}','{5}')", DIndex, 1, 0, 0, Chans.remark, strParam); DataModule.ExecuteSQLDatabase(strsql); #endregion } }
//<summary> //将缓存里所有HVAC的设置存在数据库 //</summary> public void SaveInfoToDb() { //// delete all old information and refresh the database string strsql = string.Format("delete from dbHVAC where DIndex=" + DIndex.ToString()); DataModule.ExecuteSQLDatabase(strsql); strsql = @"Insert into dbHVAC(DIndex,bytAutoRun,bytModeONDelay,bytModeOFFDelay,bytFanONDelay,bytFanOFFDelay,bytCOrP,bytHigh," + "bytMid,bytLow,bytSteps) values(@DIndex,@bytAutoRun,@bytModeONDelay,@bytModeOFFDelay,@bytFanONDelay,@bytFanOFFDelay," + "@bytCOrP,@bytHigh,@bytMid,@bytLow,@bytSteps)"; //创建一个OleDbConnection对象 OleDbConnection conn; conn = new OleDbConnection(DataModule.ConString + CsConst.mstrDefaultPath); conn.Open(); if (bytSteps == null) { bytSteps = new byte[12]; } OleDbCommand cmd = new OleDbCommand(strsql, conn); ((OleDbParameter)cmd.Parameters.Add("@DIndex", OleDbType.Integer)).Value = DIndex; ((OleDbParameter)cmd.Parameters.Add("@bytAutoRun", OleDbType.VarChar)).Value = bytAutoRun; ((OleDbParameter)cmd.Parameters.Add("@bytModeONDelay", OleDbType.VarChar)).Value = bytModeONDelay; ((OleDbParameter)cmd.Parameters.Add("@bytModeOFFDelay", OleDbType.VarChar)).Value = bytModeOFFDelay; ((OleDbParameter)cmd.Parameters.Add("@bytFanONDelay", OleDbType.VarChar)).Value = bytFanONDelay; ((OleDbParameter)cmd.Parameters.Add("@bytFanOFFDelay", OleDbType.VarChar)).Value = bytFanOFFDelay; ((OleDbParameter)cmd.Parameters.Add("@bytCOrP", OleDbType.VarChar)).Value = bytCOrP; ((OleDbParameter)cmd.Parameters.Add("@bytHigh", OleDbType.VarChar)).Value = bytHigh; ((OleDbParameter)cmd.Parameters.Add("@bytMid", OleDbType.VarChar)).Value = bytMid; ((OleDbParameter)cmd.Parameters.Add("@bytLow", OleDbType.VarChar)).Value = bytLow; ((OleDbParameter)cmd.Parameters.Add("@bytSteps", OleDbType.Binary)).Value = bytSteps; try { cmd.ExecuteNonQuery(); } catch (OleDbException exp) { MessageBox.Show(exp.ToString()); } conn.Close(); }
//<summary> //保存数据 //</summary> public void SaveDataToDB() { try { #region string strsql = string.Format("delete * from dbClassInfomation where DIndex={0}", DIndex); DataModule.ExecuteSQLDatabase(strsql); if (myACSetting != null) { for (int i = 0; i < myACSetting.Count; i++) { ThirdPartAC temp = myACSetting[i]; string strParam = temp.ID.ToString() + "-" + temp.Enable.ToString() + "-" + temp.ACNO.ToString() + "-" + temp.CoolMasterAddress.ToString() + "-" + temp.GroupID.ToString(); strsql = @"Insert into dbClassInfomation(DIndex,ClassID,ObjectID,SenNum,Remark,strParam1,byteAry1)" + " values(@DIndex,@ClassID,@ObjectID,@SenNum,@Remark,@strParam1,@byteAry1)"; OleDbConnection conn; conn = new OleDbConnection(DataModule.ConString + CsConst.mstrDefaultPath); //OleDbConnection conn = new OleDbConnection(DataModule.ConString + CsConst.mstrCurPath); conn.Open(); OleDbCommand cmd = new OleDbCommand(strsql, conn); ((OleDbParameter)cmd.Parameters.Add("@DIndex", OleDbType.Integer)).Value = DIndex; ((OleDbParameter)cmd.Parameters.Add("@ClassID", OleDbType.Integer)).Value = 0; ((OleDbParameter)cmd.Parameters.Add("@ObjectID", OleDbType.Integer)).Value = 0; ((OleDbParameter)cmd.Parameters.Add("@SenNum", OleDbType.Integer)).Value = i; ((OleDbParameter)cmd.Parameters.Add("@Remark", OleDbType.VarChar)).Value = temp.Remark; ((OleDbParameter)cmd.Parameters.Add("@strParam1", OleDbType.VarChar)).Value = strParam; ((OleDbParameter)cmd.Parameters.Add("@byteAry1", OleDbType.Binary)).Value = temp.arayACinfo; try { cmd.ExecuteNonQuery(); } catch { conn.Close(); } conn.Close(); } } #endregion } catch { } }
//<summary> //保存数据库面板设置,将所有数据保存 //</summary> public void SaveCurtainToDB() { try { #region string strsql = string.Format("delete * from dbClassInfomation where DIndex={0}", DIndex); DataModule.ExecuteSQLDatabase(strsql); string strDeviceRemark = ""; if (DeviceName.Contains("\\")) { strDeviceRemark = DeviceName.Split('\\')[1].ToString(); } string strParam = bytCurType.ToString() + "-" + intJogTime.ToString() + "-" + intJogTime1.ToString() + "-" + bytInvert.ToString() + "-" + bytAutoMeasure.ToString() + "-" + bytDragMode.ToString() + "-" + intDragLong.ToString() + "-" + intDragShort.ToString() + "-" + intDragSafe.ToString(); strsql = string.Format("Insert into dbClassInfomation(DIndex,ClassID,ObjectID,SenNum,Remark,strParam1) values ({0},{1},{2},{3},'{4}','{5}')", DIndex, 0, 0, 0, strDeviceRemark, strParam); DataModule.ExecuteSQLDatabase(strsql); #endregion #region if (Curtains != null) { for (int i = 0; i < Curtains.Count; i++) { BasicCurtain temp = Curtains[i]; strParam = temp.runTime.ToString() + "-" + temp.onDelay.ToString() + "-" + temp.offDelay.ToString(); strsql = string.Format("Insert into dbClassInfomation(DIndex,ClassID,ObjectID,SenNum,Remark,strParam1) values ({0},{1},{2},{3},'{4}','{5}')", DIndex, 1, 0, 0, temp.remark, strParam); DataModule.ExecuteSQLDatabase(strsql); } } #endregion } catch { } }
//<summary> //保存数据库面板设置,将所有数据保存 //</summary> public void SaveSendIRToDB() { try { string strsql = string.Format("delete * from dbClassInfomation where DIndex={0}", DIndex); DataModule.ExecuteSQLDatabase(strsql); #region string strDeviceRemark = ""; if (strName.Contains("\\")) { strDeviceRemark = strName.Split('\\')[1].ToString(); } string strBasic = RemoteEnable.ToString() + "-" + mbytOne.ToString() + "-" + mbytTwo.ToString(); strsql = string.Format("Insert into dbClassInfomation(DIndex,ClassID,ObjectID,SenNum,Remark,strParam1) values ({0},{1},{2},{3},'{4}','{5}')", DIndex, 0, 0, 0, strDeviceRemark, strBasic); DataModule.ExecuteSQLDatabase(strsql); #endregion #region if (IRCodes != null) { for (int i = 0; i < IRCodes.Count; i++) { UVCMD.IRCode temp = IRCodes[i]; string strParam = temp.KeyID.ToString() + "-" + temp.IRLength.ToString() + "-" + temp.IRLoation.ToString() + "-" + temp.Enable.ToString() + "-" + temp.Codes.ToString(); strsql = string.Format("Insert into dbClassInfomation(DIndex,ClassID,ObjectID,SenNum,Remark,strParam1) values ({0},{1},{2},{3},'{4}','{5}')", DIndex, 1, 0, i, temp.Remark1, strParam); DataModule.ExecuteSQLDatabase(strsql); } } #endregion } catch { } }
//<summary> //将缓存里所有调光模块的设置存在数据库 //</summary> public void SaveInfoToDb() { byte bytChnID = 1; foreach (Chn ch in Chans) { string str = "select * from dbTempSensor where DIndex=" + DIndex.ToString() + " and ChnID = " + bytChnID.ToString(); if (DataModule.IsExitstInDatabase(str) == false) { str = string.Format("insert into dbTempSensor(DIndex,ChnID,ThemType,R0,R10,R25,blnBrdTemp,SubNetID,DevID,AdjustValue) values({0},{1},{2},{3},{4},{5},{6},{7},{8},{9})", DIndex, bytChnID, ch.bytTheType, ch.bytRValue[0] * 256 + ch.bytRValue[1], ch.bytRValue[2] * 256 + ch.bytRValue[3], ch.bytRValue[4] * 256 + ch.bytRValue[5], ch.blnBroadTemp, ch.bytSubID, ch.bytDevID, ch.byAdjustVal); } else { str = string.Format("update dbTempSensor set ThemType={0},R0={1},R10={2},R25={3},blnBrdTemp={4},SubNetID={5},DevID{6},AdjustValue={7} where DIndex={8} and and ChnID ={9}", ch.bytTheType, ch.bytRValue[0] * 256 + ch.bytRValue[1], ch.bytRValue[2] * 256 + ch.bytRValue[3], ch.bytRValue[4] * 256 + ch.bytRValue[5], ch.blnBroadTemp, ch.bytSubID, ch.bytDevID, ch.byAdjustVal, DIndex, bytChnID); } DataModule.ExecuteSQLDatabase(str); bytChnID++; } }
private void btnDelAll_Click(object sender, EventArgs e) { if (tvEdit.SelectedNode == null) { return; } TreeNode oTmp = tvEdit.SelectedNode; if (oTmp.Level != 0) { return; } if (oTmp.Level == 0) // 如果是设备 而且本身没有任何红外码 可以直接移除并移除其全部子节点 { string strsql = string.Format("Delete from tblRemoteDevice where ID = {0}", oTmp.Name); DataModule.ExecuteSQLDatabase(strsql); //更新表格 string strInsert = string.Format("Delete from tblRemoteCode where RemoteDeviceID = {0}", oTmp.Name); DataModule.ExecuteSQLDatabase(strInsert); oTmp.Remove(); } }
private void btnRestore_Click(object sender, EventArgs e) { // open file string strFileName = HDLPF.OpenFileDialog("mdb files (*.mdb)|*.mdb", "IR Database"); if (strFileName == null) { return; } string strPrj = "select * from tblRemoteDevice order by ID"; List <int> ArayID = new List <int>(); OleDbCommand cmd = new OleDbCommand(); //创建一个OleDbConnection对象 #region OleDbConnection conn = null; conn = new OleDbConnection(DataModule.ConString + strFileName); try { //cmd属性赋值 cmd.Connection = conn; cmd.CommandText = strPrj; if (conn.State == ConnectionState.Closed) { conn.Open(); } OleDbDataReader reader = cmd.ExecuteReader(CommandBehavior.CloseConnection); #region if (reader != null) { while (reader.Read()) { string strRemark = reader.GetString(1); string strsql = string.Format("select * from tblRemoteDevice where Remark= '{0}'", strRemark); if (DataModule.IsExitstInDatabase(strsql) == false) { ArayID.Add(reader.GetInt16(0)); strsql = string.Format("Insert into tblRemoteDevice(ID,Remark) values({0},'{1}')", reader.GetInt16(0), strRemark); DataModule.ExecuteSQLDatabase(strsql); } } } #endregion } catch (Exception) { conn.Close(); } finally { conn.Close(); } #endregion #region for (int intI = 0; intI < ArayID.Count; intI++) { strPrj = "select * from tblRemoteCode where RemoteDeviceID=" + ArayID[intI] + " order by ID"; try { //cmd属性赋值 cmd.Connection = conn; cmd.CommandText = strPrj; if (conn.State == ConnectionState.Closed) { conn.Open(); } OleDbDataReader reader = cmd.ExecuteReader(CommandBehavior.CloseConnection); #region if (reader != null) { while (reader.Read()) { string strSql = string.Format("insert into tblRemoteCode(ID,RemoteDeviceID,Remark,Code,QtyPack) values ({0},{1},'{2}','{3}',{4})", reader.GetInt16(0), reader.GetInt16(1), reader.GetString(2), reader.GetString(3), reader.GetInt16(4)); DataModule.ExecuteSQLDatabase(strSql); } } #endregion } catch (Exception) { conn.Close(); } finally { conn.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 }
///<summary> ///保存数据库面板设置,将所有数据保存 ///</summary> public void saveHaiInfoToDB(int DIndex) { /// delete all old information and refresh the database string strsql = string.Format("delete from dbKeyTargets where DIndex={0}", DIndex); DataModule.ExecuteSQLDatabase(strsql); ///save save basic setup of HAI #region if (units != null && units.Count != 0) { foreach (Unit oTmp in units) { if (oTmp.oUnit != null) { UVCMD.ControlTargets TmpCmds = oTmp.oUnit; 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, 1, oTmp.bytID, TmpCmds.Type, TmpCmds.SubnetID, TmpCmds.DeviceID, TmpCmds.Param1, TmpCmds.Param2, TmpCmds.Param3, TmpCmds.Param4, 0); DataModule.ExecuteSQLDatabase(strsql); } } } #endregion //save infomation of Hai Scene #region if (scen != null && scen.Count != 0) { foreach (Scene oTmp in scen) { if (oTmp.oUnit != null) { UVCMD.ControlTargets TmpCmds = oTmp.oUnit; strsql = string.Format("Insert into dbKeyTargets(DIndex,KeyIndex,objID,KeyFunType,SubNetID,DeviceID,FirstParameter," + "SecondParameter,RunTimeMinute,RunTimeSecond,Ms04State,StrTip) values ({0},{1},'{2}',{3},{4},{5},{6},{7},{8},{9},{10})", DIndex, 2, oTmp.bytID, TmpCmds.Type, TmpCmds.SubnetID, TmpCmds.DeviceID, TmpCmds.Param1, TmpCmds.Param2, TmpCmds.Param3, TmpCmds.Param4, 0); DataModule.ExecuteSQLDatabase(strsql); } } } #endregion //save infomation of Hai ButtonStatus #region if (buttonstatus != null && buttonstatus.Count != 0) { foreach (ButtonStatus oTmp in buttonstatus) { if (oTmp.oUnit != null) { UVCMD.ControlTargets TmpCmds = oTmp.oUnit; 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, 3, oTmp.bytID, TmpCmds.Type, TmpCmds.SubnetID, TmpCmds.DeviceID, TmpCmds.Param1, TmpCmds.Param2, TmpCmds.Param3, TmpCmds.Param4, 0); DataModule.ExecuteSQLDatabase(strsql); } } } #endregion }
//<summary> //保存数据 //</summary> public void SaveDataToDB() { try { string strsql = string.Format("delete * from dbClassInfomation where DIndex={0}", DIndex); DataModule.ExecuteSQLDatabase(strsql); strsql = string.Format("delete * from dbKeyTargets where DIndex={0}", DIndex); DataModule.ExecuteSQLDatabase(strsql); #region string strRemarkBasic = ""; string strParamBasic = Backlight.ToString() + "-" + Ledlight.ToString(); if (arayButtonColor == null) { arayButtonColor = new byte[0]; } if (arayButtonBalance == null) { arayButtonBalance = new byte[0]; } if (arayButtonSensitiVity == null) { arayButtonSensitiVity = new byte[0]; } if (arayHotel == null) { arayHotel = new byte[13]; } strsql = @"Insert into dbClassInfomation(DIndex,ClassID,ObjectID,SenNum,Remark,strParam1,byteAry1,byteAry2,byteAry3,byteAry4)" + " values(@DIndex,@ClassID,@ObjectID,@SenNum,@Remark,@strParam1,@byteAry1,@byteAry2,@byteAry3,@byteAry4)"; //创建一个OleDbConnection对象 OleDbConnection connBasic; connBasic = new OleDbConnection(DataModule.ConString + CsConst.mstrDefaultPath); //OleDbConnection conn = new OleDbConnection(DataModule.ConString + CsConst.mstrCurPath); connBasic.Open(); OleDbCommand cmdBaic = new OleDbCommand(strsql, connBasic); ((OleDbParameter)cmdBaic.Parameters.Add("@DIndex", OleDbType.Integer)).Value = DIndex; ((OleDbParameter)cmdBaic.Parameters.Add("@ClassID", OleDbType.Integer)).Value = 0; ((OleDbParameter)cmdBaic.Parameters.Add("@ObjectID", OleDbType.Integer)).Value = 0; ((OleDbParameter)cmdBaic.Parameters.Add("@SenNum", OleDbType.Integer)).Value = 0; ((OleDbParameter)cmdBaic.Parameters.Add("@Remark", OleDbType.VarChar)).Value = strRemarkBasic; ((OleDbParameter)cmdBaic.Parameters.Add("@strParam1", OleDbType.VarChar)).Value = strParamBasic; ((OleDbParameter)cmdBaic.Parameters.Add("@byteAry1", OleDbType.Binary)).Value = arayButtonColor; ((OleDbParameter)cmdBaic.Parameters.Add("@byteAry2", OleDbType.Binary)).Value = arayButtonBalance; ((OleDbParameter)cmdBaic.Parameters.Add("@byteAry3", OleDbType.Binary)).Value = arayButtonSensitiVity; ((OleDbParameter)cmdBaic.Parameters.Add("@byteAry4", OleDbType.Binary)).Value = arayHotel; try { cmdBaic.ExecuteNonQuery(); } catch { connBasic.Close(); } connBasic.Close(); #endregion #region if (myKeySetting != null) { for (int i = 0; i < myKeySetting.Count; i++) { string strRemark = myKeySetting[i].Remark; string strParam = myKeySetting[i].ID.ToString() + "-" + myKeySetting[i].Mode.ToString() + "-" + myKeySetting[i].Delay.ToString(); strsql = string.Format("Insert into dbClassInfomation(DIndex,ClassID,ObjectID,SenNum,Remark,strParam1) values ({0},{1},{2},{3},'{4}','{5}')", DIndex, 1, 0, i, strRemark, strParam); DataModule.ExecuteSQLDatabase(strsql); if (myKeySetting[i].KeyTargets != null) { for (int intK = 0; intK < myKeySetting[i].KeyTargets.Count; intK++) { UVCMD.ControlTargets TmpCmds = myKeySetting[i].KeyTargets[intK]; ///// insert into all commands to database 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, myKeySetting[i].ID, TmpCmds.ID, TmpCmds.Type, TmpCmds.SubnetID, TmpCmds.DeviceID, TmpCmds.Param1, TmpCmds.Param2, TmpCmds.Param3, TmpCmds.Param4, 0); DataModule.ExecuteSQLDatabase(strsql); } } } } #endregion } catch { } }
//<summary> //保存数据库面板设置,将所有数据保存 //</summary> public void SaveSecurityToDB() { //// delete all old information and refresh the database string strsql = string.Format("delete * from dbLogic where DIndex={0}", DIndex); DataModule.ExecuteSQLDatabase(strsql); strsql = string.Format("delete * from dbLogicTable where DIndex={0}", DIndex); DataModule.ExecuteSQLDatabase(strsql); strsql = string.Format("delete * from dbKeyTargets where DIndex={0}", DIndex); DataModule.ExecuteSQLDatabase(strsql); //保存基本经纬度信息 #region strsql = @"Insert into dbLogic(DIndex,LogicPos,LogicSummerTime,DateTimeAry,isBroadcastTime) " + "values(@DIndex,@LogicPos,@LogicSummerTime,@DateTimeAry,@isBroadcastTime)"; //创建一个OleDbConnection对象 OleDbConnection conn; if (CsConst.mstrCurPath != null) { conn = new OleDbConnection(DataModule.ConString + CsConst.mstrCurPath); } else { conn = new OleDbConnection(DataModule.ConString + CsConst.mstrDefaultPath); } conn.Open(); OleDbCommand cmd = new OleDbCommand(strsql, conn); ((OleDbParameter)cmd.Parameters.Add("@DIndex", OleDbType.Integer)).Value = DIndex; ((OleDbParameter)cmd.Parameters.Add("@LogicPos", OleDbType.Binary)).Value = LogicPos; ((OleDbParameter)cmd.Parameters.Add("@LogicSummerTime", OleDbType.Binary)).Value = LogicSummerTime; ((OleDbParameter)cmd.Parameters.Add("@DateTimeAry", OleDbType.Binary)).Value = DateTimeAry; ((OleDbParameter)cmd.Parameters.Add("@isBroadcastTime", OleDbType.Boolean)).Value = isBroadcastTime; try { cmd.ExecuteNonQuery(); } catch (OleDbException exp) { MessageBox.Show(exp.ToString()); conn.Close(); } conn.Close(); #endregion for (int intI = 1; intI <= 12; intI++) { if (MyDesign[intI - 1] != null && MyDesign[intI - 1].TableIDs != null && MyDesign[intI - 1].MyPins != null && MyDesign[intI - 1].MyPins.Count == 0) { //保存基本信息 #region strsql = @"Insert into dbLogicTable(DIndex,TableID,Remark,TableIDs,MyPins1,MyPins2,MyPins3,MyPins4,MyPins5,MyPins6,MyPins7,MyPins8,MyPins9,MyPins10," + "MyPins11,MyPins12,MyPins13,MyPins14,MyPins15,MyPins16,MyPins17,MyPins18,MyPins19,MyPins20)" + " values(@DIndex,@TableID,@Remark,@TableIDs,@MyPins1,@MyPins2,@MyPins3,@MyPins4,@MyPins5,@MyPins6,@MyPins7,@MyPins8,@MyPins9,@MyPins10," + "@MyPins11,@MyPins12,@MyPins13,@MyPins14,@MyPins15,@MyPins16,@MyPins17,@MyPins18,@MyPins19,@MyPins20)"; //创建一个OleDbConnection对象 if (CsConst.mstrCurPath != null) { conn = new OleDbConnection(DataModule.ConString + CsConst.mstrCurPath); } else { conn = new OleDbConnection(DataModule.ConString + CsConst.mstrDefaultPath); } conn.Open(); cmd = new OleDbCommand(strsql, conn); ((OleDbParameter)cmd.Parameters.Add("@DIndex", OleDbType.Integer)).Value = DIndex; ((OleDbParameter)cmd.Parameters.Add("@TableID", OleDbType.Integer)).Value = intI; ((OleDbParameter)cmd.Parameters.Add("@Remark", OleDbType.VarChar)).Value = MyDesign[intI - 1].Remark; ((OleDbParameter)cmd.Parameters.Add("@TableIDs", OleDbType.Binary)).Value = MyDesign[intI - 1].TableIDs; //((OleDbParameter)cmd.Parameters.Add("@Hints", OleDbType.ch)).Value = MyDesign[intI - 1].Remarks; if (MyDesign[intI - 1].MyPins.Count >= 20) { for (byte bytI = 0; bytI < 20; bytI++) { ((OleDbParameter)cmd.Parameters.Add("@MyPins" + (bytI + 1).ToString(), OleDbType.Binary)).Value = MyDesign[intI - 1].MyPins[bytI]; } } if (MyDesign[intI - 1].MyPins.Count < 20) { byte[] Tmp = new byte[] { 0 }; for (int i = MyDesign[intI - 1].MyPins.Count; i < 20; i++) { ((OleDbParameter)cmd.Parameters.Add("@MyPins" + (i + 1).ToString(), OleDbType.Binary)).Value = Tmp; } } try { cmd.ExecuteNonQuery(); } catch { //MessageBox.Show(exp.ToString()); conn.Close(); } conn.Close(); #endregion //保存目标设置 #region if (MyDesign[intI - 1].ArmCmds != null && MyDesign[intI - 1].ArmCmds.Length != 0) { for (int intJ = 0; intJ < MyDesign[intI - 1].ArmCmds.Length; intJ++) // b表ID { if (MyDesign[intI - 1].ArmCmds[intJ] != null && MyDesign[intI - 1].ArmCmds[intJ].Count != 0) { foreach (UVCMD.ControlTargets TmpCmds in MyDesign[intI - 1].ArmCmds[intJ]) { ///// insert into all commands to database strsql = string.Format("Insert into dbKeyTargets(DIndex,KeyIndex,objID,KeyFunType,SubNetID,DeviceID,FirstParameter," + "SecondParameter,RunTimeMinute,RunTimeSecond,Ms04State,StrTip) values ({0},{1},{2},{3},{4},{5},{6},{7},{8},{9},{10},'{11}')", DIndex, intI, TmpCmds.ID, TmpCmds.Type, TmpCmds.SubnetID, TmpCmds.DeviceID, TmpCmds.Param1, TmpCmds.Param2, TmpCmds.Param3, TmpCmds.Param4, intJ + 1, TmpCmds.Hint); DataModule.ExecuteSQLDatabase(strsql); } } } } #endregion } } }