Ejemplo n.º 1
0
        /// <summary>
        ///  批量删除
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="t"></param>
        /// <returns></returns>
        public bool Delete <T>(List <int> idList)
        {
            List <CommandInfo> commandInfos = new List <CommandInfo>();

            if (idList == null || idList.Count <= 0)
            {
                return(false);
            }
            CommandInfo commandInfo = null;
            SqlModel    deleteModel = null;

            string whereStr = "";

            Type type = typeof(T);

            PrimaryKeyAttribute primaryKeyAttribute = type.GetPrimaryKey();

            for (int i = 0; i < idList.Count; i++)
            {
                whereStr = string.Format("{0}='{1}'", primaryKeyAttribute.ColumnName, idList[i]);

                deleteModel = CreateSqlHelper.DeleteSqlByWhere <T>(whereStr);

                commandInfo = new CommandInfo()
                {
                    CommendText = deleteModel.Sql,
                    IsProcess   = false,
                    Params      = deleteModel.SqlParameters
                };
                commandInfos.Add(commandInfo);
            }
            return(SQLiteHelper.ExecuteTrans(commandInfos));
        }
Ejemplo n.º 2
0
        /// <summary>
        ///  分页查询
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <typeparam name="whereCols">查询条件</typeparam>
        /// <param name="t"></param>
        /// <returns></returns>
        public PageInfo <T> SelectPage <T>(PageInfo <T> pageInfo, string cols, string whereCols, WhereType whereType)
        {
            SqlModel selectModel = CreateSqlHelper.SelectSqlByPage(pageInfo, cols, whereCols, whereType);

            DataTable dataTable = SQLiteHelper.ExecuteDataTable(selectModel.Sql, false, selectModel.SqlParameters);

            List <T> lists = DbConvert.TableToList <T>(dataTable);


            SqlModel selectCountModel = CreateSqlHelper.SelectCount(pageInfo.ParamsSearch, whereCols, whereType);

            object result = SQLiteHelper.ExecuteScalar(selectCountModel.Sql, false, selectCountModel.SqlParameters);

            int total     = Convert.ToInt32(result);
            int totalPage = 0;

            if (total % pageInfo.PageSize == 0)
            {
                totalPage = total / pageInfo.PageSize;
            }
            else
            {
                totalPage = total / pageInfo.PageSize + 1;
            }

            pageInfo.TotalPage    = totalPage;
            pageInfo.Records      = lists;
            pageInfo.CurrentCount = total;
            //lists.Count;

            return(pageInfo);
        }
Ejemplo n.º 3
0
        /// <summary>
        ///  批量修改
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="t"></param>
        /// <param name="cols">选择性修改的字段</param>
        /// <param name="whereCols">修改的条件 可以是字段也可是  字段 逗号隔开的字段</param>
        /// <returns></returns>
        public bool UpdateBatch <T>(List <T> list, string cols, string whereStr, WhereType whereType)
        {
            List <CommandInfo> commandInfos = new List <CommandInfo>();

            if (list == null || list.Count <= 0)
            {
                return(false);
            }
            CommandInfo commandInfo = null;
            SqlModel    updateModel = null;

            for (int i = 0; i < list.Count; i++)
            {
                updateModel = CreateSqlHelper.UpdateSql(list[i], cols, whereStr, whereType);

                commandInfo = new CommandInfo()
                {
                    CommendText = updateModel.Sql,
                    IsProcess   = false,
                    Params      = updateModel.SqlParameters
                };
                commandInfos.Add(commandInfo);
            }
            return(SQLiteHelper.ExecuteTrans(commandInfos));
        }
Ejemplo n.º 4
0
        /// <summary>
        ///  批量新增
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="t"></param>
        /// <param name="cols">选择性插入的字段</param>
        /// <returns></returns>
        public bool InsertBatch <T>(List <T> list, string cols, bool needReturn)
        {
            List <CommandInfo> commandInfos = new List <CommandInfo>();

            if (list == null || list.Count <= 0)
            {
                return(false);
            }
            CommandInfo commandInfo = null;
            SqlModel    insertModel = null;

            for (int i = 0; i < list.Count; i++)
            {
                insertModel = CreateSqlHelper.InsertSql(list[i], cols, needReturn);

                commandInfo = new CommandInfo()
                {
                    CommendText = insertModel.Sql,
                    IsProcess   = false,
                    Params      = insertModel.SqlParameters
                };
                commandInfos.Add(commandInfo);
            }
            return(SQLiteHelper.ExecuteTrans(commandInfos));
        }
