1数据库创建:
RAGMA foreign_keys = false;
-- ----------------------------
-- Table structure for OrderSIndex
-- ----------------------------
DROP TABLE IF EXISTS "OrderSIndex";
CREATE TABLE "OrderSIndex" (
"Id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
"OrderName" nvarchar(40),
"OrderIndexInSigle" integer,
"IndexType" integer,
"CreateDate" datetime,
"Updated" datetime,
"ThisSigle" nvarchar(20)
);
-- ----------------------------
-- Auto increment value for OrderSIndex
-- ----------------------------
UPDATE "sqlite_sequence" SET seq = 4 WHERE name = 'OrderSIndex';
PRAGMA foreign_keys = true;
Model数据:
/// <summary>
///
/// </summary>
public class OrderSIndex
{
/// <summary>
///
/// </summary>
[Description("")]
public int Id { get; set; }
/// <summary>
///
/// </summary>
[Description("")]
public string OrderName { get; set; }
/// <summary>
///
/// </summary>
[Description("")]
public int OrderIndexInSigle { get; set; }
/// <summary>
///
/// </summary>
[Description("")]
public int IndexType { get; set; }
/// <summary>
///
/// </summary>
[Description("")]
public DateTime CreateDate { get; set; }
/// <summary>
///
/// </summary>
[Description("")]
public DateTime Updated { get; set; }
/// <summary>
///
/// </summary>
[Description("")]
public string ThisSigle { get; set; }
}
DAL操作文章来源:https://www.toymoban.com/news/detail-691757.html
public class DALOrderSIndex
{
/// <summary>
///获取当前 0月累计,1日累计,2年累计,3,总共累计
/// </summary>
/// <param name="SetNoType"> 0月累计,1日累计,2年累计,3,总共累计</param>
/// <param name="SetKeyword">当前关键字(需要的表单名子)</param>
/// <param name="OutIndexLength">index编号长度 0001 就是4 </param>
/// <returns></returns>
public string OutIndexStr(string SetKeyword, int SetNoType = 0, int OutIndexLength = 5)
{
string ThisSigle;
switch (SetNoType)
{
case 0:
ThisSigle = $"{DateTime.Now.Year}{DateTime.Now.ToString("MM")}";
break;
case 1:
ThisSigle = DateTime.Now.ToString("yyyyMMdd");
break;
case 2:
ThisSigle = DateTime.Now.Year.ToString();
break;
default://3
ThisSigle = string.Empty;//数据空
break;
}
string OutStr;
string sqlQurey = $"select * from OrderSIndex where OrderName = '{SetKeyword}' and ThisSigle = '{ThisSigle}'";
string SqlInsert = $"insert into OrderSIndex (OrderName,OrderIndexInSigle,IndexType,CreateDate,Updated,ThisSigle) values('{SetKeyword}',1,{SetNoType},datetime('now','localtime'),datetime('now','localtime'),'{ThisSigle}')";
string SqlUpdate = $"Update OrderSIndex set OrderIndexInSigle=OrderIndexInSigle +1 where OrderName = '{SetKeyword}' and ThisSigle = '{ThisSigle}' ";
using (IDbConnection Conn = new DALDBBase().GetOpenConn())
{
IEnumerable<OrderSIndex> list = Conn.Query<OrderSIndex>(sqlQurey);
if (list == null || list.Count() == 0)
{
Conn.Execute(SqlInsert);
OutStr = $"{ThisSigle}{1.ToString().PadLeft(OutIndexLength, '0')}";
}
else
{
Conn.Execute(SqlUpdate);
OrderSIndex oneModel = list.FirstOrDefault();
OutStr = $"{ThisSigle}{(oneModel.OrderIndexInSigle + 1).ToString().PadLeft(OutIndexLength, '0')}";
}
}
return OutStr;
}
}
使用方法:文章来源地址https://www.toymoban.com/news/detail-691757.html
string innn = new DAL.DALOrderSIndex().OutIndexStr("功能表数据",3,2);
到了这里,关于关于计数以及Index返回订单号升级版可以控制年月日累计(不重复)(sqlite)的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!