Example #1
0
 /// <summary>
 /// 上传数据
 /// </summary>
 public static void UploadData()
 {
     try
     {
         ThreadUploadDataState = ThreadState.Running;
         //CLog.WriteSysLog("UploadData:Start...");
         while (ThreadUploadFlag)
         {
             try
             {
                 int  BatchCount     = GetBatchCount();
                 int  MaterialCount  = GetMarterialCount();
                 bool BatchStatus    = BatchCount > 0;
                 bool MaterialStatus = MaterialCount > 0;
                 if (!BatchStatus && !MaterialStatus)
                 {
                     int Time = 60 * Minutes;
                     for (int i = 0; i < Time; i++)
                     {
                         if (!ThreadUploadFlag)
                         {
                             break;
                         }
                         Thread.Sleep(1000);
                     }
                     if (ThreadUploadFlag)
                     {
                         continue;
                     }
                     else
                     {
                         break;
                     }
                 }
                 else if (BatchStatus && Opt.GlobalNetStatus())
                 {
                     UploadBatchTable();
                 }
                 else if (MaterialStatus && Opt.GlobalNetStatus())
                 {
                     UploadMaterialTable();
                 }
             }
             catch (Exception ex)
             {
                 CLog.WriteErrLog("UploadDataing Exception:" + ex.Message);
             }
         }
     }
     catch (Exception ex)
     {
         CLog.WriteErrLog("UploadData Exception:" + ex.Message);
     }
     ThreadUploadDataState = ThreadState.Stop;
 }
Example #2
0
 /// <summary>
 /// 批次信息提醒
 /// </summary>
 private void BatchTip()
 {
     if (BaseVariable.DeviceEntity.ProductType != "踏板" && BaseVariable.DeviceEntity.ProductType != "制动泵" && Opt.GlobalNetStatus())
     {
         bool flag = Opt.CheckBatchStatus(this.productModel.ProductCode);
         if (flag)
         {
             Tip("有批次零件需要更新");
         }
     }
 }
Example #3
0
 /// <summary>
 /// 初始化网络
 /// </summary>
 private void InitNetwork()
 {
     try
     {
         int WiFiLevel = (int)Network.GetWifiStrengthLevel();
         if (WiFiLevel == -1)
         {
             this.lblMsg.Text     = "网络未连接";
             NetStatus            = false;
             this.btnLogin.Text   = "本地登录";
             this.lblNetwork.Text = "离线模式";
             GetDeviceInfo(false);//获取设备信息
         }
         else
         {
             NetStatus    = true;
             ServerStatus = Opt.ServerConnectStatus();
             if (!ServerStatus)
             {
                 this.lblMsg.Text = "服务器连接失败";
                 ////this.btnLogin.Text = "登    录";
                 this.lblNetwork.Text = "离线模式";
                 this.btnLogin.Text   = "本地登录";
                 GetDeviceInfo(ServerStatus);//获取设备信息
             }
             else
             {
                 object obj = Opt.GetDateTime();
                 if (obj != null)//设置系统时间
                 {
                     DateTime date = DateTime.Parse(obj.ToString());
                     SystemTime.SetDate(date);
                 }
                 this.lblMsg.Text      = "服务器连接成功";
                 this.lblNetwork.Text  = "在线模式";
                 this.btnLogin.Enabled = true;
                 GetDeviceInfo(ServerStatus);//获取设备信息
             }
         }
     }
     catch (Exception ex)
     {
         CLog.WriteErrLog(ex.Message);
     }
 }
Example #4
0
 /// <summary>
 /// 应用更新
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void btnApply_Click(object sender, EventArgs e)
 {
     try
     {
         int rst = 0;
         if (Opt.GlobalNetStatus())//网络状态良好的情况下
         {
             rst = ResultDAL.Update(BaseVariable.ResultTableName, this.lblHJCode.Text, this.lblProductCode.Text, "", "", "", RequestParam);
             rst = ResultDAL.Update(BaseVariable.ResultTableName, this.lblHJCode.Text, this.lblProductCode.Text, BaseVariable.DeviceEntity.ProductType, BaseVariable.UserEntity.UserID, BaseVariable.DeviceEntity.StationID, RequestParam);
         }
         if (rst == 1)
         {
             //重新加载数据
             foreach (ListViewItem item in this.lvMaterial.Items)
             {
                 item.SubItems[2].Text = "";//扫描条码
                 item.ForeColor        = Color.Black;
             }
             this.lblTip.Text = "更新成功!请扫描合件条码";
             Audio.SoundTip(2);//正确提示音
             this.lblHJCode.Text       = "";
             this.lblMaterialCode.Text = "";
             this.lblBarCode.Text      = "";
             scantype = ScanType.MATERIALCODE;
             IsHjScan = true;
             RequestParam.Clear();
         }
         else if (rst == 201)
         {
             this.lblTip.Text = "合件不存在!";
             Audio.SoundTip(0);//失败提示音
         }
         else
         {
             this.lblTip.Text = "更新失败!";
             Audio.SoundTip(0);//失败提示音
         }
     }
     catch (Exception ex)
     {
         CLog.WriteErrLog(ex.Message);
     }
 }
Example #5
0
 /// <summary>
 /// 启动的Timer
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void tTime_Tick(object sender, EventArgs e)
 {
     try
     {
         tTime.Enabled = false;
         if (BaseVariable.IsRunFirst)
         {
             MessageBox.Show("第一次使用请先下载数据!!!");
         }
         else
         {
             //加载产品特征码列表
             Opt.LoadProductInfo();
         }
     }
     catch (Exception ex)
     {
         CLog.WriteErrLog(ex.Message);
     }
 }
