Esempio n. 1
0
        internal int CreateComDayRandom(int comid, DateTime searchdate, int num = 3)
        {
            string now_str = searchdate.ToString("yyyy-MM-dd");

            sqlHelper.BeginTrancation();
            try
            {
                for (int i = 0; i < 24; i++)
                {//循环24次每小时产生一个随机码
                    string date_temp = searchdate.AddHours(i).ToString("yyyy-MM-dd HH:mm:ss");

                    string nowdayrandom_selsql = "select * from b2b_company_nowdayrandom where nowdate='" + date_temp + "' and comid=" + comid;
                    var    cmd = sqlHelper.PrepareTextSqlCommand(nowdayrandom_selsql);

                    B2b_company_nowdayrandom t = null;
                    using (var reader = cmd.ExecuteReader())
                    {
                        if (reader.Read())
                        {
                            t = new B2b_company_nowdayrandom()
                            {
                                id          = reader.GetValue <int>("id"),
                                comid       = reader.GetValue <int>("comid"),
                                createposid = reader.GetValue <string>("createposid"),
                                createtime  = reader.GetValue <DateTime>("createtime"),
                                nowdate     = reader.GetValue <DateTime>("nowdate"),
                                randomstr   = reader.GetValue <string>("randomstr"),
                                remark      = reader.GetValue <string>("remark"),
                            };
                        }
                    }

                    if (t == null)
                    {
                        string dayrandom           = CommonFunc.RandCode(num);
                        string nowdayrandom_inssql = "INSERT INTO  [b2b_company_nowdayrandom] ([comid] ,[randomstr]  ,[nowdate] ,[createtime] ,[createposid] ,[remark])VALUES(" + comid + "  ,'" + dayrandom + "' ,'" + date_temp + "' ,'" + DateTime.Now + "','999999999','')";
                        cmd = sqlHelper.PrepareTextSqlCommand(nowdayrandom_inssql);
                        cmd.ExecuteNonQuery();
                    }
                }

                sqlHelper.Commit();
                sqlHelper.Dispose();
                return(1);
            }
            catch
            {
                sqlHelper.Rollback();
                sqlHelper.Dispose();
                return(0);
            }
        }
Esempio n. 2
0
        internal string GetComDayRandomstr(int comid, string posid, int num = 3)
        {
            string dayrandom = CommonFunc.RandCode(num);
            string now_str   = DateTime.Now.ToString("yyyy-MM-dd hh") + ":00:00";

            sqlHelper.BeginTrancation();
            try
            {
                string nowdayrandom_selsql = "select * from b2b_company_nowdayrandom where nowdate='" + now_str + "' and comid=" + comid;
                var    cmd = sqlHelper.PrepareTextSqlCommand(nowdayrandom_selsql);
                B2b_company_nowdayrandom t = null;
                using (var reader = cmd.ExecuteReader())
                {
                    if (reader.Read())
                    {
                        t = new B2b_company_nowdayrandom()
                        {
                            id          = reader.GetValue <int>("id"),
                            comid       = reader.GetValue <int>("comid"),
                            createposid = reader.GetValue <string>("createposid"),
                            createtime  = reader.GetValue <DateTime>("createtime"),
                            nowdate     = reader.GetValue <DateTime>("nowdate"),
                            randomstr   = reader.GetValue <string>("randomstr"),
                            remark      = reader.GetValue <string>("remark"),
                        };
                    }
                }

                if (t == null)
                {
                    string nowdayrandom_inssql = "INSERT INTO  [b2b_company_nowdayrandom] ([comid] ,[randomstr]  ,[nowdate] ,[createtime] ,[createposid] ,[remark])VALUES(" + comid + "  ,'" + dayrandom + "' ,'" + now_str + "' ,'" + DateTime.Now + "','" + posid + "','')";
                    cmd = sqlHelper.PrepareTextSqlCommand(nowdayrandom_inssql);
                    cmd.ExecuteNonQuery();
                }
                else
                {
                    dayrandom = t.randomstr;
                }

                sqlHelper.Commit();
                sqlHelper.Dispose();
                return(dayrandom);
            }
            catch
            {
                sqlHelper.Rollback();
                sqlHelper.Dispose();
                return("");
            }
        }