コード例 #1
0
        //<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++;
            }
        }
コード例 #2
0
ファイル: frmIRlearner.cs プロジェクト: Test0222/Test02
        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
        }