Example #6
0
 /// <summary>
 /// 返修设置
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void bntBack_Click(object sender, EventArgs e)
 {
     try
     {
         if (!Opt.GlobalNetStatus())
         {
             MessageBox.Show("离线模式下不能记录返修,待在线模式下返修!", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button1);
         }
         else
         {
             FrmRepair form = new FrmRepair();
             form.frmMain = this;
             form.ShowDialog();
             form.Dispose();
         }
     }
     catch (Exception ex)
     {
         CLog.WriteErrLog("[FrmMain.bntBack]" + ex.Message);
     }
 }
Example #7
0
        /// <summary>
        /// 下载数据
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnDnData_Click(object sender, EventArgs e)
        {
            try
            {
                if (!Opt.GlobalNetStatus())
                {
                    MessageBox.Show("离线模式下不能下载数据,待在线模式下下载数据!", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button1);
                }
                else
                {
                    FrmDataSync form = new FrmDataSync(SyncType.Download);
                    form.ShowDialog();
                    form.Dispose();
                    LoadForm();

                    //加载产品特征码列表
                    Opt.LoadProductInfo();
                }
            }
            catch (Exception ex)
            {
                CLog.WriteErrLog("[FrmMain.btnDnData]" + ex.Message);
            }
        }
Example #8
0
        /// <summary>
        /// 扫描验证
        /// </summary>
        /// <param name="barcode"></param>
        private void ScanValidate(string barcode, SymbologyOptions.SymbologyType t)
        {
            try
            {
                barcode = barcode.Replace("<cr><lf>", "").Replace("\r\n", "").Replace("]C1", ""); //获取条码/二维码,过滤回车换行
                bool IsExist = false;                                                             //标记是否存在
                foreach (ListViewItem item in this.lvMaterial.Items)
                {
                    string tmpBarcode   = barcode;
                    string ItemCode     = item.Text.ToString();  //当前的零件编码
                    string FeatureCode  = item.SubItems[3].Text; //特征码
                    string FeatureIndex = item.SubItems[4].Text; //特征位
                    string TraceType    = item.SubItems[4].Text; //追溯类型
                    bool   flag         = false;

                    if (FeatureCode == null || FeatureCode.Trim() == "")
                    {
                        if (tmpBarcode.Length < ItemCode.Length)
                        {
                            continue;
                        }
                        string tmpCode = "";

                        if ((t == SymbologyOptions.SymbologyType.QR_Code ||
                             t == SymbologyOptions.SymbologyType.DataMatrix ||
                             t == SymbologyOptions.SymbologyType.Maxicode ||
                             t == SymbologyOptions.SymbologyType.PDF417 ||
                             t == SymbologyOptions.SymbologyType.Aztec) &&
                            barcode.Trim().Length >= 38)
                        //if (t == SymbologyOptions.SymbologyType.QR_Code && barcode.Trim().Length >= 38) //if (tmpBarcode.Length >= 38)
                        {
                            tmpCode = tmpBarcode.Substring(0, 10);
                            string supplier = tmpBarcode.Substring(15, 10); //供应商代码
                            string bno      = tmpBarcode.Substring(25, 13); //批次号
                            tmpBarcode = bno + ";" + supplier;
                        }
                        //else
                        //{
                        //    tmpCode = tmpBarcode.Substring(0, ItemCode.Length);
                        //}

                        //flag = tmpCode == ItemCode;//判断特征码
                    }
                    else
                    {
                        if (tmpBarcode.Length < FeatureCode.Length)
                        {
                            continue;
                        }
                        flag = Opt.ValidateFeatureCode(tmpBarcode, FeatureIndex, FeatureCode);//判断特征码
                    }

                    if (flag)
                    {
                        materialCode              = ItemCode;
                        item.ForeColor            = Color.Green; //当防错正常时字体为绿色
                        item.SubItems[2].Text     = tmpBarcode;  //扫描条码
                        this.lblMaterialCode.Text = ItemCode;
                        this.lblBarCode.Text      = tmpBarcode;
                        item.Selected             = true;
                        RecordScanInfo();  //记录扫描信息
                        this.lblTip.Text = "扫描零件条码或零件批次条码";
                        Audio.SoundTip(1); //扫描提示音
                        IsExist = true;
                        break;
                    }
                    else
                    {
                        string code = tmpBarcode.Substring(1);
                        bool   IsOk = false;
                        switch (scantype)
                        {
                        case ScanType.MATERIALCODE:
                            if (ItemCode.Equals(code))
                            {
                                this.lblMaterialCode.Text = code;    //扫描的条码
                                this.lblBarCode.Text      = "";
                                materialCode      = ItemCode;
                                item.Selected     = true;            //选中扫描的材料
                                listViewItemIndex = item.Index;
                                Audio.SoundTip(1);                   //扫描提示音
                                scantype         = ScanType.BARCODE; //修改扫描类型为批次条码
                                this.lblTip.Text = "扫描零件批次条码";
                                IsExist          = true;
                                IsOk             = true;
                            }
                            break;

                        case ScanType.BARCODE:
                            this.lblBarCode.Text = tmpBarcode;                                       //扫描的条码
                            this.lvMaterial.Items[listViewItemIndex].ForeColor        = Color.Green; //当防错正常时字体为绿色
                            this.lvMaterial.Items[listViewItemIndex].SubItems[2].Text = tmpBarcode;  //扫描条码
                            scantype = ScanType.MATERIALCODE;
                            RecordScanInfo();                                                        //记录扫描信息
                            this.lblTip.Text = "扫描零件条码或零件批次条码";
                            Audio.SoundTip(1);                                                       //扫描提示音
                            IsExist = true;
                            IsOk    = true;
                            break;

                        default:
                            break;
                        }

                        if (IsOk)
                        {
                            break;
                        }
                    }
                }
                if (!IsExist && scantype != ScanType.BARCODE)//不存在的情况
                {
                    this.lblTip.Text = "扫描零件编码不在此产品之列";
                    Audio.SoundTip(0);//错误提示音
                }
            }
            catch (Exception ex)
            {
                CLog.WriteErrLog(ex.Message);
            }
        }
