Ejemplo n.º 1
0
        private void savingDataThreadFunc()
        {
            while (true)
            {
                try
                {
                    if (mCancel)
                    {
                        return;
                    }

                    CUploadData ud = getQueueData();

                    if (ud != null)
                    {
                        YKBoxInfo upData = ud.Data as YKBoxInfo;
                        if (upData != null)
                        {
                            //upload
                            string uploadRe = "";
                            string sapMsg   = "";

                            SapResult result = SAPDataService.UploadYKBoxInfo(SysConfig.LGNUM, upData);
                            uploadRe = result.STATUS;
                            sapMsg   = result.MSG;

                            if (uploadRe == "E")
                            {
                                SqliteDataService.updateMsgToSqlite(ud.Guid, sapMsg);
                                playSoundWarn();
                            }
                            else
                            {
                                SqliteDataService.delUploadFromSqlite(ud.Guid);
                            }

                            upData.SapRemark = result.MSG;
                            upData.SapStatus = result.STATUS;

                            //save
                            YKBoxService.SaveBox(upData);

                            if (upData.Status == "S" && uploadRe == "S")
                            {
                                updateBoxList(upData);
                                UpdateTotalInfo();
                            }

                            updateUploadCount();
                            updateExpButton();
                        }
                    }
                    Thread.Sleep(500);
                }
                catch (Exception)
                {
                    //LogHelper.WriteLine(ex.Message + "\r\n" + ex.StackTrace.ToString());
                }
            }
        }
