public static List <HisDataBaseModel> SelectHisData() { List <HisDataBaseModel> hisDataBaseModelList = new List <HisDataBaseModel>(); using (SQLiteConnection conn = new SQLiteConnection(connStr)) { try { conn.Open(); string sql = "SELECT * FROM HisDataBase"; SQLiteDataAdapter ap = new SQLiteDataAdapter(sql, conn); DataSet ds = new DataSet(); ap.Fill(ds); ap.Dispose(); DataTable dt = ds.Tables[0]; foreach (DataRow item in dt.Rows) { HisDataBaseModel hisDataBaseModel = new HisDataBaseModel(); hisDataBaseModel.id = Convert.ToInt32(item["id"]); hisDataBaseModel.Humidity = (double)item["Humidity"]; hisDataBaseModel.PH = (double)item["PH"]; hisDataBaseModel.RunNum = (int)item["RunNum"]; hisDataBaseModel.Temperature = (double)item["Temperature"]; hisDataBaseModel.Turbidity = (double)item["Turbidity"]; hisDataBaseModel.Uv254 = (double)item["Uv254"]; hisDataBaseModel.AirTemperature = (double)item["AirTemperature"]; hisDataBaseModel.Bod = (double)item["Bod"]; hisDataBaseModel.BodElePot = (double)item["BodElePot"]; hisDataBaseModel.BodElePotDrop = (double)item["BodElePotDrop"]; hisDataBaseModel.Cod = (double)item["Cod"]; hisDataBaseModel.CreateDate = (string)item["CreateDate"]; hisDataBaseModel.CreateTime = (string)item["CreateTime"]; hisDataBaseModel.DO = (double)item["DO"]; hisDataBaseModelList.Add(hisDataBaseModel); } } catch (Exception ex) { LogUtil.LogError(ex); } finally { conn.Close(); conn.Dispose(); } } return(hisDataBaseModelList); }
public static void InsertHisBodData(HisDataBaseModel hisDatabasesModel) { using (SQLiteConnection conn = new SQLiteConnection(connStr)) { try { conn.Open(); string sql = "SELECT * FROM HisDataBase"; SQLiteDataAdapter ap = new SQLiteDataAdapter(sql, conn); DataSet ds = new DataSet(); ap.Fill(ds); ap.Dispose(); DataTable dt = ds.Tables[0]; DataRow dataRow = dt.NewRow(); dt.Rows.Add(dataRow); sql = "INSERT INTO HisDataBase(PH,DO,Temperature,Turbidity,Uv254,AirTemperature,Humidity,RunNum,Cod,Bod,BodElePot,BodElePotDrop,CreateDate,CreateTime) " + "VALUES(@PH,@DO,@Temperature,@Turbidity,@Uv254,@AirTemperature,@Humidity,@RunNum,@Cod,@Bod,@BodElePot,@BodElePotDrop,@CreateDate,@CreateTime)"; object[] paramList = hisDatabasesModel.GetObjectList(); SQLiteHelper.ExecuteNonQuery(conn, sql, paramList); } catch (Exception ex) { LogUtil.LogError(ex); } finally { conn.Close(); conn.Dispose(); } } }