123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109 |
- using CP.Dapper;
- using CP.Model;
- using MC.ORM;
- using MySql.Data.MySqlClient;
- using System;
- using System.Collections.Generic;
- using System.Configuration;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace CP.Business
- {
- public class ZtArticleBll : BaseBll
- {
-
-
-
-
- public static void testadd(List<ZtArticle> datas)
- {
- using (Database db = new Database(mysql, MySqlClientFactory.Instance))
- {
- try
- {
- db.BeginTransaction();
- for (var i = 0; i < datas.Count; i++)
- {
- db.Insert("Zt_Article", "Id", false, datas[i]);
- Console.WriteLine($"{i}");
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- db.CompleteTransaction();
- }
- catch (Exception ex)
- {
- db.AbortTransaction();
- throw ex;
- }
- }
- }
- public static Page<ZtArticle> GetPager(ZtArticle entity, int pageSize, int pageIndex)
- {
- var dc = new DataConnect();
- string where = "";
- if(entity.Cid>0)
- where = $" where cid={entity.Cid} ";
- if (entity.TagId > 0)
- {
- if (where.Contains("where"))
- {
- where += $" and TagId={entity.TagId} ";
- }
- else {
- where = $"where TagId={entity.TagId} ";
- }
- }
- string sql = $@"select Id,Title,Cid,TagId,ShortDetail,Addtime from ZT_Article
- {where} order by id desc";
- var datas = dc.db.Page<ZtArticle>(pageIndex, pageSize, new Sql(sql));
- return datas;
- ; }
- }
-
-
-
- public class ZtArticleTest : DbHelper
- {
- public ZtArticleTest()
- {
- }
- public void TestAdd()
- {
- base.db = new MsSqlDatabase(ConfigurationManager.ConnectionStrings["ZhuanTiSqlService"].ToString());
-
-
-
- var list = new List<ZtArticle>();
- if (list != null && list.Count > 0)
- {
- ZtArticleBll.testadd(list);
- }
- }
- }
- }
|