using JiangSu.Models;
|
using Npgsql;
|
using System;
|
using System.Collections.Generic;
|
using System.Data;
|
using System.Data.Common;
|
using System.Data.SQLite;
|
using System.Linq;
|
using System.Web;
|
|
namespace JiangSu.cs
|
{
|
public class ImgDAL
|
{
|
public static List<Img> SelectByPage(string name, int pageSize = 10, int pageIndex = 1)
|
{
|
bool flag = string.IsNullOrWhiteSpace(name);
|
string sql = string.Format("select * from img {0} order by id limit {1} offset {2}", flag ? "" : "where upper(name) like @name", pageSize, pageSize * (pageIndex - 1));
|
|
DataTable dt = flag ? SQLiteHelper.GetDataTable(sql) :
|
SQLiteHelper.GetDataTable(sql, new SQLiteParameter("@name", "%" + name.Trim().ToUpper() + "%"));
|
if (null == dt || dt.Rows.Count == 0)
|
{
|
return null;
|
}
|
|
List<Img> list = ModelHandler.FillModel<Img>(dt);
|
|
return list;
|
}
|
|
public static Img SelectById(long id)
|
{
|
string sql = "select * from img where id = @id";
|
|
SQLiteParameter param = new SQLiteParameter("@id", id);
|
|
DataTable dt = SQLiteHelper.GetDataTable(sql, param);
|
if (null == dt || dt.Rows.Count == 0)
|
{
|
return null;
|
}
|
|
List<Img> list = ModelHandler.FillModel<Img>(dt);
|
|
return null == list || list.Count == 0 ? null : list[0];
|
}
|
|
public static int DeleteByIds(List<int> ids)
|
{
|
string str = string.Join(",", ids.ToArray());
|
string sql = string.Format("delete from img where id in ({0})", str);
|
|
return SQLiteHelper.ExecuteNonQuery(sql);
|
}
|
|
public static int DelAll()
|
{
|
return SQLiteHelper.ExecuteNonQuery("delete from img");
|
}
|
|
public static int Insert(Img img)
|
{
|
string sql = "insert into img (name, path, json, x, y, z) values (@name, @path, @json, @x, @y, @z); select last_insert_rowid();";
|
SQLiteParameter[] sqlParams = Tools.GetSQLiteParams<Img>(sql, img);
|
|
object obj = SQLiteHelper.ExecuteScalar(sql, sqlParams);
|
|
return null == obj ? 0 : Convert.ToInt32(obj);
|
}
|
|
public static int UpdateById(Img img)
|
{
|
string sql = "update img set name = @name, path = @path, json = @json, x = @x, y = @y, z = @z where id = @id";
|
SQLiteParameter[] sqlParams = Tools.GetSQLiteParams<Img>(sql, img);
|
|
return SQLiteHelper.ExecuteNonQuery(sql, sqlParams);
|
}
|
}
|
}
|