Ejemplo n.º 2
0
 private void btnGenerateDoc_Click(object sender, EventArgs e)
 {
     if (mBoxList != null && mBoxList.Count > 0)
     {
         HideLoading();
         if (MetroMessageBox.Show(this, "确认交接列表中所有箱记录?", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Information) == DialogResult.OK)
         {
             new Thread(new ThreadStart(() =>
             {
                 ShowLoading("正在交接...");
                 if (YKBoxService.HandoverBoxByDevice(SysConfig.DeviceNO))
                 {
                     Invoke(new Action(() =>
                     {
                         mBoxList.Clear();
                         grid.Rows.Clear();
                         UpdateTotalInfo();
                         HideLoading();
                         MetroMessageBox.Show(this, "交接成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                     }));
                 }
                 else
                 {
                     HideLoading();
                     MetroMessageBox.Show(this, "交接失败,可能是网络不稳定,请稍候再试", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                 }
             })).Start();
         }
     }
 }
Ejemplo n.º 3
0
        private void btnClear_Click(object sender, EventArgs e)
        {
            List <YKBoxInfo> rowBoxList = new List <YKBoxInfo>();

            List <DataGridViewRow> rows = GetCheckedRows();

            if (rows != null && rows.Count > 0)
            {
                foreach (DataGridViewRow row in rows)
                {
                    YKBoxInfo box = row.Tag as YKBoxInfo;
                    if (box != null)
                    {
                        if (!rowBoxList.Exists(r => r.Hu == box.Hu))
                        {
                            rowBoxList.Add(box);
                        }
                    }
                }
            }
            if (rowBoxList.Count > 0)
            {
                if (MetroMessageBox.Show(this, "确认清除列表中箱记录?", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Information) == DialogResult.OK)
                {
                    if (YKBoxService.DeleteBoxByHu(rowBoxList.Select(i => i.Hu).Distinct().ToList()))
                    {
                        MetroMessageBox.Show(this, "清除成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        DialogResult = DialogResult.OK;

                        currentBoxList.RemoveAll(i => rowBoxList.Exists(j => j.Hu == i.Hu));
                        updateGrid();
                    }
                    else
                    {
                        MetroMessageBox.Show(this, "清除失败,可能是网络不稳定,请稍候再试", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                }
            }



            //if (boxList!=null && boxList.Count>0)
            //{
            //    if (MetroMessageBox.Show(this, "确认清除列表中所有箱记录?", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Information) == DialogResult.OK)
            //    {
            //        if(YKBoxService.DeleteBoxByHu(boxList.Select(i=>i.Hu).Distinct().ToList()))
            //        {
            //            MetroMessageBox.Show(this, "清除成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            //            DialogResult = DialogResult.OK;
            //            Close();
            //        }
            //        else
            //        {
            //            MetroMessageBox.Show(this, "清除失败,可能是网络不稳定,请稍候再试", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            //        }
            //    }
            //}
        }
Ejemplo n.º 4
0
        public void updateSAP(YKBoxInfo uploadData)
        {
            CUploadData ud = new CUploadData();

            ud.Guid       = Guid.NewGuid().ToString();
            ud.Data       = uploadData;
            ud.IsUpload   = 0;
            ud.CreateTime = DateTime.Now;
            SqliteDataService.saveToSqlite(ud);

            YKBoxInfo upData = ud.Data as YKBoxInfo;

            if (upData == null)
            {
                return;
            }

            string uploadRe = "";
            string sapMsg   = "";

            SapResult result = SAPDataService.UploadYKBoxInfo(SysConfig.LGNUM, upData);

            uploadRe = result.STATUS;
            sapMsg   = result.MSG;

            if (uploadRe == "E")
            {
                SqliteDataService.updateMsgToSqlite(ud.Guid, sapMsg);
            }
            else
            {
                SqliteDataService.delUploadFromSqlite(ud.Guid);
            }

            upData.SapRemark = result.MSG;
            upData.SapStatus = result.STATUS;

            //save
            YKBoxService.SaveBox(upData);

            if (upData.Status == "S" && uploadRe == "S")
            {
                updateBoxList(upData);
                UpdateTotalInfo();
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// 取出队列中第一个上传任务,进行上传,上传完成后删除这条
        /// </summary>
        public void Upload()
        {
            lock (_lockObject)
            {
                if (isbusy)
                {
                    return;
                }
                else
                {
                    isbusy = true;
                }
                try
                {
                    if (CurrentUploadQueue.Count > 0)
                    {
                        //取出任务上传
                        object o = CurrentUploadQueue.Pop();
                        if (o.GetType() == typeof(SqliteUploadDataInfo))
                        {
                            YKBoxInfo box = (o as SqliteUploadDataInfo).Data;
                            //if(box.Status == "S")
                            //{
                            SapResult result = SAPDataService.UploadYKBoxInfo(SysConfig.LGNUM, box);
                            box.SapRemark = result.MSG;
                            box.SapStatus = result.STATUS;
                            bool xdSaveResult = YKBoxService.SaveBox(box);
                            YKBoxSqliteService.SetUploaded((o as SqliteUploadDataInfo).Guid);
                            if (OnUploaded != null)
                            {
                                OnUploaded(box);
                            }
                            //}
                        }
                    }
                }
                catch (Exception ex)
                {
                    LogHelper.WriteLine(ex.Message + "\r\n" + ex.StackTrace);
                }

                isbusy = false;
            }
        }
Ejemplo n.º 6
0
        void uploadSap(YKBoxInfo box)
        {
            try
            {
                SqliteUploadDataInfo ud = new SqliteUploadDataInfo();
                ud.Guid       = Guid.NewGuid().ToString();
                ud.Data       = box;
                ud.IsUpload   = 0;
                ud.CreateTime = DateTime.Now;
                YKBoxSqliteService.InsertUploadData(ud);

                SapResult result = SAPDataService.UploadYKBoxInfo(SysConfig.LGNUM, box);
                box.SapRemark = result.MSG;
                box.SapStatus = result.STATUS;
                bool xdSaveResult = YKBoxService.SaveBox(box);
                YKBoxSqliteService.SetUploaded(ud.Guid);
            }
            catch (Exception e)
            {
                Log4netHelper.LogError(e);
            }
        }
Ejemplo n.º 7
0
        private void InventoryForm_Load(object sender, EventArgs e)
        {
            InitView();

            Thread thread = new Thread(new ThreadStart(() =>
            {
                ShowLoading("正在连接PLC...");
                if (ConnectPlc())
                {
                    Invoke(new Action(() => { lblPlc.Text = "正常"; lblPlc.ForeColor = Color.Black; }));
                }
                else
                {
                    Invoke(new Action(() => { lblPlc.Text = "异常"; lblPlc.ForeColor = Color.OrangeRed; }));
                }
                ShowLoading("正在连接条码扫描枪...");
                ConnectBarcode();
                ShowLoading("正在连接读写器...");
                if (ConnectReader())
                {
                    Invoke(new Action(() => { lblReader.Text = "正常"; lblReader.ForeColor = Color.Black; }));
                }
                else
                {
                    Invoke(new Action(() =>
                    {
                        lblReader.Text = "异常"; lblReader.ForeColor = Color.OrangeRed;
                    }));
                }

                bool closed = false;

                ShowLoading("正在下载包材信息...");
                string def = "";
                DataTable boxStyleTable = SAPDataService.GetPackagingMaterialsList(SysConfig.LGNUM, SysConfig.DeviceInfo.LOUCENG, out def);

                if (boxStyleTable != null && boxStyleTable.Rows.Count > 0)
                {
                    this.Invoke(new Action(() =>
                    {
                        cboPxmat.DataSource    = boxStyleTable;
                        cboPxmat.ValueMember   = "PMAT_MATNR";
                        cboPxmat.DisplayMember = "MAKTX";
                    }));
                }
                else
                {
                    this.Invoke(new Action(() =>
                    {
                        HideLoading();
                        MetroMessageBox.Show(this, "未下载到包材数据,请检查网络情况", "提示");
                        closed = true;
                        Close();
                    }));
                }

                if (closed)
                {
                    return;
                }

                ShowLoading("正在更新SAP最新物料数据...");
                //materialList = SAPDataService.GetMaterialInfoList(SysConfig.LGNUM);
                materialList = LocalDataService.GetMaterialInfoList();

                if (materialList == null || materialList.Count <= 0)
                {
                    this.Invoke(new Action(() =>
                    {
                        HideLoading();
                        MetroMessageBox.Show(this, "未下载到物料主数据,请检查网络情况", "提示");
                        closed = true;
                        Close();
                    }));
                }
                if (closed)
                {
                    return;
                }

                hlaTagList = LocalDataService.GetAllRfidHlaTagList();
                if (hlaTagList == null || hlaTagList.Count <= 0)
                {
                    this.Invoke(new Action(() =>
                    {
                        HideLoading();
                        MetroMessageBox.Show(this, "未下载到吊牌主数据,请检查网络情况", "提示");
                        closed = true;
                        Close();
                    }));
                }
                if (closed)
                {
                    return;
                }

                ShowLoading("正在获取历史箱记录...");
                mBoxList = YKBoxService.GetUnHandoverBoxList(SysConfig.DeviceNO);
                if (mBoxList != null && mBoxList.Count > 0)
                {
                    bool first = true;
                    foreach (YKBoxInfo item in mBoxList)
                    {
                        Invoke(new Action(() =>
                        {
                            if (first)
                            {
                                cboSource.Text = item.Source;
                                cboTarget.Text = item.Target;
                            }
                            AddGrid(item);
                        }));
                    }
                }

                HideLoading();
            }));

            thread.IsBackground = true;
            thread.Start();
        }
Ejemplo n.º 8
0
        private void InventoryForm_Load(object sender, EventArgs e)
        {
#if DEBUG
            panelDebug.Show();
#endif
            InitView();
            dmButtonStart.Enabled = false;
            dmButtonStop.Enabled  = false;
            thread = new Thread(new ThreadStart(() => {
                ShowLoading("正在连接PLC...");
                if (ConnectPlc())
                {
                    Invoke(new Action(() => { lblPlc.Text = "正常"; lblPlc.ForeColor = Color.Black; }));
                }
                else
                {
                    Invoke(new Action(() => { lblPlc.Text = "异常"; lblPlc.ForeColor = Color.OrangeRed; }));
                }
                ShowLoading("正在连接条码扫描枪...");
                ConnectBarcode();
                ShowLoading("正在连接读写器...");
                if (ConnectReader())
                {
                    Invoke(new Action(() => { lblReader.Text = "正常"; lblReader.ForeColor = Color.Black; }));
                }
                else
                {
                    Invoke(new Action(() => {
                        lblReader.Text = "异常"; lblReader.ForeColor = Color.OrangeRed;
                    }));
                }

                mControlFlag = SysConfig.DeviceInfo != null ? SysConfig.DeviceInfo?.AuthList?.FindAll(i => i.AUTH_CODE.StartsWith("B")) : null;


                bool closed = false;

                ShowLoading("正在下载包材信息...");
                BoxStyleTable = SAPDataService.GetPackagingMaterialsList(SysConfig.LGNUM, SysConfig.DeviceInfo.LOUCENG, out res);

                if (BoxStyleTable != null)
                {
                    cboPxmat.DataSource    = BoxStyleTable;
                    cboPxmat.ValueMember   = "PMAT_MATNR";
                    cboPxmat.DisplayMember = "MAKTX";

                    if (BoxStyleTable.Rows.Count <= 0)
                    {
                        this.Invoke(new Action(() =>
                        {
                            HideLoading();
                            MetroMessageBox.Show(this, "未下载到包材数据,请检查网络情况", "提示");
                            closed = true;
                            Close();
                        }));
                    }
                }
                else
                {
                    this.Invoke(new Action(() =>
                    {
                        HideLoading();
                        MetroMessageBox.Show(this, "未下载到包材数据,请检查网络情况", "提示");
                        closed = true;
                        Close();
                    }));
                }

                if (closed)
                {
                    return;
                }

                ShowLoading("正在更新SAP最新物料数据...");
                materialList = SAPDataService.GetMaterialInfoList(SysConfig.LGNUM);
                //materialList = LocalDataService.GetMaterialInfoList();

                if (materialList == null || materialList.Count <= 0)
                {
                    this.Invoke(new Action(() =>
                    {
                        HideLoading();
                        MetroMessageBox.Show(this, "未下载到物料主数据,请检查网络情况", "提示");
                        closed = true;
                        Close();
                    }));
                }
                if (closed)
                {
                    return;
                }

                hlaTagList = LocalDataService.GetAllRfidHlaTagList();
                if (hlaTagList == null || hlaTagList.Count <= 0)
                {
                    this.Invoke(new Action(() =>
                    {
                        HideLoading();
                        MetroMessageBox.Show(this, "未下载到吊牌主数据,请检查网络情况", "提示");
                        closed = true;
                        Close();
                    }));
                }

                if (closed)
                {
                    return;
                }


                ShowLoading("正在检查是否存在未交接的历史箱记录...");
                boxList = YKBoxService.GetUnHandoverBoxList(SysConfig.DeviceNO);
                if (boxList != null && boxList.Count > 0)
                {
                    bool first = true;
                    foreach (YKBoxInfo item in boxList)
                    {
                        Invoke(new Action(() => {
                            if (first)
                            {
                                cboSource.Text = item.Source;
                                cboTarget.Text = item.Target;
                                Start();
                            }
                            AddGrid(item);
                        }));
                    }
                }
                UploadServer.GetInstance().OnUploaded += UploadServer_OnUploaded;
                UploadServer.GetInstance().Start();
                Invoke(new Action(() => {
                    dmButtonStart.Enabled = true;
                    UpdateTotalInfo();
                    UpdateErrorBoxButton();
                }));
                HideLoading();
            }));
            thread.IsBackground = true;
            thread.Start();
        }