示例#1
0
        private void synToClient()
        {
            List <SynModel> items = this.getDownloadCommands("SELECT * FROM queues");

            if (items == null)
            {
                return;
            }

            foreach (SynModel model in items)
            {
                int row = SQLiteHelper.ExecuteNonQuery(masterConnString, CommandType.Text,
                                                       model.Command);

                String sql =
                    String.Format(
                        "INSERT INTO commands_results(command, result, created_at) VALUES('{0}', '{1}', '{2}')",
                        model.Command.Replace("'", "\\\'"), "成功条数:" + row, TimeStamp.GetNowTimeStamp());

                Tools.MySqlHelper.ExecuteNonQuery(Tools.MySqlHelper.ConnectionStringLocalTransaction, CommandType.Text, sql);
                if (row > 0)
                {
                    Console.WriteLine("MySQL执行:" + String.Format("DELETE FROM queues WHERE id = {0}", model.Id));
                    Tools.MySqlHelper.ExecuteNonQuery(Tools.MySqlHelper.ConnectionStringLocalTransaction, CommandType.Text,
                                                      String.Format("DELETE FROM queues WHERE id = {0}", model.Id));
                    refresh();
                }
            }
        }
示例#2
0
        /// <summary>
        /// 显示刷卡信息
        /// </summary>
        /// <param name="card">会员卡实体</param>
        /// <param name="status">其它信息</param>
        /// <param name="color">字体颜色</param>
        public void ChangeText(Models.MemberCard card, String status, System.Drawing.Color color)
        {
            if (card == null)
            {
                return;
            }

            String balance = "未找到";
            String expire  = "未找到";

            if (card.Record != null)
            {
                expire  = TimeStamp.ConvertIntDateTime(card.Record.ExpiredAt).ToString("yyyy-MM-dd");
                balance = card.Record == null ? "0" : card.Record.Balance.ToString();

                if (card.Record.Status == Status.Disabled)
                {
                    expire = "已收回";
                }
                else if (card.Record.ExpiredAt < TimeStamp.GetNowTimeStamp())
                {
                    balance = "此卡已过期";
                }
            }
            this.labCategory.Text    = String.Format("会员类别:{0}", card.Category == null ? "未找到" : card.Category.Name);
            this.labCardNo.Text      = String.Format("会员卡号:{0}", card == null ? "未找到" : card.CardNo);
            this.labCardNum.Text     = String.Format("剩余次数:{0}", balance);
            this.labExpire.Text      = String.Format("到期时间:{0}", expire);
            this.labStatus.Text      = String.Format("{0}", status);
            this.labStatus.ForeColor = color;
            changeLoction();
        }
 /// <summary>
 /// 向数据库插入一刀数据
 /// </summary>
 /// <param name="uid">出刀者UID</param>
 /// <param name="guildInfo">公会信息</param>
 /// <param name="dmg">伤害</param>
 /// <param name="attackType">出刀类型</param>
 /// <returns>
 /// <para>本次出刀刀号</para>
 /// <para><see langword="-1"/> 数据库错误</para>
 /// </returns>
 public int NewAttack(long uid, GuildInfo guildInfo, long dmg, AttackType attackType)
 {
     try
     {
         using var dbClient = SugarUtils.CreateSqlSugarClient(DBPath);
         //插入一刀数据
         var insertData = new GuildBattle()
         {
             Uid    = uid,
             Time   = TimeStamp.GetNowTimeStamp(),
             Order  = guildInfo.Order,
             Round  = guildInfo.Round,
             Damage = dmg,
             Attack = attackType
         };
         return(dbClient.Insertable(insertData)
                .AS(BattleTableName)
                .ExecuteReturnIdentity());
     }
     catch (Exception e)
     {
         Log.Error("Database error", Log.ErrorLogBuilder(e));
         return(-1);
     }
 }
 /// <summary>
 /// 设置成员SL
 /// 同时自动下树
 /// 如果只清空则不会修改状态
 /// </summary>
 /// <param name="uid">成员UID</param>
 /// <param name="cleanSL">是否清空SL</param>
 /// <returns>
 /// <para><see langword="true"/> 写入成功</para>
 /// <para><see langword="false"/> 数据库错误</para>
 /// </returns>
 public bool SetMemberSL(long uid, bool cleanSL = false)
 {
     try
     {
         using var dbClient = SugarUtils.CreateSqlSugarClient(DBPath);
         if (cleanSL) //清空SL
         {
             return(dbClient
                    .Updateable <MemberInfo>()
                    .SetColumns(i => new MemberInfo
             {
                 SL = 0
             })
                    .Where(i => i.Gid == GuildEventArgs.SourceGroup.Id && i.Uid == uid)
                    .ExecuteCommandHasChange());
         }
         else //设置新的SL
         {
             return(dbClient
                    .Updateable <MemberInfo>()
                    .SetColumns(i => new MemberInfo
             {
                 Flag = FlagType.IDLE, SL = TimeStamp.GetNowTimeStamp(),
                 Time = TimeStamp.GetNowTimeStamp(), Info = null
             })
                    .Where(i => i.Gid == GuildEventArgs.SourceGroup.Id && i.Uid == uid)
                    .ExecuteCommandHasChange());
         }
     }
     catch (Exception e)
     {
         Log.Error("Database error", Log.ErrorLogBuilder(e));
         return(false);
     }
 }
        /// <summary>
        /// 刷新心跳包记录
        /// </summary>
        /// <param name="connectionGuid">连接标识</param>
        internal static void HeartBeatUpdate(Guid connectionGuid)
        {
            int connectionIndex = ConnectionList.FindIndex(conn => conn.ConnectionGuid == connectionGuid);

            if (connectionIndex == -1)
            {
                return;
            }
            var connection = ConnectionList[connectionIndex];

            connection.LastHeartBeatTime    = TimeStamp.GetNowTimeStamp();
            ConnectionList[connectionIndex] = connection;
        }
