コード例 #1
0
        /// <summary>
        /// 当超过65536行后不能导出(可能是excel版本问题,暂时采用分sheet解决)--benjamin20191216
        /// </summary>
        /// <param name="y"></param>
        /// <param name="newY"></param>
        /// <param name="sheet"></param>
        private void GetSheetByY(int y, out int newY, out Worksheet newSheet)
        {
            int pageSize = 60000;

            if (y < pageSize)
            {
                newY     = y;
                newSheet = sheet;
                return;
            }
            else
            {
                //10
                //0~9:0
                //10~19:1

                //page从0开始的
                //var page = Math.Ceiling(Convert.ToDecimal(y) / Convert.ToDecimal(pageSize));
                var page = PFDataHelper.ObjectToInt(Math.Floor(Convert.ToDecimal(y) / Convert.ToDecimal(pageSize))) ?? 0;
                //var page=int.Parse(Math.Ceiling(y / pageSize).ToString())+1;
                if (page >= sheets.Count)
                {
                    //count=2,page=4, 2~4
                    for (var i = sheets.Count; i <= page; i++)
                    {
                        sheets.Add(workbook.Worksheets.Add("sheet" + (i + 1).ToString()));
                    }
                }
                newY     = y % pageSize;
                newSheet = sheets[page];
            }
        }
コード例 #2
0
        /// <summary>
        /// 适用场境,在测试库时,更新完数据后,验证数据是否有异常
        ///
        /// 常用方法:
        ///var update = new SqlUpdateCollection(new
        ///{
        ///    id = id,
        ///    agentno = agentno
        ///})
        ///.PrimaryKeyFields("id");
        ///PFSqlUpdateValidateHelper.TestUpdate("t_hyzl_orders", update, sqlExec);
        ///
        /// </summary>
        /// <param name="tableName"></param>
        /// <param name="update"></param>
        /// <param name="sql"></param>
        public static void TestUpdate(string tableName, SqlUpdateCollection update, ProcManager sql)
        {
            string updateSqlString = string.Format(@" select * from {0} {1}
                ", tableName, update.ToWhereSql());
            string totalSqlString  = string.Format(@" select count(*) from {0}
                ", tableName);

            //用set条件的字段做where来查总数,如果行数等于全表行数,那说明把整个表的值都更新了(where没有生效)
            var updateSet = new SqlWhereCollection();

            foreach (var i in update)
            {
                updateSet.Add(i.Key, i.Value.Value);
            }
            string updateSetTotalSqlString = string.Format(@" select count(*) from {0} {1}
                ", tableName, updateSet.ToSql());

            var updated  = sql.GetQueryTable(updateSqlString);
            var total    = PFDataHelper.ObjectToInt(sql.QuerySingleValue(totalSqlString));
            var setTotal = PFDataHelper.ObjectToInt(sql.QuerySingleValue(updateSetTotalSqlString));

            if (updated == null)
            {
                throw new Exception("更新后的数据全部丢失.异常");
            }
            if (total < 2)
            {
                throw new Exception("测试数据少于2条,这样不保险");
            }
            if (total == updated.Rows.Count)
            {
                throw new Exception("更新了整个表的数据,请确认是否缺少where条件.异常");
            }
            if (total == setTotal)
            {
                throw new Exception("更新了整个表的数据,请确认是否缺少where条件.异常");
            }
            AssertIsTrue(updated != null && updated.Rows.Count == 1);
            AssertIsTrue(total > 1);
            AssertIsTrue(IsDataRowMatchUpdate(updated.Rows[0], update));
            AssertIsTrue(setTotal >= updated.Rows.Count && setTotal < total);
        }