Example #9
0
        private void ValidateHj(string barcode)
        {
            this.lblHJCode.Text = barcode;

            bool isNew = false;//新产品标识

            #region 判断合件条码长度
            bool CheckBitRST = Opt.HJValidate(barcode);
            //校验位判断
            if (!CheckBitRST)
            {
                this.lblTip.Text = "合件条码长度不符合!";
                Audio.SoundTip(0);//错误提示音
                return;
            }
            #endregion

            #region 判断校验位
            //判断校验位
            string CheckCode      = barcode.Substring(0, 13); //校验合件条码
            string CheckBitOrigin = barcode.Substring(13, 1); //校验位
            string CheckBit       = Opt.CheckBit(CheckCode);  //获取校验位
            if (!CheckBit.ToLower().Equals(CheckBitOrigin.ToLower()))
            {
                this.lblTip.Text = "合件条码校验位错误!";
                Audio.SoundTip(0);//错误提示音
                return;
            }
            #endregion

            #region //判断特征码
            string fc = barcode.Substring(0, 6);
            //前一个特征码与现在扫描相同
            if (this.productModel != null && this.productModel.FeatureCode == fc)
            {
                //清除前一次信息
                foreach (ListViewItem item in lvMaterial.Items)
                {
                    item.SubItems[2].Text = "";          //初始化状态为空
                    item.ForeColor        = Color.Black; //初始化字体颜色为黑色
                }
            }
            else
            {
                isNew = this.productModel == null;
                if (Opt.FeatureCodeList.ContainsKey(fc))
                {
                    //扫描合件的特征码存在
                    this.productModel = Opt.FeatureCodeList[fc];
                    isNew             = true;
                }
                else
                {
                    //扫描合件的特征码不存在
                    IsHjScan         = true;
                    this.lblTip.Text = "合件条码不符,请重新扫描合件";
                    Audio.SoundTip(0);//错误提示音
                    return;
                }
            }
            #endregion

            #region 加载ListView数据
            if (isNew)
            {
                InitListView();
            }
            #endregion

            Audio.SoundTip(1); //扫描提示音
            RecordScanInfo();  //记录扫描信息
            IsHjScan         = false;
            this.lblTip.Text = "请扫描零件条码或批次条码";
        }
Example #10
0
        /// <summary>
        /// 应用更新
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnApply_Click(object sender, EventArgs e)
        {
            try
            {
                if (IsOK)
                {
                    this.lblTip.Text = "未录入数据!!!";
                    Audio.SoundTip(0);//失败提示音
                    return;
                }
                if (!string.IsNullOrEmpty(this.cmbMaterialCode.Text) &&
                    this.cmbMaterialCode.Text.Trim() != "" &&
                    !string.IsNullOrEmpty(this.tbMaterialBatchNo.Text) &&
                    this.tbMaterialBatchNo.Text.Trim() != "" &&
                    !string.IsNullOrEmpty(this.tbMaterialBatchNum.Text) &&
                    this.tbMaterialBatchNum.Text.Trim() != "" &&
                    !string.IsNullOrEmpty(this.tbBarCode.Text) &&
                    this.tbBarCode.Text.Trim() != "")
                {
                    if (IsEdit)
                    {
                        #region //添加合件验证
                        if (!Opt.ValidatePartCode(this.cmbMaterialCode.Text, this.tbBarCode.Text.Trim()))
                        {
                            Audio.SoundTip(0);
                            this.lblTip.Text = "扫描的合件不匹配,请重新录入";
                            return;
                        }
                        if (string.IsNullOrEmpty(this.tbBarCode.Text))
                        {
                            Audio.SoundTip(0);
                            this.lblTip.Text = "请录入合件条码";
                            return;
                        }
                        if (string.IsNullOrEmpty(this.tbMaterialBatchNo.Text))
                        {
                            Audio.SoundTip(0);
                            this.lblTip.Text = "请录入批次流水号";
                            return;
                        }
                        if (string.IsNullOrEmpty(this.tbMaterialBatchNum.Text))
                        {
                            Audio.SoundTip(0);
                            this.lblTip.Text = "请录入包装数量";
                            return;
                        }
                        else
                        {
                            int num = 0;
                            try
                            {
                                num = int.Parse(this.tbMaterialBatchNum.Text);
                            }
                            catch (Exception)
                            {
                                num      = 0;
                                scantype = ScanType.PacketNumber;
                            }

                            if (num == 0)
                            {
                                this.lblTip.Text = "扫描包装数量不是数字或=0";
                                return;
                            }
                        }
                        //if (string.IsNullOrEmpty(this.tbSupplier.Text))
                        //{
                        //    Audio.SoundTip(0);
                        //    this.lblTip.Text = "请录入供应商编码";
                        //    return;
                        //}
                        #endregion
                    }

                    BatchNoMDL model = MaterialInfoList[this.cmbMaterialCode.Text.Trim()] as BatchNoMDL;
                    if (model == null)
                    {
                        return;
                    }

                    string barcode  = this.tbBarCode.Text.Trim();
                    string batchno  = this.tbMaterialBatchNo.Text.Trim();
                    string supplier = this.tbSupplier.Text.Trim();
                    int    batchnum = model.BatchNum;
                    if (!string.IsNullOrEmpty(this.tbMaterialBatchNum.Text.Trim()))
                    {
                        try
                        {
                            int num = int.Parse(this.tbMaterialBatchNum.Text.Trim());
                            batchnum = num;
                        }
                        catch (Exception)
                        {
                        }
                    }

                    model.BarCode     = barcode;
                    model.BatchNo     = batchno;
                    model.Supplier    = supplier;
                    model.BatchNum    = batchnum;
                    model.ProductType = BaseVariable.DeviceEntity.ProductType;

                    bool flag = false;         //结果标识
                    if (Opt.GlobalNetStatus()) //存储到服务器
                    {
                        flag = batchDAL.Insert(model);
                    }
                    else//存储到服务器
                    {
                        flag = lBatchDAL.Add(model);
                    }

                    if (flag)
                    {
                        IsOK             = true;
                        scantype         = ScanType.MATERIALCODE;
                        this.lblTip.Text = "更新成功,请扫描批次条码";
                        Audio.SoundTip(2);//正确提示音
                    }
                    else
                    {
                        this.lblTip.Text = "更新失败,请重试";
                        Audio.SoundTip(0);//失败提示音
                    }
                }
                else
                {
                    this.lblTip.Text = "批次相关信息不能为空";
                }
            }
            catch (Exception ex)
            {
                CLog.WriteErrLog("[Frmbatch.Apply]" + ex.Message);
            }
        }