示例#6
0
        public static NetResult GetAccessToken(String appId, String appSecret)
        {
            Soft   soft = null;
            String url  = String.Format("{0}{1}.json", domain, GetUrl);

            String time = TimeStamp.GetNowTimeStamp().ToString();

            System.String nonce = Encryption.MD5(time);

            IDictionary <String, String> param = new Dictionary <String, String>();

            param.Add("app_id", appId);
            param.Add("nonce", nonce);
            param.Add("timestamp", time);
            param.Add("signature", Encryption.MD5(String.Format("{0}{1}{2}&key={3}", appId, nonce, time, appSecret)));

            String       json   = null;
            Stream       stream = null;
            StreamReader reader = null;

            try
            {
                HttpWebResponse response = HttpWebResponseUtility.CreatePostHttpResponse(url, param, 30000, "WinFormFeiyu", Encoding.UTF8, null);

                stream = response.GetResponseStream();
                reader = new StreamReader(stream);
                json   = reader.ReadToEnd();
                reader.Close();
                stream.Close();
            }
            catch (System.Net.WebException e)
            {
                MessageBox.Show(e.Message, "获取Token时发生异常", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(null);
            }
            finally
            {
                reader?.Close();
                stream?.Close();
            }

            if (String.IsNullOrEmpty(json))
            {
                return(null);
            }
            NetResult result = JsonHelper.DeserializeJsonToObject <NetResult>(json);

            return(result);
        }
示例#7
0
        private void loadINI()
        {
            IniFile iniFile = new IniFile(String.Format("{0}/application.cache", Application.StartupPath));
            String  expired = iniFile.IniReadValue("AccessToken", "expired");

            if (String.IsNullOrEmpty(expired) ||
                Convert.ToInt64(expired) < TimeStamp.GetNowTimeStamp())
            {
                String[] token = GetAccessToken(AppID, AppSecret);
                if (token == null)
                {
                    return;
                }
                iniFile.IniWriteValue("AccessToken", "token", token[0]);
                iniFile.IniWriteValue("AccessToken", "expired", token[1]);
            }
        }
 /// <summary>
 /// 添加一名成员
 /// </summary>
 /// <param name="uid">成员QQ号</param>
 /// <param name="groupid">成员所在群号</param>
 /// <param name="name">成员昵称</param>
 /// <returns>状态值
 /// <para><see langword="0"/> 正常添加</para>
 /// <para><see langword="1"/> 该成员已存在,更新信息</para>
 /// <para><see langword="-1"/> 数据库出错/API错误</para>
 /// </returns>
 public int JoinGuild(long uid, long groupid, string name)
 {
     try
     {
         //读取数据库
         using SqlSugarClient dbClient = SugarUtils.CreateSqlSugarClient(DBPath);
         //已存在成员则更新
         if (dbClient.Queryable <MemberInfo>().Any(i => i.Uid == uid && i.Gid == groupid))
         {
             var data = new MemberInfo()
             {
                 Uid  = uid,
                 Gid  = groupid,
                 Name = name
             };
             return(dbClient.Updateable(data)
                    .Where(i => i.Uid == uid && i.Gid == groupid)
                    .ExecuteCommandHasChange()
                 ? 1
                 : -1);
         }
         //加入成员并写入成员信息
         else
         {
             var memberStatus = new MemberInfo
             {
                 Flag = FlagType.IDLE,
                 Gid  = groupid,
                 Info = null,
                 SL   = 0,
                 Time = TimeStamp.GetNowTimeStamp(),
                 Uid  = uid,
                 Name = name
             };
             //成员信息
             return(dbClient.Insertable(memberStatus).ExecuteCommand() > 0 ? 0 : -1);
         }
     }
     catch (Exception e)
     {
         Log.Error("Database", Log.ErrorLogBuilder(e));
         return(-1);
     }
 }
        /// <summary>
        /// 心跳包超时检查
        /// </summary>
        internal void HeartBeatCheck(object msg)
        {
            if (ConnectionList.Count == 0)
            {
                return;
            }
            ConsoleLog.Debug("HeartBeatCheck", $"Connection count={ConnectionList.Count}");
            List <Guid> lostConnections = new List <Guid>();

            //锁定列表
            lock (ConnectionList)
            {
                //遍历超时的连接
                foreach (var connection in ConnectionList
                         .Where(connection => TimeStamp.GetNowTimeStamp() - connection.LastHeartBeatTime > Config.HeartBeatTimeOut))
                {
                    try
                    {
                        //添加需要删除的连接
                        lostConnections.Add(connection.ConnectionGuid);

                        //关闭超时的连接
                        connection.Connection.Close();
                        ConsoleLog.Error("Sora",
                                         $"与Onebot客户端[{connection.Connection.ConnectionInfo.ClientIpAddress}:{connection.Connection.ConnectionInfo.ClientPort}]失去链接(心跳包超时)");
                        HeartBeatTimeOutEvent(connection.SelfId, connection.Connection.ConnectionInfo);
                    }
                    catch (Exception e)
                    {
                        ConsoleLog.Error("Sora", "检查心跳包时发生错误 code -2");
                        ConsoleLog.Error("Sora", ConsoleLog.ErrorLogBuilder(e));
                        //添加需要删除的连接
                        lostConnections.Add(connection.ConnectionGuid);
                    }
                }
            }
            //删除超时的连接
            foreach (var lostConnection in lostConnections
                     .Where(lostConnection => !RemoveConnection(lostConnection)))
            {
                ConsoleLog.Error("Sora", $"检查心跳包时发生错误 code -1, 连接[{lostConnection}]无法被关闭");
            }
        }
示例#10
0
        private void btnSubmit_Click(object sender, System.EventArgs e)
        {
            if (String.IsNullOrEmpty(this.txtMoney.Text.Trim()))
            {
                MessageBox.Show("请先选择充值次数及金额!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            else if (this.card.Record == null || this.card.Record.Status == Status.Disabled)
            {
                this.card.Record = new MemberCardRecord();
                this.card.Record.MemberCardId = this.card.Id;
                this.card.Record.CreatedAt    = TimeStamp.GetNowTimeStamp();
            }

            MemberCardCategoryValue cat = this.cmbMoney.SelectedItem as MemberCardCategoryValue;

            this.card.Record.Balance  += cat.ValueNum;
            this.card.Record.BeginAt   = TimeStamp.ConvertDateTimeInt(DateTime.Now.Date);
            this.card.Record.ExpiredAt = TimeStamp.ConvertDateTimeInt(this.validTime.Value.Date.AddHours(23));

            if (this.card.Record.Id > 0 ? recordBll.EditMemberCardRecord(this.card.Record) : recordBll.AddMemberCardRecord(this.card.Record))
            {
                SaleLog log = new SaleLog();
                log.CreatedAt = TimeStamp.ConvertDateTimeInt(DateTime.Now);
                log.MemberId  = this.card.Id;
                log.MemberNo  = this.card.CardNo;
                log.GoodsId   = cat.GoodsId;
                log.Money     = Convert.ToDecimal(this.txtMoney.Text.Trim());
                log.Summary   = String.Format("卡号:{0}在{1}充值{2}元", this.card.CardNo, DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss"), cat.Money);
                saleBll.AddLog(log);
                Callback(log.Summary);
                this.labMoney.Text = String.Format("帐户剩余次数:{0}次", this.card.Record.Balance.ToString());
            }

            this.btnSubmit.Enabled = false;
            this.validTime.Visible = false;
            this.labTip.Visible    = false;
            this.card = null;
            this.cmbMoney.DataSource = null;
            this.txtMoney.Clear();
            MessageBox.Show("充值成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }
示例#11
0
        /// <summary>
        /// 添加交易记录
        /// </summary>
        private void AddRecord()
        {
            if (card.Record.Balance <= 0)
            {
                this.setLabelStatus("此卡次数不足,请充值后再试!", Color.Red, "AudioCardArrearage");
                return;
            }

            this.btnSearch.Enabled = false;
            this.btnSubmit.Enabled = false;
            this.numValue.Enabled  = false;

            Decimal num = this.numValue.Value;

            for (int i = 0; i < num; i++)
            {
                SaleLog log = new SaleLog();
                log.CreatedAt = TimeStamp.GetNowTimeStamp();
                log.Money     = 0;
                log.GoodsId   = Convert.ToInt32(ConfigurationManager.AppSettings["RecordGoodsID"]);
                log.MemberNo  = this.card.CardNo;
                log.Summary   = String.Format("卡号:{0}({1})在{2}进行了一笔消费", this.labNo.Text.Trim(), this.labType.Text.Trim(), DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
                logBll.AddLog(log);
            }

            this.AddRecordToDataGridView(String.Format("卡号:{0}({1})在{2}进行了{3}笔消费", this.labNo.Text.Trim(), this.labType.Text.Trim(), DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), Convert.ToInt32(num)));
            this.card.Record.Balance -= num;
            recordBll.EditMemberCardRecord(this.card.Record);

            this.btnSearch.Enabled = true;
            this.btnSubmit.Enabled = true;
            this.numValue.Enabled  = true;
            this.numValue.Maximum  = this.card.Record.Balance;
            this.numValue.Value    = this.numValue.Value > this.numValue.Maximum ? this.numValue.Maximum : this.numValue.Value;

            if (!this.timer.Enabled)
            {
                this.timer.Interval = 1000 * 20;
                this.timer.Start();
            }
        }
示例#12
0
        private void findCard(String no)
        {
            this.card = cardBll.GetMemberCardByNo(no);
            if (this.card != null)
            {
                this.card.Record   = recordBll.GetMemberCardRecordByMemberCardId(this.card.Id);
                this.card.Category = catBll.GetMemberCardCategoryById(this.card.CategoryId);
            }


            String msg = null;

            if (this.card == null)
            {
                msg = "此卡不存在!";
            }

            if (!String.IsNullOrEmpty(msg))
            {
                MessageBox.Show(msg, "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            if (this.card.Record == null || this.card.Record.Status == Status.Disabled)
            {
                DialogResult result = MessageBox.Show("此卡未开户,是否开卡?", "温馨提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                if (result == DialogResult.No)
                {
                    return;
                }

                this.card.Record = new MemberCardRecord();
                this.card.Record.MemberCardId = this.card.Id;
                this.card.Record.CreatedAt    = TimeStamp.GetNowTimeStamp();
            }

            this.labMemberCardCategory.Text = this.card.Category.Name;
            this.labMoney.Text     = String.Format("帐户剩余次数:{0}次", Convert.ToInt32(this.card.Record.Balance));
            this.btnSubmit.Enabled = true;
        }
示例#13
0
        private void btnSubmit_Click(object sender, System.EventArgs e)
        {
            String msg = null;

            if (String.IsNullOrEmpty(this.txtFee.Text.Trim()))
            {
                msg = "请填写销售金额!";
            }
            else if (Convert.ToDecimal(this.txtFee.Text.Trim()) < 1)
            {
                msg = "销售金额必须大于0元!";
            }

            if (!String.IsNullOrEmpty(msg))
            {
                MessageBox.Show(msg, "保存失败", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            SaleLog log = new SaleLog();

            log.CreatedAt = TimeStamp.GetNowTimeStamp();
            log.Money     = Convert.ToDecimal(this.txtFee.Text.Trim());
            log.GoodsId   = this.goods.Id;
            log.MemberNo  = "";
            log.Summary   = String.Format("{0}出售了{1}元的{2}",
                                          DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
                                          this.txtFee.Text.Trim(),
                                          this.goods.Name);

            ISaleLogBLL logBll = BllFactory.GetSaleLogBll();

            if (!logBll.AddLog(log))
            {
                MessageBox.Show("商品销售记录失败!", "保存失败", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            callback(log.Summary);
            this.Close();
        }
 /// <summary>
 /// 更新成员状态
 /// </summary>
 /// <param name="uid">成员UID</param>
 /// <param name="newFlag">新的状态</param>
 /// <param name="newInfo">新的消息</param>
 /// <returns>
 /// <para><see langword="true"/> 写入成功</para>
 /// <para><see langword="false"/> 数据库错误</para>
 /// </returns>
 public bool UpdateMemberStatus(long uid, FlagType newFlag, string newInfo)
 {
     try
     {
         using var dbClient = SugarUtils.CreateSqlSugarClient(DBPath);
         //更新成员信息
         return(dbClient.Updateable <MemberInfo>()
                .SetColumns(i => new MemberInfo()
         {
             Flag = newFlag,
             Info = newInfo,
             Time = TimeStamp.GetNowTimeStamp(),
         })
                .Where(i => i.Gid == GuildEventArgs.SourceGroup.Id && i.Uid == uid)
                .ExecuteCommandHasChange());
     }
     catch (Exception e)
     {
         Log.Error("Database error", Log.ErrorLogBuilder(e));
         return(false);
     }
 }
示例#15
0
 /// <summary>
 /// 添加服务器连接记录
 /// </summary>
 /// <param name="connectionGuid">连接标识</param>
 /// <param name="connectionInfo">连接信息</param>
 /// <param name="selfId">机器人UID</param>
 private bool AddConnection(Guid connectionGuid, IWebSocketConnection connectionInfo, string selfId)
 {
     //锁定记录表
     lock (ConnectionList)
     {
         //检查是否已存在值
         if (ConnectionList.All(connection => connection.ConnectionGuid != connectionGuid))
         {
             long.TryParse(selfId, out long uid);
             ConnectionList.Add(new SoraConnectionInfo
             {
                 ConnectionGuid    = connectionGuid,
                 Connection        = connectionInfo,
                 LastHeartBeatTime = TimeStamp.GetNowTimeStamp(),
                 SelfId            = uid
             });
             return(true);
         }
         else
         {
             return(false);
         }
     }
 }
示例#16
0
        public List <ReportGoodsRank> GetStatisticsTodayGoodsSale()
        {
            long   beginAt = TimeStamp.ConvertDateTimeInt(DateTime.Now.Date);
            String sql     = String.Format("SELECT g.name, SUM(s.money) AS money, COUNT(*) AS count FROM sales_records AS s LEFT JOIN goods AS g ON g.id = s.goods_id WHERE s.created_at BETWEEN {0} AND {1} GROUP BY g.id ORDER BY g.sort DESC;", beginAt, TimeStamp.GetNowTimeStamp());

            return(dal.GetStatisticsBySql(sql));
        }
示例#17
0
        /// <summary>
        /// 查找会员卡信息
        /// </summary>
        /// <param name="no"></param>
        private void FindMemberCard(String no)
        {
            this.initUI();

            String audioKey = null;
            String msg      = "";


            this.card = cardBll.GetMemberCardByNo(no);
            if (this.card != null)
            {
                this.card.Category = catBll.GetMemberCardCategoryById(this.card.CategoryId);
                this.card.Record   = recordBll.GetMemberCardRecordByMemberCardId(this.card.Id);
                this.fullCardInfo();
            }


            //判断会员卡是否存在
            if (card == null)
            {
                msg      = "此卡不存在!";
                audioKey = "AudioCardNotFound";
            }
            else if (card.Record == null)
            {
                msg      = "此卡未开启!";
                audioKey = "AudioCardNotAvailable";
            }
            else if (card.Record.Status == Status.Disabled)
            {
                msg      = "此卡已回收,请重新开卡后使用!";
                audioKey = "AudioCardStatusInvalid";
            }
            else if (card.Record.Balance <= 0)
            {
                msg      = "此卡次数不足,请充值后再试!";
                audioKey = "AudioCardArrearage";
            }
            else if (card.Record.ExpiredAt < TimeStamp.GetNowTimeStamp())
            {
                msg      = "此卡已过期!";
                audioKey = "AudioCardExpired";
            }
            else if (!card.Category.isDateAllow() || !card.Category.isTimeAllow())
            {
                msg      = "此卡不在可用时间段!";
                audioKey = "AudioCardTimeInvalid";
            }

            if (!String.IsNullOrEmpty(msg))
            {
                this.setLabelStatus(msg, Color.Red, audioKey);
                return;
            }

            this.setLabelStatus("此卡可以使用", Color.Green);
            this.numValue.Enabled  = true;
            this.btnSubmit.Enabled = true;
            this.numValue.Maximum  = card.Record.Balance;

            if (!this.ckbAuto.Checked)
            {
                return;
            }

            this.AddRecord();
        }