Пример #1
0
        public static List <MaintainInfoModel> SelectMaintainInfo()
        {
            List <MaintainInfoModel> maintainInfoModelList = new List <MaintainInfoModel>();

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

                    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)
                    {
                        MaintainInfoModel maintainInfoModel = new MaintainInfoModel();
                        maintainInfoModel.id         = Convert.ToInt32(item["id"]);
                        maintainInfoModel.Name       = (string)item["Name"];
                        maintainInfoModel.AlramId    = (string)item["AlramId"];
                        maintainInfoModel.Info       = (string)item["Info"];
                        maintainInfoModel.CreateDate = (string)item["CreateDate"];
                        maintainInfoModel.CreateTime = (string)item["CreateTime"];

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

            return(maintainInfoModelList);
        }
Пример #2
0
        public static void InsertMaintainInfo(MaintainInfoModel maintainInfoModel)
        {
            using (SQLiteConnection conn = new SQLiteConnection(connStr))
            {
                try
                {
                    conn.Open();

                    string sql = "SELECT * FROM MaintainInfo";

                    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 MaintainInfo(Name,AlramId,Info,CreateDate,CreateTime) " +
                          "VALUES(@Name,@AlramId,@Info,@CreateDate,@CreateTime)";

                    object[] paramList = maintainInfoModel.GetObjectList();

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