• 关于计数以及Index返回订单号升级版可以控制年月日累计(不重复)(sqlite)


    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;
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22

    Model数据:

     /// 
        /// 
        /// 
        public class OrderSIndex
        {
    
            /// 
            /// 
            ///  
            [Description("")]
            public int Id { get; set; }
            /// 
            /// 
            ///  
            [Description("")]
            public string OrderName { get; set; }
            /// 
            /// 
            ///  
            [Description("")]
            public int OrderIndexInSigle { get; set; }
            /// 
            /// 
            ///  
            [Description("")]
            public int IndexType { get; set; }
            /// 
            /// 
            ///  
            [Description("")]
            public DateTime CreateDate { get; set; }
            /// 
            /// 
            ///  
            [Description("")]
            public DateTime Updated { get; set; }
            /// 
            /// 
            ///  
            [Description("")]
            public string ThisSigle { get; set; }
        }
    
    • 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

    DAL操作

     public  class DALOrderSIndex
        {
            /// 
            ///获取当前 0月累计,1日累计,2年累计,3,总共累计
            /// 
            ///  0月累计,1日累计,2年累计,3,总共累计
            /// 当前关键字(需要的表单名子)
            /// index编号长度 0001 就是4 
            /// 
            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; 
            }
    
        }
    
    • 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

    使用方法:

     string  innn =  new DAL.DALOrderSIndex().OutIndexStr("功能表数据",3,2);
    
    • 1
  • 相关阅读:
    Spring MVC 十一:@EnableWebMvc
    第3章_瑞萨MCU零基础入门系列教程之开发环境搭建与体验
    阿里云郑大禹:云上应用构建的三大挑战与解决之道
    糖友吃什么有助于控制血糖
    C++ 课堂实验 编写一个能计算银行存款的小程序。
    LQ0190 李白打酒【填空题】
    LeetCode(力扣)17. 电话号码的字母组合Python
    数据分析之人力资源管理驾驶舱
    Unity资源加密解决方案
    Go :验证编译器是否强制执行了复制参数要求(附完整源码)
  • 原文地址:https://blog.csdn.net/weixin_40029679/article/details/132641069