Ejemplo n.º 5
0
        /// <summary>
        ///  查询
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <typeparam name="whereCols">查询条件</typeparam>
        /// <param name="t"></param>
        /// <returns></returns>
        public List <T> SelectPage <T>(T t, string cols, string whereCols, WhereType whereType)
        {
            SqlModel insertModel = CreateSqlHelper.SelectSql(t, cols, whereCols, whereType);

            DataTable dataTable = SQLiteHelper.ExecuteDataTable(insertModel.Sql, false, insertModel.SqlParameters);

            List <T> lists = DbConvert.TableToList <T>(dataTable);

            return(lists);
        }
Ejemplo n.º 6
0
        /// <summary>
        ///  修改
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="t"></param>
        /// <param name="cols">选择性修改的字段</param>
        /// <param name="whereCols">修改的条件 可以是字段也可是  字段 逗号隔开的字段</param>
        /// <returns></returns>
        public int Update <T>(T t, string cols, string whereCols, WhereType whereType, bool needReturn)
        {
            if (t == null)
            {
                return(0);
            }

            SqlModel updateModel = CreateSqlHelper.UpdateSql(t, cols, whereCols, whereType);

            return(SQLiteHelper.ExecuteNonQuery(updateModel.Sql, needReturn, updateModel.SqlParameters));
        }
Ejemplo n.º 7
0
        /// <summary>
        ///  删除
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="t"></param>
        /// <param name="logDel">是否逻辑删除</param>
        /// <returns></returns>
        public int Delete <T>(T t, bool logDel, string cols)
        {
            if (t == null)
            {
                return(0);
            }
            SqlModel deleteModel = null;

            if (!logDel)
            {
                deleteModel = CreateSqlHelper.DeleteSql(t, cols);
            }
            else
            {
                //待完善
                //deleteModel = CreateSqlHelper.UpdateSql(t, cols);
            }
            return(SQLiteHelper.ExecuteNonQuery(deleteModel.Sql, false, deleteModel.SqlParameters));
        }
Ejemplo n.º 8
0
        public bool RecordPrescriptionInputHistory(PrescriptionInputHistoryDto inputHistory)
        {
            return(DapperHelper.SQLLiteSession <bool>((conn, trans) =>
            {
                POSQuerySqlHelper posSql = new POSQuerySqlHelper(new SqlCommonQuery {
                    OrganSign = CacheInfo.Drugstore.OrganSign, Yn = 1
                });
                string sql = posSql.Sql_PrescriptionInputHistory();
                PrescriptionInputHistoryDto currentInputHistory = conn.Query <PrescriptionInputHistoryDto>(sql).FirstOrDefault();

                if (currentInputHistory != null)
                {
                    string updateSql = CreateSqlHelper.GetUpdateSqlByModel(typeof(PrescriptionInputHistoryDto), CacheService.GetInstance().TableNames[typeof(PrescriptionInputHistoryDto)]);
                    updateSql = updateSql + $" WHERE OrganSign = '{ inputHistory.OrganSign }'";

                    return conn.Execute(updateSql, inputHistory, trans) > 0 ? true : false;
                }

                string intsertSql = CreateSqlHelper.GetInsertSqlByModel(typeof(PrescriptionInputHistoryDto), CacheService.GetInstance().TableNames[typeof(PrescriptionInputHistoryDto)]);
                return conn.Execute(intsertSql, inputHistory, trans) > 0 ? true : false;
            }));
        }
Ejemplo n.º 9
0
        /// <summary>
        ///  新增
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="cols">选择性插入的字段</param>
        /// <param name="t"></param>
        /// <returns></returns>
        public int Insert <T>(T t, string cols, bool needReturn)
        {
            if (t == null)
            {
                return(0);
            }

            SqlModel insertModel = CreateSqlHelper.InsertSql(t, cols, needReturn);

            if (!needReturn)
            {
                return(SQLiteHelper.ExecuteNonQuery(insertModel.Sql, needReturn, insertModel.SqlParameters));
            }

            object resultObj = SQLiteHelper.ExecuteScalar(insertModel.Sql, false, insertModel.SqlParameters);

            if (resultObj != null && resultObj.ToString() != "")
            {
                return(Convert.ToInt32(resultObj));
            }
            return(0);
        }