コード例 #1
0
        private bool Addnew(PresetDCVoltage vo)
        {
            using (OleDbConnection conn = CreateConnection())
            {
                OleDbTransaction trans = conn.BeginTransaction();
                try
                {
                    StringBuilder sql = new StringBuilder();
                    StringBuilder param = new StringBuilder();

                    sql.Append("INSERT INTO PresetDCVoltage (");
                    param.Append(" VALUES (");

                    sql.Append(" DCVoltagePreSet");
                    param.Append("").Append(Convert.ToInt32(vo.DCVoltagePreSet) * -1).Append("");
                    sql.Append(")").Append(param).Append(");");

                    OleDbCommand insertcmd = new OleDbCommand(sql.ToString(), conn);
                    insertcmd.ExecuteNonQuery();

                    entryDAL.Addnew(vo.Entries, conn, vo.ID);

                    trans.Commit();
                }
                catch (Exception e)
                {
                    trans.Rollback();
                    ResetConn();
                    throw e;
                }

            }
            ResetConn();
            return true;
        }
コード例 #2
0
 private bool LoadData(PresetDCVoltage vo)
 {
     using (OleDbConnection conn = CreateConnection())
     {
         string sql = "Select * from PresetDCVoltage ";
         if (vo.ID != -1)
         {
             sql += "where ID = " + vo.ID;
         }
         OleDbCommand myCommand = new OleDbCommand(sql, conn);
         OleDbDataReader reader = myCommand.ExecuteReader(); //执行command并得到相应的DataReader
         if (reader.Read())
         {
             fillVOData(vo, reader);
             entryDAL.QueryData(vo.Entries, conn, vo.ID);
             ResetConn();
         }
         else
         {
             ResetConn();
             return false;
         }
     }
     return true;
 }
コード例 #3
0
 private void fillVOData(PresetDCVoltage vo, OleDbDataReader reader)
 {
     vo.ID = (Int32)reader["ID"];
     vo.DCVoltagePreSet = Convert.ToBoolean(reader["RecTapStep"]);
 }
コード例 #4
0
 private bool UpdateOrAddnew(PresetDCVoltage vo)
 {
     if (!queryExists(vo))
     {
         return Addnew(vo);
     }
     else
     {
         return Update(vo);
     }
 }
コード例 #5
0
 private bool Update(PresetDCVoltage vo)
 {
     StringBuilder sql = new StringBuilder();//当时在这里定义,是为了在出现异常的时候看看我的SQL语句是否正确
     using (OleDbConnection conn = CreateConnection())
     {
         OleDbTransaction trans = conn.BeginTransaction();
         try
         {
             sql.Append("UPDATE PresetDCVoltage SET DCVoltagePreSet=").Append(Convert.ToInt32(vo.DCVoltagePreSet) * -1);
             sql.Append(" WHERE ID = ").Append(vo.ID);
             //定义command对象,并执行相应的SQL语句
             OleDbCommand myCommand = new OleDbCommand(sql.ToString(), conn);
             myCommand.ExecuteNonQuery(); //执行SELECT的时候我们是用的ExecuteReader()
             entryDAL.Update(vo.Entries, conn, vo.ID);
             trans.Commit();
         }
         catch (Exception e)
         {
             trans.Rollback();
             ResetConn();
             throw e;
         }
     }
     ResetConn();
     return true;
 }