コード例 #1
0
        public static List <AlramInfoModel> SelectAlramInfo()
        {
            List <AlramInfoModel> alramInfoModelList = new List <AlramInfoModel>();

            using (SQLiteConnection conn = new SQLiteConnection(connStr))
            {
                try
                {
                    conn.Open();
                    string sql = "SELECT * FROM AlramInfo";

                    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)
                    {
                        AlramInfoModel alramInfoModel = new AlramInfoModel();
                        alramInfoModel.id         = Convert.ToInt32(item["id"]);
                        alramInfoModel.DeviceInfo = (int)item["DeviceInfo"];
                        alramInfoModel.ErrorCode  = (int)item["ErrorCode"];
                        alramInfoModel.ErrorDes   = (string)item["ErrorDes"];
                        alramInfoModel.HasHandle  = (Boolean)item["HasHandle"];
                        alramInfoModel.CreateDate = (string)item["CreateDate"];
                        alramInfoModel.CreateTime = (string)item["CreateTime"];

                        alramInfoModelList.Add(alramInfoModel);
                    }
                }
                catch (Exception ex)
                {
                    LogUtil.LogError(ex);
                }
                finally
                {
                    conn.Close();
                    conn.Dispose();
                }
            }

            return(alramInfoModelList);
        }
コード例 #2
0
        public static void InsertAlramInfo(AlramInfoModel alramInfoModel)
        {
            using (SQLiteConnection conn = new SQLiteConnection(connStr))
            {
                try
                {
                    conn.Open();
                    string sql = "SELECT * FROM AlramInfo";

                    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 AlramInfo(DeviceInfo,ErrorCode,ErrorDes,HasHandle,CreateDate,CreateTime) " +
                          "VALUES(@DeviceInfo,@ErrorCode,@ErrorDes,@HasHandle,@CreateDate,@CreateTime)";

                    object[] paramList = alramInfoModel.GetObjectList();

                    SQLiteHelper.ExecuteNonQuery(conn, sql, paramList);
                }
                catch (Exception ex)
                {
                    LogUtil.LogError(ex);
                }
                finally
                {
                    conn.Close();
                    conn.Dispose();
                }
            }
        }