Ejemplo n.º 1
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void tmrUploadTimer_Tick(object sender, EventArgs e)
 {
     try
     {
         tmrUploadTimer_Tick();
     }
     catch (Exception ex)
     {
         LogThreadManager.WriteLog(Common.LogFile.Error, ex.StackTrace);
     }
 }
Ejemplo n.º 2
0
        /// <summary>
        /// 从sqlite数据库中提取要上传的数据,
        /// 上传前将每行状态标记为1,表示可以上传
        /// </summary>
        /// <returns></returns>
        public List <Card> FetchCardsForUpload()
        {
            List <Card> ret = new List <Card>();

            try
            {
                string CommandText = "";

                CommandText = String.Format("select count(*) from [cards] where flag = {0}", (int)CardStatus.ForUpload);
                object obj = this.SqliteHelper.ExecuteScalar(CommandType.Text, CommandText);
                if (obj != null && obj != DBNull.Value && Convert.ToInt32(obj) > 0)
                {
                    //log.InfoFormat("上次循环有{0}条上传失败!", obj);

                    LogThreadManager.WriteLog(Framework.Libs.Common.LogFile.Error, string.Format("上次循环有{0}条上传失败!", obj));
                }

                else
                {
                }
                CommandText = String.Format("update [cards]  set flag = {0} where flag = {1}", (int)CardStatus.ForUpload, (int)CardStatus.NewInsert); //falg=1 标记准备上传
                this.SqliteHelper.ExecuteNonQuery(CommandType.Text, CommandText);


                DataSet ds = null;
                CommandText = String.Format("select * from [cards] where flag = {0}", (int)CardStatus.ForUpload);
                ds          = this.SqliteHelper.ExecuteDataSet(CommandType.Text, CommandText);
                foreach (DataRow dr in ds.Tables[0].Rows)
                {
                    long kdt = Convert.ToInt64(dr["kdt"]);
                    long dt  = Convert.ToInt64(dr["dt"]);
                    ret.Add(new Card(kdt, dr["epc"] as String, dt));
                }
                ds.Clear();
                ds = null;
            }
            catch (Exception e)
            {
                //log.ErrorFormat("FetchCardsForUpload:{0}", e.ToString());
                LogThreadManager.WriteLog(Framework.Libs.Common.LogFile.Error, string.Format("FetchCardsForUpload:{0}", e.ToString()));
            }

            return(ret);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 扫描数据上传处理
        /// </summary>
        private void tmrUploadTimer_Tick()
        {
            try
            {
                timUploadTimer.Enabled = false;

                // 获取未上传卡数量
                this.lblWaitLoadCnt.Text = daoSqlLite.Instance.GetCardsCount().ToString();

                /// 从sqlite数据库中提取要上传的数据,
                /// 上传前将每行状态标记为1,表示可以上传
                List <Card> cards = daoSqlLite.Instance.FetchCardsForUpload();

                //"实现数据上传"
                for (int i = 0; i < cards.Count; i++)
                {
                    int overtime    = 0; //部品入库超时
                    int overtime_nh = 0; //部品南华送货超时

                    Card card = cards[i];

                    //#region 空箱出库处理

                    ////采集器功能类型区分
                    //if (Common._deviceFuncType == 0)
                    //{

                    //    //===================================================//
                    //    //===============空箱出库数据上传处理================//
                    //    //===================================================//
                    //    //获取部品配送超时时长
                    //    int k = this.m_busUploadScan.GetOverTime(card.EPC, ref overtime, ref overtime_nh);

                    //    DateTime dadatetime = new DateTime(card.Dt);
                    //    //获取部品配送超时时刻
                    //    DateTime dtovertime = workTimeCacl.GetExpiredDateTime(dadatetime, overtime);
                    //    //获取部品南华为集结超时时刻
                    //    DateTime dtovertime_nh = workTimeCacl.GetExpiredDateTime(dadatetime, overtime_nh);

                    //    //将采集信息保存到(空箱出库上传更新)
                    //    int ret = this.m_busUploadScan.UploadDaRecord(i, Common._terminalNo, card.EPC, dadatetime, dtovertime, dtovertime_nh);

                    //    if (ret >= 0)
                    //    {
                    //        //更新本地数据状态
                    //        if (!daoSqlLite.Instance.UpdateFlagAfterUploaded(card.Kdt, card.EPC))

                    //            LogThreadManager.WriteLog(Common.LogFile.Error, string.Format("(空箱出库)上传成功,但是本地标记为已上传失败,{0},{1}", card.Kdt, card.EPC));
                    //        if (ret >= 100)
                    //            //log.DebugFormat("(空箱出库)上传卡号成功!({0},{1},{2})", card.Kdt, card.EPC, dadatetime);
                    //            LogThreadManager.WriteLog(Common.LogFile.Error, string.Format("(空箱出库)上传卡号成功!({0},{1},{2})", card.Kdt, card.EPC, dadatetime));
                    //        if (ret > 10 && ret < 100)
                    //            //log.DebugFormat("(空箱出库)上传卡号报警!({0},{1},{2})[ret={3}]", card.Kdt, card.EPC, dadatetime, ret);
                    //            LogThreadManager.WriteLog(Common.LogFile.Error, string.Format("(空箱出库)上传卡号报警!({0},{1},{2})[ret={3}]", card.Kdt, card.EPC, dadatetime, ret));
                    //        if (ret == 0)
                    //            //log.ErrorFormat("(空箱出库)采集器无处理类型!({0},{1},{2})[采集器={3},ret={4}]", card.Kdt, card.EPC, dadatetime, Common._terminalNo, ret);
                    //            LogThreadManager.WriteLog(Common.LogFile.Error, string.Format("(空箱出库)采集器无处理类型!({0},{1},{2})[采集器={3},ret={4}]", card.Kdt, card.EPC, dadatetime, Common._terminalNo, ret));
                    //    }
                    //    else
                    //    {
                    //        //log.DebugFormat("(空箱出库)上传卡号失败!({0},{1},{2})[ret={3}]", card.Kdt, card.EPC, dadatetime, ret);
                    //        LogThreadManager.WriteLog(Common.LogFile.Error, string.Format("(空箱出库)上传卡号失败!({0},{1},{2})[ret={3}]", card.Kdt, card.EPC, dadatetime, ret));

                    //    }
                    //    if (k < 0)
                    //    {
                    //        //log.InfoFormat("(空箱出库)无法获得部品超时时间,存储过程返回代码:{0}", k);
                    //        LogThreadManager.WriteLog(Common.LogFile.Error, string.Format("(空箱出库)无法获得部品超时时间,存储过程返回代码:{0}", k));
                    //    }
                    //}

                    //#endregion

                    //#region 南华出库处理

                    //else if (Common._deviceFuncType == 1)
                    //{

                    //    //===================================================//
                    //    //===============南华出库数据上传处理================//
                    //    //===================================================//
                    //    //南华送货货使用时长
                    //    int k = this.m_busUploadScan.GetNHOverTime(card.EPC, ref overtime);

                    //    DateTime dadatetime = new DateTime(card.Dt);

                    //    //获取南华送货后到达工厂的时刻
                    //    DateTime dtovertime = workTimeCacl.GetExpiredDateTime(dadatetime, overtime);

                    //    //将采集信息保存到(南华出库上传更新)
                    //    int ret = this.m_busUploadScan.UploadDaRecord(i, Common._terminalNo, card.EPC, dadatetime, dtovertime, null);

                    //    if (ret >= 0)
                    //    {
                    //        //更新本地数据状态
                    //        if (!daoSqlLite.Instance.UpdateFlagAfterUploaded(card.Kdt, card.EPC))
                    //            //log.ErrorFormat("(空箱出库)上传成功,但是本地标记为已上传失败,{0},{1}", card.Kdt, card.EPC);
                    //            LogThreadManager.WriteLog(Common.LogFile.Error, string.Format("(空箱出库)上传成功,但是本地标记为已上传失败,{0},{1}", card.Kdt, card.EPC));

                    //        if (ret >= 100)
                    //            //log.DebugFormat("(南华出库)上传卡号成功!({0},{1},{2})", card.Kdt, card.EPC, dadatetime);
                    //            LogThreadManager.WriteLog(Common.LogFile.Error, string.Format("(南华出库)上传卡号成功!({0},{1},{2})", card.Kdt, card.EPC, dadatetime));
                    //        if (ret > 10 && ret < 100)
                    //            //log.DebugFormat("(南华出库)上传卡号报警!({0},{1},{2})[ret={3}]", card.Kdt, card.EPC, dadatetime, ret);
                    //            LogThreadManager.WriteLog(Common.LogFile.Error, string.Format("(南华出库)上传卡号报警!({0},{1},{2})[ret={3}]", card.Kdt, card.EPC, dadatetime, ret));
                    //        if (ret == 0)
                    //            //log.ErrorFormat("(南华出库)采集器无处理类型!({0},{1},{2})[采集器={3},ret={4}]", card.Kdt, card.EPC, dadatetime, Common._terminalNo, ret);
                    //            LogThreadManager.WriteLog(Common.LogFile.Error, string.Format("(南华出库)采集器无处理类型!({0},{1},{2})[采集器={3},ret={4}]", card.Kdt, card.EPC, dadatetime, Common._terminalNo, ret));
                    //    }
                    //    else
                    //    {
                    //        //log.DebugFormat("(南华出库)上传卡号失败!({0},{1},{2})[ret={3}]", card.Kdt, card.EPC, dadatetime, ret);
                    //        LogThreadManager.WriteLog(Common.LogFile.Error, string.Format("(南华出库)上传卡号失败!({0},{1},{2})[ret={3}]", card.Kdt, card.EPC, dadatetime, ret));

                    //    }
                    //    if (k < 0)
                    //    {
                    //        //log.InfoFormat("(南华出库)无法获得部品超时时间,存储过程返回代码:{0}", k);
                    //        LogThreadManager.WriteLog(Common.LogFile.Error, string.Format("(南华出库)无法获得部品超时时间,存储过程返回代码:{0}", k));

                    //    }
                    //}

                    //#endregion

                    //#region 工厂入库处理

                    //else if (Common._deviceFuncType == 2)
                    //{

                    //    //===================================================//
                    //    //===============工厂入库数据上传处理================//
                    //    //===================================================//

                    //    DateTime dadatetime = new DateTime(card.Dt);

                    //    int ret = this.m_busUploadScan.UploadDaRecord(i, Common._terminalNo, card.EPC, dadatetime, null, null);
                    //    if (ret >= 0)
                    //    {
                    //        if (!daoSqlLite.Instance.UpdateFlagAfterUploaded(card.Kdt, card.EPC))
                    //            //log.ErrorFormat("(工厂入库)上传成功,但是本地标记为已上传失败,{0},{1}", card.Kdt, card.EPC);
                    //            LogThreadManager.WriteLog(Common.LogFile.Error, string.Format("工厂入库)上传成功,但是本地标记为已上传失败,{0},{1}", card.Kdt, card.EPC));

                    //        if (ret >= 100)
                    //            //log.DebugFormat("(工厂入库)上传卡号成功!({0},{1},{2})", card.Kdt, card.EPC, dadatetime);
                    //            LogThreadManager.WriteLog(Common.LogFile.Error, string.Format("(工厂入库)上传卡号成功!({0},{1},{2})", card.Kdt, card.EPC, dadatetime));
                    //        if (ret > 10 && ret < 100)
                    //            //log.DebugFormat("(工厂入库)上传卡号报警!({0},{1},{2})[ret={3}]", card.Kdt, card.EPC, dadatetime, ret);
                    //            LogThreadManager.WriteLog(Common.LogFile.Error, string.Format("(工厂入库)上传卡号报警!({0},{1},{2})[ret={3}]", card.Kdt, card.EPC, dadatetime, ret));
                    //        if (ret == 0)
                    //            //log.ErrorFormat("(工厂入库)采集器无处理类型!({0},{1},{2})[采集器={3},ret={4}]", card.Kdt, card.EPC, dadatetime, Common._terminalNo, ret);
                    //            LogThreadManager.WriteLog(Common.LogFile.Error, string.Format("(工厂入库)采集器无处理类型!({0},{1},{2})[采集器={3},ret={4}]", card.Kdt, card.EPC, dadatetime, Common._terminalNo, ret));
                    //    }
                    //    else
                    //    {
                    //        //log.DebugFormat("(工厂入库)上传卡号失败!({0},{1},{2})[ret={3}]", card.Kdt, card.EPC, dadatetime, ret);
                    //        LogThreadManager.WriteLog(Common.LogFile.Error, string.Format("(工厂入库)上传卡号失败!({0},{1},{2})[ret={3}]", card.Kdt, card.EPC, dadatetime, ret));
                    //    }
                    //}
                    //else
                    //{
                    //    daoSqlLite.Instance.UpdateFlagAfterUploaded(card.Kdt, card.EPC);
                    //    //log.DebugFormat("上传卡号失败,未知的采集器功能!({0},{1},{2})[funcType={3}]", card.Kdt, card.EPC, this.AllCfg.deviceFuncType);
                    //    LogThreadManager.WriteLog(Common.LogFile.Error, string.Format("上传卡号失败,未知的采集器功能!({0},{1},{2})[funcType={3}]", card.Kdt, card.EPC, Common._deviceFuncType));
                    //}

                    //#endregion
                }
            }
            catch (Exception ex)
            {
                LogThreadManager.WriteLog(Common.LogFile.Error, "tmrUploadTimer_Elapsed : " + ex.StackTrace);
            }
            finally
            {
                // 获取未上传卡数量
                this.lblWaitLoadCnt.Text = daoSqlLite.Instance.GetCardsCount().ToString();

                timUploadTimer.Enabled = true;
            }
        }