Example #11
0
        /// <summary>
        /// 扫描执行操作的方法
        /// </summary>
        /// <param name="obj"></param>
        private void ScanOptFun(string barcode, SymbologyOptions.SymbologyType t)
        {
            try
            {
                if (!IsEdit)
                {
                    #region 扫描录入
                    this.lblTip.Text = "";

                    switch (scantype)
                    {
                    case ScanType.MATERIALCODE: //材料编码扫描
                    {
                        #region                 //材料编码扫描
                        this.cmbMaterialCode.SelectedIndex = -1;
                        this.lblMaterialName.Text          = "";
                        this.tbMaterialBatchNum.Text       = "";
                        this.tbMaterialBatchNo.Text        = "";
                        this.tbSupplier.Text = "";
                        this.tbBarCode.Text  = "";
                        string pcode = "";

                        //判断是否为二维码
                        #region         // 二维码
                        if ((t == SymbologyOptions.SymbologyType.QR_Code ||
                             t == SymbologyOptions.SymbologyType.DataMatrix ||
                             t == SymbologyOptions.SymbologyType.Maxicode ||
                             t == SymbologyOptions.SymbologyType.PDF417 ||
                             t == SymbologyOptions.SymbologyType.Aztec) &&
                            barcode.Trim().Length >= 38)
                        {
                            pcode = barcode.Substring(0, 10);
                            if (MaterialInfoList.ContainsKey(pcode))
                            {
                                //能够匹配
                                Audio.SoundTip(1);                           //扫描提示音
                                string bnumstr  = barcode.Substring(10, 5);  //包装量
                                string supplier = barcode.Substring(15, 10); //供应商代码
                                string bno      = barcode.Substring(25, 13); //批次号

                                BatchNoMDL model = MaterialInfoList[pcode] as BatchNoMDL;

                                int batchnum = model.BatchNum;
                                try
                                {
                                    int bnum = int.Parse(bnumstr);
                                    batchnum = bnum;
                                }
                                catch (Exception)
                                {
                                }

                                this.cmbMaterialCode.Text    = model.MaterialCode;
                                this.lblMaterialName.Text    = model.MaterialName;
                                this.tbMaterialBatchNum.Text = batchnum.ToString();
                                this.tbSupplier.Text         = supplier;
                                this.tbMaterialBatchNo.Text  = bno;
                                IsOK     = false;
                                scantype = ScanType.HJBARCODE;

                                this.tbBarCode.Focus();
                                this.lblTip.Text = "请扫描合件条码";
                            }
                            else
                            {
                                //不能够匹配
                                Audio.SoundTip(0);        //错误提示音
                                scantype                    = ScanType.MATERIALCODE;
                                this.lblTip.Text            = "扫描的条码的零件不符当前产品";
                                this.tbMaterialBatchNo.Text = barcode;
                                IsOK = true;
                            }
                            return;
                        }
                        #endregion

                        string code = barcode.Substring(1);
                        this.cmbMaterialCode.Text = code;        //扫描的条码
                        if (MaterialInfoList.ContainsKey(code))
                        {
                            Audio.SoundTip(1);                //扫描提示音
                            scantype = ScanType.PacketNumber; //修改扫描类型为供应商条码
                            BatchNoMDL model = MaterialInfoList[code] as BatchNoMDL;
                            this.cmbMaterialCode.Text = model.MaterialCode;
                            this.lblMaterialName.Text = model.MaterialName;
                            //this.tbMaterialBatchNum.Text = model.BatchNum.ToString();

                            this.tbMaterialBatchNum.Focus();

                            this.lblTip.Text = "请扫描包装数量";
                            //this.lblTip.Text = "请扫描供应商编码";
                        }
                        else
                        {
                            Audio.SoundTip(0);        //错误提示音
                            scantype         = ScanType.MATERIALCODE;
                            this.lblTip.Text = "扫描的条码的零件不符当前产品";
                        }
                        #endregion
                    }
                    break;

                    case ScanType.Supplier:    //供应商编码
                    {
                        Audio.SoundTip(1);     //扫描提示音
                        this.tbSupplier.Text = barcode;
                        scantype             = ScanType.PacketNumber;
                        this.tbMaterialBatchNum.Focus();

                        this.lblTip.Text = "请扫描包装数量";
                    }
                    break;

                    case ScanType.PacketNumber:    //包装数量
                    {
                        this.tbMaterialBatchNum.Text = barcode.ToUpper().Replace("Q", "");
                        int num = 0;
                        try
                        {
                            num = int.Parse(this.tbMaterialBatchNum.Text);
                        }
                        catch (Exception)
                        {
                            num      = 0;
                            scantype = ScanType.PacketNumber;
                        }

                        if (num == 0)
                        {
                            this.lblTip.Text = "扫描包装数量不是数字或=0";
                            return;
                        }

                        scantype = ScanType.BARCODE;
                        this.tbMaterialBatchNo.Focus();

                        this.lblTip.Text = "请扫描批次条码";
                    }
                    break;

                    case ScanType.BARCODE:    //批次条码
                    {
                        string code = barcode.Substring(1);
                        if (barcode.Substring(0, 1).Equals("P") && code == this.cmbMaterialCode.Text)
                        {
                            Audio.SoundTip(0);        //错误提示音
                            this.lblTip.Text = "重复扫描零件条码";
                            scantype         = ScanType.BARCODE;
                        }
                        else
                        {
                            Audio.SoundTip(1);                     //扫描提示音
                            this.tbMaterialBatchNo.Text = barcode; //扫描的条码
                            this.lblTip.Text            = "请扫描合件条码";
                            scantype = ScanType.HJBARCODE;
                            this.tbBarCode.Focus();
                        }
                    }
                    break;

                    case ScanType.HJBARCODE:    //合件条码扫描
                    {
                        this.tbBarCode.Text = barcode;

                        #region         //添加合件验证
                        if (Opt.ValidatePartCode(this.cmbMaterialCode.Text, barcode))
                        {
                            Audio.SoundTip(1);
                            scantype         = ScanType.MATERIALCODE;
                            this.lblTip.Text = "更新信息或者是重新录入";
                            return;
                        }
                        #endregion

                        Audio.SoundTip(0);
                        scantype         = ScanType.HJBARCODE;
                        this.lblTip.Text = "扫描的合件不匹配,请重新录入";
                    }
                    break;
                    }
                    #endregion
                }
                else
                {
                    #region 手动录入
                    if (this.MaterialInfoList != null && this.cmbMaterialCode.SelectedIndex > 0)
                    {
                        //判断是否为二维码
                        if (barcode.Trim().Length >= 38)
                        {
                            var pcode = barcode.Substring(0, 10);
                            if (MaterialInfoList.ContainsKey(pcode))
                            {
                                //能够匹配
                                Audio.SoundTip(1);//扫描提示音
                                SetQrCode(barcode);
                            }
                            return;
                        }

                        if (this.tbBarCode.Focused)
                        {
                            this.tbBarCode.Text = barcode;
                            Audio.SoundTip(1);
                        }
                        else if (this.tbSupplier.Focused)
                        {
                            this.tbSupplier.Text = barcode;
                            Audio.SoundTip(1);
                            this.tbMaterialBatchNum.Focus();
                        }
                        else if (this.tbMaterialBatchNum.Focused)
                        {
                            this.tbMaterialBatchNum.Text = barcode.ToUpper().Replace("Q", "");
                            int num = 0;
                            try
                            {
                                num = int.Parse(this.tbMaterialBatchNum.Text);
                            }
                            catch (Exception)
                            {
                                num = 0;
                            }

                            if (num == 0)
                            {
                                this.lblTip.Text = "扫描包装数量不是数字或=0";
                                Audio.SoundTip(0);
                                return;
                            }

                            Audio.SoundTip(1);
                            this.tbMaterialBatchNo.Focus();
                        }
                        else if (this.tbMaterialBatchNo.Focused)
                        {
                            this.tbMaterialBatchNo.Text = barcode;
                            Audio.SoundTip(1);
                            this.tbBarCode.Focus();
                        }
                        else
                        {
                            return;
                        }

                        int ret = 0;

                        if (string.IsNullOrEmpty(this.tbBarCode.Text))
                        {
                            ret += 1;
                            this.lblTip.Text = "请录入合件条码";
                            this.tbBarCode.Focus();
                        }
                        if (string.IsNullOrEmpty(this.tbMaterialBatchNo.Text))
                        {
                            ret += 1;
                            this.lblTip.Text = "请录入批次流水号";
                            this.tbMaterialBatchNo.Focus();
                        }
                        if (string.IsNullOrEmpty(this.tbMaterialBatchNum.Text))
                        {
                            ret += 1;
                            this.lblTip.Text = "请录入包装数量";
                            this.tbMaterialBatchNum.Focus();
                        }
                        //if (string.IsNullOrEmpty(this.tbSupplier.Text))
                        //{
                        //    ret += 1;
                        //    this.lblTip.Text = "请录入供应商编码";
                        //    this.tbSupplier.Focus();
                        //}

                        if (ret == 0)
                        {
                            this.lblTip.Text = "更新信息或者是重新录入";
                        }
                    }
                    else
                    {
                        Audio.SoundTip(0);//错误提示音
                        this.lblTip.Text = "请选择零件编码";
                        this.cmbMaterialCode.Focus();
                    }
                    #endregion
                }
            }
            catch (Exception ex)
            {
                CLog.WriteErrLog(ex.Message);
            }
        }
