管道基础大数据平台系统开发-【CS】-ExportMap
13693261870
2024-09-03 3cfb6aa02516135fb174ab1b30620f2007924663
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
using JiangSu.Models;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SQLite;
using System.Linq;
using System.Reflection;
using System.Web;
 
namespace JiangSu.cs
{
    public class ModelDAL
    {
        public static List<Model> SelectByPage(string name, int pageSize = 10, int pageIndex = 1)
        {
            bool flag = string.IsNullOrWhiteSpace(name);
            string sql = string.Format("select * from model {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<Model> list = ModelHandler.FillModel<Model>(dt);
 
            return list;
        }
 
        public static Model SelectById(long id)
        {
            string sql = "select * from model where id = @id";
 
            SQLiteParameter param = new SQLiteParameter("@id");
            param.Value = id;
 
            DataTable dt = SQLiteHelper.GetDataTable(sql, param);
            if (null == dt || dt.Rows.Count == 0)
            {
                return null;
            }
 
            List<Model> list = ModelHandler.FillModel<Model>(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 model where id in ({0})", str);
 
            return SQLiteHelper.ExecuteNonQuery(sql);
        }
 
        public static int DelAll()
        {
            return SQLiteHelper.ExecuteNonQuery("delete from model");
        }
 
        public static int Insert(Model model)
        {
            string sql = "insert into model (name, json) values (@name, @json); select last_insert_rowid();";
            SQLiteParameter[] sqlParams = Tools.GetSQLiteParams<Model>(sql, model);
 
            //return SQLiteHelper.ExecuteNonQuery(sql, sqlParams);
 
            object obj = SQLiteHelper.ExecuteScalar(sql, sqlParams);
 
            return null == obj ? 0 : Convert.ToInt32(obj);
        }
 
        public static int UpdateById(Model model)
        {
            string sql = "update model set name = @name, json = @json where id = @id";
            SQLiteParameter[] sqlParams = Tools.GetSQLiteParams<Model>(sql, model);
 
            return SQLiteHelper.ExecuteNonQuery(sql, sqlParams);
        }
    }
}