Ejemplo n.º 1
0
        private int GetStartCount(AcqLineCountMDL mdl)
        {
            int precount = 0;

            try
            {
                //采集列表的索引号
                //int index = Convert.ToInt32(mdl.TGNMAE);

                AcqLineDAL dal = new AcqLineDAL();

                //获取产品编号的历史的计数
                //  precount = dal.GetAcqLineMDLPerCount(mdl.PLID, mdl.UNITID, mdl.PN);


                return(precount);
            }
            catch
            {
                throw;
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 更新采集数据
        /// </summary>
        /// <param name="mdl"></param>
        /// <param name="index"></param>
        /// <param name="curUnit"></param>
        /// <returns></returns>
        public int  UpdateAcqData(ref AcqLineCountMDL mdl, int index, int curUnit)
        {
            int ret = -1;

            try
            {
                AcqLineDAL acqDal = new AcqLineDAL();


                ProductDal pdal = new ProductDal();


                string lineID = Convert.ToInt32(mdl.PLID).ToString();

                //获取PN编码
                string pn = pdal.GetPNCodeByLineEMS(lineID, mdl.EMS);

                // string pn = pdal.GetPNbyEMSCode(mdl.FormatEMSCode(mdl.EMS));

                ///产品编码获取错误编码设置为0000
                if (pn == null || pn == string.Empty)
                {
                    pn = "E" + mdl.EMS.ToString();
                }
                // pn = "0000";


                mdl.PN = pn;

                //判断是存在有历史数据,有 更新区间信息
                if (acqDal.AcqUintExist2(mdl.PLID, mdl.EMS, mdl.UNITID) > 0)
                {
                    //获取当前区间的计数
                    int percount = GetLastRangCount(mdl);

                    // int storeCont = GetAcqLineMDLPerCount(mdl);
                    CLog.WriteStationLog("L1 T440 PRECOUNT", mdl.UNITID + "-" + this.startCount.ToString());

                    if (curUnit <= 0)
                    {
                        this.startCount = 0;
                    }


                    if (curUnit == 1)
                    {
                        startCount = 0;
                    }

                    /////当前采集的数据等于起始采集的数据值
                    //if (curUnit == startCount || curUnit < 0)
                    //    return 0;

                    //if()

                    // if (curUnit<)


                    //开启采集的数据
                    if (startCount <= 0)
                    {
                        ///当前采集数量的减去已采集的数量
                        mdl.CUR_COUNT = curUnit - startCount;

                        //CLog.WriteStationLog("ST400", "当前时间总量1" + mdl.CUR_COUNT.ToString());
                    }
                    else
                    {
                        int offset = curUnit - startCount;

                        ///采集变换的偏移量较大
                        if (offset > 1)
                        {
                            int storecount = GetStartCount(mdl);

                            if (storecount > 0)
                            {
                                offset = storecount - curUnit;
                            }

                            startCount = curUnit;
                        }

                        //可能重新计数了
                        if (offset < 0)
                        {
                            offset = 1;
                            // startCount = curUnit;
                        }

                        mdl.CUR_COUNT = offset + percount;
                        //CLog.WriteStationLog("ST400", "当前时间总量2" + mdl.CUR_COUNT.ToString());
                    }

                    ///设置采集的内存区间值
                    // setTimeRangCount(index, mdl.CUR_COUNT);

                    //ret = acqDal.UpAcqUnitCount(mdl.TID, mdl.CUR_COUNT);
                    //ret = acqDal.UpAcqUnitCount2(mdl.CUR_COUNT, mdl.PLID, mdl.UNITID, pn);

                    mdl.START_COUNT = startCount;


                    // ret = acqDal.UpAcqUnitCount2(mdl.CUR_COUNT,mdl.START_COUNT, mdl.PLID,0, mdl.UNITID, mdl.EMS);
                }
                else///当前时段的新项目
                {
                    if (curUnit <= 0)
                    {
                        this.startCount = 0;
                    }

                    /////当前采集的数据等于起始采集的数据值
                    if (curUnit == startCount || curUnit < 0)
                    {
                        return(0);
                    }

                    //清零了计数器
                    if (curUnit == 1)
                    {
                        startCount = 0;
                    }

                    //获取当前所有的区间内的计数数据
                    if (startCount == 0)
                    {
                        //startCount = acqDal.GetAcqTotalCount(mdl.PLID,DateTime.Now);

                        ///////startCount = acqDal.GetAcqLineLastConut(mdl.PLID);
                    }

                    //开启采集的数据
                    if (startCount <= 0)
                    {
                        ///当前采集数量的减去已采集的数量
                        mdl.CUR_COUNT = curUnit - startCount;
                    }
                    else
                    {
                        //计数的差值
                        int offset = curUnit - startCount;
                        mdl.CUR_COUNT = offset;

                        //计数未正常清零的情况下,重新开始计数
                    }



                    if (mdl.CUR_COUNT <= 0)
                    {
                        mdl.CUR_COUNT   = 1;
                        mdl.START_COUNT = curUnit;
                    }

                    ///设置采集的内存区间值
                    // setTimeRangCount(index, mdl.CUR_COUNT);

                    //mdl.START_COUNT = startCount;

                    mdl.START_COUNT = curUnit;

                    int uintSeq = acqDal.IsUionAcqUint(mdl.UNITID, mdl.PLID);

                    //型号发生变化重新计数 同时表示换型了
                    if (uintSeq > 0)
                    {
                        uintSeq += 1;

                        string strSeq = String.Format("{0:D2}", uintSeq);
                        mdl.SetTID(mdl.START_TIME, mdl.PLID, mdl.TGNMAE, strSeq);
                    }

                    mdl.UPDATE_TIME = DateTime.Now;
                    mdl.BEGIN_TIME  = DateTime.Now;


                    // modify by guozq  2018/3/26
                    //添加采集数据
                    //  ret = acqDal.AddAcqLine(mdl);
                }


                return(ret);
            }
            catch
            {
                throw;
            }
            finally
            {
                //更新计数值
                this.startCount = curUnit;
                CLog.WriteStationLog("L1 T440", this.startCount.ToString());
            }
        }