Example #12
0
        /// <summary>
        /// 数据上传提示
        /// </summary>
        public void TipDataUpload()
        {
            try
            {
                string productType = BaseVariable.DeviceEntity.ProductType;
                //制动泵
                int BrakeResultCount = 0;
                //踏板
                int PedalResultCount = 0;
                //散热器
                int RadiatorResultCount = 0;
                int BatchCount          = 0;
                //添加前桥和后桥
                int FrontAxleResultCount = 0;
                int RearAxleResultCount  = 0;
                //添加副仪表板
                int AuxiliaryFasiaResultCount = 0;
                switch (productType)
                {
                case "踏板":
                    PedalResultCount = lPedalResultDAL.GetRecordCount("");
                    break;

                case "制动泵":
                    BrakeResultCount = lBrakeResultDAL.GetRecordCount("");
                    break;

                case "散热器":
                    RadiatorResultCount = lRadiatorResultDAL.GetRecordCount("");
                    break;

                case "前桥":
                    FrontAxleResultCount = lFrontAxleResultDAL.GetRecordCount("");
                    break;

                case "后桥":
                    RearAxleResultCount = lRearAxleResultDAL.GetRecordCount("");
                    break;

                case "副仪表板":
                    AuxiliaryFasiaResultCount = lAuxiliaryFasiaResultDAL.GetRecordCount("");
                    break;
                }

                BatchCount = lBatchDAL.GetRecordCount("");
                int total = BatchCount + BrakeResultCount + PedalResultCount + RadiatorResultCount + FrontAxleResultCount + RearAxleResultCount + AuxiliaryFasiaResultCount;
                if (!Opt.GlobalNetStatus() && total > 0)
                {
                    string msg = string.Format("当前有{0}条数据需要上传,请在网络好的情况下手动上传!", total);
                    MessageBox.Show(msg, "温馨提示", MessageBoxButtons.OK, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1);
                    return;
                }
                if (total > 0)
                {
                    string msg = string.Format("当前有{0}条数据需要上传,是否现在上传?", total);
                    if (MessageBox.Show(msg, "温馨提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1) == DialogResult.Yes)
                    {
                        FrmDataSync form = new FrmDataSync(SyncType.Upload);
                        form.ShowDialog();
                        form.Dispose();
                        return;
                    }
                }
            }
            catch (Exception ex)
            {
                CLog.WriteErrLog("Use UploadTip Exception:" + ex.Message);
            }
        }
Example #13
0
        /// <summary>
        /// 防错追溯,将信息添加到数据库
        /// </summary>
        private bool ScanResultToDb()
        {
            try
            {
                if (CurrnetScanType == 1 || (productModel.HaveSub && RequestParam.Count > 0))
                {
                    //获取批次信息
                    //GetBatchInfoToParam();
                    bool flag = false;         //结果标识
                    if (Opt.GlobalNetStatus()) //网络状态良好的情况下
                    {
                        DateTime time = DateTime.Now;
                        flag = ResultDAL.Insert(BaseVariable.ResultTableName, this.lblHJCode.Text, this.lblProductCode.Text, this.productModel.ProductType, BaseVariable.UserEntity.UserID, BaseVariable.DeviceEntity.StationID, CurrnetScanType, RequestParam);
                        this.WirteTimeSpanLog(DateTime.Now - time, LogType.RD);
                    }
                    else
                    {
                        flag = SaveToLocal();//存储到本地数据库中
                    }
                    if (!flag)
                    {
                        flag = SaveToLocal();//存储到本地数据库中
                    }
                    if (flag)
                    {
                        this.lblOK.Text = "OK";
                        this.Tip("扫描合件条码");
                        this.lblOK.ForeColor = Color.Green;
                        CurrentCount++;
                        this.lblCurrentCount.Text = CurrentCount.ToString();
                        return(true);
                    }
                }
                this.lblOK.Text = "NG";
                this.Tip("请重新操作");
                this.lblOK.ForeColor = Color.Red;
            }
            catch (Exception ex)
            {
                bool rst = SaveToLocal();//存储到本地数据库中
                if (rst)
                {
                    this.lblOK.Text = "OK";
                    this.Tip("扫描合件条码");
                    this.lblOK.ForeColor = Color.Green;
                    CurrentCount++;
                    this.lblCurrentCount.Text = CurrentCount.ToString();
                    return(true);
                }
                else
                {
                    this.lblOK.Text = "NG";
                    this.Tip("请重新操作");
                    this.lblOK.ForeColor = Color.Red;
                }
                CLog.WriteErrLog("[FrmScan.ScanResultToDB]" + ex.Message);
            }
            finally
            {
                this.WirteTimeSpanLog(new TimeSpan(0, 0, 0, 0, (int)watch.ElapsedMilliseconds), LogType.V1);
                watch.Reset();
                //BatchTip();//批次信息提醒
            }

            return(false);
        }
Example #14
0
        /// <summary>
        /// 获取当前条码是否存在
        /// 1.合件号;2.零件号(是一一追溯的零件)
        /// </summary>
        /// <param name="type">1:合件,2:零件</param>
        /// <param name="barcode">要验证的条码</param>
        /// <param name="materialfiled">字段名</param>
        public bool ValidateScanIsExist(int Type, string BarCode, string Filed)
        {
            Stopwatch existWatch = new Stopwatch();

            try
            {
                /*
                 * 人物:xudy
                 * 时间:2015-01-18
                 * 内容:修改了条件,讲userid、barcode换为tid
                 */
                if (Opt.GlobalNetStatus())//从服务器获取数据
                {
                    existWatch.Start();
                    //string requestUrl = BaseVariable.RequestURL + "Result.ashx";
                    //Dictionary<string, object> dict = new Dictionary<string, object>();
                    //dict.Add("do", "validate");
                    //dict.Add("Type", Type);
                    //dict.Add("TableName", BaseVariable.ResultTableName);
                    //dict.Add("BarCode", BarCode);
                    //dict.Add("ProductCode", this.productModel.ProductCode);
                    //dict.Add("Filed", Filed);

                    //string str = Http.POST(requestUrl, dict);
                    //var obj = JsonHelper.JsonDeSerializer<ReturnInfo>(str);
                    //ReturnInfo ReturnData = (ReturnInfo)obj;
                    //if (ReturnData != null && ReturnData.Code == "1")
                    //{
                    //    return true;
                    //}

                    return(ResultDAL.Validate(BaseVariable.ResultTableName, BarCode, this.productModel.ProductCode, Type, Filed));
                }
                else//从本地获取数据
                {
                    string sql = "";
                    switch (Type)
                    {
                    case 1:    //合件
                        sql = string.Format("select tid from {0} where barcode='{1}' and productcode='{2}'", BaseVariable.ResultTableName, BarCode, this.productModel.ProductCode);
                        break;

                    case 2:    //子件
                        sql = string.Format("select tid from {0} where {2}='{1}'", BaseVariable.ResultTableName, BarCode, Filed);
                        break;
                    }
                    object obj = LocalDbDAL.ExecuteScaler(sql);
                    if (obj != null && !string.IsNullOrEmpty(obj.ToString()))
                    {
                        return(true);
                    }
                }
                return(false);
            }
            catch (Exception ex)
            {
                CLog.WriteErrLog(ex.Message);
                return(false);
            }
            finally
            {
                LogType ty = LogType.Y1;
                switch (Type)
                {
                case 1:        //合件
                    ty = LogType.Y1;
                    break;

                case 2:        //子件
                    ty = LogType.Y2;
                    break;
                }
                this.WirteTimeSpanLog(new TimeSpan(0, 0, 0, 0, (int)existWatch.ElapsedMilliseconds), ty);
                existWatch.Stop();
            }
        }
Example #15
0
        /// <summary>
        /// 材料防错验证-有特征码
        /// </summary>
        /// <param name="code"></param>
        private void ValidateMaterialInfo(string code)
        {
            Stopwatch validateWatch = new Stopwatch();

            try
            {
                if (!IsOK)
                {
                    validateWatch.Start();

                    bool IsExist = false;//标记是否存在
                    //标记为√
                    foreach (ListViewItem item in this.lvMaterial.Items)
                    {
                        bool meterialError = true;
                        materialCode = item.Text.ToString();         //当前的零件编码
                        string FeatureCode  = item.SubItems[5].Text; //特征码
                        string FeatureIndex = item.SubItems[6].Text; //特征位
                        bool   flag         = false;

                        if (FeatureCode == null || FeatureCode.Trim() == "")
                        {
                            if (code.Length < materialCode.Length)
                            {
                                meterialError = true;
                                continue;
                            }
                            string tmpCode = code.Substring(0, materialCode.Length);
                            flag = tmpCode == materialCode;//判断特征码
                        }
                        else
                        {
                            if (code.Length < FeatureCode.Length)
                            {
                                meterialError = true;
                                continue;
                            }

                            flag = Opt.ValidateFeatureCode(code, FeatureIndex, FeatureCode);//判断特征码
                        }
                        if (flag)
                        {
                            //判断零件是否存在
                            #region 判断合件是否存在
                            if (IsValidateBarcode)
                            {
                                string FieldName = item.SubItems[7].Text;
                                if (ValidateScanIsExist(2, code, FieldName))
                                {
                                    Tip("当前零件已使用过");
                                    Audio.SoundTip(0);//错误提示音
                                    return;
                                }
                            }
                            #endregion
                            int num  = int.Parse(item.SubItems[2].Text); //产品数量
                            int scan = int.Parse(item.SubItems[3].Text); //扫描数量

                            if ((scan + 1) == num)
                            {
                                item.SubItems[3].Text = (scan + 1).ToString();
                                item.ForeColor        = Color.Green; //当防错正常时字体为绿色
                                item.SubItems[1].Text = "OK";        //扫描次数刚好和产品数量相等时
                                meterialError         = false;
                                Audio.SoundTip(1);                   //正确提示音
                            }
                            else if ((scan + 1) < num)
                            {
                                item.SubItems[3].Text = (scan + 1).ToString();
                                item.ForeColor        = Color.CornflowerBlue; //当防错正常时字体为浅蓝色
                                item.SubItems[1].Text = "√";                  //扫描次数比产品数量小时
                                meterialError         = false;
                            }
                            else if ((scan + 1) > num)
                            {
                                meterialError = true;
                                this.Tip("该条码扫描次数超出"); //提示
                                Audio.SoundTip(0);     //错误提示音
                            }
                            //记录扫描信息
                            if (!meterialError)
                            {
                                //记录扫描信息
                                RecordScanInfo();
                            }
                            IsExist = true;//标记存在为true
                            break;
                        }
                    }

                    if (!IsExist)
                    {
                        this.Tip("合件不存在该条码的零件"); //提示不存在
                        Audio.SoundTip(0);       //错误提示音
                        return;
                    }

                    this.WirteTimeSpanLog(new TimeSpan(0, 0, 0, 0, (int)validateWatch.ElapsedMilliseconds), LogType.SC);
                    validateWatch.Stop();

                    int error = 0;
                    foreach (ListViewItem item in this.lvMaterial.Items)
                    {
                        if (item.SubItems[1].Text != "OK")
                        {
                            error++;
                        }
                    }
                    if (error == 0)
                    {
                        IsOK     = true;
                        IsHjScan = true;
                        //更新到数据库
                        bool ret = ScanResultToDb();
                        if (ret)
                        {
                            Audio.SoundTip(2);
                        }
                        else
                        {
                            Audio.SoundTip(0);//错误提示音
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                CLog.WriteErrLog("[FrmScan.ValidateMaterialInfo]" + ex.Message);
            }
        }
Example #16
0
        //方法
        #region 方法

        #region 通用扫描方法
        /// <summary>
        /// 通用扫描方法
        /// </summary>
        /// <param name="obj"></param>
        private void doCommonScan(string barcode)
        {
            try
            {
                this.lblScanCode.Text      = "";//清空提示信息
                this.lblScanCode.ForeColor = Color.Navy;

                //判断是合件条码还是材料条码
                if (IsHjScan)             //当为合件时
                {
                    RequestParam.Clear(); //清除数据

                    this.lblScanCode.Text = barcode;
                    #region 合件

                    bool isNew = false;//新产品标识

                    #region 判断合件条码长度
                    bool CheckBitRST = Opt.HJValidate(barcode);
                    //校验位判断
                    if (!CheckBitRST)
                    {
                        this.Tip("合件条码长度不符合!");
                        Audio.SoundTip(0);//错误提示音
                        return;
                    }
                    #endregion

                    #region 判断校验位
                    //判断校验位
                    string CheckCode      = barcode.Substring(0, 13); //校验合件条码
                    string CheckBitOrigin = barcode.Substring(13, 1); //校验位
                    string CheckBit       = Opt.CheckBit(CheckCode);  //获取校验位
                    if (!CheckBit.ToLower().Equals(CheckBitOrigin.ToLower()))
                    {
                        this.Tip("合件条码校验位错误!");
                        Audio.SoundTip(0);//错误提示音
                        return;
                    }
                    #endregion

                    #region //判断特征码
                    string fc = barcode.Substring(0, 6);
                    //前一个特征码与现在扫描相同
                    if (this.productModel != null && this.productModel.FeatureCode == fc)
                    {
                        //清除前一次信息
                        foreach (ListViewItem item in lvMaterial.Items)
                        {
                            item.SubItems[1].Text = "";          //初始化状态为空
                            item.SubItems[3].Text = "0";         //初始化状态为空
                            item.ForeColor        = Color.Black; //初始化字体颜色为黑色
                        }
                    }
                    else
                    {
                        isNew = this.productModel == null;
                        if (Opt.FeatureCodeList.ContainsKey(fc))
                        {
                            //扫描合件的特征码存在
                            this.productModel = Opt.FeatureCodeList[fc];
                            isNew             = true;

                            this.lblTitle.Text       = "扫描-" + this.productModel.ProductName;
                            this.lblProductCode.Text = this.productModel.ProductCode;
                        }
                        else
                        {
                            //扫描合件的特征码不存在
                            IsHjScan = true;
                            this.Tip("合件条码不符,请重新扫描合件");
                            Audio.SoundTip(0);//错误提示音
                            return;
                        }
                    }
                    #endregion

                    #region                //判断合件是否存在
                    if (IsValidateBarcode) //if (IsValidateBarcode && CurrnetScanType==1)
                    {
                        if (ValidateScanIsExist(1, barcode, ""))
                        {
                            Tip("当前合件已存在");
                            Audio.SoundTip(0);//错误提示音
                            return;
                        }
                    }
                    #endregion

                    this.lblHJCode.Text = barcode;
                    this.lblOK.Text     = "";

                    #region //判断是否有子零件
                    if (CurrnetScanType == 0)
                    {
                        #region //判断是否为新的产品
                        if (isNew || this.lvMaterial.Items == null || this.lvMaterial.Items.Count == 0)
                        {
                            InitListView();//加载子零件编码列表
                        }
                        #endregion
                    }
                    else
                    {
                        IsOK     = true;
                        IsHjScan = true;
                        //更新到数据库
                        bool ret = ScanResultToDb();
                        if (ret)
                        {
                            Audio.SoundTip(2);
                        }
                        else
                        {
                            Audio.SoundTip(0);//错误提示音
                        }
                        return;
                    }
                    #endregion

                    if (!this.productModel.HaveSub)
                    {
                        IsOK     = true;
                        IsHjScan = true;
                        Audio.SoundTip(0);//错误提示音
                        this.Tip("当前合件没有子零件");
                        return;
                    }

                    //记录扫描信息
                    RecordScanInfo();
                    IsOK     = false;
                    IsHjScan = false;
                    this.Tip("请扫描子零件条码");
                    #endregion

                    //BatchTip();//批次信息提醒
                }
                else
                {
                    //当为子零件时
                    barcode = barcode.Replace("<cr><lf>", "").Replace("\r", "").Replace("\n", "").Replace("]C1", ""); //获取条码/二维码,过滤回车换行
                    this.lblScanCode.Text = barcode;
                    ValidateMaterialInfo(barcode);                                                                    //材料防错,对比特征码
                }
            }
            catch (Exception ex)
            {
                CLog.WriteErrLog("扫描条码," + ex.Message);
            }
        }